/* $NetBSD: msdosfsmount.h,v 1.17 1997/11/17 15:37:07 ws Exp $ */12/*-3* SPDX-License-Identifier: BSD-4-Clause4*5* Copyright (C) 1994, 1995, 1997 Wolfgang Solfrank.6* Copyright (C) 1994, 1995, 1997 TooLs GmbH.7* All rights reserved.8* Original code by Paul Popelka ([email protected]) (see below).9*10* Redistribution and use in source and binary forms, with or without11* modification, are permitted provided that the following conditions12* are met:13* 1. Redistributions of source code must retain the above copyright14* notice, this list of conditions and the following disclaimer.15* 2. Redistributions in binary form must reproduce the above copyright16* notice, this list of conditions and the following disclaimer in the17* documentation and/or other materials provided with the distribution.18* 3. All advertising materials mentioning features or use of this software19* must display the following acknowledgement:20* This product includes software developed by TooLs GmbH.21* 4. The name of TooLs GmbH may not be used to endorse or promote products22* derived from this software without specific prior written permission.23*24* THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR25* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES26* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.27* IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,28* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,29* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;30* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,31* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR32* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF33* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.34*/35/*-36* Written by Paul Popelka ([email protected])37*38* You can do anything you want with this software, just don't say you wrote39* it, and don't remove this notice.40*41* This software is provided "as is".42*43* The author supplies this software to be publicly redistributed on the44* understanding that the author is not responsible for the correct45* functioning of this software in any circumstances and is not liable for46* any damages caused by this software.47*48* October 199249*/5051#ifndef _MSDOSFS_MSDOSFSMOUNT_H_52#define _MSDOSFS_MSDOSFSMOUNT_H_5354#if defined(_KERNEL) || defined(_WANT_MSDOSFS_INTERNALS)5556#include <sys/types.h>57#ifdef _KERNEL58#include <sys/lock.h>59#include <sys/lockmgr.h>60#else61#include <sys/_lock.h>62#include <sys/_lockmgr.h>63#endif64#include <sys/_task.h>65#include <sys/tree.h>6667#ifdef MALLOC_DECLARE68MALLOC_DECLARE(M_MSDOSFSMNT);69#endif7071struct msdosfs_fileno;7273/*74* Layout of the mount control block for a MSDOSFS filesystem.75*/76struct msdosfsmount {77struct mount *pm_mountp;/* vfs mount struct for this fs */78struct g_consumer *pm_cp;79struct bufobj *pm_bo;80uid_t pm_uid; /* uid to set as owner of the files */81gid_t pm_gid; /* gid to set as owner of the files */82mode_t pm_mask; /* mask to and with file protection bits83for files */84mode_t pm_dirmask; /* mask to and with file protection bits85for directories */86struct vnode *pm_devvp; /* vnode for character device mounted */87struct vnode *pm_odevvp;/* real devfs vnode */88struct cdev *pm_dev; /* character device mounted */89struct bpb50 pm_bpb; /* BIOS parameter blk for this fs */90u_long pm_BlkPerSec; /* How many DEV_BSIZE blocks fit inside a physical sector */91u_long pm_FATsecs; /* actual number of FAT sectors */92u_long pm_fatblk; /* block # of first FAT */93u_long pm_rootdirblk; /* block # (cluster # for FAT32) of root directory number */94u_long pm_rootdirsize; /* size in blocks (not clusters) */95u_long pm_firstcluster; /* block number of first cluster */96u_long pm_maxcluster; /* maximum cluster number */97u_long pm_freeclustercount; /* number of free clusters */98u_long pm_cnshift; /* shift file offset right this amount to get a cluster number */99u_long pm_crbomask; /* and a file offset with this mask to get cluster rel offset */100u_long pm_bnshift; /* shift file offset right this amount to get a block number */101u_long pm_bpcluster; /* bytes per cluster */102u_long pm_fmod; /* ~0 if fs is modified, this can rollover to 0 */103u_long pm_fatblocksize; /* size of FAT blocks in bytes */104u_long pm_fatblocksec; /* size of FAT blocks in sectors */105u_long pm_fatsize; /* size of FAT in bytes */106uint32_t pm_fatmask; /* mask to use for FAT numbers */107u_long pm_fsinfo; /* fsinfo block number */108u_long pm_nxtfree; /* next place to search for a free cluster */109u_int pm_fatmult; /* these 2 values are used in FAT */110u_int pm_fatdiv; /* offset computation */111u_int pm_curfat; /* current FAT for FAT32 (0 otherwise) */112int pm_rootdirfree; /* number of free slots in FAT12/16 root directory */113u_int *pm_inusemap; /* ptr to bitmap of in-use clusters */114uint64_t pm_flags; /* see below */115void *pm_u2w; /* Local->Unicode iconv handle */116void *pm_w2u; /* Unicode->Local iconv handle */117void *pm_u2d; /* Unicode->DOS iconv handle */118void *pm_d2u; /* DOS->Local iconv handle */119struct lock pm_fatlock; /* lockmgr protecting allocations */120struct task pm_rw2ro_task; /* context for emergency remount ro */121};122123/*124* A 64-bit file number and the 32-bit file number to which it is mapped,125* in a red-black tree node.126*/127struct msdosfs_fileno {128RB_ENTRY(msdosfs_fileno) mf_tree;129uint32_t mf_fileno32;130uint64_t mf_fileno64;131};132133/* Byte offset in FAT on filesystem pmp, cluster cn */134#define FATOFS(pmp, cn) ((cn) * (pmp)->pm_fatmult / (pmp)->pm_fatdiv)135136#define VFSTOMSDOSFS(mp) ((struct msdosfsmount *)mp->mnt_data)137138/* Number of bits in one pm_inusemap item: */139#define N_INUSEBITS (8 * sizeof(u_int))140141/*142* Shorthand for fields in the bpb contained in the msdosfsmount structure.143*/144#define pm_BytesPerSec pm_bpb.bpbBytesPerSec145#define pm_ResSectors pm_bpb.bpbResSectors146#define pm_FATs pm_bpb.bpbFATs147#define pm_RootDirEnts pm_bpb.bpbRootDirEnts148#define pm_Sectors pm_bpb.bpbSectors149#define pm_Media pm_bpb.bpbMedia150#define pm_SecPerTrack pm_bpb.bpbSecPerTrack151#define pm_Heads pm_bpb.bpbHeads152#define pm_HiddenSects pm_bpb.bpbHiddenSecs153#define pm_HugeSectors pm_bpb.bpbHugeSectors154155/*156* Convert pointer to buffer -> pointer to direntry157*/158#define bptoep(pmp, bp, dirofs) \159((struct direntry *)(((bp)->b_data) \160+ ((dirofs) & (pmp)->pm_crbomask)))161162/*163* Convert block number to cluster number164*/165#define de_bn2cn(pmp, bn) \166((bn) >> ((pmp)->pm_cnshift - (pmp)->pm_bnshift))167168/*169* Convert cluster number to block number170*/171#define de_cn2bn(pmp, cn) \172((cn) << ((pmp)->pm_cnshift - (pmp)->pm_bnshift))173174/*175* Convert file offset to cluster number176*/177#define de_cluster(pmp, off) \178((off) >> (pmp)->pm_cnshift)179180/*181* Clusters required to hold size bytes182*/183#define de_clcount(pmp, size) \184(((size) + (pmp)->pm_bpcluster - 1) >> (pmp)->pm_cnshift)185186/*187* Convert file offset to block number188*/189#define de_blk(pmp, off) \190(de_cn2bn(pmp, de_cluster((pmp), (off))))191192/*193* Convert cluster number to file offset194*/195#define de_cn2off(pmp, cn) \196((cn) << (pmp)->pm_cnshift)197198/*199* Convert block number to file offset200*/201#define de_bn2off(pmp, bn) \202((bn) << (pmp)->pm_bnshift)203/*204* Map a cluster number into a filesystem relative block number.205*/206#define cntobn(pmp, cn) \207(de_cn2bn((pmp), (cn)-CLUST_FIRST) + (pmp)->pm_firstcluster)208209/*210* Calculate block number for directory entry in root dir, offset dirofs211*/212#define roottobn(pmp, dirofs) \213(de_blk((pmp), (dirofs)) + (pmp)->pm_rootdirblk)214215/*216* Calculate block number for directory entry at cluster dirclu, offset217* dirofs218*/219#define detobn(pmp, dirclu, dirofs) \220((dirclu) == MSDOSFSROOT \221? roottobn((pmp), (dirofs)) \222: cntobn((pmp), (dirclu)))223224/*225* Increment the number of used entries in a fixed size FAT12/16 root226* directory227*/228#define rootde_alloced(dep) \229if ((dep)->de_StartCluster == MSDOSFSROOT) \230(dep)->de_pmp->pm_rootdirfree--;231232/*233* Decrement the number of used entries in a fixed size FAT12/16 root234* directory235*/236#define rootde_freed(dep) \237if ((dep)->de_StartCluster == MSDOSFSROOT) \238(dep)->de_pmp->pm_rootdirfree++;239240#define MSDOSFS_LOCK_MP(pmp) \241lockmgr(&(pmp)->pm_fatlock, LK_EXCLUSIVE, NULL)242#define MSDOSFS_UNLOCK_MP(pmp) \243lockmgr(&(pmp)->pm_fatlock, LK_RELEASE, NULL)244#define MSDOSFS_ASSERT_MP_LOCKED(pmp) \245lockmgr_assert(&(pmp)->pm_fatlock, KA_XLOCKED)246247#endif /* _KERNEL || _WANT_MSDOSFS_INTERNALS */248249#ifdef _KERNEL250/*251* Arguments to mount MSDOS filesystems.252*/253struct msdosfs_args {254char *fspec; /* blocks special holding the fs to mount */255struct oexport_args export; /* network export information */256uid_t uid; /* uid that owns msdosfs files */257gid_t gid; /* gid that owns msdosfs files */258mode_t mask; /* file mask to be applied for msdosfs perms */259int flags; /* see below */260int unused1; /* unused, was version number */261uint16_t unused2[128]; /* no longer used, was Local->Unicode table */262char *cs_win; /* Windows(Unicode) Charset */263char *cs_dos; /* DOS Charset */264char *cs_local; /* Local Charset */265mode_t dirmask; /* dir mask to be applied for msdosfs perms */266};267#endif /* _KERNEL */268269/*270* Msdosfs mount options:271*/272#define MSDOSFSMNT_SHORTNAME 1 /* Force old DOS short names only */273#define MSDOSFSMNT_LONGNAME 2 /* Force Win'95 long names */274#define MSDOSFSMNT_NOWIN95 4 /* Completely ignore Win95 entries */275#define MSDOSFSMNT_KICONV 0x10 /* Use libiconv to convert chars */276/* All flags above: */277#define MSDOSFSMNT_MNTOPT \278(MSDOSFSMNT_SHORTNAME|MSDOSFSMNT_LONGNAME|MSDOSFSMNT_NOWIN95 \279|MSDOSFSMNT_KICONV)280#define MSDOSFSMNT_RONLY 0x80000000 /* mounted read-only */281#define MSDOSFSMNT_WAITONFAT 0x40000000 /* mounted synchronous */282#define MSDOSFS_FATMIRROR 0x20000000 /* FAT is mirrored */283#define MSDOSFS_FSIMOD 0x01000000284#define MSDOSFS_ERR_RO 0x00800000 /* remouning ro due to error */285286#ifdef _KERNEL287void msdosfs_integrity_error(struct msdosfsmount *pmp);288#endif289290#endif /* !_MSDOSFS_MSDOSFSMOUNT_H_ */291292293