1995-03-08 04:49:37 +03:00
|
|
|
/* $NetBSD: msdosfs_vfsops.c,v 1.27 1995/03/08 01:49:37 cgd Exp $ */
|
1994-07-19 01:38:08 +04:00
|
|
|
|
|
|
|
/*-
|
|
|
|
* Copyright (C) 1994 Wolfgang Solfrank.
|
|
|
|
* Copyright (C) 1994 TooLs GmbH.
|
|
|
|
* All rights reserved.
|
1994-08-21 22:43:49 +04:00
|
|
|
* Original code by Paul Popelka (paulp@uts.amdahl.com) (see below).
|
1994-07-19 01:38:08 +04:00
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed by TooLs GmbH.
|
|
|
|
* 4. The name of TooLs GmbH may not be used to endorse or promote products
|
|
|
|
* derived from this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR
|
|
|
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
|
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
|
|
* IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
|
|
|
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
|
|
|
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
|
|
|
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
|
|
|
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
|
|
|
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
1993-08-13 15:35:13 +04:00
|
|
|
/*
|
|
|
|
* Written by Paul Popelka (paulp@uts.amdahl.com)
|
|
|
|
*
|
|
|
|
* You can do anything you want with this software, just don't say you wrote
|
|
|
|
* it, and don't remove this notice.
|
|
|
|
*
|
|
|
|
* This software is provided "as is".
|
|
|
|
*
|
|
|
|
* The author supplies this software to be publicly redistributed on the
|
|
|
|
* understanding that the author is not responsible for the correct
|
|
|
|
* functioning of this software in any circumstances and is not liable for
|
|
|
|
* any damages caused by this software.
|
|
|
|
*
|
|
|
|
* October 1992
|
|
|
|
*/
|
|
|
|
|
1993-12-18 03:50:51 +03:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/namei.h>
|
|
|
|
#include <sys/proc.h>
|
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/vnode.h>
|
|
|
|
#include <miscfs/specfs/specdev.h> /* XXX */ /* defines v_rdev */
|
|
|
|
#include <sys/mount.h>
|
|
|
|
#include <sys/buf.h>
|
|
|
|
#include <sys/file.h>
|
1994-09-28 14:31:23 +03:00
|
|
|
#include <sys/disklabel.h>
|
|
|
|
#include <sys/ioctl.h>
|
1993-12-18 03:50:51 +03:00
|
|
|
#include <sys/malloc.h>
|
1993-08-13 15:35:13 +04:00
|
|
|
|
1993-12-18 03:50:51 +03:00
|
|
|
#include <msdosfs/bpb.h>
|
|
|
|
#include <msdosfs/bootsect.h>
|
|
|
|
#include <msdosfs/direntry.h>
|
|
|
|
#include <msdosfs/denode.h>
|
|
|
|
#include <msdosfs/msdosfsmount.h>
|
|
|
|
#include <msdosfs/fat.h>
|
1993-08-13 15:35:13 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
msdosfs_mount(mp, path, data, ndp, p)
|
|
|
|
struct mount *mp;
|
|
|
|
char *path;
|
|
|
|
caddr_t data;
|
|
|
|
struct nameidata *ndp;
|
|
|
|
struct proc *p;
|
|
|
|
{
|
1994-04-07 11:30:23 +04:00
|
|
|
struct vnode *devvp; /* vnode for blk device to mount */
|
|
|
|
struct msdosfs_args args; /* will hold data from mount request */
|
|
|
|
struct msdosfsmount *pmp; /* msdosfs specific mount control block */
|
1995-03-08 04:49:37 +03:00
|
|
|
u_long size;
|
1994-09-28 14:31:23 +03:00
|
|
|
int error, flags;
|
1994-12-14 19:33:18 +03:00
|
|
|
mode_t accessmode;
|
1993-08-13 15:35:13 +04:00
|
|
|
|
1994-09-28 14:31:23 +03:00
|
|
|
if (error = copyin(data, (caddr_t)&args, sizeof(struct msdosfs_args)))
|
|
|
|
return (error);
|
1993-08-13 15:35:13 +04:00
|
|
|
/*
|
1994-12-14 19:33:18 +03:00
|
|
|
* If updating, check whether changing from read-only to
|
|
|
|
* read/write; if there is no device name, that's all we do.
|
1993-08-13 15:35:13 +04:00
|
|
|
*/
|
|
|
|
if (mp->mnt_flag & MNT_UPDATE) {
|
1994-09-22 06:34:49 +04:00
|
|
|
pmp = VFSTOMSDOSFS(mp);
|
1994-07-17 01:32:06 +04:00
|
|
|
error = 0;
|
|
|
|
if (pmp->pm_ronly == 0 && (mp->mnt_flag & MNT_RDONLY)) {
|
|
|
|
flags = WRITECLOSE;
|
|
|
|
if (mp->mnt_flag & MNT_FORCE)
|
|
|
|
flags |= FORCECLOSE;
|
|
|
|
if (vfs_busy(mp))
|
1994-09-28 14:31:23 +03:00
|
|
|
return (EBUSY);
|
1994-07-17 01:32:06 +04:00
|
|
|
error = vflush(mp, NULLVP, flags);
|
|
|
|
vfs_unbusy(mp);
|
|
|
|
}
|
|
|
|
if (!error && (mp->mnt_flag & MNT_RELOAD))
|
|
|
|
/* not yet implemented */
|
1994-09-28 14:31:23 +03:00
|
|
|
error = EOPNOTSUPP;
|
1994-07-17 01:32:06 +04:00
|
|
|
if (error)
|
1994-09-28 14:31:23 +03:00
|
|
|
return (error);
|
1994-12-14 19:33:18 +03:00
|
|
|
if (pmp->pm_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) {
|
|
|
|
devvp = pmp->pm_devvp;
|
|
|
|
VOP_LOCK(devvp);
|
|
|
|
if (error = VOP_ACCESS(devvp, VREAD | VWRITE,
|
|
|
|
p->p_ucred, p)) {
|
|
|
|
VOP_UNLOCK(devvp);
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
VOP_UNLOCK(devvp);
|
|
|
|
}
|
1993-08-13 15:35:13 +04:00
|
|
|
pmp->pm_ronly = 0;
|
1994-12-14 19:33:18 +03:00
|
|
|
}
|
1994-07-17 01:32:06 +04:00
|
|
|
if (args.fspec == 0) {
|
|
|
|
/*
|
|
|
|
* Process export requests.
|
|
|
|
*/
|
1994-09-28 14:31:23 +03:00
|
|
|
return (vfs_export(mp, &pmp->pm_export, &args.export));
|
1994-07-17 01:32:06 +04:00
|
|
|
}
|
1993-08-13 15:35:13 +04:00
|
|
|
}
|
|
|
|
/*
|
1994-09-28 14:31:23 +03:00
|
|
|
* Not an update, or updating the name: look up the name
|
1994-12-14 19:33:18 +03:00
|
|
|
* and verify that it refers to a sensible block device.
|
1993-08-13 15:35:13 +04:00
|
|
|
*/
|
1994-07-17 01:32:06 +04:00
|
|
|
NDINIT(ndp, LOOKUP, FOLLOW, UIO_USERSPACE, args.fspec, p);
|
1994-12-14 19:33:18 +03:00
|
|
|
if (error = namei(ndp))
|
1994-09-28 14:31:23 +03:00
|
|
|
return (error);
|
1993-08-13 15:35:13 +04:00
|
|
|
devvp = ndp->ni_vp;
|
1994-12-14 19:33:18 +03:00
|
|
|
|
1993-08-13 15:35:13 +04:00
|
|
|
if (devvp->v_type != VBLK) {
|
1994-07-17 01:32:06 +04:00
|
|
|
vrele(devvp);
|
1994-09-28 14:31:23 +03:00
|
|
|
return (ENOTBLK);
|
1993-08-13 15:35:13 +04:00
|
|
|
}
|
|
|
|
if (major(devvp->v_rdev) >= nblkdev) {
|
|
|
|
vrele(devvp);
|
1994-09-28 14:31:23 +03:00
|
|
|
return (ENXIO);
|
1993-08-13 15:35:13 +04:00
|
|
|
}
|
|
|
|
/*
|
1994-12-14 19:33:18 +03:00
|
|
|
* If mount by non-root, then verify that user has necessary
|
|
|
|
* permissions on the device.
|
1993-08-13 15:35:13 +04:00
|
|
|
*/
|
1994-12-14 19:33:18 +03:00
|
|
|
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 = msdosfs_mountfs(devvp, mp, p);
|
|
|
|
else {
|
1993-08-13 15:35:13 +04:00
|
|
|
if (devvp != pmp->pm_devvp)
|
1994-12-14 19:33:18 +03:00
|
|
|
error = EINVAL; /* needs translation */
|
1993-08-13 15:35:13 +04:00
|
|
|
else
|
|
|
|
vrele(devvp);
|
1994-12-14 19:33:18 +03:00
|
|
|
}
|
1993-08-13 15:35:13 +04:00
|
|
|
if (error) {
|
|
|
|
vrele(devvp);
|
1994-09-28 14:31:23 +03:00
|
|
|
return (error);
|
1993-08-13 15:35:13 +04:00
|
|
|
}
|
1994-09-28 14:31:23 +03:00
|
|
|
pmp = VFSTOMSDOSFS(mp);
|
|
|
|
pmp->pm_gid = args.gid;
|
|
|
|
pmp->pm_uid = args.uid;
|
|
|
|
pmp->pm_mask = args.mask;
|
1995-01-18 12:14:37 +03:00
|
|
|
(void) copyinstr(path, mp->mnt_stat.f_mntonname, MNAMELEN - 1, &size);
|
|
|
|
bzero(mp->mnt_stat.f_mntonname + size, MNAMELEN - size);
|
1994-09-28 14:31:23 +03:00
|
|
|
(void) copyinstr(args.fspec, mp->mnt_stat.f_mntfromname, MNAMELEN - 1,
|
|
|
|
&size);
|
|
|
|
bzero(mp->mnt_stat.f_mntfromname + size, MNAMELEN - size);
|
1994-07-19 01:38:08 +04:00
|
|
|
#ifdef MSDOSFS_DEBUG
|
1993-08-13 15:35:13 +04:00
|
|
|
printf("msdosfs_mount(): mp %x, pmp %x, inusemap %x\n", mp, pmp, pmp->pm_inusemap);
|
1994-07-19 01:38:08 +04:00
|
|
|
#endif
|
1994-09-28 14:31:23 +03:00
|
|
|
return (0);
|
1993-08-13 15:35:13 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
1994-09-28 14:31:23 +03:00
|
|
|
msdosfs_mountfs(devvp, mp, p)
|
1993-08-13 15:35:13 +04:00
|
|
|
struct vnode *devvp;
|
|
|
|
struct mount *mp;
|
|
|
|
struct proc *p;
|
|
|
|
{
|
1994-09-28 14:31:23 +03:00
|
|
|
struct msdosfsmount *pmp;
|
|
|
|
struct buf *bp;
|
1993-08-13 15:35:13 +04:00
|
|
|
dev_t dev = devvp->v_rdev;
|
1994-09-28 14:31:23 +03:00
|
|
|
struct partinfo dpart;
|
1993-08-13 15:35:13 +04:00
|
|
|
union bootsector *bsp;
|
|
|
|
struct byte_bpb33 *b33;
|
|
|
|
struct byte_bpb50 *b50;
|
1994-09-28 14:31:23 +03:00
|
|
|
int bpc;
|
|
|
|
int bit;
|
|
|
|
int error, i, size;
|
|
|
|
int ronly;
|
|
|
|
extern struct vnode *rootvp;
|
1993-08-13 15:35:13 +04:00
|
|
|
|
|
|
|
/*
|
1994-09-28 14:31:23 +03:00
|
|
|
* Disallow multiple mounts of the same device.
|
|
|
|
* Disallow mounting of a device that is currently in use
|
|
|
|
* (except for root, which might share swap device for miniroot).
|
|
|
|
* Flush out any old buffers remaining from a previous use.
|
1993-08-13 15:35:13 +04:00
|
|
|
*/
|
1994-07-17 01:32:06 +04:00
|
|
|
if (error = vfs_mountedon(devvp))
|
1994-09-28 14:31:23 +03:00
|
|
|
return (error);
|
|
|
|
if (vcount(devvp) > 1 && devvp != rootvp)
|
|
|
|
return (EBUSY);
|
1994-07-17 01:32:06 +04:00
|
|
|
if (error = vinvalbuf(devvp, V_SAVE, p->p_ucred, p, 0, 0))
|
1994-09-28 14:31:23 +03:00
|
|
|
return (error);
|
1993-08-13 15:35:13 +04:00
|
|
|
|
1994-09-28 14:31:23 +03:00
|
|
|
ronly = (mp->mnt_flag & MNT_RDONLY) != 0;
|
|
|
|
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)
|
|
|
|
size = DEV_BSIZE;
|
|
|
|
else
|
|
|
|
size = dpart.disklab->d_secsize;
|
1993-08-13 15:35:13 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Read the boot sector of the filesystem, and then check the boot
|
|
|
|
* signature. If not a dos boot sector then error out. We could
|
|
|
|
* also add some checking on the bsOemName field. So far I've seen
|
|
|
|
* the following values: "IBM 3.3" "MSDOS3.3" "MSDOS5.0"
|
|
|
|
*/
|
1994-09-28 14:31:23 +03:00
|
|
|
bp = NULL;
|
|
|
|
pmp = NULL;
|
|
|
|
if (error = bread(devvp, 0, 512, NOCRED, &bp))
|
1993-08-13 15:35:13 +04:00
|
|
|
goto error_exit;
|
1994-09-28 14:31:23 +03:00
|
|
|
bp->b_flags |= B_AGE;
|
|
|
|
bsp = (union bootsector *)bp->b_data;
|
|
|
|
b33 = (struct byte_bpb33 *)bsp->bs33.bsBPB;
|
|
|
|
b50 = (struct byte_bpb50 *)bsp->bs50.bsBPB;
|
1993-08-13 15:35:13 +04:00
|
|
|
#ifdef MSDOSFS_CHECKSIG
|
|
|
|
if (bsp->bs50.bsBootSectSig != BOOTSIG) {
|
|
|
|
error = EINVAL;
|
|
|
|
goto error_exit;
|
|
|
|
}
|
|
|
|
#endif
|
1993-12-01 13:35:21 +03:00
|
|
|
if ( bsp->bs50.bsJump[0] != 0xe9 &&
|
|
|
|
(bsp->bs50.bsJump[0] != 0xeb || bsp->bs50.bsJump[2] != 0x90)) {
|
|
|
|
error = EINVAL;
|
|
|
|
goto error_exit;
|
|
|
|
}
|
1993-08-13 15:35:13 +04:00
|
|
|
|
|
|
|
pmp = malloc(sizeof *pmp, M_MSDOSFSMNT, M_WAITOK);
|
1994-07-17 01:32:06 +04:00
|
|
|
bzero((caddr_t)pmp, sizeof *pmp);
|
1993-08-13 15:35:13 +04:00
|
|
|
pmp->pm_mountp = mp;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Compute several useful quantities from the bpb in the
|
|
|
|
* bootsector. Copy in the dos 5 variant of the bpb then fix up
|
|
|
|
* the fields that are different between dos 5 and dos 3.3.
|
|
|
|
*/
|
|
|
|
pmp->pm_BytesPerSec = getushort(b50->bpbBytesPerSec);
|
|
|
|
pmp->pm_SectPerClust = b50->bpbSecPerClust;
|
|
|
|
pmp->pm_ResSectors = getushort(b50->bpbResSectors);
|
|
|
|
pmp->pm_FATs = b50->bpbFATs;
|
|
|
|
pmp->pm_RootDirEnts = getushort(b50->bpbRootDirEnts);
|
|
|
|
pmp->pm_Sectors = getushort(b50->bpbSectors);
|
|
|
|
pmp->pm_Media = b50->bpbMedia;
|
|
|
|
pmp->pm_FATsecs = getushort(b50->bpbFATsecs);
|
|
|
|
pmp->pm_SecPerTrack = getushort(b50->bpbSecPerTrack);
|
|
|
|
pmp->pm_Heads = getushort(b50->bpbHeads);
|
1993-12-01 13:35:21 +03:00
|
|
|
|
|
|
|
/* XXX - We should probably check more values here */
|
|
|
|
if (!pmp->pm_BytesPerSec || !pmp->pm_SectPerClust ||
|
|
|
|
!pmp->pm_Heads || pmp->pm_Heads > 255 ||
|
|
|
|
!pmp->pm_SecPerTrack || pmp->pm_SecPerTrack > 63) {
|
|
|
|
error = EINVAL;
|
|
|
|
goto error_exit;
|
|
|
|
}
|
|
|
|
|
1993-08-13 15:35:13 +04:00
|
|
|
if (pmp->pm_Sectors == 0) {
|
|
|
|
pmp->pm_HiddenSects = getulong(b50->bpbHiddenSecs);
|
|
|
|
pmp->pm_HugeSectors = getulong(b50->bpbHugeSectors);
|
1994-07-17 01:32:06 +04:00
|
|
|
} else {
|
1993-08-13 15:35:13 +04:00
|
|
|
pmp->pm_HiddenSects = getushort(b33->bpbHiddenSecs);
|
|
|
|
pmp->pm_HugeSectors = pmp->pm_Sectors;
|
|
|
|
}
|
|
|
|
pmp->pm_fatblk = pmp->pm_ResSectors;
|
|
|
|
pmp->pm_rootdirblk = pmp->pm_fatblk +
|
|
|
|
(pmp->pm_FATs * pmp->pm_FATsecs);
|
|
|
|
pmp->pm_rootdirsize = (pmp->pm_RootDirEnts * sizeof(struct direntry))
|
|
|
|
/
|
|
|
|
pmp->pm_BytesPerSec;/* in sectors */
|
|
|
|
pmp->pm_firstcluster = pmp->pm_rootdirblk + pmp->pm_rootdirsize;
|
|
|
|
pmp->pm_nmbrofclusters = (pmp->pm_HugeSectors - pmp->pm_firstcluster) /
|
|
|
|
pmp->pm_SectPerClust;
|
|
|
|
pmp->pm_maxcluster = pmp->pm_nmbrofclusters + 1;
|
|
|
|
pmp->pm_fatsize = pmp->pm_FATsecs * pmp->pm_BytesPerSec;
|
|
|
|
if (FAT12(pmp))
|
|
|
|
/*
|
|
|
|
* This will usually be a floppy disk. This size makes sure
|
|
|
|
* that one fat entry will not be split across multiple
|
|
|
|
* blocks.
|
|
|
|
*/
|
|
|
|
pmp->pm_fatblocksize = 3 * pmp->pm_BytesPerSec;
|
|
|
|
else
|
|
|
|
/*
|
|
|
|
* This will usually be a hard disk. Reading or writing one
|
|
|
|
* block should be quite fast.
|
|
|
|
*/
|
|
|
|
pmp->pm_fatblocksize = MAXBSIZE;
|
|
|
|
pmp->pm_fatblocksec = pmp->pm_fatblocksize / pmp->pm_BytesPerSec;
|
|
|
|
|
|
|
|
if ((pmp->pm_rootdirsize % pmp->pm_SectPerClust) != 0)
|
|
|
|
printf("mountmsdosfs(): root directory is not a multiple of the clustersize in length\n");
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Compute mask and shift value for isolating cluster relative byte
|
|
|
|
* offsets and cluster numbers from a file offset.
|
|
|
|
*/
|
|
|
|
bpc = pmp->pm_SectPerClust * pmp->pm_BytesPerSec;
|
|
|
|
pmp->pm_bpcluster = bpc;
|
|
|
|
pmp->pm_depclust = bpc / sizeof(struct direntry);
|
|
|
|
pmp->pm_crbomask = bpc - 1;
|
|
|
|
if (bpc == 0) {
|
|
|
|
error = EINVAL;
|
|
|
|
goto error_exit;
|
|
|
|
}
|
|
|
|
bit = 1;
|
|
|
|
for (i = 0; i < 32; i++) {
|
|
|
|
if (bit & bpc) {
|
|
|
|
if (bit ^ bpc) {
|
|
|
|
error = EINVAL;
|
|
|
|
goto error_exit;
|
|
|
|
}
|
|
|
|
pmp->pm_cnshift = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
bit <<= 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
pmp->pm_brbomask = 0x01ff; /* 512 byte blocks only (so far) */
|
|
|
|
pmp->pm_bnshift = 9; /* shift right 9 bits to get bn */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Release the bootsector buffer.
|
|
|
|
*/
|
1994-09-28 14:31:23 +03:00
|
|
|
brelse(bp);
|
|
|
|
bp = NULL;
|
1993-08-13 15:35:13 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Allocate memory for the bitmap of allocated clusters, and then
|
|
|
|
* fill it in.
|
|
|
|
*/
|
1994-07-19 01:38:08 +04:00
|
|
|
pmp->pm_inusemap = malloc(((pmp->pm_maxcluster + N_INUSEBITS - 1)
|
|
|
|
/ N_INUSEBITS)
|
|
|
|
* sizeof(*pmp->pm_inusemap),
|
|
|
|
M_MSDOSFSFAT, M_WAITOK);
|
1993-08-13 15:35:13 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* fillinusemap() needs pm_devvp.
|
|
|
|
*/
|
|
|
|
pmp->pm_dev = dev;
|
|
|
|
pmp->pm_devvp = devvp;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Have the inuse map filled in.
|
|
|
|
*/
|
1994-09-28 14:31:23 +03:00
|
|
|
if (error = fillinusemap(pmp))
|
1993-08-13 15:35:13 +04:00
|
|
|
goto error_exit;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If they want fat updates to be synchronous then let them suffer
|
|
|
|
* the performance degradation in exchange for the on disk copy of
|
|
|
|
* the fat being correct just about all the time. I suppose this
|
|
|
|
* would be a good thing to turn on if the kernel is still flakey.
|
|
|
|
*/
|
|
|
|
pmp->pm_waitonfat = mp->mnt_flag & MNT_SYNCHRONOUS;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Finish up.
|
|
|
|
*/
|
|
|
|
pmp->pm_ronly = ronly;
|
|
|
|
if (ronly == 0)
|
|
|
|
pmp->pm_fmod = 1;
|
1994-09-28 14:31:23 +03:00
|
|
|
mp->mnt_data = (qaddr_t)pmp;
|
1994-04-14 08:05:45 +04:00
|
|
|
mp->mnt_stat.f_fsid.val[0] = (long)dev;
|
1994-04-23 11:54:38 +04:00
|
|
|
mp->mnt_stat.f_fsid.val[1] = makefstype(MOUNT_MSDOS);
|
1993-08-13 15:35:13 +04:00
|
|
|
mp->mnt_flag |= MNT_LOCAL;
|
1994-07-19 01:38:08 +04:00
|
|
|
#ifdef QUOTA
|
1993-08-13 15:35:13 +04:00
|
|
|
/*
|
|
|
|
* If we ever do quotas for DOS filesystems this would be a place
|
|
|
|
* to fill in the info in the msdosfsmount structure. You dolt,
|
|
|
|
* quotas on dos filesystems make no sense because files have no
|
|
|
|
* owners on dos filesystems. of course there is some empty space
|
|
|
|
* in the directory entry where we could put uid's and gid's.
|
|
|
|
*/
|
1994-07-19 01:38:08 +04:00
|
|
|
#endif
|
1993-08-13 15:35:13 +04:00
|
|
|
devvp->v_specflags |= SI_MOUNTEDON;
|
|
|
|
|
1994-09-28 14:31:23 +03:00
|
|
|
return (0);
|
1993-08-13 15:35:13 +04:00
|
|
|
|
|
|
|
error_exit:;
|
1994-09-28 14:31:23 +03:00
|
|
|
if (bp)
|
|
|
|
brelse(bp);
|
|
|
|
(void) VOP_CLOSE(devvp, ronly ? FREAD : FREAD|FWRITE, NOCRED, p);
|
1993-08-13 15:35:13 +04:00
|
|
|
if (pmp) {
|
|
|
|
if (pmp->pm_inusemap)
|
1994-09-28 14:31:23 +03:00
|
|
|
free(pmp->pm_inusemap, M_MSDOSFSFAT);
|
|
|
|
free(pmp, M_MSDOSFSMNT);
|
|
|
|
mp->mnt_data = (qaddr_t)0;
|
1993-08-13 15:35:13 +04:00
|
|
|
}
|
1994-09-28 14:31:23 +03:00
|
|
|
return (error);
|
1993-08-13 15:35:13 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
msdosfs_start(mp, flags, p)
|
|
|
|
struct mount *mp;
|
|
|
|
int flags;
|
|
|
|
struct proc *p;
|
|
|
|
{
|
1994-09-28 14:31:23 +03:00
|
|
|
|
|
|
|
return (0);
|
1993-08-13 15:35:13 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Unmount the filesystem described by mp.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
msdosfs_unmount(mp, mntflags, p)
|
|
|
|
struct mount *mp;
|
|
|
|
int mntflags;
|
|
|
|
struct proc *p;
|
|
|
|
{
|
1994-12-14 19:33:18 +03:00
|
|
|
struct msdosfsmount *pmp;
|
1994-09-28 14:31:23 +03:00
|
|
|
int error, flags;
|
1993-08-13 15:35:13 +04:00
|
|
|
|
1994-09-28 14:31:23 +03:00
|
|
|
flags = 0;
|
1995-01-18 12:14:37 +03:00
|
|
|
if (mntflags & MNT_FORCE)
|
1993-08-13 15:35:13 +04:00
|
|
|
flags |= FORCECLOSE;
|
1994-07-19 01:38:08 +04:00
|
|
|
#ifdef QUOTA
|
|
|
|
#endif
|
1993-08-13 15:35:13 +04:00
|
|
|
if (error = vflush(mp, NULLVP, flags))
|
1994-09-28 14:31:23 +03:00
|
|
|
return (error);
|
1994-12-14 19:33:18 +03:00
|
|
|
pmp = VFSTOMSDOSFS(mp);
|
1993-08-13 15:35:13 +04:00
|
|
|
pmp->pm_devvp->v_specflags &= ~SI_MOUNTEDON;
|
1994-07-19 01:38:08 +04:00
|
|
|
#ifdef MSDOSFS_DEBUG
|
1993-08-13 15:35:13 +04:00
|
|
|
printf("msdosfs_umount(): just before calling VOP_CLOSE()\n");
|
|
|
|
printf("flag %08x, usecount %d, writecount %d, holdcnt %d\n",
|
|
|
|
vp->v_flag, vp->v_usecount, vp->v_writecount, vp->v_holdcnt);
|
|
|
|
printf("lastr %d, id %d, mount %08x, op %08x\n",
|
|
|
|
vp->v_lastr, vp->v_id, vp->v_mount, vp->v_op);
|
|
|
|
printf("freef %08x, freeb %08x, mountf %08x, mountb %08x\n",
|
|
|
|
vp->v_freef, vp->v_freeb, vp->v_mountf, vp->v_mountb);
|
|
|
|
printf("cleanblkhd %08x, dirtyblkhd %08x, numoutput %d, type %d\n",
|
|
|
|
vp->v_cleanblkhd, vp->v_dirtyblkhd, vp->v_numoutput, vp->v_type);
|
|
|
|
printf("union %08x, tag %d, data[0] %08x, data[1] %08x\n",
|
|
|
|
vp->v_socket, vp->v_tag, vp->v_data[0], vp->v_data[1]);
|
1994-07-19 01:38:08 +04:00
|
|
|
#endif
|
1994-09-28 14:31:23 +03:00
|
|
|
error = VOP_CLOSE(pmp->pm_devvp, pmp->pm_ronly ? FREAD : FREAD|FWRITE,
|
1993-08-13 15:35:13 +04:00
|
|
|
NOCRED, p);
|
|
|
|
vrele(pmp->pm_devvp);
|
1994-09-28 14:31:23 +03:00
|
|
|
free(pmp->pm_inusemap, M_MSDOSFSFAT);
|
|
|
|
free(pmp, M_MSDOSFSMNT);
|
|
|
|
mp->mnt_data = (qaddr_t)0;
|
1993-08-13 15:35:13 +04:00
|
|
|
mp->mnt_flag &= ~MNT_LOCAL;
|
1994-09-28 14:31:23 +03:00
|
|
|
return (error);
|
1993-08-13 15:35:13 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
msdosfs_root(mp, vpp)
|
|
|
|
struct mount *mp;
|
|
|
|
struct vnode **vpp;
|
|
|
|
{
|
1994-09-22 06:34:49 +04:00
|
|
|
struct msdosfsmount *pmp = VFSTOMSDOSFS(mp);
|
1994-09-28 14:31:23 +03:00
|
|
|
struct denode *ndep;
|
1993-08-13 15:35:13 +04:00
|
|
|
int error;
|
|
|
|
|
1994-07-19 01:38:08 +04:00
|
|
|
#ifdef MSDOSFS_DEBUG
|
1993-08-13 15:35:13 +04:00
|
|
|
printf("msdosfs_root(); mp %08x, pmp %08x, ndep %08x, vp %08x\n",
|
|
|
|
mp, pmp, ndep, DETOV(ndep));
|
1994-07-19 01:38:08 +04:00
|
|
|
#endif
|
1994-09-28 14:31:23 +03:00
|
|
|
if (error = deget(pmp, MSDOSFSROOT, MSDOSFSROOT_OFS, NULL, &ndep))
|
|
|
|
return (error);
|
|
|
|
*vpp = DETOV(ndep);
|
|
|
|
return (0);
|
1993-08-13 15:35:13 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
msdosfs_quotactl(mp, cmds, uid, arg, p)
|
|
|
|
struct mount *mp;
|
|
|
|
int cmds;
|
|
|
|
uid_t uid;
|
|
|
|
caddr_t arg;
|
|
|
|
struct proc *p;
|
|
|
|
{
|
1994-09-28 14:31:23 +03:00
|
|
|
|
1994-07-19 01:38:08 +04:00
|
|
|
#ifdef QUOTA
|
1994-09-28 14:31:23 +03:00
|
|
|
return (EOPNOTSUPP);
|
1993-08-13 15:35:13 +04:00
|
|
|
#else
|
1994-09-28 14:31:23 +03:00
|
|
|
return (EOPNOTSUPP);
|
1994-07-19 01:38:08 +04:00
|
|
|
#endif
|
1993-08-13 15:35:13 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
msdosfs_statfs(mp, sbp, p)
|
|
|
|
struct mount *mp;
|
|
|
|
struct statfs *sbp;
|
|
|
|
struct proc *p;
|
|
|
|
{
|
1994-09-28 14:31:23 +03:00
|
|
|
struct msdosfsmount *pmp;
|
1993-08-13 15:35:13 +04:00
|
|
|
|
1994-09-28 14:31:23 +03:00
|
|
|
pmp = VFSTOMSDOSFS(mp);
|
1994-04-14 08:05:45 +04:00
|
|
|
#ifdef COMPAT_09
|
|
|
|
sbp->f_type = 4;
|
|
|
|
#else
|
|
|
|
sbp->f_type = 0;
|
|
|
|
#endif
|
1993-08-13 15:35:13 +04:00
|
|
|
sbp->f_bsize = pmp->pm_bpcluster;
|
1994-04-21 11:47:31 +04:00
|
|
|
sbp->f_iosize = pmp->pm_bpcluster;
|
1993-08-13 15:35:13 +04:00
|
|
|
sbp->f_blocks = pmp->pm_nmbrofclusters;
|
|
|
|
sbp->f_bfree = pmp->pm_freeclustercount;
|
|
|
|
sbp->f_bavail = pmp->pm_freeclustercount;
|
1994-07-17 01:32:06 +04:00
|
|
|
sbp->f_files = pmp->pm_RootDirEnts; /* XXX */
|
1993-08-13 15:35:13 +04:00
|
|
|
sbp->f_ffree = 0; /* what to put in here? */
|
|
|
|
if (sbp != &mp->mnt_stat) {
|
1995-01-18 12:14:37 +03:00
|
|
|
bcopy(mp->mnt_stat.f_mntonname, sbp->f_mntonname, MNAMELEN);
|
|
|
|
bcopy(mp->mnt_stat.f_mntfromname, sbp->f_mntfromname, MNAMELEN);
|
1993-08-13 15:35:13 +04:00
|
|
|
}
|
1995-01-18 12:14:37 +03:00
|
|
|
strncpy(sbp->f_fstypename, mp->mnt_op->vfs_name, MFSNAMELEN);
|
1994-04-14 08:05:45 +04:00
|
|
|
sbp->f_fstypename[MFSNAMELEN] = '\0';
|
1994-09-28 14:31:23 +03:00
|
|
|
return (0);
|
1993-08-13 15:35:13 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
1994-07-17 01:32:06 +04:00
|
|
|
msdosfs_sync(mp, waitfor, cred, p)
|
1993-08-13 15:35:13 +04:00
|
|
|
struct mount *mp;
|
|
|
|
int waitfor;
|
1994-07-17 01:32:06 +04:00
|
|
|
struct ucred *cred;
|
|
|
|
struct proc *p;
|
1993-08-13 15:35:13 +04:00
|
|
|
{
|
|
|
|
struct vnode *vp;
|
|
|
|
struct denode *dep;
|
1994-09-19 23:28:07 +04:00
|
|
|
struct msdosfsmount *pmp = VFSTOMSDOSFS(mp);
|
1994-09-28 14:31:23 +03:00
|
|
|
int error, allerror = 0;
|
1993-08-13 15:35:13 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* If we ever switch to not updating all of the fats all the time,
|
|
|
|
* this would be the place to update them from the first one.
|
|
|
|
*/
|
1994-09-28 14:31:23 +03:00
|
|
|
if (pmp->pm_fmod != 0)
|
|
|
|
if (pmp->pm_ronly != 0)
|
1994-02-08 02:14:16 +03:00
|
|
|
panic("msdosfs_sync: rofs mod");
|
1993-08-13 15:35:13 +04:00
|
|
|
else {
|
|
|
|
/* update fats here */
|
|
|
|
}
|
|
|
|
/*
|
1994-09-19 23:28:07 +04:00
|
|
|
* Write back each (modified) denode.
|
1993-08-13 15:35:13 +04:00
|
|
|
*/
|
|
|
|
loop:
|
1994-09-19 23:28:07 +04:00
|
|
|
for (vp = mp->mnt_vnodelist.lh_first;
|
|
|
|
vp != NULL;
|
|
|
|
vp = vp->v_mntvnodes.le_next) {
|
|
|
|
/*
|
|
|
|
* If the vnode that we are about to sync is no longer
|
|
|
|
* assoicated with this mount point, start over.
|
|
|
|
*/
|
|
|
|
if (vp->v_mount != mp)
|
1993-08-13 15:35:13 +04:00
|
|
|
goto loop;
|
1994-09-19 23:28:07 +04:00
|
|
|
if (VOP_ISLOCKED(vp))
|
1993-08-13 15:35:13 +04:00
|
|
|
continue;
|
|
|
|
dep = VTODE(vp);
|
1994-07-19 08:29:55 +04:00
|
|
|
if ((dep->de_flag & DE_UPDATE) == 0 &&
|
1994-04-21 11:47:31 +04:00
|
|
|
vp->v_dirtyblkhd.lh_first == NULL)
|
1993-08-13 15:35:13 +04:00
|
|
|
continue;
|
1994-09-19 23:28:07 +04:00
|
|
|
if (vget(vp, 1))
|
1993-08-13 15:35:13 +04:00
|
|
|
goto loop;
|
1994-07-17 01:32:06 +04:00
|
|
|
if (error = VOP_FSYNC(vp, cred, waitfor, p))
|
1993-08-13 15:35:13 +04:00
|
|
|
allerror = error;
|
1994-09-19 23:28:07 +04:00
|
|
|
vput(vp);
|
1993-08-13 15:35:13 +04:00
|
|
|
}
|
|
|
|
/*
|
1994-09-19 23:28:07 +04:00
|
|
|
* Force stale file system control information to be flushed.
|
1993-08-13 15:35:13 +04:00
|
|
|
*/
|
1994-09-19 23:28:07 +04:00
|
|
|
if (error = VOP_FSYNC(pmp->pm_devvp, cred, waitfor, p))
|
|
|
|
allerror = error;
|
1994-09-28 14:31:23 +03:00
|
|
|
#ifdef QUOTA
|
|
|
|
#endif
|
|
|
|
return (allerror);
|
1993-08-13 15:35:13 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
1994-07-17 01:32:06 +04:00
|
|
|
msdosfs_fhtovp(mp, fhp, nam, vpp, exflagsp, credanonp)
|
1993-08-13 15:35:13 +04:00
|
|
|
struct mount *mp;
|
|
|
|
struct fid *fhp;
|
1994-07-17 01:32:06 +04:00
|
|
|
struct mbuf *nam;
|
1993-08-13 15:35:13 +04:00
|
|
|
struct vnode **vpp;
|
1994-07-17 01:32:06 +04:00
|
|
|
int *exflagsp;
|
|
|
|
struct ucred **credanonp;
|
1993-08-13 15:35:13 +04:00
|
|
|
{
|
1994-09-22 06:34:49 +04:00
|
|
|
struct msdosfsmount *pmp = VFSTOMSDOSFS(mp);
|
1993-08-13 15:35:13 +04:00
|
|
|
struct defid *defhp = (struct defid *) fhp;
|
|
|
|
struct denode *dep;
|
1994-07-17 01:32:06 +04:00
|
|
|
struct netcred *np;
|
1993-08-13 15:35:13 +04:00
|
|
|
int error;
|
|
|
|
|
1994-07-17 01:32:06 +04:00
|
|
|
np = vfs_export_lookup(mp, &pmp->pm_export, nam);
|
|
|
|
if (np == NULL)
|
1994-09-28 14:31:23 +03:00
|
|
|
return (EACCES);
|
1993-08-13 15:35:13 +04:00
|
|
|
error = deget(pmp, defhp->defid_dirclust, defhp->defid_dirofs,
|
|
|
|
NULL, &dep);
|
1994-07-17 01:32:06 +04:00
|
|
|
if (error) {
|
|
|
|
*vpp = NULLVP;
|
1994-09-28 14:31:23 +03:00
|
|
|
return (error);
|
1994-07-17 01:32:06 +04:00
|
|
|
}
|
1993-08-13 15:35:13 +04:00
|
|
|
*vpp = DETOV(dep);
|
1994-07-17 01:32:06 +04:00
|
|
|
*exflagsp = np->netc_exflags;
|
|
|
|
*credanonp = &np->netc_anon;
|
1994-09-28 14:31:23 +03:00
|
|
|
return (0);
|
1993-08-13 15:35:13 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
msdosfs_vptofh(vp, fhp)
|
|
|
|
struct vnode *vp;
|
|
|
|
struct fid *fhp;
|
|
|
|
{
|
1994-09-28 14:31:23 +03:00
|
|
|
struct denode *dep;
|
|
|
|
struct defid *defhp;
|
1993-08-13 15:35:13 +04:00
|
|
|
|
1994-09-28 14:31:23 +03:00
|
|
|
dep = VTODE(vp);
|
|
|
|
defhp = (struct defid *)fhp;
|
1993-08-13 15:35:13 +04:00
|
|
|
defhp->defid_len = sizeof(struct defid);
|
|
|
|
defhp->defid_dirclust = dep->de_dirclust;
|
|
|
|
defhp->defid_dirofs = dep->de_diroffset;
|
1994-09-28 14:31:23 +03:00
|
|
|
/* defhp->defid_gen = dep->de_gen; */
|
|
|
|
return (0);
|
1994-07-17 01:32:06 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
msdosfs_vget(mp, ino, vpp)
|
|
|
|
struct mount *mp;
|
|
|
|
ino_t ino;
|
|
|
|
struct vnode **vpp;
|
|
|
|
{
|
1994-09-28 14:31:23 +03:00
|
|
|
|
|
|
|
return (EOPNOTSUPP);
|
1993-08-13 15:35:13 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
struct vfsops msdosfs_vfsops = {
|
1994-04-14 08:05:45 +04:00
|
|
|
MOUNT_MSDOS,
|
1993-08-13 15:35:13 +04:00
|
|
|
msdosfs_mount,
|
|
|
|
msdosfs_start,
|
|
|
|
msdosfs_unmount,
|
|
|
|
msdosfs_root,
|
|
|
|
msdosfs_quotactl,
|
|
|
|
msdosfs_statfs,
|
|
|
|
msdosfs_sync,
|
1994-07-17 01:32:06 +04:00
|
|
|
msdosfs_vget,
|
1993-08-13 15:35:13 +04:00
|
|
|
msdosfs_fhtovp,
|
|
|
|
msdosfs_vptofh,
|
|
|
|
msdosfs_init
|
|
|
|
};
|