Home | History | Annotate | Line # | Download | only in libsa
stand.h revision 1.79
      1 /*	$NetBSD: stand.h,v 1.79 2014/08/10 07:40:49 isaki 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 vprintf		libsa_vprintf
     84 #endif
     85 
     86 struct open_file;
     87 
     88 #define FS_DEF_BASE(fs) \
     89 	extern __compactcall int	__CONCAT(fs,_open)(const char *, struct open_file *); \
     90 	extern __compactcall int	__CONCAT(fs,_close)(struct open_file *); \
     91 	extern __compactcall int	__CONCAT(fs,_read)(struct open_file *, void *, \
     92 						size_t, size_t *); \
     93 	extern __compactcall int	__CONCAT(fs,_write)(struct open_file *, void *, \
     94 						size_t, size_t *); \
     95 	extern __compactcall off_t	__CONCAT(fs,_seek)(struct open_file *, off_t, int); \
     96 	extern __compactcall int	__CONCAT(fs,_stat)(struct open_file *, struct stat *)
     97 
     98 #if defined(LIBSA_ENABLE_LS_OP)
     99 #define FS_DEF(fs) \
    100 	FS_DEF_BASE(fs);\
    101 	extern __compactcall void	__CONCAT(fs,_ls)(struct open_file *, const char *)
    102 #else
    103 #define FS_DEF(fs) FS_DEF_BASE(fs)
    104 #endif
    105 
    106 
    107 /*
    108  * This structure is used to define file system operations in a file system
    109  * independent way.
    110  */
    111 extern const char *fsmod;
    112 
    113 #if !defined(LIBSA_SINGLE_FILESYSTEM)
    114 struct fs_ops {
    115 	__compactcall int	(*open)(const char *, struct open_file *);
    116 	__compactcall int	(*close)(struct open_file *);
    117 	__compactcall int	(*read)(struct open_file *, void *, size_t, size_t *);
    118 	__compactcall int	(*write)(struct open_file *, void *, size_t size, size_t *);
    119 	__compactcall off_t	(*seek)(struct open_file *, off_t, int);
    120 	__compactcall int	(*stat)(struct open_file *, struct stat *);
    121 #if defined(LIBSA_ENABLE_LS_OP)
    122 	__compactcall void	(*ls)(struct open_file *, const char *);
    123 #endif
    124 };
    125 
    126 extern struct fs_ops file_system[];
    127 extern int nfsys;
    128 
    129 #if defined(LIBSA_ENABLE_LS_OP)
    130 #define FS_OPS(fs) { \
    131 	__CONCAT(fs,_open), \
    132 	__CONCAT(fs,_close), \
    133 	__CONCAT(fs,_read), \
    134 	__CONCAT(fs,_write), \
    135 	__CONCAT(fs,_seek), \
    136 	__CONCAT(fs,_stat), \
    137 	__CONCAT(fs,_ls) }
    138 #else
    139 #define FS_OPS(fs) { \
    140 	__CONCAT(fs,_open), \
    141 	__CONCAT(fs,_close), \
    142 	__CONCAT(fs,_read), \
    143 	__CONCAT(fs,_write), \
    144 	__CONCAT(fs,_seek), \
    145 	__CONCAT(fs,_stat) }
    146 #endif
    147 
    148 #define	FS_OPEN(fs)		((fs)->open)
    149 #define	FS_CLOSE(fs)		((fs)->close)
    150 #define	FS_READ(fs)		((fs)->read)
    151 #define	FS_WRITE(fs)		((fs)->write)
    152 #define	FS_SEEK(fs)		((fs)->seek)
    153 #define	FS_STAT(fs)		((fs)->stat)
    154 #if defined(LIBSA_ENABLE_LS_OP)
    155 #define	FS_LS(fs)		((fs)->ls)
    156 #endif
    157 
    158 #else
    159 
    160 #define	FS_OPEN(fs)		___CONCAT(LIBSA_SINGLE_FILESYSTEM,_open)
    161 #define	FS_CLOSE(fs)		___CONCAT(LIBSA_SINGLE_FILESYSTEM,_close)
    162 #define	FS_READ(fs)		___CONCAT(LIBSA_SINGLE_FILESYSTEM,_read)
    163 #define	FS_WRITE(fs)		___CONCAT(LIBSA_SINGLE_FILESYSTEM,_write)
    164 #define	FS_SEEK(fs)		___CONCAT(LIBSA_SINGLE_FILESYSTEM,_seek)
    165 #define	FS_STAT(fs)		___CONCAT(LIBSA_SINGLE_FILESYSTEM,_stat)
    166 #if defined(LIBSA_ENABLE_LS_OP)
    167 #define	FS_LS(fs)		___CONCAT(LIBSA_SINGLE_FILESYSTEM,_ls)
    168 #endif
    169 
    170 FS_DEF(LIBSA_SINGLE_FILESYSTEM);
    171 
    172 #endif
    173 
    174 /* where values for lseek(2) */
    175 #define	SEEK_SET	0	/* set file offset to offset */
    176 #define	SEEK_CUR	1	/* set file offset to current plus offset */
    177 #define	SEEK_END	2	/* set file offset to EOF plus offset */
    178 
    179 /* Device switch */
    180 #if !defined(LIBSA_SINGLE_DEVICE)
    181 
    182 struct devsw {
    183 	char	*dv_name;
    184 	int	(*dv_strategy)(void *, int, daddr_t, size_t, void *, size_t *);
    185 	int	(*dv_open)(struct open_file *, ...);
    186 	int	(*dv_close)(struct open_file *);
    187 	int	(*dv_ioctl)(struct open_file *, u_long, void *);
    188 };
    189 
    190 extern struct devsw devsw[];	/* device array */
    191 extern int ndevs;		/* number of elements in devsw[] */
    192 
    193 #define	DEV_NAME(d)		((d)->dv_name)
    194 #define	DEV_STRATEGY(d)		((d)->dv_strategy)
    195 #define	DEV_OPEN(d)		((d)->dv_open)
    196 #define	DEV_CLOSE(d)		((d)->dv_close)
    197 #define	DEV_IOCTL(d)		((d)->dv_ioctl)
    198 
    199 #else
    200 
    201 #define	DEV_NAME(d)		___STRING(LIBSA_SINGLE_DEVICE)
    202 #define	DEV_STRATEGY(d)		___CONCAT(LIBSA_SINGLE_DEVICE,strategy)
    203 #define	DEV_OPEN(d)		___CONCAT(LIBSA_SINGLE_DEVICE,open)
    204 #define	DEV_CLOSE(d)		___CONCAT(LIBSA_SINGLE_DEVICE,close)
    205 #define	DEV_IOCTL(d)		___CONCAT(LIBSA_SINGLE_DEVICE,ioctl)
    206 
    207 /* These may be #defines which must not be expanded here, hence the extra () */
    208 int	(DEV_STRATEGY(unused))(void *, int, daddr_t, size_t, void *, size_t *);
    209 int	(DEV_OPEN(unused))(struct open_file *, ...);
    210 int	(DEV_CLOSE(unused))(struct open_file *);
    211 int	(DEV_IOCTL(unused))(struct open_file *, u_long, void *);
    212 
    213 #endif
    214 
    215 struct open_file {
    216 	int		f_flags;	/* see F_* below */
    217 #if !defined(LIBSA_SINGLE_DEVICE)
    218 	const struct devsw	*f_dev;	/* pointer to device operations */
    219 #endif
    220 	void		*f_devdata;	/* device specific data */
    221 #if !defined(LIBSA_SINGLE_FILESYSTEM)
    222 	const struct fs_ops	*f_ops;	/* pointer to file system operations */
    223 #endif
    224 	void		*f_fsdata;	/* file system specific data */
    225 #if !defined(LIBSA_NO_RAW_ACCESS)
    226 	off_t		f_offset;	/* current file offset (F_RAW) */
    227 #endif
    228 };
    229 
    230 #define	SOPEN_MAX	4
    231 extern struct open_file files[];
    232 
    233 /* f_flags values */
    234 #define	F_READ		0x0001	/* file opened for reading */
    235 #define	F_WRITE		0x0002	/* file opened for writing */
    236 #if !defined(LIBSA_NO_RAW_ACCESS)
    237 #define	F_RAW		0x0004	/* raw device open - no file system */
    238 #endif
    239 #define F_NODEV		0x0008	/* network open - no device */
    240 
    241 int	(devopen)(struct open_file *, const char *, char **);
    242 #ifdef HEAP_VARIABLE
    243 void	setheap(void *, void *);
    244 #endif
    245 void	*alloc(size_t) __compactcall;
    246 void	dealloc(void *, size_t) __compactcall;
    247 struct	disklabel;
    248 char	*getdisklabel(const char *, struct disklabel *);
    249 int	dkcksum(const struct disklabel *);
    250 
    251 void	printf(const char *, ...)
    252     __attribute__((__format__(__printf__, 1, 2)));
    253 int	snprintf(char *, size_t, const char *, ...)
    254     __attribute__((__format__(__printf__, 3, 4)));
    255 void	vprintf(const char *, va_list)
    256     __attribute__((__format__(__printf__, 1, 0)));
    257 int	vsnprintf(char *, size_t, const char *, va_list)
    258     __attribute__((__format__(__printf__, 3, 0)));
    259 void	twiddle(void);
    260 void	gets(char *);
    261 int	getfile(char *prompt, int mode);
    262 char	*strerror(int);
    263 __dead void	exit(int);
    264 __dead void	panic(const char *, ...)
    265     __attribute__((__format__(__printf__, 1, 2)));
    266 __dead void	_rtt(void);
    267 void	*memcpy(void *, const void *, size_t);
    268 void	*memmove(void *, const void *, size_t);
    269 int	memcmp(const void *, const void *, size_t);
    270 void	*memset(void *, int, size_t);
    271 void	exec(char *, char *, int);
    272 int	open(const char *, int);
    273 int	close(int);
    274 void	closeall(void);
    275 ssize_t	read(int, void *, size_t);
    276 ssize_t	write(int, const void *, size_t);
    277 off_t	lseek(int, off_t, int);
    278 int	ioctl(int, u_long, char *);
    279 int	stat(const char *, struct stat *);
    280 int	fstat(int, struct stat *);
    281 #if defined(LIBSA_ENABLE_LS_OP)
    282 void	ls(const char *);
    283 #endif
    284 
    285 typedef int cmp_t(const void *, const void *);
    286 void	qsort(void *, size_t, size_t, cmp_t *);
    287 
    288 extern int opterr, optind, optopt, optreset;
    289 extern char *optarg;
    290 int	getopt(int, char * const *, const char *);
    291 
    292 char	*getpass(const char *);
    293 int	checkpasswd(void);
    294 int	check_password(const char *);
    295 
    296 int	nodev(void);
    297 int	noioctl(struct open_file *, u_long, void *);
    298 void	nullsys(void);
    299 
    300 FS_DEF(null);
    301 
    302 /* Machine dependent functions */
    303 void	machdep_start(char *, int, char *, char *, char *);
    304 int	getchar(void);
    305 void	putchar(int);
    306 
    307 #ifdef __INTERNAL_LIBSA_CREAD
    308 int	oopen(const char *, int);
    309 int	oclose(int);
    310 ssize_t	oread(int, void *, size_t);
    311 off_t	olseek(int, off_t, int);
    312 #endif
    313 
    314 extern const char hexdigits[];
    315 
    316 int	fnmatch(const char *, const char *);
    317 
    318 /* XXX: These should be removed eventually. */
    319 void	bcopy(const void *, void *, size_t);
    320 void	bzero(void *, size_t);
    321 
    322 int	atoi(const char *);
    323 
    324 #endif /* _LIBSA_STAND_H_ */
    325