daddr_t => ufs_daddr_t
[unix-history] / usr / src / sys / ufs / lfs / lfs_vfsops.c
index 48069b0..fbd9ea2 100644 (file)
@@ -1,10 +1,10 @@
 /*
 /*
- * Copyright (c) 1989, 1991, 1993
+ * Copyright (c) 1989, 1991, 1993, 1994
  *     The Regents of the University of California.  All rights reserved.
  *
  * %sccs.include.redist.c%
  *
  *     The Regents of the University of California.  All rights reserved.
  *
  * %sccs.include.redist.c%
  *
- *     @(#)lfs_vfsops.c        8.4 (Berkeley) %G%
+ *     @(#)lfs_vfsops.c        8.11 (Berkeley) %G%
  */
 
 #include <sys/param.h>
  */
 
 #include <sys/param.h>
@@ -42,7 +42,7 @@ struct vfsops lfs_vfsops = {
        lfs_mount,
        ufs_start,
        lfs_unmount,
        lfs_mount,
        ufs_start,
        lfs_unmount,
-       lfs_root,
+       ufs_root,
        ufs_quotactl,
        lfs_statfs,
        lfs_sync,
        ufs_quotactl,
        lfs_statfs,
        lfs_sync,
@@ -76,43 +76,42 @@ lfs_mount(mp, path, data, ndp, p)
        register struct lfs *fs;                                /* LFS */
        u_int size;
        int error;
        register struct lfs *fs;                                /* LFS */
        u_int size;
        int error;
+       mode_t accessmode;
 
        if (error = copyin(data, (caddr_t)&args, sizeof (struct ufs_args)))
                return (error);
 
        /* Until LFS can do NFS right.          XXX */
 
        if (error = copyin(data, (caddr_t)&args, sizeof (struct ufs_args)))
                return (error);
 
        /* Until LFS can do NFS right.          XXX */
-       if (args.exflags & MNT_EXPORTED)
+       if (args.export.ex_flags & MNT_EXPORTED)
                return (EINVAL);
                return (EINVAL);
+
        /*
         * If updating, check whether changing from read-only to
         * read/write; if there is no device name, that's all we do.
         */
        if (mp->mnt_flag & MNT_UPDATE) {
                ump = VFSTOUFS(mp);
        /*
         * If updating, check whether changing from read-only to
         * read/write; if there is no device name, that's all we do.
         */
        if (mp->mnt_flag & MNT_UPDATE) {
                ump = VFSTOUFS(mp);
-#ifdef NOTLFS                                                  /* LFS */
-               fs = ump->um_fs;
-               if (fs->fs_ronly && (mp->mnt_flag & MNT_RDONLY) == 0)
-                       fs->fs_ronly = 0;
-#else
-               fs = ump->um_lfs;
-               if (fs->lfs_ronly && (mp->mnt_flag & MNT_RDONLY) == 0)
+               if (fs->lfs_ronly && (mp->mnt_flag & MNT_WANTRDWR)) {
+                       /*
+                        * If upgrade to read-write by non-root, then verify
+                        * that user has necessary permissions on the device.
+                        */
+                       if (p->p_ucred->cr_uid != 0) {
+                               VOP_LOCK(ump->um_devvp);
+                               if (error = VOP_ACCESS(ump->um_devvp,
+                                   VREAD | VWRITE, p->p_ucred, p)) {
+                                       VOP_UNLOCK(ump->um_devvp);
+                                       return (error);
+                               }
+                               VOP_UNLOCK(ump->um_devvp);
+                       }
                        fs->lfs_ronly = 0;
                        fs->lfs_ronly = 0;
-#endif
+               }
                if (args.fspec == 0) {
                        /*
                         * Process export requests.
                         */
                if (args.fspec == 0) {
                        /*
                         * Process export requests.
                         */
-                       if (args.exflags & MNT_EXPORTED) {
-                               if (error = ufs_hang_addrlist(mp, &args))
-                                       return (error);
-                               mp->mnt_flag |= MNT_EXPORTED;
-                       }
-                       if (args.exflags & MNT_DELEXPORT) {
-                               ufs_free_addrlist(ump);
-                               mp->mnt_flag &=
-                                   ~(MNT_EXPORTED | MNT_DEFEXPORTED);
-                       }
-                       return (0);
+                       return (vfs_export(mp, &ump->um_export, &args.export));
                }
        }
        /*
                }
        }
        /*
@@ -131,6 +130,21 @@ lfs_mount(mp, path, data, ndp, p)
                vrele(devvp);
                return (ENXIO);
        }
                vrele(devvp);
                return (ENXIO);
        }
+       /*
+        * If mount by non-root, then verify that user has necessary
+        * permissions on the device.
+        */
+       if (p->p_ucred->cr_uid != 0) {
+               accessmode = VREAD;
+               if ((mp->mnt_flag & MNT_RDONLY) == 0)
+                       accessmode |= VWRITE;
+               VOP_LOCK(devvp);
+               if (error = VOP_ACCESS(devvp, accessmode, p->p_ucred, p)) {
+                       vput(devvp);
+                       return (error);
+               }
+               VOP_UNLOCK(devvp);
+       }
        if ((mp->mnt_flag & MNT_UPDATE) == 0)
                error = lfs_mountfs(devvp, mp, p);              /* LFS */
        else {
        if ((mp->mnt_flag & MNT_UPDATE) == 0)
                error = lfs_mountfs(devvp, mp, p);              /* LFS */
        else {
@@ -185,11 +199,13 @@ lfs_mountfs(devvp, mp, p)
        struct partinfo dpart;
        dev_t dev;
        int error, i, ronly, size;
        struct partinfo dpart;
        dev_t dev;
        int error, i, ronly, size;
+       struct ucred *cred;
 
 
+       cred = p ? p->p_ucred : NOCRED;
        if (error = VOP_OPEN(devvp, ronly ? FREAD : FREAD|FWRITE, FSCRED, p))
                return (error);
 
        if (error = VOP_OPEN(devvp, ronly ? FREAD : FREAD|FWRITE, FSCRED, p))
                return (error);
 
-       if (VOP_IOCTL(devvp, DIOCGPART, (caddr_t)&dpart, FREAD, NOCRED, p) != 0)
+       if (VOP_IOCTL(devvp, DIOCGPART, (caddr_t)&dpart, FREAD, cred, p) != 0)
                size = DEV_BSIZE;
        else {
                size = dpart.disklab->d_secsize;
                size = DEV_BSIZE;
        else {
                size = dpart.disklab->d_secsize;
@@ -206,7 +222,7 @@ lfs_mountfs(devvp, mp, p)
        ump = NULL;
 
        /* Read in the superblock. */
        ump = NULL;
 
        /* Read in the superblock. */
-       if (error = bread(devvp, LFS_LABELPAD / size, LFS_SBPAD, NOCRED, &bp))
+       if (error = bread(devvp, LFS_LABELPAD / size, LFS_SBPAD, cred, &bp))
                goto out;
                error = EINVAL;         /* XXX needs translation */
                goto out;
                goto out;
                error = EINVAL;         /* XXX needs translation */
                goto out;
@@ -240,6 +256,7 @@ lfs_mountfs(devvp, mp, p)
        mp->mnt_data = (qaddr_t)ump;
        mp->mnt_stat.f_fsid.val[0] = (long)dev;
        mp->mnt_stat.f_fsid.val[1] = MOUNT_LFS;
        mp->mnt_data = (qaddr_t)ump;
        mp->mnt_stat.f_fsid.val[0] = (long)dev;
        mp->mnt_stat.f_fsid.val[1] = MOUNT_LFS;
+       mp->mnt_maxsymlinklen = fs->lfs_maxsymlinklen;
        mp->mnt_flag |= MNT_LOCAL;
        ump->um_mountp = mp;
        ump->um_dev = dev;
        mp->mnt_flag |= MNT_LOCAL;
        ump->um_mountp = mp;
        ump->um_dev = dev;
@@ -268,7 +285,7 @@ lfs_mountfs(devvp, mp, p)
 out:
        if (bp)
                brelse(bp);
 out:
        if (bp)
                brelse(bp);
-       (void)VOP_CLOSE(devvp, ronly ? FREAD : FREAD|FWRITE, NOCRED, p);
+       (void)VOP_CLOSE(devvp, ronly ? FREAD : FREAD|FWRITE, cred, p);
        if (ump) {
                free(ump->um_lfs, M_UFSMNT);
                free(ump, M_UFSMNT);
        if (ump) {
                free(ump->um_lfs, M_UFSMNT);
                free(ump, M_UFSMNT);
@@ -399,7 +416,7 @@ lfs_vget(mp, ino, vpp)
        struct ifile *ifp;
        struct vnode *vp;
        struct ufsmount *ump;
        struct ifile *ifp;
        struct vnode *vp;
        struct ufsmount *ump;
-       daddr_t daddr;
+       ufs_daddr_t daddr;
        dev_t dev;
        int error;
 
        dev_t dev;
        int error;