stand.h 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. /* $OpenBSD: stand.h,v 1.60 2015/02/05 12:56:50 millert Exp $ */
  2. /* $NetBSD: stand.h,v 1.18 1996/11/30 04:35:51 gwr Exp $ */
  3. /*-
  4. * Copyright (c) 1993
  5. * The Regents of the University of California. All rights reserved.
  6. *
  7. * Redistribution and use in source and binary forms, with or without
  8. * modification, are permitted provided that the following conditions
  9. * are met:
  10. * 1. Redistributions of source code must retain the above copyright
  11. * notice, this list of conditions and the following disclaimer.
  12. * 2. Redistributions in binary form must reproduce the above copyright
  13. * notice, this list of conditions and the following disclaimer in the
  14. * documentation and/or other materials provided with the distribution.
  15. * 3. Neither the name of the University nor the names of its contributors
  16. * may be used to endorse or promote products derived from this software
  17. * without specific prior written permission.
  18. *
  19. * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  20. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  21. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  22. * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  23. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  24. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  25. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  26. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  27. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  28. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  29. * SUCH DAMAGE.
  30. *
  31. * @(#)stand.h 8.1 (Berkeley) 6/11/93
  32. */
  33. #include <sys/types.h>
  34. #include <sys/stat.h>
  35. #include <sys/stdarg.h>
  36. #include <sys/stdint.h>
  37. #include "saerrno.h"
  38. #ifndef NULL
  39. #define NULL 0
  40. #endif
  41. struct open_file;
  42. /*
  43. * Useful macros
  44. */
  45. /* don't define if libkern included */
  46. #ifndef LIBKERN_INLINE
  47. #define max(a,b) (((a)>(b))? (a) : (b))
  48. #define min(a,b) (((a)>(b))? (b) : (a))
  49. #endif
  50. /*
  51. * This structure is used to define file system operations in a file system
  52. * independent way.
  53. */
  54. struct fs_ops {
  55. int (*open)(char *path, struct open_file *f);
  56. int (*close)(struct open_file *f);
  57. int (*read)(struct open_file *f, void *buf,
  58. size_t size, size_t *resid);
  59. int (*write)(struct open_file *f, void *buf,
  60. size_t size, size_t *resid);
  61. off_t (*seek)(struct open_file *f, off_t offset, int where);
  62. int (*stat)(struct open_file *f, struct stat *sb);
  63. int (*readdir)(struct open_file *f, char *);
  64. };
  65. extern struct fs_ops file_system[];
  66. extern int nfsys;
  67. /* where values for lseek(2) */
  68. #define SEEK_SET 0 /* set file offset to offset */
  69. #define SEEK_CUR 1 /* set file offset to current plus offset */
  70. #define SEEK_END 2 /* set file offset to EOF plus offset */
  71. /* Device switch */
  72. struct devsw {
  73. char *dv_name;
  74. int (*dv_strategy)(void *devdata, int rw,
  75. daddr32_t blk, size_t size,
  76. void *buf, size_t *rsize);
  77. int (*dv_open)(struct open_file *f, ...);
  78. int (*dv_close)(struct open_file *f);
  79. int (*dv_ioctl)(struct open_file *f, u_long cmd, void *data);
  80. };
  81. extern struct devsw devsw[]; /* device array */
  82. extern int ndevs; /* number of elements in devsw[] */
  83. extern struct consdev *cn_tab;
  84. struct open_file {
  85. int f_flags; /* see F_* below */
  86. struct devsw *f_dev; /* pointer to device operations */
  87. void *f_devdata; /* device specific data */
  88. struct fs_ops *f_ops; /* pointer to file system operations */
  89. void *f_fsdata; /* file system specific data */
  90. off_t f_offset; /* current file offset (F_RAW) */
  91. };
  92. #define SOPEN_MAX 4
  93. extern struct open_file files[];
  94. /* f_flags values */
  95. #define F_READ 0x0001 /* file opened for reading */
  96. #define F_WRITE 0x0002 /* file opened for writing */
  97. #define F_RAW 0x0004 /* raw device open - no file system */
  98. #define F_NODEV 0x0008 /* network open - no device */
  99. #define isupper(c) ((c) >= 'A' && (c) <= 'Z')
  100. #define islower(c) ((c) >= 'a' && (c) <= 'z')
  101. #define isalpha(c) (isupper(c)||islower(c))
  102. #define tolower(c) (isupper(c)?((c) - 'A' + 'a'):(c))
  103. #define toupper(c) (islower(c)?((c) - 'a' + 'A'):(c))
  104. #define isspace(c) ((c) == ' ' || (c) == '\t')
  105. #define isdigit(c) ((c) >= '0' && (c) <= '9')
  106. #define btochs(b,c,h,s,nh,ns) \
  107. c = (b) / ((nh) * (ns)); \
  108. h = ((b) % ((nh) * (ns))) / (ns); \
  109. s = ((b) % ((nh) * (ns))) % (ns);
  110. void *alloc(u_int);
  111. void *alloca(size_t);
  112. void free(void *, u_int);
  113. struct disklabel;
  114. char *getdisklabel(const char *, struct disklabel *);
  115. u_int dkcksum(const struct disklabel *);
  116. #define BOOTRANDOM "/etc/random.seed"
  117. #define BOOTRANDOM_MAX 512
  118. extern char rnddata[BOOTRANDOM_MAX];
  119. void printf(const char *, ...);
  120. int snprintf(char *, size_t, const char *, ...);
  121. void vprintf(const char *, __va_list);
  122. void twiddle(void);
  123. void gets(char *);
  124. __dead void panic(const char *, ...) __attribute__((noreturn));
  125. __dead void _rtt(void) __attribute__((noreturn));
  126. #define bzero(s,n) ((void)memset((s),0,(n)))
  127. #define bcmp(s1,s2,n) (memcmp((s2),(s1),(n)))
  128. #define bcopy(s1,s2,n) ((void)memcpy((s2),(s1),(n)))
  129. void explicit_bzero(void *, size_t);
  130. void *memcpy(void *, const void *, size_t);
  131. int memcmp(const void *, const void *, size_t);
  132. char *strncpy(char *, const char *, size_t);
  133. int strncmp(const char *, const char *, size_t);
  134. int strcmp(const char *, const char *);
  135. size_t strlen(const char *);
  136. long strtol(const char *, char **, int);
  137. long long strtoll(const char *, char **, int);
  138. char *strchr(const char *, int);
  139. void *memset(void *, int, size_t);
  140. void exit(void);
  141. int open(const char *, int);
  142. int close(int);
  143. void closeall(void);
  144. ssize_t read(int, void *, size_t);
  145. ssize_t write(int, void *, size_t);
  146. int stat(const char *path, struct stat *sb);
  147. int fstat(int fd, struct stat *sb);
  148. int opendir(const char *);
  149. int readdir(int, char *);
  150. void closedir(int);
  151. int nodev(void);
  152. int noioctl(struct open_file *, u_long, void *);
  153. void nullsys(void);
  154. int null_open(char *path, struct open_file *f);
  155. int null_close(struct open_file *f);
  156. ssize_t null_read(struct open_file *f, void *buf, size_t size, size_t *resid);
  157. ssize_t null_write(struct open_file *f, void *buf, size_t size, size_t *resid);
  158. off_t null_seek(struct open_file *f, off_t offset, int where);
  159. int null_stat(struct open_file *f, struct stat *sb);
  160. int null_readdir(struct open_file *f, char *name);
  161. char *ttyname(int); /* match userland decl, but ignore !0 */
  162. dev_t ttydev(char *);
  163. void cninit(void);
  164. int cnset(dev_t);
  165. void cnputc(int);
  166. int cngetc(void);
  167. int cnischar(void);
  168. int cnspeed(dev_t, int);
  169. u_int sleep(u_int);
  170. void usleep(u_int);
  171. char *ctime(const time_t *);
  172. int ioctl(int, u_long, char *);
  173. void putchar(int);
  174. int getchar(void);
  175. #ifdef __INTERNAL_LIBSA_CREAD
  176. int oopen(const char *, int);
  177. int oclose(int);
  178. ssize_t oread(int, void *, size_t);
  179. off_t olseek(int, off_t, int);
  180. #endif
  181. /* Machine dependent functions */
  182. int devopen(struct open_file *, const char *, char **);
  183. void machdep_start(char *, int, char *, char *, char *);
  184. time_t getsecs(void);