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> 6897cbd5e7SToomas Soome #include <sys/queue.h> 69ca987d46SWarner Losh 70ca987d46SWarner Losh /* this header intentionally exports NULL from <string.h> */ 71ca987d46SWarner Losh #include <string.h> 72c7b46ba4SWarner Losh #define strcoll(a, b) strcmp((a), (b)) 73ca987d46SWarner Losh 74ca987d46SWarner Losh #define CHK(fmt, args...) printf("%s(%d): " fmt "\n", __func__, __LINE__ , ##args) 75ca987d46SWarner Losh #define PCHK(fmt, args...) {printf("%s(%d): " fmt "\n", __func__, __LINE__ , ##args); getchar();} 76ca987d46SWarner Losh 77ca987d46SWarner Losh #include <sys/errno.h> 78ca987d46SWarner Losh 79ca987d46SWarner Losh /* special stand error codes */ 80ca987d46SWarner Losh #define EADAPT (ELAST+1) /* bad adaptor */ 81ca987d46SWarner Losh #define ECTLR (ELAST+2) /* bad controller */ 82ca987d46SWarner Losh #define EUNIT (ELAST+3) /* bad unit */ 83ca987d46SWarner Losh #define ESLICE (ELAST+4) /* bad slice */ 84ca987d46SWarner Losh #define EPART (ELAST+5) /* bad partition */ 85ca987d46SWarner Losh #define ERDLAB (ELAST+6) /* can't read disk label */ 86ca987d46SWarner Losh #define EUNLAB (ELAST+7) /* unlabeled disk */ 87ca987d46SWarner Losh #define EOFFSET (ELAST+8) /* relative seek not supported */ 88ca987d46SWarner Losh #define ESALAST (ELAST+8) /* */ 89ca987d46SWarner Losh 9049cb0130SWarner Losh /* Partial signal emulation for sig_atomic_t */ 9149cb0130SWarner Losh #include <machine/signal.h> 9249cb0130SWarner Losh 93ca987d46SWarner Losh struct open_file; 94ca987d46SWarner Losh 95ca987d46SWarner Losh /* 96ca987d46SWarner Losh * This structure is used to define file system operations in a file system 97ca987d46SWarner Losh * independent way. 98ca987d46SWarner Losh * 99ca987d46SWarner Losh * XXX note that filesystem providers should export a pointer to their fs_ops 100ca987d46SWarner Losh * struct, so that consumers can reference this and thus include the 101ca987d46SWarner Losh * filesystems that they require. 102ca987d46SWarner Losh */ 103ca987d46SWarner Losh struct fs_ops { 104ca987d46SWarner Losh const char *fs_name; 105ca987d46SWarner Losh int (*fo_open)(const char *path, struct open_file *f); 106ca987d46SWarner Losh int (*fo_close)(struct open_file *f); 107ca987d46SWarner Losh int (*fo_read)(struct open_file *f, void *buf, 108ca987d46SWarner Losh size_t size, size_t *resid); 1092e7e6fbcSConrad Meyer int (*fo_write)(struct open_file *f, const void *buf, 110ca987d46SWarner Losh size_t size, size_t *resid); 111ca987d46SWarner Losh off_t (*fo_seek)(struct open_file *f, off_t offset, int where); 112ca987d46SWarner Losh int (*fo_stat)(struct open_file *f, struct stat *sb); 113ca987d46SWarner Losh int (*fo_readdir)(struct open_file *f, struct dirent *d); 114c25d9affSEmmanuel Vadot int (*fo_preload)(struct open_file *f); 115b4cb3fe0SToomas Soome int (*fo_mount)(const char *, const char *, void **); 116b4cb3fe0SToomas Soome int (*fo_unmount)(const char *, void *); 117ca987d46SWarner Losh }; 118ca987d46SWarner Losh 119ca987d46SWarner Losh /* 120bd001d86SWarner Losh * libsa-supplied filesystems 121ca987d46SWarner Losh */ 122ca987d46SWarner Losh extern struct fs_ops ufs_fsops; 123ca987d46SWarner Losh extern struct fs_ops tftp_fsops; 124ca987d46SWarner Losh extern struct fs_ops nfs_fsops; 125ca987d46SWarner Losh extern struct fs_ops cd9660_fsops; 126ca987d46SWarner Losh extern struct fs_ops gzipfs_fsops; 127ca987d46SWarner Losh extern struct fs_ops bzipfs_fsops; 128ca987d46SWarner Losh extern struct fs_ops dosfs_fsops; 129ca987d46SWarner Losh extern struct fs_ops ext2fs_fsops; 130ca987d46SWarner Losh extern struct fs_ops splitfs_fsops; 131ca987d46SWarner Losh extern struct fs_ops pkgfs_fsops; 132da4961c7SRebecca Cran extern struct fs_ops efihttp_fsops; 133ca987d46SWarner Losh 134ca987d46SWarner Losh /* where values for lseek(2) */ 135ca987d46SWarner Losh #define SEEK_SET 0 /* set file offset to offset */ 136ca987d46SWarner Losh #define SEEK_CUR 1 /* set file offset to current plus offset */ 137ca987d46SWarner Losh #define SEEK_END 2 /* set file offset to EOF plus offset */ 138ca987d46SWarner Losh 139ca987d46SWarner Losh /* 140ca987d46SWarner Losh * Device switch 141ca987d46SWarner Losh */ 1424932a6e4SWarner Losh #define DEV_NAMLEN 8 /* Length of name of device class */ 1434d4b1a29SWarner Losh #define DEV_DEVLEN 128 /* Length of longest device instance name */ 1444d4b1a29SWarner Losh struct devdesc; 145ca987d46SWarner Losh struct devsw { 1464932a6e4SWarner Losh const char dv_name[DEV_NAMLEN]; 147079f02e8SWarner Losh int dv_type; /* opaque type constant */ 148b3a2aad1SWarner Losh #define DEVT_NONE 0 149b3a2aad1SWarner Losh #define DEVT_DISK 1 150b3a2aad1SWarner Losh #define DEVT_NET 2 151b3a2aad1SWarner Losh #define DEVT_CD 3 152b3a2aad1SWarner Losh #define DEVT_ZFS 4 153b3a2aad1SWarner Losh #define DEVT_FD 5 154ca987d46SWarner Losh int (*dv_init)(void); /* early probe call */ 155ca987d46SWarner Losh int (*dv_strategy)(void *devdata, int rw, daddr_t blk, 156ca987d46SWarner Losh size_t size, char *buf, size_t *rsize); 157ca987d46SWarner Losh int (*dv_open)(struct open_file *f, ...); 158ca987d46SWarner Losh int (*dv_close)(struct open_file *f); 159ca987d46SWarner Losh int (*dv_ioctl)(struct open_file *f, u_long cmd, void *data); 160ca987d46SWarner Losh int (*dv_print)(int verbose); /* print device information */ 161ca987d46SWarner Losh void (*dv_cleanup)(void); 1624d4b1a29SWarner Losh char * (*dv_fmtdev)(struct devdesc *); 163a0aad69fSWarner Losh int (*dv_parsedev)(struct devdesc **, const char *, const char **); 164a07cef5aSWarner Losh bool (*dv_match)(struct devsw *, const char *); 165ca987d46SWarner Losh }; 166ca987d46SWarner Losh 167ca987d46SWarner Losh /* 168bd001d86SWarner Losh * libsa-supplied device switch 169ca987d46SWarner Losh */ 170ca987d46SWarner Losh extern struct devsw netdev; 171ca987d46SWarner Losh 172ca987d46SWarner Losh extern int errno; 173ca987d46SWarner Losh 174ca987d46SWarner Losh /* 175269865a8SWarner Losh * Generic device specifier; architecture-dependent versions may be larger, but 176269865a8SWarner Losh * should be allowed to overlap. The larger device specifiers store more data 177269865a8SWarner Losh * than can fit in the generic one that's gleaned after parsing the device 178269865a8SWarner Losh * string, or used in some cases to indicate wildcards that match a variety of 179269865a8SWarner Losh * situations based on what's on the drive itself rather than what the progammer 180269865a8SWarner Losh * might know in advance. Information about open files is stored in d_opendata, 181269865a8SWarner Losh * though what's passed into the open routine may differ from what's present 182269865a8SWarner Losh * after the open on some configurations. 183ca987d46SWarner Losh */ 184b3a2aad1SWarner Losh struct devdesc { 185ca987d46SWarner Losh struct devsw *d_dev; 186ca987d46SWarner Losh int d_unit; 187ca987d46SWarner Losh void *d_opendata; 188ca987d46SWarner Losh }; 189ca987d46SWarner Losh 1904d4b1a29SWarner Losh char *devformat(struct devdesc *d); 191781ca0afSWarner Losh int devparse(struct devdesc **, const char *, const char **); 19266012c8fSWarner Losh int devinit(void); 1934d4b1a29SWarner Losh 194ca987d46SWarner Losh struct open_file { 195ca987d46SWarner Losh int f_flags; /* see F_* below */ 196ca987d46SWarner Losh struct devsw *f_dev; /* pointer to device operations */ 197ca987d46SWarner Losh void *f_devdata; /* device specific data */ 198ca987d46SWarner Losh struct fs_ops *f_ops; /* pointer to file system operations */ 199ca987d46SWarner Losh void *f_fsdata; /* file system specific data */ 200ca987d46SWarner Losh off_t f_offset; /* current file offset */ 201ca987d46SWarner Losh char *f_rabuf; /* readahead buffer pointer */ 202ca987d46SWarner Losh size_t f_ralen; /* valid data in readahead buffer */ 203ca987d46SWarner Losh off_t f_raoffset; /* consumer offset in readahead buffer */ 20497cbd5e7SToomas Soome int f_id; /* file number */ 20597cbd5e7SToomas Soome TAILQ_ENTRY(open_file) f_link; /* next entry */ 206ca987d46SWarner Losh #define SOPEN_RASIZE 512 207ca987d46SWarner Losh }; 208ca987d46SWarner Losh 20997cbd5e7SToomas Soome typedef TAILQ_HEAD(file_list, open_file) file_list_t; 21097cbd5e7SToomas Soome extern file_list_t files; 21197cbd5e7SToomas Soome extern struct open_file *fd2open_file(int); 212ca987d46SWarner Losh 213ca987d46SWarner Losh /* f_flags values */ 214ca987d46SWarner Losh #define F_READ 0x0001 /* file opened for reading */ 215ca987d46SWarner Losh #define F_WRITE 0x0002 /* file opened for writing */ 216ca987d46SWarner Losh #define F_RAW 0x0004 /* raw device open - no file system */ 217ca987d46SWarner Losh #define F_NODEV 0x0008 /* network open - no device */ 218ca987d46SWarner Losh #define F_MASK 0xFFFF 219ca987d46SWarner Losh /* Mode modifier for strategy() */ 220ca987d46SWarner Losh #define F_NORA (0x01 << 16) /* Disable Read-Ahead */ 221ca987d46SWarner Losh 222ca987d46SWarner Losh #define isascii(c) (((c) & ~0x7F) == 0) 223ca987d46SWarner Losh 224ca987d46SWarner Losh static __inline int isupper(int c) 225ca987d46SWarner Losh { 226ca987d46SWarner Losh return c >= 'A' && c <= 'Z'; 227ca987d46SWarner Losh } 228ca987d46SWarner Losh 229ca987d46SWarner Losh static __inline int islower(int c) 230ca987d46SWarner Losh { 231ca987d46SWarner Losh return c >= 'a' && c <= 'z'; 232ca987d46SWarner Losh } 233ca987d46SWarner Losh 234ca987d46SWarner Losh static __inline int isspace(int c) 235ca987d46SWarner Losh { 236ca987d46SWarner Losh return c == ' ' || (c >= 0x9 && c <= 0xd); 237ca987d46SWarner Losh } 238ca987d46SWarner Losh 239ca987d46SWarner Losh static __inline int isdigit(int c) 240ca987d46SWarner Losh { 241ca987d46SWarner Losh return c >= '0' && c <= '9'; 242ca987d46SWarner Losh } 243ca987d46SWarner Losh 244ca987d46SWarner Losh static __inline int isxdigit(int c) 245ca987d46SWarner Losh { 246ca987d46SWarner Losh return isdigit(c) || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F'); 247ca987d46SWarner Losh } 248ca987d46SWarner Losh 249ca987d46SWarner Losh static __inline int isalpha(int c) 250ca987d46SWarner Losh { 251ca987d46SWarner Losh return isupper(c) || islower(c); 252ca987d46SWarner Losh } 253ca987d46SWarner Losh 254ca987d46SWarner Losh static __inline int isalnum(int c) 255ca987d46SWarner Losh { 256ca987d46SWarner Losh return isalpha(c) || isdigit(c); 257ca987d46SWarner Losh } 258ca987d46SWarner Losh 2596856cf68SWarner Losh static __inline int iscntrl(int c) 2606856cf68SWarner Losh { 2616856cf68SWarner Losh return (c >= 0 && c < ' ') || c == 127; 2626856cf68SWarner Losh } 2636856cf68SWarner Losh 2646856cf68SWarner Losh static __inline int isgraph(int c) 2656856cf68SWarner Losh { 2666856cf68SWarner Losh return c >= '!' && c <= '~'; 2676856cf68SWarner Losh } 2686856cf68SWarner Losh 2696856cf68SWarner Losh static __inline int ispunct(int c) 2706856cf68SWarner Losh { 2716856cf68SWarner Losh return (c >= '!' && c <= '/') || (c >= ':' && c <= '@') || 2726856cf68SWarner Losh (c >= '[' && c <= '`') || (c >= '{' && c <= '~'); 2736856cf68SWarner Losh } 2746856cf68SWarner Losh 275ca987d46SWarner Losh static __inline int toupper(int c) 276ca987d46SWarner Losh { 277ca987d46SWarner Losh return islower(c) ? c - 'a' + 'A' : c; 278ca987d46SWarner Losh } 279ca987d46SWarner Losh 280ca987d46SWarner Losh static __inline int tolower(int c) 281ca987d46SWarner Losh { 282ca987d46SWarner Losh return isupper(c) ? c - 'A' + 'a' : c; 283ca987d46SWarner Losh } 284ca987d46SWarner Losh 285ca987d46SWarner Losh /* sbrk emulation */ 286ca987d46SWarner Losh extern void setheap(void *base, void *top); 287ca987d46SWarner Losh extern char *sbrk(int incr); 288ca987d46SWarner Losh 289ca987d46SWarner Losh extern int printf(const char *fmt, ...) __printflike(1, 2); 2905e84b578SToomas Soome extern int asprintf(char **buf, const char *cfmt, ...) __printflike(2, 3); 291ca987d46SWarner Losh extern int sprintf(char *buf, const char *cfmt, ...) __printflike(2, 3); 292ca987d46SWarner Losh extern int snprintf(char *buf, size_t size, const char *cfmt, ...) __printflike(3, 4); 2933e9c7874SIan Lepore extern int vprintf(const char *fmt, __va_list); 2943e9c7874SIan Lepore extern int vsprintf(char *buf, const char *cfmt, __va_list); 2953e9c7874SIan Lepore extern int vsnprintf(char *buf, size_t size, const char *cfmt, __va_list); 296ca987d46SWarner Losh 297ca987d46SWarner Losh extern void twiddle(u_int callerdiv); 298ca987d46SWarner Losh extern void twiddle_divisor(u_int globaldiv); 299ca987d46SWarner Losh 300ca987d46SWarner Losh extern void ngets(char *, int); 301ca987d46SWarner Losh #define gets(x) ngets((x), 0) 302ca987d46SWarner Losh extern int fgetstr(char *buf, int size, int fd); 303ca987d46SWarner Losh 304b4cb3fe0SToomas Soome extern int mount(const char *dev, const char *path, int flags, void *data); 305b4cb3fe0SToomas Soome extern int unmount(const char *dev, int flags); 306ca987d46SWarner Losh extern int open(const char *, int); 307ca987d46SWarner Losh #define O_RDONLY 0x0 308ca987d46SWarner Losh #define O_WRONLY 0x1 309ca987d46SWarner Losh #define O_RDWR 0x2 3102ef9ff7dSSimon J. Gerraty #define O_ACCMODE 0x3 31182c85a42SKyle Evans /* NOT IMPLEMENTED */ 31282c85a42SKyle Evans #define O_CREAT 0x0200 /* create if nonexistent */ 31382c85a42SKyle Evans #define O_TRUNC 0x0400 /* truncate to zero length */ 314ca987d46SWarner Losh extern int close(int); 315ca987d46SWarner Losh extern void closeall(void); 316ca987d46SWarner Losh extern ssize_t read(int, void *, size_t); 317061577c5SConrad Meyer extern ssize_t write(int, const void *, size_t); 318*2e1e68cbSWarner Losh extern int ioctl(int, u_long, void *); 319ca987d46SWarner Losh extern struct dirent *readdirfd(int); 320c25d9affSEmmanuel Vadot extern void preload(int); 321ca987d46SWarner Losh 322dcaa2d76SWarner Losh extern void srandom(unsigned int); 323e294a126SWarner Losh extern long random(void); 324ca987d46SWarner Losh 325ca987d46SWarner Losh /* imports from stdlib, locally modified */ 326ca987d46SWarner Losh extern char *optarg; /* getopt(3) external variables */ 327ca987d46SWarner Losh extern int optind, opterr, optopt, optreset; 328ca987d46SWarner Losh extern int getopt(int, char * const [], const char *); 329ca987d46SWarner Losh 330ca987d46SWarner Losh /* pager.c */ 331ca987d46SWarner Losh extern void pager_open(void); 332ca987d46SWarner Losh extern void pager_close(void); 333ca987d46SWarner Losh extern int pager_output(const char *lines); 334ca987d46SWarner Losh extern int pager_file(const char *fname); 335ca987d46SWarner Losh 336ca987d46SWarner Losh /* No signal state to preserve */ 337ca987d46SWarner Losh #define setjmp _setjmp 338ca987d46SWarner Losh #define longjmp _longjmp 339ca987d46SWarner Losh 340ca987d46SWarner Losh /* environment.c */ 341ca987d46SWarner Losh #define EV_DYNAMIC (1<<0) /* value was dynamically allocated, free if changed/unset */ 342ca987d46SWarner Losh #define EV_VOLATILE (1<<1) /* value is volatile, make a copy of it */ 343ca987d46SWarner Losh #define EV_NOHOOK (1<<2) /* don't call hook when setting */ 344ca987d46SWarner Losh 345ca987d46SWarner Losh struct env_var; 346ca987d46SWarner Losh typedef char *(ev_format_t)(struct env_var *ev); 347ca987d46SWarner Losh typedef int (ev_sethook_t)(struct env_var *ev, int flags, 348ca987d46SWarner Losh const void *value); 349ca987d46SWarner Losh typedef int (ev_unsethook_t)(struct env_var *ev); 350ca987d46SWarner Losh 351ca987d46SWarner Losh struct env_var 352ca987d46SWarner Losh { 353ca987d46SWarner Losh char *ev_name; 354ca987d46SWarner Losh int ev_flags; 355ca987d46SWarner Losh void *ev_value; 356ca987d46SWarner Losh ev_sethook_t *ev_sethook; 357ca987d46SWarner Losh ev_unsethook_t *ev_unsethook; 358ca987d46SWarner Losh struct env_var *ev_next, *ev_prev; 359ca987d46SWarner Losh }; 360ca987d46SWarner Losh extern struct env_var *environ; 361ca987d46SWarner Losh 362ca987d46SWarner Losh extern struct env_var *env_getenv(const char *name); 363ca987d46SWarner Losh extern int env_setenv(const char *name, int flags, 364ca987d46SWarner Losh const void *value, ev_sethook_t sethook, 365ca987d46SWarner Losh ev_unsethook_t unsethook); 366588f0a1eSToomas Soome extern void env_discard(struct env_var *); 367ca987d46SWarner Losh extern char *getenv(const char *name); 368ca987d46SWarner Losh extern int setenv(const char *name, const char *value, 369ca987d46SWarner Losh int overwrite); 370e8e6a5f9SWarner Losh extern int putenv(char *string); 371ca987d46SWarner Losh extern int unsetenv(const char *name); 372ca987d46SWarner Losh 373ca987d46SWarner Losh extern ev_sethook_t env_noset; /* refuse set operation */ 374ca987d46SWarner Losh extern ev_unsethook_t env_nounset; /* refuse unset operation */ 375ca987d46SWarner Losh 3762b0268cfSWarner Losh /* stdlib.h routines */ 37724dfa658SWarner Losh extern int abs(int a); 37830883627SWarner Losh extern void abort(void) __dead2; 3793a8a081bSWarner Losh extern long strtol(const char * __restrict, char ** __restrict, int); 3803a8a081bSWarner Losh extern long long strtoll(const char * __restrict, char ** __restrict, int); 3813a8a081bSWarner Losh extern unsigned long strtoul(const char * __restrict, char ** __restrict, int); 3823a8a081bSWarner Losh extern unsigned long long strtoull(const char * __restrict, char ** __restrict, int); 3832b0268cfSWarner Losh 384ca987d46SWarner Losh /* BCD conversions (undocumented) */ 385ca987d46SWarner Losh extern u_char const bcd2bin_data[]; 386ca987d46SWarner Losh extern u_char const bin2bcd_data[]; 387ca987d46SWarner Losh extern char const hex2ascii_data[]; 388ca987d46SWarner Losh 389ca987d46SWarner Losh #define bcd2bin(bcd) (bcd2bin_data[bcd]) 390ca987d46SWarner Losh #define bin2bcd(bin) (bin2bcd_data[bin]) 391ca987d46SWarner Losh #define hex2ascii(hex) (hex2ascii_data[hex]) 392b6f4732cSIan Lepore #define validbcd(bcd) (bcd == 0 || (bcd > 0 && bcd <= 0x99 && bcd2bin_data[bcd] != 0)) 393ca987d46SWarner Losh 394ca987d46SWarner Losh /* min/max (undocumented) */ 395ca987d46SWarner Losh static __inline int imax(int a, int b) { return (a > b ? a : b); } 396ca987d46SWarner Losh static __inline int imin(int a, int b) { return (a < b ? a : b); } 397ca987d46SWarner Losh static __inline long lmax(long a, long b) { return (a > b ? a : b); } 398ca987d46SWarner Losh static __inline long lmin(long a, long b) { return (a < b ? a : b); } 399ca987d46SWarner Losh static __inline u_int max(u_int a, u_int b) { return (a > b ? a : b); } 400ca987d46SWarner Losh static __inline u_int min(u_int a, u_int b) { return (a < b ? a : b); } 401ca987d46SWarner Losh static __inline quad_t qmax(quad_t a, quad_t b) { return (a > b ? a : b); } 402ca987d46SWarner Losh static __inline quad_t qmin(quad_t a, quad_t b) { return (a < b ? a : b); } 403ca987d46SWarner Losh static __inline u_long ulmax(u_long a, u_long b) { return (a > b ? a : b); } 404ca987d46SWarner Losh static __inline u_long ulmin(u_long a, u_long b) { return (a < b ? a : b); } 405ca987d46SWarner Losh 406ca987d46SWarner Losh /* null functions for device/filesystem switches (undocumented) */ 407ca987d46SWarner Losh extern int nodev(void); 408ca987d46SWarner Losh extern int noioctl(struct open_file *, u_long, void *); 409ca987d46SWarner Losh extern void nullsys(void); 410ca987d46SWarner Losh 411ca987d46SWarner Losh extern int null_open(const char *path, struct open_file *f); 412ca987d46SWarner Losh extern int null_close(struct open_file *f); 413ca987d46SWarner Losh extern int null_read(struct open_file *f, void *buf, size_t size, size_t *resid); 4142e7e6fbcSConrad Meyer extern int null_write(struct open_file *f, const void *buf, size_t size, size_t *resid); 415ca987d46SWarner Losh extern off_t null_seek(struct open_file *f, off_t offset, int where); 416ca987d46SWarner Losh extern int null_stat(struct open_file *f, struct stat *sb); 417ca987d46SWarner Losh extern int null_readdir(struct open_file *f, struct dirent *d); 418ca987d46SWarner Losh 419ca987d46SWarner Losh 420ca987d46SWarner Losh /* 421ca987d46SWarner Losh * Machine dependent functions and data, must be provided or stubbed by 422ca987d46SWarner Losh * the consumer 423ca987d46SWarner Losh */ 42486bb84d5SWarner Losh extern void exit(int) __dead2; 425ca987d46SWarner Losh extern int getchar(void); 426ca987d46SWarner Losh extern int ischar(void); 427ca987d46SWarner Losh extern void putchar(int); 428ca987d46SWarner Losh extern int devopen(struct open_file *, const char *, const char **); 429ca987d46SWarner Losh extern int devclose(struct open_file *f); 430ca987d46SWarner Losh extern void panic(const char *, ...) __dead2 __printflike(1, 2); 43186bb84d5SWarner Losh extern void panic_action(void) __weak_symbol __dead2; 43231d05586SWarner Losh extern time_t getsecs(void); 433ca987d46SWarner Losh extern struct fs_ops *file_system[]; 434ca987d46SWarner Losh extern struct fs_ops *exclusive_file_system; 435ca987d46SWarner Losh extern struct devsw *devsw[]; 436ca987d46SWarner Losh 437ca987d46SWarner Losh /* 438b9c5b432SWarner Losh * Time routines 439b9c5b432SWarner Losh */ 440b9c5b432SWarner Losh time_t time(time_t *); 441b9c5b432SWarner Losh 442b9c5b432SWarner Losh /* 443ca987d46SWarner Losh * Expose byteorder(3) functions. 444ca987d46SWarner Losh */ 445ca987d46SWarner Losh #ifndef _BYTEORDER_PROTOTYPED 446ca987d46SWarner Losh #define _BYTEORDER_PROTOTYPED 447ca987d46SWarner Losh extern uint32_t htonl(uint32_t); 448ca987d46SWarner Losh extern uint16_t htons(uint16_t); 449ca987d46SWarner Losh extern uint32_t ntohl(uint32_t); 450ca987d46SWarner Losh extern uint16_t ntohs(uint16_t); 451ca987d46SWarner Losh #endif 452ca987d46SWarner Losh 453ca987d46SWarner Losh #ifndef _BYTEORDER_FUNC_DEFINED 454ca987d46SWarner Losh #define _BYTEORDER_FUNC_DEFINED 455ca987d46SWarner Losh #define htonl(x) __htonl(x) 456ca987d46SWarner Losh #define htons(x) __htons(x) 457ca987d46SWarner Losh #define ntohl(x) __ntohl(x) 458ca987d46SWarner Losh #define ntohs(x) __ntohs(x) 459ca987d46SWarner Losh #endif 460ca987d46SWarner Losh 461ca987d46SWarner Losh void *Malloc(size_t, const char *, int); 46211db1a16SToomas Soome void *Memalign(size_t, size_t, const char *, int); 463ca987d46SWarner Losh void *Calloc(size_t, size_t, const char *, int); 464ca987d46SWarner Losh void *Realloc(void *, size_t, const char *, int); 46511db1a16SToomas Soome void *Reallocf(void *, size_t, const char *, int); 466ca987d46SWarner Losh void Free(void *, const char *, int); 46762ea4c11SToomas Soome extern void mallocstats(void); 468ca987d46SWarner Losh 469e9b148a3SSimon J. Gerraty const char *x86_hypervisor(void); 470e9b148a3SSimon J. Gerraty 471c907ec9eSToomas Soome #ifdef USER_MALLOC 472c907ec9eSToomas Soome extern void *malloc(size_t); 473c907ec9eSToomas Soome extern void *memalign(size_t, size_t); 474c907ec9eSToomas Soome extern void *calloc(size_t, size_t); 475c907ec9eSToomas Soome extern void free(void *); 476c907ec9eSToomas Soome extern void *realloc(void *, size_t); 477c907ec9eSToomas Soome extern void *reallocf(void *, size_t); 4785292d0a7SToomas Soome #elif defined(DEBUG_MALLOC) 479ca987d46SWarner Losh #define malloc(x) Malloc(x, __FILE__, __LINE__) 48011db1a16SToomas Soome #define memalign(x, y) Memalign(x, y, __FILE__, __LINE__) 481ca987d46SWarner Losh #define calloc(x, y) Calloc(x, y, __FILE__, __LINE__) 482ca987d46SWarner Losh #define free(x) Free(x, __FILE__, __LINE__) 483ca987d46SWarner Losh #define realloc(x, y) Realloc(x, y, __FILE__, __LINE__) 48462ea4c11SToomas Soome #define reallocf(x, y) Reallocf(x, y, __FILE__, __LINE__) 485ca987d46SWarner Losh #else 486ca987d46SWarner Losh #define malloc(x) Malloc(x, NULL, 0) 48711db1a16SToomas Soome #define memalign(x, y) Memalign(x, y, NULL, 0) 488ca987d46SWarner Losh #define calloc(x, y) Calloc(x, y, NULL, 0) 489ca987d46SWarner Losh #define free(x) Free(x, NULL, 0) 490ca987d46SWarner Losh #define realloc(x, y) Realloc(x, y, NULL, 0) 49162ea4c11SToomas Soome #define reallocf(x, y) Reallocf(x, y, NULL, 0) 492ca987d46SWarner Losh #endif 493ca987d46SWarner Losh 494ed2a6576SWarner Losh /* 495ed2a6576SWarner Losh * va <-> pa routines. MD code must supply. 496ed2a6576SWarner Losh */ 497ed2a6576SWarner Losh caddr_t ptov(uintptr_t); 498ed2a6576SWarner Losh 499ed19b7c5SSimon J. Gerraty /* hexdump.c */ 500ed19b7c5SSimon J. Gerraty void hexdump(caddr_t region, size_t len); 501ed19b7c5SSimon J. Gerraty 502e193d3baSColin Percival /* tslog.c */ 503e193d3baSColin Percival #define TSRAW(a, b, c) tslog(a, b, c) 504e193d3baSColin Percival #define TSENTER() TSRAW("ENTER", __func__, NULL) 50501cad731SEmmanuel Vadot #define TSENTER2(x) TSRAW("ENTER", __func__, x) 506e193d3baSColin Percival #define TSEXIT() TSRAW("EXIT", __func__, NULL) 507e193d3baSColin Percival #define TSLINE() TSRAW("EVENT", __FILE__, __XSTRING(__LINE__)) 508e193d3baSColin Percival void tslog(const char *, const char *, const char *); 509e193d3baSColin Percival void tslog_setbuf(void * buf, size_t len); 510e193d3baSColin Percival void tslog_getbuf(void ** buf, size_t * len); 511e193d3baSColin Percival 512ca987d46SWarner Losh #endif /* STAND_H */ 513