From c98a31cad3be5e324706ef5df99da87bcb688f47 Mon Sep 17 00:00:00 2001 From: Tom Rhodes Date: Tue, 12 Aug 2003 20:06:56 +0000 Subject: [PATCH] Add a '-M mask' option so that users can have different masks for files and directories. This should make some of the Midnight Commander users happy. Remove an extra ')' in the manual page. PR: 35699 Submitted by: Eugene Grosbein (original version) Tested by: simon --- sbin/mount_msdosfs/mount_msdosfs.8 | 17 ++++++++++++++++- sbin/mount_msdosfs/mount_msdosfs.c | 22 ++++++++++++++++++---- sys/fs/msdosfs/msdosfs_vfsops.c | 1 + sys/fs/msdosfs/msdosfs_vnops.c | 5 +++-- sys/fs/msdosfs/msdosfsmount.h | 8 ++++++-- 5 files changed, 44 insertions(+), 9 deletions(-) diff --git a/sbin/mount_msdosfs/mount_msdosfs.8 b/sbin/mount_msdosfs/mount_msdosfs.8 index 147f1f1ab43b..8eee35c4d47b 100644 --- a/sbin/mount_msdosfs/mount_msdosfs.8 +++ b/sbin/mount_msdosfs/mount_msdosfs.8 @@ -42,6 +42,7 @@ .Op Fl u Ar uid .Op Fl g Ar gid .Op Fl m Ar mask +.Op Fl M Ar mask .Op Fl s .Op Fl l .Op Fl 9 @@ -104,14 +105,28 @@ read, write, and execute permissions for files, but others should only have read and execute permissions. See .Xr chmod 1 -for more information about octal file modes.) +for more information about octal file modes. Only the nine low-order bits of .Ar mask are used. +The value of +.Ar -M +is used if it is supplied and +.Ar -m +is omitted. The default .Ar mask is taken from the directory on which the file system is being mounted. +.It Fl M Ar mask +Specify the maximum file permissions for directories +in the file system. +The value of +.Ar -m +is used if it is supplied and +.Ar -M +is omitted. +See the previous option's description for details. .It Fl s Force behaviour to ignore and not generate Win'95 long filenames. diff --git a/sbin/mount_msdosfs/mount_msdosfs.c b/sbin/mount_msdosfs/mount_msdosfs.c index 187dc13304c9..061e3cb0c5c1 100644 --- a/sbin/mount_msdosfs/mount_msdosfs.c +++ b/sbin/mount_msdosfs/mount_msdosfs.c @@ -88,14 +88,14 @@ main(argc, argv) { struct msdosfs_args args; struct stat sb; - int c, mntflags, set_gid, set_uid, set_mask; + int c, mntflags, set_gid, set_uid, set_mask, set_dirmask; char *dev, *dir, mntpath[MAXPATHLEN]; - mntflags = set_gid = set_uid = set_mask = 0; + mntflags = set_gid = set_uid = set_mask = set_dirmask = 0; (void)memset(&args, '\0', sizeof(args)); args.magic = MSDOSFS_ARGSMAGIC; - while ((c = getopt(argc, argv, "sl9u:g:m:o:L:W:")) != -1) { + while ((c = getopt(argc, argv, "sl9u:g:m:M:o:L:W:")) != -1) { switch (c) { #ifdef MSDOSFSMNT_GEMDOSFS case 'G': @@ -123,6 +123,10 @@ main(argc, argv) args.mask = a_mask(optarg); set_mask = 1; break; + case 'M': + args.dirmask = a_mask(optarg); + set_dirmask = 1; + break; case 'L': load_ultable(&args, optarg); args.flags |= MSDOSFSMNT_ULTABLE; @@ -144,6 +148,15 @@ main(argc, argv) if (optind + 2 != argc) usage(); + if (set_mask && !set_dirmask) { + args.dirmask = args.mask; + set_dirmask = 1; + } + else if (set_dirmask && !set_mask) { + args.mask = args.dirmask; + set_mask = 1; + } + dev = argv[optind]; dir = argv[optind + 1]; @@ -169,7 +182,8 @@ main(argc, argv) if (!set_gid) args.gid = sb.st_gid; if (!set_mask) - args.mask = sb.st_mode & (S_IRWXU | S_IRWXG | S_IRWXO); + args.mask = args.dirmask = + sb.st_mode & (S_IRWXU | S_IRWXG | S_IRWXO); } if (mount("msdosfs", mntpath, mntflags, &args) < 0) diff --git a/sys/fs/msdosfs/msdosfs_vfsops.c b/sys/fs/msdosfs/msdosfs_vfsops.c index 22d518e7f391..11a3d6d79501 100644 --- a/sys/fs/msdosfs/msdosfs_vfsops.c +++ b/sys/fs/msdosfs/msdosfs_vfsops.c @@ -108,6 +108,7 @@ update_mp(mp, argp) pmp->pm_gid = argp->gid; pmp->pm_uid = argp->uid; pmp->pm_mask = argp->mask & ALLPERMS; + pmp->pm_dirmask = argp->dirmask & ALLPERMS; pmp->pm_flags |= argp->flags & MSDOSFSMNT_MNTOPT; if (pmp->pm_flags & MSDOSFSMNT_U2WTABLE) { bcopy(argp->u2w, pmp->pm_u2w, sizeof(pmp->pm_u2w)); diff --git a/sys/fs/msdosfs/msdosfs_vnops.c b/sys/fs/msdosfs/msdosfs_vnops.c index bce6b0d151da..ba36c5ba490a 100644 --- a/sys/fs/msdosfs/msdosfs_vnops.c +++ b/sys/fs/msdosfs/msdosfs_vnops.c @@ -243,7 +243,7 @@ msdosfs_access(ap) file_mode = (S_IXUSR|S_IXGRP|S_IXOTH) | (S_IRUSR|S_IRGRP|S_IROTH) | ((dep->de_Attributes & ATTR_READONLY) ? 0 : (S_IWUSR|S_IWGRP|S_IWOTH)); - file_mode &= pmp->pm_mask; + file_mode &= (vp->v_type == VDIR ? pmp->pm_dirmask : pmp->pm_mask); /* * Disallow write attempts on read-only filesystems; @@ -307,7 +307,8 @@ msdosfs_getattr(ap) mode = S_IRWXU|S_IRWXG|S_IRWXO; else mode = S_IRUSR|S_IXUSR|S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH; - vap->va_mode = mode & pmp->pm_mask; + vap->va_mode = mode & + (ap->a_vp->v_type == VDIR ? pmp->pm_dirmask : pmp->pm_mask); vap->va_uid = pmp->pm_uid; vap->va_gid = pmp->pm_gid; vap->va_nlink = 1; diff --git a/sys/fs/msdosfs/msdosfsmount.h b/sys/fs/msdosfs/msdosfsmount.h index a3bb34ff9c20..d525771f6816 100644 --- a/sys/fs/msdosfs/msdosfsmount.h +++ b/sys/fs/msdosfs/msdosfsmount.h @@ -65,7 +65,10 @@ struct msdosfsmount { dev_t pm_dev; /* block special device mounted */ uid_t pm_uid; /* uid to set as owner of the files */ gid_t pm_gid; /* gid to set as owner of the files */ - mode_t pm_mask; /* mask to and with file protection bits */ + mode_t pm_mask; /* mask to and with file protection bits + for files */ + mode_t pm_dirmask; /* mask to and with file protection bits + for directories */ struct vnode *pm_devvp; /* vnode for block device mntd */ struct bpb50 pm_bpb; /* BIOS parameter blk for this fs */ u_long pm_BlkPerSec; /* How many DEV_BSIZE blocks fit inside a physical sector */ @@ -210,7 +213,8 @@ struct msdosfs_args { struct export_args export; /* network export information */ uid_t uid; /* uid that owns msdosfs files */ gid_t gid; /* gid that owns msdosfs files */ - mode_t mask; /* mask to be applied for msdosfs perms */ + mode_t mask; /* file mask to be applied for msdosfs perms */ + mode_t dirmask; /* dir mask to be applied for msdosfs perms */ int flags; /* see below */ int magic; /* version number */ u_int16_t u2w[128]; /* Local->Unicode table */