stand.h revision 1.32 1 1.32 christos /* $NetBSD: stand.h,v 1.32 1999/04/14 15:23:27 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.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.30 simonb #ifdef LIBSA_USE_MEMSET
79 1.30 simonb #define bzero(s, l) memset(s, 0, l)
80 1.30 simonb #endif
81 1.30 simonb #ifdef LIBSA_USE_MEMCPY
82 1.30 simonb #define bcopy(s, d, l) memcpy(d, s, l) /* For non-overlapping copies only */
83 1.1 brezak #endif
84 1.1 brezak
85 1.1 brezak struct open_file;
86 1.1 brezak
87 1.1 brezak /*
88 1.1 brezak * This structure is used to define file system operations in a file system
89 1.1 brezak * independent way.
90 1.1 brezak */
91 1.31 cgd #if !defined(LIBSA_SINGLE_FILESYSTEM)
92 1.1 brezak struct fs_ops {
93 1.1 brezak int (*open) __P((char *path, struct open_file *f));
94 1.1 brezak int (*close) __P((struct open_file *f));
95 1.11 pk int (*read) __P((struct open_file *f, void *buf,
96 1.10 pk size_t size, size_t *resid));
97 1.11 pk int (*write) __P((struct open_file *f, void *buf,
98 1.10 pk size_t size, size_t *resid));
99 1.1 brezak off_t (*seek) __P((struct open_file *f, off_t offset, int where));
100 1.1 brezak int (*stat) __P((struct open_file *f, struct stat *sb));
101 1.1 brezak };
102 1.1 brezak
103 1.1 brezak extern struct fs_ops file_system[];
104 1.13 leo extern int nfsys;
105 1.1 brezak
106 1.31 cgd #define FS_OPEN(fs) ((fs)->open)
107 1.31 cgd #define FS_CLOSE(fs) ((fs)->close)
108 1.31 cgd #define FS_READ(fs) ((fs)->read)
109 1.31 cgd #define FS_WRITE(fs) ((fs)->write)
110 1.31 cgd #define FS_SEEK(fs) ((fs)->seek)
111 1.31 cgd #define FS_STAT(fs) ((fs)->stat)
112 1.31 cgd
113 1.31 cgd #else
114 1.31 cgd
115 1.31 cgd #define FS_OPEN(fs) ___CONCAT(LIBSA_SINGLE_FILESYSTEM,_open)
116 1.31 cgd #define FS_CLOSE(fs) ___CONCAT(LIBSA_SINGLE_FILESYSTEM,_close)
117 1.31 cgd #define FS_READ(fs) ___CONCAT(LIBSA_SINGLE_FILESYSTEM,_read)
118 1.31 cgd #define FS_WRITE(fs) ___CONCAT(LIBSA_SINGLE_FILESYSTEM,_write)
119 1.31 cgd #define FS_SEEK(fs) ___CONCAT(LIBSA_SINGLE_FILESYSTEM,_seek)
120 1.31 cgd #define FS_STAT(fs) ___CONCAT(LIBSA_SINGLE_FILESYSTEM,_stat)
121 1.31 cgd
122 1.31 cgd int FS_OPEN(unused) __P((char *path, struct open_file *f));
123 1.31 cgd int FS_CLOSE(unused) __P((struct open_file *f));
124 1.31 cgd int FS_READ(unused) __P((struct open_file *f, void *buf,
125 1.31 cgd size_t size, size_t *resid));
126 1.31 cgd int FS_WRITE(unused) __P((struct open_file *f, void *buf,
127 1.31 cgd size_t size, size_t *resid));
128 1.31 cgd off_t FS_SEEK(unused) __P((struct open_file *f, off_t offset, int where));
129 1.31 cgd int FS_STAT(unused) __P((struct open_file *f, struct stat *sb));
130 1.31 cgd
131 1.31 cgd #endif
132 1.31 cgd
133 1.1 brezak /* where values for lseek(2) */
134 1.1 brezak #define SEEK_SET 0 /* set file offset to offset */
135 1.1 brezak #define SEEK_CUR 1 /* set file offset to current plus offset */
136 1.1 brezak #define SEEK_END 2 /* set file offset to EOF plus offset */
137 1.1 brezak
138 1.1 brezak /* Device switch */
139 1.31 cgd #if !defined(LIBSA_SINGLE_DEVICE)
140 1.31 cgd
141 1.1 brezak struct devsw {
142 1.1 brezak char *dv_name;
143 1.1 brezak int (*dv_strategy) __P((void *devdata, int rw,
144 1.10 pk daddr_t blk, size_t size,
145 1.10 pk void *buf, size_t *rsize));
146 1.1 brezak int (*dv_open) __P((struct open_file *f, ...));
147 1.1 brezak int (*dv_close) __P((struct open_file *f));
148 1.6 cgd int (*dv_ioctl) __P((struct open_file *f, u_long cmd, void *data));
149 1.1 brezak };
150 1.1 brezak
151 1.1 brezak extern struct devsw devsw[]; /* device array */
152 1.1 brezak extern int ndevs; /* number of elements in devsw[] */
153 1.1 brezak
154 1.31 cgd #define DEV_NAME(d) ((d)->dv_name)
155 1.31 cgd #define DEV_STRATEGY(d) ((d)->dv_strategy)
156 1.31 cgd #define DEV_OPEN(d) ((d)->dv_open)
157 1.31 cgd #define DEV_CLOSE(d) ((d)->dv_close)
158 1.31 cgd #define DEV_IOCTL(d) ((d)->dv_ioctl)
159 1.31 cgd
160 1.31 cgd #else
161 1.31 cgd
162 1.31 cgd #define DEV_NAME(d) ___STRING(LIBSA_SINGLE_DEVICE)
163 1.31 cgd #define DEV_STRATEGY(d) ___CONCAT(LIBSA_SINGLE_DEVICE,strategy)
164 1.31 cgd #define DEV_OPEN(d) ___CONCAT(LIBSA_SINGLE_DEVICE,open)
165 1.31 cgd #define DEV_CLOSE(d) ___CONCAT(LIBSA_SINGLE_DEVICE,close)
166 1.31 cgd #define DEV_IOCTL(d) ___CONCAT(LIBSA_SINGLE_DEVICE,ioctl)
167 1.31 cgd
168 1.31 cgd int DEV_STRATEGY(unused) __P((void *devdata, int rw, daddr_t blk,
169 1.31 cgd size_t size, void *buf, size_t *rsize));
170 1.31 cgd int DEV_OPEN(unused) __P((struct open_file *f, ...));
171 1.31 cgd int DEV_CLOSE(unused) __P((struct open_file *f));
172 1.31 cgd int DEV_IOCTL(unused) __P((struct open_file *f, u_long cmd, void *data));
173 1.31 cgd
174 1.31 cgd #endif
175 1.31 cgd
176 1.1 brezak struct open_file {
177 1.1 brezak int f_flags; /* see F_* below */
178 1.31 cgd #if !defined(LIBSA_SINGLE_DEVICE)
179 1.1 brezak struct devsw *f_dev; /* pointer to device operations */
180 1.31 cgd #endif
181 1.1 brezak void *f_devdata; /* device specific data */
182 1.31 cgd #if !defined(LIBSA_SINGLE_FILESYSTEM)
183 1.1 brezak struct fs_ops *f_ops; /* pointer to file system operations */
184 1.31 cgd #endif
185 1.1 brezak void *f_fsdata; /* file system specific data */
186 1.31 cgd #if !defined(LIBSA_NO_RAW_ACCESS)
187 1.14 pk off_t f_offset; /* current file offset (F_RAW) */
188 1.31 cgd #endif
189 1.1 brezak };
190 1.1 brezak
191 1.1 brezak #define SOPEN_MAX 4
192 1.8 cgd extern struct open_file files[];
193 1.1 brezak
194 1.1 brezak /* f_flags values */
195 1.1 brezak #define F_READ 0x0001 /* file opened for reading */
196 1.1 brezak #define F_WRITE 0x0002 /* file opened for writing */
197 1.31 cgd #if !defined(LIBSA_NO_RAW_ACCESS)
198 1.1 brezak #define F_RAW 0x0004 /* raw device open - no file system */
199 1.31 cgd #endif
200 1.2 brezak #define F_NODEV 0x0008 /* network open - no device */
201 1.1 brezak
202 1.1 brezak #define isupper(c) ((c) >= 'A' && (c) <= 'Z')
203 1.1 brezak #define tolower(c) ((c) - 'A' + 'a')
204 1.1 brezak #define isspace(c) ((c) == ' ' || (c) == '\t')
205 1.1 brezak #define isdigit(c) ((c) >= '0' && (c) <= '9')
206 1.1 brezak
207 1.10 pk int devopen __P((struct open_file *, const char *, char **));
208 1.22 drochner #ifdef HEAP_VARIABLE
209 1.22 drochner void setheap __P((void *, void *));
210 1.22 drochner #endif
211 1.10 pk void *alloc __P((unsigned int));
212 1.10 pk void free __P((void *, unsigned int));
213 1.1 brezak struct disklabel;
214 1.10 pk char *getdisklabel __P((const char *, struct disklabel *));
215 1.13 leo int dkcksum __P((struct disklabel *));
216 1.2 brezak
217 1.16 christos void printf __P((const char *, ...));
218 1.28 pk int sprintf __P((char *, const char *, ...));
219 1.28 pk int snprintf __P((char *, size_t, const char *, ...));
220 1.18 gwr void vprintf __P((const char *, _BSD_VA_LIST_));
221 1.28 pk int vsprintf __P((char *, const char *, _BSD_VA_LIST_));
222 1.28 pk int vsnprintf __P((char *, size_t, const char *, _BSD_VA_LIST_));
223 1.11 pk void twiddle __P((void));
224 1.4 brezak void gets __P((char *));
225 1.27 pk int getfile __P((char *prompt, int mode));
226 1.21 drochner char *strerror __P((int));
227 1.12 pk __dead void panic __P((const char *, ...)) __attribute__((noreturn));
228 1.13 leo __dead void _rtt __P((void)) __attribute__((noreturn));
229 1.12 pk void bcopy __P((const void *, void *, size_t));
230 1.13 leo void *memcpy __P((void *, const void *, size_t));
231 1.19 cgd int memcmp __P((const void *, const void *, size_t));
232 1.7 mycroft void exec __P((char *, char *, int));
233 1.10 pk int open __P((const char *, int));
234 1.4 brezak int close __P((int));
235 1.13 leo void closeall __P((void));
236 1.10 pk ssize_t read __P((int, void *, size_t));
237 1.24 is ssize_t write __P((int, void *, size_t));
238 1.20 cgd off_t lseek __P((int, off_t, int));
239 1.27 pk int ioctl __P((int, u_long, char *));
240 1.32 christos
241 1.32 christos extern int opterr, optind, optopt, optreset;
242 1.32 christos extern char *optarg;
243 1.32 christos int getopt __P((int, char * const *, const char *));
244 1.4 brezak
245 1.10 pk int nodev __P((void));
246 1.10 pk int noioctl __P((struct open_file *, u_long, void *));
247 1.10 pk void nullsys __P((void));
248 1.2 brezak
249 1.2 brezak int null_open __P((char *path, struct open_file *f));
250 1.2 brezak int null_close __P((struct open_file *f));
251 1.10 pk ssize_t null_read __P((struct open_file *f, void *buf,
252 1.10 pk size_t size, size_t *resid));
253 1.10 pk ssize_t null_write __P((struct open_file *f, void *buf,
254 1.10 pk size_t size, size_t *resid));
255 1.2 brezak off_t null_seek __P((struct open_file *f, off_t offset, int where));
256 1.2 brezak int null_stat __P((struct open_file *f, struct stat *sb));
257 1.2 brezak
258 1.4 brezak /* Machine dependent functions */
259 1.2 brezak void machdep_start __P((char *, int, char *, char *, char *));
260 1.4 brezak int getchar __P((void));
261 1.4 brezak void putchar __P((int));
262 1.20 cgd
263 1.20 cgd #ifdef __INTERNAL_LIBSA_CREAD
264 1.20 cgd int oopen __P((const char *, int));
265 1.20 cgd int oclose __P((int));
266 1.20 cgd ssize_t oread __P((int, void *, size_t));
267 1.20 cgd off_t olseek __P((int, off_t, int));
268 1.20 cgd #endif
269