14a5d661aSToomas Soome /*
24a5d661aSToomas Soome * Copyright (c) 1998 Michael Smith.
34a5d661aSToomas Soome * All rights reserved.
44a5d661aSToomas Soome *
54a5d661aSToomas Soome * Redistribution and use in source and binary forms, with or without
64a5d661aSToomas Soome * modification, are permitted provided that the following conditions
74a5d661aSToomas Soome * are met:
84a5d661aSToomas Soome * 1. Redistributions of source code must retain the above copyright
94a5d661aSToomas Soome * notice, this list of conditions and the following disclaimer.
104a5d661aSToomas Soome * 2. Redistributions in binary form must reproduce the above copyright
114a5d661aSToomas Soome * notice, this list of conditions and the following disclaimer in the
124a5d661aSToomas Soome * documentation and/or other materials provided with the distribution.
134a5d661aSToomas Soome *
144a5d661aSToomas Soome * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
154a5d661aSToomas Soome * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
164a5d661aSToomas Soome * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
174a5d661aSToomas Soome * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
184a5d661aSToomas Soome * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
194a5d661aSToomas Soome * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
204a5d661aSToomas Soome * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
214a5d661aSToomas Soome * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
224a5d661aSToomas Soome * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
234a5d661aSToomas Soome * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
244a5d661aSToomas Soome * SUCH DAMAGE.
254a5d661aSToomas Soome *
264a5d661aSToomas Soome * $FreeBSD$
274a5d661aSToomas Soome * From $NetBSD: stand.h,v 1.22 1997/06/26 19:17:40 drochner Exp $
284a5d661aSToomas Soome */
294a5d661aSToomas Soome
304a5d661aSToomas Soome /*-
314a5d661aSToomas Soome * Copyright (c) 1993
324a5d661aSToomas Soome * The Regents of the University of California. All rights reserved.
334a5d661aSToomas Soome *
344a5d661aSToomas Soome * Redistribution and use in source and binary forms, with or without
354a5d661aSToomas Soome * modification, are permitted provided that the following conditions
364a5d661aSToomas Soome * are met:
374a5d661aSToomas Soome * 1. Redistributions of source code must retain the above copyright
384a5d661aSToomas Soome * notice, this list of conditions and the following disclaimer.
394a5d661aSToomas Soome * 2. Redistributions in binary form must reproduce the above copyright
404a5d661aSToomas Soome * notice, this list of conditions and the following disclaimer in the
414a5d661aSToomas Soome * documentation and/or other materials provided with the distribution.
424a5d661aSToomas Soome * 4. Neither the name of the University nor the names of its contributors
434a5d661aSToomas Soome * may be used to endorse or promote products derived from this software
444a5d661aSToomas Soome * without specific prior written permission.
454a5d661aSToomas Soome *
464a5d661aSToomas Soome * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
474a5d661aSToomas Soome * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
484a5d661aSToomas Soome * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
494a5d661aSToomas Soome * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
504a5d661aSToomas Soome * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
514a5d661aSToomas Soome * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
524a5d661aSToomas Soome * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
534a5d661aSToomas Soome * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
544a5d661aSToomas Soome * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
554a5d661aSToomas Soome * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
564a5d661aSToomas Soome * SUCH DAMAGE.
574a5d661aSToomas Soome *
584a5d661aSToomas Soome * @(#)stand.h 8.1 (Berkeley) 6/11/93
594a5d661aSToomas Soome */
604a5d661aSToomas Soome
614a5d661aSToomas Soome #ifndef STAND_H
624a5d661aSToomas Soome #define STAND_H
634a5d661aSToomas Soome
644a5d661aSToomas Soome #include <sys/types.h>
654a5d661aSToomas Soome #include <sys/cdefs.h>
664a5d661aSToomas Soome #include <sys/stat.h>
674a5d661aSToomas Soome #include <sys/dirent.h>
684a5d661aSToomas Soome
694a5d661aSToomas Soome /* this header intentionally exports NULL from <string.h> */
704a5d661aSToomas Soome #include <string.h>
714a5d661aSToomas Soome
724a5d661aSToomas Soome #define CHK(fmt, args...) printf("%s(%d): " fmt "\n", __func__, __LINE__ , ##args)
734a5d661aSToomas Soome #define PCHK(fmt, args...) {printf("%s(%d): " fmt "\n", __func__, __LINE__ , ##args); getchar();}
744a5d661aSToomas Soome
754a5d661aSToomas Soome /* Avoid unwanted userlandish components */
764a5d661aSToomas Soome #define _KERNEL
774a5d661aSToomas Soome #include <sys/errno.h>
784a5d661aSToomas Soome #undef _KERNEL
794a5d661aSToomas Soome
804a5d661aSToomas Soome /* special stand error codes */
814a5d661aSToomas Soome #define EADAPT (ELAST+1) /* bad adaptor */
824a5d661aSToomas Soome #define ECTLR (ELAST+2) /* bad controller */
834a5d661aSToomas Soome #define EUNIT (ELAST+3) /* bad unit */
844a5d661aSToomas Soome #define ESLICE (ELAST+4) /* bad slice */
854a5d661aSToomas Soome #define EPART (ELAST+5) /* bad partition */
864a5d661aSToomas Soome #define ERDLAB (ELAST+6) /* can't read disk label */
874a5d661aSToomas Soome #define EUNLAB (ELAST+7) /* unlabeled disk */
884a5d661aSToomas Soome #define EOFFSET (ELAST+8) /* relative seek not supported */
894a5d661aSToomas Soome #define ESALAST (ELAST+8) /* */
904a5d661aSToomas Soome
914a5d661aSToomas Soome struct open_file;
924a5d661aSToomas Soome
934a5d661aSToomas Soome /*
944a5d661aSToomas Soome * This structure is used to define file system operations in a file system
954a5d661aSToomas Soome * independent way.
964a5d661aSToomas Soome *
974a5d661aSToomas Soome * XXX note that filesystem providers should export a pointer to their fs_ops
984a5d661aSToomas Soome * struct, so that consumers can reference this and thus include the
994a5d661aSToomas Soome * filesystems that they require.
1004a5d661aSToomas Soome */
1014a5d661aSToomas Soome struct fs_ops {
1024a5d661aSToomas Soome const char *fs_name;
1034a5d661aSToomas Soome int (*fo_open)(const char *path, struct open_file *f);
1044a5d661aSToomas Soome int (*fo_close)(struct open_file *f);
1054a5d661aSToomas Soome int (*fo_read)(struct open_file *f, void *buf,
1064a5d661aSToomas Soome size_t size, size_t *resid);
1074a5d661aSToomas Soome int (*fo_write)(struct open_file *f, void *buf,
1084a5d661aSToomas Soome size_t size, size_t *resid);
1094a5d661aSToomas Soome off_t (*fo_seek)(struct open_file *f, off_t offset, int where);
1104a5d661aSToomas Soome int (*fo_stat)(struct open_file *f, struct stat *sb);
1114a5d661aSToomas Soome int (*fo_readdir)(struct open_file *f, struct dirent *d);
1124a5d661aSToomas Soome };
1134a5d661aSToomas Soome
1144a5d661aSToomas Soome /*
1154a5d661aSToomas Soome * libstand-supplied filesystems
1164a5d661aSToomas Soome */
1174a5d661aSToomas Soome extern struct fs_ops ufs_fsops;
1184a5d661aSToomas Soome extern struct fs_ops tftp_fsops;
1194a5d661aSToomas Soome extern struct fs_ops nfs_fsops;
1204a5d661aSToomas Soome extern struct fs_ops cd9660_fsops;
1214a5d661aSToomas Soome extern struct fs_ops nandfs_fsops;
1224a5d661aSToomas Soome extern struct fs_ops gzipfs_fsops;
1234a5d661aSToomas Soome extern struct fs_ops bzipfs_fsops;
1244a5d661aSToomas Soome extern struct fs_ops dosfs_fsops;
1254a5d661aSToomas Soome extern struct fs_ops ext2fs_fsops;
1264a5d661aSToomas Soome extern struct fs_ops splitfs_fsops;
1274a5d661aSToomas Soome extern struct fs_ops pkgfs_fsops;
1284a5d661aSToomas Soome
1294a5d661aSToomas Soome /* where values for lseek(2) */
1304a5d661aSToomas Soome #define SEEK_SET 0 /* set file offset to offset */
1314a5d661aSToomas Soome #define SEEK_CUR 1 /* set file offset to current plus offset */
1324a5d661aSToomas Soome #define SEEK_END 2 /* set file offset to EOF plus offset */
1334a5d661aSToomas Soome
1344a5d661aSToomas Soome /*
1354a5d661aSToomas Soome * Device switch
1364a5d661aSToomas Soome */
1374a5d661aSToomas Soome struct devsw {
1384a5d661aSToomas Soome const char dv_name[8];
1394a5d661aSToomas Soome int dv_type; /* opaque type constant, arch-dependant */
1404a5d661aSToomas Soome int (*dv_init)(void); /* early probe call */
1414a5d661aSToomas Soome int (*dv_strategy)(void *devdata, int rw, daddr_t blk,
142976852c7SToomas Soome size_t size, char *buf, size_t *rsize);
1434a5d661aSToomas Soome int (*dv_open)(struct open_file *f, ...);
1444a5d661aSToomas Soome int (*dv_close)(struct open_file *f);
1454a5d661aSToomas Soome int (*dv_ioctl)(struct open_file *f, u_long cmd, void *data);
1464a5d661aSToomas Soome int (*dv_print)(int verbose); /* print device information */
1474a5d661aSToomas Soome void (*dv_cleanup)(void);
1484a5d661aSToomas Soome };
1494a5d661aSToomas Soome
1504a5d661aSToomas Soome /*
1514a5d661aSToomas Soome * libstand-supplied device switch
1524a5d661aSToomas Soome */
1534a5d661aSToomas Soome extern struct devsw netdev;
1544a5d661aSToomas Soome
1554a5d661aSToomas Soome extern int errno;
1564a5d661aSToomas Soome
1574a5d661aSToomas Soome /*
1584a5d661aSToomas Soome * Generic device specifier; architecture-dependent
1594a5d661aSToomas Soome * versions may be larger, but should be allowed to
1604a5d661aSToomas Soome * overlap.
1614a5d661aSToomas Soome */
1624a5d661aSToomas Soome struct devdesc
1634a5d661aSToomas Soome {
1644a5d661aSToomas Soome struct devsw *d_dev;
1654a5d661aSToomas Soome int d_type;
1664a5d661aSToomas Soome #define DEVT_NONE 0
1674a5d661aSToomas Soome #define DEVT_DISK 1
1684a5d661aSToomas Soome #define DEVT_NET 2
1694a5d661aSToomas Soome #define DEVT_CD 3
1704a5d661aSToomas Soome #define DEVT_ZFS 4
171*b8767a1dSToomas Soome #define DEVT_FD 5
1724a5d661aSToomas Soome int d_unit;
1734a5d661aSToomas Soome void *d_opendata;
1744a5d661aSToomas Soome };
1754a5d661aSToomas Soome
1764a5d661aSToomas Soome struct open_file {
1774a5d661aSToomas Soome int f_flags; /* see F_* below */
1784a5d661aSToomas Soome struct devsw *f_dev; /* pointer to device operations */
1794a5d661aSToomas Soome void *f_devdata; /* device specific data */
1804a5d661aSToomas Soome struct fs_ops *f_ops; /* pointer to file system operations */
1814a5d661aSToomas Soome void *f_fsdata; /* file system specific data */
1824a5d661aSToomas Soome off_t f_offset; /* current file offset */
1834a5d661aSToomas Soome char *f_rabuf; /* readahead buffer pointer */
1844a5d661aSToomas Soome size_t f_ralen; /* valid data in readahead buffer */
1854a5d661aSToomas Soome off_t f_raoffset; /* consumer offset in readahead buffer */
1864a5d661aSToomas Soome #define SOPEN_RASIZE 512
1874a5d661aSToomas Soome };
1884a5d661aSToomas Soome
1894a5d661aSToomas Soome #define SOPEN_MAX 64
1904a5d661aSToomas Soome extern struct open_file files[];
1914a5d661aSToomas Soome
1924a5d661aSToomas Soome /* f_flags values */
1934a5d661aSToomas Soome #define F_READ 0x0001 /* file opened for reading */
1944a5d661aSToomas Soome #define F_WRITE 0x0002 /* file opened for writing */
1954a5d661aSToomas Soome #define F_RAW 0x0004 /* raw device open - no file system */
1964a5d661aSToomas Soome #define F_NODEV 0x0008 /* network open - no device */
1974a5d661aSToomas Soome #define F_GZIP 0x0010 /* file is compressed by gzip */
1984a5d661aSToomas Soome #define F_BZIP 0x0020 /* file is compressed by bzip */
199a5a5c3b7SToomas Soome #define F_MASK 0xFFFF
200a5a5c3b7SToomas Soome /* Mode modifier for strategy() */
201a5a5c3b7SToomas Soome #define F_NORA (0x01 << 16) /* Disable Read-Ahead */
2024a5d661aSToomas Soome
2034a5d661aSToomas Soome #define isascii(c) (((c) & ~0x7F) == 0)
2044a5d661aSToomas Soome
isupper(int c)2054a5d661aSToomas Soome static __inline int isupper(int c)
2064a5d661aSToomas Soome {
2074a5d661aSToomas Soome return c >= 'A' && c <= 'Z';
2084a5d661aSToomas Soome }
2094a5d661aSToomas Soome
islower(int c)2104a5d661aSToomas Soome static __inline int islower(int c)
2114a5d661aSToomas Soome {
2124a5d661aSToomas Soome return c >= 'a' && c <= 'z';
2134a5d661aSToomas Soome }
2144a5d661aSToomas Soome
isspace(int c)2154a5d661aSToomas Soome static __inline int isspace(int c)
2164a5d661aSToomas Soome {
2174a5d661aSToomas Soome return c == ' ' || (c >= 0x9 && c <= 0xd);
2184a5d661aSToomas Soome }
2194a5d661aSToomas Soome
isdigit(int c)2204a5d661aSToomas Soome static __inline int isdigit(int c)
2214a5d661aSToomas Soome {
2224a5d661aSToomas Soome return c >= '0' && c <= '9';
2234a5d661aSToomas Soome }
2244a5d661aSToomas Soome
isxdigit(int c)2254a5d661aSToomas Soome static __inline int isxdigit(int c)
2264a5d661aSToomas Soome {
2274a5d661aSToomas Soome return isdigit(c) || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F');
2284a5d661aSToomas Soome }
2294a5d661aSToomas Soome
isalpha(int c)2304a5d661aSToomas Soome static __inline int isalpha(int c)
2314a5d661aSToomas Soome {
2324a5d661aSToomas Soome return isupper(c) || islower(c);
2334a5d661aSToomas Soome }
2344a5d661aSToomas Soome
isalnum(int c)2354a5d661aSToomas Soome static __inline int isalnum(int c)
2364a5d661aSToomas Soome {
2374a5d661aSToomas Soome return isalpha(c) || isdigit(c);
2384a5d661aSToomas Soome }
2394a5d661aSToomas Soome
toupper(int c)2404a5d661aSToomas Soome static __inline int toupper(int c)
2414a5d661aSToomas Soome {
2424a5d661aSToomas Soome return islower(c) ? c - 'a' + 'A' : c;
2434a5d661aSToomas Soome }
2444a5d661aSToomas Soome
tolower(int c)2454a5d661aSToomas Soome static __inline int tolower(int c)
2464a5d661aSToomas Soome {
2474a5d661aSToomas Soome return isupper(c) ? c - 'A' + 'a' : c;
2484a5d661aSToomas Soome }
2494a5d661aSToomas Soome
2504a5d661aSToomas Soome /* sbrk emulation */
2514a5d661aSToomas Soome extern void setheap(void *base, void *top);
2524a5d661aSToomas Soome extern char *sbrk(int incr);
2534a5d661aSToomas Soome
2544a5d661aSToomas Soome /* Matt Dillon's zalloc/zmalloc */
2554a5d661aSToomas Soome extern void *malloc(size_t bytes);
2564a5d661aSToomas Soome extern void free(void *ptr);
2574a5d661aSToomas Soome /*#define free(p) {CHK("free %p", p); free(p);} */ /* use for catching guard violations */
2584a5d661aSToomas Soome extern void *calloc(size_t n1, size_t n2);
2594a5d661aSToomas Soome extern void *realloc(void *ptr, size_t size);
2604a5d661aSToomas Soome extern void *reallocf(void *ptr, size_t size);
2614a5d661aSToomas Soome extern void mallocstats(void);
2624a5d661aSToomas Soome
2634a5d661aSToomas Soome extern int printf(const char *fmt, ...) __printflike(1, 2);
2644a5d661aSToomas Soome extern void vprintf(const char *fmt, __va_list);
26545ac0b4bSToomas Soome extern int asprintf(char **buf, const char *cfmt, ...) __printflike(2, 3);
2664a5d661aSToomas Soome extern int sprintf(char *buf, const char *cfmt, ...) __printflike(2, 3);
2674a5d661aSToomas Soome extern int snprintf(char *buf, size_t size, const char *cfmt, ...) __printflike(3, 4);
2684a5d661aSToomas Soome extern void vsprintf(char *buf, const char *cfmt, __va_list);
2694a5d661aSToomas Soome extern void vsnprintf(char *buf, size_t size, const char *cfmt, __va_list);
2704a5d661aSToomas Soome
2714a5d661aSToomas Soome extern void twiddle(u_int callerdiv);
2724a5d661aSToomas Soome extern void twiddle_divisor(u_int globaldiv);
2734a5d661aSToomas Soome
2744a5d661aSToomas Soome extern void ngets(char *, int);
2754a5d661aSToomas Soome #define gets(x) ngets((x), 0)
2764a5d661aSToomas Soome extern int fgetstr(char *buf, int size, int fd);
2774a5d661aSToomas Soome
2784a5d661aSToomas Soome extern int open(const char *, int);
2794a5d661aSToomas Soome #define O_RDONLY 0x0
2804a5d661aSToomas Soome #define O_WRONLY 0x1
2814a5d661aSToomas Soome #define O_RDWR 0x2
2824a5d661aSToomas Soome extern int close(int);
2834a5d661aSToomas Soome extern void closeall(void);
2844a5d661aSToomas Soome extern ssize_t read(int, void *, size_t);
2854a5d661aSToomas Soome extern ssize_t write(int, void *, size_t);
2864a5d661aSToomas Soome extern struct dirent *readdirfd(int);
2874a5d661aSToomas Soome
2884a5d661aSToomas Soome extern void srandom(u_long seed);
2894a5d661aSToomas Soome extern u_long random(void);
2904a5d661aSToomas Soome
2914a5d661aSToomas Soome /* imports from stdlib, locally modified */
2924a5d661aSToomas Soome extern long strtol(const char *, char **, int);
2934a5d661aSToomas Soome extern unsigned long strtoul(const char *, char **, int);
2944a5d661aSToomas Soome extern char *optarg; /* getopt(3) external variables */
2954a5d661aSToomas Soome extern int optind, opterr, optopt, optreset;
2964a5d661aSToomas Soome extern int getopt(int, char * const [], const char *);
2974a5d661aSToomas Soome
2984a5d661aSToomas Soome /* pager.c */
2994a5d661aSToomas Soome extern void pager_open(void);
3004a5d661aSToomas Soome extern void pager_close(void);
3014a5d661aSToomas Soome extern int pager_output(const char *lines);
3024a5d661aSToomas Soome extern int pager_file(const char *fname);
3034a5d661aSToomas Soome
3044a5d661aSToomas Soome /* No signal state to preserve */
3054a5d661aSToomas Soome #define setjmp _setjmp
3064a5d661aSToomas Soome #define longjmp _longjmp
3074a5d661aSToomas Soome
3084a5d661aSToomas Soome /* environment.c */
3094a5d661aSToomas Soome #define EV_DYNAMIC (1<<0) /* value was dynamically allocated, free if changed/unset */
3104a5d661aSToomas Soome #define EV_VOLATILE (1<<1) /* value is volatile, make a copy of it */
3114a5d661aSToomas Soome #define EV_NOHOOK (1<<2) /* don't call hook when setting */
3124a5d661aSToomas Soome
3134a5d661aSToomas Soome struct env_var;
3144a5d661aSToomas Soome typedef char *(ev_format_t)(struct env_var *ev);
3154a5d661aSToomas Soome typedef int (ev_sethook_t)(struct env_var *ev, int flags,
3164a5d661aSToomas Soome const void *value);
3174a5d661aSToomas Soome typedef int (ev_unsethook_t)(struct env_var *ev);
3184a5d661aSToomas Soome
3194a5d661aSToomas Soome struct env_var
3204a5d661aSToomas Soome {
3214a5d661aSToomas Soome char *ev_name;
3224a5d661aSToomas Soome int ev_flags;
3234a5d661aSToomas Soome void *ev_value;
3244a5d661aSToomas Soome ev_sethook_t *ev_sethook;
3254a5d661aSToomas Soome ev_unsethook_t *ev_unsethook;
3264a5d661aSToomas Soome struct env_var *ev_next, *ev_prev;
3274a5d661aSToomas Soome };
3284a5d661aSToomas Soome extern struct env_var *environ;
3294a5d661aSToomas Soome
3304a5d661aSToomas Soome extern struct env_var *env_getenv(const char *name);
3314a5d661aSToomas Soome extern int env_setenv(const char *name, int flags,
3324a5d661aSToomas Soome const void *value, ev_sethook_t sethook,
3334a5d661aSToomas Soome ev_unsethook_t unsethook);
3344a5d661aSToomas Soome extern char *getenv(const char *name);
3354a5d661aSToomas Soome extern int setenv(const char *name, const char *value,
3364a5d661aSToomas Soome int overwrite);
3374a5d661aSToomas Soome extern int putenv(const char *string);
3384a5d661aSToomas Soome extern int unsetenv(const char *name);
3394a5d661aSToomas Soome
3404a5d661aSToomas Soome extern ev_sethook_t env_noset; /* refuse set operation */
3414a5d661aSToomas Soome extern ev_unsethook_t env_nounset; /* refuse unset operation */
3424a5d661aSToomas Soome
3434a5d661aSToomas Soome /* BCD conversions (undocumented) */
3444a5d661aSToomas Soome extern u_char const bcd2bin_data[];
3454a5d661aSToomas Soome extern u_char const bin2bcd_data[];
3464a5d661aSToomas Soome extern char const hex2ascii_data[];
3474a5d661aSToomas Soome
3484a5d661aSToomas Soome #define bcd2bin(bcd) (bcd2bin_data[bcd])
3494a5d661aSToomas Soome #define bin2bcd(bin) (bin2bcd_data[bin])
3504a5d661aSToomas Soome #define hex2ascii(hex) (hex2ascii_data[hex])
3514a5d661aSToomas Soome
3524a5d661aSToomas Soome /* min/max (undocumented) */
imax(int a,int b)3534a5d661aSToomas Soome static __inline int imax(int a, int b) { return (a > b ? a : b); }
imin(int a,int b)3544a5d661aSToomas Soome static __inline int imin(int a, int b) { return (a < b ? a : b); }
lmax(long a,long b)3554a5d661aSToomas Soome static __inline long lmax(long a, long b) { return (a > b ? a : b); }
lmin(long a,long b)3564a5d661aSToomas Soome static __inline long lmin(long a, long b) { return (a < b ? a : b); }
max(u_int a,u_int b)3574a5d661aSToomas Soome static __inline u_int max(u_int a, u_int b) { return (a > b ? a : b); }
min(u_int a,u_int b)3584a5d661aSToomas Soome static __inline u_int min(u_int a, u_int b) { return (a < b ? a : b); }
qmax(quad_t a,quad_t b)3594a5d661aSToomas Soome static __inline quad_t qmax(quad_t a, quad_t b) { return (a > b ? a : b); }
qmin(quad_t a,quad_t b)3604a5d661aSToomas Soome static __inline quad_t qmin(quad_t a, quad_t b) { return (a < b ? a : b); }
ulmax(u_long a,u_long b)3614a5d661aSToomas Soome static __inline u_long ulmax(u_long a, u_long b) { return (a > b ? a : b); }
ulmin(u_long a,u_long b)3624a5d661aSToomas Soome static __inline u_long ulmin(u_long a, u_long b) { return (a < b ? a : b); }
3634a5d661aSToomas Soome
3644a5d661aSToomas Soome /* null functions for device/filesystem switches (undocumented) */
3654a5d661aSToomas Soome extern int nodev(void);
3664a5d661aSToomas Soome extern int noioctl(struct open_file *, u_long, void *);
3674a5d661aSToomas Soome extern void nullsys(void);
3684a5d661aSToomas Soome
3694a5d661aSToomas Soome extern int null_open(const char *path, struct open_file *f);
3704a5d661aSToomas Soome extern int null_close(struct open_file *f);
3714a5d661aSToomas Soome extern int null_read(struct open_file *f, void *buf, size_t size, size_t *resid);
3724a5d661aSToomas Soome extern int null_write(struct open_file *f, void *buf, size_t size, size_t *resid);
3734a5d661aSToomas Soome extern off_t null_seek(struct open_file *f, off_t offset, int where);
3744a5d661aSToomas Soome extern int null_stat(struct open_file *f, struct stat *sb);
3754a5d661aSToomas Soome extern int null_readdir(struct open_file *f, struct dirent *d);
3764a5d661aSToomas Soome
3774a5d661aSToomas Soome
3784a5d661aSToomas Soome /*
3794a5d661aSToomas Soome * Machine dependent functions and data, must be provided or stubbed by
3804a5d661aSToomas Soome * the consumer
3814a5d661aSToomas Soome */
3824a5d661aSToomas Soome extern int getchar(void);
3834a5d661aSToomas Soome extern int ischar(void);
3844a5d661aSToomas Soome extern void putchar(int);
3854a5d661aSToomas Soome extern int devopen(struct open_file *, const char *, const char **);
3864a5d661aSToomas Soome extern int devclose(struct open_file *f);
3874a5d661aSToomas Soome extern void panic(const char *, ...) __dead2 __printflike(1, 2);
3884a5d661aSToomas Soome extern struct fs_ops *file_system[];
3894a5d661aSToomas Soome extern struct fs_ops *exclusive_file_system;
3904a5d661aSToomas Soome extern struct devsw *devsw[];
3914a5d661aSToomas Soome
3924a5d661aSToomas Soome /*
3934a5d661aSToomas Soome * Expose byteorder(3) functions.
3944a5d661aSToomas Soome */
3954a5d661aSToomas Soome #ifndef _BYTEORDER_PROTOTYPED
3964a5d661aSToomas Soome #define _BYTEORDER_PROTOTYPED
3974a5d661aSToomas Soome extern uint32_t htonl(uint32_t);
3984a5d661aSToomas Soome extern uint16_t htons(uint16_t);
3994a5d661aSToomas Soome extern uint32_t ntohl(uint32_t);
4004a5d661aSToomas Soome extern uint16_t ntohs(uint16_t);
4014a5d661aSToomas Soome #endif
4024a5d661aSToomas Soome
4034a5d661aSToomas Soome #ifndef _BYTEORDER_FUNC_DEFINED
4044a5d661aSToomas Soome #define _BYTEORDER_FUNC_DEFINED
4054a5d661aSToomas Soome #define htonl(x) __htonl(x)
4064a5d661aSToomas Soome #define htons(x) __htons(x)
4074a5d661aSToomas Soome #define ntohl(x) __ntohl(x)
4084a5d661aSToomas Soome #define ntohs(x) __ntohs(x)
4094a5d661aSToomas Soome #endif
4104a5d661aSToomas Soome
4114a5d661aSToomas Soome void *Malloc(size_t, const char *, int);
4124a5d661aSToomas Soome void *Calloc(size_t, size_t, const char *, int);
4134a5d661aSToomas Soome void *Realloc(void *, size_t, const char *, int);
4144a5d661aSToomas Soome void Free(void *, const char *, int);
4154a5d661aSToomas Soome
4164a5d661aSToomas Soome #if 1
4174a5d661aSToomas Soome #define malloc(x) Malloc(x, __FILE__, __LINE__)
4184a5d661aSToomas Soome #define calloc(x, y) Calloc(x, y, __FILE__, __LINE__)
4194a5d661aSToomas Soome #define free(x) Free(x, __FILE__, __LINE__)
4204a5d661aSToomas Soome #define realloc(x, y) Realloc(x, y, __FILE__, __LINE__)
4214a5d661aSToomas Soome #else
4224a5d661aSToomas Soome #define malloc(x) Malloc(x, NULL, 0)
4234a5d661aSToomas Soome #define calloc(x, y) Calloc(x, y, NULL, 0)
4244a5d661aSToomas Soome #define free(x) Free(x, NULL, 0)
4254a5d661aSToomas Soome #define realloc(x, y) Realloc(x, y, NULL, 0)
4264a5d661aSToomas Soome #endif
4274a5d661aSToomas Soome
4284a5d661aSToomas Soome #endif /* STAND_H */
429