Home | History | Annotate | Line # | Download | only in libsa
stand.h revision 1.73
      1 /*	$NetBSD: stand.h,v 1.73 2011/07/17 20:54:52 joerg 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. Neither the name of the University nor the names of its contributors
     46  *    may be used to endorse or promote products derived from this software
     47  *    without specific prior written permission.
     48  *
     49  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     50  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     51  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     52  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     53  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     54  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     55  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     56  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     57  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     58  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     59  * SUCH DAMAGE.
     60  *
     61  *	@(#)stand.h	8.1 (Berkeley) 6/11/93
     62  */
     63 
     64 #ifndef _LIBSA_STAND_H_
     65 #define	_LIBSA_STAND_H_
     66 
     67 #include <sys/types.h>
     68 #include <sys/cdefs.h>
     69 #include <sys/stat.h>
     70 #include <sys/stdarg.h>
     71 #include "saioctl.h"
     72 #include "saerrno.h"
     73 
     74 #ifndef NULL
     75 #define	NULL	0
     76 #endif
     77 
     78 #ifdef LIBSA_RENAME_PRINTF
     79 #define getchar		libsa_getchar
     80 #define gets		libsa_gets
     81 #define printf		libsa_printf
     82 #define putchar		libsa_putchar
     83 #define sprintf		libsa_sprintf
     84 #define vprintf		libsa_vprintf
     85 #define vsprintf	libsa_vsprintf
     86 #endif
     87 
     88 struct open_file;
     89 
     90 #define FS_DEF(fs) \
     91 	extern __compactcall int	__CONCAT(fs,_open)(const char *, struct open_file *); \
     92 	extern __compactcall int	__CONCAT(fs,_close)(struct open_file *); \
     93 	extern __compactcall int	__CONCAT(fs,_read)(struct open_file *, void *, \
     94 						size_t, size_t *); \
     95 	extern __compactcall int	__CONCAT(fs,_write)(struct open_file *, void *, \
     96 						size_t, size_t *); \
     97 	extern __compactcall off_t	__CONCAT(fs,_seek)(struct open_file *, off_t, int); \
     98 	extern __compactcall int	__CONCAT(fs,_stat)(struct open_file *, struct stat *)
     99 
    100 /*
    101  * This structure is used to define file system operations in a file system
    102  * independent way.
    103  */
    104 extern char *fsmod;
    105 extern char *fsmod2;
    106 
    107 #if !defined(LIBSA_SINGLE_FILESYSTEM)
    108 struct fs_ops {
    109 	__compactcall int	(*open)(const char *, struct open_file *);
    110 	__compactcall int	(*close)(struct open_file *);
    111 	__compactcall int	(*read)(struct open_file *, void *, size_t, size_t *);
    112 	__compactcall int	(*write)(struct open_file *, void *, size_t size, size_t *);
    113 	__compactcall off_t	(*seek)(struct open_file *, off_t, int);
    114 	__compactcall int	(*stat)(struct open_file *, struct stat *);
    115 };
    116 
    117 extern struct fs_ops file_system[];
    118 extern int nfsys;
    119 
    120 #define FS_OPS(fs) { \
    121 	__CONCAT(fs,_open), \
    122 	__CONCAT(fs,_close), \
    123 	__CONCAT(fs,_read), \
    124 	__CONCAT(fs,_write), \
    125 	__CONCAT(fs,_seek), \
    126 	__CONCAT(fs,_stat) }
    127 
    128 #define	FS_OPEN(fs)		((fs)->open)
    129 #define	FS_CLOSE(fs)		((fs)->close)
    130 #define	FS_READ(fs)		((fs)->read)
    131 #define	FS_WRITE(fs)		((fs)->write)
    132 #define	FS_SEEK(fs)		((fs)->seek)
    133 #define	FS_STAT(fs)		((fs)->stat)
    134 
    135 #else
    136 
    137 #define	FS_OPEN(fs)		___CONCAT(LIBSA_SINGLE_FILESYSTEM,_open)
    138 #define	FS_CLOSE(fs)		___CONCAT(LIBSA_SINGLE_FILESYSTEM,_close)
    139 #define	FS_READ(fs)		___CONCAT(LIBSA_SINGLE_FILESYSTEM,_read)
    140 #define	FS_WRITE(fs)		___CONCAT(LIBSA_SINGLE_FILESYSTEM,_write)
    141 #define	FS_SEEK(fs)		___CONCAT(LIBSA_SINGLE_FILESYSTEM,_seek)
    142 #define	FS_STAT(fs)		___CONCAT(LIBSA_SINGLE_FILESYSTEM,_stat)
    143 
    144 FS_DEF(LIBSA_SINGLE_FILESYSTEM);
    145 
    146 #endif
    147 
    148 /* where values for lseek(2) */
    149 #define	SEEK_SET	0	/* set file offset to offset */
    150 #define	SEEK_CUR	1	/* set file offset to current plus offset */
    151 #define	SEEK_END	2	/* set file offset to EOF plus offset */
    152 
    153 /* Device switch */
    154 #if !defined(LIBSA_SINGLE_DEVICE)
    155 
    156 struct devsw {
    157 	char	*dv_name;
    158 	int	(*dv_strategy)(void *, int, daddr_t, size_t, void *, size_t *);
    159 	int	(*dv_open)(struct open_file *, ...);
    160 	int	(*dv_close)(struct open_file *);
    161 	int	(*dv_ioctl)(struct open_file *, u_long, void *);
    162 };
    163 
    164 extern struct devsw devsw[];	/* device array */
    165 extern int ndevs;		/* number of elements in devsw[] */
    166 
    167 #define	DEV_NAME(d)		((d)->dv_name)
    168 #define	DEV_STRATEGY(d)		((d)->dv_strategy)
    169 #define	DEV_OPEN(d)		((d)->dv_open)
    170 #define	DEV_CLOSE(d)		((d)->dv_close)
    171 #define	DEV_IOCTL(d)		((d)->dv_ioctl)
    172 
    173 #else
    174 
    175 #define	DEV_NAME(d)		___STRING(LIBSA_SINGLE_DEVICE)
    176 #define	DEV_STRATEGY(d)		___CONCAT(LIBSA_SINGLE_DEVICE,strategy)
    177 #define	DEV_OPEN(d)		___CONCAT(LIBSA_SINGLE_DEVICE,open)
    178 #define	DEV_CLOSE(d)		___CONCAT(LIBSA_SINGLE_DEVICE,close)
    179 #define	DEV_IOCTL(d)		___CONCAT(LIBSA_SINGLE_DEVICE,ioctl)
    180 
    181 /* These may be #defines which must not be expanded here, hence the extra () */
    182 int	(DEV_STRATEGY(unused))(void *, int, daddr_t, size_t, void *, size_t *);
    183 int	(DEV_OPEN(unused))(struct open_file *, ...);
    184 int	(DEV_CLOSE(unused))(struct open_file *);
    185 int	(DEV_IOCTL(unused))(struct open_file *, u_long, void *);
    186 
    187 #endif
    188 
    189 struct open_file {
    190 	int		f_flags;	/* see F_* below */
    191 #if !defined(LIBSA_SINGLE_DEVICE)
    192 	const struct devsw	*f_dev;	/* pointer to device operations */
    193 #endif
    194 	void		*f_devdata;	/* device specific data */
    195 #if !defined(LIBSA_SINGLE_FILESYSTEM)
    196 	const struct fs_ops	*f_ops;	/* pointer to file system operations */
    197 #endif
    198 	void		*f_fsdata;	/* file system specific data */
    199 #if !defined(LIBSA_NO_RAW_ACCESS)
    200 	off_t		f_offset;	/* current file offset (F_RAW) */
    201 #endif
    202 };
    203 
    204 #define	SOPEN_MAX	4
    205 extern struct open_file files[];
    206 
    207 /* f_flags values */
    208 #define	F_READ		0x0001	/* file opened for reading */
    209 #define	F_WRITE		0x0002	/* file opened for writing */
    210 #if !defined(LIBSA_NO_RAW_ACCESS)
    211 #define	F_RAW		0x0004	/* raw device open - no file system */
    212 #endif
    213 #define F_NODEV		0x0008	/* network open - no device */
    214 
    215 int	(devopen)(struct open_file *, const char *, char **);
    216 #ifdef HEAP_VARIABLE
    217 void	setheap(void *, void *);
    218 #endif
    219 void	*alloc(size_t) __compactcall;
    220 void	dealloc(void *, size_t) __compactcall;
    221 struct	disklabel;
    222 char	*getdisklabel(const char *, struct disklabel *);
    223 int	dkcksum(const struct disklabel *);
    224 
    225 void	printf(const char *, ...)
    226     __attribute__((__format__(__printf__, 1, 2)));
    227 int	sprintf(char *, const char *, ...)
    228     __attribute__((__format__(__printf__, 2, 3)));
    229 int	snprintf(char *, size_t, const char *, ...)
    230     __attribute__((__format__(__printf__, 3, 4)));
    231 void	vprintf(const char *, va_list)
    232     __attribute__((__format__(__printf__, 1, 0)));
    233 int	vsprintf(char *, const char *, va_list)
    234     __attribute__((__format__(__printf__, 2, 0)));
    235 int	vsnprintf(char *, size_t, const char *, va_list)
    236     __attribute__((__format__(__printf__, 3, 0)));
    237 void	twiddle(void);
    238 void	gets(char *);
    239 int	getfile(char *prompt, int mode);
    240 char	*strerror(int);
    241 __dead void	exit(int);
    242 __dead void	panic(const char *, ...)
    243     __attribute__((__format__(__printf__, 1, 2)));
    244 __dead void	_rtt(void);
    245 void	*memcpy(void *, const void *, size_t);
    246 void	*memmove(void *, const void *, size_t);
    247 int	memcmp(const void *, const void *, size_t);
    248 void	*memset(void *, int, size_t);
    249 void	exec(char *, char *, int);
    250 int	open(const char *, int);
    251 int	close(int);
    252 void	closeall(void);
    253 ssize_t	read(int, void *, size_t);
    254 ssize_t	write(int, const void *, size_t);
    255 off_t	lseek(int, off_t, int);
    256 int	ioctl(int, u_long, char *);
    257 int	stat(const char *, struct stat *);
    258 int	fstat(int, struct stat *);
    259 
    260 typedef int cmp_t(const void *, const void *);
    261 void	qsort(void *, size_t, size_t, cmp_t *);
    262 
    263 extern int opterr, optind, optopt, optreset;
    264 extern char *optarg;
    265 int	getopt(int, char * const *, const char *);
    266 
    267 char	*getpass(const char *);
    268 int	checkpasswd(void);
    269 int	check_password(const char *);
    270 
    271 int	nodev(void);
    272 int	noioctl(struct open_file *, u_long, void *);
    273 void	nullsys(void);
    274 
    275 FS_DEF(null);
    276 
    277 /* Machine dependent functions */
    278 void	machdep_start(char *, int, char *, char *, char *);
    279 int	getchar(void);
    280 void	putchar(int);
    281 
    282 #ifdef __INTERNAL_LIBSA_CREAD
    283 int	oopen(const char *, int);
    284 int	oclose(int);
    285 ssize_t	oread(int, void *, size_t);
    286 off_t	olseek(int, off_t, int);
    287 #endif
    288 
    289 extern const char hexdigits[];
    290 
    291 /* XXX: These should be removed eventually. */
    292 void	bcopy(const void *, void *, size_t);
    293 void	bzero(void *, size_t);
    294 
    295 #endif /* _LIBSA_STAND_H_ */
    296