Home | History | Annotate | Line # | Download | only in libsa
stand.h revision 1.32
      1 /*	$NetBSD: stand.h,v 1.32 1999/04/14 15:23:27 christos Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 1999 Christopher G. Demetriou.  All rights reserved.
      5  *
      6  * Redistribution and use in source and binary forms, with or without
      7  * modification, are permitted provided that the following conditions
      8  * are met:
      9  * 1. Redistributions of source code must retain the above copyright
     10  *    notice, this list of conditions and the following disclaimer.
     11  * 2. Redistributions in binary form must reproduce the above copyright
     12  *    notice, this list of conditions and the following disclaimer in the
     13  *    documentation and/or other materials provided with the distribution.
     14  * 3. All advertising materials mentioning features or use of this software
     15  *    must display the following acknowledgement:
     16  *      This product includes software developed by Christopher G. Demetriou
     17  *	for the NetBSD Project.
     18  * 4. The name of the author may not be used to endorse or promote products
     19  *    derived from this software without specific prior written permission
     20  *
     21  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     22  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     23  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     24  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     25  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     26  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     27  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     28  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     29  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     30  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     31  */
     32 
     33 /*-
     34  * Copyright (c) 1993
     35  *	The Regents of the University of California.  All rights reserved.
     36  *
     37  * Redistribution and use in source and binary forms, with or without
     38  * modification, are permitted provided that the following conditions
     39  * are met:
     40  * 1. Redistributions of source code must retain the above copyright
     41  *    notice, this list of conditions and the following disclaimer.
     42  * 2. Redistributions in binary form must reproduce the above copyright
     43  *    notice, this list of conditions and the following disclaimer in the
     44  *    documentation and/or other materials provided with the distribution.
     45  * 3. All advertising materials mentioning features or use of this software
     46  *    must display the following acknowledgement:
     47  *	This product includes software developed by the University of
     48  *	California, Berkeley and its contributors.
     49  * 4. Neither the name of the University nor the names of its contributors
     50  *    may be used to endorse or promote products derived from this software
     51  *    without specific prior written permission.
     52  *
     53  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     54  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     55  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     56  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     57  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     58  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     59  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     60  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     61  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     62  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     63  * SUCH DAMAGE.
     64  *
     65  *	@(#)stand.h	8.1 (Berkeley) 6/11/93
     66  */
     67 
     68 #include <sys/types.h>
     69 #include <sys/cdefs.h>
     70 #include <sys/stat.h>
     71 #include "saioctl.h"
     72 #include "saerrno.h"
     73 
     74 #ifndef NULL
     75 #define	NULL	0
     76 #endif
     77 
     78 #ifdef LIBSA_USE_MEMSET
     79 #define	bzero(s, l)	memset(s, 0, l)
     80 #endif
     81 #ifdef LIBSA_USE_MEMCPY
     82 #define	bcopy(s, d, l)	memcpy(d, s, l)	/* For non-overlapping copies only */
     83 #endif
     84 
     85 struct open_file;
     86 
     87 /*
     88  * This structure is used to define file system operations in a file system
     89  * independent way.
     90  */
     91 #if !defined(LIBSA_SINGLE_FILESYSTEM)
     92 struct fs_ops {
     93 	int	(*open) __P((char *path, struct open_file *f));
     94 	int	(*close) __P((struct open_file *f));
     95 	int	(*read) __P((struct open_file *f, void *buf,
     96 			     size_t size, size_t *resid));
     97 	int	(*write) __P((struct open_file *f, void *buf,
     98 			     size_t size, size_t *resid));
     99 	off_t	(*seek) __P((struct open_file *f, off_t offset, int where));
    100 	int	(*stat) __P((struct open_file *f, struct stat *sb));
    101 };
    102 
    103 extern struct fs_ops file_system[];
    104 extern int nfsys;
    105 
    106 #define	FS_OPEN(fs)		((fs)->open)
    107 #define	FS_CLOSE(fs)		((fs)->close)
    108 #define	FS_READ(fs)		((fs)->read)
    109 #define	FS_WRITE(fs)		((fs)->write)
    110 #define	FS_SEEK(fs)		((fs)->seek)
    111 #define	FS_STAT(fs)		((fs)->stat)
    112 
    113 #else
    114 
    115 #define	FS_OPEN(fs)		___CONCAT(LIBSA_SINGLE_FILESYSTEM,_open)
    116 #define	FS_CLOSE(fs)		___CONCAT(LIBSA_SINGLE_FILESYSTEM,_close)
    117 #define	FS_READ(fs)		___CONCAT(LIBSA_SINGLE_FILESYSTEM,_read)
    118 #define	FS_WRITE(fs)		___CONCAT(LIBSA_SINGLE_FILESYSTEM,_write)
    119 #define	FS_SEEK(fs)		___CONCAT(LIBSA_SINGLE_FILESYSTEM,_seek)
    120 #define	FS_STAT(fs)		___CONCAT(LIBSA_SINGLE_FILESYSTEM,_stat)
    121 
    122 int	FS_OPEN(unused) __P((char *path, struct open_file *f));
    123 int	FS_CLOSE(unused) __P((struct open_file *f));
    124 int	FS_READ(unused) __P((struct open_file *f, void *buf,
    125 			     size_t size, size_t *resid));
    126 int	FS_WRITE(unused) __P((struct open_file *f, void *buf,
    127 			      size_t size, size_t *resid));
    128 off_t	FS_SEEK(unused) __P((struct open_file *f, off_t offset, int where));
    129 int	FS_STAT(unused) __P((struct open_file *f, struct stat *sb));
    130 
    131 #endif
    132 
    133 /* where values for lseek(2) */
    134 #define	SEEK_SET	0	/* set file offset to offset */
    135 #define	SEEK_CUR	1	/* set file offset to current plus offset */
    136 #define	SEEK_END	2	/* set file offset to EOF plus offset */
    137 
    138 /* Device switch */
    139 #if !defined(LIBSA_SINGLE_DEVICE)
    140 
    141 struct devsw {
    142 	char	*dv_name;
    143 	int	(*dv_strategy) __P((void *devdata, int rw,
    144 				    daddr_t blk, size_t size,
    145 				    void *buf, size_t *rsize));
    146 	int	(*dv_open) __P((struct open_file *f, ...));
    147 	int	(*dv_close) __P((struct open_file *f));
    148 	int	(*dv_ioctl) __P((struct open_file *f, u_long cmd, void *data));
    149 };
    150 
    151 extern struct devsw devsw[];	/* device array */
    152 extern int ndevs;		/* number of elements in devsw[] */
    153 
    154 #define	DEV_NAME(d)		((d)->dv_name)
    155 #define	DEV_STRATEGY(d)		((d)->dv_strategy)
    156 #define	DEV_OPEN(d)		((d)->dv_open)
    157 #define	DEV_CLOSE(d)		((d)->dv_close)
    158 #define	DEV_IOCTL(d)		((d)->dv_ioctl)
    159 
    160 #else
    161 
    162 #define	DEV_NAME(d)		___STRING(LIBSA_SINGLE_DEVICE)
    163 #define	DEV_STRATEGY(d)		___CONCAT(LIBSA_SINGLE_DEVICE,strategy)
    164 #define	DEV_OPEN(d)		___CONCAT(LIBSA_SINGLE_DEVICE,open)
    165 #define	DEV_CLOSE(d)		___CONCAT(LIBSA_SINGLE_DEVICE,close)
    166 #define	DEV_IOCTL(d)		___CONCAT(LIBSA_SINGLE_DEVICE,ioctl)
    167 
    168 int	DEV_STRATEGY(unused) __P((void *devdata, int rw, daddr_t blk,
    169 				  size_t size, void *buf, size_t *rsize));
    170 int	DEV_OPEN(unused) __P((struct open_file *f, ...));
    171 int	DEV_CLOSE(unused) __P((struct open_file *f));
    172 int	DEV_IOCTL(unused) __P((struct open_file *f, u_long cmd, void *data));
    173 
    174 #endif
    175 
    176 struct open_file {
    177 	int		f_flags;	/* see F_* below */
    178 #if !defined(LIBSA_SINGLE_DEVICE)
    179 	struct devsw	*f_dev;		/* pointer to device operations */
    180 #endif
    181 	void		*f_devdata;	/* device specific data */
    182 #if !defined(LIBSA_SINGLE_FILESYSTEM)
    183 	struct fs_ops	*f_ops;		/* pointer to file system operations */
    184 #endif
    185 	void		*f_fsdata;	/* file system specific data */
    186 #if !defined(LIBSA_NO_RAW_ACCESS)
    187 	off_t		f_offset;	/* current file offset (F_RAW) */
    188 #endif
    189 };
    190 
    191 #define	SOPEN_MAX	4
    192 extern struct open_file files[];
    193 
    194 /* f_flags values */
    195 #define	F_READ		0x0001	/* file opened for reading */
    196 #define	F_WRITE		0x0002	/* file opened for writing */
    197 #if !defined(LIBSA_NO_RAW_ACCESS)
    198 #define	F_RAW		0x0004	/* raw device open - no file system */
    199 #endif
    200 #define F_NODEV		0x0008	/* network open - no device */
    201 
    202 #define isupper(c)	((c) >= 'A' && (c) <= 'Z')
    203 #define tolower(c)	((c) - 'A' + 'a')
    204 #define isspace(c)	((c) == ' ' || (c) == '\t')
    205 #define isdigit(c)	((c) >= '0' && (c) <= '9')
    206 
    207 int	devopen __P((struct open_file *, const char *, char **));
    208 #ifdef HEAP_VARIABLE
    209 void	setheap __P((void *, void *));
    210 #endif
    211 void	*alloc __P((unsigned int));
    212 void	free __P((void *, unsigned int));
    213 struct	disklabel;
    214 char	*getdisklabel __P((const char *, struct disklabel *));
    215 int	dkcksum __P((struct disklabel *));
    216 
    217 void	printf __P((const char *, ...));
    218 int	sprintf __P((char *, const char *, ...));
    219 int	snprintf __P((char *, size_t, const char *, ...));
    220 void	vprintf __P((const char *, _BSD_VA_LIST_));
    221 int	vsprintf __P((char *, const char *, _BSD_VA_LIST_));
    222 int	vsnprintf __P((char *, size_t, const char *, _BSD_VA_LIST_));
    223 void	twiddle __P((void));
    224 void	gets __P((char *));
    225 int	getfile __P((char *prompt, int mode));
    226 char	*strerror __P((int));
    227 __dead void	panic __P((const char *, ...)) __attribute__((noreturn));
    228 __dead void	_rtt __P((void)) __attribute__((noreturn));
    229 void	bcopy __P((const void *, void *, size_t));
    230 void	*memcpy __P((void *, const void *, size_t));
    231 int	memcmp __P((const void *, const void *, size_t));
    232 void	exec __P((char *, char *, int));
    233 int	open __P((const char *, int));
    234 int	close __P((int));
    235 void	closeall __P((void));
    236 ssize_t	read __P((int, void *, size_t));
    237 ssize_t	write __P((int, void *, size_t));
    238 off_t	lseek __P((int, off_t, int));
    239 int	ioctl __P((int, u_long, char *));
    240 
    241 extern int opterr, optind, optopt, optreset;
    242 extern char *optarg;
    243 int	getopt __P((int, char * const *, const char *));
    244 
    245 int	nodev __P((void));
    246 int	noioctl __P((struct open_file *, u_long, void *));
    247 void	nullsys __P((void));
    248 
    249 int	null_open __P((char *path, struct open_file *f));
    250 int	null_close __P((struct open_file *f));
    251 ssize_t	null_read __P((struct open_file *f, void *buf,
    252 			size_t size, size_t *resid));
    253 ssize_t	null_write __P((struct open_file *f, void *buf,
    254 			size_t size, size_t *resid));
    255 off_t	null_seek __P((struct open_file *f, off_t offset, int where));
    256 int	null_stat __P((struct open_file *f, struct stat *sb));
    257 
    258 /* Machine dependent functions */
    259 void	machdep_start __P((char *, int, char *, char *, char *));
    260 int	getchar __P((void));
    261 void	putchar __P((int));
    262 
    263 #ifdef __INTERNAL_LIBSA_CREAD
    264 int	oopen __P((const char *, int));
    265 int	oclose __P((int));
    266 ssize_t	oread __P((int, void *, size_t));
    267 off_t	olseek __P((int, off_t, int));
    268 #endif
    269