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