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