Index: head/sys/kern/subr_clist.c =================================================================== --- head/sys/kern/subr_clist.c (revision 183237) +++ head/sys/kern/subr_clist.c (revision 183238) @@ -1,700 +1,533 @@ /*- * Copyright (c) 1994, David Greenman * 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 unmodified, 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. */ /* * clist support routines */ #include __FBSDID("$FreeBSD$"); #include #include #include #include #include static void clist_init(void *); SYSINIT(clist, SI_SUB_CLIST, SI_ORDER_FIRST, clist_init, NULL); static MALLOC_DEFINE(M_CLIST, "clist", "clist queue blocks"); static struct cblock *cfreelist = 0; int cfreecount = 0; static int cslushcount; static int ctotcount; #ifndef INITIAL_CBLOCKS #define INITIAL_CBLOCKS 50 #endif -#define QUOTEMASK 0x100 - static struct cblock *cblock_alloc(void); static void cblock_alloc_cblocks(int number); static void cblock_free(struct cblock *cblockp); static void cblock_free_cblocks(int number); #include "opt_ddb.h" #ifdef DDB #include DB_SHOW_COMMAND(cbstat, cbstat) { int cbsize = CBSIZE; printf( "tot = %d (active = %d, free = %d (reserved = %d, slush = %d))\n", ctotcount * cbsize, ctotcount * cbsize - cfreecount, cfreecount, cfreecount - cslushcount * cbsize, cslushcount * cbsize); } #endif /* DDB */ /* * Called from init_main.c */ /* ARGSUSED*/ static void -clist_init(dummy) - void *dummy; +clist_init(void *dummy) { /* * Allocate an initial base set of cblocks as a 'slush'. * We allocate non-slush cblocks with each initial tty_open() and * deallocate them with each tty_close(). * We should adjust the slush allocation. This can't be done in * the i/o routines because they are sometimes called from * interrupt handlers when it may be unsafe to call malloc(). */ cblock_alloc_cblocks(cslushcount = INITIAL_CBLOCKS); } /* * Remove a cblock from the cfreelist queue and return a pointer * to it. */ static __inline struct cblock * -cblock_alloc() +cblock_alloc(void) { struct cblock *cblockp; cblockp = cfreelist; if (cblockp == NULL) panic("clist reservation botch"); cfreelist = cblockp->c_next; cblockp->c_next = NULL; cfreecount -= CBSIZE; return (cblockp); } /* * Add a cblock to the cfreelist queue. */ static __inline void -cblock_free(cblockp) - struct cblock *cblockp; +cblock_free(struct cblock *cblockp) { - if (isset(cblockp->c_quote, CBQSIZE * NBBY - 1)) - bzero(cblockp->c_quote, sizeof cblockp->c_quote); cblockp->c_next = cfreelist; cfreelist = cblockp; cfreecount += CBSIZE; } /* * Allocate some cblocks for the cfreelist queue. */ static void -cblock_alloc_cblocks(number) - int number; +cblock_alloc_cblocks(int number) { int i; struct cblock *cbp; for (i = 0; i < number; ++i) { cbp = malloc(sizeof *cbp, M_CLIST, M_NOWAIT); if (cbp == NULL) { printf( "cblock_alloc_cblocks: M_NOWAIT malloc failed, trying M_WAITOK\n"); cbp = malloc(sizeof *cbp, M_CLIST, M_WAITOK); } /* * Freed cblocks have zero quotes and garbage elsewhere. * Set the may-have-quote bit to force zeroing the quotes. */ - setbit(cbp->c_quote, CBQSIZE * NBBY - 1); cblock_free(cbp); } ctotcount += number; } /* * Set the cblock allocation policy for a clist. * Must be called in process context at spltty(). */ void -clist_alloc_cblocks(clistp, ccmax, ccreserved) - struct clist *clistp; - int ccmax; - int ccreserved; +clist_alloc_cblocks(struct clist *clistp, int ccmax, int ccreserved) { int dcbr; /* * Allow for wasted space at the head. */ if (ccmax != 0) ccmax += CBSIZE - 1; if (ccreserved != 0) ccreserved += CBSIZE - 1; clistp->c_cbmax = roundup(ccmax, CBSIZE) / CBSIZE; dcbr = roundup(ccreserved, CBSIZE) / CBSIZE - clistp->c_cbreserved; if (dcbr >= 0) cblock_alloc_cblocks(dcbr); else { if (clistp->c_cbreserved + dcbr < clistp->c_cbcount) dcbr = clistp->c_cbcount - clistp->c_cbreserved; cblock_free_cblocks(-dcbr); } clistp->c_cbreserved += dcbr; } /* * Free some cblocks from the cfreelist queue back to the * system malloc pool. */ static void -cblock_free_cblocks(number) - int number; +cblock_free_cblocks(int number) { int i; for (i = 0; i < number; ++i) free(cblock_alloc(), M_CLIST); ctotcount -= number; } /* * Free the cblocks reserved for a clist. * Must be called at spltty(). */ void -clist_free_cblocks(clistp) - struct clist *clistp; +clist_free_cblocks(struct clist *clistp) { if (clistp->c_cbcount != 0) panic("freeing active clist cblocks"); cblock_free_cblocks(clistp->c_cbreserved); clistp->c_cbmax = 0; clistp->c_cbreserved = 0; } /* * Get a character from the head of a clist. */ int -getc(clistp) - struct clist *clistp; +getc(struct clist *clistp) { int chr = -1; int s; struct cblock *cblockp; s = spltty(); /* If there are characters in the list, get one */ if (clistp->c_cc) { cblockp = (struct cblock *)((intptr_t)clistp->c_cf & ~CROUND); chr = (u_char)*clistp->c_cf; /* - * If this char is quoted, set the flag. - */ - if (isset(cblockp->c_quote, clistp->c_cf - (char *)cblockp->c_info)) - chr |= QUOTEMASK; - - /* * Advance to next character. */ clistp->c_cf++; clistp->c_cc--; /* * If we have advanced the 'first' character pointer * past the end of this cblock, advance to the next one. * If there are no more characters, set the first and * last pointers to NULL. In either case, free the * current cblock. */ if ((clistp->c_cf >= (char *)(cblockp+1)) || (clistp->c_cc == 0)) { if (clistp->c_cc > 0) { clistp->c_cf = cblockp->c_next->c_info; } else { clistp->c_cf = clistp->c_cl = NULL; } cblock_free(cblockp); if (--clistp->c_cbcount >= clistp->c_cbreserved) ++cslushcount; } } splx(s); return (chr); } /* * Copy 'amount' of chars, beginning at head of clist 'clistp' to * destination linear buffer 'dest'. Return number of characters * actually copied. */ int -q_to_b(clistp, dest, amount) - struct clist *clistp; - char *dest; - int amount; +q_to_b(struct clist *clistp, char *dest, int amount) { struct cblock *cblockp; struct cblock *cblockn; char *dest_orig = dest; int numc; int s; s = spltty(); while (clistp && amount && (clistp->c_cc > 0)) { cblockp = (struct cblock *)((intptr_t)clistp->c_cf & ~CROUND); cblockn = cblockp + 1; /* pointer arithmetic! */ numc = min(amount, (char *)cblockn - clistp->c_cf); numc = min(numc, clistp->c_cc); bcopy(clistp->c_cf, dest, numc); amount -= numc; clistp->c_cf += numc; clistp->c_cc -= numc; dest += numc; /* * If this cblock has been emptied, advance to the next * one. If there are no more characters, set the first * and last pointer to NULL. In either case, free the * current cblock. */ if ((clistp->c_cf >= (char *)cblockn) || (clistp->c_cc == 0)) { if (clistp->c_cc > 0) { clistp->c_cf = cblockp->c_next->c_info; } else { clistp->c_cf = clistp->c_cl = NULL; } cblock_free(cblockp); if (--clistp->c_cbcount >= clistp->c_cbreserved) ++cslushcount; } } splx(s); return (dest - dest_orig); } /* * Flush 'amount' of chars, beginning at head of clist 'clistp'. */ void -ndflush(clistp, amount) - struct clist *clistp; - int amount; +ndflush(struct clist *clistp, int amount) { struct cblock *cblockp; struct cblock *cblockn; int numc; int s; s = spltty(); while (amount && (clistp->c_cc > 0)) { cblockp = (struct cblock *)((intptr_t)clistp->c_cf & ~CROUND); cblockn = cblockp + 1; /* pointer arithmetic! */ numc = min(amount, (char *)cblockn - clistp->c_cf); numc = min(numc, clistp->c_cc); amount -= numc; clistp->c_cf += numc; clistp->c_cc -= numc; /* * If this cblock has been emptied, advance to the next * one. If there are no more characters, set the first * and last pointer to NULL. In either case, free the * current cblock. */ if ((clistp->c_cf >= (char *)cblockn) || (clistp->c_cc == 0)) { if (clistp->c_cc > 0) { clistp->c_cf = cblockp->c_next->c_info; } else { clistp->c_cf = clistp->c_cl = NULL; } cblock_free(cblockp); if (--clistp->c_cbcount >= clistp->c_cbreserved) ++cslushcount; } } splx(s); } /* * Add a character to the end of a clist. Return -1 is no * more clists, or 0 for success. */ int -putc(chr, clistp) - int chr; - struct clist *clistp; +putc(char chr, struct clist *clistp) { struct cblock *cblockp; int s; s = spltty(); if (clistp->c_cl == NULL) { if (clistp->c_cbreserved < 1) { splx(s); printf("putc to a clist with no reserved cblocks\n"); return (-1); /* nothing done */ } cblockp = cblock_alloc(); clistp->c_cbcount = 1; clistp->c_cf = clistp->c_cl = cblockp->c_info; clistp->c_cc = 0; } else { cblockp = (struct cblock *)((intptr_t)clistp->c_cl & ~CROUND); if (((intptr_t)clistp->c_cl & CROUND) == 0) { struct cblock *prev = (cblockp - 1); if (clistp->c_cbcount >= clistp->c_cbreserved) { if (clistp->c_cbcount >= clistp->c_cbmax || cslushcount <= 0) { splx(s); return (-1); } --cslushcount; } cblockp = cblock_alloc(); clistp->c_cbcount++; prev->c_next = cblockp; clistp->c_cl = cblockp->c_info; } } - /* - * If this character is quoted, set the quote bit, if not, clear it. - */ - if (chr & QUOTEMASK) { - setbit(cblockp->c_quote, clistp->c_cl - (char *)cblockp->c_info); - /* - * Use one of the spare quote bits to record that something - * may be quoted. - */ - setbit(cblockp->c_quote, CBQSIZE * NBBY - 1); - } else - clrbit(cblockp->c_quote, clistp->c_cl - (char *)cblockp->c_info); - *clistp->c_cl++ = chr; clistp->c_cc++; splx(s); return (0); } /* * Copy data from linear buffer to clist chain. Return the * number of characters not copied. */ int -b_to_q(src, amount, clistp) - char *src; - int amount; - struct clist *clistp; +b_to_q(char *src, int amount, struct clist *clistp) { struct cblock *cblockp; - char *firstbyte, *lastbyte; - u_char startmask, endmask; - int startbit, endbit, num_between, numc; - int s; + int numc, s; /* * Avoid allocating an initial cblock and then not using it. * c_cc == 0 must imply c_cbount == 0. */ if (amount <= 0) return (amount); s = spltty(); /* * If there are no cblocks assigned to this clist yet, * then get one. */ if (clistp->c_cl == NULL) { if (clistp->c_cbreserved < 1) { splx(s); printf("b_to_q to a clist with no reserved cblocks.\n"); return (amount); /* nothing done */ } cblockp = cblock_alloc(); clistp->c_cbcount = 1; clistp->c_cf = clistp->c_cl = cblockp->c_info; clistp->c_cc = 0; } else { cblockp = (struct cblock *)((intptr_t)clistp->c_cl & ~CROUND); } while (amount) { /* * Get another cblock if needed. */ if (((intptr_t)clistp->c_cl & CROUND) == 0) { struct cblock *prev = cblockp - 1; if (clistp->c_cbcount >= clistp->c_cbreserved) { if (clistp->c_cbcount >= clistp->c_cbmax || cslushcount <= 0) { splx(s); return (amount); } --cslushcount; } cblockp = cblock_alloc(); clistp->c_cbcount++; prev->c_next = cblockp; clistp->c_cl = cblockp->c_info; } /* * Copy a chunk of the linear buffer up to the end * of this cblock. */ numc = min(amount, (char *)(cblockp + 1) - clistp->c_cl); bcopy(src, clistp->c_cl, numc); /* - * Clear quote bits if they aren't known to be clear. - * The following could probably be made into a separate - * "bitzero()" routine, but why bother? - */ - if (isset(cblockp->c_quote, CBQSIZE * NBBY - 1)) { - startbit = clistp->c_cl - (char *)cblockp->c_info; - endbit = startbit + numc - 1; - - firstbyte = (u_char *)cblockp->c_quote + (startbit / NBBY); - lastbyte = (u_char *)cblockp->c_quote + (endbit / NBBY); - - /* - * Calculate mask of bits to preserve in first and - * last bytes. - */ - startmask = NBBY - (startbit % NBBY); - startmask = 0xff >> startmask; - endmask = (endbit % NBBY); - endmask = 0xff << (endmask + 1); - - if (firstbyte != lastbyte) { - *firstbyte &= startmask; - *lastbyte &= endmask; - - num_between = lastbyte - firstbyte - 1; - if (num_between) - bzero(firstbyte + 1, num_between); - } else { - *firstbyte &= (startmask | endmask); - } - } - - /* * ...and update pointer for the next chunk. */ src += numc; clistp->c_cl += numc; clistp->c_cc += numc; amount -= numc; /* * If we go through the loop again, it's always * for data in the next cblock, so by adding one (cblock), * (which makes the pointer 1 beyond the end of this * cblock) we prepare for the assignment of 'prev' * above. */ cblockp += 1; } splx(s); return (amount); } /* - * Get the next character in the clist. Store it at dst. Don't - * advance any clist pointers, but return a pointer to the next - * character position. - */ -char * -nextc(clistp, cp, dst) - struct clist *clistp; - char *cp; - int *dst; -{ - struct cblock *cblockp; - - ++cp; - /* - * See if the next character is beyond the end of - * the clist. - */ - if (clistp->c_cc && (cp != clistp->c_cl)) { - /* - * If the next character is beyond the end of this - * cblock, advance to the next cblock. - */ - if (((intptr_t)cp & CROUND) == 0) - cp = ((struct cblock *)cp - 1)->c_next->c_info; - cblockp = (struct cblock *)((intptr_t)cp & ~CROUND); - - /* - * Get the character. Set the quote flag if this character - * is quoted. - */ - *dst = (u_char)*cp | (isset(cblockp->c_quote, cp - (char *)cblockp->c_info) ? QUOTEMASK : 0); - - return (cp); - } - - return (NULL); -} - -/* * "Unput" a character from a clist. */ int -unputc(clistp) - struct clist *clistp; +unputc(struct clist *clistp) { struct cblock *cblockp = 0, *cbp = 0; int s; int chr = -1; s = spltty(); if (clistp->c_cc) { --clistp->c_cc; --clistp->c_cl; chr = (u_char)*clistp->c_cl; cblockp = (struct cblock *)((intptr_t)clistp->c_cl & ~CROUND); /* - * Set quote flag if this character was quoted. - */ - if (isset(cblockp->c_quote, (u_char *)clistp->c_cl - cblockp->c_info)) - chr |= QUOTEMASK; - - /* * If all of the characters have been unput in this * cblock, then find the previous one and free this * one. */ if (clistp->c_cc && (clistp->c_cl <= (char *)cblockp->c_info)) { cbp = (struct cblock *)((intptr_t)clistp->c_cf & ~CROUND); while (cbp->c_next != cblockp) cbp = cbp->c_next; /* * When the previous cblock is at the end, the 'last' * pointer always points (invalidly) one past. */ clistp->c_cl = (char *)(cbp+1); cblock_free(cblockp); if (--clistp->c_cbcount >= clistp->c_cbreserved) ++cslushcount; cbp->c_next = NULL; } } /* * If there are no more characters on the list, then * free the last cblock. */ if ((clistp->c_cc == 0) && clistp->c_cl) { cblockp = (struct cblock *)((intptr_t)clistp->c_cl & ~CROUND); cblock_free(cblockp); if (--clistp->c_cbcount >= clistp->c_cbreserved) ++cslushcount; clistp->c_cf = clistp->c_cl = NULL; } splx(s); return (chr); -} - -/* - * Move characters in source clist to destination clist, - * preserving quote bits. - */ -void -catq(src_clistp, dest_clistp) - struct clist *src_clistp, *dest_clistp; -{ - int chr, s; - - s = spltty(); - /* - * If the destination clist is empty (has no cblocks atttached), - * and there are no possible complications with the resource counters, - * then we simply assign the current clist to the destination. - */ - if (!dest_clistp->c_cf - && src_clistp->c_cbcount <= src_clistp->c_cbmax - && src_clistp->c_cbcount <= dest_clistp->c_cbmax) { - dest_clistp->c_cf = src_clistp->c_cf; - dest_clistp->c_cl = src_clistp->c_cl; - src_clistp->c_cf = src_clistp->c_cl = NULL; - - dest_clistp->c_cc = src_clistp->c_cc; - src_clistp->c_cc = 0; - dest_clistp->c_cbcount = src_clistp->c_cbcount; - src_clistp->c_cbcount = 0; - - splx(s); - return; - } - - splx(s); - - /* - * XXX This should probably be optimized to more than one - * character at a time. - */ - while ((chr = getc(src_clistp)) != -1) - putc(chr, dest_clistp); } Index: head/sys/sys/clist.h =================================================================== --- head/sys/sys/clist.h (revision 183237) +++ head/sys/sys/clist.h (revision 183238) @@ -1,72 +1,69 @@ /*- * Copyright (c) 1990, 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. * 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. * * @(#)clist.h 8.1 (Berkeley) 6/4/93 * $FreeBSD$ */ #ifndef _SYS_CLIST_H_ #define _SYS_CLIST_H_ #include /* * Clists are character lists, which is a variable length linked list * of cblocks, with a count of the number of characters in the list. */ struct clist { int c_cc; /* Number of characters in the clist. */ int c_cbcount; /* Number of cblocks. */ int c_cbmax; /* Max # cblocks allowed for this clist. */ int c_cbreserved; /* # cblocks reserved for this clist. */ char *c_cf; /* Pointer to the first cblock. */ char *c_cl; /* Pointer to the last cblock. */ }; struct cblock { struct cblock *c_next; /* next cblock in queue */ - unsigned char c_quote[CBQSIZE]; /* quoted characters */ unsigned char c_info[CBSIZE]; /* characters */ }; #ifdef _KERNEL extern int cfreecount; int b_to_q(char *cp, int cc, struct clist *q); -void catq(struct clist *from, struct clist *to); void clist_alloc_cblocks(struct clist *q, int ccmax, int ccres); void clist_free_cblocks(struct clist *q); int getc(struct clist *q); void ndflush(struct clist *q, int cc); -char *nextc(struct clist *q, char *cp, int *c); -int putc(int c, struct clist *q); +int putc(char c, struct clist *q); int q_to_b(struct clist *q, char *cp, int cc); int unputc(struct clist *q); #endif #endif Index: head/sys/sys/param.h =================================================================== --- head/sys/sys/param.h (revision 183237) +++ head/sys/sys/param.h (revision 183238) @@ -1,315 +1,314 @@ /*- * Copyright (c) 1982, 1986, 1989, 1993 * The Regents of the University of California. All rights reserved. * (c) UNIX System Laboratories, Inc. * All or some portions of this file are derived from material licensed * to the University of California by American Telephone and Telegraph * Co. or Unix System Laboratories, Inc. and are reproduced herein with * the permission of UNIX System Laboratories, Inc. * * 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. * 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. * * @(#)param.h 8.3 (Berkeley) 4/4/95 * $FreeBSD$ */ #ifndef _SYS_PARAM_H_ #define _SYS_PARAM_H_ #include #define BSD 199506 /* System version (year & month). */ #define BSD4_3 1 #define BSD4_4 1 /* * __FreeBSD_version numbers are documented in the Porter's Handbook. * If you bump the version for any reason, you should update the documentation * there. * Currently this lives here: * * doc/en_US.ISO8859-1/books/porters-handbook/book.sgml * * scheme is: Rxx * 'R' is 0 if release branch or x.0-CURRENT before RELENG_*_0 * is created, otherwise 1. */ #undef __FreeBSD_version #define __FreeBSD_version 800049 /* Master, propagated to newvers */ #ifndef LOCORE #include #endif /* * Machine-independent constants (some used in following include files). * Redefined constants are from POSIX 1003.1 limits file. * * MAXCOMLEN should be >= sizeof(ac_comm) (see ) * MAXLOGNAME should be == UT_NAMESIZE+1 (see ) */ #include #define MAXCOMLEN 19 /* max command name remembered */ #define MAXINTERP 32 /* max interpreter file name length */ #define MAXLOGNAME 17 /* max login name length (incl. NUL) */ #define MAXUPRC CHILD_MAX /* max simultaneous processes */ #define NCARGS ARG_MAX /* max bytes for an exec function */ #define NGROUPS NGROUPS_MAX /* max number groups */ #define NOFILE OPEN_MAX /* max open files per process */ #define NOGROUP 65535 /* marker for empty group set member */ #define MAXHOSTNAMELEN 256 /* max hostname size */ #define SPECNAMELEN 63 /* max length of devicename */ /* More types and definitions used throughout the kernel. */ #ifdef _KERNEL #include #include #ifndef LOCORE #include #include #endif #define FALSE 0 #define TRUE 1 #endif #ifndef _KERNEL /* Signals. */ #include #endif /* Machine type dependent parameters. */ #include #ifndef _KERNEL #include #endif #ifndef _NO_NAMESPACE_POLLUTION #ifndef DEV_BSHIFT #define DEV_BSHIFT 9 /* log2(DEV_BSIZE) */ #endif #define DEV_BSIZE (1<>PAGE_SHIFT) #endif /* * btodb() is messy and perhaps slow because `bytes' may be an off_t. We * want to shift an unsigned type to avoid sign extension and we don't * want to widen `bytes' unnecessarily. Assume that the result fits in * a daddr_t. */ #ifndef btodb #define btodb(bytes) /* calculates (bytes / DEV_BSIZE) */ \ (sizeof (bytes) > sizeof(long) \ ? (daddr_t)((unsigned long long)(bytes) >> DEV_BSHIFT) \ : (daddr_t)((unsigned long)(bytes) >> DEV_BSHIFT)) #endif #ifndef dbtob #define dbtob(db) /* calculates (db * DEV_BSIZE) */ \ ((off_t)(db) << DEV_BSHIFT) #endif #endif /* _NO_NAMESPACE_POLLUTION */ #define PRIMASK 0x0ff #define PCATCH 0x100 /* OR'd with pri for tsleep to check signals */ #define PDROP 0x200 /* OR'd with pri to stop re-entry of interlock mutex */ #define NZERO 0 /* default "nice" */ #define NBBY 8 /* number of bits in a byte */ #define NBPW sizeof(int) /* number of bytes per word (integer) */ #define CMASK 022 /* default file mask: S_IWGRP|S_IWOTH */ #define NODEV (dev_t)(-1) /* non-existent device */ #define CBLOCK 128 /* Clist block size, must be a power of 2. */ -#define CBQSIZE (CBLOCK/NBBY) /* Quote bytes/cblock - can do better. */ /* Data chars/clist. */ -#define CBSIZE (CBLOCK - sizeof(struct cblock *) - CBQSIZE) +#define CBSIZE (CBLOCK - sizeof(struct cblock *)) #define CROUND (CBLOCK - 1) /* Clist rounding. */ /* * File system parameters and macros. * * MAXBSIZE - Filesystems are made out of blocks of at most MAXBSIZE bytes * per block. MAXBSIZE may be made larger without effecting * any existing filesystems as long as it does not exceed MAXPHYS, * and may be made smaller at the risk of not being able to use * filesystems which require a block size exceeding MAXBSIZE. * * BKVASIZE - Nominal buffer space per buffer, in bytes. BKVASIZE is the * minimum KVM memory reservation the kernel is willing to make. * Filesystems can of course request smaller chunks. Actual * backing memory uses a chunk size of a page (PAGE_SIZE). * * If you make BKVASIZE too small you risk seriously fragmenting * the buffer KVM map which may slow things down a bit. If you * make it too big the kernel will not be able to optimally use * the KVM memory reserved for the buffer cache and will wind * up with too-few buffers. * * The default is 16384, roughly 2x the block size used by a * normal UFS filesystem. */ #define MAXBSIZE 65536 /* must be power of 2 */ #define BKVASIZE 16384 /* must be power of 2 */ #define BKVAMASK (BKVASIZE-1) /* * MAXPATHLEN defines the longest permissible path length after expanding * symbolic links. It is used to allocate a temporary buffer from the buffer * pool in which to do the name expansion, hence should be a power of two, * and must be less than or equal to MAXBSIZE. MAXSYMLINKS defines the * maximum number of symbolic links that may be expanded in a path name. * It should be set high enough to allow all legitimate uses, but halt * infinite loops reasonably quickly. */ #define MAXPATHLEN PATH_MAX #define MAXSYMLINKS 32 /* Bit map related macros. */ #define setbit(a,i) (((unsigned char *)(a))[(i)/NBBY] |= 1<<((i)%NBBY)) #define clrbit(a,i) (((unsigned char *)(a))[(i)/NBBY] &= ~(1<<((i)%NBBY))) #define isset(a,i) \ (((const unsigned char *)(a))[(i)/NBBY] & (1<<((i)%NBBY))) #define isclr(a,i) \ ((((const unsigned char *)(a))[(i)/NBBY] & (1<<((i)%NBBY))) == 0) /* Macros for counting and rounding. */ #ifndef howmany #define howmany(x, y) (((x)+((y)-1))/(y)) #endif #define rounddown(x, y) (((x)/(y))*(y)) #define roundup(x, y) ((((x)+((y)-1))/(y))*(y)) /* to any y */ #define roundup2(x, y) (((x)+((y)-1))&(~((y)-1))) /* if y is powers of two */ #define powerof2(x) ((((x)-1)&(x))==0) /* Macros for min/max. */ #define MIN(a,b) (((a)<(b))?(a):(b)) #define MAX(a,b) (((a)>(b))?(a):(b)) #ifdef _KERNEL /* * Basic byte order function prototypes for non-inline functions. */ #ifndef LOCORE #ifndef _BYTEORDER_PROTOTYPED #define _BYTEORDER_PROTOTYPED __BEGIN_DECLS __uint32_t htonl(__uint32_t); __uint16_t htons(__uint16_t); __uint32_t ntohl(__uint32_t); __uint16_t ntohs(__uint16_t); __END_DECLS #endif #endif #ifndef lint #ifndef _BYTEORDER_FUNC_DEFINED #define _BYTEORDER_FUNC_DEFINED #define htonl(x) __htonl(x) #define htons(x) __htons(x) #define ntohl(x) __ntohl(x) #define ntohs(x) __ntohs(x) #endif /* !_BYTEORDER_FUNC_DEFINED */ #endif /* lint */ #endif /* _KERNEL */ /* * Scale factor for scaled integers used to count %cpu time and load avgs. * * The number of CPU `tick's that map to a unique `%age' can be expressed * by the formula (1 / (2 ^ (FSHIFT - 11))). The maximum load average that * can be calculated (assuming 32 bits) can be closely approximated using * the formula (2 ^ (2 * (16 - FSHIFT))) for (FSHIFT < 15). * * For the scheduler to maintain a 1:1 mapping of CPU `tick' to `%age', * FSHIFT must be at least 11; this gives us a maximum load avg of ~1024. */ #define FSHIFT 11 /* bits to right of fixed binary point */ #define FSCALE (1<> (PAGE_SHIFT - DEV_BSHIFT)) #define ctodb(db) /* calculates pages to devblks */ \ ((db) << (PAGE_SHIFT - DEV_BSHIFT)) /* * Given the pointer x to the member m of the struct s, return * a pointer to the containing structure. */ #define member2struct(s, m, x) \ ((struct s *)(void *)((char *)(x) - offsetof(struct s, m))) #endif /* _SYS_PARAM_H_ */