1199767fToomas Soome/*
2199767fToomas Soome * Copyright (c) 1998 Michael Smith.
3199767fToomas Soome * All rights reserved.
4199767fToomas Soome *
5199767fToomas Soome * Redistribution and use in source and binary forms, with or without
6199767fToomas Soome * modification, are permitted provided that the following conditions
7199767fToomas Soome * are met:
8199767fToomas Soome * 1. Redistributions of source code must retain the above copyright
9199767fToomas Soome *    notice, this list of conditions and the following disclaimer.
10199767fToomas Soome * 2. Redistributions in binary form must reproduce the above copyright
11199767fToomas Soome *    notice, this list of conditions and the following disclaimer in the
12199767fToomas Soome *    documentation and/or other materials provided with the distribution.
13199767fToomas Soome *
14199767fToomas Soome * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15199767fToomas Soome * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16199767fToomas Soome * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17199767fToomas Soome * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18199767fToomas Soome * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19199767fToomas Soome * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20199767fToomas Soome * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21199767fToomas Soome * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22199767fToomas Soome * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23199767fToomas Soome * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24199767fToomas Soome * SUCH DAMAGE.
25199767fToomas Soome *
26199767fToomas Soome * $FreeBSD$
27c142ce1Toomas Soome * From	$NetBSD: stand.h,v 1.22 1997/06/26 19:17:40 drochner Exp $
28199767fToomas Soome */
29199767fToomas Soome
30cf837edToomas Soome/*
31199767fToomas Soome * Copyright (c) 1993
32199767fToomas Soome *	The Regents of the University of California.  All rights reserved.
33199767fToomas Soome *
34199767fToomas Soome * Redistribution and use in source and binary forms, with or without
35199767fToomas Soome * modification, are permitted provided that the following conditions
36199767fToomas Soome * are met:
37199767fToomas Soome * 1. Redistributions of source code must retain the above copyright
38199767fToomas Soome *    notice, this list of conditions and the following disclaimer.
39199767fToomas Soome * 2. Redistributions in binary form must reproduce the above copyright
40199767fToomas Soome *    notice, this list of conditions and the following disclaimer in the
41199767fToomas Soome *    documentation and/or other materials provided with the distribution.
42199767fToomas Soome * 4. Neither the name of the University nor the names of its contributors
43199767fToomas Soome *    may be used to endorse or promote products derived from this software
44199767fToomas Soome *    without specific prior written permission.
45199767fToomas Soome *
46199767fToomas Soome * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
47199767fToomas Soome * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
48199767fToomas Soome * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
49199767fToomas Soome * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
50199767fToomas Soome * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
51199767fToomas Soome * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
52199767fToomas Soome * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
53199767fToomas Soome * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
54199767fToomas Soome * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
55199767fToomas Soome * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
56199767fToomas Soome * SUCH DAMAGE.
57199767fToomas Soome *
58199767fToomas Soome *	@(#)stand.h	8.1 (Berkeley) 6/11/93
59199767fToomas Soome */
60199767fToomas Soome
61199767fToomas Soome#ifndef	STAND_H
62199767fToomas Soome#define	STAND_H
63199767fToomas Soome
64199767fToomas Soome#include <sys/types.h>
65199767fToomas Soome#include <sys/cdefs.h>
66199767fToomas Soome#include <sys/stat.h>
67199767fToomas Soome#include <sys/dirent.h>
68199767fToomas Soome
69199767fToomas Soome/* this header intentionally exports NULL from <string.h> */
70199767fToomas Soome#include <string.h>
71199767fToomas Soome
72573f593Toomas Soome#define	CHK(fmt, args...)	\
73573f593Toomas Soome	printf("%s(%d): " fmt "\n", __func__, __LINE__, ##args)
74573f593Toomas Soome#define	PCHK(fmt, args...)	{\
75573f593Toomas Soome	printf("%s(%d): " fmt "\n", __func__, __LINE__, ##args); getchar();\
76573f593Toomas Soome}
77199767fToomas Soome
78199767fToomas Soome/* Avoid unwanted userlandish components */
79573f593Toomas Soome#define	_KERNEL
80199767fToomas Soome#include <sys/errno.h>
81199767fToomas Soome#undef _KERNEL
82199767fToomas Soome
83199767fToomas Soome/* special stand error codes */
84199767fToomas Soome#define	EADAPT	(ELAST+1)	/* bad adaptor */
85199767fToomas Soome#define	ECTLR	(ELAST+2)	/* bad controller */
86199767fToomas Soome#define	EUNIT	(ELAST+3)	/* bad unit */
87573f593Toomas Soome#define	ESLICE	(ELAST+4)	/* bad slice */
88199767fToomas Soome#define	EPART	(ELAST+5)	/* bad partition */
89199767fToomas Soome#define	ERDLAB	(ELAST+6)	/* can't read disk label */
90199767fToomas Soome#define	EUNLAB	(ELAST+7)	/* unlabeled disk */
91199767fToomas Soome#define	EOFFSET	(ELAST+8)	/* relative seek not supported */
92199767fToomas Soome#define	ESALAST	(ELAST+8)	/* */
93199767fToomas Soome
94199767fToomas Soomestruct open_file;
95199767fToomas Soome
96199767fToomas Soome/*
97199767fToomas Soome * This structure is used to define file system operations in a file system
98199767fToomas Soome * independent way.
99199767fToomas Soome *
100199767fToomas Soome * XXX note that filesystem providers should export a pointer to their fs_ops
101199767fToomas Soome *     struct, so that consumers can reference this and thus include the
102199767fToomas Soome *     filesystems that they require.
103199767fToomas Soome */
104199767fToomas Soomestruct fs_ops {
105573f593Toomas Soome	const char *fs_name;
106573f593Toomas Soome	int (*fo_open)(const char *path, struct open_file *f);
107573f593Toomas Soome	int (*fo_close)(struct open_file *f);
108573f593Toomas Soome	int (*fo_read)(struct open_file *f, void *buf,
109573f593Toomas Soome	    size_t size, size_t *resid);
110573f593Toomas Soome	int (*fo_write)(struct open_file *f, const void *buf,
111573f593Toomas Soome	    size_t size, size_t *resid);
112573f593Toomas Soome	off_t (*fo_seek)(struct open_file *f, off_t offset, int where);
113573f593Toomas Soome	int (*fo_stat)(struct open_file *f, struct stat *sb);
114573f593Toomas Soome	int (*fo_readdir)(struct open_file *f, struct dirent *d);
115199767fToomas Soome};
116199767fToomas Soome
117199767fToomas Soome/*
118199767fToomas Soome * libstand-supplied filesystems
119199767fToomas Soome */
120199767fToomas Soomeextern struct fs_ops ufs_fsops;
121199767fToomas Soomeextern struct fs_ops tftp_fsops;
122199767fToomas Soomeextern struct fs_ops nfs_fsops;
123199767fToomas Soomeextern struct fs_ops cd9660_fsops;
124199767fToomas Soomeextern struct fs_ops nandfs_fsops;
125199767fToomas Soomeextern struct fs_ops gzipfs_fsops;
126199767fToomas Soomeextern struct fs_ops bzipfs_fsops;
127199767fToomas Soomeextern struct fs_ops dosfs_fsops;
128199767fToomas Soomeextern struct fs_ops ext2fs_fsops;
129199767fToomas Soomeextern struct fs_ops splitfs_fsops;
130199767fToomas Soomeextern struct fs_ops pkgfs_fsops;
131199767fToomas Soome
132199767fToomas Soome/* where values for lseek(2) */
133199767fToomas Soome#define	SEEK_SET	0	/* set file offset to offset */
134199767fToomas Soome#define	SEEK_CUR	1	/* set file offset to current plus offset */
135199767fToomas Soome#define	SEEK_END	2	/* set file offset to EOF plus offset */
136199767fToomas Soome
137c142ce1Toomas Soome/*
138199767fToomas Soome * Device switch
139199767fToomas Soome */
140199767fToomas Soomestruct devsw {
141573f593Toomas Soome	const char dv_name[8];
142573f593Toomas Soome	int dv_type;		/* opaque type constant, arch-dependant */
1430a06a80Toomas Soome#define	DEVT_NONE	0
1440a06a80Toomas Soome#define	DEVT_DISK	1
1450a06a80Toomas Soome#define	DEVT_NET	2
1460a06a80Toomas Soome#define	DEVT_CD		3
1470a06a80Toomas Soome#define	DEVT_ZFS	4
1480a06a80Toomas Soome#define	DEVT_FD		5
149573f593Toomas Soome	int (*dv_init)(void);	/* early probe call */
150573f593Toomas Soome	int (*dv_strategy)(void *devdata, int rw, daddr_t blk,
15138dea91Toomas Soome			size_t size, char *buf, size_t *rsize);
152573f593Toomas Soome	int (*dv_open)(struct open_file *f, ...);
153573f593Toomas Soome	int (*dv_close)(struct open_file *f);
154573f593Toomas Soome	int (*dv_ioctl)(struct open_file *f, ulong_t cmd, void *data);
155573f593Toomas Soome	int (*dv_print)(int verbose);	/* print device information */
156573f593Toomas Soome	void (*dv_cleanup)(void);
157199767fToomas Soome};
158199767fToomas Soome
159199767fToomas Soome/*
160199767fToomas Soome * libstand-supplied device switch
161199767fToomas Soome */
162199767fToomas Soomeextern struct devsw netdev;
163199767fToomas Soome
164199767fToomas Soomeextern int errno;
165199767fToomas Soome
166199767fToomas Soome/*
167199767fToomas Soome * Generic device specifier; architecture-dependent
168199767fToomas Soome * versions may be larger, but should be allowed to
169199767fToomas Soome * overlap.
170199767fToomas Soome */
1710a06a80Toomas Soomestruct devdesc {
172573f593Toomas Soome	struct devsw	*d_dev;
173573f593Toomas Soome	int		d_unit;
174573f593Toomas Soome	void		*d_opendata;
175199767fToomas Soome};
176199767fToomas Soome
177199767fToomas Soomestruct open_file {
178573f593Toomas Soome	int		f_flags;	/* see F_* below */
179573f593Toomas Soome	struct devsw	*f_dev;		/* pointer to device operations */
180573f593Toomas Soome	void		*f_devdata;	/* device specific data */
181573f593Toomas Soome	struct fs_ops	*f_ops;		/* pointer to file system operations */
182573f593Toomas Soome	void		*f_fsdata;	/* file system specific data */
183573f593Toomas Soome	off_t		f_offset;	/* current file offset */
184573f593Toomas Soome	char		*f_rabuf;	/* readahead buffer pointer */
185573f593Toomas Soome	size_t		f_ralen;	/* valid data in readahead buffer */
186573f593Toomas Soome	off_t		f_raoffset; /* consumer offset in readahead buffer */
187573f593Toomas Soome#define	SOPEN_RASIZE	512
188199767fToomas Soome};
189199767fToomas Soome
190199767fToomas Soome#define	SOPEN_MAX	64
191199767fToomas Soomeextern struct open_file files[];
192199767fToomas Soome
193199767fToomas Soome/* f_flags values */
194199767fToomas Soome#define	F_READ		0x0001	/* file opened for reading */
195199767fToomas Soome#define	F_WRITE		0x0002	/* file opened for writing */
196199767fToomas Soome#define	F_RAW		0x0004	/* raw device open - no file system */
197199767fToomas Soome#define	F_NODEV		0x0008	/* network open - no device */
198199767fToomas Soome#define	F_GZIP		0x0010  /* file is compressed by gzip */
199199767fToomas Soome#define	F_BZIP		0x0020	/* file is compressed by bzip */
2003dab250Toomas Soome#define	F_MASK		0xFFFF
2013dab250Toomas Soome/* Mode modifier for strategy() */
2023dab250Toomas Soome#define	F_NORA		(0x01 << 16)	/* Disable Read-Ahead */
203199767fToomas Soome
204573f593Toomas Soome#define	isascii(c)	(((c) & ~0x7F) == 0)
205199767fToomas Soome
206199767fToomas Soomestatic __inline int isupper(int c)
207199767fToomas Soome{
208573f593Toomas Soome	return (c >= 'A' && c <= 'Z');
209199767fToomas Soome}
210199767fToomas Soome
211199767fToomas Soomestatic __inline int islower(int c)
212199767fToomas Soome{
213573f593Toomas Soome	return (c >= 'a' && c <= 'z');
214199767fToomas Soome}
215199767fToomas Soome
216199767fToomas Soomestatic __inline int isspace(int c)
217199767fToomas Soome{
218573f593Toomas Soome	return (c == ' ' || (c >= 0x9 && c <= 0xd));
219199767fToomas Soome}
220199767fToomas Soome
221199767fToomas Soomestatic __inline int isdigit(int c)
222199767fToomas Soome{
223573f593Toomas Soome	return (c >= '0' && c <= '9');
224199767fToomas Soome}
225199767fToomas Soome
226199767fToomas Soomestatic __inline int isxdigit(int c)
227199767fToomas Soome{
228573f593Toomas Soome	return (isdigit(c) || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F'));
229199767fToomas Soome}
230199767fToomas Soome
231199767fToomas Soomestatic __inline int isalpha(int c)
232199767fToomas Soome{
233573f593Toomas Soome	return (isupper(c) || islower(c));
234199767fToomas Soome}
235199767fToomas Soome
236199767fToomas Soomestatic __inline int isalnum(int c)
237199767fToomas Soome{
238573f593Toomas Soome	return (isalpha(c) || isdigit(c));
239199767fToomas Soome}
240199767fToomas Soome
241be9c3adToomas Soomestatic __inline int iscntrl(int c)
242be9c3adToomas Soome{
243be9c3adToomas Soome	return ((c >= 0 && c < ' ') || c == 127);
244be9c3adToomas Soome}
245be9c3adToomas Soome
246be9c3adToomas Soomestatic __inline int isgraph(int c)
247be9c3adToomas Soome{
248be9c3adToomas Soome	return (c >= '!' && c <= '~');
249be9c3adToomas Soome}
250be9c3adToomas Soome
251be9c3adToomas Soomestatic __inline int ispunct(int c)
252be9c3adToomas Soome{
253be9c3adToomas Soome	return ((c >= '!' && c <= '/') || (c >= ':' && c <= '@') ||
254be9c3adToomas Soome	    (c >= '[' && c <= '`') || (c >= '{' && c <= '~'));
255be9c3adToomas Soome}
256be9c3adToomas Soome
257199767fToomas Soomestatic __inline int toupper(int c)
258199767fToomas Soome{
259573f593Toomas Soome	return (islower(c) ? c - 'a' + 'A' : c);
260199767fToomas Soome}
261199767fToomas Soome
262199767fToomas Soomestatic __inline int tolower(int c)
263199767fToomas Soome{
264573f593Toomas Soome	return (isupper(c) ? c - 'A' + 'a' : c);
265199767fToomas Soome}
266199767fToomas Soome
267199767fToomas Soome/* sbrk emulation */
268199767fToomas Soomeextern void	setheap(void *base, void *top);
269199767fToomas Soomeextern char	*sbrk(int incr);
270199767fToomas Soome
271199767fToomas Soomeextern void	mallocstats(void);
272199767fToomas Soome
273199767fToomas Soomeextern int	printf(const char *fmt, ...) __printflike(1, 2);
274199767fToomas Soomeextern void	vprintf(const char *fmt, __va_list);
2756ea3a31Toomas Soomeextern int	asprintf(char **buf, const char *cfmt, ...) __printflike(2, 3);
276199767fToomas Soomeextern int	sprintf(char *buf, const char *cfmt, ...) __printflike(2, 3);
277573f593Toomas Soomeextern int	snprintf(char *buf, size_t size, const char *cfmt, ...) \
278573f593Toomas Soome		__printflike(3, 4);
279199767fToomas Soomeextern void	vsprintf(char *buf, const char *cfmt, __va_list);
280199767fToomas Soomeextern void	vsnprintf(char *buf, size_t size, const char *cfmt, __va_list);
281199767fToomas Soome
282573f593Toomas Soomeextern void	twiddle(uint_t callerdiv);
283573f593Toomas Soomeextern void	twiddle_divisor(uint_t globaldiv);
284199767fToomas Soome
285199767fToomas Soomeextern void	ngets(char *, int);
286573f593Toomas Soome#define	gets(x)	ngets((x), 0)
287199767fToomas Soomeextern int	fgetstr(char *buf, int size, int fd);
288199767fToomas Soome
289199767fToomas Soomeextern int	open(const char *, int);
290199767fToomas Soome#define	O_RDONLY	0x0
291573f593Toomas Soome#define	O_WRONLY	0x1
292573f593Toomas Soome#define	O_RDWR		0x2
293199767fToomas Soomeextern int	close(int);
294199767fToomas Soomeextern void	closeall(void);
295199767fToomas Soomeextern ssize_t	read(int, void *, size_t);
296cf837edToomas Soomeextern ssize_t	write(int, const void *, size_t);
297199767fToomas Soomeextern struct	dirent *readdirfd(int);
298199767fToomas Soome
299573f593Toomas Soomeextern void	srandom(ulong_t seed);
300573f593Toomas Soomeextern ulong_t	random(void);
301c142ce1Toomas Soome
302199767fToomas Soome/* imports from stdlib, locally modified */
303199767fToomas Soomeextern long	strtol(const char *, char **, int);
304199767fToomas Soomeextern unsigned long	strtoul(const char *, char **, int);
305573f593Toomas Soomeextern char	*optarg;		/* getopt(3) external variables */
306199767fToomas Soomeextern int	optind, opterr, optopt, optreset;
307199767fToomas Soomeextern int	getopt(int, char * const [], const char *);
308199767fToomas Soome
309199767fToomas Soome/* pager.c */
310199767fToomas Soomeextern void	pager_open(void);
311199767fToomas Soomeextern void	pager_close(void);
312199767fToomas Soomeextern int	pager_output(const char *lines);
313199767fToomas Soomeextern int	pager_file(const char *fname);
314199767fToomas Soome
315199767fToomas Soome/* No signal state to preserve */
316573f593Toomas Soome#define	setjmp	_setjmp
317573f593Toomas Soome#define	longjmp	_longjmp
318199767fToomas Soome
319199767fToomas Soome/* environment.c */
320573f593Toomas Soome/* value was dynamically allocated, free if changed/unset */
321573f593Toomas Soome#define	EV_DYNAMIC	(1<<0)
322573f593Toomas Soome/* value is volatile, make a copy of it */
323573f593Toomas Soome#define	EV_VOLATILE	(1<<1)
324573f593Toomas Soome/* don't call hook when setting */
325573f593Toomas Soome#define	EV_NOHOOK	(1<<2)
326199767fToomas Soome
327199767fToomas Soomestruct env_var;
328199767fToomas Soometypedef char	*(ev_format_t)(struct env_var *ev);
329199767fToomas Soometypedef int	(ev_sethook_t)(struct env_var *ev, int flags,
330199767fToomas Soome		    const void *value);
331199767fToomas Soometypedef int	(ev_unsethook_t)(struct env_var *ev);
332199767fToomas Soome
333199767fToomas Soomestruct env_var
334199767fToomas Soome{
335199767fToomas Soome    char		*ev_name;
336199767fToomas Soome    int			ev_flags;
337199767fToomas Soome    void		*ev_value;
338199767fToomas Soome    ev_sethook_t	*ev_sethook;
339199767fToomas Soome    ev_unsethook_t	*ev_unsethook;
340199767fToomas Soome    struct env_var	*ev_next, *ev_prev;
341199767fToomas Soome};
342199767fToomas Soomeextern struct env_var	*environ;
343199767fToomas Soome
344199767fToomas Soomeextern struct env_var	*env_getenv(const char *name);
345199767fToomas Soomeextern int		env_setenv(const char *name, int flags,
346573f593Toomas Soome				const void *value, ev_sethook_t sethook,
347573f593Toomas Soome				ev_unsethook_t unsethook);
348199767fToomas Soomeextern char		*getenv(const char *name);
349199767fToomas Soomeextern int		setenv(const char *name, const char *value,
350573f593Toomas Soome				int overwrite);
351199767fToomas Soomeextern int		putenv(const char *string);
352199767fToomas Soomeextern int		unsetenv(const char *name);
353199767fToomas Soome
354199767fToomas Soomeextern ev_sethook_t	env_noset;		/* refuse set operation */
355199767fToomas Soomeextern ev_unsethook_t	env_nounset;		/* refuse unset operation */
356199767fToomas Soome
357199767fToomas Soome/* BCD conversions (undocumented) */
358573f593Toomas Soomeextern uchar_t const	bcd2bin_data[];
359573f593Toomas Soomeextern uchar_t const	bin2bcd_data[];
360199767fToomas Soomeextern char const	hex2ascii_data[];
361199767fToomas Soome
362199767fToomas Soome#define	bcd2bin(bcd)	(bcd2bin_data[bcd])
363199767fToomas Soome#define	bin2bcd(bin)	(bin2bcd_data[bin])
364199767fToomas Soome#define	hex2ascii(hex)	(hex2ascii_data[hex])
365199767fToomas Soome
366199767fToomas Soome/* min/max (undocumented) */
367199767fToomas Soomestatic __inline int imax(int a, int b) { return (a > b ? a : b); }
368199767fToomas Soomestatic __inline int imin(int a, int b) { return (a < b ? a : b); }
369199767fToomas Soomestatic __inline long lmax(long a, long b) { return (a > b ? a : b); }
370199767fToomas Soomestatic __inline long lmin(long a, long b) { return (a < b ? a : b); }
371573f593Toomas Soomestatic __inline uint_t max(uint_t a, uint_t b) { return (a > b ? a : b); }
372573f593Toomas Soomestatic __inline uint_t min(uint_t a, uint_t b) { return (a < b ? a : b); }
373199767fToomas Soomestatic __inline quad_t qmax(quad_t a, quad_t b) { return (a > b ? a : b); }
374199767fToomas Soomestatic __inline quad_t qmin(quad_t a, quad_t b) { return (a < b ? a : b); }
375573f593Toomas Soomestatic __inline ulong_t ulmax(ulong_t a, ulong_t b) { return (a > b ? a : b); }
376573f593Toomas Soomestatic __inline ulong_t ulmin(ulong_t a, ulong_t b) { return (a < b ? a : b); }
377199767fToomas Soome
378199767fToomas Soome/* null functions for device/filesystem switches (undocumented) */
379199767fToomas Soomeextern int	nodev(void);
380573f593Toomas Soomeextern int	noioctl(struct open_file *, ulong_t, void *);
381199767fToomas Soomeextern void	nullsys(void);
382199767fToomas Soome
383573f593Toomas Soomeextern int	null_open(const char *, struct open_file *);
384573f593Toomas Soomeextern int	null_close(struct open_file *);
385573f593Toomas Soomeextern int	null_read(struct open_file *, void *, size_t, size_t *);
386573f593Toomas Soomeextern int	null_write(struct open_file *, const void *, size_t, size_t *);
387573f593Toomas Soomeextern off_t	null_seek(struct open_file *, off_t, int);
388573f593Toomas Soomeextern int	null_stat(struct open_file *, struct stat *);
389573f593Toomas Soomeextern int	null_readdir(struct open_file *, struct dirent *);
390199767fToomas Soome
391199767fToomas Soome
392c142ce1Toomas Soome/*
393c142ce1Toomas Soome * Machine dependent functions and data, must be provided or stubbed by
394c142ce1Toomas Soome * the consumer
395199767fToomas Soome */
396573f593Toomas Soomeextern void	exit(int) __dead2;
397573f593Toomas Soomeextern int	getchar(void);
398573f593Toomas Soomeextern int	ischar(void);
399573f593Toomas Soomeextern void	putchar(int);
400573f593Toomas Soomeextern int	devopen(struct open_file *, const char *, const char **);
401573f593Toomas Soomeextern int	devclose(struct open_file *f);
402573f593Toomas Soomeextern void	panic(const char *, ...) __dead2 __printflike(1, 2);
403573f593Toomas Soomeextern void	panic_action(void) __weak_symbol __dead2;
404573f593Toomas Soomeextern time_t	getsecs(void);
405199767fToomas Soomeextern struct fs_ops	*file_system[];
406199767fToomas Soomeextern struct fs_ops	*exclusive_file_system;
407199767fToomas Soomeextern struct devsw	*devsw[];
408199767fToomas Soome
409199767fToomas Soome/*
410199767fToomas Soome * Expose byteorder(3) functions.
411199767fToomas Soome */
412199767fToomas Soome#ifndef _BYTEORDER_PROTOTYPED
413199767fToomas Soome#define	_BYTEORDER_PROTOTYPED
414199767fToomas Soomeextern uint32_t		htonl(uint32_t);
415199767fToomas Soomeextern uint16_t		htons(uint16_t);
416199767fToomas Soomeextern uint32_t		ntohl(uint32_t);
417199767fToomas Soomeextern uint16_t		ntohs(uint16_t);
418199767fToomas Soome#endif
419199767fToomas Soome
420199767fToomas Soome#ifndef _BYTEORDER_FUNC_DEFINED
421199767fToomas Soome#define	_BYTEORDER_FUNC_DEFINED
422199767fToomas Soome#define	htonl(x)	__htonl(x)
423199767fToomas Soome#define	htons(x)	__htons(x)
424199767fToomas Soome#define	ntohl(x)	__ntohl(x)
425199767fToomas Soome#define	ntohs(x)	__ntohs(x)
426199767fToomas Soome#endif
427199767fToomas Soome
428199767fToomas Soomevoid *Malloc(size_t, const char *, int);
429081aa5fToomas Soomevoid *Memalign(size_t, size_t, const char *, int);
430199767fToomas Soomevoid *Calloc(size_t, size_t, const char *, int);
431199767fToomas Soomevoid *Realloc(void *, size_t, const char *, int);
432081aa5fToomas Soomevoid *Reallocf(void *, size_t, const char *, int);
433199767fToomas Soomevoid Free(void *, const char *, int);
434199767fToomas Soome
435081aa5fToomas Soome#if DEBUG_MALLOC
436573f593Toomas Soome#define	malloc(x)	Malloc(x, __FILE__, __LINE__)
437081aa5fToomas Soome#define	memalign(x, y)	Memalign(x, y, __FILE__, __LINE__)
438573f593Toomas Soome#define	calloc(x, y)	Calloc(x, y, __FILE__, __LINE__)
439573f593Toomas Soome#define	free(x)		Free(x, __FILE__, __LINE__)
440573f593Toomas Soome#define	realloc(x, y)	Realloc(x, y, __FILE__, __LINE__)
441081aa5fToomas Soome#define	reallocf(x, y)	Reallocf(x, y, __FILE__, __LINE__)
442199767fToomas Soome#else
443573f593Toomas Soome#define	malloc(x)	Malloc(x, NULL, 0)
444081aa5fToomas Soome#define	memalign(x, y)	Memalign(x, y, NULL, 0)
445573f593Toomas Soome#define	calloc(x, y)	Calloc(x, y, NULL, 0)
446573f593Toomas Soome#define	free(x)		Free(x, NULL, 0)
447573f593Toomas Soome#define	realloc(x, y)	Realloc(x, y, NULL, 0)
448081aa5fToomas Soome#define	reallocf(x, y)	Reallocf(x, y, NULL, 0)
449199767fToomas Soome#endif
450199767fToomas Soome
451199767fToomas Soome#endif	/* STAND_H */
452