1999-08-28 01:08:13 +00:00
|
|
|
/* $FreeBSD$ */
|
1998-02-18 09:28:47 +00:00
|
|
|
/* $NetBSD: msdosfs_vfsops.c,v 1.51 1997/11/17 15:36:58 ws Exp $ */
|
1994-09-19 15:41:57 +00:00
|
|
|
|
|
|
|
/*-
|
1998-02-18 09:28:47 +00:00
|
|
|
* Copyright (C) 1994, 1995, 1997 Wolfgang Solfrank.
|
|
|
|
* Copyright (C) 1994, 1995, 1997 TooLs GmbH.
|
1994-09-19 15:41:57 +00:00
|
|
|
* All rights reserved.
|
|
|
|
* Original code by Paul Popelka (paulp@uts.amdahl.com) (see below).
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
/*
|
|
|
|
* Written by Paul Popelka (paulp@uts.amdahl.com)
|
1995-05-30 08:16:23 +00:00
|
|
|
*
|
1994-09-19 15:41:57 +00:00
|
|
|
* You can do anything you want with this software, just don't say you wrote
|
|
|
|
* it, and don't remove this notice.
|
1995-05-30 08:16:23 +00:00
|
|
|
*
|
1994-09-19 15:41:57 +00:00
|
|
|
* This software is provided "as is".
|
1995-05-30 08:16:23 +00:00
|
|
|
*
|
1994-09-19 15:41:57 +00:00
|
|
|
* 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.
|
1995-05-30 08:16:23 +00:00
|
|
|
*
|
1994-09-19 15:41:57 +00:00
|
|
|
* October 1992
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
1998-10-25 19:26:18 +00:00
|
|
|
#include <sys/conf.h>
|
1994-09-19 15:41:57 +00:00
|
|
|
#include <sys/namei.h>
|
|
|
|
#include <sys/proc.h>
|
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/vnode.h>
|
|
|
|
#include <sys/mount.h>
|
2000-05-05 09:59:14 +00:00
|
|
|
#include <sys/bio.h>
|
1994-09-19 15:41:57 +00:00
|
|
|
#include <sys/buf.h>
|
1997-03-23 03:37:54 +00:00
|
|
|
#include <sys/fcntl.h>
|
1994-09-19 15:41:57 +00:00
|
|
|
#include <sys/malloc.h>
|
1998-02-18 09:28:47 +00:00
|
|
|
#include <sys/stat.h> /* defines ALLPERMS */
|
2001-01-24 12:35:55 +00:00
|
|
|
#include <sys/mutex.h>
|
2000-10-04 01:29:17 +00:00
|
|
|
|
1994-09-19 15:41:57 +00: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>
|
|
|
|
|
2000-03-27 21:29:33 +00:00
|
|
|
#define MSDOSFS_DFLTBSIZE 4096
|
|
|
|
|
2000-01-27 14:43:07 +00:00
|
|
|
#if 1 /*def PC98*/
|
|
|
|
/*
|
|
|
|
* XXX - The boot signature formatted by NEC PC-98 DOS looks like a
|
|
|
|
* garbage or a random value :-{
|
|
|
|
* If you want to use that broken-signatured media, define the
|
|
|
|
* following symbol even though PC/AT.
|
|
|
|
* (ex. mount PC-98 DOS formatted FD on PC/AT)
|
|
|
|
*/
|
|
|
|
#define MSDOSFS_NOCHECKSIG
|
|
|
|
#endif
|
|
|
|
|
1997-10-12 20:26:33 +00:00
|
|
|
MALLOC_DEFINE(M_MSDOSFSMNT, "MSDOSFS mount", "MSDOSFS mount structure");
|
|
|
|
static MALLOC_DEFINE(M_MSDOSFSFAT, "MSDOSFS FAT", "MSDOSFS file allocation table");
|
1997-10-11 18:31:40 +00:00
|
|
|
|
1998-02-18 09:28:47 +00:00
|
|
|
static int update_mp __P((struct mount *mp, struct msdosfs_args *argp));
|
1995-11-16 11:48:10 +00:00
|
|
|
static int mountmsdosfs __P((struct vnode *devvp, struct mount *mp,
|
1998-02-18 09:28:47 +00:00
|
|
|
struct proc *p, struct msdosfs_args *argp));
|
1995-11-16 11:48:10 +00:00
|
|
|
static int msdosfs_fhtovp __P((struct mount *, struct fid *,
|
1999-09-11 00:46:08 +00:00
|
|
|
struct vnode **));
|
|
|
|
static int msdosfs_checkexp __P((struct mount *, struct sockaddr *,
|
|
|
|
int *, struct ucred **));
|
1995-11-16 11:48:10 +00:00
|
|
|
static int msdosfs_mount __P((struct mount *, char *, caddr_t,
|
|
|
|
struct nameidata *, struct proc *));
|
|
|
|
static int msdosfs_root __P((struct mount *, struct vnode **));
|
|
|
|
static int msdosfs_statfs __P((struct mount *, struct statfs *,
|
|
|
|
struct proc *));
|
|
|
|
static int msdosfs_sync __P((struct mount *, int, struct ucred *,
|
|
|
|
struct proc *));
|
|
|
|
static int msdosfs_unmount __P((struct mount *, int, struct proc *));
|
|
|
|
static int msdosfs_vptofh __P((struct vnode *, struct fid *));
|
|
|
|
|
1998-02-18 09:28:47 +00:00
|
|
|
static int
|
|
|
|
update_mp(mp, argp)
|
|
|
|
struct mount *mp;
|
|
|
|
struct msdosfs_args *argp;
|
|
|
|
{
|
|
|
|
struct msdosfsmount *pmp = VFSTOMSDOSFS(mp);
|
|
|
|
int error;
|
|
|
|
|
|
|
|
pmp->pm_gid = argp->gid;
|
|
|
|
pmp->pm_uid = argp->uid;
|
|
|
|
pmp->pm_mask = argp->mask & ALLPERMS;
|
|
|
|
pmp->pm_flags |= argp->flags & MSDOSFSMNT_MNTOPT;
|
1998-02-23 16:44:37 +00:00
|
|
|
if (pmp->pm_flags & MSDOSFSMNT_U2WTABLE) {
|
1998-02-22 15:09:54 +00:00
|
|
|
bcopy(argp->u2w, pmp->pm_u2w, sizeof(pmp->pm_u2w));
|
1998-02-23 16:44:37 +00:00
|
|
|
bcopy(argp->d2u, pmp->pm_d2u, sizeof(pmp->pm_d2u));
|
|
|
|
bcopy(argp->u2d, pmp->pm_u2d, sizeof(pmp->pm_u2d));
|
|
|
|
}
|
|
|
|
if (pmp->pm_flags & MSDOSFSMNT_ULTABLE) {
|
1998-02-23 09:59:08 +00:00
|
|
|
bcopy(argp->ul, pmp->pm_ul, sizeof(pmp->pm_ul));
|
1998-02-23 16:44:37 +00:00
|
|
|
bcopy(argp->lu, pmp->pm_lu, sizeof(pmp->pm_lu));
|
|
|
|
}
|
1998-02-18 09:28:47 +00:00
|
|
|
|
|
|
|
#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))) {
|
|
|
|
struct vnode *rootvp;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Try to divine whether to support Win'95 long filenames
|
|
|
|
*/
|
|
|
|
if (FAT32(pmp))
|
|
|
|
pmp->pm_flags |= MSDOSFSMNT_LONGNAME;
|
|
|
|
else {
|
|
|
|
if ((error = msdosfs_root(mp, &rootvp)) != 0)
|
|
|
|
return error;
|
|
|
|
pmp->pm_flags |= findwin95(VTODE(rootvp))
|
|
|
|
? MSDOSFSMNT_LONGNAME
|
|
|
|
: MSDOSFSMNT_SHORTNAME;
|
|
|
|
vput(rootvp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
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");
|
|
|
|
|
2000-12-08 21:51:06 +00:00
|
|
|
mp = malloc((u_long)sizeof(struct mount), M_MOUNT, M_WAITOK | M_ZERO);
|
1998-02-18 09:28:47 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
1999-11-20 10:00:46 +00:00
|
|
|
TAILQ_INSERT_TAIL(&mountlist, mp, mnt_list);
|
1998-02-18 09:28:47 +00:00
|
|
|
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
|
|
|
|
|
1994-09-19 15:41:57 +00:00
|
|
|
/*
|
1995-05-30 08:16:23 +00:00
|
|
|
* mp - path - addr in user space of mount point (ie /usr or whatever)
|
1994-09-19 15:41:57 +00:00
|
|
|
* data - addr in user space of mount params including the name of the block
|
1995-05-30 08:16:23 +00:00
|
|
|
* special file to treat as a filesystem.
|
1994-09-19 15:41:57 +00:00
|
|
|
*/
|
1995-11-07 14:06:45 +00:00
|
|
|
static int
|
1994-09-19 15:41:57 +00:00
|
|
|
msdosfs_mount(mp, path, data, ndp, p)
|
|
|
|
struct mount *mp;
|
|
|
|
char *path;
|
|
|
|
caddr_t data;
|
|
|
|
struct nameidata *ndp;
|
|
|
|
struct proc *p;
|
|
|
|
{
|
|
|
|
struct vnode *devvp; /* vnode for blk device to mount */
|
|
|
|
struct msdosfs_args args; /* will hold data from mount request */
|
1998-02-18 09:28:47 +00:00
|
|
|
/* msdosfs specific mount control block */
|
|
|
|
struct msdosfsmount *pmp = NULL;
|
|
|
|
size_t size;
|
1994-09-19 15:41:57 +00:00
|
|
|
int error, flags;
|
1998-02-18 09:28:47 +00:00
|
|
|
mode_t accessmode;
|
1994-09-19 15:41:57 +00:00
|
|
|
|
1998-02-18 09:28:47 +00:00
|
|
|
error = copyin(data, (caddr_t)&args, sizeof(struct msdosfs_args));
|
1994-09-27 20:42:59 +00:00
|
|
|
if (error)
|
1998-02-18 09:28:47 +00:00
|
|
|
return (error);
|
1998-04-15 11:04:53 +00:00
|
|
|
if (args.magic != MSDOSFS_ARGSMAGIC)
|
1998-02-18 09:28:47 +00:00
|
|
|
args.flags = 0;
|
1994-09-19 15:41:57 +00:00
|
|
|
/*
|
1998-02-18 09:28:47 +00:00
|
|
|
* If updating, check whether changing from read-only to
|
|
|
|
* read/write; if there is no device name, that's all we do.
|
1994-09-19 15:41:57 +00:00
|
|
|
*/
|
|
|
|
if (mp->mnt_flag & MNT_UPDATE) {
|
1998-02-18 09:28:47 +00:00
|
|
|
pmp = VFSTOMSDOSFS(mp);
|
1994-09-19 15:41:57 +00:00
|
|
|
error = 0;
|
1998-02-18 09:28:47 +00:00
|
|
|
if (!(pmp->pm_flags & MSDOSFSMNT_RONLY) && (mp->mnt_flag & MNT_RDONLY)) {
|
1994-09-19 15:41:57 +00:00
|
|
|
flags = WRITECLOSE;
|
|
|
|
if (mp->mnt_flag & MNT_FORCE)
|
|
|
|
flags |= FORCECLOSE;
|
|
|
|
error = vflush(mp, NULLVP, flags);
|
|
|
|
}
|
|
|
|
if (!error && (mp->mnt_flag & MNT_RELOAD))
|
|
|
|
/* not yet implemented */
|
1998-02-18 09:28:47 +00:00
|
|
|
error = EOPNOTSUPP;
|
1994-09-19 15:41:57 +00:00
|
|
|
if (error)
|
1998-02-18 09:28:47 +00:00
|
|
|
return (error);
|
|
|
|
if ((pmp->pm_flags & MSDOSFSMNT_RONLY) && (mp->mnt_kern_flag & MNTK_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;
|
1998-04-15 11:04:53 +00:00
|
|
|
vn_lock(devvp, LK_EXCLUSIVE | LK_RETRY, p);
|
1998-02-18 09:28:47 +00:00
|
|
|
error = VOP_ACCESS(devvp, VREAD | VWRITE,
|
|
|
|
p->p_ucred, p);
|
|
|
|
if (error) {
|
|
|
|
VOP_UNLOCK(devvp, 0, p);
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
VOP_UNLOCK(devvp, 0, p);
|
|
|
|
}
|
|
|
|
pmp->pm_flags &= ~MSDOSFSMNT_RONLY;
|
|
|
|
}
|
1994-09-19 15:41:57 +00:00
|
|
|
if (args.fspec == 0) {
|
1998-02-18 09:28:47 +00:00
|
|
|
#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)
|
|
|
|
pmp->pm_flags |= MSDOSFSMNT_SHORTNAME;
|
|
|
|
}
|
|
|
|
#endif
|
1994-09-19 15:41:57 +00:00
|
|
|
/*
|
|
|
|
* Process export requests.
|
|
|
|
*/
|
1998-02-18 09:28:47 +00:00
|
|
|
return (vfs_export(mp, &pmp->pm_export, &args.export));
|
1994-09-19 15:41:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
/*
|
1998-02-18 09:28:47 +00:00
|
|
|
* Not an update, or updating the name: look up the name
|
|
|
|
* and verify that it refers to a sensible block device.
|
1994-09-19 15:41:57 +00:00
|
|
|
*/
|
|
|
|
NDINIT(ndp, LOOKUP, FOLLOW, UIO_USERSPACE, args.fspec, p);
|
|
|
|
error = namei(ndp);
|
1998-02-18 09:28:47 +00:00
|
|
|
if (error)
|
|
|
|
return (error);
|
1994-09-19 15:41:57 +00:00
|
|
|
devvp = ndp->ni_vp;
|
1999-12-15 23:02:35 +00:00
|
|
|
NDFREE(ndp, NDF_ONLY_PNBUF);
|
1998-02-18 09:28:47 +00:00
|
|
|
|
2000-01-10 12:04:27 +00:00
|
|
|
if (!vn_isdisk(devvp, &error)) {
|
1994-09-19 15:41:57 +00:00
|
|
|
vrele(devvp);
|
2000-01-10 12:04:27 +00:00
|
|
|
return (error);
|
1994-09-19 15:41:57 +00:00
|
|
|
}
|
|
|
|
/*
|
1998-02-18 09:28:47 +00:00
|
|
|
* If mount by non-root, then verify that user has necessary
|
|
|
|
* permissions on the device.
|
1994-09-19 15:41:57 +00:00
|
|
|
*/
|
1998-02-18 09:28:47 +00:00
|
|
|
if (p->p_ucred->cr_uid != 0) {
|
|
|
|
accessmode = VREAD;
|
|
|
|
if ((mp->mnt_flag & MNT_RDONLY) == 0)
|
|
|
|
accessmode |= VWRITE;
|
|
|
|
vn_lock(devvp, LK_EXCLUSIVE | LK_RETRY, p);
|
|
|
|
error = VOP_ACCESS(devvp, accessmode, p->p_ucred, p);
|
|
|
|
if (error) {
|
|
|
|
vput(devvp);
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
VOP_UNLOCK(devvp, 0, p);
|
|
|
|
}
|
|
|
|
if ((mp->mnt_flag & MNT_UPDATE) == 0) {
|
|
|
|
error = mountmsdosfs(devvp, mp, p, &args);
|
|
|
|
#ifdef MSDOSFS_DEBUG /* only needed for the printf below */
|
|
|
|
pmp = VFSTOMSDOSFS(mp);
|
|
|
|
#endif
|
|
|
|
} else {
|
1994-09-19 15:41:57 +00:00
|
|
|
if (devvp != pmp->pm_devvp)
|
1998-02-18 09:28:47 +00:00
|
|
|
error = EINVAL; /* XXX needs translation */
|
1994-09-19 15:41:57 +00:00
|
|
|
else
|
|
|
|
vrele(devvp);
|
|
|
|
}
|
|
|
|
if (error) {
|
|
|
|
vrele(devvp);
|
1998-02-18 09:28:47 +00:00
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
error = update_mp(mp, &args);
|
|
|
|
if (error) {
|
|
|
|
msdosfs_unmount(mp, MNT_FORCE, p);
|
1994-09-19 15:41:57 +00:00
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
1998-02-18 09:28:47 +00:00
|
|
|
(void) copyinstr(path, mp->mnt_stat.f_mntonname, MNAMELEN - 1, &size);
|
|
|
|
bzero(mp->mnt_stat.f_mntonname + size, MNAMELEN - size);
|
|
|
|
(void) copyinstr(args.fspec, mp->mnt_stat.f_mntfromname, MNAMELEN - 1,
|
|
|
|
&size);
|
|
|
|
bzero(mp->mnt_stat.f_mntfromname + size, MNAMELEN - size);
|
1994-09-19 15:41:57 +00:00
|
|
|
(void) msdosfs_statfs(mp, &mp->mnt_stat, p);
|
|
|
|
#ifdef MSDOSFS_DEBUG
|
1994-10-02 17:48:58 +00:00
|
|
|
printf("msdosfs_mount(): mp %p, pmp %p, inusemap %p\n", mp, pmp, pmp->pm_inusemap);
|
1994-09-19 15:41:57 +00:00
|
|
|
#endif
|
1998-02-18 09:28:47 +00:00
|
|
|
return (0);
|
1994-09-19 15:41:57 +00:00
|
|
|
}
|
|
|
|
|
1995-11-07 14:06:45 +00:00
|
|
|
static int
|
1998-02-18 09:28:47 +00:00
|
|
|
mountmsdosfs(devvp, mp, p, argp)
|
1994-09-19 15:41:57 +00:00
|
|
|
struct vnode *devvp;
|
|
|
|
struct mount *mp;
|
|
|
|
struct proc *p;
|
1998-02-18 09:28:47 +00:00
|
|
|
struct msdosfs_args *argp;
|
1994-09-19 15:41:57 +00:00
|
|
|
{
|
1998-02-18 09:28:47 +00:00
|
|
|
struct msdosfsmount *pmp;
|
|
|
|
struct buf *bp;
|
1994-09-19 15:41:57 +00:00
|
|
|
dev_t dev = devvp->v_rdev;
|
1998-02-18 09:28:47 +00:00
|
|
|
#ifndef __FreeBSD__
|
|
|
|
struct partinfo dpart;
|
1998-12-07 21:58:50 +00:00
|
|
|
int bsize = 0, dtype = 0, tmp;
|
1998-02-18 09:28:47 +00:00
|
|
|
#endif
|
1994-09-19 15:41:57 +00:00
|
|
|
union bootsector *bsp;
|
|
|
|
struct byte_bpb33 *b33;
|
|
|
|
struct byte_bpb50 *b50;
|
1998-02-18 09:28:47 +00:00
|
|
|
struct byte_bpb710 *b710;
|
|
|
|
u_int8_t SecPerClust;
|
1999-12-28 15:27:39 +00:00
|
|
|
u_long clusters;
|
1998-02-18 09:28:47 +00:00
|
|
|
int ronly, error;
|
1994-09-19 15:41:57 +00:00
|
|
|
|
|
|
|
/*
|
1998-02-18 09:28:47 +00: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.
|
1994-09-19 15:41:57 +00:00
|
|
|
*/
|
1994-09-27 20:42:59 +00:00
|
|
|
error = vfs_mountedon(devvp);
|
|
|
|
if (error)
|
1998-02-18 09:28:47 +00:00
|
|
|
return (error);
|
|
|
|
if (vcount(devvp) > 1 && devvp != rootvp)
|
|
|
|
return (EBUSY);
|
|
|
|
vn_lock(devvp, LK_EXCLUSIVE | LK_RETRY, p);
|
1994-09-27 20:42:59 +00:00
|
|
|
error = vinvalbuf(devvp, V_SAVE, p->p_ucred, p, 0, 0);
|
1998-02-18 09:28:47 +00:00
|
|
|
VOP_UNLOCK(devvp, 0, p);
|
1994-09-27 20:42:59 +00:00
|
|
|
if (error)
|
1998-02-18 09:28:47 +00:00
|
|
|
return (error);
|
1994-09-19 15:41:57 +00:00
|
|
|
|
1998-02-18 09:28:47 +00:00
|
|
|
ronly = (mp->mnt_flag & MNT_RDONLY) != 0;
|
1999-11-09 14:15:33 +00:00
|
|
|
vn_lock(devvp, LK_EXCLUSIVE | LK_RETRY, p);
|
1998-02-18 09:28:47 +00:00
|
|
|
error = VOP_OPEN(devvp, ronly ? FREAD : FREAD|FWRITE, FSCRED, p);
|
1999-11-09 14:15:33 +00:00
|
|
|
VOP_UNLOCK(devvp, 0, p);
|
1994-09-27 20:42:59 +00:00
|
|
|
if (error)
|
1998-02-18 09:28:47 +00:00
|
|
|
return (error);
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
1994-09-19 15:41:57 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
1998-02-18 09:28:47 +00:00
|
|
|
* Read the boot sector of the filesystem, and then check the
|
|
|
|
* boot signature. If not a dos boot sector then error out.
|
2000-01-27 14:43:07 +00:00
|
|
|
*
|
|
|
|
* NOTE: 2048 is a maximum sector size in current...
|
1994-09-19 15:41:57 +00:00
|
|
|
*/
|
2000-01-27 14:43:07 +00:00
|
|
|
error = bread(devvp, 0, 2048, NOCRED, &bp);
|
1994-09-27 20:42:59 +00:00
|
|
|
if (error)
|
1994-09-19 15:41:57 +00:00
|
|
|
goto error_exit;
|
1998-02-18 09:28:47 +00: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;
|
|
|
|
b710 = (struct byte_bpb710 *)bsp->bs710.bsPBP;
|
|
|
|
|
|
|
|
#ifndef __FreeBSD__
|
|
|
|
if (!(argp->flags & MSDOSFSMNT_GEMDOSFS)) {
|
|
|
|
#endif
|
2000-01-27 14:43:07 +00:00
|
|
|
#ifndef MSDOSFS_NOCHECKSIG
|
1998-02-18 09:28:47 +00:00
|
|
|
if (bsp->bs50.bsBootSectSig0 != BOOTSIG0
|
|
|
|
|| bsp->bs50.bsBootSectSig1 != BOOTSIG1) {
|
|
|
|
error = EINVAL;
|
|
|
|
goto error_exit;
|
|
|
|
}
|
2000-01-27 14:43:07 +00:00
|
|
|
#endif
|
1998-02-18 09:28:47 +00:00
|
|
|
#ifndef __FreeBSD__
|
1994-09-19 15:41:57 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2000-12-08 21:51:06 +00:00
|
|
|
pmp = malloc(sizeof *pmp, M_MSDOSFSMNT, M_WAITOK | M_ZERO);
|
1994-09-19 15:41:57 +00: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.
|
|
|
|
*/
|
1998-02-18 09:28:47 +00:00
|
|
|
SecPerClust = b50->bpbSecPerClust;
|
1994-09-19 15:41:57 +00:00
|
|
|
pmp->pm_BytesPerSec = getushort(b50->bpbBytesPerSec);
|
|
|
|
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_FATsecs = getushort(b50->bpbFATsecs);
|
|
|
|
pmp->pm_SecPerTrack = getushort(b50->bpbSecPerTrack);
|
|
|
|
pmp->pm_Heads = getushort(b50->bpbHeads);
|
1998-02-18 09:28:47 +00:00
|
|
|
pmp->pm_Media = b50->bpbMedia;
|
1994-09-19 15:41:57 +00:00
|
|
|
|
2000-01-27 14:43:07 +00:00
|
|
|
/* calculate the ratio of sector size to DEV_BSIZE */
|
|
|
|
pmp->pm_BlkPerSec = pmp->pm_BytesPerSec / DEV_BSIZE;
|
|
|
|
|
1998-02-18 09:28:47 +00:00
|
|
|
#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
|
1996-06-14 11:02:28 +00:00
|
|
|
#ifdef PC98
|
1998-02-18 09:28:47 +00:00
|
|
|
|| !pmp->pm_SecPerTrack || pmp->pm_SecPerTrack > 255) {
|
1996-06-14 11:02:28 +00:00
|
|
|
#else
|
1998-02-18 09:28:47 +00:00
|
|
|
|| !pmp->pm_SecPerTrack || pmp->pm_SecPerTrack > 63) {
|
1996-06-14 11:02:28 +00:00
|
|
|
#endif
|
1998-02-18 09:28:47 +00:00
|
|
|
error = EINVAL;
|
|
|
|
goto error_exit;
|
|
|
|
}
|
|
|
|
#ifndef __FreeBSD__
|
1994-09-19 15:41:57 +00:00
|
|
|
}
|
1998-02-18 09:28:47 +00:00
|
|
|
#endif
|
1994-09-19 15:41:57 +00:00
|
|
|
|
|
|
|
if (pmp->pm_Sectors == 0) {
|
|
|
|
pmp->pm_HiddenSects = getulong(b50->bpbHiddenSecs);
|
|
|
|
pmp->pm_HugeSectors = getulong(b50->bpbHugeSectors);
|
|
|
|
} else {
|
|
|
|
pmp->pm_HiddenSects = getushort(b33->bpbHiddenSecs);
|
|
|
|
pmp->pm_HugeSectors = pmp->pm_Sectors;
|
|
|
|
}
|
1998-04-29 12:55:51 +00:00
|
|
|
if (pmp->pm_HugeSectors > 0xffffffff /
|
|
|
|
(pmp->pm_BytesPerSec / sizeof(struct direntry)) + 1) {
|
1998-02-18 09:28:47 +00:00
|
|
|
/*
|
|
|
|
* We cannot deal currently with this size of disk
|
|
|
|
* due to fileid limitations (see msdosfs_getattr and
|
|
|
|
* msdosfs_readdir)
|
|
|
|
*/
|
|
|
|
error = EINVAL;
|
1998-04-05 13:10:11 +00:00
|
|
|
printf("mountmsdosfs(): disk too big, sorry\n");
|
1998-02-18 09:28:47 +00:00
|
|
|
goto error_exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pmp->pm_RootDirEnts == 0) {
|
|
|
|
if (bsp->bs710.bsBootSectSig2 != BOOTSIG2
|
|
|
|
|| bsp->bs710.bsBootSectSig3 != BOOTSIG3
|
|
|
|
|| pmp->pm_Sectors
|
|
|
|
|| pmp->pm_FATsecs
|
|
|
|
|| getushort(b710->bpbFSVers)) {
|
|
|
|
error = EINVAL;
|
1998-04-05 13:10:11 +00:00
|
|
|
printf("mountmsdosfs(): bad FAT32 filesystem\n");
|
1998-02-18 09:28:47 +00:00
|
|
|
goto error_exit;
|
|
|
|
}
|
|
|
|
pmp->pm_fatmask = FAT32_MASK;
|
|
|
|
pmp->pm_fatmult = 4;
|
|
|
|
pmp->pm_fatdiv = 1;
|
|
|
|
pmp->pm_FATsecs = getulong(b710->bpbBigFATsecs);
|
|
|
|
if (getushort(b710->bpbExtFlags) & FATMIRROR)
|
|
|
|
pmp->pm_curfat = getushort(b710->bpbExtFlags) & FATNUM;
|
|
|
|
else
|
|
|
|
pmp->pm_flags |= MSDOSFS_FATMIRROR;
|
|
|
|
} else
|
|
|
|
pmp->pm_flags |= MSDOSFS_FATMIRROR;
|
|
|
|
|
2000-01-27 14:43:07 +00:00
|
|
|
/*
|
|
|
|
* Check a few values (could do some more):
|
|
|
|
* - logical sector size: power of 2, >= block size
|
|
|
|
* - sectors per cluster: power of 2, >= 1
|
|
|
|
* - number of sectors: >= 1, <= size of partition
|
|
|
|
*/
|
|
|
|
if ( (SecPerClust == 0)
|
|
|
|
|| (SecPerClust & (SecPerClust - 1))
|
|
|
|
|| (pmp->pm_BytesPerSec < DEV_BSIZE)
|
|
|
|
|| (pmp->pm_BytesPerSec & (pmp->pm_BytesPerSec - 1))
|
|
|
|
|| (pmp->pm_HugeSectors == 0)
|
|
|
|
) {
|
|
|
|
error = EINVAL;
|
|
|
|
goto error_exit;
|
1998-02-18 09:28:47 +00:00
|
|
|
}
|
2000-01-27 14:43:07 +00:00
|
|
|
|
|
|
|
pmp->pm_HugeSectors *= pmp->pm_BlkPerSec;
|
|
|
|
pmp->pm_HiddenSects *= pmp->pm_BlkPerSec; /* XXX not used? */
|
|
|
|
pmp->pm_FATsecs *= pmp->pm_BlkPerSec;
|
|
|
|
SecPerClust *= pmp->pm_BlkPerSec;
|
|
|
|
|
|
|
|
pmp->pm_fatblk = pmp->pm_ResSectors * pmp->pm_BlkPerSec;
|
|
|
|
|
1998-02-18 09:28:47 +00:00
|
|
|
if (FAT32(pmp)) {
|
|
|
|
pmp->pm_rootdirblk = getulong(b710->bpbRootClust);
|
|
|
|
pmp->pm_firstcluster = pmp->pm_fatblk
|
|
|
|
+ (pmp->pm_FATs * pmp->pm_FATsecs);
|
2000-01-27 14:43:07 +00:00
|
|
|
pmp->pm_fsinfo = getushort(b710->bpbFSInfo) * pmp->pm_BlkPerSec;
|
1998-02-18 09:28:47 +00:00
|
|
|
} else {
|
|
|
|
pmp->pm_rootdirblk = pmp->pm_fatblk +
|
|
|
|
(pmp->pm_FATs * pmp->pm_FATsecs);
|
|
|
|
pmp->pm_rootdirsize = (pmp->pm_RootDirEnts * sizeof(struct direntry)
|
2000-01-27 14:43:07 +00:00
|
|
|
+ DEV_BSIZE - 1)
|
|
|
|
/ DEV_BSIZE; /* in blocks */
|
1998-02-18 09:28:47 +00:00
|
|
|
pmp->pm_firstcluster = pmp->pm_rootdirblk + pmp->pm_rootdirsize;
|
|
|
|
}
|
|
|
|
|
1999-12-28 15:27:39 +00:00
|
|
|
pmp->pm_maxcluster = (pmp->pm_HugeSectors - pmp->pm_firstcluster) /
|
|
|
|
SecPerClust + 1;
|
2000-01-27 14:43:07 +00:00
|
|
|
pmp->pm_fatsize = pmp->pm_FATsecs * DEV_BSIZE; /* XXX not used? */
|
1998-02-18 09:28:47 +00:00
|
|
|
|
|
|
|
#ifndef __FreeBSD__
|
|
|
|
if (argp->flags & MSDOSFSMNT_GEMDOSFS) {
|
1999-12-28 15:27:39 +00:00
|
|
|
if ((pmp->pm_maxcluster <= (0xff0 - 2))
|
1998-02-18 09:28:47 +00:00
|
|
|
&& ((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)) {
|
|
|
|
/*
|
|
|
|
* This will usually be a floppy disk. This size makes
|
|
|
|
* sure that one fat entry will not be split across
|
|
|
|
* multiple blocks.
|
|
|
|
*/
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
1999-12-28 15:27:39 +00:00
|
|
|
|
|
|
|
clusters = (pmp->pm_fatsize / pmp->pm_fatmult) * pmp->pm_fatdiv;
|
|
|
|
if (pmp->pm_maxcluster >= clusters) {
|
|
|
|
printf("Warning: number of clusters (%ld) exceeds FAT "
|
|
|
|
"capacity (%ld)\n", pmp->pm_maxcluster + 1, clusters);
|
|
|
|
pmp->pm_maxcluster = clusters - 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1994-09-19 15:41:57 +00:00
|
|
|
if (FAT12(pmp))
|
|
|
|
pmp->pm_fatblocksize = 3 * pmp->pm_BytesPerSec;
|
|
|
|
else
|
2000-03-27 21:29:33 +00:00
|
|
|
pmp->pm_fatblocksize = MSDOSFS_DFLTBSIZE;
|
1994-09-19 15:41:57 +00:00
|
|
|
|
2000-01-27 14:43:07 +00:00
|
|
|
pmp->pm_fatblocksec = pmp->pm_fatblocksize / DEV_BSIZE;
|
|
|
|
pmp->pm_bnshift = ffs(DEV_BSIZE) - 1;
|
1994-09-19 15:41:57 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Compute mask and shift value for isolating cluster relative byte
|
|
|
|
* offsets and cluster numbers from a file offset.
|
|
|
|
*/
|
2000-01-27 14:43:07 +00:00
|
|
|
pmp->pm_bpcluster = SecPerClust * DEV_BSIZE;
|
1998-02-18 09:28:47 +00:00
|
|
|
pmp->pm_crbomask = pmp->pm_bpcluster - 1;
|
|
|
|
pmp->pm_cnshift = ffs(pmp->pm_bpcluster) - 1;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check for valid cluster size
|
|
|
|
* must be a power of 2
|
|
|
|
*/
|
|
|
|
if (pmp->pm_bpcluster ^ (1 << pmp->pm_cnshift)) {
|
1994-09-19 15:41:57 +00:00
|
|
|
error = EINVAL;
|
|
|
|
goto error_exit;
|
|
|
|
}
|
|
|
|
|
1998-02-18 09:28:47 +00:00
|
|
|
/*
|
|
|
|
* Release the bootsector buffer.
|
|
|
|
*/
|
|
|
|
brelse(bp);
|
|
|
|
bp = NULL;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check FSInfo.
|
|
|
|
*/
|
|
|
|
if (pmp->pm_fsinfo) {
|
|
|
|
struct fsinfo *fp;
|
|
|
|
|
2000-01-27 14:43:07 +00:00
|
|
|
if ((error = bread(devvp, pmp->pm_fsinfo, fsi_size(pmp),
|
|
|
|
NOCRED, &bp)) != 0)
|
1998-02-18 09:28:47 +00:00
|
|
|
goto error_exit;
|
|
|
|
fp = (struct fsinfo *)bp->b_data;
|
|
|
|
if (!bcmp(fp->fsisig1, "RRaA", 4)
|
|
|
|
&& !bcmp(fp->fsisig2, "rrAa", 4)
|
|
|
|
&& !bcmp(fp->fsisig3, "\0\0\125\252", 4)
|
|
|
|
&& !bcmp(fp->fsisig4, "\0\0\125\252", 4))
|
|
|
|
pmp->pm_nxtfree = getulong(fp->fsinxtfree);
|
|
|
|
else
|
|
|
|
pmp->pm_fsinfo = 0;
|
|
|
|
brelse(bp);
|
|
|
|
bp = NULL;
|
1996-06-14 11:02:28 +00:00
|
|
|
}
|
1994-09-19 15:41:57 +00:00
|
|
|
|
|
|
|
/*
|
1998-02-18 09:28:47 +00:00
|
|
|
* Check and validate (or perhaps invalidate?) the fsinfo structure? XXX
|
1994-09-19 15:41:57 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Allocate memory for the bitmap of allocated clusters, and then
|
|
|
|
* fill it in.
|
|
|
|
*/
|
|
|
|
pmp->pm_inusemap = malloc(((pmp->pm_maxcluster + N_INUSEBITS - 1)
|
|
|
|
/ N_INUSEBITS)
|
|
|
|
* sizeof(*pmp->pm_inusemap),
|
|
|
|
M_MSDOSFSFAT, M_WAITOK);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* fillinusemap() needs pm_devvp.
|
|
|
|
*/
|
|
|
|
pmp->pm_dev = dev;
|
|
|
|
pmp->pm_devvp = devvp;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Have the inuse map filled in.
|
|
|
|
*/
|
1998-02-18 09:28:47 +00:00
|
|
|
if ((error = fillinusemap(pmp)) != 0)
|
1994-09-19 15:41:57 +00: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.
|
|
|
|
*/
|
1998-02-18 09:28:47 +00:00
|
|
|
if (mp->mnt_flag & MNT_SYNCHRONOUS)
|
|
|
|
pmp->pm_flags |= MSDOSFSMNT_WAITONFAT;
|
1994-09-19 15:41:57 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Finish up.
|
|
|
|
*/
|
1998-02-18 09:28:47 +00:00
|
|
|
if (ronly)
|
|
|
|
pmp->pm_flags |= MSDOSFSMNT_RONLY;
|
|
|
|
else
|
1994-09-19 15:41:57 +00:00
|
|
|
pmp->pm_fmod = 1;
|
|
|
|
mp->mnt_data = (qaddr_t) pmp;
|
1999-08-23 21:07:13 +00:00
|
|
|
mp->mnt_stat.f_fsid.val[0] = dev2udev(dev);
|
1997-02-26 14:23:16 +00:00
|
|
|
mp->mnt_stat.f_fsid.val[1] = mp->mnt_vfc->vfc_typenum;
|
1997-03-18 19:50:12 +00:00
|
|
|
mp->mnt_flag |= MNT_LOCAL;
|
2000-10-09 17:31:39 +00:00
|
|
|
devvp->v_rdev->si_mountpoint = mp;
|
1994-09-19 15:41:57 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
1998-02-18 09:28:47 +00:00
|
|
|
error_exit:
|
|
|
|
if (bp)
|
|
|
|
brelse(bp);
|
|
|
|
(void) VOP_CLOSE(devvp, ronly ? FREAD : FREAD | FWRITE, NOCRED, p);
|
1994-09-19 15:41:57 +00:00
|
|
|
if (pmp) {
|
|
|
|
if (pmp->pm_inusemap)
|
1998-02-18 09:28:47 +00:00
|
|
|
free(pmp->pm_inusemap, M_MSDOSFSFAT);
|
|
|
|
free(pmp, M_MSDOSFSMNT);
|
|
|
|
mp->mnt_data = (qaddr_t)0;
|
1994-09-19 15:41:57 +00:00
|
|
|
}
|
1998-02-18 09:28:47 +00:00
|
|
|
return (error);
|
1994-09-19 15:41:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Unmount the filesystem described by mp.
|
|
|
|
*/
|
1995-11-07 14:06:45 +00:00
|
|
|
static int
|
1994-09-19 15:41:57 +00:00
|
|
|
msdosfs_unmount(mp, mntflags, p)
|
|
|
|
struct mount *mp;
|
|
|
|
int mntflags;
|
|
|
|
struct proc *p;
|
|
|
|
{
|
1998-02-18 09:28:47 +00:00
|
|
|
struct msdosfsmount *pmp;
|
|
|
|
int error, flags;
|
1994-09-19 15:41:57 +00:00
|
|
|
|
1998-02-18 09:28:47 +00:00
|
|
|
flags = 0;
|
|
|
|
if (mntflags & MNT_FORCE)
|
1994-09-19 15:41:57 +00:00
|
|
|
flags |= FORCECLOSE;
|
1994-09-27 20:42:59 +00:00
|
|
|
error = vflush(mp, NULLVP, flags);
|
|
|
|
if (error)
|
1994-09-19 15:41:57 +00:00
|
|
|
return error;
|
1998-02-18 09:28:47 +00:00
|
|
|
pmp = VFSTOMSDOSFS(mp);
|
2000-10-09 17:31:39 +00:00
|
|
|
pmp->pm_devvp->v_rdev->si_mountpoint = NULL;
|
1998-02-18 09:28:47 +00:00
|
|
|
#ifdef MSDOSFS_DEBUG
|
|
|
|
{
|
|
|
|
struct vnode *vp = pmp->pm_devvp;
|
|
|
|
|
|
|
|
printf("msdosfs_umount(): just before calling VOP_CLOSE()\n");
|
|
|
|
printf("flag %08lx, usecount %d, writecount %d, holdcnt %ld\n",
|
|
|
|
vp->v_flag, vp->v_usecount, vp->v_writecount, vp->v_holdcnt);
|
1999-09-20 23:27:58 +00:00
|
|
|
printf("id %lu, mount %p, op %p\n",
|
|
|
|
vp->v_id, vp->v_mount, vp->v_op);
|
1998-02-18 09:28:47 +00:00
|
|
|
printf("freef %p, freeb %p, mount %p\n",
|
2001-02-04 13:13:25 +00:00
|
|
|
TAILQ_NEXT(vp, v_freelist), vp->v_freelist.tqe_prev,
|
1998-02-18 09:28:47 +00:00
|
|
|
vp->v_mount);
|
|
|
|
printf("cleanblkhd %p, dirtyblkhd %p, numoutput %ld, type %d\n",
|
1998-10-31 15:31:29 +00:00
|
|
|
TAILQ_FIRST(&vp->v_cleanblkhd),
|
|
|
|
TAILQ_FIRST(&vp->v_dirtyblkhd),
|
1998-02-18 09:28:47 +00:00
|
|
|
vp->v_numoutput, vp->v_type);
|
|
|
|
printf("union %p, tag %d, data[0] %08x, data[1] %08x\n",
|
|
|
|
vp->v_socket, vp->v_tag,
|
|
|
|
((u_int *)vp->v_data)[0],
|
|
|
|
((u_int *)vp->v_data)[1]);
|
|
|
|
}
|
|
|
|
#endif
|
1998-03-08 09:59:44 +00:00
|
|
|
error = VOP_CLOSE(pmp->pm_devvp,
|
|
|
|
(pmp->pm_flags&MSDOSFSMNT_RONLY) ? FREAD : FREAD | FWRITE,
|
|
|
|
NOCRED, p);
|
1994-09-19 15:41:57 +00:00
|
|
|
vrele(pmp->pm_devvp);
|
1998-02-18 09:28:47 +00:00
|
|
|
free(pmp->pm_inusemap, M_MSDOSFSFAT);
|
|
|
|
free(pmp, M_MSDOSFSMNT);
|
|
|
|
mp->mnt_data = (qaddr_t)0;
|
1997-03-18 19:50:12 +00:00
|
|
|
mp->mnt_flag &= ~MNT_LOCAL;
|
1998-02-18 09:28:47 +00:00
|
|
|
return (error);
|
1994-09-19 15:41:57 +00:00
|
|
|
}
|
|
|
|
|
1995-11-07 14:06:45 +00:00
|
|
|
static int
|
1994-09-19 15:41:57 +00:00
|
|
|
msdosfs_root(mp, vpp)
|
|
|
|
struct mount *mp;
|
|
|
|
struct vnode **vpp;
|
|
|
|
{
|
1998-02-18 09:28:47 +00:00
|
|
|
struct msdosfsmount *pmp = VFSTOMSDOSFS(mp);
|
1994-09-19 15:41:57 +00:00
|
|
|
struct denode *ndep;
|
|
|
|
int error;
|
|
|
|
|
|
|
|
#ifdef MSDOSFS_DEBUG
|
1998-02-18 09:28:47 +00:00
|
|
|
printf("msdosfs_root(); mp %p, pmp %p\n", mp, pmp);
|
1994-09-19 15:41:57 +00:00
|
|
|
#endif
|
1998-02-18 09:28:47 +00:00
|
|
|
error = deget(pmp, MSDOSFSROOT, MSDOSFSROOT_OFS, &ndep);
|
|
|
|
if (error)
|
|
|
|
return (error);
|
|
|
|
*vpp = DETOV(ndep);
|
|
|
|
return (0);
|
1994-09-19 15:41:57 +00:00
|
|
|
}
|
|
|
|
|
1995-11-07 14:06:45 +00:00
|
|
|
static int
|
1994-09-19 15:41:57 +00:00
|
|
|
msdosfs_statfs(mp, sbp, p)
|
|
|
|
struct mount *mp;
|
|
|
|
struct statfs *sbp;
|
|
|
|
struct proc *p;
|
|
|
|
{
|
1998-02-18 09:28:47 +00:00
|
|
|
struct msdosfsmount *pmp;
|
1994-09-19 15:41:57 +00:00
|
|
|
|
1998-02-18 09:28:47 +00:00
|
|
|
pmp = VFSTOMSDOSFS(mp);
|
1994-09-19 15:41:57 +00:00
|
|
|
sbp->f_bsize = pmp->pm_bpcluster;
|
|
|
|
sbp->f_iosize = pmp->pm_bpcluster;
|
1999-12-28 15:27:39 +00:00
|
|
|
sbp->f_blocks = pmp->pm_maxcluster + 1;
|
1994-09-19 15:41:57 +00:00
|
|
|
sbp->f_bfree = pmp->pm_freeclustercount;
|
|
|
|
sbp->f_bavail = pmp->pm_freeclustercount;
|
|
|
|
sbp->f_files = pmp->pm_RootDirEnts; /* XXX */
|
|
|
|
sbp->f_ffree = 0; /* what to put in here? */
|
|
|
|
if (sbp != &mp->mnt_stat) {
|
1997-02-26 14:23:16 +00:00
|
|
|
sbp->f_type = mp->mnt_vfc->vfc_typenum;
|
1998-02-18 09:28:47 +00:00
|
|
|
bcopy(mp->mnt_stat.f_mntonname, sbp->f_mntonname, MNAMELEN);
|
|
|
|
bcopy(mp->mnt_stat.f_mntfromname, sbp->f_mntfromname, MNAMELEN);
|
1994-09-19 15:41:57 +00:00
|
|
|
}
|
1998-02-18 09:28:47 +00:00
|
|
|
strncpy(sbp->f_fstypename, mp->mnt_vfc->vfc_name, MFSNAMELEN);
|
|
|
|
return (0);
|
1994-09-19 15:41:57 +00:00
|
|
|
}
|
|
|
|
|
1995-11-07 14:06:45 +00:00
|
|
|
static int
|
1994-09-19 15:41:57 +00:00
|
|
|
msdosfs_sync(mp, waitfor, cred, p)
|
|
|
|
struct mount *mp;
|
|
|
|
int waitfor;
|
|
|
|
struct ucred *cred;
|
|
|
|
struct proc *p;
|
|
|
|
{
|
1998-02-18 09:28:47 +00:00
|
|
|
struct vnode *vp, *nvp;
|
1994-09-19 15:41:57 +00:00
|
|
|
struct denode *dep;
|
1998-02-18 09:28:47 +00:00
|
|
|
struct msdosfsmount *pmp = VFSTOMSDOSFS(mp);
|
|
|
|
int error, allerror = 0;
|
1994-09-19 15:41:57 +00: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.
|
|
|
|
*/
|
1999-05-06 18:13:11 +00:00
|
|
|
if (pmp->pm_fmod != 0) {
|
1998-02-18 09:28:47 +00:00
|
|
|
if (pmp->pm_flags & MSDOSFSMNT_RONLY)
|
1994-09-19 15:41:57 +00:00
|
|
|
panic("msdosfs_sync: rofs mod");
|
|
|
|
else {
|
|
|
|
/* update fats here */
|
|
|
|
}
|
1999-05-06 18:13:11 +00:00
|
|
|
}
|
1994-09-19 15:41:57 +00:00
|
|
|
/*
|
1998-02-18 09:28:47 +00:00
|
|
|
* Write back each (modified) denode.
|
1994-09-19 15:41:57 +00:00
|
|
|
*/
|
Change and clean the mutex lock interface.
mtx_enter(lock, type) becomes:
mtx_lock(lock) for sleep locks (MTX_DEF-initialized locks)
mtx_lock_spin(lock) for spin locks (MTX_SPIN-initialized)
similarily, for releasing a lock, we now have:
mtx_unlock(lock) for MTX_DEF and mtx_unlock_spin(lock) for MTX_SPIN.
We change the caller interface for the two different types of locks
because the semantics are entirely different for each case, and this
makes it explicitly clear and, at the same time, it rids us of the
extra `type' argument.
The enter->lock and exit->unlock change has been made with the idea
that we're "locking data" and not "entering locked code" in mind.
Further, remove all additional "flags" previously passed to the
lock acquire/release routines with the exception of two:
MTX_QUIET and MTX_NOSWITCH
The functionality of these flags is preserved and they can be passed
to the lock/unlock routines by calling the corresponding wrappers:
mtx_{lock, unlock}_flags(lock, flag(s)) and
mtx_{lock, unlock}_spin_flags(lock, flag(s)) for MTX_DEF and MTX_SPIN
locks, respectively.
Re-inline some lock acq/rel code; in the sleep lock case, we only
inline the _obtain_lock()s in order to ensure that the inlined code
fits into a cache line. In the spin lock case, we inline recursion and
actually only perform a function call if we need to spin. This change
has been made with the idea that we generally tend to avoid spin locks
and that also the spin locks that we do have and are heavily used
(i.e. sched_lock) do recurse, and therefore in an effort to reduce
function call overhead for some architectures (such as alpha), we
inline recursion for this case.
Create a new malloc type for the witness code and retire from using
the M_DEV type. The new type is called M_WITNESS and is only declared
if WITNESS is enabled.
Begin cleaning up some machdep/mutex.h code - specifically updated the
"optimized" inlined code in alpha/mutex.h and wrote MTX_LOCK_SPIN
and MTX_UNLOCK_SPIN asm macros for the i386/mutex.h as we presently
need those.
Finally, caught up to the interface changes in all sys code.
Contributors: jake, jhb, jasone (in no particular order)
2001-02-09 06:11:45 +00:00
|
|
|
mtx_lock(&mntvnode_mtx);
|
1994-09-19 15:41:57 +00:00
|
|
|
loop:
|
2000-12-31 10:24:19 +00:00
|
|
|
for (vp = LIST_FIRST(&mp->mnt_vnodelist); vp != NULL; vp = nvp) {
|
1998-02-18 09:28:47 +00:00
|
|
|
/*
|
|
|
|
* If the vnode that we are about to sync is no longer
|
1998-04-29 12:55:51 +00:00
|
|
|
* associated with this mount point, start over.
|
1998-02-18 09:28:47 +00:00
|
|
|
*/
|
|
|
|
if (vp->v_mount != mp)
|
1994-09-19 15:41:57 +00:00
|
|
|
goto loop;
|
1998-02-18 09:28:47 +00:00
|
|
|
|
Change and clean the mutex lock interface.
mtx_enter(lock, type) becomes:
mtx_lock(lock) for sleep locks (MTX_DEF-initialized locks)
mtx_lock_spin(lock) for spin locks (MTX_SPIN-initialized)
similarily, for releasing a lock, we now have:
mtx_unlock(lock) for MTX_DEF and mtx_unlock_spin(lock) for MTX_SPIN.
We change the caller interface for the two different types of locks
because the semantics are entirely different for each case, and this
makes it explicitly clear and, at the same time, it rids us of the
extra `type' argument.
The enter->lock and exit->unlock change has been made with the idea
that we're "locking data" and not "entering locked code" in mind.
Further, remove all additional "flags" previously passed to the
lock acquire/release routines with the exception of two:
MTX_QUIET and MTX_NOSWITCH
The functionality of these flags is preserved and they can be passed
to the lock/unlock routines by calling the corresponding wrappers:
mtx_{lock, unlock}_flags(lock, flag(s)) and
mtx_{lock, unlock}_spin_flags(lock, flag(s)) for MTX_DEF and MTX_SPIN
locks, respectively.
Re-inline some lock acq/rel code; in the sleep lock case, we only
inline the _obtain_lock()s in order to ensure that the inlined code
fits into a cache line. In the spin lock case, we inline recursion and
actually only perform a function call if we need to spin. This change
has been made with the idea that we generally tend to avoid spin locks
and that also the spin locks that we do have and are heavily used
(i.e. sched_lock) do recurse, and therefore in an effort to reduce
function call overhead for some architectures (such as alpha), we
inline recursion for this case.
Create a new malloc type for the witness code and retire from using
the M_DEV type. The new type is called M_WITNESS and is only declared
if WITNESS is enabled.
Begin cleaning up some machdep/mutex.h code - specifically updated the
"optimized" inlined code in alpha/mutex.h and wrote MTX_LOCK_SPIN
and MTX_UNLOCK_SPIN asm macros for the i386/mutex.h as we presently
need those.
Finally, caught up to the interface changes in all sys code.
Contributors: jake, jhb, jasone (in no particular order)
2001-02-09 06:11:45 +00:00
|
|
|
mtx_lock(&vp->v_interlock);
|
2000-12-31 10:24:19 +00:00
|
|
|
nvp = LIST_NEXT(vp, v_mntvnodes);
|
1994-09-19 15:41:57 +00:00
|
|
|
dep = VTODE(vp);
|
1998-04-29 12:55:51 +00:00
|
|
|
if (vp->v_type == VNON ||
|
1999-01-27 22:42:27 +00:00
|
|
|
((dep->de_flag &
|
1998-04-29 12:55:51 +00:00
|
|
|
(DE_ACCESS | DE_CREATE | DE_UPDATE | DE_MODIFIED)) == 0 &&
|
1999-01-27 22:42:27 +00:00
|
|
|
(TAILQ_EMPTY(&vp->v_dirtyblkhd) || waitfor == MNT_LAZY))) {
|
Change and clean the mutex lock interface.
mtx_enter(lock, type) becomes:
mtx_lock(lock) for sleep locks (MTX_DEF-initialized locks)
mtx_lock_spin(lock) for spin locks (MTX_SPIN-initialized)
similarily, for releasing a lock, we now have:
mtx_unlock(lock) for MTX_DEF and mtx_unlock_spin(lock) for MTX_SPIN.
We change the caller interface for the two different types of locks
because the semantics are entirely different for each case, and this
makes it explicitly clear and, at the same time, it rids us of the
extra `type' argument.
The enter->lock and exit->unlock change has been made with the idea
that we're "locking data" and not "entering locked code" in mind.
Further, remove all additional "flags" previously passed to the
lock acquire/release routines with the exception of two:
MTX_QUIET and MTX_NOSWITCH
The functionality of these flags is preserved and they can be passed
to the lock/unlock routines by calling the corresponding wrappers:
mtx_{lock, unlock}_flags(lock, flag(s)) and
mtx_{lock, unlock}_spin_flags(lock, flag(s)) for MTX_DEF and MTX_SPIN
locks, respectively.
Re-inline some lock acq/rel code; in the sleep lock case, we only
inline the _obtain_lock()s in order to ensure that the inlined code
fits into a cache line. In the spin lock case, we inline recursion and
actually only perform a function call if we need to spin. This change
has been made with the idea that we generally tend to avoid spin locks
and that also the spin locks that we do have and are heavily used
(i.e. sched_lock) do recurse, and therefore in an effort to reduce
function call overhead for some architectures (such as alpha), we
inline recursion for this case.
Create a new malloc type for the witness code and retire from using
the M_DEV type. The new type is called M_WITNESS and is only declared
if WITNESS is enabled.
Begin cleaning up some machdep/mutex.h code - specifically updated the
"optimized" inlined code in alpha/mutex.h and wrote MTX_LOCK_SPIN
and MTX_UNLOCK_SPIN asm macros for the i386/mutex.h as we presently
need those.
Finally, caught up to the interface changes in all sys code.
Contributors: jake, jhb, jasone (in no particular order)
2001-02-09 06:11:45 +00:00
|
|
|
mtx_unlock(&vp->v_interlock);
|
1994-09-19 15:41:57 +00:00
|
|
|
continue;
|
1997-02-26 14:23:16 +00:00
|
|
|
}
|
Change and clean the mutex lock interface.
mtx_enter(lock, type) becomes:
mtx_lock(lock) for sleep locks (MTX_DEF-initialized locks)
mtx_lock_spin(lock) for spin locks (MTX_SPIN-initialized)
similarily, for releasing a lock, we now have:
mtx_unlock(lock) for MTX_DEF and mtx_unlock_spin(lock) for MTX_SPIN.
We change the caller interface for the two different types of locks
because the semantics are entirely different for each case, and this
makes it explicitly clear and, at the same time, it rids us of the
extra `type' argument.
The enter->lock and exit->unlock change has been made with the idea
that we're "locking data" and not "entering locked code" in mind.
Further, remove all additional "flags" previously passed to the
lock acquire/release routines with the exception of two:
MTX_QUIET and MTX_NOSWITCH
The functionality of these flags is preserved and they can be passed
to the lock/unlock routines by calling the corresponding wrappers:
mtx_{lock, unlock}_flags(lock, flag(s)) and
mtx_{lock, unlock}_spin_flags(lock, flag(s)) for MTX_DEF and MTX_SPIN
locks, respectively.
Re-inline some lock acq/rel code; in the sleep lock case, we only
inline the _obtain_lock()s in order to ensure that the inlined code
fits into a cache line. In the spin lock case, we inline recursion and
actually only perform a function call if we need to spin. This change
has been made with the idea that we generally tend to avoid spin locks
and that also the spin locks that we do have and are heavily used
(i.e. sched_lock) do recurse, and therefore in an effort to reduce
function call overhead for some architectures (such as alpha), we
inline recursion for this case.
Create a new malloc type for the witness code and retire from using
the M_DEV type. The new type is called M_WITNESS and is only declared
if WITNESS is enabled.
Begin cleaning up some machdep/mutex.h code - specifically updated the
"optimized" inlined code in alpha/mutex.h and wrote MTX_LOCK_SPIN
and MTX_UNLOCK_SPIN asm macros for the i386/mutex.h as we presently
need those.
Finally, caught up to the interface changes in all sys code.
Contributors: jake, jhb, jasone (in no particular order)
2001-02-09 06:11:45 +00:00
|
|
|
mtx_unlock(&mntvnode_mtx);
|
1997-02-26 14:23:16 +00:00
|
|
|
error = vget(vp, LK_EXCLUSIVE | LK_NOWAIT | LK_INTERLOCK, p);
|
|
|
|
if (error) {
|
Change and clean the mutex lock interface.
mtx_enter(lock, type) becomes:
mtx_lock(lock) for sleep locks (MTX_DEF-initialized locks)
mtx_lock_spin(lock) for spin locks (MTX_SPIN-initialized)
similarily, for releasing a lock, we now have:
mtx_unlock(lock) for MTX_DEF and mtx_unlock_spin(lock) for MTX_SPIN.
We change the caller interface for the two different types of locks
because the semantics are entirely different for each case, and this
makes it explicitly clear and, at the same time, it rids us of the
extra `type' argument.
The enter->lock and exit->unlock change has been made with the idea
that we're "locking data" and not "entering locked code" in mind.
Further, remove all additional "flags" previously passed to the
lock acquire/release routines with the exception of two:
MTX_QUIET and MTX_NOSWITCH
The functionality of these flags is preserved and they can be passed
to the lock/unlock routines by calling the corresponding wrappers:
mtx_{lock, unlock}_flags(lock, flag(s)) and
mtx_{lock, unlock}_spin_flags(lock, flag(s)) for MTX_DEF and MTX_SPIN
locks, respectively.
Re-inline some lock acq/rel code; in the sleep lock case, we only
inline the _obtain_lock()s in order to ensure that the inlined code
fits into a cache line. In the spin lock case, we inline recursion and
actually only perform a function call if we need to spin. This change
has been made with the idea that we generally tend to avoid spin locks
and that also the spin locks that we do have and are heavily used
(i.e. sched_lock) do recurse, and therefore in an effort to reduce
function call overhead for some architectures (such as alpha), we
inline recursion for this case.
Create a new malloc type for the witness code and retire from using
the M_DEV type. The new type is called M_WITNESS and is only declared
if WITNESS is enabled.
Begin cleaning up some machdep/mutex.h code - specifically updated the
"optimized" inlined code in alpha/mutex.h and wrote MTX_LOCK_SPIN
and MTX_UNLOCK_SPIN asm macros for the i386/mutex.h as we presently
need those.
Finally, caught up to the interface changes in all sys code.
Contributors: jake, jhb, jasone (in no particular order)
2001-02-09 06:11:45 +00:00
|
|
|
mtx_lock(&mntvnode_mtx);
|
1997-02-26 14:23:16 +00:00
|
|
|
if (error == ENOENT)
|
|
|
|
goto loop;
|
|
|
|
continue;
|
|
|
|
}
|
1994-09-27 20:42:59 +00:00
|
|
|
error = VOP_FSYNC(vp, cred, waitfor, p);
|
|
|
|
if (error)
|
1994-09-19 15:41:57 +00:00
|
|
|
allerror = error;
|
1997-02-26 14:23:16 +00:00
|
|
|
VOP_UNLOCK(vp, 0, p);
|
1998-04-29 12:55:51 +00:00
|
|
|
vrele(vp);
|
Change and clean the mutex lock interface.
mtx_enter(lock, type) becomes:
mtx_lock(lock) for sleep locks (MTX_DEF-initialized locks)
mtx_lock_spin(lock) for spin locks (MTX_SPIN-initialized)
similarily, for releasing a lock, we now have:
mtx_unlock(lock) for MTX_DEF and mtx_unlock_spin(lock) for MTX_SPIN.
We change the caller interface for the two different types of locks
because the semantics are entirely different for each case, and this
makes it explicitly clear and, at the same time, it rids us of the
extra `type' argument.
The enter->lock and exit->unlock change has been made with the idea
that we're "locking data" and not "entering locked code" in mind.
Further, remove all additional "flags" previously passed to the
lock acquire/release routines with the exception of two:
MTX_QUIET and MTX_NOSWITCH
The functionality of these flags is preserved and they can be passed
to the lock/unlock routines by calling the corresponding wrappers:
mtx_{lock, unlock}_flags(lock, flag(s)) and
mtx_{lock, unlock}_spin_flags(lock, flag(s)) for MTX_DEF and MTX_SPIN
locks, respectively.
Re-inline some lock acq/rel code; in the sleep lock case, we only
inline the _obtain_lock()s in order to ensure that the inlined code
fits into a cache line. In the spin lock case, we inline recursion and
actually only perform a function call if we need to spin. This change
has been made with the idea that we generally tend to avoid spin locks
and that also the spin locks that we do have and are heavily used
(i.e. sched_lock) do recurse, and therefore in an effort to reduce
function call overhead for some architectures (such as alpha), we
inline recursion for this case.
Create a new malloc type for the witness code and retire from using
the M_DEV type. The new type is called M_WITNESS and is only declared
if WITNESS is enabled.
Begin cleaning up some machdep/mutex.h code - specifically updated the
"optimized" inlined code in alpha/mutex.h and wrote MTX_LOCK_SPIN
and MTX_UNLOCK_SPIN asm macros for the i386/mutex.h as we presently
need those.
Finally, caught up to the interface changes in all sys code.
Contributors: jake, jhb, jasone (in no particular order)
2001-02-09 06:11:45 +00:00
|
|
|
mtx_lock(&mntvnode_mtx);
|
1994-09-19 15:41:57 +00:00
|
|
|
}
|
Change and clean the mutex lock interface.
mtx_enter(lock, type) becomes:
mtx_lock(lock) for sleep locks (MTX_DEF-initialized locks)
mtx_lock_spin(lock) for spin locks (MTX_SPIN-initialized)
similarily, for releasing a lock, we now have:
mtx_unlock(lock) for MTX_DEF and mtx_unlock_spin(lock) for MTX_SPIN.
We change the caller interface for the two different types of locks
because the semantics are entirely different for each case, and this
makes it explicitly clear and, at the same time, it rids us of the
extra `type' argument.
The enter->lock and exit->unlock change has been made with the idea
that we're "locking data" and not "entering locked code" in mind.
Further, remove all additional "flags" previously passed to the
lock acquire/release routines with the exception of two:
MTX_QUIET and MTX_NOSWITCH
The functionality of these flags is preserved and they can be passed
to the lock/unlock routines by calling the corresponding wrappers:
mtx_{lock, unlock}_flags(lock, flag(s)) and
mtx_{lock, unlock}_spin_flags(lock, flag(s)) for MTX_DEF and MTX_SPIN
locks, respectively.
Re-inline some lock acq/rel code; in the sleep lock case, we only
inline the _obtain_lock()s in order to ensure that the inlined code
fits into a cache line. In the spin lock case, we inline recursion and
actually only perform a function call if we need to spin. This change
has been made with the idea that we generally tend to avoid spin locks
and that also the spin locks that we do have and are heavily used
(i.e. sched_lock) do recurse, and therefore in an effort to reduce
function call overhead for some architectures (such as alpha), we
inline recursion for this case.
Create a new malloc type for the witness code and retire from using
the M_DEV type. The new type is called M_WITNESS and is only declared
if WITNESS is enabled.
Begin cleaning up some machdep/mutex.h code - specifically updated the
"optimized" inlined code in alpha/mutex.h and wrote MTX_LOCK_SPIN
and MTX_UNLOCK_SPIN asm macros for the i386/mutex.h as we presently
need those.
Finally, caught up to the interface changes in all sys code.
Contributors: jake, jhb, jasone (in no particular order)
2001-02-09 06:11:45 +00:00
|
|
|
mtx_unlock(&mntvnode_mtx);
|
1994-09-19 15:41:57 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Flush filesystem control info.
|
|
|
|
*/
|
1998-04-29 12:55:51 +00:00
|
|
|
if (waitfor != MNT_LAZY) {
|
|
|
|
vn_lock(pmp->pm_devvp, LK_EXCLUSIVE | LK_RETRY, p);
|
|
|
|
error = VOP_FSYNC(pmp->pm_devvp, cred, waitfor, p);
|
|
|
|
if (error)
|
|
|
|
allerror = error;
|
|
|
|
VOP_UNLOCK(pmp->pm_devvp, 0, p);
|
|
|
|
}
|
1998-02-18 09:28:47 +00:00
|
|
|
return (allerror);
|
1994-09-19 15:41:57 +00:00
|
|
|
}
|
|
|
|
|
1995-11-07 14:06:45 +00:00
|
|
|
static int
|
1999-09-11 00:46:08 +00:00
|
|
|
msdosfs_fhtovp(mp, fhp, vpp)
|
1994-09-19 15:41:57 +00:00
|
|
|
struct mount *mp;
|
|
|
|
struct fid *fhp;
|
|
|
|
struct vnode **vpp;
|
|
|
|
{
|
1998-02-18 09:28:47 +00:00
|
|
|
struct msdosfsmount *pmp = VFSTOMSDOSFS(mp);
|
1994-09-19 15:41:57 +00:00
|
|
|
struct defid *defhp = (struct defid *) fhp;
|
|
|
|
struct denode *dep;
|
|
|
|
int error;
|
|
|
|
|
1998-02-18 09:28:47 +00:00
|
|
|
error = deget(pmp, defhp->defid_dirclust, defhp->defid_dirofs, &dep);
|
1994-09-19 15:41:57 +00:00
|
|
|
if (error) {
|
|
|
|
*vpp = NULLVP;
|
1998-02-18 09:28:47 +00:00
|
|
|
return (error);
|
1994-09-19 15:41:57 +00:00
|
|
|
}
|
|
|
|
*vpp = DETOV(dep);
|
1999-09-11 00:46:08 +00:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
msdosfs_checkexp(mp, nam, exflagsp, credanonp)
|
|
|
|
struct mount *mp;
|
|
|
|
struct sockaddr *nam;
|
|
|
|
int *exflagsp;
|
|
|
|
struct ucred **credanonp;
|
|
|
|
{
|
|
|
|
struct msdosfsmount *pmp = VFSTOMSDOSFS(mp);
|
|
|
|
struct netcred *np;
|
|
|
|
|
|
|
|
np = vfs_export_lookup(mp, &pmp->pm_export, nam);
|
|
|
|
if (np == NULL)
|
|
|
|
return (EACCES);
|
1994-09-19 15:41:57 +00:00
|
|
|
*exflagsp = np->netc_exflags;
|
|
|
|
*credanonp = &np->netc_anon;
|
1998-02-18 09:28:47 +00:00
|
|
|
return (0);
|
1994-09-19 15:41:57 +00:00
|
|
|
}
|
|
|
|
|
1995-11-07 14:06:45 +00:00
|
|
|
static int
|
1994-09-19 15:41:57 +00:00
|
|
|
msdosfs_vptofh(vp, fhp)
|
|
|
|
struct vnode *vp;
|
|
|
|
struct fid *fhp;
|
|
|
|
{
|
1998-02-18 09:28:47 +00:00
|
|
|
struct denode *dep;
|
|
|
|
struct defid *defhp;
|
1994-09-19 15:41:57 +00:00
|
|
|
|
1998-02-18 09:28:47 +00:00
|
|
|
dep = VTODE(vp);
|
|
|
|
defhp = (struct defid *)fhp;
|
1994-09-19 15:41:57 +00:00
|
|
|
defhp->defid_len = sizeof(struct defid);
|
|
|
|
defhp->defid_dirclust = dep->de_dirclust;
|
|
|
|
defhp->defid_dirofs = dep->de_diroffset;
|
1998-02-18 09:28:47 +00:00
|
|
|
/* defhp->defid_gen = dep->de_gen; */
|
|
|
|
return (0);
|
1994-09-19 15:41:57 +00:00
|
|
|
}
|
|
|
|
|
1995-11-07 14:10:19 +00:00
|
|
|
static struct vfsops msdosfs_vfsops = {
|
1994-09-19 15:41:57 +00:00
|
|
|
msdosfs_mount,
|
1999-09-07 22:42:38 +00:00
|
|
|
vfs_stdstart,
|
1994-09-19 15:41:57 +00:00
|
|
|
msdosfs_unmount,
|
|
|
|
msdosfs_root,
|
1999-09-07 22:42:38 +00:00
|
|
|
vfs_stdquotactl,
|
1994-09-19 15:41:57 +00:00
|
|
|
msdosfs_statfs,
|
|
|
|
msdosfs_sync,
|
1999-09-07 22:42:38 +00:00
|
|
|
vfs_stdvget,
|
1994-09-19 15:41:57 +00:00
|
|
|
msdosfs_fhtovp,
|
1999-09-11 00:46:08 +00:00
|
|
|
msdosfs_checkexp,
|
1994-09-19 15:41:57 +00:00
|
|
|
msdosfs_vptofh,
|
1999-12-19 06:08:07 +00:00
|
|
|
msdosfs_init,
|
2000-06-29 01:12:47 +00:00
|
|
|
msdosfs_uninit,
|
1999-12-19 06:08:07 +00:00
|
|
|
vfs_stdextattrctl,
|
1994-09-19 15:41:57 +00:00
|
|
|
};
|
1994-09-21 03:47:43 +00:00
|
|
|
|
1998-09-07 13:17:06 +00:00
|
|
|
VFS_SET(msdosfs_vfsops, msdos, 0);
|