diff --git a/lib/libstand/environment.c b/lib/libstand/environment.c index f2ca120a177d..158e8452f3eb 100644 --- a/lib/libstand/environment.c +++ b/lib/libstand/environment.c @@ -1,219 +1,219 @@ /* * Copyright (c) 1998 Michael Smith. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * * $FreeBSD$ * */ /* * Manage an environment-like space in which string variables may be stored. * Provide support for some method-like operations for setting/retrieving * variables in order to allow some type strength. */ #include "stand.h" #include static void env_discard(struct env_var *ev); struct env_var *environ = NULL; /* * Look up (name) and return it's env_var structure. */ struct env_var * env_getenv(const char *name) { struct env_var *ev; for (ev = environ; ev != NULL; ev = ev->ev_next) if (!strcmp(ev->ev_name, name)) break; return(ev); } /* * Some notes: * * If the EV_VOLATILE flag is set, a copy of the variable is made. * If EV_DYNAMIC is set, the the variable has been allocated with * malloc and ownership transferred to the environment. * If (value) is NULL, the variable is set but has no value. */ int -env_setenv(const char *name, int flags, void *value, ev_sethook_t sethook, - ev_unsethook_t unsethook) +env_setenv(const char *name, int flags, const void *value, + ev_sethook_t sethook, ev_unsethook_t unsethook) { struct env_var *ev, *curr, *last; if ((ev = env_getenv(name)) != NULL) { /* * If there's a set hook, let it do the work (unless we are working * for one already. */ if ((ev->ev_sethook != NULL) && !(flags & EV_NOHOOK)) return(ev->ev_sethook(ev, flags, value)); } else { /* * New variable; create and sort into list */ ev = malloc(sizeof(struct env_var)); ev->ev_name = strdup(name); ev->ev_value = NULL; /* hooks can only be set when the variable is instantiated */ ev->ev_sethook = sethook; ev->ev_unsethook = unsethook; /* Sort into list */ ev->ev_prev = NULL; ev->ev_next = NULL; /* Search for the record to insert before */ for (last = NULL, curr = environ; curr != NULL; last = curr, curr = curr->ev_next) { if (strcmp(ev->ev_name, curr->ev_name) < 0) { if (curr->ev_prev) { curr->ev_prev->ev_next = ev; } else { environ = ev; } ev->ev_next = curr; ev->ev_prev = curr->ev_prev; curr->ev_prev = ev; break; } } if (curr == NULL) { if (last == NULL) { environ = ev; } else { last->ev_next = ev; ev->ev_prev = last; } } } /* If there is data in the variable, discard it */ if (ev->ev_value != NULL) free(ev->ev_value); /* If we have a new value, use it */ if (flags & EV_VOLATILE) { ev->ev_value = strdup(value); } else { ev->ev_value = value; } /* Keep the flag components that are relevant */ ev->ev_flags = flags & (EV_DYNAMIC); return(0); } char * getenv(const char *name) { struct env_var *ev; /* Set but no value gives empty string */ if ((ev = env_getenv(name)) != NULL) { if (ev->ev_value != NULL) return(ev->ev_value); return(""); } return(NULL); } int -setenv(const char *name, char *value, int overwrite) +setenv(const char *name, const char *value, int overwrite) { /* No guarantees about state, always assume volatile */ if (overwrite || (env_getenv(name) == NULL)) return(env_setenv(name, EV_VOLATILE, value, NULL, NULL)); return(0); } int putenv(const char *string) { char *value, *copy; int result; copy = strdup(string); if ((value = strchr(copy, '=')) != NULL) *(value++) = 0; result = setenv(copy, value, 1); free(copy); return(result); } int unsetenv(const char *name) { struct env_var *ev; int err; err = 0; if ((ev = env_getenv(name)) == NULL) { err = ENOENT; } else { if (ev->ev_unsethook != NULL) err = ev->ev_unsethook(ev); if (err == 0) { env_discard(ev); } } return(err); } static void env_discard(struct env_var *ev) { if (ev->ev_prev) ev->ev_prev->ev_next = ev->ev_next; if (ev->ev_next) ev->ev_next->ev_prev = ev->ev_prev; if (environ == ev) environ = ev->ev_next; free(ev->ev_name); if (ev->ev_flags & EV_DYNAMIC) free(ev->ev_value); free(ev); } int env_noset(struct env_var *ev, int flags, void *value) { return(EPERM); } int env_nounset(struct env_var *ev) { return(EPERM); } diff --git a/lib/libstand/net.h b/lib/libstand/net.h index 6f6d4435e657..47ff0a0d2e20 100644 --- a/lib/libstand/net.h +++ b/lib/libstand/net.h @@ -1,122 +1,127 @@ /* $NetBSD: net.h,v 1.10 1995/10/20 00:46:30 cgd Exp $ */ /* * Copyright (c) 1993 Adam Glass * Copyright (c) 1992 Regents of the University of California. * All rights reserved. * * This software was developed by the Computer Systems Engineering group * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and * contributed to Berkeley. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: * This product includes software developed by the University of * California, Lawrence Berkeley Laboratory and its contributors. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. + * + * $FreeBSD$ */ #define NETIF_DEBUG 1 #ifndef _KERNEL /* XXX - see */ #undef __IPADDR #define __IPADDR(x) htonl((u_int32_t)(x)) #endif #include "iodesc.h" #define BA { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff } /* Returns true if n_long's on the same net */ #define SAMENET(a1, a2, m) ((a1.s_addr & m) == (a2.s_addr & m)) #define MACPY(s, d) bcopy((char *)s, (char *)d, 6) #define MAXTMO 20 /* seconds */ #define MINTMO 2 /* seconds */ #define FNAME_SIZE 128 #define IFNAME_SIZE 16 #define RECV_SIZE 1536 /* XXX delete this */ /* * How much room to leave for headers: * 14: struct ether_header * 20: struct ip * 8: struct udphdr * That's 42 but let's pad it out to 48 bytes. */ #define ETHER_SIZE 14 #define HEADER_SIZE 48 extern u_char bcea[6]; extern char rootpath[FNAME_SIZE]; extern char bootfile[FNAME_SIZE]; extern char hostname[FNAME_SIZE]; extern int hostnamelen; extern char domainname[FNAME_SIZE]; extern int domainnamelen; extern char ifname[IFNAME_SIZE]; /* All of these are in network order. */ extern struct in_addr myip; extern struct in_addr rootip; extern struct in_addr swapip; extern struct in_addr gateip; extern struct in_addr nameip; extern n_long netmask; extern int debug; /* defined in the machdep sources */ extern struct iodesc sockets[SOPEN_MAX]; /* ARP/RevARP functions: */ u_char *arpwhohas(struct iodesc *, struct in_addr); void arp_reply(struct iodesc *, void *); int rarp_getipaddress(int); /* Link functions: */ ssize_t sendether(struct iodesc *d, void *pkt, size_t len, u_char *dea, int etype); ssize_t readether(struct iodesc *d, void *pkt, size_t len, time_t tleft, u_int16_t *etype); ssize_t sendudp(struct iodesc *, void *, size_t); ssize_t readudp(struct iodesc *, void *, size_t, time_t); ssize_t sendrecv(struct iodesc *, ssize_t (*)(struct iodesc *, void *, size_t), void *, size_t, ssize_t (*)(struct iodesc *, void *, size_t, time_t), void *, size_t); +/* bootp/DHCP */ +void bootp(int); + /* Utilities: */ char *ether_sprintf(u_char *); int in_cksum(void *, int); char *inet_ntoa(struct in_addr); char *intoa(n_long); /* similar to inet_ntoa */ n_long inet_addr(char *); /* Machine-dependent functions: */ time_t getsecs(void); diff --git a/lib/libstand/netif.h b/lib/libstand/netif.h index 06093103fa05..dac285107a73 100644 --- a/lib/libstand/netif.h +++ b/lib/libstand/netif.h @@ -1,65 +1,67 @@ /* $NetBSD: netif.h,v 1.4 1995/09/14 23:45:30 pk Exp $ */ +/* $FreeBSD$ */ + #ifndef __SYS_LIBNETBOOT_NETIF_H #define __SYS_LIBNETBOOT_NETIF_H #include "iodesc.h" #define NENTS(x) sizeof(x)/sizeof(x[0]) struct netif_driver { - char *netif_bname; + const char *netif_bname; int (*netif_match)(struct netif *, void *); int (*netif_probe)(struct netif *, void *); void (*netif_init)(struct iodesc *, void *); int (*netif_get)(struct iodesc *, void *, size_t, time_t); int (*netif_put)(struct iodesc *, void *, size_t); void (*netif_end)(struct netif *); struct netif_dif *netif_ifs; int netif_nifs; }; struct netif_dif { int dif_unit; int dif_nsel; struct netif_stats *dif_stats; void *dif_private; /* the following fields are used internally by the netif layer */ u_long dif_used; }; struct netif_stats { int collisions; int collision_error; int missed; int sent; int received; int deferred; int overflow; }; struct netif { struct netif_driver *nif_driver; int nif_unit; int nif_sel; void *nif_devdata; }; extern struct netif_driver *netif_drivers[]; /* machdep */ extern int n_netif_drivers; extern int netif_debug; void netif_init(void); struct netif *netif_select(void *); int netif_probe(struct netif *, void *); void netif_attach(struct netif *, struct iodesc *, void *); void netif_detach(struct netif *); ssize_t netif_get(struct iodesc *, void *, size_t, time_t); ssize_t netif_put(struct iodesc *, void *, size_t); int netif_open(void *); int netif_close(int); struct iodesc *socktodesc(int); #endif /* __SYS_LIBNETBOOT_NETIF_H */ diff --git a/lib/libstand/stand.h b/lib/libstand/stand.h index 5fd209d98e40..aa8e65fd0fd1 100644 --- a/lib/libstand/stand.h +++ b/lib/libstand/stand.h @@ -1,362 +1,363 @@ /* * Copyright (c) 1998 Michael Smith. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * * $FreeBSD$ * From $NetBSD: stand.h,v 1.22 1997/06/26 19:17:40 drochner Exp $ */ /*- * Copyright (c) 1993 * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: * This product includes software developed by the University of * California, Berkeley and its contributors. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * * @(#)stand.h 8.1 (Berkeley) 6/11/93 */ #include #include #include #include +#include #define CHK(fmt, args...) printf("%s(%d): " fmt "\n", __FUNCTION__, __LINE__ , ##args) #define PCHK(fmt, args...) {printf("%s(%d): " fmt "\n", __FUNCTION__, __LINE__ , ##args); getchar();} #ifndef NULL #define NULL 0 #endif /* Avoid unwanted userlandish components */ #define _KERNEL #include #undef _KERNEL /* special stand error codes */ #define EADAPT (ELAST+1) /* bad adaptor */ #define ECTLR (ELAST+2) /* bad controller */ #define EUNIT (ELAST+3) /* bad unit */ #define ESLICE (ELAST+4) /* bad slice */ #define EPART (ELAST+5) /* bad partition */ #define ERDLAB (ELAST+6) /* can't read disk label */ #define EUNLAB (ELAST+7) /* unlabeled disk */ #define EOFFSET (ELAST+8) /* relative seek not supported */ #define ESALAST (ELAST+8) /* */ struct open_file; /* * This structure is used to define file system operations in a file system * independent way. * * XXX note that filesystem providers should export a pointer to their fs_ops * struct, so that consumers can reference this and thus include the * filesystems that they require. */ struct fs_ops { const char *fs_name; int (*fo_open)(const char *path, struct open_file *f); int (*fo_close)(struct open_file *f); int (*fo_read)(struct open_file *f, void *buf, size_t size, size_t *resid); int (*fo_write)(struct open_file *f, void *buf, size_t size, size_t *resid); off_t (*fo_seek)(struct open_file *f, off_t offset, int where); int (*fo_stat)(struct open_file *f, struct stat *sb); int (*fo_readdir)(struct open_file *f, struct dirent *d); }; /* * libstand-supplied filesystems */ extern struct fs_ops ufs_fsops; extern struct fs_ops tftp_fsops; extern struct fs_ops nfs_fsops; extern struct fs_ops cd9660_fsops; extern struct fs_ops zipfs_fsops; extern struct fs_ops dosfs_fsops; extern struct fs_ops ext2fs_fsops; /* where values for lseek(2) */ #define SEEK_SET 0 /* set file offset to offset */ #define SEEK_CUR 1 /* set file offset to current plus offset */ #define SEEK_END 2 /* set file offset to EOF plus offset */ /* * Device switch */ struct devsw { const char dv_name[8]; int dv_type; /* opaque type constant, arch-dependant */ int (*dv_init)(void); /* early probe call */ - int (*dv_strategy)(void *devdata, int rw, daddr_t blk, size_t size, void *buf, size_t *rsize); + int (*dv_strategy)(void *devdata, int rw, daddr_t blk, size_t size, + char *buf, size_t *rsize); int (*dv_open)(struct open_file *f, ...); int (*dv_close)(struct open_file *f); int (*dv_ioctl)(struct open_file *f, u_long cmd, void *data); void (*dv_print)(int verbose); /* print device information */ - void (*dv_cleanup)(); + void (*dv_cleanup)(void); }; /* * libstand-supplied device switch */ extern struct devsw netdev; extern int errno; struct open_file { int f_flags; /* see F_* below */ struct devsw *f_dev; /* pointer to device operations */ void *f_devdata; /* device specific data */ struct fs_ops *f_ops; /* pointer to file system operations */ void *f_fsdata; /* file system specific data */ off_t f_offset; /* current file offset (F_RAW) */ }; #define SOPEN_MAX 8 extern struct open_file files[]; /* f_flags values */ #define F_READ 0x0001 /* file opened for reading */ #define F_WRITE 0x0002 /* file opened for writing */ #define F_RAW 0x0004 /* raw device open - no file system */ #define F_NODEV 0x0008 /* network open - no device */ #define isupper(c) ((c) >= 'A' && (c) <= 'Z') #define islower(c) ((c) >= 'a' && (c) <= 'z') #define isspace(c) ((c) == ' ' || ((c) >= 0x9 && (c) <= 0xd)) #define isdigit(c) ((c) >= '0' && (c) <= '9') #define isxdigit(c) (isdigit(c) || ((c) >= 'a' && (c) <= 'f') || ((c) >= 'A' && (c) <= 'F')) #define isascii(c) (((c) & ~0x7F) == 0) #define isalpha(c) (isupper(c) || (islower(c))) static __inline int toupper(int c) { return islower(c) ? c - 'a' + 'A' : c; } static __inline int tolower(int c) { return isupper(c) ? c - 'A' + 'a' : c; } /* sbrk emulation */ extern void setheap(void *base, void *top); extern char *sbrk(int incr); /* Matt Dillon's zalloc/zmalloc */ extern void *malloc(size_t bytes); extern void free(void *ptr); /*#define free(p) {CHK("free %p", p); free(p);} */ /* use for catching guard violations */ extern void *calloc(size_t n1, size_t n2); extern void *realloc(void *ptr, size_t size); extern void *reallocf(void *ptr, size_t size); extern void mallocstats(void); #ifdef __alpha__ extern void free_region(void *start, void *end); #endif /* disklabel support (undocumented, may be junk) */ struct disklabel; extern char *getdisklabel(const char *, struct disklabel *); extern int dkcksum(struct disklabel *); extern int printf(const char *fmt, ...); extern void vprintf(const char *fmt, _BSD_VA_LIST_); extern int sprintf(char *buf, const char *cfmt, ...); extern void vsprintf(char *buf, const char *cfmt, _BSD_VA_LIST_); extern void twiddle(void); extern void ngets(char *, int); #define gets(x) ngets((x), 0) extern int fgetstr(char *buf, int size, int fd); extern int open(const char *, int); #define O_RDONLY 0x0 #define O_WRONLY 0x1 /* writing not (yet?) supported */ #define O_RDWR 0x2 extern int close(int); extern void closeall(void); extern ssize_t read(int, void *, size_t); extern ssize_t write(int, void *, size_t); -extern off_t lseek(int, off_t, int); -extern int stat(const char *, struct stat *); extern struct dirent *readdirfd(int); extern void srandom(u_long seed); extern u_long random(void); /* imports from stdlib, locally modified */ extern long strtol(const char *, char **, int); -extern char * strerror(int err); extern char *optarg; /* getopt(3) external variables */ extern int optind, opterr, optopt, optreset; extern int getopt(int, char * const [], const char *); /* pager.c */ extern void pager_open(void); extern void pager_close(void); extern int pager_output(const char *lines); extern int pager_file(const char *fname); /* No signal state to preserve */ #define setjmp _setjmp #define longjmp _longjmp /* environment.c */ #define EV_DYNAMIC (1<<0) /* value was dynamically allocated, free if changed/unset */ #define EV_VOLATILE (1<<1) /* value is volatile, make a copy of it */ #define EV_NOHOOK (1<<2) /* don't call hook when setting */ struct env_var; typedef char *(ev_format_t)(struct env_var *ev); typedef int (ev_sethook_t)(struct env_var *ev, int flags, void *value); typedef int (ev_unsethook_t)(struct env_var *ev); struct env_var { char *ev_name; int ev_flags; void *ev_value; ev_sethook_t *ev_sethook; ev_unsethook_t *ev_unsethook; struct env_var *ev_next, *ev_prev; }; extern struct env_var *environ; extern struct env_var *env_getenv(const char *name); -extern int env_setenv(const char *name, int flags, void *value, - ev_sethook_t sethook, ev_unsethook_t unsethook); +extern int env_setenv(const char *name, int flags, + const void *value, ev_sethook_t sethook, + ev_unsethook_t unsethook); extern char *getenv(const char *name); -extern int setenv(const char *name, char *value, int overwrite); +extern int setenv(const char *name, const char *value, + int overwrite); extern int putenv(const char *string); extern int unsetenv(const char *name); extern ev_sethook_t env_noset; /* refuse set operation */ extern ev_unsethook_t env_nounset; /* refuse unset operation */ /* BCD conversions (undocumented) */ extern u_char const bcd2bin_data[]; extern u_char const bin2bcd_data[]; extern char const hex2ascii_data[]; #define bcd2bin(bcd) (bcd2bin_data[bcd]) #define bin2bcd(bin) (bin2bcd_data[bin]) #define hex2ascii(hex) (hex2ascii_data[hex]) /* min/max (undocumented) */ static __inline int imax(int a, int b) { return (a > b ? a : b); } static __inline int imin(int a, int b) { return (a < b ? a : b); } static __inline long lmax(long a, long b) { return (a > b ? a : b); } static __inline long lmin(long a, long b) { return (a < b ? a : b); } static __inline u_int max(u_int a, u_int b) { return (a > b ? a : b); } static __inline u_int min(u_int a, u_int b) { return (a < b ? a : b); } static __inline quad_t qmax(quad_t a, quad_t b) { return (a > b ? a : b); } static __inline quad_t qmin(quad_t a, quad_t b) { return (a < b ? a : b); } static __inline u_long ulmax(u_long a, u_long b) { return (a > b ? a : b); } static __inline u_long ulmin(u_long a, u_long b) { return (a < b ? a : b); } /* swaps (undocumented, useful?) */ #ifdef __i386__ extern u_int32_t bswap32(u_int32_t x); extern u_int64_t bswap64(u_int32_t x); #endif /* null functions for device/filesystem switches (undocumented) */ extern int nodev(void); extern int noioctl(struct open_file *, u_long, void *); extern void nullsys(void); extern int null_open(const char *path, struct open_file *f); extern int null_close(struct open_file *f); extern int null_read(struct open_file *f, void *buf, size_t size, size_t *resid); extern int null_write(struct open_file *f, void *buf, size_t size, size_t *resid); extern off_t null_seek(struct open_file *f, off_t offset, int where); extern int null_stat(struct open_file *f, struct stat *sb); extern int null_readdir(struct open_file *f, struct dirent *d); /* * Machine dependent functions and data, must be provided or stubbed by * the consumer */ extern int getchar(void); extern int ischar(void); extern void putchar(int); extern int devopen(struct open_file *, const char *, const char **); extern int devclose(struct open_file *f); extern void panic(const char *, ...) __dead2; extern struct fs_ops *file_system[]; extern struct devsw *devsw[]; #if 0 static inline void * malloc_debug(size_t size, const char *file, int line) { void *p; printf("%s:%d malloc(%ld)", file, line, size); p = malloc(size); printf("=%p\n", p); return p; } static inline void free_debug(void *p, const char *file, int line) { printf("%s:%d free(%p)\n", file, line, p); free(p); } #define malloc(x) malloc_debug(x, __FILE__, __LINE__) #define free(x) free_debug(x, __FILE__, __LINE__) #endif