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