1c3aac50fSPeter Wemm /* $FreeBSD$ */ 2952a6212SJordan K. Hubbard /* $NetBSD: msdosfsmount.h,v 1.17 1997/11/17 15:37:07 ws Exp $ */ 327a0bc89SDoug Rabson 427a0bc89SDoug Rabson /*- 5952a6212SJordan K. Hubbard * Copyright (C) 1994, 1995, 1997 Wolfgang Solfrank. 6952a6212SJordan K. Hubbard * Copyright (C) 1994, 1995, 1997 TooLs GmbH. 727a0bc89SDoug Rabson * All rights reserved. 827a0bc89SDoug Rabson * Original code by Paul Popelka (paulp@uts.amdahl.com) (see below). 927a0bc89SDoug Rabson * 1027a0bc89SDoug Rabson * Redistribution and use in source and binary forms, with or without 1127a0bc89SDoug Rabson * modification, are permitted provided that the following conditions 1227a0bc89SDoug Rabson * are met: 1327a0bc89SDoug Rabson * 1. Redistributions of source code must retain the above copyright 1427a0bc89SDoug Rabson * notice, this list of conditions and the following disclaimer. 1527a0bc89SDoug Rabson * 2. Redistributions in binary form must reproduce the above copyright 1627a0bc89SDoug Rabson * notice, this list of conditions and the following disclaimer in the 1727a0bc89SDoug Rabson * documentation and/or other materials provided with the distribution. 1827a0bc89SDoug Rabson * 3. All advertising materials mentioning features or use of this software 1927a0bc89SDoug Rabson * must display the following acknowledgement: 2027a0bc89SDoug Rabson * This product includes software developed by TooLs GmbH. 2127a0bc89SDoug Rabson * 4. The name of TooLs GmbH may not be used to endorse or promote products 2227a0bc89SDoug Rabson * derived from this software without specific prior written permission. 2327a0bc89SDoug Rabson * 2427a0bc89SDoug Rabson * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR 2527a0bc89SDoug Rabson * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 2627a0bc89SDoug Rabson * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 2727a0bc89SDoug Rabson * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 2827a0bc89SDoug Rabson * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 2927a0bc89SDoug Rabson * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 3027a0bc89SDoug Rabson * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 3127a0bc89SDoug Rabson * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 3227a0bc89SDoug Rabson * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 3327a0bc89SDoug Rabson * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 3427a0bc89SDoug Rabson */ 35d167cf6fSWarner Losh /*- 3627a0bc89SDoug Rabson * Written by Paul Popelka (paulp@uts.amdahl.com) 3727a0bc89SDoug Rabson * 3827a0bc89SDoug Rabson * You can do anything you want with this software, just don't say you wrote 3927a0bc89SDoug Rabson * it, and don't remove this notice. 4027a0bc89SDoug Rabson * 4127a0bc89SDoug Rabson * This software is provided "as is". 4227a0bc89SDoug Rabson * 4327a0bc89SDoug Rabson * The author supplies this software to be publicly redistributed on the 4427a0bc89SDoug Rabson * understanding that the author is not responsible for the correct 4527a0bc89SDoug Rabson * functioning of this software in any circumstances and is not liable for 4627a0bc89SDoug Rabson * any damages caused by this software. 4727a0bc89SDoug Rabson * 4827a0bc89SDoug Rabson * October 1992 4927a0bc89SDoug Rabson */ 5027a0bc89SDoug Rabson 5160e0f7e2SBruce Evans #ifndef _MSDOSFS_MSDOSFSMOUNT_H_ 5260e0f7e2SBruce Evans #define _MSDOSFS_MSDOSFSMOUNT_H_ 5360e0f7e2SBruce Evans 54c4473420SPeter Wemm #ifdef _KERNEL 5560e0f7e2SBruce Evans 5623b6c230SKonstantin Belousov #include <sys/types.h> 5723b6c230SKonstantin Belousov #include <sys/lock.h> 5823b6c230SKonstantin Belousov #include <sys/lockmgr.h> 593bc482ecSTim J. Robbins #include <sys/tree.h> 603bc482ecSTim J. Robbins 61a1c995b6SPoul-Henning Kamp #ifdef MALLOC_DECLARE 62a1c995b6SPoul-Henning Kamp MALLOC_DECLARE(M_MSDOSFSMNT); 63a1c995b6SPoul-Henning Kamp #endif 64a1c995b6SPoul-Henning Kamp 653bc482ecSTim J. Robbins struct msdosfs_fileno; 663bc482ecSTim J. Robbins 6727a0bc89SDoug Rabson /* 68*9287dbaaSEd Maste * Layout of the mount control block for a MSDOSFS filesystem. 6927a0bc89SDoug Rabson */ 7027a0bc89SDoug Rabson struct msdosfsmount { 7127a0bc89SDoug Rabson struct mount *pm_mountp;/* vfs mount struct for this fs */ 729a135592SPoul-Henning Kamp struct g_consumer *pm_cp; 739a135592SPoul-Henning Kamp struct bufobj *pm_bo; 7427a0bc89SDoug Rabson uid_t pm_uid; /* uid to set as owner of the files */ 7527a0bc89SDoug Rabson gid_t pm_gid; /* gid to set as owner of the files */ 76c98a31caSTom Rhodes mode_t pm_mask; /* mask to and with file protection bits 77c98a31caSTom Rhodes for files */ 78c98a31caSTom Rhodes mode_t pm_dirmask; /* mask to and with file protection bits 79c98a31caSTom Rhodes for directories */ 80c72ae142SJohn Baldwin struct vnode *pm_devvp; /* vnode for character device mounted */ 81c72ae142SJohn Baldwin struct cdev *pm_dev; /* character device mounted */ 8227a0bc89SDoug Rabson struct bpb50 pm_bpb; /* BIOS parameter blk for this fs */ 8301f6cfbaSYoshihiro Takahashi u_long pm_BlkPerSec; /* How many DEV_BSIZE blocks fit inside a physical sector */ 84*9287dbaaSEd Maste u_long pm_FATsecs; /* actual number of FAT sectors */ 8527a0bc89SDoug Rabson u_long pm_fatblk; /* block # of first FAT */ 86952a6212SJordan K. Hubbard u_long pm_rootdirblk; /* block # (cluster # for FAT32) of root directory number */ 8727a0bc89SDoug Rabson u_long pm_rootdirsize; /* size in blocks (not clusters) */ 8827a0bc89SDoug Rabson u_long pm_firstcluster; /* block number of first cluster */ 8927a0bc89SDoug Rabson u_long pm_maxcluster; /* maximum cluster number */ 9027a0bc89SDoug Rabson u_long pm_freeclustercount; /* number of free clusters */ 9127a0bc89SDoug Rabson u_long pm_cnshift; /* shift file offset right this amount to get a cluster number */ 9227a0bc89SDoug Rabson u_long pm_crbomask; /* and a file offset with this mask to get cluster rel offset */ 93952a6212SJordan K. Hubbard u_long pm_bnshift; /* shift file offset right this amount to get a block number */ 9427a0bc89SDoug Rabson u_long pm_bpcluster; /* bytes per cluster */ 9527a0bc89SDoug Rabson u_long pm_fmod; /* ~0 if fs is modified, this can rollover to 0 */ 96*9287dbaaSEd Maste u_long pm_fatblocksize; /* size of FAT blocks in bytes */ 97*9287dbaaSEd Maste u_long pm_fatblocksec; /* size of FAT blocks in sectors */ 98*9287dbaaSEd Maste u_long pm_fatsize; /* size of FAT in bytes */ 99*9287dbaaSEd Maste uint32_t pm_fatmask; /* mask to use for FAT numbers */ 100952a6212SJordan K. Hubbard u_long pm_fsinfo; /* fsinfo block number */ 1018e55bfafSBruce Evans u_long pm_nxtfree; /* next place to search for a free cluster */ 102*9287dbaaSEd Maste u_int pm_fatmult; /* these 2 values are used in FAT */ 103952a6212SJordan K. Hubbard u_int pm_fatdiv; /* offset computation */ 104*9287dbaaSEd Maste u_int pm_curfat; /* current FAT for FAT32 (0 otherwise) */ 10527a0bc89SDoug Rabson u_int *pm_inusemap; /* ptr to bitmap of in-use clusters */ 1066beb3bb4SKirk McKusick uint64_t pm_flags; /* see below */ 107c4f02a89SMax Khon void *pm_u2w; /* Local->Unicode iconv handle */ 108c4f02a89SMax Khon void *pm_w2u; /* Unicode->Local iconv handle */ 109c4f02a89SMax Khon void *pm_u2d; /* Unicode->DOS iconv handle */ 110c4f02a89SMax Khon void *pm_d2u; /* DOS->Local iconv handle */ 11123c53312SEd Maste uint32_t pm_nfileno; /* next 32-bit fileno */ 11223b6c230SKonstantin Belousov RB_HEAD(msdosfs_filenotree, msdosfs_fileno) 11323b6c230SKonstantin Belousov pm_filenos; /* 64<->32-bit fileno mapping */ 11423b6c230SKonstantin Belousov struct lock pm_fatlock; /* lockmgr protecting allocations and rb tree */ 11527a0bc89SDoug Rabson }; 1163bc482ecSTim J. Robbins 1173bc482ecSTim J. Robbins /* 1183bc482ecSTim J. Robbins * A 64-bit file number and the 32-bit file number to which it is mapped, 1193bc482ecSTim J. Robbins * in a red-black tree node. 1203bc482ecSTim J. Robbins */ 1213bc482ecSTim J. Robbins struct msdosfs_fileno { 1223bc482ecSTim J. Robbins RB_ENTRY(msdosfs_fileno) mf_tree; 1233bc482ecSTim J. Robbins uint32_t mf_fileno32; 1243bc482ecSTim J. Robbins uint64_t mf_fileno64; 1253bc482ecSTim J. Robbins }; 1263bc482ecSTim J. Robbins 127952a6212SJordan K. Hubbard /* Byte offset in FAT on filesystem pmp, cluster cn */ 128952a6212SJordan K. Hubbard #define FATOFS(pmp, cn) ((cn) * (pmp)->pm_fatmult / (pmp)->pm_fatdiv) 129952a6212SJordan K. Hubbard 130952a6212SJordan K. Hubbard 131952a6212SJordan K. Hubbard #define VFSTOMSDOSFS(mp) ((struct msdosfsmount *)mp->mnt_data) 13227a0bc89SDoug Rabson 13327a0bc89SDoug Rabson /* Number of bits in one pm_inusemap item: */ 13427a0bc89SDoug Rabson #define N_INUSEBITS (8 * sizeof(u_int)) 13527a0bc89SDoug Rabson 13627a0bc89SDoug Rabson /* 13727a0bc89SDoug Rabson * Shorthand for fields in the bpb contained in the msdosfsmount structure. 13827a0bc89SDoug Rabson */ 13927a0bc89SDoug Rabson #define pm_BytesPerSec pm_bpb.bpbBytesPerSec 14027a0bc89SDoug Rabson #define pm_ResSectors pm_bpb.bpbResSectors 14127a0bc89SDoug Rabson #define pm_FATs pm_bpb.bpbFATs 14227a0bc89SDoug Rabson #define pm_RootDirEnts pm_bpb.bpbRootDirEnts 14327a0bc89SDoug Rabson #define pm_Sectors pm_bpb.bpbSectors 14427a0bc89SDoug Rabson #define pm_Media pm_bpb.bpbMedia 14527a0bc89SDoug Rabson #define pm_SecPerTrack pm_bpb.bpbSecPerTrack 14627a0bc89SDoug Rabson #define pm_Heads pm_bpb.bpbHeads 14727a0bc89SDoug Rabson #define pm_HiddenSects pm_bpb.bpbHiddenSecs 14827a0bc89SDoug Rabson #define pm_HugeSectors pm_bpb.bpbHugeSectors 14927a0bc89SDoug Rabson 15027a0bc89SDoug Rabson /* 151952a6212SJordan K. Hubbard * Convert pointer to buffer -> pointer to direntry 152952a6212SJordan K. Hubbard */ 153952a6212SJordan K. Hubbard #define bptoep(pmp, bp, dirofs) \ 154952a6212SJordan K. Hubbard ((struct direntry *)(((bp)->b_data) \ 155952a6212SJordan K. Hubbard + ((dirofs) & (pmp)->pm_crbomask))) 156952a6212SJordan K. Hubbard 157952a6212SJordan K. Hubbard /* 158952a6212SJordan K. Hubbard * Convert block number to cluster number 159952a6212SJordan K. Hubbard */ 160952a6212SJordan K. Hubbard #define de_bn2cn(pmp, bn) \ 161952a6212SJordan K. Hubbard ((bn) >> ((pmp)->pm_cnshift - (pmp)->pm_bnshift)) 162952a6212SJordan K. Hubbard 163952a6212SJordan K. Hubbard /* 164952a6212SJordan K. Hubbard * Convert cluster number to block number 165952a6212SJordan K. Hubbard */ 166952a6212SJordan K. Hubbard #define de_cn2bn(pmp, cn) \ 167952a6212SJordan K. Hubbard ((cn) << ((pmp)->pm_cnshift - (pmp)->pm_bnshift)) 168952a6212SJordan K. Hubbard 169952a6212SJordan K. Hubbard /* 170952a6212SJordan K. Hubbard * Convert file offset to cluster number 171952a6212SJordan K. Hubbard */ 172952a6212SJordan K. Hubbard #define de_cluster(pmp, off) \ 173952a6212SJordan K. Hubbard ((off) >> (pmp)->pm_cnshift) 174952a6212SJordan K. Hubbard 175952a6212SJordan K. Hubbard /* 176952a6212SJordan K. Hubbard * Clusters required to hold size bytes 177952a6212SJordan K. Hubbard */ 178952a6212SJordan K. Hubbard #define de_clcount(pmp, size) \ 179952a6212SJordan K. Hubbard (((size) + (pmp)->pm_bpcluster - 1) >> (pmp)->pm_cnshift) 180952a6212SJordan K. Hubbard 181952a6212SJordan K. Hubbard /* 182952a6212SJordan K. Hubbard * Convert file offset to block number 183952a6212SJordan K. Hubbard */ 184952a6212SJordan K. Hubbard #define de_blk(pmp, off) \ 185952a6212SJordan K. Hubbard (de_cn2bn(pmp, de_cluster((pmp), (off)))) 186952a6212SJordan K. Hubbard 187952a6212SJordan K. Hubbard /* 188952a6212SJordan K. Hubbard * Convert cluster number to file offset 189952a6212SJordan K. Hubbard */ 190952a6212SJordan K. Hubbard #define de_cn2off(pmp, cn) \ 191952a6212SJordan K. Hubbard ((cn) << (pmp)->pm_cnshift) 192952a6212SJordan K. Hubbard 193952a6212SJordan K. Hubbard /* 194952a6212SJordan K. Hubbard * Convert block number to file offset 195952a6212SJordan K. Hubbard */ 196952a6212SJordan K. Hubbard #define de_bn2off(pmp, bn) \ 197952a6212SJordan K. Hubbard ((bn) << (pmp)->pm_bnshift) 198952a6212SJordan K. Hubbard /* 19927a0bc89SDoug Rabson * Map a cluster number into a filesystem relative block number. 20027a0bc89SDoug Rabson */ 20127a0bc89SDoug Rabson #define cntobn(pmp, cn) \ 202952a6212SJordan K. Hubbard (de_cn2bn((pmp), (cn)-CLUST_FIRST) + (pmp)->pm_firstcluster) 20327a0bc89SDoug Rabson 20427a0bc89SDoug Rabson /* 20527a0bc89SDoug Rabson * Calculate block number for directory entry in root dir, offset dirofs 20627a0bc89SDoug Rabson */ 20727a0bc89SDoug Rabson #define roottobn(pmp, dirofs) \ 208952a6212SJordan K. Hubbard (de_blk((pmp), (dirofs)) + (pmp)->pm_rootdirblk) 20927a0bc89SDoug Rabson 21027a0bc89SDoug Rabson /* 21127a0bc89SDoug Rabson * Calculate block number for directory entry at cluster dirclu, offset 21227a0bc89SDoug Rabson * dirofs 21327a0bc89SDoug Rabson */ 21427a0bc89SDoug Rabson #define detobn(pmp, dirclu, dirofs) \ 21527a0bc89SDoug Rabson ((dirclu) == MSDOSFSROOT \ 21627a0bc89SDoug Rabson ? roottobn((pmp), (dirofs)) \ 21727a0bc89SDoug Rabson : cntobn((pmp), (dirclu))) 21827a0bc89SDoug Rabson 2193bc482ecSTim J. Robbins void msdosfs_fileno_init(struct mount *); 2203bc482ecSTim J. Robbins void msdosfs_fileno_free(struct mount *); 2213bc482ecSTim J. Robbins uint32_t msdosfs_fileno_map(struct mount *, uint64_t); 2223bc482ecSTim J. Robbins 22323b6c230SKonstantin Belousov #define MSDOSFS_LOCK_MP(pmp) \ 22423b6c230SKonstantin Belousov lockmgr(&(pmp)->pm_fatlock, LK_EXCLUSIVE, NULL) 22523b6c230SKonstantin Belousov #define MSDOSFS_UNLOCK_MP(pmp) \ 22623b6c230SKonstantin Belousov lockmgr(&(pmp)->pm_fatlock, LK_RELEASE, NULL) 22723b6c230SKonstantin Belousov #define MSDOSFS_ASSERT_MP_LOCKED(pmp) \ 22823b6c230SKonstantin Belousov lockmgr_assert(&(pmp)->pm_fatlock, KA_XLOCKED) 22923b6c230SKonstantin Belousov 230c4473420SPeter Wemm #endif /* _KERNEL */ 23160e0f7e2SBruce Evans 232996c772fSJohn Dyson /* 233996c772fSJohn Dyson * Arguments to mount MSDOS filesystems. 234996c772fSJohn Dyson */ 235996c772fSJohn Dyson struct msdosfs_args { 236996c772fSJohn Dyson char *fspec; /* blocks special holding the fs to mount */ 237d0cc54f3SKonstantin Belousov struct oexport_args export; /* network export information */ 238996c772fSJohn Dyson uid_t uid; /* uid that owns msdosfs files */ 239996c772fSJohn Dyson gid_t gid; /* gid that owns msdosfs files */ 240c98a31caSTom Rhodes mode_t mask; /* file mask to be applied for msdosfs perms */ 241952a6212SJordan K. Hubbard int flags; /* see below */ 242c66d17c7SKonstantin Belousov int unused1; /* unused, was version number */ 24323c53312SEd Maste uint16_t unused2[128]; /* no longer used, was Local->Unicode table */ 244c4f02a89SMax Khon char *cs_win; /* Windows(Unicode) Charset */ 245c4f02a89SMax Khon char *cs_dos; /* DOS Charset */ 246c4f02a89SMax Khon char *cs_local; /* Local Charset */ 24701ba334cSTom Rhodes mode_t dirmask; /* dir mask to be applied for msdosfs perms */ 248996c772fSJohn Dyson }; 249996c772fSJohn Dyson 250952a6212SJordan K. Hubbard /* 251952a6212SJordan K. Hubbard * Msdosfs mount options: 252952a6212SJordan K. Hubbard */ 253952a6212SJordan K. Hubbard #define MSDOSFSMNT_SHORTNAME 1 /* Force old DOS short names only */ 254952a6212SJordan K. Hubbard #define MSDOSFSMNT_LONGNAME 2 /* Force Win'95 long names */ 255952a6212SJordan K. Hubbard #define MSDOSFSMNT_NOWIN95 4 /* Completely ignore Win95 entries */ 256c4f02a89SMax Khon #define MSDOSFSMNT_KICONV 0x10 /* Use libiconv to convert chars */ 257952a6212SJordan K. Hubbard /* All flags above: */ 258952a6212SJordan K. Hubbard #define MSDOSFSMNT_MNTOPT \ 259952a6212SJordan K. Hubbard (MSDOSFSMNT_SHORTNAME|MSDOSFSMNT_LONGNAME|MSDOSFSMNT_NOWIN95 \ 260c4f02a89SMax Khon |MSDOSFSMNT_KICONV) 261952a6212SJordan K. Hubbard #define MSDOSFSMNT_RONLY 0x80000000 /* mounted read-only */ 262952a6212SJordan K. Hubbard #define MSDOSFSMNT_WAITONFAT 0x40000000 /* mounted synchronous */ 263952a6212SJordan K. Hubbard #define MSDOSFS_FATMIRROR 0x20000000 /* FAT is mirrored */ 2643bc482ecSTim J. Robbins #define MSDOSFS_LARGEFS 0x10000000 /* perform fileno mapping */ 265bb7ca822SKonstantin Belousov #define MSDOSFS_FSIMOD 0x01000000 266952a6212SJordan K. Hubbard 26760e0f7e2SBruce Evans #endif /* !_MSDOSFS_MSDOSFSMOUNT_H_ */ 268