1ca987d46SWarner Losh /* 2ca987d46SWarner Losh * Copyright (c) 1998 Michael Smith. 3ca987d46SWarner Losh * All rights reserved. 4ca987d46SWarner Losh * 5ca987d46SWarner Losh * Redistribution and use in source and binary forms, with or without 6ca987d46SWarner Losh * modification, are permitted provided that the following conditions 7ca987d46SWarner Losh * are met: 8ca987d46SWarner Losh * 1. Redistributions of source code must retain the above copyright 9ca987d46SWarner Losh * notice, this list of conditions and the following disclaimer. 10ca987d46SWarner Losh * 2. Redistributions in binary form must reproduce the above copyright 11ca987d46SWarner Losh * notice, this list of conditions and the following disclaimer in the 12ca987d46SWarner Losh * documentation and/or other materials provided with the distribution. 13ca987d46SWarner Losh * 14ca987d46SWarner Losh * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15ca987d46SWarner Losh * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16ca987d46SWarner Losh * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17ca987d46SWarner Losh * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18ca987d46SWarner Losh * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19ca987d46SWarner Losh * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20ca987d46SWarner Losh * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21ca987d46SWarner Losh * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22ca987d46SWarner Losh * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23ca987d46SWarner Losh * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24ca987d46SWarner Losh * SUCH DAMAGE. 25ca987d46SWarner Losh * 26ca987d46SWarner Losh * $FreeBSD$ 27ca987d46SWarner Losh * From $NetBSD: stand.h,v 1.22 1997/06/26 19:17:40 drochner Exp $ 28ca987d46SWarner Losh */ 29ca987d46SWarner Losh 30ca987d46SWarner Losh /*- 31ca987d46SWarner Losh * Copyright (c) 1993 32ca987d46SWarner Losh * The Regents of the University of California. All rights reserved. 33ca987d46SWarner Losh * 34ca987d46SWarner Losh * Redistribution and use in source and binary forms, with or without 35ca987d46SWarner Losh * modification, are permitted provided that the following conditions 36ca987d46SWarner Losh * are met: 37ca987d46SWarner Losh * 1. Redistributions of source code must retain the above copyright 38ca987d46SWarner Losh * notice, this list of conditions and the following disclaimer. 39ca987d46SWarner Losh * 2. Redistributions in binary form must reproduce the above copyright 40ca987d46SWarner Losh * notice, this list of conditions and the following disclaimer in the 41ca987d46SWarner Losh * documentation and/or other materials provided with the distribution. 42ca987d46SWarner Losh * 3. Neither the name of the University nor the names of its contributors 43ca987d46SWarner Losh * may be used to endorse or promote products derived from this software 44ca987d46SWarner Losh * without specific prior written permission. 45ca987d46SWarner Losh * 46ca987d46SWarner Losh * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 47ca987d46SWarner Losh * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 48ca987d46SWarner Losh * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 49ca987d46SWarner Losh * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 50ca987d46SWarner Losh * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 51ca987d46SWarner Losh * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 52ca987d46SWarner Losh * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 53ca987d46SWarner Losh * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 54ca987d46SWarner Losh * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 55ca987d46SWarner Losh * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 56ca987d46SWarner Losh * SUCH DAMAGE. 57ca987d46SWarner Losh * 58ca987d46SWarner Losh * @(#)stand.h 8.1 (Berkeley) 6/11/93 59ca987d46SWarner Losh */ 60ca987d46SWarner Losh 61ca987d46SWarner Losh #ifndef STAND_H 62ca987d46SWarner Losh #define STAND_H 63ca987d46SWarner Losh 64ca987d46SWarner Losh #include <sys/types.h> 65ca987d46SWarner Losh #include <sys/cdefs.h> 66ca987d46SWarner Losh #include <sys/stat.h> 67ca987d46SWarner Losh #include <sys/dirent.h> 68ca987d46SWarner Losh 69ca987d46SWarner Losh /* this header intentionally exports NULL from <string.h> */ 70ca987d46SWarner Losh #include <string.h> 71c7b46ba4SWarner Losh #define strcoll(a, b) strcmp((a), (b)) 72ca987d46SWarner Losh 73ca987d46SWarner Losh #define CHK(fmt, args...) printf("%s(%d): " fmt "\n", __func__, __LINE__ , ##args) 74ca987d46SWarner Losh #define PCHK(fmt, args...) {printf("%s(%d): " fmt "\n", __func__, __LINE__ , ##args); getchar();} 75ca987d46SWarner Losh 76ca987d46SWarner Losh #include <sys/errno.h> 77ca987d46SWarner Losh 78ca987d46SWarner Losh /* special stand error codes */ 79ca987d46SWarner Losh #define EADAPT (ELAST+1) /* bad adaptor */ 80ca987d46SWarner Losh #define ECTLR (ELAST+2) /* bad controller */ 81ca987d46SWarner Losh #define EUNIT (ELAST+3) /* bad unit */ 82ca987d46SWarner Losh #define ESLICE (ELAST+4) /* bad slice */ 83ca987d46SWarner Losh #define EPART (ELAST+5) /* bad partition */ 84ca987d46SWarner Losh #define ERDLAB (ELAST+6) /* can't read disk label */ 85ca987d46SWarner Losh #define EUNLAB (ELAST+7) /* unlabeled disk */ 86ca987d46SWarner Losh #define EOFFSET (ELAST+8) /* relative seek not supported */ 87ca987d46SWarner Losh #define ESALAST (ELAST+8) /* */ 88ca987d46SWarner Losh 8949cb0130SWarner Losh /* Partial signal emulation for sig_atomic_t */ 9049cb0130SWarner Losh #include <machine/signal.h> 9149cb0130SWarner Losh 92ca987d46SWarner Losh struct open_file; 93ca987d46SWarner Losh 94ca987d46SWarner Losh /* 95ca987d46SWarner Losh * This structure is used to define file system operations in a file system 96ca987d46SWarner Losh * independent way. 97ca987d46SWarner Losh * 98ca987d46SWarner Losh * XXX note that filesystem providers should export a pointer to their fs_ops 99ca987d46SWarner Losh * struct, so that consumers can reference this and thus include the 100ca987d46SWarner Losh * filesystems that they require. 101ca987d46SWarner Losh */ 102ca987d46SWarner Losh struct fs_ops { 103ca987d46SWarner Losh const char *fs_name; 104ca987d46SWarner Losh int (*fo_open)(const char *path, struct open_file *f); 105ca987d46SWarner Losh int (*fo_close)(struct open_file *f); 106ca987d46SWarner Losh int (*fo_read)(struct open_file *f, void *buf, 107ca987d46SWarner Losh size_t size, size_t *resid); 1082e7e6fbcSConrad Meyer int (*fo_write)(struct open_file *f, const void *buf, 109ca987d46SWarner Losh size_t size, size_t *resid); 110ca987d46SWarner Losh off_t (*fo_seek)(struct open_file *f, off_t offset, int where); 111ca987d46SWarner Losh int (*fo_stat)(struct open_file *f, struct stat *sb); 112ca987d46SWarner Losh int (*fo_readdir)(struct open_file *f, struct dirent *d); 113ca987d46SWarner Losh }; 114ca987d46SWarner Losh 115ca987d46SWarner Losh /* 116ca987d46SWarner Losh * libstand-supplied filesystems 117ca987d46SWarner Losh */ 118ca987d46SWarner Losh extern struct fs_ops ufs_fsops; 119ca987d46SWarner Losh extern struct fs_ops tftp_fsops; 120ca987d46SWarner Losh extern struct fs_ops nfs_fsops; 121ca987d46SWarner Losh extern struct fs_ops cd9660_fsops; 122ca987d46SWarner Losh extern struct fs_ops gzipfs_fsops; 123ca987d46SWarner Losh extern struct fs_ops bzipfs_fsops; 124ca987d46SWarner Losh extern struct fs_ops dosfs_fsops; 125ca987d46SWarner Losh extern struct fs_ops ext2fs_fsops; 126ca987d46SWarner Losh extern struct fs_ops splitfs_fsops; 127ca987d46SWarner Losh extern struct fs_ops pkgfs_fsops; 128da4961c7SRebecca Cran extern struct fs_ops efihttp_fsops; 129ca987d46SWarner Losh 130ca987d46SWarner Losh /* where values for lseek(2) */ 131ca987d46SWarner Losh #define SEEK_SET 0 /* set file offset to offset */ 132ca987d46SWarner Losh #define SEEK_CUR 1 /* set file offset to current plus offset */ 133ca987d46SWarner Losh #define SEEK_END 2 /* set file offset to EOF plus offset */ 134ca987d46SWarner Losh 135ca987d46SWarner Losh /* 136ca987d46SWarner Losh * Device switch 137ca987d46SWarner Losh */ 138ca987d46SWarner Losh struct devsw { 139ca987d46SWarner Losh const char dv_name[8]; 140ca987d46SWarner Losh int dv_type; /* opaque type constant, arch-dependant */ 141b3a2aad1SWarner Losh #define DEVT_NONE 0 142b3a2aad1SWarner Losh #define DEVT_DISK 1 143b3a2aad1SWarner Losh #define DEVT_NET 2 144b3a2aad1SWarner Losh #define DEVT_CD 3 145b3a2aad1SWarner Losh #define DEVT_ZFS 4 146b3a2aad1SWarner Losh #define DEVT_FD 5 147ca987d46SWarner Losh int (*dv_init)(void); /* early probe call */ 148ca987d46SWarner Losh int (*dv_strategy)(void *devdata, int rw, daddr_t blk, 149ca987d46SWarner Losh size_t size, char *buf, size_t *rsize); 150ca987d46SWarner Losh int (*dv_open)(struct open_file *f, ...); 151ca987d46SWarner Losh int (*dv_close)(struct open_file *f); 152ca987d46SWarner Losh int (*dv_ioctl)(struct open_file *f, u_long cmd, void *data); 153ca987d46SWarner Losh int (*dv_print)(int verbose); /* print device information */ 154ca987d46SWarner Losh void (*dv_cleanup)(void); 155ca987d46SWarner Losh }; 156ca987d46SWarner Losh 157ca987d46SWarner Losh /* 158ca987d46SWarner Losh * libstand-supplied device switch 159ca987d46SWarner Losh */ 160ca987d46SWarner Losh extern struct devsw netdev; 161ca987d46SWarner Losh 162ca987d46SWarner Losh extern int errno; 163ca987d46SWarner Losh 164ca987d46SWarner Losh /* 165ca987d46SWarner Losh * Generic device specifier; architecture-dependent 166ca987d46SWarner Losh * versions may be larger, but should be allowed to 167ca987d46SWarner Losh * overlap. 168ca987d46SWarner Losh */ 169b3a2aad1SWarner Losh struct devdesc { 170ca987d46SWarner Losh struct devsw *d_dev; 171ca987d46SWarner Losh int d_unit; 172ca987d46SWarner Losh void *d_opendata; 173ca987d46SWarner Losh }; 174ca987d46SWarner Losh 175ca987d46SWarner Losh struct open_file { 176ca987d46SWarner Losh int f_flags; /* see F_* below */ 177ca987d46SWarner Losh struct devsw *f_dev; /* pointer to device operations */ 178ca987d46SWarner Losh void *f_devdata; /* device specific data */ 179ca987d46SWarner Losh struct fs_ops *f_ops; /* pointer to file system operations */ 180ca987d46SWarner Losh void *f_fsdata; /* file system specific data */ 181ca987d46SWarner Losh off_t f_offset; /* current file offset */ 182ca987d46SWarner Losh char *f_rabuf; /* readahead buffer pointer */ 183ca987d46SWarner Losh size_t f_ralen; /* valid data in readahead buffer */ 184ca987d46SWarner Losh off_t f_raoffset; /* consumer offset in readahead buffer */ 185ca987d46SWarner Losh #define SOPEN_RASIZE 512 186ca987d46SWarner Losh }; 187ca987d46SWarner Losh 188ca987d46SWarner Losh #define SOPEN_MAX 64 189ca987d46SWarner Losh extern struct open_file files[]; 190ca987d46SWarner Losh 191ca987d46SWarner Losh /* f_flags values */ 192ca987d46SWarner Losh #define F_READ 0x0001 /* file opened for reading */ 193ca987d46SWarner Losh #define F_WRITE 0x0002 /* file opened for writing */ 194ca987d46SWarner Losh #define F_RAW 0x0004 /* raw device open - no file system */ 195ca987d46SWarner Losh #define F_NODEV 0x0008 /* network open - no device */ 196ca987d46SWarner Losh #define F_MASK 0xFFFF 197ca987d46SWarner Losh /* Mode modifier for strategy() */ 198ca987d46SWarner Losh #define F_NORA (0x01 << 16) /* Disable Read-Ahead */ 199ca987d46SWarner Losh 200ca987d46SWarner Losh #define isascii(c) (((c) & ~0x7F) == 0) 201ca987d46SWarner Losh 202ca987d46SWarner Losh static __inline int isupper(int c) 203ca987d46SWarner Losh { 204ca987d46SWarner Losh return c >= 'A' && c <= 'Z'; 205ca987d46SWarner Losh } 206ca987d46SWarner Losh 207ca987d46SWarner Losh static __inline int islower(int c) 208ca987d46SWarner Losh { 209ca987d46SWarner Losh return c >= 'a' && c <= 'z'; 210ca987d46SWarner Losh } 211ca987d46SWarner Losh 212ca987d46SWarner Losh static __inline int isspace(int c) 213ca987d46SWarner Losh { 214ca987d46SWarner Losh return c == ' ' || (c >= 0x9 && c <= 0xd); 215ca987d46SWarner Losh } 216ca987d46SWarner Losh 217ca987d46SWarner Losh static __inline int isdigit(int c) 218ca987d46SWarner Losh { 219ca987d46SWarner Losh return c >= '0' && c <= '9'; 220ca987d46SWarner Losh } 221ca987d46SWarner Losh 222ca987d46SWarner Losh static __inline int isxdigit(int c) 223ca987d46SWarner Losh { 224ca987d46SWarner Losh return isdigit(c) || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F'); 225ca987d46SWarner Losh } 226ca987d46SWarner Losh 227ca987d46SWarner Losh static __inline int isalpha(int c) 228ca987d46SWarner Losh { 229ca987d46SWarner Losh return isupper(c) || islower(c); 230ca987d46SWarner Losh } 231ca987d46SWarner Losh 232ca987d46SWarner Losh static __inline int isalnum(int c) 233ca987d46SWarner Losh { 234ca987d46SWarner Losh return isalpha(c) || isdigit(c); 235ca987d46SWarner Losh } 236ca987d46SWarner Losh 2376856cf68SWarner Losh static __inline int iscntrl(int c) 2386856cf68SWarner Losh { 2396856cf68SWarner Losh return (c >= 0 && c < ' ') || c == 127; 2406856cf68SWarner Losh } 2416856cf68SWarner Losh 2426856cf68SWarner Losh static __inline int isgraph(int c) 2436856cf68SWarner Losh { 2446856cf68SWarner Losh return c >= '!' && c <= '~'; 2456856cf68SWarner Losh } 2466856cf68SWarner Losh 2476856cf68SWarner Losh static __inline int ispunct(int c) 2486856cf68SWarner Losh { 2496856cf68SWarner Losh return (c >= '!' && c <= '/') || (c >= ':' && c <= '@') || 2506856cf68SWarner Losh (c >= '[' && c <= '`') || (c >= '{' && c <= '~'); 2516856cf68SWarner Losh } 2526856cf68SWarner Losh 253ca987d46SWarner Losh static __inline int toupper(int c) 254ca987d46SWarner Losh { 255ca987d46SWarner Losh return islower(c) ? c - 'a' + 'A' : c; 256ca987d46SWarner Losh } 257ca987d46SWarner Losh 258ca987d46SWarner Losh static __inline int tolower(int c) 259ca987d46SWarner Losh { 260ca987d46SWarner Losh return isupper(c) ? c - 'A' + 'a' : c; 261ca987d46SWarner Losh } 262ca987d46SWarner Losh 263ca987d46SWarner Losh /* sbrk emulation */ 264ca987d46SWarner Losh extern void setheap(void *base, void *top); 265ca987d46SWarner Losh extern char *sbrk(int incr); 266ca987d46SWarner Losh 267ca987d46SWarner Losh extern int printf(const char *fmt, ...) __printflike(1, 2); 2685e84b578SToomas Soome extern int asprintf(char **buf, const char *cfmt, ...) __printflike(2, 3); 269ca987d46SWarner Losh extern int sprintf(char *buf, const char *cfmt, ...) __printflike(2, 3); 270ca987d46SWarner Losh extern int snprintf(char *buf, size_t size, const char *cfmt, ...) __printflike(3, 4); 2713e9c7874SIan Lepore extern int vprintf(const char *fmt, __va_list); 2723e9c7874SIan Lepore extern int vsprintf(char *buf, const char *cfmt, __va_list); 2733e9c7874SIan Lepore extern int vsnprintf(char *buf, size_t size, const char *cfmt, __va_list); 274ca987d46SWarner Losh 275ca987d46SWarner Losh extern void twiddle(u_int callerdiv); 276ca987d46SWarner Losh extern void twiddle_divisor(u_int globaldiv); 277ca987d46SWarner Losh 278ca987d46SWarner Losh extern void ngets(char *, int); 279ca987d46SWarner Losh #define gets(x) ngets((x), 0) 280ca987d46SWarner Losh extern int fgetstr(char *buf, int size, int fd); 281ca987d46SWarner Losh 282ca987d46SWarner Losh extern int open(const char *, int); 283ca987d46SWarner Losh #define O_RDONLY 0x0 284ca987d46SWarner Losh #define O_WRONLY 0x1 285ca987d46SWarner Losh #define O_RDWR 0x2 2862ef9ff7dSSimon J. Gerraty #define O_ACCMODE 0x3 28782c85a42SKyle Evans /* NOT IMPLEMENTED */ 28882c85a42SKyle Evans #define O_CREAT 0x0200 /* create if nonexistent */ 28982c85a42SKyle Evans #define O_TRUNC 0x0400 /* truncate to zero length */ 290ca987d46SWarner Losh extern int close(int); 291ca987d46SWarner Losh extern void closeall(void); 292ca987d46SWarner Losh extern ssize_t read(int, void *, size_t); 293061577c5SConrad Meyer extern ssize_t write(int, const void *, size_t); 294ca987d46SWarner Losh extern struct dirent *readdirfd(int); 295ca987d46SWarner Losh 296dcaa2d76SWarner Losh extern void srandom(unsigned int); 297e294a126SWarner Losh extern long random(void); 298ca987d46SWarner Losh 299ca987d46SWarner Losh /* imports from stdlib, locally modified */ 300ca987d46SWarner Losh extern char *optarg; /* getopt(3) external variables */ 301ca987d46SWarner Losh extern int optind, opterr, optopt, optreset; 302ca987d46SWarner Losh extern int getopt(int, char * const [], const char *); 303ca987d46SWarner Losh 304ca987d46SWarner Losh /* pager.c */ 305ca987d46SWarner Losh extern void pager_open(void); 306ca987d46SWarner Losh extern void pager_close(void); 307ca987d46SWarner Losh extern int pager_output(const char *lines); 308ca987d46SWarner Losh extern int pager_file(const char *fname); 309ca987d46SWarner Losh 310ca987d46SWarner Losh /* No signal state to preserve */ 311ca987d46SWarner Losh #define setjmp _setjmp 312ca987d46SWarner Losh #define longjmp _longjmp 313ca987d46SWarner Losh 314ca987d46SWarner Losh /* environment.c */ 315ca987d46SWarner Losh #define EV_DYNAMIC (1<<0) /* value was dynamically allocated, free if changed/unset */ 316ca987d46SWarner Losh #define EV_VOLATILE (1<<1) /* value is volatile, make a copy of it */ 317ca987d46SWarner Losh #define EV_NOHOOK (1<<2) /* don't call hook when setting */ 318ca987d46SWarner Losh 319ca987d46SWarner Losh struct env_var; 320ca987d46SWarner Losh typedef char *(ev_format_t)(struct env_var *ev); 321ca987d46SWarner Losh typedef int (ev_sethook_t)(struct env_var *ev, int flags, 322ca987d46SWarner Losh const void *value); 323ca987d46SWarner Losh typedef int (ev_unsethook_t)(struct env_var *ev); 324ca987d46SWarner Losh 325ca987d46SWarner Losh struct env_var 326ca987d46SWarner Losh { 327ca987d46SWarner Losh char *ev_name; 328ca987d46SWarner Losh int ev_flags; 329ca987d46SWarner Losh void *ev_value; 330ca987d46SWarner Losh ev_sethook_t *ev_sethook; 331ca987d46SWarner Losh ev_unsethook_t *ev_unsethook; 332ca987d46SWarner Losh struct env_var *ev_next, *ev_prev; 333ca987d46SWarner Losh }; 334ca987d46SWarner Losh extern struct env_var *environ; 335ca987d46SWarner Losh 336ca987d46SWarner Losh extern struct env_var *env_getenv(const char *name); 337ca987d46SWarner Losh extern int env_setenv(const char *name, int flags, 338ca987d46SWarner Losh const void *value, ev_sethook_t sethook, 339ca987d46SWarner Losh ev_unsethook_t unsethook); 340588f0a1eSToomas Soome extern void env_discard(struct env_var *); 341ca987d46SWarner Losh extern char *getenv(const char *name); 342ca987d46SWarner Losh extern int setenv(const char *name, const char *value, 343ca987d46SWarner Losh int overwrite); 344e8e6a5f9SWarner Losh extern int putenv(char *string); 345ca987d46SWarner Losh extern int unsetenv(const char *name); 346ca987d46SWarner Losh 347ca987d46SWarner Losh extern ev_sethook_t env_noset; /* refuse set operation */ 348ca987d46SWarner Losh extern ev_unsethook_t env_nounset; /* refuse unset operation */ 349ca987d46SWarner Losh 3502b0268cfSWarner Losh /* stdlib.h routines */ 35124dfa658SWarner Losh extern int abs(int a); 35230883627SWarner Losh extern void abort(void) __dead2; 3533a8a081bSWarner Losh extern long strtol(const char * __restrict, char ** __restrict, int); 3543a8a081bSWarner Losh extern long long strtoll(const char * __restrict, char ** __restrict, int); 3553a8a081bSWarner Losh extern unsigned long strtoul(const char * __restrict, char ** __restrict, int); 3563a8a081bSWarner Losh extern unsigned long long strtoull(const char * __restrict, char ** __restrict, int); 3572b0268cfSWarner Losh 358ca987d46SWarner Losh /* BCD conversions (undocumented) */ 359ca987d46SWarner Losh extern u_char const bcd2bin_data[]; 360ca987d46SWarner Losh extern u_char const bin2bcd_data[]; 361ca987d46SWarner Losh extern char const hex2ascii_data[]; 362ca987d46SWarner Losh 363ca987d46SWarner Losh #define bcd2bin(bcd) (bcd2bin_data[bcd]) 364ca987d46SWarner Losh #define bin2bcd(bin) (bin2bcd_data[bin]) 365ca987d46SWarner Losh #define hex2ascii(hex) (hex2ascii_data[hex]) 366b6f4732cSIan Lepore #define validbcd(bcd) (bcd == 0 || (bcd > 0 && bcd <= 0x99 && bcd2bin_data[bcd] != 0)) 367ca987d46SWarner Losh 368ca987d46SWarner Losh /* min/max (undocumented) */ 369ca987d46SWarner Losh static __inline int imax(int a, int b) { return (a > b ? a : b); } 370ca987d46SWarner Losh static __inline int imin(int a, int b) { return (a < b ? a : b); } 371ca987d46SWarner Losh static __inline long lmax(long a, long b) { return (a > b ? a : b); } 372ca987d46SWarner Losh static __inline long lmin(long a, long b) { return (a < b ? a : b); } 373ca987d46SWarner Losh static __inline u_int max(u_int a, u_int b) { return (a > b ? a : b); } 374ca987d46SWarner Losh static __inline u_int min(u_int a, u_int b) { return (a < b ? a : b); } 375ca987d46SWarner Losh static __inline quad_t qmax(quad_t a, quad_t b) { return (a > b ? a : b); } 376ca987d46SWarner Losh static __inline quad_t qmin(quad_t a, quad_t b) { return (a < b ? a : b); } 377ca987d46SWarner Losh static __inline u_long ulmax(u_long a, u_long b) { return (a > b ? a : b); } 378ca987d46SWarner Losh static __inline u_long ulmin(u_long a, u_long b) { return (a < b ? a : b); } 379ca987d46SWarner Losh 380ca987d46SWarner Losh /* null functions for device/filesystem switches (undocumented) */ 381ca987d46SWarner Losh extern int nodev(void); 382ca987d46SWarner Losh extern int noioctl(struct open_file *, u_long, void *); 383ca987d46SWarner Losh extern void nullsys(void); 384ca987d46SWarner Losh 385ca987d46SWarner Losh extern int null_open(const char *path, struct open_file *f); 386ca987d46SWarner Losh extern int null_close(struct open_file *f); 387ca987d46SWarner Losh extern int null_read(struct open_file *f, void *buf, size_t size, size_t *resid); 3882e7e6fbcSConrad Meyer extern int null_write(struct open_file *f, const void *buf, size_t size, size_t *resid); 389ca987d46SWarner Losh extern off_t null_seek(struct open_file *f, off_t offset, int where); 390ca987d46SWarner Losh extern int null_stat(struct open_file *f, struct stat *sb); 391ca987d46SWarner Losh extern int null_readdir(struct open_file *f, struct dirent *d); 392ca987d46SWarner Losh 393ca987d46SWarner Losh 394ca987d46SWarner Losh /* 395ca987d46SWarner Losh * Machine dependent functions and data, must be provided or stubbed by 396ca987d46SWarner Losh * the consumer 397ca987d46SWarner Losh */ 39886bb84d5SWarner Losh extern void exit(int) __dead2; 399ca987d46SWarner Losh extern int getchar(void); 400ca987d46SWarner Losh extern int ischar(void); 401ca987d46SWarner Losh extern void putchar(int); 402ca987d46SWarner Losh extern int devopen(struct open_file *, const char *, const char **); 403ca987d46SWarner Losh extern int devclose(struct open_file *f); 404ca987d46SWarner Losh extern void panic(const char *, ...) __dead2 __printflike(1, 2); 40586bb84d5SWarner Losh extern void panic_action(void) __weak_symbol __dead2; 40631d05586SWarner Losh extern time_t getsecs(void); 407ca987d46SWarner Losh extern struct fs_ops *file_system[]; 408ca987d46SWarner Losh extern struct fs_ops *exclusive_file_system; 409ca987d46SWarner Losh extern struct devsw *devsw[]; 410ca987d46SWarner Losh 411ca987d46SWarner Losh /* 412*b9c5b432SWarner Losh * Time routines 413*b9c5b432SWarner Losh */ 414*b9c5b432SWarner Losh time_t time(time_t *); 415*b9c5b432SWarner Losh 416*b9c5b432SWarner Losh /* 417ca987d46SWarner Losh * Expose byteorder(3) functions. 418ca987d46SWarner Losh */ 419ca987d46SWarner Losh #ifndef _BYTEORDER_PROTOTYPED 420ca987d46SWarner Losh #define _BYTEORDER_PROTOTYPED 421ca987d46SWarner Losh extern uint32_t htonl(uint32_t); 422ca987d46SWarner Losh extern uint16_t htons(uint16_t); 423ca987d46SWarner Losh extern uint32_t ntohl(uint32_t); 424ca987d46SWarner Losh extern uint16_t ntohs(uint16_t); 425ca987d46SWarner Losh #endif 426ca987d46SWarner Losh 427ca987d46SWarner Losh #ifndef _BYTEORDER_FUNC_DEFINED 428ca987d46SWarner Losh #define _BYTEORDER_FUNC_DEFINED 429ca987d46SWarner Losh #define htonl(x) __htonl(x) 430ca987d46SWarner Losh #define htons(x) __htons(x) 431ca987d46SWarner Losh #define ntohl(x) __ntohl(x) 432ca987d46SWarner Losh #define ntohs(x) __ntohs(x) 433ca987d46SWarner Losh #endif 434ca987d46SWarner Losh 435ca987d46SWarner Losh void *Malloc(size_t, const char *, int); 43611db1a16SToomas Soome void *Memalign(size_t, size_t, const char *, int); 437ca987d46SWarner Losh void *Calloc(size_t, size_t, const char *, int); 438ca987d46SWarner Losh void *Realloc(void *, size_t, const char *, int); 43911db1a16SToomas Soome void *Reallocf(void *, size_t, const char *, int); 440ca987d46SWarner Losh void Free(void *, const char *, int); 44162ea4c11SToomas Soome extern void mallocstats(void); 442ca987d46SWarner Losh 443e9b148a3SSimon J. Gerraty const char *x86_hypervisor(void); 444e9b148a3SSimon J. Gerraty 445c907ec9eSToomas Soome #ifdef USER_MALLOC 446c907ec9eSToomas Soome extern void *malloc(size_t); 447c907ec9eSToomas Soome extern void *memalign(size_t, size_t); 448c907ec9eSToomas Soome extern void *calloc(size_t, size_t); 449c907ec9eSToomas Soome extern void free(void *); 450c907ec9eSToomas Soome extern void *realloc(void *, size_t); 451c907ec9eSToomas Soome extern void *reallocf(void *, size_t); 4525292d0a7SToomas Soome #elif defined(DEBUG_MALLOC) 453ca987d46SWarner Losh #define malloc(x) Malloc(x, __FILE__, __LINE__) 45411db1a16SToomas Soome #define memalign(x, y) Memalign(x, y, __FILE__, __LINE__) 455ca987d46SWarner Losh #define calloc(x, y) Calloc(x, y, __FILE__, __LINE__) 456ca987d46SWarner Losh #define free(x) Free(x, __FILE__, __LINE__) 457ca987d46SWarner Losh #define realloc(x, y) Realloc(x, y, __FILE__, __LINE__) 45862ea4c11SToomas Soome #define reallocf(x, y) Reallocf(x, y, __FILE__, __LINE__) 459ca987d46SWarner Losh #else 460ca987d46SWarner Losh #define malloc(x) Malloc(x, NULL, 0) 46111db1a16SToomas Soome #define memalign(x, y) Memalign(x, y, NULL, 0) 462ca987d46SWarner Losh #define calloc(x, y) Calloc(x, y, NULL, 0) 463ca987d46SWarner Losh #define free(x) Free(x, NULL, 0) 464ca987d46SWarner Losh #define realloc(x, y) Realloc(x, y, NULL, 0) 46562ea4c11SToomas Soome #define reallocf(x, y) Reallocf(x, y, NULL, 0) 466ca987d46SWarner Losh #endif 467ca987d46SWarner Losh 468ed2a6576SWarner Losh /* 469ed2a6576SWarner Losh * va <-> pa routines. MD code must supply. 470ed2a6576SWarner Losh */ 471ed2a6576SWarner Losh caddr_t ptov(uintptr_t); 472ed2a6576SWarner Losh 473ca987d46SWarner Losh #endif /* STAND_H */ 474