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