1 /* $NetBSD: stand.h,v 1.76 2012/05/21 21:34:16 dsl 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 sprintf libsa_sprintf
84 #define vprintf libsa_vprintf
85 #define vsprintf libsa_vsprintf
90 #define FS_DEF_BASE(fs) \
91 extern __compactcall int __CONCAT(fs,_open)(const char *, struct open_file *); \
92 extern __compactcall int __CONCAT(fs,_close)(struct open_file *); \
93 extern __compactcall int __CONCAT(fs,_read)(struct open_file *, void *, \
95 extern __compactcall int __CONCAT(fs,_write)(struct open_file *, void *, \
97 extern __compactcall off_t __CONCAT(fs,_seek)(struct open_file *, off_t, int); \
98 extern __compactcall int __CONCAT(fs,_stat)(struct open_file *, struct stat *)
100 #if defined(LIBSA_ENABLE_LS_OP)
103 extern __compactcall void __CONCAT(fs,_ls)(struct open_file *, const char *,\
104 void (*)(char* arg), char*)
106 #define FS_DEF(fs) FS_DEF_BASE(fs)
111 * This structure is used to define file system operations in a file system
117 #if !defined(LIBSA_SINGLE_FILESYSTEM)
119 __compactcall
int (*open
)(const char *, struct open_file
*);
120 __compactcall
int (*close
)(struct open_file
*);
121 __compactcall
int (*read
)(struct open_file
*, void *, size_t, size_t *);
122 __compactcall
int (*write
)(struct open_file
*, void *, size_t size
, size_t *);
123 __compactcall
off_t (*seek
)(struct open_file
*, off_t
, int);
124 __compactcall
int (*stat
)(struct open_file
*, struct stat
*);
125 #if defined(LIBSA_ENABLE_LS_OP)
126 __compactcall
void (*ls
)(struct open_file
*, const char *,
127 void (*)(char* arg
), char*);
131 extern struct fs_ops file_system
[];
134 #if defined(LIBSA_ENABLE_LS_OP)
135 #define FS_OPS(fs) { \
136 __CONCAT(fs,_open), \
137 __CONCAT(fs,_close), \
138 __CONCAT(fs,_read), \
139 __CONCAT(fs,_write), \
140 __CONCAT(fs,_seek), \
141 __CONCAT(fs,_stat), \
144 #define FS_OPS(fs) { \
145 __CONCAT(fs,_open), \
146 __CONCAT(fs,_close), \
147 __CONCAT(fs,_read), \
148 __CONCAT(fs,_write), \
149 __CONCAT(fs,_seek), \
153 #define FS_OPEN(fs) ((fs)->open)
154 #define FS_CLOSE(fs) ((fs)->close)
155 #define FS_READ(fs) ((fs)->read)
156 #define FS_WRITE(fs) ((fs)->write)
157 #define FS_SEEK(fs) ((fs)->seek)
158 #define FS_STAT(fs) ((fs)->stat)
159 #if defined(LIBSA_ENABLE_LS_OP)
160 #define FS_LS(fs) ((fs)->ls)
165 #define FS_OPEN(fs) ___CONCAT(LIBSA_SINGLE_FILESYSTEM,_open)
166 #define FS_CLOSE(fs) ___CONCAT(LIBSA_SINGLE_FILESYSTEM,_close)
167 #define FS_READ(fs) ___CONCAT(LIBSA_SINGLE_FILESYSTEM,_read)
168 #define FS_WRITE(fs) ___CONCAT(LIBSA_SINGLE_FILESYSTEM,_write)
169 #define FS_SEEK(fs) ___CONCAT(LIBSA_SINGLE_FILESYSTEM,_seek)
170 #define FS_STAT(fs) ___CONCAT(LIBSA_SINGLE_FILESYSTEM,_stat)
171 #if defined(LIBSA_ENABLE_LS_OP)
172 #define FS_LS(fs) ___CONCAT(LIBSA_SINGLE_FILESYSTEM,_ls)
175 FS_DEF(LIBSA_SINGLE_FILESYSTEM
);
179 /* where values for lseek(2) */
180 #define SEEK_SET 0 /* set file offset to offset */
181 #define SEEK_CUR 1 /* set file offset to current plus offset */
182 #define SEEK_END 2 /* set file offset to EOF plus offset */
185 #if !defined(LIBSA_SINGLE_DEVICE)
189 int (*dv_strategy
)(void *, int, daddr_t
, size_t, void *, size_t *);
190 int (*dv_open
)(struct open_file
*, ...);
191 int (*dv_close
)(struct open_file
*);
192 int (*dv_ioctl
)(struct open_file
*, u_long
, void *);
195 extern struct devsw devsw
[]; /* device array */
196 extern int ndevs
; /* number of elements in devsw[] */
198 #define DEV_NAME(d) ((d)->dv_name)
199 #define DEV_STRATEGY(d) ((d)->dv_strategy)
200 #define DEV_OPEN(d) ((d)->dv_open)
201 #define DEV_CLOSE(d) ((d)->dv_close)
202 #define DEV_IOCTL(d) ((d)->dv_ioctl)
206 #define DEV_NAME(d) ___STRING(LIBSA_SINGLE_DEVICE)
207 #define DEV_STRATEGY(d) ___CONCAT(LIBSA_SINGLE_DEVICE,strategy)
208 #define DEV_OPEN(d) ___CONCAT(LIBSA_SINGLE_DEVICE,open)
209 #define DEV_CLOSE(d) ___CONCAT(LIBSA_SINGLE_DEVICE,close)
210 #define DEV_IOCTL(d) ___CONCAT(LIBSA_SINGLE_DEVICE,ioctl)
212 /* These may be #defines which must not be expanded here, hence the extra () */
213 int (DEV_STRATEGY(unused
))(void *, int, daddr_t
, size_t, void *, size_t *);
214 int (DEV_OPEN(unused
))(struct open_file
*, ...);
215 int (DEV_CLOSE(unused
))(struct open_file
*);
216 int (DEV_IOCTL(unused
))(struct open_file
*, u_long
, void *);
221 int f_flags
; /* see F_* below */
222 #if !defined(LIBSA_SINGLE_DEVICE)
223 const struct devsw
*f_dev
; /* pointer to device operations */
225 void *f_devdata
; /* device specific data */
226 #if !defined(LIBSA_SINGLE_FILESYSTEM)
227 const struct fs_ops
*f_ops
; /* pointer to file system operations */
229 void *f_fsdata
; /* file system specific data */
230 #if !defined(LIBSA_NO_RAW_ACCESS)
231 off_t f_offset
; /* current file offset (F_RAW) */
236 extern struct open_file files
[];
239 #define F_READ 0x0001 /* file opened for reading */
240 #define F_WRITE 0x0002 /* file opened for writing */
241 #if !defined(LIBSA_NO_RAW_ACCESS)
242 #define F_RAW 0x0004 /* raw device open - no file system */
244 #define F_NODEV 0x0008 /* network open - no device */
246 int (devopen
)(struct open_file
*, const char *, char **);
248 void setheap(void *, void *);
250 void *alloc(size_t) __compactcall
;
251 void dealloc(void *, size_t) __compactcall
;
253 char *getdisklabel(const char *, struct disklabel
*);
254 int dkcksum(const struct disklabel
*);
256 void printf(const char *, ...)
257 __attribute__((__format__(__printf__
, 1, 2)));
258 int sprintf(char *, const char *, ...)
259 __attribute__((__format__(__printf__
, 2, 3)));
260 int snprintf(char *, size_t, const char *, ...)
261 __attribute__((__format__(__printf__
, 3, 4)));
262 void vprintf(const char *, va_list)
263 __attribute__((__format__(__printf__
, 1, 0)));
264 int vsprintf(char *, const char *, va_list)
265 __attribute__((__format__(__printf__
, 2, 0)));
266 int vsnprintf(char *, size_t, const char *, va_list)
267 __attribute__((__format__(__printf__
, 3, 0)));
270 int getfile(char *prompt
, int mode
);
272 __dead
void exit(int);
273 __dead
void panic(const char *, ...)
274 __attribute__((__format__(__printf__
, 1, 2)));
275 __dead
void _rtt(void);
276 void *memcpy(void *, const void *, size_t);
277 void *memmove(void *, const void *, size_t);
278 int memcmp(const void *, const void *, size_t);
279 void *memset(void *, int, size_t);
280 void exec(char *, char *, int);
281 int open(const char *, int);
284 ssize_t
read(int, void *, size_t);
285 ssize_t
write(int, const void *, size_t);
286 off_t
lseek(int, off_t
, int);
287 int ioctl(int, u_long
, char *);
288 int stat(const char *, struct stat
*);
289 int fstat(int, struct stat
*);
290 #if defined(LIBSA_ENABLE_LS_OP)
291 void ls(const char *, void (*funcp
)(char* arg
));
294 typedef int cmp_t(const void *, const void *);
295 void qsort(void *, size_t, size_t, cmp_t
*);
297 extern int opterr
, optind
, optopt
, optreset
;
299 int getopt(int, char * const *, const char *);
301 char *getpass(const char *);
302 int checkpasswd(void);
303 int check_password(const char *);
306 int noioctl(struct open_file
*, u_long
, void *);
311 /* Machine dependent functions */
312 void machdep_start(char *, int, char *, char *, char *);
316 #ifdef __INTERNAL_LIBSA_CREAD
317 int oopen(const char *, int);
319 ssize_t
oread(int, void *, size_t);
320 off_t
olseek(int, off_t
, int);
323 extern const char hexdigits
[];
325 int fnmatch(const char *, const char *);
327 /* XXX: These should be removed eventually. */
328 void bcopy(const void *, void *, size_t);
329 void bzero(void *, size_t);
331 #endif /* _LIBSA_STAND_H_ */