Annotation of src/sys/lib/libsa/stand.h, Revision 1.62.6.1
1.62.6.1! bouyer 1: /* $NetBSD$ */
1.31 cgd 2:
3: /*
4: * Copyright (c) 1999 Christopher G. Demetriou. All rights reserved.
5: *
6: * Redistribution and use in source and binary forms, with or without
7: * modification, are permitted provided that the following conditions
8: * are met:
9: * 1. Redistributions of source code must retain the above copyright
10: * notice, this list of conditions and the following disclaimer.
11: * 2. Redistributions in binary form must reproduce the above copyright
12: * notice, this list of conditions and the following disclaimer in the
13: * documentation and/or other materials provided with the distribution.
14: * 3. All advertising materials mentioning features or use of this software
15: * must display the following acknowledgement:
16: * This product includes software developed by Christopher G. Demetriou
17: * for the NetBSD Project.
18: * 4. The name of the author may not be used to endorse or promote products
19: * derived from this software without specific prior written permission
20: *
21: * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22: * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24: * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25: * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26: * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30: * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31: */
1.5 cgd 32:
1.1 brezak 33: /*-
34: * Copyright (c) 1993
35: * The Regents of the University of California. All rights reserved.
36: *
37: * Redistribution and use in source and binary forms, with or without
38: * modification, are permitted provided that the following conditions
39: * are met:
40: * 1. Redistributions of source code must retain the above copyright
41: * notice, this list of conditions and the following disclaimer.
42: * 2. Redistributions in binary form must reproduce the above copyright
43: * notice, this list of conditions and the following disclaimer in the
44: * documentation and/or other materials provided with the distribution.
1.49 agc 45: * 3. Neither the name of the University nor the names of its contributors
1.1 brezak 46: * may be used to endorse or promote products derived from this software
47: * without specific prior written permission.
48: *
49: * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
50: * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
51: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
52: * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
53: * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
54: * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
55: * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
56: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
57: * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
58: * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
59: * SUCH DAMAGE.
60: *
1.5 cgd 61: * @(#)stand.h 8.1 (Berkeley) 6/11/93
1.1 brezak 62: */
63:
1.53 christos 64: #ifndef _LIBSA_STAND_H_
65: #define _LIBSA_STAND_H_
66:
1.1 brezak 67: #include <sys/types.h>
68: #include <sys/cdefs.h>
69: #include <sys/stat.h>
70: #include "saioctl.h"
71: #include "saerrno.h"
72:
73: #ifndef NULL
74: #define NULL 0
1.30 simonb 75: #endif
76:
1.41 takemura 77: #ifdef LIBSA_RENAME_PRINTF
78: #define getchar libsa_getchar
79: #define gets libsa_gets
80: #define printf libsa_printf
81: #define putchar libsa_putchar
82: #define sprintf libsa_sprintf
83: #define vprintf libsa_vprintf
84: #define vsprintf libsa_vsprintf
85: #endif
1.57 junyoung 86: #define bcmp(s1, s2, l) memcmp(s1, s2, l)
1.30 simonb 87: #ifdef LIBSA_USE_MEMSET
88: #define bzero(s, l) memset(s, 0, l)
89: #endif
90: #ifdef LIBSA_USE_MEMCPY
91: #define bcopy(s, d, l) memcpy(d, s, l) /* For non-overlapping copies only */
1.1 brezak 92: #endif
93:
94: struct open_file;
95:
1.46 dsl 96: #define FS_DEF(fs) \
1.50 dsl 97: extern int __CONCAT(fs,_open)(const char *, struct open_file *); \
1.46 dsl 98: extern int __CONCAT(fs,_close)(struct open_file *); \
99: extern int __CONCAT(fs,_read)(struct open_file *, void *, \
100: size_t, size_t *); \
101: extern int __CONCAT(fs,_write)(struct open_file *, void *, \
102: size_t, size_t *); \
103: extern off_t __CONCAT(fs,_seek)(struct open_file *, off_t, int); \
104: extern int __CONCAT(fs,_stat)(struct open_file *, struct stat *)
105:
1.1 brezak 106: /*
107: * This structure is used to define file system operations in a file system
108: * independent way.
109: */
1.31 cgd 110: #if !defined(LIBSA_SINGLE_FILESYSTEM)
1.1 brezak 111: struct fs_ops {
1.50 dsl 112: int (*open)(const char *, struct open_file *);
1.46 dsl 113: int (*close)(struct open_file *);
114: int (*read)(struct open_file *, void *, size_t, size_t *);
115: int (*write)(struct open_file *, void *, size_t size, size_t *);
116: off_t (*seek)(struct open_file *, off_t, int);
117: int (*stat)(struct open_file *, struct stat *);
1.1 brezak 118: };
119:
120: extern struct fs_ops file_system[];
1.13 leo 121: extern int nfsys;
1.1 brezak 122:
1.46 dsl 123: #define FS_OPS(fs) { \
124: __CONCAT(fs,_open), \
125: __CONCAT(fs,_close), \
126: __CONCAT(fs,_read), \
127: __CONCAT(fs,_write), \
128: __CONCAT(fs,_seek), \
129: __CONCAT(fs,_stat) }
130:
1.31 cgd 131: #define FS_OPEN(fs) ((fs)->open)
132: #define FS_CLOSE(fs) ((fs)->close)
133: #define FS_READ(fs) ((fs)->read)
134: #define FS_WRITE(fs) ((fs)->write)
135: #define FS_SEEK(fs) ((fs)->seek)
136: #define FS_STAT(fs) ((fs)->stat)
137:
138: #else
139:
140: #define FS_OPEN(fs) ___CONCAT(LIBSA_SINGLE_FILESYSTEM,_open)
141: #define FS_CLOSE(fs) ___CONCAT(LIBSA_SINGLE_FILESYSTEM,_close)
142: #define FS_READ(fs) ___CONCAT(LIBSA_SINGLE_FILESYSTEM,_read)
143: #define FS_WRITE(fs) ___CONCAT(LIBSA_SINGLE_FILESYSTEM,_write)
144: #define FS_SEEK(fs) ___CONCAT(LIBSA_SINGLE_FILESYSTEM,_seek)
145: #define FS_STAT(fs) ___CONCAT(LIBSA_SINGLE_FILESYSTEM,_stat)
146:
1.46 dsl 147: FS_DEF(LIBSA_SINGLE_FILESYSTEM);
1.31 cgd 148:
149: #endif
150:
1.1 brezak 151: /* where values for lseek(2) */
152: #define SEEK_SET 0 /* set file offset to offset */
153: #define SEEK_CUR 1 /* set file offset to current plus offset */
154: #define SEEK_END 2 /* set file offset to EOF plus offset */
155:
156: /* Device switch */
1.31 cgd 157: #if !defined(LIBSA_SINGLE_DEVICE)
158:
1.1 brezak 159: struct devsw {
160: char *dv_name;
1.46 dsl 161: int (*dv_strategy)(void *, int, daddr_t, size_t, void *, size_t *);
162: int (*dv_open)(struct open_file *, ...);
163: int (*dv_close)(struct open_file *);
164: int (*dv_ioctl)(struct open_file *, u_long, void *);
1.1 brezak 165: };
166:
167: extern struct devsw devsw[]; /* device array */
168: extern int ndevs; /* number of elements in devsw[] */
169:
1.31 cgd 170: #define DEV_NAME(d) ((d)->dv_name)
171: #define DEV_STRATEGY(d) ((d)->dv_strategy)
172: #define DEV_OPEN(d) ((d)->dv_open)
173: #define DEV_CLOSE(d) ((d)->dv_close)
174: #define DEV_IOCTL(d) ((d)->dv_ioctl)
175:
176: #else
177:
178: #define DEV_NAME(d) ___STRING(LIBSA_SINGLE_DEVICE)
179: #define DEV_STRATEGY(d) ___CONCAT(LIBSA_SINGLE_DEVICE,strategy)
180: #define DEV_OPEN(d) ___CONCAT(LIBSA_SINGLE_DEVICE,open)
181: #define DEV_CLOSE(d) ___CONCAT(LIBSA_SINGLE_DEVICE,close)
182: #define DEV_IOCTL(d) ___CONCAT(LIBSA_SINGLE_DEVICE,ioctl)
183:
1.46 dsl 184: /* These may be #defines which must not be expanded here, hence the extra () */
185: int (DEV_STRATEGY(unused))(void *, int, daddr_t, size_t, void *, size_t *);
186: int (DEV_OPEN(unused))(struct open_file *, ...);
187: int (DEV_CLOSE(unused))(struct open_file *);
188: int (DEV_IOCTL(unused))(struct open_file *, u_long, void *);
1.31 cgd 189:
190: #endif
191:
1.1 brezak 192: struct open_file {
193: int f_flags; /* see F_* below */
1.31 cgd 194: #if !defined(LIBSA_SINGLE_DEVICE)
1.45 mycroft 195: const struct devsw *f_dev; /* pointer to device operations */
1.31 cgd 196: #endif
1.1 brezak 197: void *f_devdata; /* device specific data */
1.31 cgd 198: #if !defined(LIBSA_SINGLE_FILESYSTEM)
1.45 mycroft 199: const struct fs_ops *f_ops; /* pointer to file system operations */
1.31 cgd 200: #endif
1.1 brezak 201: void *f_fsdata; /* file system specific data */
1.31 cgd 202: #if !defined(LIBSA_NO_RAW_ACCESS)
1.14 pk 203: off_t f_offset; /* current file offset (F_RAW) */
1.31 cgd 204: #endif
1.1 brezak 205: };
206:
207: #define SOPEN_MAX 4
1.8 cgd 208: extern struct open_file files[];
1.1 brezak 209:
210: /* f_flags values */
211: #define F_READ 0x0001 /* file opened for reading */
212: #define F_WRITE 0x0002 /* file opened for writing */
1.31 cgd 213: #if !defined(LIBSA_NO_RAW_ACCESS)
1.1 brezak 214: #define F_RAW 0x0004 /* raw device open - no file system */
1.31 cgd 215: #endif
1.2 brezak 216: #define F_NODEV 0x0008 /* network open - no device */
1.1 brezak 217:
1.46 dsl 218: int (devopen)(struct open_file *, const char *, char **);
1.22 drochner 219: #ifdef HEAP_VARIABLE
1.46 dsl 220: void setheap(void *, void *);
1.22 drochner 221: #endif
1.61 uwe 222: void *alloc(size_t);
223: void dealloc(void *, size_t);
1.1 brezak 224: struct disklabel;
1.46 dsl 225: char *getdisklabel(const char *, struct disklabel *);
1.53 christos 226: int dkcksum(const struct disklabel *);
1.2 brezak 227:
1.60 christos 228: void printf(const char *, ...)
229: __attribute__((__format__(__printf__, 1, 2)));
230: int sprintf(char *, const char *, ...)
231: __attribute__((__format__(__printf__, 2, 3)));
232: int snprintf(char *, size_t, const char *, ...)
233: __attribute__((__format__(__printf__, 3, 4)));
234: void vprintf(const char *, _BSD_VA_LIST_)
235: __attribute__((__format__(__printf__, 1, 0)));
236: int vsprintf(char *, const char *, _BSD_VA_LIST_)
237: __attribute__((__format__(__printf__, 2, 0)));
238: int vsnprintf(char *, size_t, const char *, _BSD_VA_LIST_)
239: __attribute__((__format__(__printf__, 3, 0)));
1.46 dsl 240: void twiddle(void);
241: void gets(char *);
242: int getfile(char *prompt, int mode);
243: char *strerror(int);
1.62.6.1! bouyer 244: __dead void exit(int);
! 245: __dead void panic(const char *, ...);
! 246: __dead void _rtt(void);
1.47 dsl 247: void (bcopy)(const void *, void *, size_t);
1.46 dsl 248: void *memcpy(void *, const void *, size_t);
249: void *memmove(void *, const void *, size_t);
250: int memcmp(const void *, const void *, size_t);
1.51 he 251: void *memset(void *, int, size_t);
1.46 dsl 252: void exec(char *, char *, int);
253: int open(const char *, int);
254: int close(int);
255: void closeall(void);
256: ssize_t read(int, void *, size_t);
1.59 christos 257: ssize_t write(int, const void *, size_t);
1.46 dsl 258: off_t lseek(int, off_t, int);
259: int ioctl(int, u_long, char *);
260: int stat(const char *, struct stat *);
261: int fstat(int, struct stat *);
1.34 thorpej 262:
1.52 abs 263: typedef int cmp_t __P((const void *, const void *));
1.62 isaki 264: void qsort(void *, size_t, size_t, cmp_t *);
1.52 abs 265:
1.32 christos 266: extern int opterr, optind, optopt, optreset;
267: extern char *optarg;
1.46 dsl 268: int getopt(int, char * const *, const char *);
269:
270: char *getpass(const char *);
271: int checkpasswd(void);
1.48 dsl 272: int check_password(const char *);
1.33 drochner 273:
1.46 dsl 274: int nodev(void);
275: int noioctl(struct open_file *, u_long, void *);
276: void nullsys(void);
1.33 drochner 277:
1.46 dsl 278: FS_DEF(null);
1.2 brezak 279:
1.4 brezak 280: /* Machine dependent functions */
1.46 dsl 281: void machdep_start(char *, int, char *, char *, char *);
282: int getchar(void);
1.54 perry 283: void putchar(int);
1.20 cgd 284:
285: #ifdef __INTERNAL_LIBSA_CREAD
1.46 dsl 286: int oopen(const char *, int);
287: int oclose(int);
288: ssize_t oread(int, void *, size_t);
289: off_t olseek(int, off_t, int);
1.20 cgd 290: #endif
1.53 christos 291:
1.56 jmc 292: extern const char HEXDIGITS[];
1.55 christos 293: extern const char hexdigits[];
294:
1.53 christos 295: #endif /* _LIBSA_STAND_H_ */
CVSweb <webmaster@jp.NetBSD.org>