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