diff options
author | phk <phk@FreeBSD.org> | 2004-06-17 17:16:53 +0000 |
---|---|---|
committer | phk <phk@FreeBSD.org> | 2004-06-17 17:16:53 +0000 |
commit | 40dd98a3bd2049465e7644b361b60da41a46efa0 (patch) | |
tree | fe8b297144afd6d6f7db41275c72cb5eb663ec02 /sys/kern | |
parent | 9acfe1e733142ca875624a3acbf96c4ff27b36a4 (diff) | |
download | FreeBSD-src-40dd98a3bd2049465e7644b361b60da41a46efa0.zip FreeBSD-src-40dd98a3bd2049465e7644b361b60da41a46efa0.tar.gz |
Second half of the dev_t cleanup.
The big lines are:
NODEV -> NULL
NOUDEV -> NODEV
udev_t -> dev_t
udev2dev() -> findcdev()
Various minor adjustments including handling of userland access to kernel
space struct cdev etc.
Diffstat (limited to 'sys/kern')
-rw-r--r-- | sys/kern/kern_acct.c | 2 | ||||
-rw-r--r-- | sys/kern/kern_conf.c | 62 | ||||
-rw-r--r-- | sys/kern/kern_proc.c | 4 | ||||
-rw-r--r-- | sys/kern/kern_shutdown.c | 2 | ||||
-rw-r--r-- | sys/kern/tty_cons.c | 6 | ||||
-rw-r--r-- | sys/kern/tty_pty.c | 4 | ||||
-rw-r--r-- | sys/kern/tty_tty.c | 2 | ||||
-rw-r--r-- | sys/kern/uipc_usrreq.c | 2 | ||||
-rw-r--r-- | sys/kern/vfs_bio.c | 8 | ||||
-rw-r--r-- | sys/kern/vfs_mount.c | 12 | ||||
-rw-r--r-- | sys/kern/vfs_subr.c | 16 |
11 files changed, 57 insertions, 63 deletions
diff --git a/sys/kern/kern_acct.c b/sys/kern/kern_acct.c index 63d7891..5dca0f6 100644 --- a/sys/kern/kern_acct.c +++ b/sys/kern/kern_acct.c @@ -285,7 +285,7 @@ acct_process(td) if ((p->p_flag & P_CONTROLT) && p->p_pgrp->pg_session->s_ttyp) acct.ac_tty = dev2udev(p->p_pgrp->pg_session->s_ttyp->t_dev); else - acct.ac_tty = NOUDEV; + acct.ac_tty = NODEV; SESS_UNLOCK(p->p_session); /* (8) The boolean flags that tell how the process terminated, etc. */ diff --git a/sys/kern/kern_conf.c b/sys/kern/kern_conf.c index 216a777..b417b73 100644 --- a/sys/kern/kern_conf.c +++ b/sys/kern/kern_conf.c @@ -51,7 +51,7 @@ extern unsigned char reserved_majors[256]; /* * This is the number of hash-buckets. Experiements with 'real-life' - * udev_t's show that a prime halfway between two powers of two works + * dev_t's show that a prime halfway between two powers of two works * best. */ #define DEVT_HASH 83 @@ -70,6 +70,8 @@ SYSCTL_INT(_debug, OID_AUTO, free_devt, CTLFLAG_RW, &free_devt, 0, ""); static struct mtx devmtx; static void freedev(struct cdev *dev); +static struct cdev *newdev(int x, int y); + static void devlock(void) @@ -125,8 +127,6 @@ cdevsw_rel(struct cdevsw *csw) devunlock(); } -static struct cdev *makedev(int x, int y); - int nullop(void) { @@ -247,16 +247,16 @@ devsw(struct cdev *dev) int major(struct cdev *x) { - if (x == NODEV) - return NOUDEV; + if (x == NULL) + return NODEV; return((x->si_udev >> 8) & 0xff); } int minor(struct cdev *x) { - if (x == NODEV) - return NOUDEV; + if (x == NULL) + return NODEV; return(x->si_udev & 0xffff00ff); } @@ -265,8 +265,8 @@ dev2unit(struct cdev *x) { int i; - if (x == NODEV) - return NOUDEV; + if (x == NULL) + return NODEV; i = minor(x); return ((i & 0xff) | (i >> 8)); } @@ -304,14 +304,14 @@ allocdev(void) } static struct cdev * -makedev(int x, int y) +newdev(int x, int y) { struct cdev *si; - udev_t udev; + dev_t udev; int hash; - if (x == umajor(NOUDEV) && y == uminor(NOUDEV)) - panic("makedev of NOUDEV"); + if (x == umajor(NODEV) && y == uminor(NODEV)) + panic("newdev of NODEV"); udev = (x << 8) | y; hash = udev % DEVT_HASH; LIST_FOREACH(si, &dev_hash[hash], si_hash) { @@ -337,48 +337,42 @@ freedev(struct cdev *dev) } } -udev_t +dev_t dev2udev(struct cdev *x) { - if (x == NODEV) - return (NOUDEV); + if (x == NULL) + return (NODEV); return (x->si_udev); } struct cdev * -udev2dev(udev_t udev) +findcdev(dev_t udev) { struct cdev *si; int hash; - if (udev == NOUDEV) - return (NODEV); + if (udev == NODEV) + return (NULL); hash = udev % DEVT_HASH; LIST_FOREACH(si, &dev_hash[hash], si_hash) { if (si->si_udev == udev) return (si); } - return (NODEV); + return (NULL); } int -uminor(udev_t dev) +uminor(dev_t dev) { return (dev & 0xffff00ff); } int -umajor(udev_t dev) +umajor(dev_t dev) { return ((dev & 0xff00) >> 8); } -udev_t -makeudev(int x, int y) -{ - return ((x << 8) | y); -} - static void find_major(struct cdevsw *devsw) { @@ -479,7 +473,7 @@ make_dev(struct cdevsw *devsw, int minornr, uid_t uid, gid_t gid, int perms, con if (!(devsw->d_flags & D_INIT)) prep_cdevsw(devsw); - dev = makedev(devsw->d_maj, minornr); + dev = newdev(devsw->d_maj, minornr); if (dev->si_flags & SI_CHEAPCLONE && dev->si_flags & SI_NAMED && dev->si_devsw == devsw) { @@ -750,7 +744,7 @@ clone_create(struct clonedevs **cdp, struct cdevsw *csw, int *up, struct cdev ** } if (unit == -1) unit = low & CLONE_UNITMASK; - dev = makedev(csw->d_maj, unit2minor(unit | extra)); + dev = newdev(csw->d_maj, unit2minor(unit | extra)); KASSERT(!(dev->si_flags & SI_CLONELIST), ("Dev %p should not be on clonelist", dev)); if (dl != NULL) @@ -794,16 +788,16 @@ static int sysctl_devname(SYSCTL_HANDLER_ARGS) { int error; - udev_t ud; + dev_t ud; struct cdev *dev; error = SYSCTL_IN(req, &ud, sizeof (ud)); if (error) return (error); - if (ud == NOUDEV) + if (ud == NODEV) return(EINVAL); - dev = udev2dev(ud); - if (dev == NODEV) + dev = findcdev(ud); + if (dev == NULL) error = ENOENT; else error = SYSCTL_OUT(req, dev->si_name, strlen(dev->si_name) + 1); diff --git a/sys/kern/kern_proc.c b/sys/kern/kern_proc.c index daf51b0..c757124 100644 --- a/sys/kern/kern_proc.c +++ b/sys/kern/kern_proc.c @@ -800,7 +800,7 @@ fill_kinfo_thread(struct thread *td, struct kinfo_proc *kp) if (tp->t_session) kp->ki_tsid = tp->t_session->s_sid; } else - kp->ki_tdev = NOUDEV; + kp->ki_tdev = NODEV; if (p->p_comm[0] != '\0') { strlcpy(kp->ki_comm, p->p_comm, sizeof(kp->ki_comm)); strlcpy(kp->ki_ocomm, p->p_comm, sizeof(kp->ki_ocomm)); @@ -1012,7 +1012,7 @@ sysctl_kern_proc(SYSCTL_HANDLER_ARGS) SESS_LOCK(p->p_session); if (p->p_session->s_ttyp == NULL || dev2udev(p->p_session->s_ttyp->t_dev) != - (udev_t)name[0]) { + (dev_t)name[0]) { SESS_UNLOCK(p->p_session); PROC_UNLOCK(p); continue; diff --git a/sys/kern/kern_shutdown.c b/sys/kern/kern_shutdown.c index 49c6a41..491bc9e 100644 --- a/sys/kern/kern_shutdown.c +++ b/sys/kern/kern_shutdown.c @@ -324,7 +324,7 @@ boot(int howto) for (bp = &buf[nbuf]; --bp >= buf; ) { if (((bp->b_flags&B_INVAL) == 0 && BUF_REFCNT(bp)) || ((bp->b_flags & (B_DELWRI|B_INVAL)) == B_DELWRI)) { - if (bp->b_dev == NODEV) { + if (bp->b_dev == NULL) { TAILQ_REMOVE(&mountlist, bp->b_vp->v_mount, mnt_list); continue; diff --git a/sys/kern/tty_cons.c b/sys/kern/tty_cons.c index a9bea7c..e44ea5f 100644 --- a/sys/kern/tty_cons.c +++ b/sys/kern/tty_cons.c @@ -103,7 +103,7 @@ static STAILQ_HEAD(, cn_device) cn_devlist = (cnd == NULL || cnd->cnd_vp == NULL || \ (cnd->cnd_vp->v_type == VBAD && !cn_devopen(cnd, td, 1))) -static udev_t cn_udev_t; +static dev_t cn_udev_t; SYSCTL_OPAQUE(_machdep, CPU_CONSDEV, consdev, CTLFLAG_RD, &cn_udev_t, sizeof cn_udev_t, "T,struct cdev *", ""); @@ -371,9 +371,9 @@ sysctl_kern_consmute(SYSCTL_HANDLER_ARGS) if (error != 0 || req->newptr == NULL) return (error); if (ocn_mute && !cn_mute && cn_is_open) - error = cnopen(NODEV, openflag, 0, curthread); + error = cnopen(NULL, openflag, 0, curthread); else if (!ocn_mute && cn_mute && cn_is_open) { - error = cnclose(NODEV, openflag, 0, curthread); + error = cnclose(NULL, openflag, 0, curthread); cn_is_open = 1; /* XXX hack */ } return (error); diff --git a/sys/kern/tty_pty.c b/sys/kern/tty_pty.c index b4082a3..1e5d202 100644 --- a/sys/kern/tty_pty.c +++ b/sys/kern/tty_pty.c @@ -143,7 +143,7 @@ ptyinit(struct cdev *devc) n = minor(devc); /* For now we only map the lower 8 bits of the minor */ if (n & ~0xff) - return (NODEV); + return (NULL); devc->si_flags &= ~SI_CHEAPCLONE; @@ -777,7 +777,7 @@ pty_clone(void *arg, char *name, int namelen, struct cdev **dev) { int u; - if (*dev != NODEV) + if (*dev != NULL) return; if (bcmp(name, "pty", 3) != 0) return; diff --git a/sys/kern/tty_tty.c b/sys/kern/tty_tty.c index 85b0eac..e467dd3 100644 --- a/sys/kern/tty_tty.c +++ b/sys/kern/tty_tty.c @@ -58,7 +58,7 @@ static void ctty_clone(void *arg, char *name, int namelen, struct cdev **dev) { - if (*dev != NODEV) + if (*dev != NULL) return; if (strcmp(name, "tty")) return; diff --git a/sys/kern/uipc_usrreq.c b/sys/kern/uipc_usrreq.c index 18a4274..16d80b4 100644 --- a/sys/kern/uipc_usrreq.c +++ b/sys/kern/uipc_usrreq.c @@ -447,7 +447,7 @@ uipc_sense(struct socket *so, struct stat *sb) so2 = unp->unp_conn->unp_socket; sb->st_blksize += so2->so_rcv.sb_cc; } - sb->st_dev = NOUDEV; + sb->st_dev = NODEV; if (unp->unp_ino == 0) unp->unp_ino = (++unp_ino == 0) ? ++unp_ino : unp_ino; sb->st_ino = unp->unp_ino; diff --git a/sys/kern/vfs_bio.c b/sys/kern/vfs_bio.c index 19b6726..1bfb331 100644 --- a/sys/kern/vfs_bio.c +++ b/sys/kern/vfs_bio.c @@ -517,7 +517,7 @@ bufinit(void) bp = &buf[i]; bzero(bp, sizeof *bp); bp->b_flags = B_INVAL; /* we're just an empty header */ - bp->b_dev = NODEV; + bp->b_dev = NULL; bp->b_rcred = NOCRED; bp->b_wcred = NOCRED; bp->b_qindex = QUEUE_EMPTY; @@ -1413,7 +1413,7 @@ brelse(struct buf * bp) bp->b_qindex = QUEUE_EMPTY; } TAILQ_INSERT_HEAD(&bufqueues[bp->b_qindex], bp, b_freelist); - bp->b_dev = NODEV; + bp->b_dev = NULL; /* buffers with junk contents */ } else if (bp->b_flags & (B_INVAL | B_NOCACHE | B_RELBUF) || (bp->b_ioflags & BIO_ERROR)) { @@ -1423,7 +1423,7 @@ brelse(struct buf * bp) panic("losing buffer 2"); bp->b_qindex = QUEUE_CLEAN; TAILQ_INSERT_HEAD(&bufqueues[QUEUE_CLEAN], bp, b_freelist); - bp->b_dev = NODEV; + bp->b_dev = NULL; /* remaining buffers */ } else { if (bp->b_flags & B_DELWRI) @@ -1917,7 +1917,7 @@ restart: bp->b_ioflags = 0; bp->b_xflags = 0; bp->b_vflags = 0; - bp->b_dev = NODEV; + bp->b_dev = NULL; bp->b_vp = NULL; bp->b_blkno = bp->b_lblkno = 0; bp->b_offset = NOOFFSET; diff --git a/sys/kern/vfs_mount.c b/sys/kern/vfs_mount.c index 8eaa6e9..82086ad 100644 --- a/sys/kern/vfs_mount.c +++ b/sys/kern/vfs_mount.c @@ -147,7 +147,7 @@ static char *cdrom_rootdevnames[] = { /* legacy find-root code */ char *rootdevnames[2] = {NULL, NULL}; static int setrootbyname(char *name); -struct cdev *rootdev = NODEV; +struct cdev *rootdev = NULL; /* * Has to be dynamic as the value of rootdev can change; however, it can't @@ -162,7 +162,7 @@ sysctl_rootdev(SYSCTL_HANDLER_ARGS) /* _RD prevents this from happening. */ KASSERT(req->newptr == NULL, ("Attempt to change root device name")); - if (rootdev != NODEV) + if (rootdev != NULL) error = sysctl_handle_string(oidp, rootdev->si_name, 0, req); else error = sysctl_handle_string(oidp, "", 0, req); @@ -1339,7 +1339,7 @@ vfs_mountroot_try(char *mountfrom) printf("setrootbyname failed\n"); /* If the root device is a type "memory disk", mount RW */ - if (rootdev != NODEV && devsw(rootdev) != NULL) { + if (rootdev != NULL && devsw(rootdev) != NULL) { devname = devtoname(rootdev); if (devname[0] == 'm' && devname[1] == 'd') mp->mnt_flag &= ~MNT_RDONLY; @@ -1457,7 +1457,7 @@ getdiskbyname(char *name) { if (!bcmp(cp, "/dev/", 5)) cp += 5; - dev = NODEV; + dev = NULL; EVENTHANDLER_INVOKE(dev_clone, cp, strlen(cp), &dev); return (dev); } @@ -1472,7 +1472,7 @@ setrootbyname(char *name) struct cdev *diskdev; diskdev = getdiskbyname(name); - if (diskdev != NODEV) { + if (diskdev != NULL) { rootdev = diskdev; return (0); } @@ -1491,7 +1491,7 @@ DB_SHOW_COMMAND(disk, db_getdiskbyname) return; } dev = getdiskbyname(modif); - if (dev != NODEV) + if (dev != NULL) db_printf("struct cdev *= %p\n", dev); else db_printf("No disk device matched.\n"); diff --git a/sys/kern/vfs_subr.c b/sys/kern/vfs_subr.c index 0346fa2..96fdaab 100644 --- a/sys/kern/vfs_subr.c +++ b/sys/kern/vfs_subr.c @@ -367,7 +367,7 @@ vfs_getnewfsid(mp) tfsid.val[1] = mtype; mtype = (mtype & 0xFF) << 24; for (;;) { - tfsid.val[0] = makeudev(255, + tfsid.val[0] = makedev(255, mtype | ((mntid_base & 0xFF00) << 8) | (mntid_base & 0xFF)); mntid_base++; if (vfs_getvfs(&tfsid) == NULL) @@ -1744,7 +1744,7 @@ bdevvp(dev, vpp) struct vnode *nvp; int error; - if (dev == NODEV) { + if (dev == NULL) { *vpp = NULLVP; return (ENXIO); } @@ -1786,7 +1786,7 @@ v_incr_usecount(struct vnode *vp, int delta) struct vnode * addaliasu(nvp, nvp_rdev) struct vnode *nvp; - udev_t nvp_rdev; + dev_t nvp_rdev; { struct vnode *ovp; vop_t **ops; @@ -1796,8 +1796,8 @@ addaliasu(nvp, nvp_rdev) return (nvp); if (nvp->v_type != VCHR) panic("addaliasu on non-special vnode"); - dev = udev2dev(nvp_rdev); - if (dev == NODEV) + dev = findcdev(nvp_rdev); + if (dev == NULL) return (nvp); /* * Check to see if we have a bdevvp vnode with no associated @@ -1836,7 +1836,7 @@ addaliasu(nvp, nvp_rdev) } /* This is a local helper function that do the same as addaliasu, but for a - * struct cdev *instead of an udev_t. */ + * struct cdev *instead of an dev_t. */ static void addalias(nvp, dev) struct vnode *nvp; @@ -2581,7 +2581,7 @@ vgonel(vp, td) * if it is on one. */ VI_LOCK(vp); - if (vp->v_type == VCHR && vp->v_rdev != NODEV) { + if (vp->v_type == VCHR && vp->v_rdev != NULL) { mtx_lock(&spechash_mtx); SLIST_REMOVE(&vp->v_rdev->si_hlist, vp, vnode, v_specnext); vp->v_rdev->si_usecount -= vp->v_usecount; @@ -3407,7 +3407,7 @@ vn_todev(vp) { if (vp->v_type != VCHR) - return (NODEV); + return (NULL); return (vp->v_rdev); } |