1 /* $NetBSD: stand.h,v 1.79 2014/08/10 07:40:49 isaki Exp $ */
4 * Copyright (c) 1999 Christopher G. Demetriou. All rights reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
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
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.
35 * The Regents of the University of California. All rights reserved.
37 * Redistribution and use in source and binary forms, with or without
38 * modification, are permitted provided that the following conditions
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.
45 * 3. Neither the name of the University nor the names of its contributors
46 * may be used to endorse or promote products derived from this software
47 * without specific prior written permission.
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
61 * @(#)stand.h 8.1 (Berkeley) 6/11/93
64 #ifndef _LIBSA_STAND_H_
65 #define _LIBSA_STAND_H_
67 #include <sys/types.h>
68 #include <sys/cdefs.h>
70 #include <sys/stdarg.h>
78 #ifdef LIBSA_RENAME_PRINTF
79 #define getchar libsa_getchar
80 #define gets libsa_gets
81 #define printf libsa_printf
82 #define putchar libsa_putchar
83 #define vprintf libsa_vprintf
88 #define FS_DEF_BASE(fs) \
89 extern __compactcall int __CONCAT(fs,_open)(const char *, struct open_file *); \
90 extern __compactcall int __CONCAT(fs,_close)(struct open_file *); \
91 extern __compactcall int __CONCAT(fs,_read)(struct open_file *, void *, \
93 extern __compactcall int __CONCAT(fs,_write)(struct open_file *, void *, \
95 extern __compactcall off_t __CONCAT(fs,_seek)(struct open_file *, off_t, int); \
96 extern __compactcall int __CONCAT(fs,_stat)(struct open_file *, struct stat *)
98 #if defined(LIBSA_ENABLE_LS_OP)
99 # if defined(__minix) && LIBSA_ENABLE_LOAD_MODS_OP
102 extern __compactcall void __CONCAT(fs,_ls)(struct open_file *, const char *); \
103 extern __compactcall void __CONCAT(fs,_load_mods)(struct open_file *, const char *, \
104 void (*)(char *), char *)
108 extern __compactcall void __CONCAT(fs,_ls)(struct open_file *, const char *)
109 # endif /* defined(__minix) && LIBSA_ENABLE_LOAD_MODS_OP */
111 #define FS_DEF(fs) FS_DEF_BASE(fs)
116 * This structure is used to define file system operations in a file system
119 extern const char *fsmod
;
121 #if !defined(LIBSA_SINGLE_FILESYSTEM)
123 __compactcall
int (*open
)(const char *, struct open_file
*);
124 __compactcall
int (*close
)(struct open_file
*);
125 __compactcall
int (*read
)(struct open_file
*, void *, size_t, size_t *);
126 __compactcall
int (*write
)(struct open_file
*, void *, size_t size
, size_t *);
127 __compactcall
off_t (*seek
)(struct open_file
*, off_t
, int);
128 __compactcall
int (*stat
)(struct open_file
*, struct stat
*);
129 #if defined(LIBSA_ENABLE_LS_OP)
130 __compactcall
void (*ls
)(struct open_file
*, const char *);
131 # if defined(__minix) && LIBSA_ENABLE_LOAD_MODS_OP
132 __compactcall
void (*load_mods
)(struct open_file
*, const char *,
133 void (*)(char *), char *);
134 # endif /* defined(__minix) && LIBSA_ENABLE_LOAD_MODS_OP */
138 extern struct fs_ops file_system
[];
141 #if defined(LIBSA_ENABLE_LS_OP)
142 # if defined(__minix) && LIBSA_ENABLE_LOAD_MODS_OP
143 #define FS_OPS(fs) { \
144 __CONCAT(fs,_open), \
145 __CONCAT(fs,_close), \
146 __CONCAT(fs,_read), \
147 __CONCAT(fs,_write), \
148 __CONCAT(fs,_seek), \
149 __CONCAT(fs,_stat), \
151 __CONCAT(fs,_load_mods) }
153 #define FS_OPS(fs) { \
154 __CONCAT(fs,_open), \
155 __CONCAT(fs,_close), \
156 __CONCAT(fs,_read), \
157 __CONCAT(fs,_write), \
158 __CONCAT(fs,_seek), \
159 __CONCAT(fs,_stat), \
161 # endif /* defined(__minix) && LIBSA_ENABLE_LOAD_MODS_OP */
163 #define FS_OPS(fs) { \
164 __CONCAT(fs,_open), \
165 __CONCAT(fs,_close), \
166 __CONCAT(fs,_read), \
167 __CONCAT(fs,_write), \
168 __CONCAT(fs,_seek), \
172 #define FS_OPEN(fs) ((fs)->open)
173 #define FS_CLOSE(fs) ((fs)->close)
174 #define FS_READ(fs) ((fs)->read)
175 #define FS_WRITE(fs) ((fs)->write)
176 #define FS_SEEK(fs) ((fs)->seek)
177 #define FS_STAT(fs) ((fs)->stat)
178 #if defined(LIBSA_ENABLE_LS_OP)
179 #define FS_LS(fs) ((fs)->ls)
180 #if defined(__minix) && defined(LIBSA_ENABLE_LOAD_MODS_OP)
181 #define FS_LOAD_MODS(fs) ((fs)->load_mods)
182 #endif /* defined(__minix) && defined(LIBSA_ENABLE_LOAD_MODS_OP) */
187 #define FS_OPEN(fs) ___CONCAT(LIBSA_SINGLE_FILESYSTEM,_open)
188 #define FS_CLOSE(fs) ___CONCAT(LIBSA_SINGLE_FILESYSTEM,_close)
189 #define FS_READ(fs) ___CONCAT(LIBSA_SINGLE_FILESYSTEM,_read)
190 #define FS_WRITE(fs) ___CONCAT(LIBSA_SINGLE_FILESYSTEM,_write)
191 #define FS_SEEK(fs) ___CONCAT(LIBSA_SINGLE_FILESYSTEM,_seek)
192 #define FS_STAT(fs) ___CONCAT(LIBSA_SINGLE_FILESYSTEM,_stat)
193 #if defined(LIBSA_ENABLE_LS_OP)
194 #define FS_LS(fs) ___CONCAT(LIBSA_SINGLE_FILESYSTEM,_ls)
195 #if defined(__minix) && defined(LIBSA_ENABLE_LOAD_MODS_OP)
196 #define FS_LOAD_MODS(fs) ___CONCAT(LIBSA_SINGLE_FILESYSTEM,_load_mods)
197 #endif /* defined(__minix) && defined(LIBSA_ENABLE_LOAD_MODS_OP) */
200 FS_DEF(LIBSA_SINGLE_FILESYSTEM
);
204 /* where values for lseek(2) */
205 #define SEEK_SET 0 /* set file offset to offset */
206 #define SEEK_CUR 1 /* set file offset to current plus offset */
207 #define SEEK_END 2 /* set file offset to EOF plus offset */
210 #if !defined(LIBSA_SINGLE_DEVICE)
214 int (*dv_strategy
)(void *, int, daddr_t
, size_t, void *, size_t *);
215 int (*dv_open
)(struct open_file
*, ...);
216 int (*dv_close
)(struct open_file
*);
217 int (*dv_ioctl
)(struct open_file
*, u_long
, void *);
220 extern struct devsw devsw
[]; /* device array */
221 extern int ndevs
; /* number of elements in devsw[] */
223 #define DEV_NAME(d) ((d)->dv_name)
224 #define DEV_STRATEGY(d) ((d)->dv_strategy)
225 #define DEV_OPEN(d) ((d)->dv_open)
226 #define DEV_CLOSE(d) ((d)->dv_close)
227 #define DEV_IOCTL(d) ((d)->dv_ioctl)
231 #define DEV_NAME(d) ___STRING(LIBSA_SINGLE_DEVICE)
232 #define DEV_STRATEGY(d) ___CONCAT(LIBSA_SINGLE_DEVICE,strategy)
233 #define DEV_OPEN(d) ___CONCAT(LIBSA_SINGLE_DEVICE,open)
234 #define DEV_CLOSE(d) ___CONCAT(LIBSA_SINGLE_DEVICE,close)
235 #define DEV_IOCTL(d) ___CONCAT(LIBSA_SINGLE_DEVICE,ioctl)
237 /* These may be #defines which must not be expanded here, hence the extra () */
238 int (DEV_STRATEGY(unused
))(void *, int, daddr_t
, size_t, void *, size_t *);
239 int (DEV_OPEN(unused
))(struct open_file
*, ...);
240 int (DEV_CLOSE(unused
))(struct open_file
*);
241 int (DEV_IOCTL(unused
))(struct open_file
*, u_long
, void *);
246 int f_flags
; /* see F_* below */
247 #if !defined(LIBSA_SINGLE_DEVICE)
248 const struct devsw
*f_dev
; /* pointer to device operations */
250 void *f_devdata
; /* device specific data */
251 #if !defined(LIBSA_SINGLE_FILESYSTEM)
252 const struct fs_ops
*f_ops
; /* pointer to file system operations */
254 void *f_fsdata
; /* file system specific data */
255 #if !defined(LIBSA_NO_RAW_ACCESS)
256 off_t f_offset
; /* current file offset (F_RAW) */
261 extern struct open_file files
[];
264 #define F_READ 0x0001 /* file opened for reading */
265 #define F_WRITE 0x0002 /* file opened for writing */
266 #if !defined(LIBSA_NO_RAW_ACCESS)
267 #define F_RAW 0x0004 /* raw device open - no file system */
269 #define F_NODEV 0x0008 /* network open - no device */
271 int (devopen
)(struct open_file
*, const char *, char **);
273 void setheap(void *, void *);
275 void *alloc(size_t) __compactcall
;
276 void dealloc(void *, size_t) __compactcall
;
278 char *getdisklabel(const char *, struct disklabel
*);
279 int dkcksum(const struct disklabel
*);
281 void printf(const char *, ...)
282 __attribute__((__format__(__printf__
, 1, 2)));
283 int snprintf(char *, size_t, const char *, ...)
284 __attribute__((__format__(__printf__
, 3, 4)));
285 void vprintf(const char *, va_list)
286 __attribute__((__format__(__printf__
, 1, 0)));
287 int vsnprintf(char *, size_t, const char *, va_list)
288 __attribute__((__format__(__printf__
, 3, 0)));
291 int getfile(char *prompt
, int mode
);
293 __dead
void exit(int);
294 __dead
void panic(const char *, ...)
295 __attribute__((__format__(__printf__
, 1, 2)));
296 __dead
void _rtt(void);
297 void *memcpy(void *, const void *, size_t);
298 void *memmove(void *, const void *, size_t);
299 int memcmp(const void *, const void *, size_t);
300 void *memset(void *, int, size_t);
301 void exec(char *, char *, int);
302 int open(const char *, int);
305 ssize_t
read(int, void *, size_t);
306 ssize_t
write(int, const void *, size_t);
307 off_t
lseek(int, off_t
, int);
308 int ioctl(int, u_long
, char *);
309 int stat(const char *, struct stat
*);
310 int fstat(int, struct stat
*);
311 #if defined(LIBSA_ENABLE_LS_OP)
312 void ls(const char *);
313 #if defined(__minix) && LIBSA_ENABLE_LOAD_MODS_OP
314 void load_mods(const char *, void (*)(char *));
315 #endif /* defined(__minix) && LIBSA_ENABLE_LOAD_MODS_OP */
318 typedef int cmp_t(const void *, const void *);
319 void qsort(void *, size_t, size_t, cmp_t
*);
321 extern int opterr
, optind
, optopt
, optreset
;
323 int getopt(int, char * const *, const char *);
325 char *getpass(const char *);
326 int checkpasswd(void);
327 int check_password(const char *);
330 int noioctl(struct open_file
*, u_long
, void *);
335 /* Machine dependent functions */
336 void machdep_start(char *, int, char *, char *, char *);
340 #ifdef __INTERNAL_LIBSA_CREAD
341 int oopen(const char *, int);
343 ssize_t
oread(int, void *, size_t);
344 off_t
olseek(int, off_t
, int);
347 extern const char hexdigits
[];
349 int fnmatch(const char *, const char *);
351 /* XXX: These should be removed eventually. */
352 void bcopy(const void *, void *, size_t);
353 void bzero(void *, size_t);
355 int atoi(const char *);
357 #endif /* _LIBSA_STAND_H_ */