Date: Sat, 7 Oct 2000 04:33:43 +0200 (CEST) From: mbendiks@eunet.no To: FreeBSD-gnats-submit@freebsd.org Subject: kern/21809: [patches] Remove huge amounts of legacy from msdosfs Message-ID: <200010070233.EAA23978@suiram.freebsd.org>
next in thread | raw e-mail | index | archive | help
>Number: 21809
>Category: kern
>Synopsis: [patches] Removes legacy code from msdosfs
>Confidential: no
>Severity: non-critical
>Priority: low
>Responsible: freebsd-bugs
>State: open
>Quarter:
>Keywords:
>Date-Required:
>Class: change-request
>Submitter-Id: current-users
>Arrival-Date: Fri Oct 06 21:40:01 PDT 2000
>Closed-Date:
>Last-Modified:
>Originator: Marius Bendiksen
>Release: FreeBSD 4.1-RELEASE i386
>Organization:
n/a
>Environment:
not relevant.
>Description:
The msdosfs sources have vast amounts of legacy code, including several
sections that are only built if 0 and atari and not FreeBSD. I think it
is safe to say that we do not need these. As to the msdosfs_root() code
which didn't work, I'd volunteer to write a replacement if someone gets
us boot blocks and such for msdosfs.
The patch also resolves some legacy credential checking.
>How-To-Repeat:
not relevant.
>Fix:
In /sys/msdosfs; diff -u4 output:
--- ./bootsect.h.orig Sat Aug 28 02:48:06 1999
+++ ./bootsect.h Sat Oct 7 04:25:01 2000
@@ -70,24 +70,8 @@
#define BOOTSIG1 0xaa
#define BOOTSIG2 0
#define BOOTSIG3 0
};
-#ifdef atari
-/*
- * The boot sector on a gemdos fs is a little bit different from the msdos fs
- * format. Currently there is no need to declare a seperate structure, the
- * bootsector33 struct will do.
- */
-#if 0
-struct bootsec_atari {
- u_int8_t bsBranch[2]; /* branch inst if auto-boot */
- int8_t bsFiller[6]; /* anything or nothing */
- int8_t bsSerial[3]; /* serial no. for mediachange */
- int8_t bsBPB[19]; /* BIOS parameter block */
- int8_t bsBootCode[482]; /* pad so struct is 512b */
-};
-#endif
-#endif /* atari */
union bootsector {
struct bootsector33 bs33;
struct bootsector50 bs50;
--- ./bpb.h.orig Fri Aug 25 11:03:58 2000
+++ ./bpb.h Sat Oct 7 04:25:01 2000
@@ -80,30 +80,8 @@
u_int16_t bpbBackup; /* backup boot sector */
/* There is a 12 byte filler here, but we ignore it */
};
-#ifdef atari
-/*
- * BPB for gemdos filesystems. Atari leaves the obsolete stuff undefined.
- * Currently there is no need for a separate BPB structure.
- */
-#if 0
-struct bpb_a {
- u_int16_t bpbBytesPerSec; /* bytes per sector */
- u_int8_t bpbSecPerClust; /* sectors per cluster */
- u_int16_t bpbResSectors; /* number of reserved sectors */
- u_int8_t bpbFATs; /* number of FATs */
- u_int16_t bpbRootDirEnts; /* number of root directory entries */
- u_int16_t bpbSectors; /* total number of sectors */
- u_int8_t bpbUseless1; /* meaningless on gemdos fs */
- u_int16_t bpbFATsecs; /* number of sectors per FAT */
- u_int16_t bpbUseless2; /* meaningless for harddisk fs */
- u_int16_t bpbUseless3; /* meaningless for harddisk fs */
- u_int16_t bpbHiddenSecs; /* the TOS-BIOS ignores this */
-};
-#endif
-#endif /* atari */
-
/*
* The following structures represent how the bpb's look on disk. shorts
* and longs are just character arrays of the appropriate length. This is
* because the compiler forces shorts and longs to align on word or
--- ./fat.h.orig Wed Dec 29 05:54:53 1999
+++ ./fat.h Sat Oct 7 04:25:01 2000
@@ -70,13 +70,8 @@
* Reference says if the maximum cluster number in a filesystem is greater
* than 4078 ((CLUST_RSRVS - CLUST_FIRST) & FAT12_MASK) then we've got a
* 16 bit fat filesystem. While mounting, the result of this test is stored
* in pm_fatentrysize.
- * GEMDOS-flavour (atari):
- * If the filesystem is on floppy we've got a 12 bit fat filesystem, otherwise
- * 16 bit. We check the d_type field in the disklabel struct while mounting
- * and store the result in the pm_fatentrysize. Note that this kind of
- * detection gets flakey when mounting a vnd-device.
*/
#define FAT12(pmp) (pmp->pm_fatmask == FAT12_MASK)
#define FAT16(pmp) (pmp->pm_fatmask == FAT16_MASK)
#define FAT32(pmp) (pmp->pm_fatmask == FAT32_MASK)
--- ./msdosfs_vfsops.c.orig Thu Jun 29 03:12:47 2000
+++ ./msdosfs_vfsops.c Sat Oct 7 04:25:01 2000
@@ -123,16 +123,8 @@
bcopy(argp->ul, pmp->pm_ul, sizeof(pmp->pm_ul));
bcopy(argp->lu, pmp->pm_lu, sizeof(pmp->pm_lu));
}
-#ifndef __FreeBSD__
- /*
- * GEMDOS knows nothing (yet) about win95
- */
- if (pmp->pm_flags & MSDOSFSMNT_GEMDOSFS)
- pmp->pm_flags |= MSDOSFSMNT_NOWIN95;
-#endif
-
if (pmp->pm_flags & MSDOSFSMNT_NOWIN95)
pmp->pm_flags |= MSDOSFSMNT_SHORTNAME;
else if (!(pmp->pm_flags &
(MSDOSFSMNT_SHORTNAME | MSDOSFSMNT_LONGNAME))) {
@@ -154,69 +146,8 @@
}
return 0;
}
-#ifndef __FreeBSD__
-int
-msdosfs_mountroot()
-{
- register struct mount *mp;
- struct proc *p = curproc; /* XXX */
- size_t size;
- int error;
- struct msdosfs_args args;
-
- if (root_device->dv_class != DV_DISK)
- return (ENODEV);
-
- /*
- * Get vnodes for swapdev and rootdev.
- */
- if (bdevvp(rootdev, &rootvp))
- panic("msdosfs_mountroot: can't setup rootvp");
-
- mp = malloc((u_long)sizeof(struct mount), M_MOUNT, M_WAITOK);
- bzero((char *)mp, (u_long)sizeof(struct mount));
- mp->mnt_op = &msdosfs_vfsops;
- mp->mnt_flag = 0;
- LIST_INIT(&mp->mnt_vnodelist);
-
- args.flags = 0;
- args.uid = 0;
- args.gid = 0;
- args.mask = 0777;
-
- if ((error = mountmsdosfs(rootvp, mp, p, &args)) != 0) {
- free(mp, M_MOUNT);
- return (error);
- }
-
- if ((error = update_mp(mp, &args)) != 0) {
- (void)msdosfs_unmount(mp, 0, p);
- free(mp, M_MOUNT);
- return (error);
- }
-
- if ((error = vfs_lock(mp)) != 0) {
- (void)msdosfs_unmount(mp, 0, p);
- free(mp, M_MOUNT);
- return (error);
- }
-
- TAILQ_INSERT_TAIL(&mountlist, mp, mnt_list);
- mp->mnt_vnodecovered = NULLVP;
- (void) copystr("/", mp->mnt_stat.f_mntonname, MNAMELEN - 1,
- &size);
- bzero(mp->mnt_stat.f_mntonname + size, MNAMELEN - size);
- (void) copystr(ROOTNAME, mp->mnt_stat.f_mntfromname, MNAMELEN - 1,
- &size);
- bzero(mp->mnt_stat.f_mntfromname + size, MNAMELEN - size);
- (void)msdosfs_statfs(mp, &mp->mnt_stat, p);
- vfs_unlock(mp);
- return (0);
-}
-#endif
-
/*
* mp - path - addr in user space of mount point (ie /usr or whatever)
* data - addr in user space of mount params including the name of the block
* special file to treat as a filesystem.
@@ -236,8 +167,12 @@
size_t size;
int error, flags;
mode_t accessmode;
+ /* Check to see if we are mounting root */
+ if (mp->mnt_flag & MNT_ROOTFS)
+ panic("msdosfs_mount: root support yanked");
+
error = copyin(data, (caddr_t)&args, sizeof(struct msdosfs_args));
if (error)
return (error);
if (args.magic != MSDOSFS_ARGSMAGIC)
@@ -261,12 +196,12 @@
if (error)
return (error);
if ((pmp->pm_flags & MSDOSFSMNT_RONLY) && (mp->mnt_kern_flag & MNTK_WANTRDWR)) {
/*
- * If upgrade to read-write by non-root, then verify
+ * If upgrade to read-write by regular user, then verify
* that user has necessary permissions on the device.
*/
- if (p->p_ucred->cr_uid != 0) {
+ if (suser(p)) {
devvp = pmp->pm_devvp;
vn_lock(devvp, LK_EXCLUSIVE | LK_RETRY, p);
error = VOP_ACCESS(devvp, VREAD | VWRITE,
p->p_ucred, p);
@@ -278,9 +213,9 @@
}
pmp->pm_flags &= ~MSDOSFSMNT_RONLY;
}
if (args.fspec == 0) {
-#ifdef __notyet__ /* doesn't work correctly with current mountd XXX */
+#ifdef __notyet__ /* doesn't work correctly with current mountd XXX */
if (args.flags & MSDOSFSMNT_MNTOPT) {
pmp->pm_flags &= ~MSDOSFSMNT_MNTOPT;
pmp->pm_flags |= args.flags & MSDOSFSMNT_MNTOPT;
if (pmp->pm_flags & MSDOSFSMNT_NOWIN95)
@@ -311,9 +246,9 @@
/*
* If mount by non-root, then verify that user has necessary
* permissions on the device.
*/
- if (p->p_ucred->cr_uid != 0) {
+ if (suser(p)) {
accessmode = VREAD;
if ((mp->mnt_flag & MNT_RDONLY) == 0)
accessmode |= VWRITE;
vn_lock(devvp, LK_EXCLUSIVE | LK_RETRY, p);
@@ -367,12 +302,8 @@
{
struct msdosfsmount *pmp;
struct buf *bp;
dev_t dev = devvp->v_rdev;
-#ifndef __FreeBSD__
- struct partinfo dpart;
- int bsize = 0, dtype = 0, tmp;
-#endif
union bootsector *bsp;
struct byte_bpb33 *b33;
struct byte_bpb50 *b50;
struct byte_bpb710 *b710;
@@ -406,34 +337,8 @@
bp = NULL; /* both used in error_exit */
pmp = NULL;
-#ifndef __FreeBSD__
- if (argp->flags & MSDOSFSMNT_GEMDOSFS) {
- /*
- * We need the disklabel to calculate the size of a FAT entry
- * later on. Also make sure the partition contains a filesystem
- * of type FS_MSDOS. This doesn't work for floppies, so we have
- * to check for them too.
- *
- * At least some parts of the msdos fs driver seem to assume
- * that the size of a disk block will always be 512 bytes.
- * Let's check it...
- */
- error = VOP_IOCTL(devvp, DIOCGPART, (caddr_t)&dpart,
- FREAD, NOCRED, p);
- if (error)
- goto error_exit;
- tmp = dpart.part->p_fstype;
- dtype = dpart.disklab->d_type;
- bsize = dpart.disklab->d_secsize;
- if (bsize != 512 || (dtype!=DTYPE_FLOPPY && tmp!=FS_MSDOS)) {
- error = EINVAL;
- goto error_exit;
- }
- }
-#endif
-
/*
* Read the boot sector of the filesystem, and then check the
* boot signature. If not a dos boot sector then error out.
*
@@ -447,19 +352,13 @@
b33 = (struct byte_bpb33 *)bsp->bs33.bsBPB;
b50 = (struct byte_bpb50 *)bsp->bs50.bsBPB;
b710 = (struct byte_bpb710 *)bsp->bs710.bsPBP;
-#ifndef __FreeBSD__
- if (!(argp->flags & MSDOSFSMNT_GEMDOSFS)) {
-#endif
#ifndef MSDOSFS_NOCHECKSIG
- if (bsp->bs50.bsBootSectSig0 != BOOTSIG0
- || bsp->bs50.bsBootSectSig1 != BOOTSIG1) {
- error = EINVAL;
- goto error_exit;
- }
-#endif
-#ifndef __FreeBSD__
+ if (bsp->bs50.bsBootSectSig0 != BOOTSIG0
+ || bsp->bs50.bsBootSectSig1 != BOOTSIG1) {
+ error = EINVAL;
+ goto error_exit;
}
#endif
pmp = malloc(sizeof *pmp, M_MSDOSFSMNT, M_WAITOK);
@@ -484,25 +383,19 @@
/* calculate the ratio of sector size to DEV_BSIZE */
pmp->pm_BlkPerSec = pmp->pm_BytesPerSec / DEV_BSIZE;
-#ifndef __FreeBSD__
- if (!(argp->flags & MSDOSFSMNT_GEMDOSFS)) {
-#endif
- /* XXX - We should probably check more values here */
- if (!pmp->pm_BytesPerSec || !SecPerClust
- || !pmp->pm_Heads || pmp->pm_Heads > 255
+ /* XXX - We should probably check more values here */
+ if (!pmp->pm_BytesPerSec || !SecPerClust
+ || !pmp->pm_Heads || pmp->pm_Heads > 255
#ifdef PC98
- || !pmp->pm_SecPerTrack || pmp->pm_SecPerTrack > 255) {
+ || !pmp->pm_SecPerTrack || pmp->pm_SecPerTrack > 255) {
#else
- || !pmp->pm_SecPerTrack || pmp->pm_SecPerTrack > 63) {
+ || !pmp->pm_SecPerTrack || pmp->pm_SecPerTrack > 63) {
#endif
- error = EINVAL;
- goto error_exit;
- }
-#ifndef __FreeBSD__
+ error = EINVAL;
+ goto error_exit;
}
-#endif
if (pmp->pm_Sectors == 0) {
pmp->pm_HiddenSects = getulong(b50->bpbHiddenSecs);
pmp->pm_HugeSectors = getulong(b50->bpbHugeSectors);
@@ -583,24 +476,8 @@
pmp->pm_maxcluster = (pmp->pm_HugeSectors - pmp->pm_firstcluster) /
SecPerClust + 1;
pmp->pm_fatsize = pmp->pm_FATsecs * DEV_BSIZE; /* XXX not used? */
-#ifndef __FreeBSD__
- if (argp->flags & MSDOSFSMNT_GEMDOSFS) {
- if ((pmp->pm_maxcluster <= (0xff0 - 2))
- && ((dtype == DTYPE_FLOPPY) || ((dtype == DTYPE_VNODE)
- && ((pmp->pm_Heads == 1) || (pmp->pm_Heads == 2))))
- ) {
- pmp->pm_fatmask = FAT12_MASK;
- pmp->pm_fatmult = 3;
- pmp->pm_fatdiv = 2;
- } else {
- pmp->pm_fatmask = FAT16_MASK;
- pmp->pm_fatmult = 2;
- pmp->pm_fatdiv = 1;
- }
- } else
-#endif
if (pmp->pm_fatmask == 0) {
if (pmp->pm_maxcluster
<= ((CLUST_RSRVD - CLUST_FIRST) & FAT12_MASK)) {
/*
--- ./msdosfs_vnops.c.orig Sat Oct 7 04:18:38 2000
+++ ./msdosfs_vnops.c Sat Oct 7 04:26:26 2000
@@ -415,9 +415,9 @@
*
* An exception with regards to the SF_SETTABLE bits, is
* SF_IMMUTABLE, which we map to ATTR_SYSTEM.
*/
- if (cred->cr_uid != 0) {
+ if (suser(ap->a_p)) {
if (vap->va_flags & (SF_SETTABLE^SF_IMMUTABLE))
return EPERM;
if (vap->va_flags & SF_IMMUTABLE)
dep->de_Attributes |= ATTR_SYSTEM;
--- ./msdosfsmount.h.orig Fri Aug 25 11:03:58 2000
+++ ./msdosfsmount.h Sat Oct 7 04:25:01 2000
@@ -226,18 +226,15 @@
*/
#define MSDOSFSMNT_SHORTNAME 1 /* Force old DOS short names only */
#define MSDOSFSMNT_LONGNAME 2 /* Force Win'95 long names */
#define MSDOSFSMNT_NOWIN95 4 /* Completely ignore Win95 entries */
-#ifndef __FreeBSD__
-#define MSDOSFSMNT_GEMDOSFS 8 /* This is a gemdos-flavour */
-#endif
#define MSDOSFSMNT_U2WTABLE 0x10 /* Local->Unicode and local<->DOS */
/* tables loaded */
#define MSDOSFSMNT_ULTABLE 0x20 /* Local upper<->lower table loaded */
/* All flags above: */
#define MSDOSFSMNT_MNTOPT \
(MSDOSFSMNT_SHORTNAME|MSDOSFSMNT_LONGNAME|MSDOSFSMNT_NOWIN95 \
- /*|MSDOSFSMNT_GEMDOSFS*/|MSDOSFSMNT_U2WTABLE|MSDOSFSMNT_ULTABLE)
+ |MSDOSFSMNT_U2WTABLE|MSDOSFSMNT_ULTABLE)
#define MSDOSFSMNT_RONLY 0x80000000 /* mounted read-only */
#define MSDOSFSMNT_WAITONFAT 0x40000000 /* mounted synchronous */
#define MSDOSFS_FATMIRROR 0x20000000 /* FAT is mirrored */
>Release-Note:
>Audit-Trail:
>Unformatted:
To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-bugs" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200010070233.EAA23978>
