1335c4bemsmith/*
2335c4bemsmith * Copyright (c) 1998 Michael Smith.
3335c4bemsmith * All rights reserved.
4335c4bemsmith *
5335c4bemsmith * Redistribution and use in source and binary forms, with or without
6335c4bemsmith * modification, are permitted provided that the following conditions
7335c4bemsmith * are met:
8335c4bemsmith * 1. Redistributions of source code must retain the above copyright
9335c4bemsmith *    notice, this list of conditions and the following disclaimer.
10335c4bemsmith * 2. Redistributions in binary form must reproduce the above copyright
11335c4bemsmith *    notice, this list of conditions and the following disclaimer in the
12335c4bemsmith *    documentation and/or other materials provided with the distribution.
13335c4bemsmith *
14335c4bemsmith * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15335c4bemsmith * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16335c4bemsmith * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17335c4bemsmith * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18335c4bemsmith * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19335c4bemsmith * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20335c4bemsmith * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21335c4bemsmith * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22335c4bemsmith * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23335c4bemsmith * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24335c4bemsmith * SUCH DAMAGE.
25335c4bemsmith *
2676f0c92peter * $FreeBSD$
27335c4bemsmith * From	$NetBSD: stand.h,v 1.22 1997/06/26 19:17:40 drochner Exp $
28335c4bemsmith */
29335c4bemsmith
30335c4bemsmith/*-
31335c4bemsmith * Copyright (c) 1993
32335c4bemsmith *	The Regents of the University of California.  All rights reserved.
33335c4bemsmith *
34335c4bemsmith * Redistribution and use in source and binary forms, with or without
35335c4bemsmith * modification, are permitted provided that the following conditions
36335c4bemsmith * are met:
37335c4bemsmith * 1. Redistributions of source code must retain the above copyright
38335c4bemsmith *    notice, this list of conditions and the following disclaimer.
39335c4bemsmith * 2. Redistributions in binary form must reproduce the above copyright
40335c4bemsmith *    notice, this list of conditions and the following disclaimer in the
41335c4bemsmith *    documentation and/or other materials provided with the distribution.
427e6cabdimp * 3. Neither the name of the University nor the names of its contributors
43335c4bemsmith *    may be used to endorse or promote products derived from this software
44335c4bemsmith *    without specific prior written permission.
45335c4bemsmith *
46335c4bemsmith * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
47335c4bemsmith * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
48335c4bemsmith * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
49335c4bemsmith * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
50335c4bemsmith * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
51335c4bemsmith * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
52335c4bemsmith * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
53335c4bemsmith * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
54335c4bemsmith * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
55335c4bemsmith * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
56335c4bemsmith * SUCH DAMAGE.
57335c4bemsmith *
58335c4bemsmith *	@(#)stand.h	8.1 (Berkeley) 6/11/93
59335c4bemsmith */
60335c4bemsmith
61c856e4dobrien#ifndef	STAND_H
62c856e4dobrien#define	STAND_H
63c856e4dobrien
64335c4bemsmith#include <sys/types.h>
65335c4bemsmith#include <sys/cdefs.h>
66335c4bemsmith#include <sys/stat.h>
679f5d586jlemon#include <sys/dirent.h>
68de81e76avatar
69de81e76avatar/* this header intentionally exports NULL from <string.h> */
7004f2dc8jhb#include <string.h>
71f701b31imp#define strcoll(a, b)	strcmp((a), (b))
72335c4bemsmith
735b6654bstefanf#define CHK(fmt, args...)	printf("%s(%d): " fmt "\n", __func__, __LINE__ , ##args)
745b6654bstefanf#define PCHK(fmt, args...)	{printf("%s(%d): " fmt "\n", __func__, __LINE__ , ##args); getchar();}
75ea78326msmith
76335c4bemsmith#include <sys/errno.h>
77335c4bemsmith
78335c4bemsmith/* special stand error codes */
79335c4bemsmith#define	EADAPT	(ELAST+1)	/* bad adaptor */
80335c4bemsmith#define	ECTLR	(ELAST+2)	/* bad controller */
81335c4bemsmith#define	EUNIT	(ELAST+3)	/* bad unit */
82335c4bemsmith#define ESLICE	(ELAST+4)	/* bad slice */
83335c4bemsmith#define	EPART	(ELAST+5)	/* bad partition */
84335c4bemsmith#define	ERDLAB	(ELAST+6)	/* can't read disk label */
85335c4bemsmith#define	EUNLAB	(ELAST+7)	/* unlabeled disk */
86335c4bemsmith#define	EOFFSET	(ELAST+8)	/* relative seek not supported */
87335c4bemsmith#define	ESALAST	(ELAST+8)	/* */
88335c4bemsmith
891fb5990imp/* Partial signal emulation for sig_atomic_t */
901fb5990imp#include <machine/signal.h>
911fb5990imp
92335c4bemsmithstruct open_file;
93335c4bemsmith
94335c4bemsmith/*
95335c4bemsmith * This structure is used to define file system operations in a file system
96335c4bemsmith * independent way.
97335c4bemsmith *
98335c4bemsmith * XXX note that filesystem providers should export a pointer to their fs_ops
99335c4bemsmith *     struct, so that consumers can reference this and thus include the
100335c4bemsmith *     filesystems that they require.
101335c4bemsmith */
102335c4bemsmithstruct fs_ops {
1033b7700fmsmith    const char	*fs_name;
1043b7700fmsmith    int		(*fo_open)(const char *path, struct open_file *f);
105335c4bemsmith    int		(*fo_close)(struct open_file *f);
106335c4bemsmith    int		(*fo_read)(struct open_file *f, void *buf,
107335c4bemsmith			   size_t size, size_t *resid);
10823d934dcem    int		(*fo_write)(struct open_file *f, const void *buf,
109335c4bemsmith			    size_t size, size_t *resid);
110335c4bemsmith    off_t	(*fo_seek)(struct open_file *f, off_t offset, int where);
111335c4bemsmith    int		(*fo_stat)(struct open_file *f, struct stat *sb);
1129f5d586jlemon    int		(*fo_readdir)(struct open_file *f, struct dirent *d);
113335c4bemsmith};
114335c4bemsmith
115335c4bemsmith/*
116335c4bemsmith * libstand-supplied filesystems
117335c4bemsmith */
118335c4bemsmithextern struct fs_ops ufs_fsops;
119335c4bemsmithextern struct fs_ops tftp_fsops;
120335c4bemsmithextern struct fs_ops nfs_fsops;
121335c4bemsmithextern struct fs_ops cd9660_fsops;
122081cb68jakeextern struct fs_ops gzipfs_fsops;
123f261311sobomaxextern struct fs_ops bzipfs_fsops;
124335c4bemsmithextern struct fs_ops dosfs_fsops;
1259f5d586jlemonextern struct fs_ops ext2fs_fsops;
1269d703dcsobomaxextern struct fs_ops splitfs_fsops;
127e8c9682marcelextern struct fs_ops pkgfs_fsops;
128dcddd84bcranextern struct fs_ops efihttp_fsops;
129335c4bemsmith
130335c4bemsmith/* where values for lseek(2) */
131335c4bemsmith#define	SEEK_SET	0	/* set file offset to offset */
132335c4bemsmith#define	SEEK_CUR	1	/* set file offset to current plus offset */
133335c4bemsmith#define	SEEK_END	2	/* set file offset to EOF plus offset */
134335c4bemsmith
135335c4bemsmith/*
136335c4bemsmith * Device switch
137335c4bemsmith */
138335c4bemsmithstruct devsw {
1393b7700fmsmith    const char	dv_name[8];
140335c4bemsmith    int		dv_type;		/* opaque type constant, arch-dependant */
14163b1228imp#define DEVT_NONE	0
14263b1228imp#define DEVT_DISK	1
14363b1228imp#define DEVT_NET	2
14463b1228imp#define DEVT_CD		3
14563b1228imp#define DEVT_ZFS	4
14663b1228imp#define DEVT_FD		5
147335c4bemsmith    int		(*dv_init)(void);	/* early probe call */
1482b75f57allanjude    int		(*dv_strategy)(void *devdata, int rw, daddr_t blk,
1492bcaf52tsoome			size_t size, char *buf, size_t *rsize);
150335c4bemsmith    int		(*dv_open)(struct open_file *f, ...);
151335c4bemsmith    int		(*dv_close)(struct open_file *f);
152335c4bemsmith    int		(*dv_ioctl)(struct open_file *f, u_long cmd, void *data);
1534455fc8tsoome    int		(*dv_print)(int verbose);	/* print device information */
15404f2dc8jhb    void	(*dv_cleanup)(void);
155335c4bemsmith};
156335c4bemsmith
1579f5d586jlemon/*
1589f5d586jlemon * libstand-supplied device switch
1599f5d586jlemon */
1609f5d586jlemonextern struct devsw netdev;
1619f5d586jlemon
162335c4bemsmithextern int errno;
163335c4bemsmith
1642b75f57allanjude/*
1652b75f57allanjude * Generic device specifier; architecture-dependent
1662b75f57allanjude * versions may be larger, but should be allowed to
1672b75f57allanjude * overlap.
1682b75f57allanjude */
16963b1228impstruct devdesc {
1702b75f57allanjude    struct devsw	*d_dev;
1712b75f57allanjude    int			d_unit;
1722b75f57allanjude    void		*d_opendata;
1732b75f57allanjude};
1742b75f57allanjude
175335c4bemsmithstruct open_file {
176335c4bemsmith    int			f_flags;	/* see F_* below */
177335c4bemsmith    struct devsw	*f_dev;		/* pointer to device operations */
178335c4bemsmith    void		*f_devdata;	/* device specific data */
179335c4bemsmith    struct fs_ops	*f_ops;		/* pointer to file system operations */
180335c4bemsmith    void		*f_fsdata;	/* file system specific data */
1816ff92c1msmith    off_t		f_offset;	/* current file offset */
1826ff92c1msmith    char		*f_rabuf;	/* readahead buffer pointer */
1836ff92c1msmith    size_t		f_ralen;	/* valid data in readahead buffer */
1846ff92c1msmith    off_t		f_raoffset;	/* consumer offset in readahead buffer */
1856ff92c1msmith#define SOPEN_RASIZE	512
186335c4bemsmith};
187335c4bemsmith
188216f2b3dfr#define	SOPEN_MAX	64
189335c4bemsmithextern struct open_file files[];
190335c4bemsmith
191335c4bemsmith/* f_flags values */
192335c4bemsmith#define	F_READ		0x0001	/* file opened for reading */
193335c4bemsmith#define	F_WRITE		0x0002	/* file opened for writing */
194335c4bemsmith#define	F_RAW		0x0004	/* raw device open - no file system */
195335c4bemsmith#define F_NODEV		0x0008	/* network open - no device */
196d76435etsoome#define	F_MASK		0xFFFF
197d76435etsoome/* Mode modifier for strategy() */
198d76435etsoome#define	F_NORA		(0x01 << 16)	/* Disable Read-Ahead */
199335c4bemsmith
2008d18889peter#define isascii(c)	(((c) & ~0x7F) == 0)
201bcc6e22dcs
202bcc6e22dcsstatic __inline int isupper(int c)
203bcc6e22dcs{
204bcc6e22dcs    return c >= 'A' && c <= 'Z';
205bcc6e22dcs}
206bcc6e22dcs
207bcc6e22dcsstatic __inline int islower(int c)
208bcc6e22dcs{
209bcc6e22dcs    return c >= 'a' && c <= 'z';
210bcc6e22dcs}
211bcc6e22dcs
212bcc6e22dcsstatic __inline int isspace(int c)
213bcc6e22dcs{
214bcc6e22dcs    return c == ' ' || (c >= 0x9 && c <= 0xd);
215bcc6e22dcs}
216bcc6e22dcs
217bcc6e22dcsstatic __inline int isdigit(int c)
218bcc6e22dcs{
219bcc6e22dcs    return c >= '0' && c <= '9';
220bcc6e22dcs}
221bcc6e22dcs
222bcc6e22dcsstatic __inline int isxdigit(int c)
223bcc6e22dcs{
224bcc6e22dcs    return isdigit(c) || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F');
225bcc6e22dcs}
226bcc6e22dcs
227bcc6e22dcsstatic __inline int isalpha(int c)
228bcc6e22dcs{
229bcc6e22dcs    return isupper(c) || islower(c);
230bcc6e22dcs}
231bcc6e22dcs
232bcc6e22dcsstatic __inline int isalnum(int c)
233bcc6e22dcs{
234bcc6e22dcs    return isalpha(c) || isdigit(c);
235bcc6e22dcs}
236d9e5c7ddfr
237fdba3fbimpstatic __inline int iscntrl(int c)
238fdba3fbimp{
239fdba3fbimp	return (c >= 0 && c < ' ') || c == 127;
240fdba3fbimp}
241fdba3fbimp
242fdba3fbimpstatic __inline int isgraph(int c)
243fdba3fbimp{
244fdba3fbimp	return c >= '!' && c <= '~';
245fdba3fbimp}
246fdba3fbimp
247fdba3fbimpstatic __inline int ispunct(int c)
248fdba3fbimp{
249fdba3fbimp	return (c >= '!' && c <= '/') || (c >= ':' && c <= '@') ||
250fdba3fbimp	    (c >= '[' && c <= '`') || (c >= '{' && c <= '~');
251fdba3fbimp}
252fdba3fbimp
253d9e5c7ddfrstatic __inline int toupper(int c)
254d9e5c7ddfr{
255d9e5c7ddfr    return islower(c) ? c - 'a' + 'A' : c;
256d9e5c7ddfr}
257d9e5c7ddfr
258d9e5c7ddfrstatic __inline int tolower(int c)
259d9e5c7ddfr{
260d9e5c7ddfr    return isupper(c) ? c - 'A' + 'a' : c;
261d9e5c7ddfr}
262335c4bemsmith
263ea78326msmith/* sbrk emulation */
264ea78326msmithextern void	setheap(void *base, void *top);
265ea78326msmithextern char	*sbrk(int incr);
266ea78326msmith
26726b02a9peterextern int	printf(const char *fmt, ...) __printflike(1, 2);
268e9b9f14tsoomeextern int	asprintf(char **buf, const char *cfmt, ...) __printflike(2, 3);
26926b02a9peterextern int	sprintf(char *buf, const char *cfmt, ...) __printflike(2, 3);
2706b258c1hselaskyextern int	snprintf(char *buf, size_t size, const char *cfmt, ...) __printflike(3, 4);
27198ec7f9ianextern int	vprintf(const char *fmt, __va_list);
27298ec7f9ianextern int	vsprintf(char *buf, const char *cfmt, __va_list);
27398ec7f9ianextern int	vsnprintf(char *buf, size_t size, const char *cfmt, __va_list);
274335c4bemsmith
275e44e2acianextern void	twiddle(u_int callerdiv);
276e44e2acianextern void	twiddle_divisor(u_int globaldiv);
277335c4bemsmith
278335c4bemsmithextern void	ngets(char *, int);
279335c4bemsmith#define gets(x)	ngets((x), 0)
280335c4bemsmithextern int	fgetstr(char *buf, int size, int fd);
281335c4bemsmith
282335c4bemsmithextern int	open(const char *, int);
283335c4bemsmith#define	O_RDONLY	0x0
28470c430ajhb#define O_WRONLY	0x1
285335c4bemsmith#define O_RDWR		0x2
28660c18c4sjg#define O_ACCMODE	0x3
2879ad97fakevans/* NOT IMPLEMENTED */
2889ad97fakevans#define	O_CREAT		0x0200		/* create if nonexistent */
2899ad97fakevans#define	O_TRUNC		0x0400		/* truncate to zero length */
290335c4bemsmithextern int	close(int);
291335c4bemsmithextern void	closeall(void);
292335c4bemsmithextern ssize_t	read(int, void *, size_t);
29328fcfa7cemextern ssize_t	write(int, const void *, size_t);
2949f5d586jlemonextern struct	dirent *readdirfd(int);
295335c4bemsmith
29620d9ab0impextern void	srandom(unsigned int);
2978fcb352impextern long	random(void);
298335c4bemsmith
299335c4bemsmith/* imports from stdlib, locally modified */
300335c4bemsmithextern char	*optarg;			/* getopt(3) external variables */
301192ad36msmithextern int	optind, opterr, optopt, optreset;
302335c4bemsmithextern int	getopt(int, char * const [], const char *);
303335c4bemsmith
304335c4bemsmith/* pager.c */
305335c4bemsmithextern void	pager_open(void);
306335c4bemsmithextern void	pager_close(void);
307335c4bemsmithextern int	pager_output(const char *lines);
3083b7700fmsmithextern int	pager_file(const char *fname);
309335c4bemsmith
3104674ed7msmith/* No signal state to preserve */
3114674ed7msmith#define setjmp	_setjmp
3124674ed7msmith#define longjmp	_longjmp
3134674ed7msmith
314335c4bemsmith/* environment.c */
315335c4bemsmith#define EV_DYNAMIC	(1<<0)		/* value was dynamically allocated, free if changed/unset */
316335c4bemsmith#define EV_VOLATILE	(1<<1)		/* value is volatile, make a copy of it */
317335c4bemsmith#define EV_NOHOOK	(1<<2)		/* don't call hook when setting */
318335c4bemsmith
319335c4bemsmithstruct env_var;
320335c4bemsmithtypedef char	*(ev_format_t)(struct env_var *ev);
32192983ccpetertypedef int	(ev_sethook_t)(struct env_var *ev, int flags,
32292983ccpeter		    const void *value);
323335c4bemsmithtypedef int	(ev_unsethook_t)(struct env_var *ev);
324335c4bemsmith
325335c4bemsmithstruct env_var
326335c4bemsmith{
327335c4bemsmith    char		*ev_name;
328335c4bemsmith    int			ev_flags;
329335c4bemsmith    void		*ev_value;
330335c4bemsmith    ev_sethook_t	*ev_sethook;
331335c4bemsmith    ev_unsethook_t	*ev_unsethook;
332335c4bemsmith    struct env_var	*ev_next, *ev_prev;
333335c4bemsmith};
334335c4bemsmithextern struct env_var	*environ;
335335c4bemsmith
336335c4bemsmithextern struct env_var	*env_getenv(const char *name);
33704f2dc8jhbextern int		env_setenv(const char *name, int flags,
33804f2dc8jhb				   const void *value, ev_sethook_t sethook,
33904f2dc8jhb				   ev_unsethook_t unsethook);
340335c4bemsmithextern char		*getenv(const char *name);
34104f2dc8jhbextern int		setenv(const char *name, const char *value,
34204f2dc8jhb			       int overwrite);
3431f7bf6aimpextern int		putenv(char *string);
344335c4bemsmithextern int		unsetenv(const char *name);
345335c4bemsmith
346335c4bemsmithextern ev_sethook_t	env_noset;		/* refuse set operation */
347335c4bemsmithextern ev_unsethook_t	env_nounset;		/* refuse unset operation */
348335c4bemsmith
3498c8c3f5imp/* stdlib.h routines */
3507ceca2aimpextern int		abs(int a);
351bd3d902impextern void		abort(void) __dead2;
352086d3e5impextern long		strtol(const char * __restrict, char ** __restrict, int);
353086d3e5impextern long long	strtoll(const char * __restrict, char ** __restrict, int);
354086d3e5impextern unsigned long	strtoul(const char * __restrict, char ** __restrict, int);
355086d3e5impextern unsigned long long strtoull(const char * __restrict, char ** __restrict, int);
3568c8c3f5imp
357335c4bemsmith/* BCD conversions (undocumented) */
358335c4bemsmithextern u_char const	bcd2bin_data[];
359335c4bemsmithextern u_char const	bin2bcd_data[];
360335c4bemsmithextern char const	hex2ascii_data[];
361335c4bemsmith
362335c4bemsmith#define	bcd2bin(bcd)	(bcd2bin_data[bcd])
363335c4bemsmith#define	bin2bcd(bin)	(bin2bcd_data[bin])
364335c4bemsmith#define	hex2ascii(hex)	(hex2ascii_data[hex])
36597b1743ian#define	validbcd(bcd)	(bcd == 0 || (bcd > 0 && bcd <= 0x99 && bcd2bin_data[bcd] != 0))
366335c4bemsmith
367335c4bemsmith/* min/max (undocumented) */
368335c4bemsmithstatic __inline int imax(int a, int b) { return (a > b ? a : b); }
369335c4bemsmithstatic __inline int imin(int a, int b) { return (a < b ? a : b); }
370335c4bemsmithstatic __inline long lmax(long a, long b) { return (a > b ? a : b); }
371335c4bemsmithstatic __inline long lmin(long a, long b) { return (a < b ? a : b); }
372335c4bemsmithstatic __inline u_int max(u_int a, u_int b) { return (a > b ? a : b); }
373335c4bemsmithstatic __inline u_int min(u_int a, u_int b) { return (a < b ? a : b); }
374335c4bemsmithstatic __inline quad_t qmax(quad_t a, quad_t b) { return (a > b ? a : b); }
375335c4bemsmithstatic __inline quad_t qmin(quad_t a, quad_t b) { return (a < b ? a : b); }
376335c4bemsmithstatic __inline u_long ulmax(u_long a, u_long b) { return (a > b ? a : b); }
377335c4bemsmithstatic __inline u_long ulmin(u_long a, u_long b) { return (a < b ? a : b); }
378335c4bemsmith
379335c4bemsmith/* null functions for device/filesystem switches (undocumented) */
380335c4bemsmithextern int	nodev(void);
381335c4bemsmithextern int	noioctl(struct open_file *, u_long, void *);
382335c4bemsmithextern void	nullsys(void);
383335c4bemsmith
3843b7700fmsmithextern int	null_open(const char *path, struct open_file *f);
385335c4bemsmithextern int	null_close(struct open_file *f);
386070fb07peterextern int	null_read(struct open_file *f, void *buf, size_t size, size_t *resid);
38723d934dcemextern int	null_write(struct open_file *f, const void *buf, size_t size, size_t *resid);
388335c4bemsmithextern off_t	null_seek(struct open_file *f, off_t offset, int where);
389335c4bemsmithextern int	null_stat(struct open_file *f, struct stat *sb);
3909f5d586jlemonextern int	null_readdir(struct open_file *f, struct dirent *d);
3919f5d586jlemon
392335c4bemsmith
393335c4bemsmith/*
394335c4bemsmith * Machine dependent functions and data, must be provided or stubbed by
395335c4bemsmith * the consumer
396335c4bemsmith */
3970c57de7impextern void		exit(int) __dead2;
398335c4bemsmithextern int		getchar(void);
399335c4bemsmithextern int		ischar(void);
400335c4bemsmithextern void		putchar(int);
401236ad5edfrextern int		devopen(struct open_file *, const char *, const char **);
402335c4bemsmithextern int		devclose(struct open_file *f);
4034446d36jhbextern void		panic(const char *, ...) __dead2 __printflike(1, 2);
4040c57de7impextern void		panic_action(void) __weak_symbol __dead2;
4057641855impextern time_t		getsecs(void);
406335c4bemsmithextern struct fs_ops	*file_system[];
407d8a11bemarcelextern struct fs_ops	*exclusive_file_system;
408335c4bemsmithextern struct devsw	*devsw[];
409335c4bemsmith
410bcee06dmike/*
411bcee06dmike * Expose byteorder(3) functions.
412bcee06dmike */
413b8cc0d1mike#ifndef _BYTEORDER_PROTOTYPED
414b8cc0d1mike#define	_BYTEORDER_PROTOTYPED
415bcee06dmikeextern uint32_t		htonl(uint32_t);
416bcee06dmikeextern uint16_t		htons(uint16_t);
417bcee06dmikeextern uint32_t		ntohl(uint32_t);
418bcee06dmikeextern uint16_t		ntohs(uint16_t);
419b8cc0d1mike#endif
420b8cc0d1mike
421b8cc0d1mike#ifndef _BYTEORDER_FUNC_DEFINED
422b8cc0d1mike#define	_BYTEORDER_FUNC_DEFINED
423b8cc0d1mike#define	htonl(x)	__htonl(x)
424b8cc0d1mike#define	htons(x)	__htons(x)
425b8cc0d1mike#define	ntohl(x)	__ntohl(x)
426b8cc0d1mike#define	ntohs(x)	__ntohs(x)
427b8cc0d1mike#endif
428bcee06dmike
429c718195petervoid *Malloc(size_t, const char *, int);
43005e4fd4tsoomevoid *Memalign(size_t, size_t, const char *, int);
431c718195petervoid *Calloc(size_t, size_t, const char *, int);
432c718195petervoid *Realloc(void *, size_t, const char *, int);
43305e4fd4tsoomevoid *Reallocf(void *, size_t, const char *, int);
434c718195petervoid Free(void *, const char *, int);
4354cfe636tsoomeextern void	mallocstats(void);
436c718195peter
437e7dfb8esjgconst char *x86_hypervisor(void);
438e7dfb8esjg
4395a3b590tsoome#ifdef USER_MALLOC
4405a3b590tsoomeextern void *malloc(size_t);
4415a3b590tsoomeextern void *memalign(size_t, size_t);
4425a3b590tsoomeextern void *calloc(size_t, size_t);
4435a3b590tsoomeextern void free(void *);
4445a3b590tsoomeextern void *realloc(void *, size_t);
4455a3b590tsoomeextern void *reallocf(void *, size_t);
446bd07d9dtsoome#elif defined(DEBUG_MALLOC)
447c718195peter#define malloc(x)	Malloc(x, __FILE__, __LINE__)
44805e4fd4tsoome#define memalign(x, y)	Memalign(x, y, __FILE__, __LINE__)
449c718195peter#define calloc(x, y)	Calloc(x, y, __FILE__, __LINE__)
450c718195peter#define free(x)		Free(x, __FILE__, __LINE__)
451c718195peter#define realloc(x, y)	Realloc(x, y, __FILE__, __LINE__)
4524cfe636tsoome#define reallocf(x, y)	Reallocf(x, y, __FILE__, __LINE__)
453c718195peter#else
4542d2341ascottl#define malloc(x)	Malloc(x, NULL, 0)
45505e4fd4tsoome#define memalign(x, y)	Memalign(x, y, NULL, 0)
456c718195peter#define calloc(x, y)	Calloc(x, y, NULL, 0)
457c718195peter#define free(x)		Free(x, NULL, 0)
458c718195peter#define realloc(x, y)	Realloc(x, y, NULL, 0)
4594cfe636tsoome#define reallocf(x, y)	Reallocf(x, y, NULL, 0)
460236ad5edfr#endif
461c856e4dobrien
462d796054imp/*
463d796054imp * va <-> pa routines. MD code must supply.
464d796054imp */
465d796054impcaddr_t ptov(uintptr_t);
466d796054imp
467c856e4dobrien#endif	/* STAND_H */
468