* SPDX-License-Identifier: BSD-4-Clause
*
* Copyright (C) 1994, 1995, 1997 Wolfgang Solfrank.
* Copyright (C) 1994, 1995, 1997 TooLs GmbH.
* 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)
*
* You can do anything you want with this software, just don't say you wrote
* it, and don't remove this notice.
*
* This software is provided "as is".
*
* The author supplies this software to be publicly redistributed on the
* understanding that the author is not responsible for the correct
* functioning of this software in any circumstances and is not liable for
* any damages caused by this software.
*
* October 1992
*/
#ifndef _MSDOSFS_MSDOSFSMOUNT_H_
#define _MSDOSFS_MSDOSFSMOUNT_H_
#if defined (_KERNEL) || defined(MAKEFS)
#include <sys/types.h>
#ifndef MAKEFS
#include <sys/lockmgr.h>
#include <sys/_task.h>
#endif
#ifdef MALLOC_DECLARE
MALLOC_DECLARE(M_MSDOSFSMNT);
#endif
struct msdosfs_fileno;
* Layout of the mount control block for a MSDOSFS filesystem.
*/
struct msdosfsmount {
struct mount *pm_mountp;
struct g_consumer *pm_cp;
struct bufobj *pm_bo;
uid_t pm_uid;
gid_t pm_gid;
mode_t pm_mask;
for files */
mode_t pm_dirmask;
for directories */
struct vnode *pm_devvp;
struct vnode *pm_odevvp;
struct cdev *pm_dev;
struct bpb50 pm_bpb;
u_long pm_BlkPerSec;
u_long pm_FATsecs;
u_long pm_fatblk;
u_long pm_rootdirblk;
u_long pm_rootdirsize;
u_long pm_firstcluster;
u_long pm_maxcluster;
u_long pm_freeclustercount;
u_long pm_cnshift;
u_long pm_crbomask;
u_long pm_bnshift;
u_long pm_bpcluster;
u_long pm_fmod;
u_long pm_fatblocksize;
u_long pm_fatblocksec;
u_long pm_fatsize;
uint32_t pm_fatmask;
u_long pm_fsinfo;
u_long pm_nxtfree;
u_int pm_fatmult;
u_int pm_fatdiv;
u_int pm_curfat;
int pm_rootdirfree;
u_int *pm_inusemap;
uint64_t pm_flags;
void *pm_u2w;
void *pm_w2u;
void *pm_u2d;
void *pm_d2u;
#ifndef MAKEFS
struct lock pm_fatlock;
struct lock pm_checkpath_lock;
struct task pm_rw2ro_task;
#endif
};
* 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 {
uint32_t mf_fileno32;
uint64_t mf_fileno64;
};
#define FATOFS(pmp, cn) ((cn) * (pmp)->pm_fatmult / (pmp)->pm_fatdiv)
#define VFSTOMSDOSFS(mp) ((struct msdosfsmount *)mp->mnt_data)
#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
* Convert pointer to buffer -> pointer to direntry
*/
#define bptoep(pmp, bp, dirofs) \
((struct direntry *)(((bp)->b_data) \
+ ((dirofs) & (pmp)->pm_crbomask)))
* Convert block number to cluster number
*/
#define de_bn2cn(pmp, bn) \
((bn) >> ((pmp)->pm_cnshift - (pmp)->pm_bnshift))
* Convert cluster number to block number
*/
#define de_cn2bn(pmp, cn) \
((cn) << ((pmp)->pm_cnshift - (pmp)->pm_bnshift))
* Convert file offset to cluster number
*/
#define de_cluster(pmp, off) \
((off) >> (pmp)->pm_cnshift)
* Clusters required to hold size bytes
*/
#define de_clcount(pmp, size) \
(((size) + (pmp)->pm_bpcluster - 1) >> (pmp)->pm_cnshift)
* Convert file offset to block number
*/
#define de_blk(pmp, off) \
(de_cn2bn(pmp, de_cluster((pmp), (off))))
* Convert cluster number to file offset
*/
#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)))
* Increment the number of used entries in a fixed size FAT12/16 root
* directory
*/
#define rootde_alloced(dep) \
if ((dep)->de_StartCluster == MSDOSFSROOT) \
(dep)->de_pmp->pm_rootdirfree--;
* Decrement the number of used entries in a fixed size FAT12/16 root
* directory
*/
#define rootde_freed(dep) \
if ((dep)->de_StartCluster == MSDOSFSROOT) \
(dep)->de_pmp->pm_rootdirfree++;
#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)
#endif
#if 0
* Arguments to mount MSDOS filesystems.
*/
struct msdosfs_args {
char *fspec;
struct oexport_args export;
uid_t uid;
gid_t gid;
mode_t mask;
int flags;
int unused1;
uint16_t unused2[128];
char *cs_win;
char *cs_dos;
char *cs_local;
mode_t dirmask;
};
#endif
* 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 */
#define MSDOSFSMNT_KICONV 0x10 /* Use libiconv to convert chars */
#define MSDOSFSMNT_MNTOPT \
(MSDOSFSMNT_SHORTNAME|MSDOSFSMNT_LONGNAME|MSDOSFSMNT_NOWIN95 \
|MSDOSFSMNT_KICONV)
#define MSDOSFSMNT_RONLY 0x80000000 /* mounted read-only */
#define MSDOSFSMNT_WAITONFAT 0x40000000 /* mounted synchronous */
#define MSDOSFS_FATMIRROR 0x20000000 /* FAT is mirrored */
#define MSDOSFS_FSIMOD 0x01000000
#define MSDOSFS_ERR_RO 0x00800000 /* remouning ro due to error */
#ifdef _KERNEL
void msdosfs_integrity_error(struct msdosfsmount *pmp);
#endif
#endif