1999-08-28 01:08:13 +00:00
|
|
|
/* $FreeBSD$ */
|
1998-02-18 09:28:47 +00:00
|
|
|
/* $NetBSD: msdosfsmount.h,v 1.17 1997/11/17 15:37:07 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
|
|
|
|
*/
|
|
|
|
|
1997-03-03 17:36:11 +00:00
|
|
|
#ifndef _MSDOSFS_MSDOSFSMOUNT_H_
|
|
|
|
#define _MSDOSFS_MSDOSFSMOUNT_H_
|
|
|
|
|
2019-09-01 16:55:33 +00:00
|
|
|
#if defined (_KERNEL) || defined(MAKEFS)
|
1997-03-03 17:36:11 +00:00
|
|
|
|
2010-02-28 17:13:07 +00:00
|
|
|
#include <sys/types.h>
|
2020-01-27 12:02:41 +00:00
|
|
|
#ifndef MAKEFS
|
2010-02-28 17:13:07 +00:00
|
|
|
#include <sys/lock.h>
|
|
|
|
#include <sys/lockmgr.h>
|
2021-12-25 21:20:56 +00:00
|
|
|
#include <sys/_task.h>
|
2020-01-27 12:02:41 +00:00
|
|
|
#endif
|
2004-07-03 13:22:38 +00:00
|
|
|
#include <sys/tree.h>
|
|
|
|
|
1997-10-12 20:26:33 +00:00
|
|
|
#ifdef MALLOC_DECLARE
|
|
|
|
MALLOC_DECLARE(M_MSDOSFSMNT);
|
|
|
|
#endif
|
|
|
|
|
2004-07-03 13:22:38 +00:00
|
|
|
struct msdosfs_fileno;
|
|
|
|
|
1994-09-19 15:41:57 +00:00
|
|
|
/*
|
2017-05-21 19:29:28 +00:00
|
|
|
* Layout of the mount control block for a MSDOSFS filesystem.
|
1994-09-19 15:41:57 +00:00
|
|
|
*/
|
|
|
|
struct msdosfsmount {
|
|
|
|
struct mount *pm_mountp;/* vfs mount struct for this fs */
|
2004-10-29 10:40:14 +00:00
|
|
|
struct g_consumer *pm_cp;
|
|
|
|
struct bufobj *pm_bo;
|
1994-09-19 15:41:57 +00:00
|
|
|
uid_t pm_uid; /* uid to set as owner of the files */
|
|
|
|
gid_t pm_gid; /* gid to set as owner of the files */
|
2017-05-21 19:29:28 +00:00
|
|
|
mode_t pm_mask; /* mask to and with file protection bits
|
2003-08-12 20:06:56 +00:00
|
|
|
for files */
|
|
|
|
mode_t pm_dirmask; /* mask to and with file protection bits
|
|
|
|
for directories */
|
2009-02-27 20:00:15 +00:00
|
|
|
struct vnode *pm_devvp; /* vnode for character device mounted */
|
2022-01-06 01:47:31 +00:00
|
|
|
struct vnode *pm_odevvp;/* real devfs vnode */
|
2009-02-27 20:00:15 +00:00
|
|
|
struct cdev *pm_dev; /* character device mounted */
|
1994-09-19 15:41:57 +00:00
|
|
|
struct bpb50 pm_bpb; /* BIOS parameter blk for this fs */
|
2000-01-27 14:43:07 +00:00
|
|
|
u_long pm_BlkPerSec; /* How many DEV_BSIZE blocks fit inside a physical sector */
|
2017-05-21 19:29:28 +00:00
|
|
|
u_long pm_FATsecs; /* actual number of FAT sectors */
|
1994-09-19 15:41:57 +00:00
|
|
|
u_long pm_fatblk; /* block # of first FAT */
|
1998-02-18 09:28:47 +00:00
|
|
|
u_long pm_rootdirblk; /* block # (cluster # for FAT32) of root directory number */
|
1994-09-19 15:41:57 +00:00
|
|
|
u_long pm_rootdirsize; /* size in blocks (not clusters) */
|
|
|
|
u_long pm_firstcluster; /* block number of first cluster */
|
|
|
|
u_long pm_maxcluster; /* maximum cluster number */
|
|
|
|
u_long pm_freeclustercount; /* number of free clusters */
|
|
|
|
u_long pm_cnshift; /* shift file offset right this amount to get a cluster number */
|
|
|
|
u_long pm_crbomask; /* and a file offset with this mask to get cluster rel offset */
|
1998-02-18 09:28:47 +00:00
|
|
|
u_long pm_bnshift; /* shift file offset right this amount to get a block number */
|
1994-09-19 15:41:57 +00:00
|
|
|
u_long pm_bpcluster; /* bytes per cluster */
|
|
|
|
u_long pm_fmod; /* ~0 if fs is modified, this can rollover to 0 */
|
2017-05-21 19:29:28 +00:00
|
|
|
u_long pm_fatblocksize; /* size of FAT blocks in bytes */
|
|
|
|
u_long pm_fatblocksec; /* size of FAT blocks in sectors */
|
|
|
|
u_long pm_fatsize; /* size of FAT in bytes */
|
|
|
|
uint32_t pm_fatmask; /* mask to use for FAT numbers */
|
1998-02-18 09:28:47 +00:00
|
|
|
u_long pm_fsinfo; /* fsinfo block number */
|
Don't use almost perfectly pessimal cluster allocation. Allocation
of the the first cluster in a file (and, if the allocation cannot be
continued contiguously, for subsequent clusters in a file) was randomized
in an attempt to leave space for contiguous allocation of subsequent
clusters in each file when there are multiple writers. This reduced
internal fragmentation by a few percent, but it increased external
fragmentation by up to a few thousand percent.
Use simple sequential allocation instead. Actually maintain the fsinfo
sequence index for this. The read and write of this index from/to
disk still have many non-critical bugs, but we now write an index that
has something to do with our allocations instead of being modified
garbage. If there is no fsinfo on the disk, then we maintain the index
internally and don't go near the bugs for writing it.
Allocating the first free cluster gives a layout that is almost as good
(better in some cases), but takes too much CPU if the FAT is large and
the first free cluster is not near the beginning.
The effect of this change for untar and tar of a slightly reduced copy
of /usr/src on a new file system was:
Before (msdosfs 4K-clusters):
untar: 459.57 real untar from cached file (actually a pipe)
tar: 342.50 real tar from uncached tree to /dev/zero
Before (ffs2 soft updates 4K-blocks 4K-frags)
untar: 39.18 real
tar: 29.94 real
Before (ffs2 soft updates 16K-blocks 2K-frags)
untar: 31.35 real
tar: 18.30 real
After (msdosfs 4K-clusters):
untar 54.83 real
tar 16.18 real
All of these times can be improved further.
With multiple concurrent writers or readers (especially readers), the
improvement is smaller, but I couldn't find any case where it is
negative. 342 seconds for tarring up about 342 MB on a ~47MB/S partition
is just hard to unimprove on. (This operation would take about 7.3
seconds with reasonably localized allocation and perfect read-ahead.)
However, for active file systems, 342 seconds is closer to normal than
the 16+ seconds above or the 11 seconds with other changes (best I've
measured -- won easily by msdosfs!). E.g., my active /usr/src on ffs1
is quite old and fragmented, so reading to prepare for the above
benchmark takes about 6 times longer than reading back the fresh copies
of it.
Approved by: re (kensmith)
2007-07-10 13:20:24 +00:00
|
|
|
u_long pm_nxtfree; /* next place to search for a free cluster */
|
2017-05-21 19:29:28 +00:00
|
|
|
u_int pm_fatmult; /* these 2 values are used in FAT */
|
1998-02-18 09:28:47 +00:00
|
|
|
u_int pm_fatdiv; /* offset computation */
|
2017-05-21 19:29:28 +00:00
|
|
|
u_int pm_curfat; /* current FAT for FAT32 (0 otherwise) */
|
1994-09-19 15:41:57 +00:00
|
|
|
u_int *pm_inusemap; /* ptr to bitmap of in-use clusters */
|
2011-07-24 17:43:09 +00:00
|
|
|
uint64_t pm_flags; /* see below */
|
2003-09-26 20:26:25 +00:00
|
|
|
void *pm_u2w; /* Local->Unicode iconv handle */
|
|
|
|
void *pm_w2u; /* Unicode->Local iconv handle */
|
|
|
|
void *pm_u2d; /* Unicode->DOS iconv handle */
|
|
|
|
void *pm_d2u; /* DOS->Local iconv handle */
|
2020-01-27 12:02:41 +00:00
|
|
|
#ifndef MAKEFS
|
2017-06-09 12:06:22 +00:00
|
|
|
struct lock pm_fatlock; /* lockmgr protecting allocations */
|
2021-08-07 20:18:26 +00:00
|
|
|
struct lock pm_checkpath_lock; /* protects doscheckpath result */
|
2021-12-25 21:20:56 +00:00
|
|
|
struct task pm_rw2ro_task; /* context for emergency remount ro */
|
2020-01-27 12:02:41 +00:00
|
|
|
#endif
|
2004-07-03 13:22:38 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* A 64-bit file number and the 32-bit file number to which it is mapped,
|
|
|
|
* in a red-black tree node.
|
|
|
|
*/
|
|
|
|
struct msdosfs_fileno {
|
|
|
|
RB_ENTRY(msdosfs_fileno) mf_tree;
|
|
|
|
uint32_t mf_fileno32;
|
|
|
|
uint64_t mf_fileno64;
|
1994-09-19 15:41:57 +00:00
|
|
|
};
|
2004-07-03 13:22:38 +00:00
|
|
|
|
1998-02-18 09:28:47 +00:00
|
|
|
/* Byte offset in FAT on filesystem pmp, cluster cn */
|
|
|
|
#define FATOFS(pmp, cn) ((cn) * (pmp)->pm_fatmult / (pmp)->pm_fatdiv)
|
|
|
|
|
|
|
|
#define VFSTOMSDOSFS(mp) ((struct msdosfsmount *)mp->mnt_data)
|
1994-09-19 15:41:57 +00:00
|
|
|
|
|
|
|
/* Number of bits in one pm_inusemap item: */
|
|
|
|
#define N_INUSEBITS (8 * sizeof(u_int))
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Shorthand for fields in the bpb contained in the msdosfsmount structure.
|
|
|
|
*/
|
|
|
|
#define pm_BytesPerSec pm_bpb.bpbBytesPerSec
|
|
|
|
#define pm_ResSectors pm_bpb.bpbResSectors
|
|
|
|
#define pm_FATs pm_bpb.bpbFATs
|
|
|
|
#define pm_RootDirEnts pm_bpb.bpbRootDirEnts
|
|
|
|
#define pm_Sectors pm_bpb.bpbSectors
|
|
|
|
#define pm_Media pm_bpb.bpbMedia
|
|
|
|
#define pm_SecPerTrack pm_bpb.bpbSecPerTrack
|
|
|
|
#define pm_Heads pm_bpb.bpbHeads
|
|
|
|
#define pm_HiddenSects pm_bpb.bpbHiddenSecs
|
|
|
|
#define pm_HugeSectors pm_bpb.bpbHugeSectors
|
|
|
|
|
|
|
|
/*
|
1998-02-18 09:28:47 +00:00
|
|
|
* Convert pointer to buffer -> pointer to direntry
|
1994-09-19 15:41:57 +00:00
|
|
|
*/
|
1998-02-18 09:28:47 +00:00
|
|
|
#define bptoep(pmp, bp, dirofs) \
|
|
|
|
((struct direntry *)(((bp)->b_data) \
|
|
|
|
+ ((dirofs) & (pmp)->pm_crbomask)))
|
1994-09-19 15:41:57 +00:00
|
|
|
|
|
|
|
/*
|
1998-02-18 09:28:47 +00:00
|
|
|
* Convert block number to cluster number
|
1994-09-19 15:41:57 +00:00
|
|
|
*/
|
1998-02-18 09:28:47 +00:00
|
|
|
#define de_bn2cn(pmp, bn) \
|
|
|
|
((bn) >> ((pmp)->pm_cnshift - (pmp)->pm_bnshift))
|
1994-09-19 15:41:57 +00:00
|
|
|
|
|
|
|
/*
|
1998-02-18 09:28:47 +00:00
|
|
|
* Convert cluster number to block number
|
1994-09-19 15:41:57 +00:00
|
|
|
*/
|
1998-02-18 09:28:47 +00:00
|
|
|
#define de_cn2bn(pmp, cn) \
|
|
|
|
((cn) << ((pmp)->pm_cnshift - (pmp)->pm_bnshift))
|
1994-09-19 15:41:57 +00:00
|
|
|
|
|
|
|
/*
|
1998-02-18 09:28:47 +00:00
|
|
|
* Convert file offset to cluster number
|
1994-09-19 15:41:57 +00:00
|
|
|
*/
|
1998-02-18 09:28:47 +00:00
|
|
|
#define de_cluster(pmp, off) \
|
|
|
|
((off) >> (pmp)->pm_cnshift)
|
1994-09-19 15:41:57 +00:00
|
|
|
|
|
|
|
/*
|
1998-02-18 09:28:47 +00:00
|
|
|
* Clusters required to hold size bytes
|
1994-09-19 15:41:57 +00:00
|
|
|
*/
|
1998-02-18 09:28:47 +00:00
|
|
|
#define de_clcount(pmp, size) \
|
|
|
|
(((size) + (pmp)->pm_bpcluster - 1) >> (pmp)->pm_cnshift)
|
1994-09-19 15:41:57 +00:00
|
|
|
|
|
|
|
/*
|
1998-02-18 09:28:47 +00:00
|
|
|
* Convert file offset to block number
|
1994-09-19 15:41:57 +00:00
|
|
|
*/
|
|
|
|
#define de_blk(pmp, off) \
|
1998-02-18 09:28:47 +00:00
|
|
|
(de_cn2bn(pmp, de_cluster((pmp), (off))))
|
1994-09-19 15:41:57 +00:00
|
|
|
|
|
|
|
/*
|
1998-02-18 09:28:47 +00:00
|
|
|
* Convert cluster number to file offset
|
1994-09-19 15:41:57 +00:00
|
|
|
*/
|
1998-02-18 09:28:47 +00:00
|
|
|
#define de_cn2off(pmp, cn) \
|
|
|
|
((cn) << (pmp)->pm_cnshift)
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Convert block number to file offset
|
|
|
|
*/
|
|
|
|
#define de_bn2off(pmp, bn) \
|
|
|
|
((bn) << (pmp)->pm_bnshift)
|
|
|
|
/*
|
|
|
|
* Map a cluster number into a filesystem relative block number.
|
|
|
|
*/
|
|
|
|
#define cntobn(pmp, cn) \
|
|
|
|
(de_cn2bn((pmp), (cn)-CLUST_FIRST) + (pmp)->pm_firstcluster)
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Calculate block number for directory entry in root dir, offset dirofs
|
|
|
|
*/
|
|
|
|
#define roottobn(pmp, dirofs) \
|
|
|
|
(de_blk((pmp), (dirofs)) + (pmp)->pm_rootdirblk)
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Calculate block number for directory entry at cluster dirclu, offset
|
|
|
|
* dirofs
|
|
|
|
*/
|
|
|
|
#define detobn(pmp, dirclu, dirofs) \
|
|
|
|
((dirclu) == MSDOSFSROOT \
|
|
|
|
? roottobn((pmp), (dirofs)) \
|
|
|
|
: cntobn((pmp), (dirclu)))
|
1994-09-19 15:41:57 +00:00
|
|
|
|
2010-02-28 17:13:07 +00:00
|
|
|
#define MSDOSFS_LOCK_MP(pmp) \
|
|
|
|
lockmgr(&(pmp)->pm_fatlock, LK_EXCLUSIVE, NULL)
|
|
|
|
#define MSDOSFS_UNLOCK_MP(pmp) \
|
|
|
|
lockmgr(&(pmp)->pm_fatlock, LK_RELEASE, NULL)
|
|
|
|
#define MSDOSFS_ASSERT_MP_LOCKED(pmp) \
|
|
|
|
lockmgr_assert(&(pmp)->pm_fatlock, KA_XLOCKED)
|
|
|
|
|
2019-09-09 18:35:17 +00:00
|
|
|
#endif /* _KERNEL || MAKEFS */
|
1997-03-03 17:36:11 +00:00
|
|
|
|
2019-09-01 16:55:33 +00:00
|
|
|
#ifndef MAKEFS
|
1997-02-10 02:22:35 +00:00
|
|
|
/*
|
|
|
|
* Arguments to mount MSDOS filesystems.
|
|
|
|
*/
|
|
|
|
struct msdosfs_args {
|
|
|
|
char *fspec; /* blocks special holding the fs to mount */
|
2010-10-10 07:05:47 +00:00
|
|
|
struct oexport_args export; /* network export information */
|
1997-02-10 02:22:35 +00:00
|
|
|
uid_t uid; /* uid that owns msdosfs files */
|
|
|
|
gid_t gid; /* gid that owns msdosfs files */
|
2003-08-12 20:06:56 +00:00
|
|
|
mode_t mask; /* file mask to be applied for msdosfs perms */
|
1998-02-18 09:28:47 +00:00
|
|
|
int flags; /* see below */
|
2015-03-22 09:09:26 +00:00
|
|
|
int unused1; /* unused, was version number */
|
2017-05-19 18:13:41 +00:00
|
|
|
uint16_t unused2[128]; /* no longer used, was Local->Unicode table */
|
2003-09-26 20:26:25 +00:00
|
|
|
char *cs_win; /* Windows(Unicode) Charset */
|
|
|
|
char *cs_dos; /* DOS Charset */
|
|
|
|
char *cs_local; /* Local Charset */
|
2004-07-03 13:22:38 +00:00
|
|
|
mode_t dirmask; /* dir mask to be applied for msdosfs perms */
|
1997-02-10 02:22:35 +00:00
|
|
|
};
|
2019-09-01 16:55:33 +00:00
|
|
|
#endif /* MAKEFS */
|
1997-02-10 02:22:35 +00:00
|
|
|
|
1998-02-18 09:28:47 +00:00
|
|
|
/*
|
|
|
|
* Msdosfs mount options:
|
|
|
|
*/
|
|
|
|
#define MSDOSFSMNT_SHORTNAME 1 /* Force old DOS short names only */
|
|
|
|
#define MSDOSFSMNT_LONGNAME 2 /* Force Win'95 long names */
|
|
|
|
#define MSDOSFSMNT_NOWIN95 4 /* Completely ignore Win95 entries */
|
2003-09-26 20:26:25 +00:00
|
|
|
#define MSDOSFSMNT_KICONV 0x10 /* Use libiconv to convert chars */
|
1998-02-18 09:28:47 +00:00
|
|
|
/* All flags above: */
|
|
|
|
#define MSDOSFSMNT_MNTOPT \
|
|
|
|
(MSDOSFSMNT_SHORTNAME|MSDOSFSMNT_LONGNAME|MSDOSFSMNT_NOWIN95 \
|
2003-09-26 20:26:25 +00:00
|
|
|
|MSDOSFSMNT_KICONV)
|
1998-02-18 09:28:47 +00:00
|
|
|
#define MSDOSFSMNT_RONLY 0x80000000 /* mounted read-only */
|
|
|
|
#define MSDOSFSMNT_WAITONFAT 0x40000000 /* mounted synchronous */
|
|
|
|
#define MSDOSFS_FATMIRROR 0x20000000 /* FAT is mirrored */
|
2013-02-17 20:35:54 +00:00
|
|
|
#define MSDOSFS_FSIMOD 0x01000000
|
2021-12-25 21:20:56 +00:00
|
|
|
#define MSDOSFS_ERR_RO 0x00800000 /* remouning ro due to error */
|
|
|
|
|
|
|
|
#ifdef _KERNEL
|
|
|
|
void msdosfs_integrity_error(struct msdosfsmount *pmp);
|
|
|
|
#endif
|
1998-02-18 09:28:47 +00:00
|
|
|
|
1997-03-03 17:36:11 +00:00
|
|
|
#endif /* !_MSDOSFS_MSDOSFSMOUNT_H_ */
|