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
|
|
|
|
|
|
|
/*-
|
2017-11-27 15:15:37 +00:00
|
|
|
* SPDX-License-Identifier: BSD-4-Clause
|
|
|
|
*
|
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.
|
|
|
|
*/
|
2005-01-06 18:10:42 +00:00
|
|
|
/*-
|
1994-09-19 15:41:57 +00:00
|
|
|
* 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>
|
2007-08-07 02:27:35 +00:00
|
|
|
#include <sys/buf.h>
|
1998-10-25 19:26:18 +00:00
|
|
|
#include <sys/conf.h>
|
2008-03-31 12:01:21 +00:00
|
|
|
#include <sys/fcntl.h>
|
2007-08-07 02:27:35 +00:00
|
|
|
#include <sys/iconv.h>
|
|
|
|
#include <sys/kernel.h>
|
2007-08-07 01:37:59 +00:00
|
|
|
#include <sys/lock.h>
|
2007-08-07 02:27:35 +00:00
|
|
|
#include <sys/malloc.h>
|
|
|
|
#include <sys/mount.h>
|
2007-08-07 01:37:59 +00:00
|
|
|
#include <sys/mutex.h>
|
1994-09-19 15:41:57 +00:00
|
|
|
#include <sys/namei.h>
|
2006-11-06 13:42:10 +00:00
|
|
|
#include <sys/priv.h>
|
1994-09-19 15:41:57 +00:00
|
|
|
#include <sys/proc.h>
|
2007-08-07 02:27:35 +00:00
|
|
|
#include <sys/stat.h>
|
1994-09-19 15:41:57 +00:00
|
|
|
#include <sys/vnode.h>
|
2000-10-04 01:29:17 +00:00
|
|
|
|
2007-08-07 02:27:35 +00:00
|
|
|
#include <geom/geom.h>
|
|
|
|
#include <geom/geom_vfs.h>
|
|
|
|
|
2001-05-25 08:14:14 +00:00
|
|
|
#include <fs/msdosfs/bootsect.h>
|
2007-08-07 02:27:35 +00:00
|
|
|
#include <fs/msdosfs/bpb.h>
|
2001-05-25 08:14:14 +00:00
|
|
|
#include <fs/msdosfs/direntry.h>
|
|
|
|
#include <fs/msdosfs/denode.h>
|
|
|
|
#include <fs/msdosfs/fat.h>
|
2007-08-07 02:27:35 +00:00
|
|
|
#include <fs/msdosfs/msdosfsmount.h>
|
2004-10-29 10:40:14 +00:00
|
|
|
|
2017-10-19 12:55:11 +00:00
|
|
|
#ifdef MSDOSFS_DEBUG
|
|
|
|
#include <sys/rwlock.h>
|
|
|
|
#endif
|
|
|
|
|
2010-02-28 17:13:07 +00:00
|
|
|
static const char msdosfs_lock_msg[] = "fatlk";
|
|
|
|
|
2007-10-18 15:48:10 +00:00
|
|
|
/* Mount options that we support. */
|
2004-12-06 19:05:48 +00:00
|
|
|
static const char *msdosfs_opts[] = {
|
2007-10-19 12:23:25 +00:00
|
|
|
"async", "noatime", "noclusterr", "noclusterw",
|
2007-10-18 15:48:10 +00:00
|
|
|
"export", "force", "from", "sync",
|
|
|
|
"cs_dos", "cs_local", "cs_win", "dirmask",
|
2017-06-09 12:06:22 +00:00
|
|
|
"gid", "kiconv", "longname",
|
2007-10-18 15:48:10 +00:00
|
|
|
"longnames", "mask", "shortname", "shortnames",
|
|
|
|
"uid", "win95", "nowin95",
|
2004-12-06 19:05:48 +00:00
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
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
|
|
|
|
|
2005-10-31 15:41:29 +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
|
|
|
|
2007-08-07 03:38:36 +00:00
|
|
|
struct iconv_functions *msdosfs_iconv;
|
2003-09-26 20:26:25 +00:00
|
|
|
|
2004-12-06 19:05:48 +00:00
|
|
|
static int update_mp(struct mount *mp, struct thread *td);
|
2008-10-10 21:23:50 +00:00
|
|
|
static int mountmsdosfs(struct vnode *devvp, struct mount *mp);
|
2007-06-01 17:06:46 +00:00
|
|
|
static vfs_fhtovp_t msdosfs_fhtovp;
|
2004-12-06 19:05:48 +00:00
|
|
|
static vfs_mount_t msdosfs_mount;
|
2002-08-13 10:05:50 +00:00
|
|
|
static vfs_root_t msdosfs_root;
|
|
|
|
static vfs_statfs_t msdosfs_statfs;
|
|
|
|
static vfs_sync_t msdosfs_sync;
|
|
|
|
static vfs_unmount_t msdosfs_unmount;
|
1995-11-16 11:48:10 +00:00
|
|
|
|
2004-08-26 13:16:44 +00:00
|
|
|
/* Maximum length of a character set name (arbitrary). */
|
|
|
|
#define MAXCSLEN 64
|
|
|
|
|
1998-02-18 09:28:47 +00:00
|
|
|
static int
|
2007-02-08 02:25:35 +00:00
|
|
|
update_mp(struct mount *mp, struct thread *td)
|
1998-02-18 09:28:47 +00:00
|
|
|
{
|
|
|
|
struct msdosfsmount *pmp = VFSTOMSDOSFS(mp);
|
2004-12-06 19:05:48 +00:00
|
|
|
void *dos, *win, *local;
|
|
|
|
int error, v;
|
|
|
|
|
|
|
|
if (!vfs_getopt(mp->mnt_optnew, "kiconv", NULL, NULL)) {
|
|
|
|
if (msdosfs_iconv != NULL) {
|
|
|
|
error = vfs_getopt(mp->mnt_optnew,
|
|
|
|
"cs_win", &win, NULL);
|
|
|
|
if (!error)
|
|
|
|
error = vfs_getopt(mp->mnt_optnew,
|
|
|
|
"cs_local", &local, NULL);
|
|
|
|
if (!error)
|
|
|
|
error = vfs_getopt(mp->mnt_optnew,
|
|
|
|
"cs_dos", &dos, NULL);
|
|
|
|
if (!error) {
|
|
|
|
msdosfs_iconv->open(win, local, &pmp->pm_u2w);
|
|
|
|
msdosfs_iconv->open(local, win, &pmp->pm_w2u);
|
|
|
|
msdosfs_iconv->open(dos, local, &pmp->pm_u2d);
|
|
|
|
msdosfs_iconv->open(local, dos, &pmp->pm_d2u);
|
|
|
|
}
|
2004-08-26 13:16:44 +00:00
|
|
|
if (error != 0)
|
|
|
|
return (error);
|
|
|
|
} else {
|
|
|
|
pmp->pm_w2u = NULL;
|
|
|
|
pmp->pm_u2w = NULL;
|
|
|
|
pmp->pm_d2u = NULL;
|
|
|
|
pmp->pm_u2d = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-04 09:38:20 +00:00
|
|
|
if (vfs_scanopt(mp->mnt_optnew, "gid", "%d", &v) == 1)
|
2004-12-06 19:05:48 +00:00
|
|
|
pmp->pm_gid = v;
|
2012-03-04 09:38:20 +00:00
|
|
|
if (vfs_scanopt(mp->mnt_optnew, "uid", "%d", &v) == 1)
|
2004-12-06 19:05:48 +00:00
|
|
|
pmp->pm_uid = v;
|
2012-03-04 09:38:20 +00:00
|
|
|
if (vfs_scanopt(mp->mnt_optnew, "mask", "%d", &v) == 1)
|
2004-12-06 19:05:48 +00:00
|
|
|
pmp->pm_mask = v & ALLPERMS;
|
2012-03-04 09:38:20 +00:00
|
|
|
if (vfs_scanopt(mp->mnt_optnew, "dirmask", "%d", &v) == 1)
|
2004-12-06 19:05:48 +00:00
|
|
|
pmp->pm_dirmask = v & ALLPERMS;
|
|
|
|
vfs_flagopt(mp->mnt_optnew, "shortname",
|
|
|
|
&pmp->pm_flags, MSDOSFSMNT_SHORTNAME);
|
2005-11-18 22:34:31 +00:00
|
|
|
vfs_flagopt(mp->mnt_optnew, "shortnames",
|
|
|
|
&pmp->pm_flags, MSDOSFSMNT_SHORTNAME);
|
2004-12-06 19:05:48 +00:00
|
|
|
vfs_flagopt(mp->mnt_optnew, "longname",
|
|
|
|
&pmp->pm_flags, MSDOSFSMNT_LONGNAME);
|
2005-11-18 22:34:31 +00:00
|
|
|
vfs_flagopt(mp->mnt_optnew, "longnames",
|
|
|
|
&pmp->pm_flags, MSDOSFSMNT_LONGNAME);
|
2004-12-06 19:05:48 +00:00
|
|
|
vfs_flagopt(mp->mnt_optnew, "kiconv",
|
|
|
|
&pmp->pm_flags, MSDOSFSMNT_KICONV);
|
|
|
|
|
2005-11-19 16:38:39 +00:00
|
|
|
if (vfs_getopt(mp->mnt_optnew, "nowin95", NULL, NULL) == 0)
|
2004-12-06 19:05:48 +00:00
|
|
|
pmp->pm_flags |= MSDOSFSMNT_NOWIN95;
|
2005-11-19 16:38:39 +00:00
|
|
|
else
|
|
|
|
pmp->pm_flags &= ~MSDOSFSMNT_NOWIN95;
|
1998-02-18 09:28:47 +00:00
|
|
|
|
|
|
|
if (pmp->pm_flags & MSDOSFSMNT_NOWIN95)
|
|
|
|
pmp->pm_flags |= MSDOSFSMNT_SHORTNAME;
|
2016-09-23 19:05:07 +00:00
|
|
|
else
|
|
|
|
pmp->pm_flags |= MSDOSFSMNT_LONGNAME;
|
1998-02-18 09:28:47 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2004-12-06 19:05:48 +00:00
|
|
|
static int
|
2012-01-17 01:08:01 +00:00
|
|
|
msdosfs_cmount(struct mntarg *ma, void *data, uint64_t flags)
|
2004-12-06 19:05:48 +00:00
|
|
|
{
|
|
|
|
struct msdosfs_args args;
|
2010-10-10 07:05:47 +00:00
|
|
|
struct export_args exp;
|
2004-12-06 19:05:48 +00:00
|
|
|
int error;
|
|
|
|
|
|
|
|
if (data == NULL)
|
|
|
|
return (EINVAL);
|
|
|
|
error = copyin(data, &args, sizeof args);
|
|
|
|
if (error)
|
|
|
|
return (error);
|
2010-10-10 07:05:47 +00:00
|
|
|
vfs_oexport_conv(&args.export, &exp);
|
2004-12-06 19:05:48 +00:00
|
|
|
|
|
|
|
ma = mount_argsu(ma, "from", args.fspec, MAXPATHLEN);
|
2010-10-10 07:05:47 +00:00
|
|
|
ma = mount_arg(ma, "export", &exp, sizeof(exp));
|
2004-12-06 19:05:48 +00:00
|
|
|
ma = mount_argf(ma, "uid", "%d", args.uid);
|
|
|
|
ma = mount_argf(ma, "gid", "%d", args.gid);
|
|
|
|
ma = mount_argf(ma, "mask", "%d", args.mask);
|
|
|
|
ma = mount_argf(ma, "dirmask", "%d", args.dirmask);
|
|
|
|
|
2007-08-07 03:38:36 +00:00
|
|
|
ma = mount_argb(ma, args.flags & MSDOSFSMNT_SHORTNAME, "noshortname");
|
|
|
|
ma = mount_argb(ma, args.flags & MSDOSFSMNT_LONGNAME, "nolongname");
|
|
|
|
ma = mount_argb(ma, !(args.flags & MSDOSFSMNT_NOWIN95), "nowin95");
|
|
|
|
ma = mount_argb(ma, args.flags & MSDOSFSMNT_KICONV, "nokiconv");
|
2004-12-06 19:05:48 +00:00
|
|
|
|
2007-08-07 03:38:36 +00:00
|
|
|
ma = mount_argsu(ma, "cs_win", args.cs_win, MAXCSLEN);
|
|
|
|
ma = mount_argsu(ma, "cs_dos", args.cs_dos, MAXCSLEN);
|
|
|
|
ma = mount_argsu(ma, "cs_local", args.cs_local, MAXCSLEN);
|
2004-12-06 19:05:48 +00:00
|
|
|
|
|
|
|
error = kernel_mount(ma, flags);
|
|
|
|
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
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
|
2009-05-11 15:33:26 +00:00
|
|
|
msdosfs_mount(struct mount *mp)
|
1994-09-19 15:41:57 +00:00
|
|
|
{
|
|
|
|
struct vnode *devvp; /* vnode for blk device to mount */
|
2009-05-11 15:33:26 +00:00
|
|
|
struct thread *td;
|
1998-02-18 09:28:47 +00:00
|
|
|
/* msdosfs specific mount control block */
|
|
|
|
struct msdosfsmount *pmp = NULL;
|
2004-07-30 22:08:52 +00:00
|
|
|
struct nameidata ndp;
|
2004-12-11 20:37:48 +00:00
|
|
|
int error, flags;
|
2008-10-28 13:44:11 +00:00
|
|
|
accmode_t accmode;
|
2004-12-06 19:05:48 +00:00
|
|
|
char *from;
|
|
|
|
|
2009-05-11 15:33:26 +00:00
|
|
|
td = curthread;
|
2004-12-06 19:05:48 +00:00
|
|
|
if (vfs_filteropt(mp->mnt_optnew, msdosfs_opts))
|
|
|
|
return (EINVAL);
|
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) {
|
2007-08-07 03:38:36 +00:00
|
|
|
pmp = VFSTOMSDOSFS(mp);
|
2004-10-29 10:40:14 +00:00
|
|
|
if (!(pmp->pm_flags & MSDOSFSMNT_RONLY) &&
|
2004-12-06 19:05:48 +00:00
|
|
|
vfs_flagopt(mp->mnt_optnew, "ro", NULL, 0)) {
|
2009-05-11 15:33:26 +00:00
|
|
|
error = VFS_SYNC(mp, MNT_WAIT);
|
2004-08-07 22:05:12 +00:00
|
|
|
if (error)
|
|
|
|
return (error);
|
1994-09-19 15:41:57 +00:00
|
|
|
flags = WRITECLOSE;
|
|
|
|
if (mp->mnt_flag & MNT_FORCE)
|
|
|
|
flags |= FORCECLOSE;
|
2004-07-12 08:14:09 +00:00
|
|
|
error = vflush(mp, 0, flags, td);
|
2004-12-06 19:05:48 +00:00
|
|
|
if (error)
|
|
|
|
return (error);
|
2007-10-22 17:43:43 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Now the volume is clean. Mark it so while the
|
|
|
|
* device is still rw.
|
|
|
|
*/
|
|
|
|
error = markvoldirty(pmp, 0);
|
|
|
|
if (error) {
|
|
|
|
(void)markvoldirty(pmp, 1);
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Downgrade the device from rw to ro. */
|
2004-10-29 10:40:14 +00:00
|
|
|
g_topology_lock();
|
Make using msdosfs as the root file system sort of work:
o Initialize ownerships and permissions. They were garbage (0) for
root mounts since vfs_mountroot_try() doesn't ask for them to be set
and msdosfs's old incomplete code to set them was removed. The
garbage happened to give the correct ownerships root:wheel, but it
gave permissions 000 so init could not be execed. Use the macros
for root: wheel and 0755. (The removed code gave 0:0 and 0777. 0755
is more normal and secure, thought wrong for /tmp.)
o Check the readonly flag for initial (non-MNT_UPDATE) mounts in the
correct place, as in ffs. For root mounts, it is only passed in
mp->mnt_flags, since vfs_mountroot_try() only passes it as a flag
and nothing translates the flag to the "ro" option string. msdosfs
only looked for it in the string, so it gave a rw mount for root
mounts without even clearing the flag in mp->mnt_flags, so the final
state was inconsistent. Checking the flag only in mp->mnt_flags
works for initial userland mounts too. The MNT_UPDATE case is
messier.
The main point that should work but doesn't is fsck of msdosfs root
while it is mounted ro. This needs mainly MNT_RELOAD support to work.
It should be possible to run fsck -p and succeed provided the fs is
consistent, not just for msdosfs, but this fails because fsck -p always
tries to open the device rw. The hack that allows open for writing
in ffs is not implemented in msdosfs, since without MNT_RELOAD support
writing could only be harmful. So fsck must be turned off to use
msdosfs as root. This is quite dangerous, since msdosfs is still missing
actually using its fs-dirty flag internally, so it is happy to mount
dirty fileystems rw.
Unrelated changes:
- Fix missing error handling for MNT_UPDATE from rw to ro.
- Catch up with renaming msdos to msdosfs in a string.
Approved by: re (kensmith)
2007-07-23 07:10:17 +00:00
|
|
|
error = g_access(pmp->pm_cp, 0, -1, 0);
|
2004-10-29 10:40:14 +00:00
|
|
|
g_topology_unlock();
|
2007-10-22 17:43:43 +00:00
|
|
|
if (error) {
|
|
|
|
(void)markvoldirty(pmp, 1);
|
Make using msdosfs as the root file system sort of work:
o Initialize ownerships and permissions. They were garbage (0) for
root mounts since vfs_mountroot_try() doesn't ask for them to be set
and msdosfs's old incomplete code to set them was removed. The
garbage happened to give the correct ownerships root:wheel, but it
gave permissions 000 so init could not be execed. Use the macros
for root: wheel and 0755. (The removed code gave 0:0 and 0777. 0755
is more normal and secure, thought wrong for /tmp.)
o Check the readonly flag for initial (non-MNT_UPDATE) mounts in the
correct place, as in ffs. For root mounts, it is only passed in
mp->mnt_flags, since vfs_mountroot_try() only passes it as a flag
and nothing translates the flag to the "ro" option string. msdosfs
only looked for it in the string, so it gave a rw mount for root
mounts without even clearing the flag in mp->mnt_flags, so the final
state was inconsistent. Checking the flag only in mp->mnt_flags
works for initial userland mounts too. The MNT_UPDATE case is
messier.
The main point that should work but doesn't is fsck of msdosfs root
while it is mounted ro. This needs mainly MNT_RELOAD support to work.
It should be possible to run fsck -p and succeed provided the fs is
consistent, not just for msdosfs, but this fails because fsck -p always
tries to open the device rw. The hack that allows open for writing
in ffs is not implemented in msdosfs, since without MNT_RELOAD support
writing could only be harmful. So fsck must be turned off to use
msdosfs as root. This is quite dangerous, since msdosfs is still missing
actually using its fs-dirty flag internally, so it is happy to mount
dirty fileystems rw.
Unrelated changes:
- Fix missing error handling for MNT_UPDATE from rw to ro.
- Catch up with renaming msdos to msdosfs in a string.
Approved by: re (kensmith)
2007-07-23 07:10:17 +00:00
|
|
|
return (error);
|
2007-10-22 17:43:43 +00:00
|
|
|
}
|
Make using msdosfs as the root file system sort of work:
o Initialize ownerships and permissions. They were garbage (0) for
root mounts since vfs_mountroot_try() doesn't ask for them to be set
and msdosfs's old incomplete code to set them was removed. The
garbage happened to give the correct ownerships root:wheel, but it
gave permissions 000 so init could not be execed. Use the macros
for root: wheel and 0755. (The removed code gave 0:0 and 0777. 0755
is more normal and secure, thought wrong for /tmp.)
o Check the readonly flag for initial (non-MNT_UPDATE) mounts in the
correct place, as in ffs. For root mounts, it is only passed in
mp->mnt_flags, since vfs_mountroot_try() only passes it as a flag
and nothing translates the flag to the "ro" option string. msdosfs
only looked for it in the string, so it gave a rw mount for root
mounts without even clearing the flag in mp->mnt_flags, so the final
state was inconsistent. Checking the flag only in mp->mnt_flags
works for initial userland mounts too. The MNT_UPDATE case is
messier.
The main point that should work but doesn't is fsck of msdosfs root
while it is mounted ro. This needs mainly MNT_RELOAD support to work.
It should be possible to run fsck -p and succeed provided the fs is
consistent, not just for msdosfs, but this fails because fsck -p always
tries to open the device rw. The hack that allows open for writing
in ffs is not implemented in msdosfs, since without MNT_RELOAD support
writing could only be harmful. So fsck must be turned off to use
msdosfs as root. This is quite dangerous, since msdosfs is still missing
actually using its fs-dirty flag internally, so it is happy to mount
dirty fileystems rw.
Unrelated changes:
- Fix missing error handling for MNT_UPDATE from rw to ro.
- Catch up with renaming msdos to msdosfs in a string.
Approved by: re (kensmith)
2007-07-23 07:10:17 +00:00
|
|
|
|
2007-10-22 17:43:43 +00:00
|
|
|
/*
|
|
|
|
* Backing out after an error was painful in the
|
|
|
|
* above. Now we are committed to succeeding.
|
|
|
|
*/
|
|
|
|
pmp->pm_fmod = 0;
|
|
|
|
pmp->pm_flags |= MSDOSFSMNT_RONLY;
|
|
|
|
MNT_ILOCK(mp);
|
|
|
|
mp->mnt_flag |= MNT_RDONLY;
|
|
|
|
MNT_IUNLOCK(mp);
|
2004-12-06 19:05:48 +00:00
|
|
|
} else if ((pmp->pm_flags & MSDOSFSMNT_RONLY) &&
|
|
|
|
!vfs_flagopt(mp->mnt_optnew, "ro", NULL, 0)) {
|
1998-02-18 09:28:47 +00:00
|
|
|
/*
|
|
|
|
* If upgrade to read-write by non-root, then verify
|
|
|
|
* that user has necessary permissions on the device.
|
|
|
|
*/
|
2006-11-06 13:42:10 +00:00
|
|
|
devvp = pmp->pm_devvp;
|
2008-01-10 01:10:58 +00:00
|
|
|
vn_lock(devvp, LK_EXCLUSIVE | LK_RETRY);
|
2006-11-06 13:42:10 +00:00
|
|
|
error = VOP_ACCESS(devvp, VREAD | VWRITE,
|
2007-08-07 03:38:36 +00:00
|
|
|
td->td_ucred, td);
|
2006-11-06 13:42:10 +00:00
|
|
|
if (error)
|
|
|
|
error = priv_check(td, PRIV_VFS_MOUNT_PERM);
|
|
|
|
if (error) {
|
2020-01-03 22:29:58 +00:00
|
|
|
VOP_UNLOCK(devvp);
|
2006-11-06 13:42:10 +00:00
|
|
|
return (error);
|
1998-02-18 09:28:47 +00:00
|
|
|
}
|
2020-01-03 22:29:58 +00:00
|
|
|
VOP_UNLOCK(devvp);
|
2004-10-29 10:40:14 +00:00
|
|
|
g_topology_lock();
|
|
|
|
error = g_access(pmp->pm_cp, 0, 1, 0);
|
|
|
|
g_topology_unlock();
|
|
|
|
if (error)
|
|
|
|
return (error);
|
2003-12-29 09:50:42 +00:00
|
|
|
|
2019-09-11 21:24:14 +00:00
|
|
|
/* Now that the volume is modifiable, mark it dirty. */
|
|
|
|
error = markvoldirty_upgrade(pmp, true, true);
|
|
|
|
if (error) {
|
|
|
|
/*
|
|
|
|
* If dirtying the superblock failed, drop GEOM
|
|
|
|
* 'w' refs (we're still RO).
|
|
|
|
*/
|
|
|
|
g_topology_lock();
|
|
|
|
(void)g_access(pmp->pm_cp, 0, -1, 0);
|
|
|
|
g_topology_unlock();
|
|
|
|
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
2007-10-22 17:43:43 +00:00
|
|
|
pmp->pm_fmod = 1;
|
|
|
|
pmp->pm_flags &= ~MSDOSFSMNT_RONLY;
|
|
|
|
MNT_ILOCK(mp);
|
|
|
|
mp->mnt_flag &= ~MNT_RDONLY;
|
|
|
|
MNT_IUNLOCK(mp);
|
2007-01-06 20:46:02 +00:00
|
|
|
}
|
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
|
2004-02-14 04:41:13 +00:00
|
|
|
* and verify that it refers to a sensible disk device.
|
1994-09-19 15:41:57 +00:00
|
|
|
*/
|
2004-12-06 19:05:48 +00:00
|
|
|
if (vfs_getopt(mp->mnt_optnew, "from", (void **)&from, NULL))
|
|
|
|
return (EINVAL);
|
2005-09-02 15:27:23 +00:00
|
|
|
NDINIT(&ndp, LOOKUP, FOLLOW | LOCKLEAF, UIO_SYSSPACE, from, td);
|
2004-07-30 22:08:52 +00:00
|
|
|
error = namei(&ndp);
|
1998-02-18 09:28:47 +00:00
|
|
|
if (error)
|
|
|
|
return (error);
|
2004-07-30 22:08:52 +00:00
|
|
|
devvp = ndp.ni_vp;
|
|
|
|
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)) {
|
2005-09-02 15:27:23 +00:00
|
|
|
vput(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
|
|
|
*/
|
2008-10-28 13:44:11 +00:00
|
|
|
accmode = VREAD;
|
2006-11-06 13:42:10 +00:00
|
|
|
if ((mp->mnt_flag & MNT_RDONLY) == 0)
|
2008-10-28 13:44:11 +00:00
|
|
|
accmode |= VWRITE;
|
|
|
|
error = VOP_ACCESS(devvp, accmode, td->td_ucred, td);
|
2006-11-06 13:42:10 +00:00
|
|
|
if (error)
|
|
|
|
error = priv_check(td, PRIV_VFS_MOUNT_PERM);
|
|
|
|
if (error) {
|
|
|
|
vput(devvp);
|
|
|
|
return (error);
|
1998-02-18 09:28:47 +00:00
|
|
|
}
|
|
|
|
if ((mp->mnt_flag & MNT_UPDATE) == 0) {
|
2008-10-10 21:23:50 +00:00
|
|
|
error = mountmsdosfs(devvp, mp);
|
1998-02-18 09:28:47 +00:00
|
|
|
#ifdef MSDOSFS_DEBUG /* only needed for the printf below */
|
|
|
|
pmp = VFSTOMSDOSFS(mp);
|
|
|
|
#endif
|
|
|
|
} else {
|
2010-03-02 17:24:33 +00:00
|
|
|
vput(devvp);
|
1994-09-19 15:41:57 +00:00
|
|
|
if (devvp != pmp->pm_devvp)
|
2010-03-02 17:24:33 +00:00
|
|
|
return (EINVAL); /* XXX needs translation */
|
1994-09-19 15:41:57 +00:00
|
|
|
}
|
|
|
|
if (error) {
|
|
|
|
vrele(devvp);
|
1998-02-18 09:28:47 +00:00
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
2004-12-06 19:05:48 +00:00
|
|
|
error = update_mp(mp, td);
|
1998-02-18 09:28:47 +00:00
|
|
|
if (error) {
|
2004-08-26 13:16:44 +00:00
|
|
|
if ((mp->mnt_flag & MNT_UPDATE) == 0)
|
2009-05-11 15:33:26 +00:00
|
|
|
msdosfs_unmount(mp, MNT_FORCE);
|
1994-09-19 15:41:57 +00:00
|
|
|
return error;
|
|
|
|
}
|
2007-08-07 03:38:36 +00:00
|
|
|
|
2004-12-06 19:05:48 +00:00
|
|
|
vfs_mountedfrom(mp, from);
|
1994-09-19 15:41:57 +00:00
|
|
|
#ifdef MSDOSFS_DEBUG
|
2004-12-06 19:05:48 +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
|
2008-10-10 21:23:50 +00:00
|
|
|
mountmsdosfs(struct vnode *devvp, struct mount *mp)
|
1994-09-19 15:41:57 +00:00
|
|
|
{
|
1998-02-18 09:28:47 +00:00
|
|
|
struct msdosfsmount *pmp;
|
|
|
|
struct buf *bp;
|
2009-02-27 20:00:15 +00:00
|
|
|
struct cdev *dev;
|
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;
|
2017-05-19 18:13:41 +00:00
|
|
|
uint8_t SecPerClust;
|
1999-12-28 15:27:39 +00:00
|
|
|
u_long clusters;
|
2007-08-07 03:38:36 +00:00
|
|
|
int ronly, error;
|
2004-10-29 10:40:14 +00:00
|
|
|
struct g_consumer *cp;
|
|
|
|
struct bufobj *bo;
|
1994-09-19 15:41:57 +00:00
|
|
|
|
2009-02-27 20:00:15 +00:00
|
|
|
bp = NULL; /* This and pmp both used in error_exit. */
|
|
|
|
pmp = NULL;
|
Make using msdosfs as the root file system sort of work:
o Initialize ownerships and permissions. They were garbage (0) for
root mounts since vfs_mountroot_try() doesn't ask for them to be set
and msdosfs's old incomplete code to set them was removed. The
garbage happened to give the correct ownerships root:wheel, but it
gave permissions 000 so init could not be execed. Use the macros
for root: wheel and 0755. (The removed code gave 0:0 and 0777. 0755
is more normal and secure, thought wrong for /tmp.)
o Check the readonly flag for initial (non-MNT_UPDATE) mounts in the
correct place, as in ffs. For root mounts, it is only passed in
mp->mnt_flags, since vfs_mountroot_try() only passes it as a flag
and nothing translates the flag to the "ro" option string. msdosfs
only looked for it in the string, so it gave a rw mount for root
mounts without even clearing the flag in mp->mnt_flags, so the final
state was inconsistent. Checking the flag only in mp->mnt_flags
works for initial userland mounts too. The MNT_UPDATE case is
messier.
The main point that should work but doesn't is fsck of msdosfs root
while it is mounted ro. This needs mainly MNT_RELOAD support to work.
It should be possible to run fsck -p and succeed provided the fs is
consistent, not just for msdosfs, but this fails because fsck -p always
tries to open the device rw. The hack that allows open for writing
in ffs is not implemented in msdosfs, since without MNT_RELOAD support
writing could only be harmful. So fsck must be turned off to use
msdosfs as root. This is quite dangerous, since msdosfs is still missing
actually using its fs-dirty flag internally, so it is happy to mount
dirty fileystems rw.
Unrelated changes:
- Fix missing error handling for MNT_UPDATE from rw to ro.
- Catch up with renaming msdos to msdosfs in a string.
Approved by: re (kensmith)
2007-07-23 07:10:17 +00:00
|
|
|
ronly = (mp->mnt_flag & MNT_RDONLY) != 0;
|
2009-02-27 20:00:15 +00:00
|
|
|
|
|
|
|
dev = devvp->v_rdev;
|
2016-05-21 11:40:41 +00:00
|
|
|
if (atomic_cmpset_acq_ptr((uintptr_t *)&dev->si_mountpt, 0,
|
|
|
|
(uintptr_t)mp) == 0) {
|
2020-01-03 22:29:58 +00:00
|
|
|
VOP_UNLOCK(devvp);
|
2016-05-21 11:40:41 +00:00
|
|
|
return (EBUSY);
|
|
|
|
}
|
2004-10-29 10:40:14 +00:00
|
|
|
g_topology_lock();
|
Make using msdosfs as the root file system sort of work:
o Initialize ownerships and permissions. They were garbage (0) for
root mounts since vfs_mountroot_try() doesn't ask for them to be set
and msdosfs's old incomplete code to set them was removed. The
garbage happened to give the correct ownerships root:wheel, but it
gave permissions 000 so init could not be execed. Use the macros
for root: wheel and 0755. (The removed code gave 0:0 and 0777. 0755
is more normal and secure, thought wrong for /tmp.)
o Check the readonly flag for initial (non-MNT_UPDATE) mounts in the
correct place, as in ffs. For root mounts, it is only passed in
mp->mnt_flags, since vfs_mountroot_try() only passes it as a flag
and nothing translates the flag to the "ro" option string. msdosfs
only looked for it in the string, so it gave a rw mount for root
mounts without even clearing the flag in mp->mnt_flags, so the final
state was inconsistent. Checking the flag only in mp->mnt_flags
works for initial userland mounts too. The MNT_UPDATE case is
messier.
The main point that should work but doesn't is fsck of msdosfs root
while it is mounted ro. This needs mainly MNT_RELOAD support to work.
It should be possible to run fsck -p and succeed provided the fs is
consistent, not just for msdosfs, but this fails because fsck -p always
tries to open the device rw. The hack that allows open for writing
in ffs is not implemented in msdosfs, since without MNT_RELOAD support
writing could only be harmful. So fsck must be turned off to use
msdosfs as root. This is quite dangerous, since msdosfs is still missing
actually using its fs-dirty flag internally, so it is happy to mount
dirty fileystems rw.
Unrelated changes:
- Fix missing error handling for MNT_UPDATE from rw to ro.
- Catch up with renaming msdos to msdosfs in a string.
Approved by: re (kensmith)
2007-07-23 07:10:17 +00:00
|
|
|
error = g_vfs_open(devvp, &cp, "msdosfs", ronly ? 0 : 1);
|
2004-10-29 10:40:14 +00:00
|
|
|
g_topology_unlock();
|
2016-05-21 11:40:41 +00:00
|
|
|
if (error != 0) {
|
|
|
|
atomic_store_rel_ptr((uintptr_t *)&dev->si_mountpt, 0);
|
2020-01-03 22:29:58 +00:00
|
|
|
VOP_UNLOCK(devvp);
|
2016-05-21 11:40:41 +00:00
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
dev_ref(dev);
|
2004-10-29 10:40:14 +00:00
|
|
|
bo = &devvp->v_bufobj;
|
2020-01-03 22:29:58 +00:00
|
|
|
VOP_UNLOCK(devvp);
|
2018-12-21 20:12:43 +00:00
|
|
|
if (dev->si_iosize_max != 0)
|
|
|
|
mp->mnt_iosize_max = dev->si_iosize_max;
|
|
|
|
if (mp->mnt_iosize_max > MAXPHYS)
|
|
|
|
mp->mnt_iosize_max = MAXPHYS;
|
1998-02-18 09:28:47 +00:00
|
|
|
|
1994-09-19 15:41:57 +00:00
|
|
|
/*
|
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
|
|
|
*
|
2007-07-12 17:17:47 +00:00
|
|
|
* NOTE: 8192 is a magic size that works for ffs.
|
1994-09-19 15:41:57 +00:00
|
|
|
*/
|
2007-07-12 17:17:47 +00:00
|
|
|
error = bread(devvp, 0, 8192, 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;
|
2002-10-21 20:52:51 +00:00
|
|
|
b710 = (struct byte_bpb710 *)bsp->bs710.bsBPB;
|
1998-02-18 09:28:47 +00:00
|
|
|
|
2000-01-27 14:43:07 +00:00
|
|
|
#ifndef MSDOSFS_NOCHECKSIG
|
2001-11-28 18:29:16 +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
|
1994-09-19 15:41:57 +00:00
|
|
|
|
2003-02-19 05:47:46 +00:00
|
|
|
pmp = malloc(sizeof *pmp, M_MSDOSFSMNT, M_WAITOK | M_ZERO);
|
1994-09-19 15:41:57 +00:00
|
|
|
pmp->pm_mountp = mp;
|
2004-10-29 10:40:14 +00:00
|
|
|
pmp->pm_cp = cp;
|
|
|
|
pmp->pm_bo = bo;
|
1994-09-19 15:41:57 +00:00
|
|
|
|
2010-02-28 17:13:07 +00:00
|
|
|
lockinit(&pmp->pm_fatlock, 0, msdosfs_lock_msg, 0, 0);
|
|
|
|
|
Make using msdosfs as the root file system sort of work:
o Initialize ownerships and permissions. They were garbage (0) for
root mounts since vfs_mountroot_try() doesn't ask for them to be set
and msdosfs's old incomplete code to set them was removed. The
garbage happened to give the correct ownerships root:wheel, but it
gave permissions 000 so init could not be execed. Use the macros
for root: wheel and 0755. (The removed code gave 0:0 and 0777. 0755
is more normal and secure, thought wrong for /tmp.)
o Check the readonly flag for initial (non-MNT_UPDATE) mounts in the
correct place, as in ffs. For root mounts, it is only passed in
mp->mnt_flags, since vfs_mountroot_try() only passes it as a flag
and nothing translates the flag to the "ro" option string. msdosfs
only looked for it in the string, so it gave a rw mount for root
mounts without even clearing the flag in mp->mnt_flags, so the final
state was inconsistent. Checking the flag only in mp->mnt_flags
works for initial userland mounts too. The MNT_UPDATE case is
messier.
The main point that should work but doesn't is fsck of msdosfs root
while it is mounted ro. This needs mainly MNT_RELOAD support to work.
It should be possible to run fsck -p and succeed provided the fs is
consistent, not just for msdosfs, but this fails because fsck -p always
tries to open the device rw. The hack that allows open for writing
in ffs is not implemented in msdosfs, since without MNT_RELOAD support
writing could only be harmful. So fsck must be turned off to use
msdosfs as root. This is quite dangerous, since msdosfs is still missing
actually using its fs-dirty flag internally, so it is happy to mount
dirty fileystems rw.
Unrelated changes:
- Fix missing error handling for MNT_UPDATE from rw to ro.
- Catch up with renaming msdos to msdosfs in a string.
Approved by: re (kensmith)
2007-07-23 07:10:17 +00:00
|
|
|
/*
|
|
|
|
* Initialize ownerships and permissions, since nothing else will
|
2007-11-18 09:21:30 +00:00
|
|
|
* initialize them iff we are mounting root.
|
Make using msdosfs as the root file system sort of work:
o Initialize ownerships and permissions. They were garbage (0) for
root mounts since vfs_mountroot_try() doesn't ask for them to be set
and msdosfs's old incomplete code to set them was removed. The
garbage happened to give the correct ownerships root:wheel, but it
gave permissions 000 so init could not be execed. Use the macros
for root: wheel and 0755. (The removed code gave 0:0 and 0777. 0755
is more normal and secure, thought wrong for /tmp.)
o Check the readonly flag for initial (non-MNT_UPDATE) mounts in the
correct place, as in ffs. For root mounts, it is only passed in
mp->mnt_flags, since vfs_mountroot_try() only passes it as a flag
and nothing translates the flag to the "ro" option string. msdosfs
only looked for it in the string, so it gave a rw mount for root
mounts without even clearing the flag in mp->mnt_flags, so the final
state was inconsistent. Checking the flag only in mp->mnt_flags
works for initial userland mounts too. The MNT_UPDATE case is
messier.
The main point that should work but doesn't is fsck of msdosfs root
while it is mounted ro. This needs mainly MNT_RELOAD support to work.
It should be possible to run fsck -p and succeed provided the fs is
consistent, not just for msdosfs, but this fails because fsck -p always
tries to open the device rw. The hack that allows open for writing
in ffs is not implemented in msdosfs, since without MNT_RELOAD support
writing could only be harmful. So fsck must be turned off to use
msdosfs as root. This is quite dangerous, since msdosfs is still missing
actually using its fs-dirty flag internally, so it is happy to mount
dirty fileystems rw.
Unrelated changes:
- Fix missing error handling for MNT_UPDATE from rw to ro.
- Catch up with renaming msdos to msdosfs in a string.
Approved by: re (kensmith)
2007-07-23 07:10:17 +00:00
|
|
|
*/
|
|
|
|
pmp->pm_uid = UID_ROOT;
|
|
|
|
pmp->pm_gid = GID_WHEEL;
|
|
|
|
pmp->pm_mask = pmp->pm_dirmask = S_IXUSR | S_IXGRP | S_IXOTH |
|
|
|
|
S_IRUSR | S_IRGRP | S_IROTH | S_IWUSR;
|
|
|
|
|
1994-09-19 15:41:57 +00:00
|
|
|
/*
|
|
|
|
* 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);
|
2003-04-24 18:19:19 +00:00
|
|
|
if (pmp->pm_BytesPerSec < DEV_BSIZE) {
|
|
|
|
error = EINVAL;
|
|
|
|
goto error_exit;
|
|
|
|
}
|
1994-09-19 15:41:57 +00:00
|
|
|
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;
|
|
|
|
|
2008-02-21 03:19:46 +00:00
|
|
|
/*
|
|
|
|
* We don't check pm_Heads nor pm_SecPerTrack, because
|
|
|
|
* these may not be set for EFI file systems. We don't
|
|
|
|
* use these anyway, so we're unaffected if they are
|
|
|
|
* invalid.
|
|
|
|
*/
|
|
|
|
if (!pmp->pm_BytesPerSec || !SecPerClust) {
|
2001-11-28 18:29:16 +00:00
|
|
|
error = EINVAL;
|
|
|
|
goto error_exit;
|
|
|
|
}
|
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-02-18 09:28:47 +00:00
|
|
|
|
|
|
|
if (pmp->pm_RootDirEnts == 0) {
|
2013-02-01 18:01:03 +00:00
|
|
|
if (pmp->pm_FATsecs
|
1998-02-18 09:28:47 +00:00
|
|
|
|| getushort(b710->bpbFSVers)) {
|
|
|
|
error = EINVAL;
|
2011-11-22 13:30:36 +00:00
|
|
|
#ifdef MSDOSFS_DEBUG
|
1998-04-05 13:10:11 +00:00
|
|
|
printf("mountmsdosfs(): bad FAT32 filesystem\n");
|
2011-11-22 13:30:36 +00:00
|
|
|
#endif
|
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
|
2003-04-24 18:19:19 +00:00
|
|
|
* - number of FAT sectors: >= 1
|
2000-01-27 14:43:07 +00:00
|
|
|
*/
|
|
|
|
if ( (SecPerClust == 0)
|
|
|
|
|| (SecPerClust & (SecPerClust - 1))
|
|
|
|
|| (pmp->pm_BytesPerSec < DEV_BSIZE)
|
|
|
|
|| (pmp->pm_BytesPerSec & (pmp->pm_BytesPerSec - 1))
|
|
|
|
|| (pmp->pm_HugeSectors == 0)
|
2003-04-24 18:19:19 +00:00
|
|
|
|| (pmp->pm_FATsecs == 0)
|
2010-04-02 15:22:23 +00:00
|
|
|
|| (SecPerClust * pmp->pm_BlkPerSec > MAXBSIZE / DEV_BSIZE)
|
2000-01-27 14:43:07 +00:00
|
|
|
) {
|
|
|
|
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;
|
2007-08-07 03:38:36 +00:00
|
|
|
pmp->pm_HiddenSects *= pmp->pm_BlkPerSec; /* XXX not used? */
|
2000-01-27 14:43:07 +00:00
|
|
|
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);
|
2016-04-26 15:38:17 +00:00
|
|
|
pmp->pm_rootdirsize = howmany(pmp->pm_RootDirEnts *
|
|
|
|
sizeof(struct direntry), 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;
|
2007-08-07 03:38:36 +00:00
|
|
|
pmp->pm_fatsize = pmp->pm_FATsecs * DEV_BSIZE; /* XXX not used? */
|
1998-02-18 09:28:47 +00:00
|
|
|
|
|
|
|
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
|
2017-05-21 19:29:28 +00:00
|
|
|
* sure that one FAT entry will not be split across
|
1998-02-18 09:28:47 +00:00
|
|
|
* 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) {
|
2011-11-22 13:30:36 +00:00
|
|
|
#ifdef MSDOSFS_DEBUG
|
1999-12-28 15:27:39 +00:00
|
|
|
printf("Warning: number of clusters (%ld) exceeds FAT "
|
|
|
|
"capacity (%ld)\n", pmp->pm_maxcluster + 1, clusters);
|
2011-11-22 13:30:36 +00:00
|
|
|
#endif
|
1999-12-28 15:27:39 +00:00
|
|
|
pmp->pm_maxcluster = clusters - 1;
|
|
|
|
}
|
|
|
|
|
1994-09-19 15:41:57 +00:00
|
|
|
if (FAT12(pmp))
|
2007-07-12 17:17:47 +00:00
|
|
|
pmp->pm_fatblocksize = 3 * 512;
|
1994-09-19 15:41:57 +00:00
|
|
|
else
|
2007-07-12 17:17:47 +00:00
|
|
|
pmp->pm_fatblocksize = PAGE_SIZE;
|
|
|
|
pmp->pm_fatblocksize = roundup(pmp->pm_fatblocksize,
|
|
|
|
pmp->pm_BytesPerSec);
|
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;
|
|
|
|
|
|
|
|
/*
|
2007-08-05 12:58:34 +00:00
|
|
|
* Check the fsinfo sector if we have one. Silently fix up our
|
|
|
|
* in-core copy of fp->fsinxtfree if it is unknown (0xffffffff)
|
|
|
|
* or too large. Ignore fp->fsinfree for now, since we need to
|
|
|
|
* read the entire FAT anyway to fill the inuse map.
|
1998-02-18 09:28:47 +00:00
|
|
|
*/
|
|
|
|
if (pmp->pm_fsinfo) {
|
|
|
|
struct fsinfo *fp;
|
|
|
|
|
2007-08-03 23:13:50 +00:00
|
|
|
if ((error = bread(devvp, pmp->pm_fsinfo, pmp->pm_BytesPerSec,
|
2000-01-27 14:43:07 +00:00
|
|
|
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)
|
Fix some bugs involving the fsinfo block (many remain unfixed). This is
part of fixing msdosfs for large sector sizes. One of the fixed bugs
was fatal for large sector sizes.
1. The fsinfo block has size 512, but it was misunderstood and declared
as having size 1024, with nothing in the second 512 bytes except a
signature at the end. The second 512 bytes actually normally (if
the file system was created by Windows) consist of a second boot
sector which is normally (in WinXP) empty except for a signature --
the normal layout is one boot sector, one fsinfo sector, another
boot sector, then these 3 sectors duplicated. However, other
layouts are valid. newfs_msdos produces a valid layout with one
boot sector, one fsinfo sector, then these 2 sectors duplicated.
The signature check for the extra part of the fsinfo was thus
normally checking the signature in either the second boot sector
or the first boot sector in the copy, and thus accidentally
succeeding. The extra signature check would just fail for weirder
layouts with 512-byte sectors, and for normal layouts with any other
sector size.
Remove the extra bytes and the extra signature check.
2. Old versions did i/o to the fsinfo block using size 1024, with the
second half only used for the extra signature check on read. This
was harmless for sector size 512, and worked accidentally for sector
size 1024. The i/o just failed for larger sector sizes.
The version being fixed did i/o to the fsinfo block using size
fsi_size(pmp) = (1024 << ((pmp)->pm_BlkPerSec >> 2)). This
expression makes no sense. It happens to work for sector small
sector sizes, but for sector size 32K it gives the preposterous
value of 64M and thus causes panics. A sector size of 32768 is
necessary for at least some DVD-RW's (where the minimum write size
is 32768 although the minimum read size is 2048).
Now that the size of the fsinfo block is 512, it always fits in
one sector so there is no need for a macro to express it. Just
use the sector size where the old code uses 1024.
Approved by: re (kensmith)
Approved by: nyan (several years ago for a different version of (2))
2007-07-12 16:09:07 +00:00
|
|
|
&& !bcmp(fp->fsisig3, "\0\0\125\252", 4)) {
|
1998-02-18 09:28:47 +00:00
|
|
|
pmp->pm_nxtfree = getulong(fp->fsinxtfree);
|
2007-08-05 12:58:34 +00:00
|
|
|
if (pmp->pm_nxtfree > pmp->pm_maxcluster)
|
2004-02-17 08:51:49 +00:00
|
|
|
pmp->pm_nxtfree = CLUST_FIRST;
|
|
|
|
} else
|
1998-02-18 09:28:47 +00:00
|
|
|
pmp->pm_fsinfo = 0;
|
|
|
|
brelse(bp);
|
|
|
|
bp = NULL;
|
1996-06-14 11:02:28 +00:00
|
|
|
}
|
1994-09-19 15:41:57 +00:00
|
|
|
|
|
|
|
/*
|
2007-08-05 12:58:34 +00:00
|
|
|
* Finish initializing pmp->pm_nxtfree (just in case the first few
|
|
|
|
* sectors aren't properly reserved in the FAT). This completes
|
|
|
|
* the fixup for fp->fsinxtfree, and fixes up the zero-initialized
|
|
|
|
* value if there is no fsinfo. We will use pmp->pm_nxtfree
|
|
|
|
* internally even if there is no fsinfo.
|
1994-09-19 15:41:57 +00:00
|
|
|
*/
|
2007-08-05 12:58:34 +00:00
|
|
|
if (pmp->pm_nxtfree < CLUST_FIRST)
|
|
|
|
pmp->pm_nxtfree = CLUST_FIRST;
|
1994-09-19 15:41:57 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Allocate memory for the bitmap of allocated clusters, and then
|
|
|
|
* fill it in.
|
|
|
|
*/
|
2004-02-21 22:47:19 +00:00
|
|
|
pmp->pm_inusemap = malloc(howmany(pmp->pm_maxcluster + 1, N_INUSEBITS)
|
1994-09-19 15:41:57 +00:00
|
|
|
* sizeof(*pmp->pm_inusemap),
|
2003-02-19 05:47:46 +00:00
|
|
|
M_MSDOSFSFAT, M_WAITOK);
|
1994-09-19 15:41:57 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* fillinusemap() needs pm_devvp.
|
|
|
|
*/
|
|
|
|
pmp->pm_devvp = devvp;
|
2009-02-27 20:00:15 +00:00
|
|
|
pmp->pm_dev = dev;
|
1994-09-19 15:41:57 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Have the inuse map filled in.
|
|
|
|
*/
|
2010-02-28 17:13:59 +00:00
|
|
|
MSDOSFS_LOCK_MP(pmp);
|
|
|
|
error = fillinusemap(pmp);
|
|
|
|
MSDOSFS_UNLOCK_MP(pmp);
|
|
|
|
if (error != 0)
|
1994-09-19 15:41:57 +00:00
|
|
|
goto error_exit;
|
|
|
|
|
|
|
|
/*
|
2017-05-21 19:29:28 +00:00
|
|
|
* If they want FAT updates to be synchronous then let them suffer
|
1994-09-19 15:41:57 +00:00
|
|
|
* the performance degradation in exchange for the on disk copy of
|
2017-05-21 19:29:28 +00:00
|
|
|
* the FAT being correct just about all the time. I suppose this
|
1994-09-19 15:41:57 +00:00
|
|
|
* 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;
|
2003-12-26 17:19:19 +00:00
|
|
|
else {
|
2019-09-11 21:24:14 +00:00
|
|
|
if ((error = markvoldirty(pmp, 1)) != 0)
|
2003-12-29 09:50:42 +00:00
|
|
|
goto error_exit;
|
1994-09-19 15:41:57 +00:00
|
|
|
pmp->pm_fmod = 1;
|
2003-12-26 17:19:19 +00:00
|
|
|
}
|
2007-10-16 10:54:55 +00:00
|
|
|
mp->mnt_data = 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;
|
2006-09-26 04:12:49 +00:00
|
|
|
MNT_ILOCK(mp);
|
1997-03-18 19:50:12 +00:00
|
|
|
mp->mnt_flag |= MNT_LOCAL;
|
2016-10-28 11:35:06 +00:00
|
|
|
mp->mnt_kern_flag |= MNTK_USES_BCACHE | MNTK_NO_IOPF;
|
2006-09-26 04:12:49 +00:00
|
|
|
MNT_IUNLOCK(mp);
|
1994-09-19 15:41:57 +00:00
|
|
|
|
2017-06-09 12:06:22 +00:00
|
|
|
return (0);
|
1994-09-19 15:41:57 +00:00
|
|
|
|
1998-02-18 09:28:47 +00:00
|
|
|
error_exit:
|
|
|
|
if (bp)
|
|
|
|
brelse(bp);
|
2004-10-29 10:40:14 +00:00
|
|
|
if (cp != NULL) {
|
|
|
|
g_topology_lock();
|
2008-10-10 21:23:50 +00:00
|
|
|
g_vfs_close(cp);
|
2004-10-29 10:40:14 +00:00
|
|
|
g_topology_unlock();
|
|
|
|
}
|
1994-09-19 15:41:57 +00:00
|
|
|
if (pmp) {
|
2010-03-02 11:02:59 +00:00
|
|
|
lockdestroy(&pmp->pm_fatlock);
|
2016-10-28 10:57:41 +00:00
|
|
|
free(pmp->pm_inusemap, M_MSDOSFSFAT);
|
1998-02-18 09:28:47 +00:00
|
|
|
free(pmp, M_MSDOSFSMNT);
|
2007-10-16 10:54:55 +00:00
|
|
|
mp->mnt_data = NULL;
|
1994-09-19 15:41:57 +00:00
|
|
|
}
|
2016-05-21 11:40:41 +00:00
|
|
|
atomic_store_rel_ptr((uintptr_t *)&dev->si_mountpt, 0);
|
2009-02-27 20:00:15 +00:00
|
|
|
dev_rel(dev);
|
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
|
2009-05-11 15:33:26 +00:00
|
|
|
msdosfs_unmount(struct mount *mp, int mntflags)
|
1994-09-19 15:41:57 +00:00
|
|
|
{
|
1998-02-18 09:28:47 +00:00
|
|
|
struct msdosfsmount *pmp;
|
|
|
|
int error, flags;
|
1994-09-19 15:41:57 +00:00
|
|
|
|
2015-04-05 21:10:38 +00:00
|
|
|
error = flags = 0;
|
|
|
|
pmp = VFSTOMSDOSFS(mp);
|
|
|
|
if ((pmp->pm_flags & MSDOSFSMNT_RONLY) == 0)
|
|
|
|
error = msdosfs_sync(mp, MNT_WAIT);
|
|
|
|
if ((mntflags & MNT_FORCE) != 0)
|
1994-09-19 15:41:57 +00:00
|
|
|
flags |= FORCECLOSE;
|
2015-04-05 21:10:38 +00:00
|
|
|
else if (error != 0)
|
2014-12-09 10:00:47 +00:00
|
|
|
return (error);
|
2009-05-11 15:33:26 +00:00
|
|
|
error = vflush(mp, 0, flags, curthread);
|
2014-12-09 10:00:47 +00:00
|
|
|
if (error != 0 && error != ENXIO)
|
|
|
|
return (error);
|
2007-10-22 17:43:43 +00:00
|
|
|
if ((pmp->pm_flags & MSDOSFSMNT_RONLY) == 0) {
|
|
|
|
error = markvoldirty(pmp, 0);
|
2009-02-23 21:09:28 +00:00
|
|
|
if (error && error != ENXIO) {
|
2007-10-22 17:43:43 +00:00
|
|
|
(void)markvoldirty(pmp, 1);
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
}
|
2003-09-26 20:26:25 +00:00
|
|
|
if (pmp->pm_flags & MSDOSFSMNT_KICONV && msdosfs_iconv) {
|
|
|
|
if (pmp->pm_w2u)
|
|
|
|
msdosfs_iconv->close(pmp->pm_w2u);
|
|
|
|
if (pmp->pm_u2w)
|
|
|
|
msdosfs_iconv->close(pmp->pm_u2w);
|
|
|
|
if (pmp->pm_d2u)
|
|
|
|
msdosfs_iconv->close(pmp->pm_d2u);
|
|
|
|
if (pmp->pm_u2d)
|
|
|
|
msdosfs_iconv->close(pmp->pm_u2d);
|
|
|
|
}
|
2003-12-26 17:19:19 +00:00
|
|
|
|
1998-02-18 09:28:47 +00:00
|
|
|
#ifdef MSDOSFS_DEBUG
|
|
|
|
{
|
|
|
|
struct vnode *vp = pmp->pm_devvp;
|
2008-03-22 09:15:16 +00:00
|
|
|
struct bufobj *bo;
|
1998-02-18 09:28:47 +00:00
|
|
|
|
2008-03-22 09:15:16 +00:00
|
|
|
bo = &vp->v_bufobj;
|
|
|
|
BO_LOCK(bo);
|
2002-09-25 02:32:42 +00:00
|
|
|
VI_LOCK(vp);
|
2005-02-22 14:58:59 +00:00
|
|
|
vn_printf(vp,
|
|
|
|
"msdosfs_umount(): just before calling VOP_CLOSE()\n");
|
1998-02-18 09:28:47 +00:00
|
|
|
printf("freef %p, freeb %p, mount %p\n",
|
2020-01-13 02:37:25 +00:00
|
|
|
TAILQ_NEXT(vp, v_vnodelist), vp->v_vnodelist.tqe_prev,
|
1998-02-18 09:28:47 +00:00
|
|
|
vp->v_mount);
|
|
|
|
printf("cleanblkhd %p, dirtyblkhd %p, numoutput %ld, type %d\n",
|
2004-10-25 09:14:03 +00:00
|
|
|
TAILQ_FIRST(&vp->v_bufobj.bo_clean.bv_hd),
|
|
|
|
TAILQ_FIRST(&vp->v_bufobj.bo_dirty.bv_hd),
|
|
|
|
vp->v_bufobj.bo_numoutput, vp->v_type);
|
2002-09-25 02:32:42 +00:00
|
|
|
VI_UNLOCK(vp);
|
2008-03-22 09:15:16 +00:00
|
|
|
BO_UNLOCK(bo);
|
1998-02-18 09:28:47 +00:00
|
|
|
}
|
|
|
|
#endif
|
2004-10-29 10:40:14 +00:00
|
|
|
g_topology_lock();
|
2008-10-10 21:23:50 +00:00
|
|
|
g_vfs_close(pmp->pm_cp);
|
2004-10-29 10:40:14 +00:00
|
|
|
g_topology_unlock();
|
2016-05-21 11:40:41 +00:00
|
|
|
atomic_store_rel_ptr((uintptr_t *)&pmp->pm_dev->si_mountpt, 0);
|
1994-09-19 15:41:57 +00:00
|
|
|
vrele(pmp->pm_devvp);
|
2009-02-27 20:00:15 +00:00
|
|
|
dev_rel(pmp->pm_dev);
|
1998-02-18 09:28:47 +00:00
|
|
|
free(pmp->pm_inusemap, M_MSDOSFSFAT);
|
2010-02-28 17:13:07 +00:00
|
|
|
lockdestroy(&pmp->pm_fatlock);
|
1998-02-18 09:28:47 +00:00
|
|
|
free(pmp, M_MSDOSFSMNT);
|
2007-10-16 10:54:55 +00:00
|
|
|
mp->mnt_data = NULL;
|
2006-09-26 04:12:49 +00:00
|
|
|
MNT_ILOCK(mp);
|
1997-03-18 19:50:12 +00:00
|
|
|
mp->mnt_flag &= ~MNT_LOCAL;
|
2006-09-26 04:12:49 +00:00
|
|
|
MNT_IUNLOCK(mp);
|
2009-02-23 21:09:28 +00:00
|
|
|
return (error);
|
1994-09-19 15:41:57 +00:00
|
|
|
}
|
|
|
|
|
1995-11-07 14:06:45 +00:00
|
|
|
static int
|
2009-05-11 15:33:26 +00:00
|
|
|
msdosfs_root(struct mount *mp, int flags, struct vnode **vpp)
|
1994-09-19 15:41:57 +00:00
|
|
|
{
|
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
|
2009-05-11 15:33:26 +00:00
|
|
|
msdosfs_statfs(struct mount *mp, struct statfs *sbp)
|
1994-09-19 15:41:57 +00:00
|
|
|
{
|
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;
|
2007-08-07 03:38:36 +00:00
|
|
|
sbp->f_files = pmp->pm_RootDirEnts; /* XXX */
|
1994-09-19 15:41:57 +00:00
|
|
|
sbp->f_ffree = 0; /* what to put in here? */
|
1998-02-18 09:28:47 +00:00
|
|
|
return (0);
|
1994-09-19 15:41:57 +00:00
|
|
|
}
|
|
|
|
|
2013-02-17 20:35:54 +00:00
|
|
|
/*
|
|
|
|
* If we have an FSInfo block, update it.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
msdosfs_fsiflush(struct msdosfsmount *pmp, int waitfor)
|
|
|
|
{
|
|
|
|
struct fsinfo *fp;
|
|
|
|
struct buf *bp;
|
|
|
|
int error;
|
|
|
|
|
|
|
|
MSDOSFS_LOCK_MP(pmp);
|
|
|
|
if (pmp->pm_fsinfo == 0 || (pmp->pm_flags & MSDOSFS_FSIMOD) == 0) {
|
|
|
|
error = 0;
|
|
|
|
goto unlock;
|
|
|
|
}
|
|
|
|
error = bread(pmp->pm_devvp, pmp->pm_fsinfo, pmp->pm_BytesPerSec,
|
|
|
|
NOCRED, &bp);
|
|
|
|
if (error != 0) {
|
|
|
|
goto unlock;
|
|
|
|
}
|
|
|
|
fp = (struct fsinfo *)bp->b_data;
|
|
|
|
putulong(fp->fsinfree, pmp->pm_freeclustercount);
|
|
|
|
putulong(fp->fsinxtfree, pmp->pm_nxtfree);
|
|
|
|
pmp->pm_flags &= ~MSDOSFS_FSIMOD;
|
|
|
|
if (waitfor == MNT_WAIT)
|
|
|
|
error = bwrite(bp);
|
|
|
|
else
|
|
|
|
bawrite(bp);
|
|
|
|
unlock:
|
|
|
|
MSDOSFS_UNLOCK_MP(pmp);
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
1995-11-07 14:06:45 +00:00
|
|
|
static int
|
2009-05-11 15:33:26 +00:00
|
|
|
msdosfs_sync(struct mount *mp, int waitfor)
|
1994-09-19 15:41:57 +00:00
|
|
|
{
|
1998-02-18 09:28:47 +00:00
|
|
|
struct vnode *vp, *nvp;
|
2009-05-11 15:33:26 +00:00
|
|
|
struct thread *td;
|
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
|
|
|
|
2009-05-11 15:33:26 +00:00
|
|
|
td = curthread;
|
|
|
|
|
1994-09-19 15:41:57 +00:00
|
|
|
/*
|
2017-05-21 19:29:28 +00:00
|
|
|
* If we ever switch to not updating all of the FATs all the time,
|
1994-09-19 15:41:57 +00:00
|
|
|
* 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 {
|
2017-05-21 19:29:28 +00:00
|
|
|
/* update FATs here */
|
1994-09-19 15:41:57 +00:00
|
|
|
}
|
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
|
|
|
*/
|
|
|
|
loop:
|
2012-04-17 16:28:22 +00:00
|
|
|
MNT_VNODE_FOREACH_ALL(vp, mp, nvp) {
|
|
|
|
if (vp->v_type == VNON) {
|
2003-10-05 06:44:53 +00:00
|
|
|
VI_UNLOCK(vp);
|
|
|
|
continue;
|
|
|
|
}
|
1994-09-19 15:41:57 +00:00
|
|
|
dep = VTODE(vp);
|
2004-10-28 08:22:11 +00:00
|
|
|
if ((dep->de_flag &
|
1998-04-29 12:55:51 +00:00
|
|
|
(DE_ACCESS | DE_CREATE | DE_UPDATE | DE_MODIFIED)) == 0 &&
|
2004-10-25 09:14:03 +00:00
|
|
|
(vp->v_bufobj.bo_dirty.bv_cnt == 0 ||
|
2004-10-28 08:22:11 +00:00
|
|
|
waitfor == MNT_LAZY)) {
|
2002-09-25 02:32:42 +00:00
|
|
|
VI_UNLOCK(vp);
|
1994-09-19 15:41:57 +00:00
|
|
|
continue;
|
1997-02-26 14:23:16 +00:00
|
|
|
}
|
2001-09-12 08:38:13 +00:00
|
|
|
error = vget(vp, LK_EXCLUSIVE | LK_NOWAIT | LK_INTERLOCK, td);
|
1997-02-26 14:23:16 +00:00
|
|
|
if (error) {
|
2020-01-01 22:47:00 +00:00
|
|
|
if (error == ENOENT) {
|
|
|
|
MNT_VNODE_FOREACH_ALL_ABORT(mp, nvp);
|
1997-02-26 14:23:16 +00:00
|
|
|
goto loop;
|
2020-01-01 22:47:00 +00:00
|
|
|
}
|
1997-02-26 14:23:16 +00:00
|
|
|
continue;
|
|
|
|
}
|
2005-01-11 07:36:22 +00:00
|
|
|
error = VOP_FSYNC(vp, waitfor, td);
|
1994-09-27 20:42:59 +00:00
|
|
|
if (error)
|
1994-09-19 15:41:57 +00:00
|
|
|
allerror = error;
|
2020-01-03 22:29:58 +00:00
|
|
|
VOP_UNLOCK(vp);
|
2003-11-02 04:52:53 +00:00
|
|
|
vrele(vp);
|
1994-09-19 15:41:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Flush filesystem control info.
|
|
|
|
*/
|
1998-04-29 12:55:51 +00:00
|
|
|
if (waitfor != MNT_LAZY) {
|
2008-01-10 01:10:58 +00:00
|
|
|
vn_lock(pmp->pm_devvp, LK_EXCLUSIVE | LK_RETRY);
|
2005-01-11 07:36:22 +00:00
|
|
|
error = VOP_FSYNC(pmp->pm_devvp, waitfor, td);
|
1998-04-29 12:55:51 +00:00
|
|
|
if (error)
|
|
|
|
allerror = error;
|
2020-01-03 22:29:58 +00:00
|
|
|
VOP_UNLOCK(pmp->pm_devvp);
|
1998-04-29 12:55:51 +00:00
|
|
|
}
|
2013-02-17 20:35:54 +00:00
|
|
|
|
|
|
|
error = msdosfs_fsiflush(pmp, waitfor);
|
|
|
|
if (error != 0)
|
|
|
|
allerror = error;
|
1998-02-18 09:28:47 +00:00
|
|
|
return (allerror);
|
1994-09-19 15:41:57 +00:00
|
|
|
}
|
|
|
|
|
2007-06-01 17:06:46 +00:00
|
|
|
static int
|
2011-05-22 01:07:54 +00:00
|
|
|
msdosfs_fhtovp(struct mount *mp, struct fid *fhp, int flags, struct vnode **vpp)
|
2007-06-01 17:06:46 +00:00
|
|
|
{
|
|
|
|
struct msdosfsmount *pmp = VFSTOMSDOSFS(mp);
|
|
|
|
struct defid *defhp = (struct defid *) fhp;
|
|
|
|
struct denode *dep;
|
|
|
|
int error;
|
|
|
|
|
|
|
|
error = deget(pmp, defhp->defid_dirclust, defhp->defid_dirofs, &dep);
|
|
|
|
if (error) {
|
|
|
|
*vpp = NULLVP;
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
*vpp = DETOV(dep);
|
|
|
|
vnode_create_vobject(*vpp, dep->de_FileSize, curthread);
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
1995-11-07 14:10:19 +00:00
|
|
|
static struct vfsops msdosfs_vfsops = {
|
2007-06-01 17:06:46 +00:00
|
|
|
.vfs_fhtovp = msdosfs_fhtovp,
|
2004-12-06 19:05:48 +00:00
|
|
|
.vfs_mount = msdosfs_mount,
|
|
|
|
.vfs_cmount = msdosfs_cmount,
|
2003-06-12 20:48:38 +00:00
|
|
|
.vfs_root = msdosfs_root,
|
|
|
|
.vfs_statfs = msdosfs_statfs,
|
|
|
|
.vfs_sync = msdosfs_sync,
|
|
|
|
.vfs_unmount = msdosfs_unmount,
|
1994-09-19 15:41:57 +00:00
|
|
|
};
|
1994-09-21 03:47:43 +00:00
|
|
|
|
2001-06-01 10:57:26 +00:00
|
|
|
VFS_SET(msdosfs_vfsops, msdosfs, 0);
|
2003-09-26 20:26:25 +00:00
|
|
|
MODULE_VERSION(msdosfs, 1);
|