Allow separate masks for files and directories. Useful e.g. to turn

the execute bit off for files, but keep search permission for directories.
Change contributed in PR kern/21538 by Pavel Arnost, based on some FreeBSD
patches.
Further manpage changes, and backward-compatibility adjustments done by me.

Also fixes PR kern/16778 by Johan Danielsson, and PR kern/3400 by Rick Byers
This commit is contained in:
jdolecek 2003-08-02 11:41:19 +00:00
parent 913ed381f5
commit 62e0ed44c8
5 changed files with 86 additions and 24 deletions

View File

@ -1,4 +1,4 @@
.\" $NetBSD: mount_msdos.8,v 1.25 2003/02/25 10:35:02 wiz Exp $
.\" $NetBSD: mount_msdos.8,v 1.26 2003/08/02 11:41:19 jdolecek Exp $
.\"
.\" Copyright (c) 1993, 1994 Christopher G. Demetriou
.\" All rights reserved.
@ -44,6 +44,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
@ -98,9 +99,20 @@ See
for more information about octal file modes.)
Only the nine low-order bits of
.Ar mask
are used.
are used. The value of
.Fl M
is used if it is supplied and
.Fl m
is omitted.
The default 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
.Fl m
is used if it is supplied and
.Fl M
is omitted. See description of previous option for details.
.It Fl s
Force behaviour to
ignore and not generate Win'95 long filenames.
@ -136,6 +148,13 @@ limited to the boot block.
This option enforces
.Fl s .
.El
.Sh EXAMPLES
To remove the 'execute' permission bit for all files, but still keep
directories searchable, use:
.Bl -item -offset indent
.It
mount_msdos -m 0644 -M 0755 /dev/wd0e /msdos
.El
.Sh SEE ALSO
.Xr mount 2 ,
.Xr unmount 2 ,

View File

@ -1,4 +1,4 @@
/* $NetBSD: mount_msdos.c,v 1.28 2003/05/03 15:37:08 christos Exp $ */
/* $NetBSD: mount_msdos.c,v 1.29 2003/08/02 11:41:20 jdolecek Exp $ */
/*
* Copyright (c) 1994 Christopher G. Demetriou
@ -36,7 +36,7 @@
#include <sys/cdefs.h>
#ifndef lint
__RCSID("$NetBSD: mount_msdos.c,v 1.28 2003/05/03 15:37:08 christos Exp $");
__RCSID("$NetBSD: mount_msdos.c,v 1.29 2003/08/02 11:41:20 jdolecek Exp $");
#endif /* not lint */
#include <sys/cdefs.h>
@ -67,7 +67,7 @@ static const struct mntopt mopts[] = {
int main __P((int, char *[]));
int mount_msdos __P((int argc, char **argv));
static void usage __P((void));
static void usage __P((void)) __attribute__((__noreturn__));
#ifndef MOUNT_NOMAIN
int
@ -86,13 +86,13 @@ mount_msdos(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, ndir[MAXPATHLEN+1];
mntflags = set_gid = set_uid = set_mask = 0;
mntflags = set_gid = set_uid = set_mask = set_dirmask = 0;
(void)memset(&args, '\0', sizeof(args));
while ((c = getopt(argc, argv, "Gsl9u:g:m:o:")) != -1) {
while ((c = getopt(argc, argv, "Gsl9u:g:m:M:o:")) != -1) {
switch (c) {
case 'G':
args.flags |= MSDOSFSMNT_GEMDOSFS;
@ -118,6 +118,10 @@ mount_msdos(argc, argv)
args.mask = a_mask(optarg);
set_mask = 1;
break;
case 'M':
args.dirmask = a_mask(optarg);
set_dirmask = 1;
break;
case 'o':
getmntopts(optarg, mopts, &mntflags, 0);
break;
@ -131,6 +135,14 @@ mount_msdos(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];
if (dir[0] != '/') {
@ -157,9 +169,13 @@ mount_msdos(argc, argv)
args.uid = sb.st_uid;
if (!set_gid)
args.gid = sb.st_gid;
if (!set_mask)
args.mask = sb.st_mode & (S_IRWXU | S_IRWXG | S_IRWXO);
if (!set_mask) {
args.mask = args.dirmask =
sb.st_mode & (S_IRWXU | S_IRWXG | S_IRWXO);
}
}
args.flags |= MSDOSFSMNT_VERSIONED;
args.version = MSDOSFSMNT_VERSION;
if (mount(MOUNT_MSDOS, dir, mntflags, &args) < 0)
err(1, "%s on %s", dev, dir);
@ -167,8 +183,8 @@ mount_msdos(argc, argv)
if (mntflags & MNT_GETARGS) {
char buf[1024];
(void)snprintb(buf, sizeof(buf), MSDOSFSMNT_BITS, args.flags);
printf("uid=%d, gid=%d, mask=0%o, flags=%s\n", args.uid,
args.gid, args.mask, buf);
printf("uid=%d, gid=%d, mask=0%o, dirmask=0%o, flags=%s\n",
args.uid, args.gid, args.mask, args.dirmask, buf);
}
exit (0);
@ -178,6 +194,6 @@ static void
usage()
{
fprintf(stderr, "usage: mount_msdos [-o options] [-u user] [-g group] [-m mask] bdev dir\n");
fprintf(stderr, "Usage:\nmount_msdos [-o options] [-u user] [-g group] [-m mask] [-M mask] [-G] bdev dir\n");
exit(1);
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: msdosfs_vfsops.c,v 1.7 2003/06/29 22:31:10 fvdl Exp $ */
/* $NetBSD: msdosfs_vfsops.c,v 1.8 2003/08/02 11:41:21 jdolecek Exp $ */
/*-
* Copyright (C) 1994, 1995, 1997 Wolfgang Solfrank.
@ -48,7 +48,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: msdosfs_vfsops.c,v 1.7 2003/06/29 22:31:10 fvdl Exp $");
__KERNEL_RCSID(0, "$NetBSD: msdosfs_vfsops.c,v 1.8 2003/08/02 11:41:21 jdolecek Exp $");
#if defined(_KERNEL_OPT)
#include "opt_quota.h"
@ -146,6 +146,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;
/*
@ -199,10 +200,12 @@ msdosfs_mountroot()
return (error);
}
args.flags = 0;
args.flags = MSDOSFSMNT_VERSIONED;
args.uid = 0;
args.gid = 0;
args.mask = 0777;
args.version = MSDOSFSMNT_VERSION;
args.dirmask = 0777;
if ((error = msdosfs_mountfs(rootvp, mp, p, &args)) != 0) {
mp->mnt_op->vfs_refcount--;
@ -257,12 +260,24 @@ msdosfs_mount(mp, path, data, ndp, p)
args.gid = pmp->pm_gid;
args.mask = pmp->pm_mask;
args.flags = pmp->pm_flags;
args.version = MSDOSFSMNT_VERSION;
args.dirmask = pmp->pm_dirmask;
vfs_showexport(mp, &args.export, &pmp->pm_export);
return copyout(&args, data, sizeof(args));
}
error = copyin(data, &args, sizeof(struct msdosfs_args));
if (error)
return (error);
/*
* If not versioned (i.e. using old mount_msdos(8)), fill in
* the additional structure items with suitable defaults.
*/
if ((args.flags & MSDOSFSMNT_VERSIONED) == 0) {
args.version = 1;
args.dirmask = args.mask;
}
/*
* If updating, check whether changing from read-only to
* read/write; if there is no device name, that's all we do.

View File

@ -1,4 +1,4 @@
/* $NetBSD: msdosfs_vnops.c,v 1.5 2003/06/29 22:31:10 fvdl Exp $ */
/* $NetBSD: msdosfs_vnops.c,v 1.6 2003/08/02 11:41:21 jdolecek Exp $ */
/*-
* Copyright (C) 1994, 1995, 1997 Wolfgang Solfrank.
@ -48,7 +48,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: msdosfs_vnops.c,v 1.5 2003/06/29 22:31:10 fvdl Exp $");
__KERNEL_RCSID(0, "$NetBSD: msdosfs_vnops.c,v 1.6 2003/08/02 11:41:21 jdolecek Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@ -263,7 +263,8 @@ msdosfs_access(v)
mode = S_IRWXU|S_IRWXG|S_IRWXO;
else
mode = S_IRUSR|S_IXUSR|S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH;
return (vaccess(ap->a_vp->v_type, mode & pmp->pm_mask,
return (vaccess(ap->a_vp->v_type,
mode & (vp->v_type == VDIR ? pmp->pm_dirmask : pmp->pm_mask),
pmp->pm_uid, pmp->pm_gid, ap->a_mode, ap->a_cred));
}
@ -308,7 +309,8 @@ msdosfs_getattr(v)
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;

View File

@ -1,4 +1,4 @@
/* $NetBSD: msdosfsmount.h,v 1.2 2003/02/01 06:23:41 thorpej Exp $ */
/* $NetBSD: msdosfsmount.h,v 1.3 2003/08/02 11:41:21 jdolecek Exp $ */
/*-
* Copyright (C) 1994, 1995, 1997 Wolfgang Solfrank.
@ -57,6 +57,11 @@ struct msdosfs_args {
gid_t gid; /* gid that owns msdosfs files */
mode_t mask; /* mask to be applied for msdosfs perms */
int flags; /* see below */
/* Following items added after versioning support */
int version; /* version of the struct */
#define MSDOSFSMNT_VERSION 2
mode_t dirmask; /* v2: mask to be applied for msdosfs perms */
};
/*
@ -66,17 +71,19 @@ struct msdosfs_args {
#define MSDOSFSMNT_LONGNAME 2 /* Force Win'95 long names */
#define MSDOSFSMNT_NOWIN95 4 /* Completely ignore Win95 entries */
#define MSDOSFSMNT_GEMDOSFS 8 /* This is a gemdos-flavour */
#define MSDOSFSMNT_VERSIONED 16 /* Struct is versioned */
/* All flags above: */
#define MSDOSFSMNT_MNTOPT \
(MSDOSFSMNT_SHORTNAME|MSDOSFSMNT_LONGNAME|MSDOSFSMNT_NOWIN95 \
|MSDOSFSMNT_GEMDOSFS)
|MSDOSFSMNT_GEMDOSFS|MSDOSFSMNT_VERSIONED)
#define MSDOSFSMNT_RONLY 0x80000000 /* mounted read-only */
#define MSDOSFSMNT_WAITONFAT 0x40000000 /* mounted synchronous */
#define MSDOSFS_FATMIRROR 0x20000000 /* FAT is mirrored */
#define MSDOSFSMNT_BITS "\177\20" \
"b\00shortname\0b\01longname\0b\02nowin95\0bgemdosfs\0" \
"b\00shortname\0b\01longname\0b\02nowin95\0b\03gemdosfs\0b\04mntversioned\0" \
"b\037ronly\0b\036waitonfat\0b\035fatmirror"
#ifdef _KERNEL
@ -91,7 +98,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_FATsecs; /* actual number of fat sectors */