stand.h revision 1.55 1 1.55 christos /* $NetBSD: stand.h,v 1.55 2005/05/17 04:14:58 christos 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.30 simonb #ifdef LIBSA_USE_MEMSET
87 1.30 simonb #define bzero(s, l) memset(s, 0, l)
88 1.30 simonb #endif
89 1.30 simonb #ifdef LIBSA_USE_MEMCPY
90 1.30 simonb #define bcopy(s, d, l) memcpy(d, s, l) /* For non-overlapping copies only */
91 1.1 brezak #endif
92 1.1 brezak
93 1.1 brezak struct open_file;
94 1.1 brezak
95 1.46 dsl #define FS_DEF(fs) \
96 1.50 dsl extern int __CONCAT(fs,_open)(const char *, struct open_file *); \
97 1.46 dsl extern int __CONCAT(fs,_close)(struct open_file *); \
98 1.46 dsl extern int __CONCAT(fs,_read)(struct open_file *, void *, \
99 1.46 dsl size_t, size_t *); \
100 1.46 dsl extern int __CONCAT(fs,_write)(struct open_file *, void *, \
101 1.46 dsl size_t, size_t *); \
102 1.46 dsl extern off_t __CONCAT(fs,_seek)(struct open_file *, off_t, int); \
103 1.46 dsl extern int __CONCAT(fs,_stat)(struct open_file *, struct stat *)
104 1.46 dsl
105 1.1 brezak /*
106 1.1 brezak * This structure is used to define file system operations in a file system
107 1.1 brezak * independent way.
108 1.1 brezak */
109 1.31 cgd #if !defined(LIBSA_SINGLE_FILESYSTEM)
110 1.1 brezak struct fs_ops {
111 1.50 dsl int (*open)(const char *, struct open_file *);
112 1.46 dsl int (*close)(struct open_file *);
113 1.46 dsl int (*read)(struct open_file *, void *, size_t, size_t *);
114 1.46 dsl int (*write)(struct open_file *, void *, size_t size, size_t *);
115 1.46 dsl off_t (*seek)(struct open_file *, off_t, int);
116 1.46 dsl int (*stat)(struct open_file *, struct stat *);
117 1.1 brezak };
118 1.1 brezak
119 1.1 brezak extern struct fs_ops file_system[];
120 1.13 leo extern int nfsys;
121 1.1 brezak
122 1.46 dsl #define FS_OPS(fs) { \
123 1.46 dsl __CONCAT(fs,_open), \
124 1.46 dsl __CONCAT(fs,_close), \
125 1.46 dsl __CONCAT(fs,_read), \
126 1.46 dsl __CONCAT(fs,_write), \
127 1.46 dsl __CONCAT(fs,_seek), \
128 1.46 dsl __CONCAT(fs,_stat) }
129 1.46 dsl
130 1.31 cgd #define FS_OPEN(fs) ((fs)->open)
131 1.31 cgd #define FS_CLOSE(fs) ((fs)->close)
132 1.31 cgd #define FS_READ(fs) ((fs)->read)
133 1.31 cgd #define FS_WRITE(fs) ((fs)->write)
134 1.31 cgd #define FS_SEEK(fs) ((fs)->seek)
135 1.31 cgd #define FS_STAT(fs) ((fs)->stat)
136 1.31 cgd
137 1.31 cgd #else
138 1.31 cgd
139 1.31 cgd #define FS_OPEN(fs) ___CONCAT(LIBSA_SINGLE_FILESYSTEM,_open)
140 1.31 cgd #define FS_CLOSE(fs) ___CONCAT(LIBSA_SINGLE_FILESYSTEM,_close)
141 1.31 cgd #define FS_READ(fs) ___CONCAT(LIBSA_SINGLE_FILESYSTEM,_read)
142 1.31 cgd #define FS_WRITE(fs) ___CONCAT(LIBSA_SINGLE_FILESYSTEM,_write)
143 1.31 cgd #define FS_SEEK(fs) ___CONCAT(LIBSA_SINGLE_FILESYSTEM,_seek)
144 1.31 cgd #define FS_STAT(fs) ___CONCAT(LIBSA_SINGLE_FILESYSTEM,_stat)
145 1.31 cgd
146 1.46 dsl FS_DEF(LIBSA_SINGLE_FILESYSTEM);
147 1.31 cgd
148 1.31 cgd #endif
149 1.31 cgd
150 1.1 brezak /* where values for lseek(2) */
151 1.1 brezak #define SEEK_SET 0 /* set file offset to offset */
152 1.1 brezak #define SEEK_CUR 1 /* set file offset to current plus offset */
153 1.1 brezak #define SEEK_END 2 /* set file offset to EOF plus offset */
154 1.1 brezak
155 1.1 brezak /* Device switch */
156 1.31 cgd #if !defined(LIBSA_SINGLE_DEVICE)
157 1.31 cgd
158 1.1 brezak struct devsw {
159 1.1 brezak char *dv_name;
160 1.46 dsl int (*dv_strategy)(void *, int, daddr_t, size_t, void *, size_t *);
161 1.46 dsl int (*dv_open)(struct open_file *, ...);
162 1.46 dsl int (*dv_close)(struct open_file *);
163 1.46 dsl int (*dv_ioctl)(struct open_file *, u_long, void *);
164 1.1 brezak };
165 1.1 brezak
166 1.1 brezak extern struct devsw devsw[]; /* device array */
167 1.1 brezak extern int ndevs; /* number of elements in devsw[] */
168 1.1 brezak
169 1.31 cgd #define DEV_NAME(d) ((d)->dv_name)
170 1.31 cgd #define DEV_STRATEGY(d) ((d)->dv_strategy)
171 1.31 cgd #define DEV_OPEN(d) ((d)->dv_open)
172 1.31 cgd #define DEV_CLOSE(d) ((d)->dv_close)
173 1.31 cgd #define DEV_IOCTL(d) ((d)->dv_ioctl)
174 1.31 cgd
175 1.31 cgd #else
176 1.31 cgd
177 1.31 cgd #define DEV_NAME(d) ___STRING(LIBSA_SINGLE_DEVICE)
178 1.31 cgd #define DEV_STRATEGY(d) ___CONCAT(LIBSA_SINGLE_DEVICE,strategy)
179 1.31 cgd #define DEV_OPEN(d) ___CONCAT(LIBSA_SINGLE_DEVICE,open)
180 1.31 cgd #define DEV_CLOSE(d) ___CONCAT(LIBSA_SINGLE_DEVICE,close)
181 1.31 cgd #define DEV_IOCTL(d) ___CONCAT(LIBSA_SINGLE_DEVICE,ioctl)
182 1.31 cgd
183 1.46 dsl /* These may be #defines which must not be expanded here, hence the extra () */
184 1.46 dsl int (DEV_STRATEGY(unused))(void *, int, daddr_t, size_t, void *, size_t *);
185 1.46 dsl int (DEV_OPEN(unused))(struct open_file *, ...);
186 1.46 dsl int (DEV_CLOSE(unused))(struct open_file *);
187 1.46 dsl int (DEV_IOCTL(unused))(struct open_file *, u_long, void *);
188 1.31 cgd
189 1.31 cgd #endif
190 1.31 cgd
191 1.1 brezak struct open_file {
192 1.1 brezak int f_flags; /* see F_* below */
193 1.31 cgd #if !defined(LIBSA_SINGLE_DEVICE)
194 1.45 mycroft const struct devsw *f_dev; /* pointer to device operations */
195 1.31 cgd #endif
196 1.1 brezak void *f_devdata; /* device specific data */
197 1.31 cgd #if !defined(LIBSA_SINGLE_FILESYSTEM)
198 1.45 mycroft const struct fs_ops *f_ops; /* pointer to file system operations */
199 1.31 cgd #endif
200 1.1 brezak void *f_fsdata; /* file system specific data */
201 1.31 cgd #if !defined(LIBSA_NO_RAW_ACCESS)
202 1.14 pk off_t f_offset; /* current file offset (F_RAW) */
203 1.31 cgd #endif
204 1.1 brezak };
205 1.1 brezak
206 1.1 brezak #define SOPEN_MAX 4
207 1.8 cgd extern struct open_file files[];
208 1.1 brezak
209 1.1 brezak /* f_flags values */
210 1.1 brezak #define F_READ 0x0001 /* file opened for reading */
211 1.1 brezak #define F_WRITE 0x0002 /* file opened for writing */
212 1.31 cgd #if !defined(LIBSA_NO_RAW_ACCESS)
213 1.1 brezak #define F_RAW 0x0004 /* raw device open - no file system */
214 1.31 cgd #endif
215 1.2 brezak #define F_NODEV 0x0008 /* network open - no device */
216 1.1 brezak
217 1.46 dsl int (devopen)(struct open_file *, const char *, char **);
218 1.22 drochner #ifdef HEAP_VARIABLE
219 1.46 dsl void setheap(void *, void *);
220 1.22 drochner #endif
221 1.46 dsl void *alloc(unsigned int);
222 1.46 dsl void free(void *, unsigned int);
223 1.1 brezak struct disklabel;
224 1.46 dsl char *getdisklabel(const char *, struct disklabel *);
225 1.53 christos int dkcksum(const struct disklabel *);
226 1.2 brezak
227 1.46 dsl void printf(const char *, ...);
228 1.46 dsl int sprintf(char *, const char *, ...);
229 1.46 dsl int snprintf(char *, size_t, const char *, ...);
230 1.46 dsl void vprintf(const char *, _BSD_VA_LIST_);
231 1.46 dsl int vsprintf(char *, const char *, _BSD_VA_LIST_);
232 1.46 dsl int vsnprintf(char *, size_t, const char *, _BSD_VA_LIST_);
233 1.46 dsl void twiddle(void);
234 1.46 dsl void gets(char *);
235 1.46 dsl int getfile(char *prompt, int mode);
236 1.46 dsl char *strerror(int);
237 1.46 dsl __dead void exit(int) __attribute__((noreturn));
238 1.46 dsl __dead void panic(const char *, ...) __attribute__((noreturn));
239 1.46 dsl __dead void _rtt(void) __attribute__((noreturn));
240 1.47 dsl void (bcopy)(const void *, void *, size_t);
241 1.46 dsl void *memcpy(void *, const void *, size_t);
242 1.46 dsl void *memmove(void *, const void *, size_t);
243 1.46 dsl int memcmp(const void *, const void *, size_t);
244 1.51 he void *memset(void *, int, size_t);
245 1.46 dsl void exec(char *, char *, int);
246 1.46 dsl int open(const char *, int);
247 1.46 dsl int close(int);
248 1.46 dsl void closeall(void);
249 1.46 dsl ssize_t read(int, void *, size_t);
250 1.46 dsl ssize_t write(int, void *, size_t);
251 1.46 dsl off_t lseek(int, off_t, int);
252 1.46 dsl int ioctl(int, u_long, char *);
253 1.46 dsl int stat(const char *, struct stat *);
254 1.46 dsl int fstat(int, struct stat *);
255 1.34 thorpej
256 1.52 abs typedef int cmp_t __P((const void *, const void *));
257 1.52 abs void qsort(void *, size_t, size_t, cmp_t * cmp);
258 1.52 abs
259 1.32 christos extern int opterr, optind, optopt, optreset;
260 1.32 christos extern char *optarg;
261 1.46 dsl int getopt(int, char * const *, const char *);
262 1.46 dsl
263 1.46 dsl char *getpass(const char *);
264 1.46 dsl int checkpasswd(void);
265 1.48 dsl int check_password(const char *);
266 1.33 drochner
267 1.46 dsl int nodev(void);
268 1.46 dsl int noioctl(struct open_file *, u_long, void *);
269 1.46 dsl void nullsys(void);
270 1.33 drochner
271 1.46 dsl FS_DEF(null);
272 1.2 brezak
273 1.4 brezak /* Machine dependent functions */
274 1.46 dsl void machdep_start(char *, int, char *, char *, char *);
275 1.46 dsl int getchar(void);
276 1.54 perry void putchar(int);
277 1.20 cgd
278 1.20 cgd #ifdef __INTERNAL_LIBSA_CREAD
279 1.46 dsl int oopen(const char *, int);
280 1.46 dsl int oclose(int);
281 1.46 dsl ssize_t oread(int, void *, size_t);
282 1.46 dsl off_t olseek(int, off_t, int);
283 1.20 cgd #endif
284 1.53 christos
285 1.55 christos extern const char hexdigits[];
286 1.55 christos
287 1.53 christos #endif /* _LIBSA_STAND_H_ */
288