diff options
author | dyson <dyson@FreeBSD.org> | 1997-02-10 02:22:35 +0000 |
---|---|---|
committer | dyson <dyson@FreeBSD.org> | 1997-02-10 02:22:35 +0000 |
commit | 10f666af84d48e89e4e2960415c9b616fce4077f (patch) | |
tree | 88a944de263165091f0a18abeedbaaccec532407 /sys/miscfs/fdesc | |
parent | 0960d7e91af3428ffba89b42228d82d8afaa0389 (diff) | |
download | FreeBSD-src-10f666af84d48e89e4e2960415c9b616fce4077f.zip FreeBSD-src-10f666af84d48e89e4e2960415c9b616fce4077f.tar.gz |
This is the kernel Lite/2 commit. There are some requisite userland
changes, so don't expect to be able to run the kernel as-is (very well)
without the appropriate Lite/2 userland changes.
The system boots and can mount UFS filesystems.
Untested: ext2fs, msdosfs, NFS
Known problems: Incorrect Berkeley ID strings in some files.
Mount_std mounts will not work until the getfsent
library routine is changed.
Reviewed by: various people
Submitted by: Jeffery Hsu <hsu@freebsd.org>
Diffstat (limited to 'sys/miscfs/fdesc')
-rw-r--r-- | sys/miscfs/fdesc/fdesc.h | 5 | ||||
-rw-r--r-- | sys/miscfs/fdesc/fdesc_vfsops.c | 71 | ||||
-rw-r--r-- | sys/miscfs/fdesc/fdesc_vnops.c | 162 |
3 files changed, 90 insertions, 148 deletions
diff --git a/sys/miscfs/fdesc/fdesc.h b/sys/miscfs/fdesc/fdesc.h index d754655..b4eff1f 100644 --- a/sys/miscfs/fdesc/fdesc.h +++ b/sys/miscfs/fdesc/fdesc.h @@ -61,8 +61,7 @@ typedef enum { } fdntype; struct fdescnode { - struct fdescnode *fd_forw; /* Hash chain */ - struct fdescnode *fd_back; + LIST_ENTRY(fdescnode) fd_hash; /* Hash list */ struct vnode *fd_vnode; /* Back ptr to vnode */ fdntype fd_type; /* Type of this node */ unsigned fd_fd; /* Fd to be dup'ed */ @@ -74,7 +73,7 @@ struct fdescnode { #define VTOFDESC(vp) ((struct fdescnode *)(vp)->v_data) extern dev_t devctty; -extern int fdesc_init __P((void)); +extern int fdesc_init __P((struct vfsconf *)); extern int fdesc_root __P((struct mount *, struct vnode **)); extern int fdesc_allocvp __P((fdntype, int, struct mount *, struct vnode **)); extern vop_t **fdesc_vnodeop_p; diff --git a/sys/miscfs/fdesc/fdesc_vfsops.c b/sys/miscfs/fdesc/fdesc_vfsops.c index 5f6703b..135052e 100644 --- a/sys/miscfs/fdesc/fdesc_vfsops.c +++ b/sys/miscfs/fdesc/fdesc_vfsops.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 1992, 1993 + * Copyright (c) 1992, 1993, 1995 * The Regents of the University of California. All rights reserved. * * This code is derived from software donated to Berkeley by @@ -108,7 +108,7 @@ fdesc_mount(mp, path, data, ndp, p) /* XXX -- don't mark as local to work around fts() problems */ /*mp->mnt_flag |= MNT_LOCAL;*/ mp->mnt_data = (qaddr_t) fmp; - getnewfsid(mp, MOUNT_FDESC); + vfs_getnewfsid(mp); (void) copyinstr(path, mp->mnt_stat.f_mntonname, MNAMELEN - 1, &size); bzero(mp->mnt_stat.f_mntonname + size, MNAMELEN - size); @@ -137,12 +137,8 @@ fdesc_unmount(mp, mntflags, p) int flags = 0; struct vnode *rootvp = VFSTOFDESC(mp)->f_root; - if (mntflags & MNT_FORCE) { - /* fdesc can never be rootfs so don't check for it */ - if (!doforce) - return (EINVAL); + if (mntflags & MNT_FORCE) flags |= FORCECLOSE; - } /* * Clear out buffer cache. I don't think we @@ -176,6 +172,7 @@ fdesc_root(mp, vpp) struct mount *mp; struct vnode **vpp; { + struct proc *p = curproc; /* XXX */ struct vnode *vp; /* @@ -183,24 +180,12 @@ fdesc_root(mp, vpp) */ vp = VFSTOFDESC(mp)->f_root; VREF(vp); - VOP_LOCK(vp); + vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, p); *vpp = vp; return (0); } static int -fdesc_quotactl(mp, cmd, uid, arg, p) - struct mount *mp; - int cmd; - uid_t uid; - caddr_t arg; - struct proc *p; -{ - - return (EOPNOTSUPP); -} - -static int fdesc_statfs(mp, sbp, p) struct mount *mp; struct statfs *sbp; @@ -233,7 +218,6 @@ fdesc_statfs(mp, sbp, p) if (fdp->fd_nfiles < lim) freefd += (lim - fdp->fd_nfiles); - sbp->f_type = MOUNT_FDESC; sbp->f_flags = 0; sbp->f_bsize = DEV_BSIZE; sbp->f_iosize = DEV_BSIZE; @@ -243,6 +227,7 @@ fdesc_statfs(mp, sbp, p) sbp->f_files = lim + 1; /* Allow for "." */ sbp->f_ffree = freefd; /* See comments above */ if (sbp != &mp->mnt_stat) { + sbp->f_type = mp->mnt_vfc->vfc_typenum; bcopy(&mp->mnt_stat.f_fsid, &sbp->f_fsid, sizeof(sbp->f_fsid)); bcopy(mp->mnt_stat.f_mntonname, sbp->f_mntonname, MNAMELEN); bcopy(mp->mnt_stat.f_mntfromname, sbp->f_mntfromname, MNAMELEN); @@ -261,41 +246,15 @@ fdesc_sync(mp, waitfor, cred, p) return (0); } -/* - * Fdesc flat namespace lookup. - * Currently unsupported. - */ -static int -fdesc_vget(mp, ino, vpp) - struct mount *mp; - ino_t ino; - struct vnode **vpp; -{ - - return (EOPNOTSUPP); -} - -static int -fdesc_fhtovp(mp, fhp, nam, vpp, exflagsp, credanonp) - struct mount *mp; - struct fid *fhp; - struct mbuf *nam; - struct vnode **vpp; - int *exflagsp; - struct ucred **credanonp; -{ - - return (EOPNOTSUPP); -} - -static int -fdesc_vptofh(vp, fhp) - struct vnode *vp; - struct fid *fhp; -{ - - return (EOPNOTSUPP); -} +#define fdesc_fhtovp ((int (*) __P((struct mount *, struct fid *, \ + struct mbuf *, struct vnode **, int *, struct ucred **)))eopnotsupp) +#define fdesc_quotactl ((int (*) __P((struct mount *, int, uid_t, caddr_t, \ + struct proc *)))eopnotsupp) +#define fdesc_sysctl ((int (*) __P((int *, u_int, void *, size_t *, void *, \ + size_t, struct proc *)))eopnotsupp) +#define fdesc_vget ((int (*) __P((struct mount *, ino_t, struct vnode **))) \ + eopnotsupp) +#define fdesc_vptofh ((int (*) __P((struct vnode *, struct fid *)))eopnotsupp) static struct vfsops fdesc_vfsops = { fdesc_mount, diff --git a/sys/miscfs/fdesc/fdesc_vnops.c b/sys/miscfs/fdesc/fdesc_vnops.c index 1fe511b..795dfd8 100644 --- a/sys/miscfs/fdesc/fdesc_vnops.c +++ b/sys/miscfs/fdesc/fdesc_vnops.c @@ -77,22 +77,14 @@ FD_STDIN, FD_STDOUT, FD_STDERR must be a sequence n, n+1, n+2 #endif #define NFDCACHE 4 -#define FD_NHASH(ix) ((ix) & NFDCACHE-1) - -/* - * Cache head - */ -struct fdcache { - struct fdescnode *fc_forw; - struct fdescnode *fc_back; -}; - -static struct fdcache fdcache[NFDCACHE]; +#define FD_NHASH(ix) \ + (&fdhashtbl[(ix) & fdhash]) +LIST_HEAD(fdhashhead, fdescnode) *fdhashtbl; +u_long fdhash; static int fdesc_attr __P((int fd, struct vattr *vap, struct ucred *cred, struct proc *p)); static int fdesc_badop __P((void)); -static int fdesc_enotsupp __P((void)); static int fdesc_getattr __P((struct vop_getattr_args *ap)); static struct fdcache * fdesc_hash __P((int ix)); @@ -115,28 +107,15 @@ static int fdesc_write __P((struct vop_write_args *ap)); * Initialise cache headers */ int -fdesc_init() +fdesc_init(vfsp) + struct vfsconf *vfsp; { - struct fdcache *fc; devctty = makedev(nchrdev, 0); - - for (fc = fdcache; fc < fdcache + NFDCACHE; fc++) - fc->fc_forw = fc->fc_back = (struct fdescnode *) fc; + fdhashtbl = hashinit(NFDCACHE, M_CACHE, &fdhash); return (0); } -/* - * Compute hash list for given target vnode - */ -static struct fdcache * -fdesc_hash(ix) - int ix; -{ - - return (&fdcache[FD_NHASH(ix)]); -} - int fdesc_allocvp(ftype, ix, mp, vpp) fdntype ftype; @@ -144,15 +123,16 @@ fdesc_allocvp(ftype, ix, mp, vpp) struct mount *mp; struct vnode **vpp; { - struct fdcache *fc; + struct proc *p = curproc; /* XXX */ + struct fdhashhead *fc; struct fdescnode *fd; int error = 0; + fc = FD_NHASH(ix); loop: - fc = fdesc_hash(ix); - for (fd = fc->fc_forw; fd != (struct fdescnode *) fc; fd = fd->fd_forw) { + for (fd = fc->lh_first; fd != 0; fd = fd->fd_hash.le_next) { if (fd->fd_ix == ix && fd->fd_vnode->v_mount == mp) { - if (vget(fd->fd_vnode, 0)) + if (vget(fd->fd_vnode, 0, p)) goto loop; *vpp = fd->fd_vnode; return (error); @@ -188,8 +168,7 @@ loop: fd->fd_fd = -1; fd->fd_link = 0; fd->fd_ix = ix; - fc = fdesc_hash(ix); - insque(fd, fc); + LIST_INSERT_HEAD(fc, fd, fd_hash); out:; fdcache_lock &= ~FDL_LOCKED; @@ -216,31 +195,28 @@ fdesc_lookup(ap) { struct vnode **vpp = ap->a_vpp; struct vnode *dvp = ap->a_dvp; - char *pname; - struct proc *p; - int nfiles; - unsigned fd = 0; + struct componentname *cnp = ap->a_cnp; + char *pname = cnp->cn_nameptr; + struct proc *p = cnp->cn_proc; + int nfiles = p->p_fd->fd_nfiles; + unsigned fd; int error; struct vnode *fvp; char *ln; - if (ap->a_cnp->cn_nameiop == DELETE || - ap->a_cnp->cn_nameiop == RENAME) { + if (cnp->cn_nameiop == DELETE || cnp->cn_nameiop == RENAME) { error = EROFS; goto bad; } - pname = ap->a_cnp->cn_nameptr; - if (ap->a_cnp->cn_namelen == 1 && *pname == '.') { + VOP_UNLOCK(dvp, 0, p); + if (cnp->cn_namelen == 1 && *pname == '.') { *vpp = dvp; - VREF(dvp); - VOP_LOCK(dvp); + VREF(dvp); + vn_lock(dvp, LK_SHARED | LK_RETRY, p); return (0); } - p = ap->a_cnp->cn_proc; - nfiles = p->p_fd->fd_nfiles; - switch (VTOFDESC(dvp)->fd_type) { default: case Flink: @@ -250,17 +226,17 @@ fdesc_lookup(ap) goto bad; case Froot: - if (ap->a_cnp->cn_namelen == 2 && bcmp(pname, "fd", 2) == 0) { + if (cnp->cn_namelen == 2 && bcmp(pname, "fd", 2) == 0) { error = fdesc_allocvp(Fdevfd, FD_DEVFD, dvp->v_mount, &fvp); if (error) goto bad; *vpp = fvp; fvp->v_type = VDIR; - VOP_LOCK(fvp); + vn_lock(fvp, LK_SHARED | LK_RETRY, p); return (0); } - if (ap->a_cnp->cn_namelen == 3 && bcmp(pname, "tty", 3) == 0) { + if (cnp->cn_namelen == 3 && bcmp(pname, "tty", 3) == 0) { struct vnode *ttyvp = cttyvp(p); if (ttyvp == NULL) { error = ENXIO; @@ -271,12 +247,12 @@ fdesc_lookup(ap) goto bad; *vpp = fvp; fvp->v_type = VFIFO; - VOP_LOCK(fvp); + vn_lock(fvp, LK_SHARED | LK_RETRY, p); return (0); } ln = 0; - switch (ap->a_cnp->cn_namelen) { + switch (cnp->cn_namelen) { case 5: if (bcmp(pname, "stdin", 5) == 0) { ln = "fd/0"; @@ -302,7 +278,7 @@ fdesc_lookup(ap) VTOFDESC(fvp)->fd_link = ln; *vpp = fvp; fvp->v_type = VLNK; - VOP_LOCK(fvp); + vn_lock(fvp, LK_SHARED | LK_RETRY, p); return (0); } else { error = ENOENT; @@ -312,9 +288,10 @@ fdesc_lookup(ap) /* FALL THROUGH */ case Fdevfd: - if (ap->a_cnp->cn_namelen == 2 && bcmp(pname, "..", 2) == 0) { - error = fdesc_root(dvp->v_mount, vpp); - return (error); + if (cnp->cn_namelen == 2 && bcmp(pname, "..", 2) == 0) { + if (error = fdesc_root(dvp->v_mount, vpp)) + goto bad; + return (0); } fd = 0; @@ -338,11 +315,13 @@ fdesc_lookup(ap) if (error) goto bad; VTOFDESC(fvp)->fd_fd = fd; + vn_lock(fvp, LK_SHARED | LK_RETRY, p); *vpp = fvp; return (0); } bad:; + vn_lock(dvp, LK_SHARED | LK_RETRY, p); *vpp = NULL; return (error); } @@ -402,10 +381,10 @@ fdesc_attr(fd, vap, cred, p) error = VOP_GETATTR((struct vnode *) fp->f_data, vap, cred, p); if (error == 0 && vap->va_type == VDIR) { /* - * don't allow directories to show up because - * that causes loops in the namespace. + * directories can cause loops in the namespace, + * so turn off the 'x' bits to avoid trouble. */ - vap->va_type = VFIFO; + vap->va_mode &= ~((VEXEC)|(VEXEC>>3)|(VEXEC>>6)); } break; @@ -591,6 +570,9 @@ fdesc_readdir(ap) struct vnode *a_vp; struct uio *a_uio; struct ucred *a_cred; + int *a_eofflag; + u_long *a_cookies; + int a_ncookies; } */ *ap; { struct uio *uio = ap->a_uio; @@ -598,6 +580,13 @@ fdesc_readdir(ap) int i; int error; + /* + * We don't allow exporting fdesc mounts, and currently local + * requests do not need cookies. + */ + if (ap->a_ncookies) + panic("fdesc_readdir: not hungry"); + switch (VTOFDESC(ap->a_vp)->fd_type) { case Fctty: return (0); @@ -814,6 +803,7 @@ static int fdesc_inactive(ap) struct vop_inactive_args /* { struct vnode *a_vp; + struct proc *a_p; } */ *ap; { struct vnode *vp = ap->a_vp; @@ -822,6 +812,7 @@ fdesc_inactive(ap) * Clear out the v_type field to avoid * nasty things happening in vgone(). */ + VOP_UNLOCK(vp, 0, ap->a_p); vp->v_type = VNON; return (0); } @@ -833,8 +824,9 @@ fdesc_reclaim(ap) } */ *ap; { struct vnode *vp = ap->a_vp; + struct fdescnode *fd = VTOFDESC(vp); - remque(VTOFDESC(vp)); + LIST_REMOVE(fd, fd_hash); FREE(vp->v_data, M_TEMP); vp->v_data = 0; @@ -907,16 +899,6 @@ fdesc_vfree(ap) } /* - * /dev/fd vnode unsupported operation - */ -static int -fdesc_enotsupp() -{ - - return (EOPNOTSUPP); -} - -/* * /dev/fd "should never get here" operation */ static int @@ -927,38 +909,39 @@ fdesc_badop() /* NOTREACHED */ } -#define fdesc_create ((int (*) __P((struct vop_create_args *)))fdesc_enotsupp) -#define fdesc_mknod ((int (*) __P((struct vop_mknod_args *)))fdesc_enotsupp) +#define fdesc_create ((int (*) __P((struct vop_create_args *)))eopnotsupp) +#define fdesc_mknod ((int (*) __P((struct vop_mknod_args *)))eopnotsupp) #define fdesc_close ((int (*) __P((struct vop_close_args *)))nullop) #define fdesc_access ((int (*) __P((struct vop_access_args *)))nullop) -#define fdesc_mmap ((int (*) __P((struct vop_mmap_args *)))fdesc_enotsupp) +#define fdesc_mmap ((int (*) __P((struct vop_mmap_args *)))eopnotsupp) +#define fdesc_revoke vop_revoke #define fdesc_fsync ((int (*) __P((struct vop_fsync_args *)))nullop) #define fdesc_seek ((int (*) __P((struct vop_seek_args *)))nullop) -#define fdesc_remove ((int (*) __P((struct vop_remove_args *)))fdesc_enotsupp) -#define fdesc_link ((int (*) __P((struct vop_link_args *)))fdesc_enotsupp) -#define fdesc_rename ((int (*) __P((struct vop_rename_args *)))fdesc_enotsupp) -#define fdesc_mkdir ((int (*) __P((struct vop_mkdir_args *)))fdesc_enotsupp) -#define fdesc_rmdir ((int (*) __P((struct vop_rmdir_args *)))fdesc_enotsupp) -#define fdesc_symlink ((int (*) __P((struct vop_symlink_args *)))fdesc_enotsupp) +#define fdesc_remove ((int (*) __P((struct vop_remove_args *)))eopnotsupp) +#define fdesc_link ((int (*) __P((struct vop_link_args *)))eopnotsupp) +#define fdesc_rename ((int (*) __P((struct vop_rename_args *)))eopnotsupp) +#define fdesc_mkdir ((int (*) __P((struct vop_mkdir_args *)))eopnotsupp) +#define fdesc_rmdir ((int (*) __P((struct vop_rmdir_args *)))eopnotsupp) +#define fdesc_symlink ((int (*) __P((struct vop_symlink_args *)))eopnotsupp) #define fdesc_abortop ((int (*) __P((struct vop_abortop_args *)))nullop) -#define fdesc_lock ((int (*) __P((struct vop_lock_args *)))nullop) -#define fdesc_unlock ((int (*) __P((struct vop_unlock_args *)))nullop) +#define fdesc_lock ((int (*) __P((struct vop_lock_args *)))vop_nolock) +#define fdesc_unlock ((int (*) __P((struct vop_unlock_args *)))vop_nounlock) #define fdesc_bmap ((int (*) __P((struct vop_bmap_args *)))fdesc_badop) #define fdesc_strategy ((int (*) __P((struct vop_strategy_args *)))fdesc_badop) -#define fdesc_islocked ((int (*) __P((struct vop_islocked_args *)))nullop) -#define fdesc_advlock ((int (*) __P((struct vop_advlock_args *)))fdesc_enotsupp) +#define fdesc_islocked \ + ((int (*) __P((struct vop_islocked_args *)))vop_noislocked) +#define fdesc_advlock ((int (*) __P((struct vop_advlock_args *)))eopnotsupp) #define fdesc_blkatoff \ - ((int (*) __P((struct vop_blkatoff_args *)))fdesc_enotsupp) -#define fdesc_vget ((int (*) __P((struct vop_vget_args *)))fdesc_enotsupp) + ((int (*) __P((struct vop_blkatoff_args *)))eopnotsupp) #define fdesc_valloc ((int(*) __P(( \ struct vnode *pvp, \ int mode, \ struct ucred *cred, \ - struct vnode **vpp))) fdesc_enotsupp) + struct vnode **vpp))) eopnotsupp) #define fdesc_truncate \ - ((int (*) __P((struct vop_truncate_args *)))fdesc_enotsupp) -#define fdesc_update ((int (*) __P((struct vop_update_args *)))fdesc_enotsupp) -#define fdesc_bwrite ((int (*) __P((struct vop_bwrite_args *)))fdesc_enotsupp) + ((int (*) __P((struct vop_truncate_args *)))eopnotsupp) +#define fdesc_update ((int (*) __P((struct vop_update_args *)))eopnotsupp) +#define fdesc_bwrite ((int (*) __P((struct vop_bwrite_args *)))eopnotsupp) static vop_t **fdesc_vnodeop_p; static struct vnodeopv_entry_desc fdesc_vnodeop_entries[] = { @@ -975,6 +958,7 @@ static struct vnodeopv_entry_desc fdesc_vnodeop_entries[] = { { &vop_write_desc, (vop_t *)fdesc_write }, /* write */ { &vop_ioctl_desc, (vop_t *)fdesc_ioctl }, /* ioctl */ { &vop_select_desc, (vop_t *)fdesc_select }, /* select */ + { &vop_revoke_desc, (vop_t *)fdesc_revoke }, /* revoke */ { &vop_mmap_desc, (vop_t *)fdesc_mmap }, /* mmap */ { &vop_fsync_desc, (vop_t *)fdesc_fsync }, /* fsync */ { &vop_seek_desc, (vop_t *)fdesc_seek }, /* seek */ |