From 5685f7669ad9386c7ce2aa46b0091902289cfc95 Mon Sep 17 00:00:00 2001 From: Keith Bostic Date: Sun, 5 Sep 1993 16:45:05 -0800 Subject: [PATCH] Cleanups for 4.4BSD-Lite SCCS-vsn: sys/sys/tty.h 8.2 SCCS-vsn: sys/sys/vnode.h 8.2 SCCS-vsn: sys/vm/vm_glue.c 8.2 SCCS-vsn: sys/ufs/ffs/ufs_bmap.c 8.2 SCCS-vsn: sys/ufs/ufs/ufs_bmap.c 8.2 SCCS-vsn: sys/ufs/ffs/ufs_disksubr.c 8.2 SCCS-vsn: sys/ufs/ufs/ufs_disksubr.c 8.2 SCCS-vsn: sys/ufs/ffs/ufs_ihash.c 8.2 SCCS-vsn: sys/ufs/ufs/ufs_ihash.c 8.2 SCCS-vsn: sys/kern/kern_clock.c 8.2 SCCS-vsn: sys/ufs/ffs/ufs_vnops.c 8.2 SCCS-vsn: sys/ufs/ufs/ufs_vnops.c 8.2 --- usr/src/sys/kern/kern_clock.c | 102 +++++++++------ usr/src/sys/sys/tty.h | 196 +++++++++++++++++------------ usr/src/sys/sys/vnode.h | 4 +- usr/src/sys/ufs/ffs/ufs_bmap.c | 46 ++++--- usr/src/sys/ufs/ffs/ufs_disksubr.c | 98 ++++++++------- usr/src/sys/ufs/ffs/ufs_ihash.c | 61 +++++---- usr/src/sys/ufs/ffs/ufs_vnops.c | 17 +-- usr/src/sys/ufs/ufs/ufs_bmap.c | 46 ++++--- usr/src/sys/ufs/ufs/ufs_disksubr.c | 98 ++++++++------- usr/src/sys/ufs/ufs/ufs_ihash.c | 61 +++++---- usr/src/sys/ufs/ufs/ufs_vnops.c | 17 +-- usr/src/sys/vm/vm_glue.c | 4 +- 12 files changed, 391 insertions(+), 359 deletions(-) diff --git a/usr/src/sys/kern/kern_clock.c b/usr/src/sys/kern/kern_clock.c index c74ae03c96..237cc307d0 100644 --- a/usr/src/sys/kern/kern_clock.c +++ b/usr/src/sys/kern/kern_clock.c @@ -4,7 +4,7 @@ * * %sccs.include.redist.c% * - * @(#)kern_clock.c 8.1 (Berkeley) %G% + * @(#)kern_clock.c 8.2 (Berkeley) %G% */ #include @@ -211,67 +211,87 @@ softclock() } /* - * Arrange that (*func)(arg) is called in t/hz seconds. + * timeout -- + * Execute a function after a specified length of time. + * + * untimeout -- + * Cancel previous timeout function call. + * + * See AT&T BCI Driver Reference Manual for specification. This + * implementation differs from that one in that no identification + * value is returned from timeout, rather, the original arguments + * to timeout are used to identify entries for untimeout. */ void -timeout(func, arg, t) - void (*func) __P((void *)); +timeout(ftn, arg, ticks) + void (*ftn) __P((void *)); void *arg; - register int t; + register int ticks; { - register struct callout *p1, *p2, *pnew; + register struct callout *new, *p, *t; register int s; + if (ticks <= 0) + ticks = 1; + + /* Lock out the clock. */ s = splhigh(); - if (t <= 0) - t = 1; - pnew = callfree; - if (pnew == NULL) - panic("timeout table overflow"); - callfree = pnew->c_next; - pnew->c_arg = arg; - pnew->c_func = func; - for (p1 = &calltodo; (p2 = p1->c_next) && p2->c_time < t; p1 = p2) - if (p2->c_time > 0) - t -= p2->c_time; - p1->c_next = pnew; - pnew->c_next = p2; - pnew->c_time = t; - if (p2) - p2->c_time -= t; + + /* Fill in the next free callout structure. */ + if (callfree == NULL) + panic("timeout table full"); + new = callfree; + callfree = new->c_next; + new->c_arg = arg; + new->c_func = ftn; + + /* + * The time for each event is stored as a difference from the time + * of the previous event on the queue. Walk the queue, correcting + * the ticks argument for queue entries passed. Correct the ticks + * value for the queue entry immediately after the insertion point + * as well. + */ + for (p = &calltodo; + (t = p->c_next) != NULL && ticks > t->c_time; p = t) + ticks -= t->c_time; + new->c_time = ticks; + if (t != NULL) + t->c_time -= ticks; + + /* Insert the new entry into the queue. */ + p->c_next = new; + new->c_next = t; splx(s); } -/* - * untimeout is called to remove a function timeout call - * from the callout structure. - */ void -untimeout(func, arg) - void (*func) __P((void *)); +untimeout(ftn, arg) + void (*ftn) __P((void *)); void *arg; { - register struct callout *p1, *p2; + register struct callout *p, *t; register int s; s = splhigh(); - for (p1 = &calltodo; (p2 = p1->c_next) != NULL; p1 = p2) { - if (p2->c_func == func && p2->c_arg == arg) { - if (p2->c_next && p2->c_time > 0) - p2->c_next->c_time += p2->c_time; - p1->c_next = p2->c_next; - p2->c_next = callfree; - callfree = p2; + for (p = &calltodo; (t = p->c_next) != NULL; p = t) + if (t->c_func == ftn && t->c_arg == arg) { + /* Increment next entry's tick count. */ + if (t->c_next && t->c_time > 0) + t->c_next->c_time += t->c_time; + + /* Move entry from callout queue to callfree queue. */ + p->c_next = t->c_next; + t->c_next = callfree; + callfree = t; break; } - } splx(s); } /* - * Compute number of hz until specified time. - * Used to compute third argument to timeout() from an - * absolute time. + * Compute number of hz until specified time. Used to + * compute third argument to timeout() from an absolute time. */ int hzto(tv) @@ -449,7 +469,7 @@ statclock(frame) if (++p->p_cpu == 0) p->p_cpu--; if ((p->p_cpu & 3) == 0) { - setpri(p); + resetpriority(p); if (p->p_pri >= PUSER) p->p_pri = p->p_usrpri; } diff --git a/usr/src/sys/sys/tty.h b/usr/src/sys/sys/tty.h index 98d595e641..7e393a2c6d 100644 --- a/usr/src/sys/sys/tty.h +++ b/usr/src/sys/sys/tty.h @@ -4,20 +4,20 @@ * * %sccs.include.redist.c% * - * @(#)tty.h 8.1 (Berkeley) %G% + * @(#)tty.h 8.2 (Berkeley) %G% */ #include -#include /* for struct selinfo */ +#include /* For struct selinfo. */ /* * Clists are character lists, which is a variable length linked list - * of cblocks, wiht a count of the number of characters in the list. + * of cblocks, with a count of the number of characters in the list. */ struct clist { - int c_cc; /* count of characters in queue */ - char *c_cf; /* first character/cblock */ - char *c_cl; /* last chararacter/cblock */ + int c_cc; /* Number of characters in the clist. */ + char *c_cf; /* Pointer to the first cblock. */ + char *c_cl; /* Pointer to the last cblock. */ }; /* @@ -28,30 +28,30 @@ struct clist { * (low, high, timeout). */ struct tty { - struct clist t_rawq; /* queues */ - struct clist t_canq; - struct clist t_outq; - void (*t_oproc)(); /* device */ + struct clist t_rawq; /* Device raw input queue. */ + struct clist t_canq; /* Device canonical queue. */ + struct clist t_outq; /* Device output queue. */ + void (*t_oproc)(); /* Device. */ #ifdef sun4c - void (*t_stop)(); /* device */ + void (*t_stop)(); /* Device. */ #endif - int (*t_param)(); /* device */ - struct selinfo t_rsel; /* tty read/oob select */ - struct selinfo t_wsel; /* tty write select */ + int (*t_param)(); /* Device. */ + struct selinfo t_rsel; /* Tty read/oob select. */ + struct selinfo t_wsel; /* Tty write select. */ caddr_t T_LINEP; /* XXX */ - caddr_t t_addr; /* ??? */ - dev_t t_dev; /* device */ + caddr_t t_addr; /* XXX */ + dev_t t_dev; /* Device. */ int t_flags; /* (compat) some of both */ - int t_state; /* some of both */ + int t_state; /* Device and driver internal state. */ struct session *t_session; /* tty */ - struct pgrp *t_pgrp; /* foreground process group */ - char t_line; /* glue */ - short t_col; /* tty */ - short t_rocount, t_rocol; /* tty */ - short t_hiwat; /* hi water mark */ - short t_lowat; /* low water mark */ - struct winsize t_winsize; /* window size */ - struct termios t_termios; /* termios state */ + struct pgrp *t_pgrp; /* Foreground process group. */ + char t_line; /* Glue. */ + short t_col; /* Tty. */ + short t_rocount, t_rocol; /* Tty. */ + short t_hiwat; /* High water mark. */ + short t_lowat; /* Low water mark. */ + struct winsize t_winsize; /* Window size. */ + struct termios t_termios; /* Termios state. */ #define t_iflag t_termios.c_iflag #define t_oflag t_termios.c_oflag #define t_cflag t_termios.c_cflag @@ -59,52 +59,51 @@ struct tty { #define t_min t_termios.c_min #define t_time t_termios.c_time #define t_cc t_termios.c_cc -#define t_ispeed t_termios.c_ispeed -#define t_ospeed t_termios.c_ospeed - long t_cancc; /* stats */ +#define t_ispeed t_termios.c_ispeed +#define t_ospeed t_termios.c_ospeed + long t_cancc; /* Statistics. */ long t_rawcc; long t_outcc; - short t_gen; /* generation number */ + short t_gen; /* Generation number. */ }; -#define TTIPRI 25 /* sleep priority for tty reads */ -#define TTOPRI 26 /* sleep priority for tty writes */ +#define TTIPRI 25 /* Sleep priority for tty reads. */ +#define TTOPRI 26 /* Sleep priority for tty writes. */ #define TTMASK 15 #define OBUFSIZ 100 #define TTYHOG 1024 #ifdef KERNEL -#define TTMAXHIWAT roundup(2048, CBSIZE) -#define TTMINHIWAT roundup(100, CBSIZE) -#define TTMAXLOWAT 256 -#define TTMINLOWAT 32 -extern struct ttychars ttydefaults; +#define TTMAXHIWAT roundup(2048, CBSIZE) +#define TTMINHIWAT roundup(100, CBSIZE) +#define TTMAXLOWAT 256 +#define TTMINLOWAT 32 #endif /* KERNEL */ -/* internal state bits */ -#define TS_TIMEOUT 0x000001 /* delay timeout in progress */ -#define TS_WOPEN 0x000002 /* waiting for open to complete */ -#define TS_ISOPEN 0x000004 /* device is open */ -#define TS_FLUSH 0x000008 /* outq has been flushed during DMA */ -#define TS_CARR_ON 0x000010 /* software copy of carrier-present */ -#define TS_BUSY 0x000020 /* output in progress */ -#define TS_ASLEEP 0x000040 /* wakeup when output done */ -#define TS_XCLUDE 0x000080 /* exclusive-use flag against open */ -#define TS_TTSTOP 0x000100 /* output stopped by ctl-s */ -/* was TS_HUPCLS 0x000200 * hang up upon last close */ -#define TS_TBLOCK 0x000400 /* tandem queue blocked */ -#define TS_ASYNC 0x004000 /* tty in async i/o mode */ -/* state for intra-line fancy editing work */ -#define TS_BKSL 0x010000 /* state for lowercase \ work */ -#define TS_ERASE 0x040000 /* within a \.../ for PRTRUB */ -#define TS_LNCH 0x080000 /* next character is literal */ -#define TS_TYPEN 0x100000 /* retyping suspended input (PENDIN) */ -#define TS_CNTTB 0x200000 /* counting tab width, ignore FLUSHO */ +/* Internal state bits. */ +#define TS_TIMEOUT 0x000001 /* Delay timeout in progress. */ +#define TS_WOPEN 0x000002 /* Waiting for open to complete. */ +#define TS_ISOPEN 0x000004 /* Indicates the device is open. */ +#define TS_FLUSH 0x000008 /* Outq has been flushed during DMA. */ +#define TS_CARR_ON 0x000010 /* Software image of carrier-present. */ +#define TS_BUSY 0x000020 /* Indicates output is in progress. */ +#define TS_ASLEEP 0x000040 /* Wakeup when output done. */ +#define TS_XCLUDE 0x000080 /* Exclusive-use flag against open. */ +#define TS_TTSTOP 0x000100 /* Output stopped by ctl-s. */ +/* was TS_HUPCLS 0x000200 * Hang up upon last close. */ +#define TS_TBLOCK 0x000400 /* Tandem queue blocked. */ +#define TS_ASYNC 0x004000 /* Tty in async i/o mode. */ +/* State for intra-line fancy editing work. */ +#define TS_BKSL 0x010000 /* State for lowercase \ work. */ +#define TS_ERASE 0x040000 /* Within a \.../ for PRTRUB. */ +#define TS_LNCH 0x080000 /* Next character is literal. */ +#define TS_TYPEN 0x100000 /* Retyping suspended input (PENDIN). */ +#define TS_CNTTB 0x200000 /* Counting tab width, ignore FLUSHO. */ #define TS_LOCAL (TS_BKSL|TS_ERASE|TS_LNCH|TS_TYPEN|TS_CNTTB) -/* define partab character types */ +/* Character type information. */ #define ORDINARY 0 #define CONTROL 1 #define BACKSPACE 2 @@ -114,37 +113,74 @@ extern struct ttychars ttydefaults; #define RETURN 6 struct speedtab { - int sp_speed; - int sp_code; + int sp_speed; /* Speed. */ + int sp_code; /* Code. */ }; -/* - * Flags on character passed to ttyinput - */ -#define TTY_CHARMASK 0x000000ff /* Character mask */ -#define TTY_QUOTE 0x00000100 /* Character quoted */ -#define TTY_ERRORMASK 0xff000000 /* Error mask */ -#define TTY_FE 0x01000000 /* Framing error or BREAK condition */ -#define TTY_PE 0x02000000 /* Parity error */ -/* - * Is tp controlling terminal for p - */ -#define isctty(p, tp) ((p)->p_session == (tp)->t_session && \ - (p)->p_flag&SCTTY) -/* - * Is p in background of tp - */ -#define isbackground(p, tp) (isctty((p), (tp)) && \ - (p)->p_pgrp != (tp)->t_pgrp) -/* - * Modem control commands (driver). - */ +/* Flags on a character passed to ttyinput. */ +#define TTY_CHARMASK 0x000000ff /* Character mask */ +#define TTY_QUOTE 0x00000100 /* Character quoted */ +#define TTY_ERRORMASK 0xff000000 /* Error mask */ +#define TTY_FE 0x01000000 /* Framing error or BREAK condition */ +#define TTY_PE 0x02000000 /* Parity error */ + +/* Is tp controlling terminal for p? */ +#define isctty(p, tp) \ + ((p)->p_session == (tp)->t_session && (p)->p_flag&SCTTY) + +/* Is p in background of tp? */ +#define isbackground(p, tp) \ + (isctty((p), (tp)) && (p)->p_pgrp != (tp)->t_pgrp) + +/* Modem control commands (driver). */ #define DMSET 0 #define DMBIS 1 #define DMBIC 2 #define DMGET 3 #ifdef KERNEL -/* symbolic sleep message strings */ +extern struct ttychars ttydefaults; + +/* Symbolic sleep message strings. */ extern char ttyin[], ttyout[], ttopen[], ttclos[], ttybg[], ttybuf[]; + +int b_to_q __P((char *cp, int cc, struct clist *q)); +void catq __P((struct clist *from, struct clist *to)); +void clist_init __P((void)); +int getc __P((struct clist *q)); +void ndflush __P((struct clist *q, int cc)); +int ndqb __P((struct clist *q, int flag)); +char *nextc __P((struct clist *q, char *cp, int *c)); +int putc __P((int c, struct clist *q)); +int q_to_b __P((struct clist *q, char *cp, int cc)); +int unputc __P((struct clist *q)); + +int nullmodem __P((struct tty *tp, int flag)); +int tputchar __P((int c, struct tty *tp)); +int ttioctl __P((struct tty *tp, int com, void *data, int flag)); +int ttread __P((struct tty *tp, struct uio *uio, int flag)); +void ttrstrt __P((void *tp)); +int ttselect __P((dev_t device, int rw, struct proc *p)); +void ttsetwater __P((struct tty *tp)); +int ttspeedtab __P((int speed, struct speedtab *table)); +int ttstart __P((struct tty *tp)); +void ttwakeup __P((struct tty *tp)); +int ttwrite __P((struct tty *tp, struct uio *uio, int flag)); +void ttychars __P((struct tty *tp)); +int ttycheckoutq __P((struct tty *tp, int wait)); +int ttyclose __P((struct tty *tp)); +void ttyflush __P((struct tty *tp, int rw)); +void ttyinfo __P((struct tty *tp)); +int ttyinput __P((int c, struct tty *tp)); +int ttylclose __P((struct tty *tp, int flag)); +int ttymodem __P((struct tty *tp, int flag)); +int ttyopen __P((dev_t device, struct tty *tp)); +int ttyoutput __P((int c, struct tty *tp)); +void ttypend __P((struct tty *tp)); +void ttyretype __P((struct tty *tp)); +void ttyrub __P((int c, struct tty *tp)); +int ttysleep __P((struct tty *tp, + void *chan, int pri, char *wmesg, int timeout)); +int ttywait __P((struct tty *tp)); +int ttywflush __P((struct tty *tp)); #endif diff --git a/usr/src/sys/sys/vnode.h b/usr/src/sys/sys/vnode.h index 68434053bb..e03cee21ff 100644 --- a/usr/src/sys/sys/vnode.h +++ b/usr/src/sys/sys/vnode.h @@ -4,7 +4,7 @@ * * %sccs.include.redist.c% * - * @(#)vnode.h 8.1 (Berkeley) %G% + * @(#)vnode.h 8.2 (Berkeley) %G% */ #include @@ -181,7 +181,7 @@ void vref __P((struct vnode *)); /* * Global vnode data. */ -extern struct vnode *rootdir; /* root (i.e. "/") vnode */ +extern struct vnode *rootvnode; /* root (i.e. "/") vnode */ extern int desiredvnodes; /* number of vnodes desired */ extern struct vattr va_null; /* predefined null vattr structure */ diff --git a/usr/src/sys/ufs/ffs/ufs_bmap.c b/usr/src/sys/ufs/ffs/ufs_bmap.c index 9884532cbf..dbc6ba62cf 100644 --- a/usr/src/sys/ufs/ffs/ufs_bmap.c +++ b/usr/src/sys/ufs/ffs/ufs_bmap.c @@ -4,7 +4,7 @@ * * %sccs.include.redist.c% * - * @(#)ufs_bmap.c 8.1 (Berkeley) %G% + * @(#)ufs_bmap.c 8.2 (Berkeley) %G% */ #include @@ -94,10 +94,10 @@ ufs_bmaparray(vp, bn, bnp, ap, nump, runp) if (runp) { /* - * XXX If MAXBSIZE is the largest transfer the disks can - * handle, we probably want maxrun to be 1 block less so - * that we don't create a block larger than the device - * can handle. + * XXX + * If MAXBSIZE is the largest transfer the disks can handle, + * we probably want maxrun to be 1 block less so that we + * don't create a block larger than the device can handle. */ *runp = 0; maxrun = MAXBSIZE / mp->mnt_stat.f_iosize - 1; @@ -200,7 +200,7 @@ ufs_getlbns(vp, bn, ap, nump) { long metalbn, realbn; struct ufsmount *ump; - int j, numlevels, off, sh; + int blockcnt, i, numlevels, off; ump = VFSTOUFS(vp->v_mount); if (nump) @@ -216,26 +216,23 @@ ufs_getlbns(vp, bn, ap, nump) /* * Determine the number of levels of indirection. After this loop - * is done, sh indicates the number of data blocks possible at the - * given level of indirection, and NIADDR - j is the number of levels - * of indirection needed to locate the requested block. + * is done, blockcnt indicates the number of data blocks possible + * at the given level of indirection, and NIADDR - i is the number + * of levels of indirection needed to locate the requested block. */ - bn -= NDADDR; - sh = 1; - for (j = NIADDR; j > 0; j--) { - sh *= MNINDIR(ump); - if (bn < sh) + for (blockcnt = 1, i = NIADDR, bn -= NDADDR;; i--, bn -= blockcnt) { + if (i == 0) + return (EFBIG); + blockcnt *= MNINDIR(ump); + if (bn < blockcnt) break; - bn -= sh; } - if (j == 0) - return (EFBIG); /* Calculate the address of the first meta-block. */ if (realbn >= 0) - metalbn = -(realbn - bn + NIADDR - j); + metalbn = -(realbn - bn + NIADDR - i); else - metalbn = -(-realbn - bn + NIADDR - j); + metalbn = -(-realbn - bn + NIADDR - i); /* * At each iteration, off is the offset into the bap array which is @@ -243,18 +240,17 @@ ufs_getlbns(vp, bn, ap, nump) * The logical block number and the offset in that block are stored * into the argument array. */ - ++numlevels; ap->in_lbn = metalbn; - ap->in_off = off = NIADDR - j; + ap->in_off = off = NIADDR - i; ap->in_exists = 0; ap++; - for (; j <= NIADDR; j++) { + for (++numlevels; i <= NIADDR; i++) { /* If searching for a meta-data block, quit when found. */ if (metalbn == realbn) break; - sh /= MNINDIR(ump); - off = (bn / sh) % MNINDIR(ump); + blockcnt /= MNINDIR(ump); + off = (bn / blockcnt) % MNINDIR(ump); ++numlevels; ap->in_lbn = metalbn; @@ -262,7 +258,7 @@ ufs_getlbns(vp, bn, ap, nump) ap->in_exists = 0; ++ap; - metalbn -= -1 + off * sh; + metalbn -= -1 + off * blockcnt; } if (nump) *nump = numlevels; diff --git a/usr/src/sys/ufs/ffs/ufs_disksubr.c b/usr/src/sys/ufs/ffs/ufs_disksubr.c index 7793dff582..e63e109386 100644 --- a/usr/src/sys/ufs/ffs/ufs_disksubr.c +++ b/usr/src/sys/ufs/ffs/ufs_disksubr.c @@ -4,7 +4,7 @@ * * %sccs.include.redist.c% * - * @(#)ufs_disksubr.c 8.1 (Berkeley) %G% + * @(#)ufs_disksubr.c 8.2 (Berkeley) %G% */ #include @@ -29,54 +29,58 @@ * allocated. */ -#define b_cylin b_resid +/* + * For portability with historic industry practice, the + * cylinder number has to be maintained in the `b_resid' + * field. + */ +#define b_cylinder b_resid void disksort(dp, bp) register struct buf *dp, *bp; { - register struct buf *ap; + register struct buf *bq; - /* - * If nothing on the activity queue, then - * we become the only thing. - */ - ap = dp->b_actf; - if(ap == NULL) { - dp->b_actf = bp; + /* If the queue is empty, then it's easy. */ + if (dp->b_actf == NULL) { bp->b_actf = NULL; + dp->b_actf = bp; return; } + /* - * If we lie after the first (currently active) - * request, then we must locate the second request list - * and add ourselves to it. + * If we lie after the first (currently active) request, then we + * must locate the second request list and add ourselves to it. */ - if (bp->b_cylin < ap->b_cylin) { - while (ap->b_actf) { + bq = dp->b_actf; + if (bp->b_cylinder < bq->b_cylinder) { + while (bq->b_actf) { /* - * Check for an ``inversion'' in the - * normally ascending cylinder numbers, - * indicating the start of the second request list. + * Check for an ``inversion'' in the normally ascending + * cylinder numbers, indicating the start of the second + * request list. */ - if (ap->b_actf->b_cylin < ap->b_cylin) { + if (bq->b_actf->b_cylinder < bq->b_cylinder) { /* - * Search the second request list - * for the first request at a larger - * cylinder number. We go before that; - * if there is no such request, we go at end. + * Search the second request list for the first + * request at a larger cylinder number. We go + * before that; if there is no such request, we + * go at end. */ do { - if (bp->b_cylin < ap->b_actf->b_cylin) + if (bp->b_cylinder < + bq->b_actf->b_cylinder) goto insert; - if (bp->b_cylin == ap->b_actf->b_cylin && - bp->b_blkno < ap->b_actf->b_blkno) + if (bp->b_cylinder == + bq->b_actf->b_cylinder && + bp->b_blkno < bq->b_actf->b_blkno) goto insert; - ap = ap->b_actf; - } while (ap->b_actf); + bq = bq->b_actf; + } while (bq->b_actf); goto insert; /* after last */ } - ap = ap->b_actf; + bq = bq->b_actf; } /* * No inversions... we will go after the last, and @@ -88,28 +92,26 @@ disksort(dp, bp) * Request is at/after the current request... * sort in the first request list. */ - while (ap->b_actf) { + while (bq->b_actf) { /* - * We want to go after the current request - * if there is an inversion after it (i.e. it is - * the end of the first request list), or if - * the next request is a larger cylinder than our request. + * We want to go after the current request if there is an + * inversion after it (i.e. it is the end of the first + * request list), or if the next request is a larger cylinder + * than our request. */ - if (ap->b_actf->b_cylin < ap->b_cylin || - bp->b_cylin < ap->b_actf->b_cylin || - (bp->b_cylin == ap->b_actf->b_cylin && - bp->b_blkno < ap->b_actf->b_blkno)) + if (bq->b_actf->b_cylinder < bq->b_cylinder || + bp->b_cylinder < bq->b_actf->b_cylinder || + (bp->b_cylinder == bq->b_actf->b_cylinder && + bp->b_blkno < bq->b_actf->b_blkno)) goto insert; - ap = ap->b_actf; + bq = bq->b_actf; } /* - * Neither a second list nor a larger - * request... we go at the end of the first list, - * which is the same as the end of the whole schebang. + * Neither a second list nor a larger request... we go at the end of + * the first list, which is the same as the end of the whole schebang. */ -insert: - bp->b_actf = ap->b_actf; - ap->b_actf = bp; +insert: bp->b_actf = bq->b_actf; + bq->b_actf = bp; } /* @@ -141,11 +143,11 @@ readdisklabel(dev, strat, lp) bp->b_blkno = LABELSECTOR; bp->b_bcount = lp->d_secsize; bp->b_flags = B_BUSY | B_READ; - bp->b_cylin = LABELSECTOR / lp->d_secpercyl; + bp->b_cylinder = LABELSECTOR / lp->d_secpercyl; (*strat)(bp); - if (biowait(bp)) { + if (biowait(bp)) msg = "I/O error"; - } else for (dlp = (struct disklabel *)bp->b_un.b_addr; + else for (dlp = (struct disklabel *)bp->b_un.b_addr; dlp <= (struct disklabel *)(bp->b_un.b_addr+DEV_BSIZE-sizeof(*dlp)); dlp = (struct disklabel *)((char *)dlp + sizeof(long))) { if (dlp->d_magic != DISKMAGIC || dlp->d_magic2 != DISKMAGIC) { diff --git a/usr/src/sys/ufs/ffs/ufs_ihash.c b/usr/src/sys/ufs/ffs/ufs_ihash.c index 6865fbe90b..865f5e11dc 100644 --- a/usr/src/sys/ufs/ffs/ufs_ihash.c +++ b/usr/src/sys/ufs/ffs/ufs_ihash.c @@ -4,7 +4,7 @@ * * %sccs.include.redist.c% * - * @(#)ufs_ihash.c 8.1 (Berkeley) %G% + * @(#)ufs_ihash.c 8.2 (Berkeley) %G% */ #include @@ -22,7 +22,7 @@ */ struct inode **ihashtbl; u_long ihash; /* size of hash table - 1 */ -#define INOHASH(dev, ino) (((dev) + (ino)) & ihash) +#define INOHASH(device, inum) (((device) + (inum)) & ihash) /* * Initialize inode hash table. @@ -35,53 +35,48 @@ ufs_ihashinit() } /* - * Use the dev/ino pair to find the incore inode, and return a pointer to it. - * If it is in core, return it, even if it is locked. + * Use the device/inum pair to find the incore inode, and return a pointer + * to it. If it is in core, return it, even if it is locked. */ struct vnode * -ufs_ihashlookup(dev, ino) - dev_t dev; - ino_t ino; +ufs_ihashlookup(device, inum) + dev_t device; + ino_t inum; { register struct inode **ipp, *ip; - ipp = &ihashtbl[INOHASH(dev, ino)]; -loop: - for (ip = *ipp; ip; ip = ip->i_next) { - if (ino != ip->i_number || dev != ip->i_dev) - continue; - return (ITOV(ip)); - } + ipp = &ihashtbl[INOHASH(device, inum)]; + for (ip = *ipp; ip; ip = ip->i_next) + if (inum == ip->i_number && device == ip->i_dev) + return (ITOV(ip)); return (NULL); } /* - * Use the dev/ino pair to find the incore inode, and return a pointer to it. - * If it is in core, but locked, wait for it. + * Use the device/inum pair to find the incore inode, and return a pointer + * to it. If it is in core, but locked, wait for it. */ struct vnode * -ufs_ihashget(dev, ino) - dev_t dev; - ino_t ino; +ufs_ihashget(device, inum) + dev_t device; + ino_t inum; { register struct inode **ipp, *ip; struct vnode *vp; - ipp = &ihashtbl[INOHASH(dev, ino)]; -loop: - for (ip = *ipp; ip; ip = ip->i_next) { - if (ino != ip->i_number || dev != ip->i_dev) - continue; - if ((ip->i_flag & ILOCKED) != 0) { - ip->i_flag |= IWANT; - sleep((caddr_t)ip, PINOD); - goto loop; + ipp = &ihashtbl[INOHASH(device, inum)]; +retry: for (ip = *ipp; ip != NULL; ip = ip->i_next) + if (inum == ip->i_number && device == ip->i_dev) { + if (ip->i_flag & ILOCKED) { + ip->i_flag |= IWANT; + sleep(ip, PINOD); + goto retry; + } + vp = ITOV(ip); + if (vget(vp)) + goto retry; + return (vp); } - vp = ITOV(ip); - if (vget(vp)) - goto loop; - return (vp); - } return (NULL); } diff --git a/usr/src/sys/ufs/ffs/ufs_vnops.c b/usr/src/sys/ufs/ffs/ufs_vnops.c index 2f303cb6e2..dded9e9eb3 100644 --- a/usr/src/sys/ufs/ffs/ufs_vnops.c +++ b/usr/src/sys/ufs/ffs/ufs_vnops.c @@ -4,7 +4,7 @@ * * %sccs.include.redist.c% * - * @(#)ufs_vnops.c 8.1 (Berkeley) %G% + * @(#)ufs_vnops.c 8.2 (Berkeley) %G% */ #include @@ -375,15 +375,15 @@ ufs_chmod(vp, mode, cred, p) (error = suser(cred, &p->p_acflag))) return (error); if (cred->cr_uid) { - if (vp->v_type != VDIR && (mode & ISVTX)) + if (vp->v_type != VDIR && (mode & S_ISTXT)) return (EFTYPE); if (!groupmember(ip->i_gid, cred) && (mode & ISGID)) return (EPERM); } - ip->i_mode &= ~07777; - ip->i_mode |= mode & 07777; + ip->i_mode &= ~ALLPERMS; + ip->i_mode |= mode & ALLPERMS; ip->i_flag |= ICHG; - if ((vp->v_flag & VTEXT) && (ip->i_mode & ISVTX) == 0) + if ((vp->v_flag & VTEXT) && (ip->i_mode & S_ISTXT) == 0) (void) vnode_pager_uncache(vp); return (0); } @@ -567,11 +567,6 @@ ufs_seek(ap) return (0); } -/* - * ufs remove - * Hard to avoid races here, especially - * in unlinking directories. - */ int ufs_remove(ap) struct vop_remove_args /* { @@ -1049,7 +1044,7 @@ abortit: * otherwise the destination may not be changed (except by * root). This implements append-only directories. */ - if ((dp->i_mode & ISVTX) && tcnp->cn_cred->cr_uid != 0 && + if ((dp->i_mode & S_ISTXT) && tcnp->cn_cred->cr_uid != 0 && tcnp->cn_cred->cr_uid != dp->i_uid && xp->i_uid != tcnp->cn_cred->cr_uid) { error = EPERM; diff --git a/usr/src/sys/ufs/ufs/ufs_bmap.c b/usr/src/sys/ufs/ufs/ufs_bmap.c index 9884532cbf..dbc6ba62cf 100644 --- a/usr/src/sys/ufs/ufs/ufs_bmap.c +++ b/usr/src/sys/ufs/ufs/ufs_bmap.c @@ -4,7 +4,7 @@ * * %sccs.include.redist.c% * - * @(#)ufs_bmap.c 8.1 (Berkeley) %G% + * @(#)ufs_bmap.c 8.2 (Berkeley) %G% */ #include @@ -94,10 +94,10 @@ ufs_bmaparray(vp, bn, bnp, ap, nump, runp) if (runp) { /* - * XXX If MAXBSIZE is the largest transfer the disks can - * handle, we probably want maxrun to be 1 block less so - * that we don't create a block larger than the device - * can handle. + * XXX + * If MAXBSIZE is the largest transfer the disks can handle, + * we probably want maxrun to be 1 block less so that we + * don't create a block larger than the device can handle. */ *runp = 0; maxrun = MAXBSIZE / mp->mnt_stat.f_iosize - 1; @@ -200,7 +200,7 @@ ufs_getlbns(vp, bn, ap, nump) { long metalbn, realbn; struct ufsmount *ump; - int j, numlevels, off, sh; + int blockcnt, i, numlevels, off; ump = VFSTOUFS(vp->v_mount); if (nump) @@ -216,26 +216,23 @@ ufs_getlbns(vp, bn, ap, nump) /* * Determine the number of levels of indirection. After this loop - * is done, sh indicates the number of data blocks possible at the - * given level of indirection, and NIADDR - j is the number of levels - * of indirection needed to locate the requested block. + * is done, blockcnt indicates the number of data blocks possible + * at the given level of indirection, and NIADDR - i is the number + * of levels of indirection needed to locate the requested block. */ - bn -= NDADDR; - sh = 1; - for (j = NIADDR; j > 0; j--) { - sh *= MNINDIR(ump); - if (bn < sh) + for (blockcnt = 1, i = NIADDR, bn -= NDADDR;; i--, bn -= blockcnt) { + if (i == 0) + return (EFBIG); + blockcnt *= MNINDIR(ump); + if (bn < blockcnt) break; - bn -= sh; } - if (j == 0) - return (EFBIG); /* Calculate the address of the first meta-block. */ if (realbn >= 0) - metalbn = -(realbn - bn + NIADDR - j); + metalbn = -(realbn - bn + NIADDR - i); else - metalbn = -(-realbn - bn + NIADDR - j); + metalbn = -(-realbn - bn + NIADDR - i); /* * At each iteration, off is the offset into the bap array which is @@ -243,18 +240,17 @@ ufs_getlbns(vp, bn, ap, nump) * The logical block number and the offset in that block are stored * into the argument array. */ - ++numlevels; ap->in_lbn = metalbn; - ap->in_off = off = NIADDR - j; + ap->in_off = off = NIADDR - i; ap->in_exists = 0; ap++; - for (; j <= NIADDR; j++) { + for (++numlevels; i <= NIADDR; i++) { /* If searching for a meta-data block, quit when found. */ if (metalbn == realbn) break; - sh /= MNINDIR(ump); - off = (bn / sh) % MNINDIR(ump); + blockcnt /= MNINDIR(ump); + off = (bn / blockcnt) % MNINDIR(ump); ++numlevels; ap->in_lbn = metalbn; @@ -262,7 +258,7 @@ ufs_getlbns(vp, bn, ap, nump) ap->in_exists = 0; ++ap; - metalbn -= -1 + off * sh; + metalbn -= -1 + off * blockcnt; } if (nump) *nump = numlevels; diff --git a/usr/src/sys/ufs/ufs/ufs_disksubr.c b/usr/src/sys/ufs/ufs/ufs_disksubr.c index 7793dff582..e63e109386 100644 --- a/usr/src/sys/ufs/ufs/ufs_disksubr.c +++ b/usr/src/sys/ufs/ufs/ufs_disksubr.c @@ -4,7 +4,7 @@ * * %sccs.include.redist.c% * - * @(#)ufs_disksubr.c 8.1 (Berkeley) %G% + * @(#)ufs_disksubr.c 8.2 (Berkeley) %G% */ #include @@ -29,54 +29,58 @@ * allocated. */ -#define b_cylin b_resid +/* + * For portability with historic industry practice, the + * cylinder number has to be maintained in the `b_resid' + * field. + */ +#define b_cylinder b_resid void disksort(dp, bp) register struct buf *dp, *bp; { - register struct buf *ap; + register struct buf *bq; - /* - * If nothing on the activity queue, then - * we become the only thing. - */ - ap = dp->b_actf; - if(ap == NULL) { - dp->b_actf = bp; + /* If the queue is empty, then it's easy. */ + if (dp->b_actf == NULL) { bp->b_actf = NULL; + dp->b_actf = bp; return; } + /* - * If we lie after the first (currently active) - * request, then we must locate the second request list - * and add ourselves to it. + * If we lie after the first (currently active) request, then we + * must locate the second request list and add ourselves to it. */ - if (bp->b_cylin < ap->b_cylin) { - while (ap->b_actf) { + bq = dp->b_actf; + if (bp->b_cylinder < bq->b_cylinder) { + while (bq->b_actf) { /* - * Check for an ``inversion'' in the - * normally ascending cylinder numbers, - * indicating the start of the second request list. + * Check for an ``inversion'' in the normally ascending + * cylinder numbers, indicating the start of the second + * request list. */ - if (ap->b_actf->b_cylin < ap->b_cylin) { + if (bq->b_actf->b_cylinder < bq->b_cylinder) { /* - * Search the second request list - * for the first request at a larger - * cylinder number. We go before that; - * if there is no such request, we go at end. + * Search the second request list for the first + * request at a larger cylinder number. We go + * before that; if there is no such request, we + * go at end. */ do { - if (bp->b_cylin < ap->b_actf->b_cylin) + if (bp->b_cylinder < + bq->b_actf->b_cylinder) goto insert; - if (bp->b_cylin == ap->b_actf->b_cylin && - bp->b_blkno < ap->b_actf->b_blkno) + if (bp->b_cylinder == + bq->b_actf->b_cylinder && + bp->b_blkno < bq->b_actf->b_blkno) goto insert; - ap = ap->b_actf; - } while (ap->b_actf); + bq = bq->b_actf; + } while (bq->b_actf); goto insert; /* after last */ } - ap = ap->b_actf; + bq = bq->b_actf; } /* * No inversions... we will go after the last, and @@ -88,28 +92,26 @@ disksort(dp, bp) * Request is at/after the current request... * sort in the first request list. */ - while (ap->b_actf) { + while (bq->b_actf) { /* - * We want to go after the current request - * if there is an inversion after it (i.e. it is - * the end of the first request list), or if - * the next request is a larger cylinder than our request. + * We want to go after the current request if there is an + * inversion after it (i.e. it is the end of the first + * request list), or if the next request is a larger cylinder + * than our request. */ - if (ap->b_actf->b_cylin < ap->b_cylin || - bp->b_cylin < ap->b_actf->b_cylin || - (bp->b_cylin == ap->b_actf->b_cylin && - bp->b_blkno < ap->b_actf->b_blkno)) + if (bq->b_actf->b_cylinder < bq->b_cylinder || + bp->b_cylinder < bq->b_actf->b_cylinder || + (bp->b_cylinder == bq->b_actf->b_cylinder && + bp->b_blkno < bq->b_actf->b_blkno)) goto insert; - ap = ap->b_actf; + bq = bq->b_actf; } /* - * Neither a second list nor a larger - * request... we go at the end of the first list, - * which is the same as the end of the whole schebang. + * Neither a second list nor a larger request... we go at the end of + * the first list, which is the same as the end of the whole schebang. */ -insert: - bp->b_actf = ap->b_actf; - ap->b_actf = bp; +insert: bp->b_actf = bq->b_actf; + bq->b_actf = bp; } /* @@ -141,11 +143,11 @@ readdisklabel(dev, strat, lp) bp->b_blkno = LABELSECTOR; bp->b_bcount = lp->d_secsize; bp->b_flags = B_BUSY | B_READ; - bp->b_cylin = LABELSECTOR / lp->d_secpercyl; + bp->b_cylinder = LABELSECTOR / lp->d_secpercyl; (*strat)(bp); - if (biowait(bp)) { + if (biowait(bp)) msg = "I/O error"; - } else for (dlp = (struct disklabel *)bp->b_un.b_addr; + else for (dlp = (struct disklabel *)bp->b_un.b_addr; dlp <= (struct disklabel *)(bp->b_un.b_addr+DEV_BSIZE-sizeof(*dlp)); dlp = (struct disklabel *)((char *)dlp + sizeof(long))) { if (dlp->d_magic != DISKMAGIC || dlp->d_magic2 != DISKMAGIC) { diff --git a/usr/src/sys/ufs/ufs/ufs_ihash.c b/usr/src/sys/ufs/ufs/ufs_ihash.c index 6865fbe90b..865f5e11dc 100644 --- a/usr/src/sys/ufs/ufs/ufs_ihash.c +++ b/usr/src/sys/ufs/ufs/ufs_ihash.c @@ -4,7 +4,7 @@ * * %sccs.include.redist.c% * - * @(#)ufs_ihash.c 8.1 (Berkeley) %G% + * @(#)ufs_ihash.c 8.2 (Berkeley) %G% */ #include @@ -22,7 +22,7 @@ */ struct inode **ihashtbl; u_long ihash; /* size of hash table - 1 */ -#define INOHASH(dev, ino) (((dev) + (ino)) & ihash) +#define INOHASH(device, inum) (((device) + (inum)) & ihash) /* * Initialize inode hash table. @@ -35,53 +35,48 @@ ufs_ihashinit() } /* - * Use the dev/ino pair to find the incore inode, and return a pointer to it. - * If it is in core, return it, even if it is locked. + * Use the device/inum pair to find the incore inode, and return a pointer + * to it. If it is in core, return it, even if it is locked. */ struct vnode * -ufs_ihashlookup(dev, ino) - dev_t dev; - ino_t ino; +ufs_ihashlookup(device, inum) + dev_t device; + ino_t inum; { register struct inode **ipp, *ip; - ipp = &ihashtbl[INOHASH(dev, ino)]; -loop: - for (ip = *ipp; ip; ip = ip->i_next) { - if (ino != ip->i_number || dev != ip->i_dev) - continue; - return (ITOV(ip)); - } + ipp = &ihashtbl[INOHASH(device, inum)]; + for (ip = *ipp; ip; ip = ip->i_next) + if (inum == ip->i_number && device == ip->i_dev) + return (ITOV(ip)); return (NULL); } /* - * Use the dev/ino pair to find the incore inode, and return a pointer to it. - * If it is in core, but locked, wait for it. + * Use the device/inum pair to find the incore inode, and return a pointer + * to it. If it is in core, but locked, wait for it. */ struct vnode * -ufs_ihashget(dev, ino) - dev_t dev; - ino_t ino; +ufs_ihashget(device, inum) + dev_t device; + ino_t inum; { register struct inode **ipp, *ip; struct vnode *vp; - ipp = &ihashtbl[INOHASH(dev, ino)]; -loop: - for (ip = *ipp; ip; ip = ip->i_next) { - if (ino != ip->i_number || dev != ip->i_dev) - continue; - if ((ip->i_flag & ILOCKED) != 0) { - ip->i_flag |= IWANT; - sleep((caddr_t)ip, PINOD); - goto loop; + ipp = &ihashtbl[INOHASH(device, inum)]; +retry: for (ip = *ipp; ip != NULL; ip = ip->i_next) + if (inum == ip->i_number && device == ip->i_dev) { + if (ip->i_flag & ILOCKED) { + ip->i_flag |= IWANT; + sleep(ip, PINOD); + goto retry; + } + vp = ITOV(ip); + if (vget(vp)) + goto retry; + return (vp); } - vp = ITOV(ip); - if (vget(vp)) - goto loop; - return (vp); - } return (NULL); } diff --git a/usr/src/sys/ufs/ufs/ufs_vnops.c b/usr/src/sys/ufs/ufs/ufs_vnops.c index 2f303cb6e2..dded9e9eb3 100644 --- a/usr/src/sys/ufs/ufs/ufs_vnops.c +++ b/usr/src/sys/ufs/ufs/ufs_vnops.c @@ -4,7 +4,7 @@ * * %sccs.include.redist.c% * - * @(#)ufs_vnops.c 8.1 (Berkeley) %G% + * @(#)ufs_vnops.c 8.2 (Berkeley) %G% */ #include @@ -375,15 +375,15 @@ ufs_chmod(vp, mode, cred, p) (error = suser(cred, &p->p_acflag))) return (error); if (cred->cr_uid) { - if (vp->v_type != VDIR && (mode & ISVTX)) + if (vp->v_type != VDIR && (mode & S_ISTXT)) return (EFTYPE); if (!groupmember(ip->i_gid, cred) && (mode & ISGID)) return (EPERM); } - ip->i_mode &= ~07777; - ip->i_mode |= mode & 07777; + ip->i_mode &= ~ALLPERMS; + ip->i_mode |= mode & ALLPERMS; ip->i_flag |= ICHG; - if ((vp->v_flag & VTEXT) && (ip->i_mode & ISVTX) == 0) + if ((vp->v_flag & VTEXT) && (ip->i_mode & S_ISTXT) == 0) (void) vnode_pager_uncache(vp); return (0); } @@ -567,11 +567,6 @@ ufs_seek(ap) return (0); } -/* - * ufs remove - * Hard to avoid races here, especially - * in unlinking directories. - */ int ufs_remove(ap) struct vop_remove_args /* { @@ -1049,7 +1044,7 @@ abortit: * otherwise the destination may not be changed (except by * root). This implements append-only directories. */ - if ((dp->i_mode & ISVTX) && tcnp->cn_cred->cr_uid != 0 && + if ((dp->i_mode & S_ISTXT) && tcnp->cn_cred->cr_uid != 0 && tcnp->cn_cred->cr_uid != dp->i_uid && xp->i_uid != tcnp->cn_cred->cr_uid) { error = EPERM; diff --git a/usr/src/sys/vm/vm_glue.c b/usr/src/sys/vm/vm_glue.c index e12f80d9c8..9afd00b2d0 100644 --- a/usr/src/sys/vm/vm_glue.c +++ b/usr/src/sys/vm/vm_glue.c @@ -7,7 +7,7 @@ * * %sccs.include.redist.c% * - * @(#)vm_glue.c 8.1 (Berkeley) %G% + * @(#)vm_glue.c 8.2 (Berkeley) %G% * * * Copyright (c) 1987, 1990 Carnegie-Mellon University. @@ -278,7 +278,7 @@ int swapdebug = 0; * clear some space. */ void -sched() +scheduler() { register struct proc *p; register int pri; -- 2.20.1