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