stand.h revision 1.43 1 1.43 tsutsui /* $NetBSD: stand.h,v 1.43 2001/09/02 07:04:16 tsutsui 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.1 brezak * 3. All advertising materials mentioning features or use of this software
46 1.1 brezak * must display the following acknowledgement:
47 1.1 brezak * This product includes software developed by the University of
48 1.1 brezak * California, Berkeley and its contributors.
49 1.1 brezak * 4. Neither the name of the University nor the names of its contributors
50 1.1 brezak * may be used to endorse or promote products derived from this software
51 1.1 brezak * without specific prior written permission.
52 1.1 brezak *
53 1.1 brezak * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
54 1.1 brezak * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
55 1.1 brezak * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
56 1.1 brezak * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
57 1.1 brezak * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
58 1.1 brezak * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
59 1.1 brezak * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
60 1.1 brezak * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
61 1.1 brezak * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
62 1.1 brezak * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
63 1.1 brezak * SUCH DAMAGE.
64 1.1 brezak *
65 1.5 cgd * @(#)stand.h 8.1 (Berkeley) 6/11/93
66 1.1 brezak */
67 1.1 brezak
68 1.1 brezak #include <sys/types.h>
69 1.1 brezak #include <sys/cdefs.h>
70 1.1 brezak #include <sys/stat.h>
71 1.1 brezak #include "saioctl.h"
72 1.1 brezak #include "saerrno.h"
73 1.1 brezak
74 1.1 brezak #ifndef NULL
75 1.1 brezak #define NULL 0
76 1.30 simonb #endif
77 1.30 simonb
78 1.41 takemura #ifdef LIBSA_RENAME_PRINTF
79 1.41 takemura #define getchar libsa_getchar
80 1.41 takemura #define gets libsa_gets
81 1.41 takemura #define printf libsa_printf
82 1.41 takemura #define putchar libsa_putchar
83 1.41 takemura #define sprintf libsa_sprintf
84 1.41 takemura #define vprintf libsa_vprintf
85 1.41 takemura #define vsprintf libsa_vsprintf
86 1.41 takemura #endif
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.1 brezak /*
97 1.1 brezak * This structure is used to define file system operations in a file system
98 1.1 brezak * independent way.
99 1.1 brezak */
100 1.31 cgd #if !defined(LIBSA_SINGLE_FILESYSTEM)
101 1.1 brezak struct fs_ops {
102 1.1 brezak int (*open) __P((char *path, struct open_file *f));
103 1.1 brezak int (*close) __P((struct open_file *f));
104 1.11 pk int (*read) __P((struct open_file *f, void *buf,
105 1.10 pk size_t size, size_t *resid));
106 1.11 pk int (*write) __P((struct open_file *f, void *buf,
107 1.10 pk size_t size, size_t *resid));
108 1.1 brezak off_t (*seek) __P((struct open_file *f, off_t offset, int where));
109 1.1 brezak int (*stat) __P((struct open_file *f, struct stat *sb));
110 1.1 brezak };
111 1.1 brezak
112 1.1 brezak extern struct fs_ops file_system[];
113 1.13 leo extern int nfsys;
114 1.1 brezak
115 1.31 cgd #define FS_OPEN(fs) ((fs)->open)
116 1.31 cgd #define FS_CLOSE(fs) ((fs)->close)
117 1.31 cgd #define FS_READ(fs) ((fs)->read)
118 1.31 cgd #define FS_WRITE(fs) ((fs)->write)
119 1.31 cgd #define FS_SEEK(fs) ((fs)->seek)
120 1.31 cgd #define FS_STAT(fs) ((fs)->stat)
121 1.31 cgd
122 1.31 cgd #else
123 1.31 cgd
124 1.31 cgd #define FS_OPEN(fs) ___CONCAT(LIBSA_SINGLE_FILESYSTEM,_open)
125 1.31 cgd #define FS_CLOSE(fs) ___CONCAT(LIBSA_SINGLE_FILESYSTEM,_close)
126 1.31 cgd #define FS_READ(fs) ___CONCAT(LIBSA_SINGLE_FILESYSTEM,_read)
127 1.31 cgd #define FS_WRITE(fs) ___CONCAT(LIBSA_SINGLE_FILESYSTEM,_write)
128 1.31 cgd #define FS_SEEK(fs) ___CONCAT(LIBSA_SINGLE_FILESYSTEM,_seek)
129 1.31 cgd #define FS_STAT(fs) ___CONCAT(LIBSA_SINGLE_FILESYSTEM,_stat)
130 1.31 cgd
131 1.31 cgd int FS_OPEN(unused) __P((char *path, struct open_file *f));
132 1.31 cgd int FS_CLOSE(unused) __P((struct open_file *f));
133 1.31 cgd int FS_READ(unused) __P((struct open_file *f, void *buf,
134 1.31 cgd size_t size, size_t *resid));
135 1.31 cgd int FS_WRITE(unused) __P((struct open_file *f, void *buf,
136 1.31 cgd size_t size, size_t *resid));
137 1.31 cgd off_t FS_SEEK(unused) __P((struct open_file *f, off_t offset, int where));
138 1.31 cgd int FS_STAT(unused) __P((struct open_file *f, struct stat *sb));
139 1.31 cgd
140 1.31 cgd #endif
141 1.31 cgd
142 1.1 brezak /* where values for lseek(2) */
143 1.1 brezak #define SEEK_SET 0 /* set file offset to offset */
144 1.1 brezak #define SEEK_CUR 1 /* set file offset to current plus offset */
145 1.1 brezak #define SEEK_END 2 /* set file offset to EOF plus offset */
146 1.1 brezak
147 1.1 brezak /* Device switch */
148 1.31 cgd #if !defined(LIBSA_SINGLE_DEVICE)
149 1.31 cgd
150 1.1 brezak struct devsw {
151 1.1 brezak char *dv_name;
152 1.1 brezak int (*dv_strategy) __P((void *devdata, int rw,
153 1.10 pk daddr_t blk, size_t size,
154 1.10 pk void *buf, size_t *rsize));
155 1.1 brezak int (*dv_open) __P((struct open_file *f, ...));
156 1.1 brezak int (*dv_close) __P((struct open_file *f));
157 1.6 cgd int (*dv_ioctl) __P((struct open_file *f, u_long cmd, void *data));
158 1.1 brezak };
159 1.1 brezak
160 1.1 brezak extern struct devsw devsw[]; /* device array */
161 1.1 brezak extern int ndevs; /* number of elements in devsw[] */
162 1.1 brezak
163 1.31 cgd #define DEV_NAME(d) ((d)->dv_name)
164 1.31 cgd #define DEV_STRATEGY(d) ((d)->dv_strategy)
165 1.31 cgd #define DEV_OPEN(d) ((d)->dv_open)
166 1.31 cgd #define DEV_CLOSE(d) ((d)->dv_close)
167 1.31 cgd #define DEV_IOCTL(d) ((d)->dv_ioctl)
168 1.31 cgd
169 1.31 cgd #else
170 1.31 cgd
171 1.31 cgd #define DEV_NAME(d) ___STRING(LIBSA_SINGLE_DEVICE)
172 1.31 cgd #define DEV_STRATEGY(d) ___CONCAT(LIBSA_SINGLE_DEVICE,strategy)
173 1.31 cgd #define DEV_OPEN(d) ___CONCAT(LIBSA_SINGLE_DEVICE,open)
174 1.31 cgd #define DEV_CLOSE(d) ___CONCAT(LIBSA_SINGLE_DEVICE,close)
175 1.31 cgd #define DEV_IOCTL(d) ___CONCAT(LIBSA_SINGLE_DEVICE,ioctl)
176 1.31 cgd
177 1.31 cgd int DEV_STRATEGY(unused) __P((void *devdata, int rw, daddr_t blk,
178 1.31 cgd size_t size, void *buf, size_t *rsize));
179 1.31 cgd int DEV_OPEN(unused) __P((struct open_file *f, ...));
180 1.31 cgd int DEV_CLOSE(unused) __P((struct open_file *f));
181 1.31 cgd int DEV_IOCTL(unused) __P((struct open_file *f, u_long cmd, void *data));
182 1.31 cgd
183 1.31 cgd #endif
184 1.31 cgd
185 1.1 brezak struct open_file {
186 1.1 brezak int f_flags; /* see F_* below */
187 1.31 cgd #if !defined(LIBSA_SINGLE_DEVICE)
188 1.1 brezak struct devsw *f_dev; /* pointer to device operations */
189 1.31 cgd #endif
190 1.1 brezak void *f_devdata; /* device specific data */
191 1.31 cgd #if !defined(LIBSA_SINGLE_FILESYSTEM)
192 1.1 brezak struct fs_ops *f_ops; /* pointer to file system operations */
193 1.31 cgd #endif
194 1.1 brezak void *f_fsdata; /* file system specific data */
195 1.31 cgd #if !defined(LIBSA_NO_RAW_ACCESS)
196 1.14 pk off_t f_offset; /* current file offset (F_RAW) */
197 1.31 cgd #endif
198 1.1 brezak };
199 1.1 brezak
200 1.1 brezak #define SOPEN_MAX 4
201 1.8 cgd extern struct open_file files[];
202 1.1 brezak
203 1.1 brezak /* f_flags values */
204 1.1 brezak #define F_READ 0x0001 /* file opened for reading */
205 1.1 brezak #define F_WRITE 0x0002 /* file opened for writing */
206 1.31 cgd #if !defined(LIBSA_NO_RAW_ACCESS)
207 1.1 brezak #define F_RAW 0x0004 /* raw device open - no file system */
208 1.31 cgd #endif
209 1.2 brezak #define F_NODEV 0x0008 /* network open - no device */
210 1.1 brezak
211 1.10 pk int devopen __P((struct open_file *, const char *, char **));
212 1.22 drochner #ifdef HEAP_VARIABLE
213 1.22 drochner void setheap __P((void *, void *));
214 1.22 drochner #endif
215 1.10 pk void *alloc __P((unsigned int));
216 1.10 pk void free __P((void *, unsigned int));
217 1.1 brezak struct disklabel;
218 1.10 pk char *getdisklabel __P((const char *, struct disklabel *));
219 1.13 leo int dkcksum __P((struct disklabel *));
220 1.2 brezak
221 1.16 christos void printf __P((const char *, ...));
222 1.28 pk int sprintf __P((char *, const char *, ...));
223 1.28 pk int snprintf __P((char *, size_t, const char *, ...));
224 1.18 gwr void vprintf __P((const char *, _BSD_VA_LIST_));
225 1.28 pk int vsprintf __P((char *, const char *, _BSD_VA_LIST_));
226 1.28 pk int vsnprintf __P((char *, size_t, const char *, _BSD_VA_LIST_));
227 1.11 pk void twiddle __P((void));
228 1.4 brezak void gets __P((char *));
229 1.27 pk int getfile __P((char *prompt, int mode));
230 1.21 drochner char *strerror __P((int));
231 1.12 pk __dead void panic __P((const char *, ...)) __attribute__((noreturn));
232 1.13 leo __dead void _rtt __P((void)) __attribute__((noreturn));
233 1.12 pk void bcopy __P((const void *, void *, size_t));
234 1.13 leo void *memcpy __P((void *, const void *, size_t));
235 1.43 tsutsui void *memmove __P((void *, const void *, size_t));
236 1.19 cgd int memcmp __P((const void *, const void *, size_t));
237 1.7 mycroft void exec __P((char *, char *, int));
238 1.10 pk int open __P((const char *, int));
239 1.4 brezak int close __P((int));
240 1.13 leo void closeall __P((void));
241 1.10 pk ssize_t read __P((int, void *, size_t));
242 1.24 is ssize_t write __P((int, void *, size_t));
243 1.20 cgd off_t lseek __P((int, off_t, int));
244 1.27 pk int ioctl __P((int, u_long, char *));
245 1.40 cgd int stat __P((const char *, struct stat *));
246 1.40 cgd int fstat __P((int, struct stat *));
247 1.34 thorpej
248 1.32 christos extern int opterr, optind, optopt, optreset;
249 1.32 christos extern char *optarg;
250 1.32 christos int getopt __P((int, char * const *, const char *));
251 1.33 drochner
252 1.33 drochner char *getpass __P((const char *));
253 1.33 drochner int checkpasswd __P((void));
254 1.33 drochner
255 1.10 pk int nodev __P((void));
256 1.10 pk int noioctl __P((struct open_file *, u_long, void *));
257 1.10 pk void nullsys __P((void));
258 1.2 brezak
259 1.2 brezak int null_open __P((char *path, struct open_file *f));
260 1.2 brezak int null_close __P((struct open_file *f));
261 1.10 pk ssize_t null_read __P((struct open_file *f, void *buf,
262 1.10 pk size_t size, size_t *resid));
263 1.10 pk ssize_t null_write __P((struct open_file *f, void *buf,
264 1.10 pk size_t size, size_t *resid));
265 1.2 brezak off_t null_seek __P((struct open_file *f, off_t offset, int where));
266 1.2 brezak int null_stat __P((struct open_file *f, struct stat *sb));
267 1.2 brezak
268 1.4 brezak /* Machine dependent functions */
269 1.2 brezak void machdep_start __P((char *, int, char *, char *, char *));
270 1.4 brezak int getchar __P((void));
271 1.4 brezak void putchar __P((int));
272 1.20 cgd
273 1.20 cgd #ifdef __INTERNAL_LIBSA_CREAD
274 1.20 cgd int oopen __P((const char *, int));
275 1.20 cgd int oclose __P((int));
276 1.20 cgd ssize_t oread __P((int, void *, size_t));
277 1.20 cgd off_t olseek __P((int, off_t, int));
278 1.20 cgd #endif
279