stand.h revision 1.30 1 /* $NetBSD: stand.h,v 1.30 1999/02/22 10:08:42 simonb Exp $ */
2
3 /*-
4 * Copyright (c) 1993
5 * The Regents of the University of California. All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. All advertising materials mentioning features or use of this software
16 * must display the following acknowledgement:
17 * This product includes software developed by the University of
18 * California, Berkeley and its contributors.
19 * 4. Neither the name of the University nor the names of its contributors
20 * may be used to endorse or promote products derived from this software
21 * without specific prior written permission.
22 *
23 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 * SUCH DAMAGE.
34 *
35 * @(#)stand.h 8.1 (Berkeley) 6/11/93
36 */
37
38 #include <sys/types.h>
39 #include <sys/cdefs.h>
40 #include <sys/stat.h>
41 #include "saioctl.h"
42 #include "saerrno.h"
43
44 #ifndef NULL
45 #define NULL 0
46 #endif
47
48 #ifdef LIBSA_USE_MEMSET
49 #define bzero(s, l) memset(s, 0, l)
50 #endif
51 #ifdef LIBSA_USE_MEMCPY
52 #define bcopy(s, d, l) memcpy(d, s, l) /* For non-overlapping copies only */
53 #endif
54
55 struct open_file;
56
57 /*
58 * This structure is used to define file system operations in a file system
59 * independent way.
60 */
61 struct fs_ops {
62 int (*open) __P((char *path, struct open_file *f));
63 int (*close) __P((struct open_file *f));
64 int (*read) __P((struct open_file *f, void *buf,
65 size_t size, size_t *resid));
66 int (*write) __P((struct open_file *f, void *buf,
67 size_t size, size_t *resid));
68 off_t (*seek) __P((struct open_file *f, off_t offset, int where));
69 int (*stat) __P((struct open_file *f, struct stat *sb));
70 };
71
72 extern struct fs_ops file_system[];
73 extern int nfsys;
74
75 /* where values for lseek(2) */
76 #define SEEK_SET 0 /* set file offset to offset */
77 #define SEEK_CUR 1 /* set file offset to current plus offset */
78 #define SEEK_END 2 /* set file offset to EOF plus offset */
79
80 /* Device switch */
81 struct devsw {
82 char *dv_name;
83 int (*dv_strategy) __P((void *devdata, int rw,
84 daddr_t blk, size_t size,
85 void *buf, size_t *rsize));
86 int (*dv_open) __P((struct open_file *f, ...));
87 int (*dv_close) __P((struct open_file *f));
88 int (*dv_ioctl) __P((struct open_file *f, u_long cmd, void *data));
89 };
90
91 extern struct devsw devsw[]; /* device array */
92 extern int ndevs; /* number of elements in devsw[] */
93
94 struct open_file {
95 int f_flags; /* see F_* below */
96 struct devsw *f_dev; /* pointer to device operations */
97 void *f_devdata; /* device specific data */
98 struct fs_ops *f_ops; /* pointer to file system operations */
99 void *f_fsdata; /* file system specific data */
100 off_t f_offset; /* current file offset (F_RAW) */
101 };
102
103 #define SOPEN_MAX 4
104 extern struct open_file files[];
105
106 /* f_flags values */
107 #define F_READ 0x0001 /* file opened for reading */
108 #define F_WRITE 0x0002 /* file opened for writing */
109 #define F_RAW 0x0004 /* raw device open - no file system */
110 #define F_NODEV 0x0008 /* network open - no device */
111
112 #define isupper(c) ((c) >= 'A' && (c) <= 'Z')
113 #define tolower(c) ((c) - 'A' + 'a')
114 #define isspace(c) ((c) == ' ' || (c) == '\t')
115 #define isdigit(c) ((c) >= '0' && (c) <= '9')
116
117 int devopen __P((struct open_file *, const char *, char **));
118 #ifdef HEAP_VARIABLE
119 void setheap __P((void *, void *));
120 #endif
121 void *alloc __P((unsigned int));
122 void free __P((void *, unsigned int));
123 struct disklabel;
124 char *getdisklabel __P((const char *, struct disklabel *));
125 int dkcksum __P((struct disklabel *));
126
127 void printf __P((const char *, ...));
128 int sprintf __P((char *, const char *, ...));
129 int snprintf __P((char *, size_t, const char *, ...));
130 void vprintf __P((const char *, _BSD_VA_LIST_));
131 int vsprintf __P((char *, const char *, _BSD_VA_LIST_));
132 int vsnprintf __P((char *, size_t, const char *, _BSD_VA_LIST_));
133 void twiddle __P((void));
134 void gets __P((char *));
135 int getfile __P((char *prompt, int mode));
136 char *strerror __P((int));
137 __dead void panic __P((const char *, ...)) __attribute__((noreturn));
138 __dead void _rtt __P((void)) __attribute__((noreturn));
139 void bcopy __P((const void *, void *, size_t));
140 void *memcpy __P((void *, const void *, size_t));
141 int memcmp __P((const void *, const void *, size_t));
142 void exec __P((char *, char *, int));
143 int open __P((const char *, int));
144 int close __P((int));
145 void closeall __P((void));
146 ssize_t read __P((int, void *, size_t));
147 ssize_t write __P((int, void *, size_t));
148 off_t lseek __P((int, off_t, int));
149 int ioctl __P((int, u_long, char *));
150
151 int nodev __P((void));
152 int noioctl __P((struct open_file *, u_long, void *));
153 void nullsys __P((void));
154
155 int null_open __P((char *path, struct open_file *f));
156 int null_close __P((struct open_file *f));
157 ssize_t null_read __P((struct open_file *f, void *buf,
158 size_t size, size_t *resid));
159 ssize_t null_write __P((struct open_file *f, void *buf,
160 size_t size, size_t *resid));
161 off_t null_seek __P((struct open_file *f, off_t offset, int where));
162 int null_stat __P((struct open_file *f, struct stat *sb));
163
164 /* Machine dependent functions */
165 void machdep_start __P((char *, int, char *, char *, char *));
166 int getchar __P((void));
167 void putchar __P((int));
168
169 #ifdef __INTERNAL_LIBSA_CREAD
170 int oopen __P((const char *, int));
171 int oclose __P((int));
172 ssize_t oread __P((int, void *, size_t));
173 off_t olseek __P((int, off_t, int));
174 #endif
175