1 /* $FreeBSD$ */ 2 /* $NetBSD: msdosfsmount.h,v 1.17 1997/11/17 15:37:07 ws Exp $ */ 3 4 /*- 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 (paulp@uts.amdahl.com) (see below). 9 * 10 * Redistribution and use in source and binary forms, with or without 11 * modification, are permitted provided that the following conditions 12 * are met: 13 * 1. Redistributions of source code must retain the above copyright 14 * notice, this list of conditions and the following disclaimer. 15 * 2. Redistributions in binary form must reproduce the above copyright 16 * notice, this list of conditions and the following disclaimer in the 17 * documentation and/or other materials provided with the distribution. 18 * 3. All advertising materials mentioning features or use of this software 19 * 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 products 22 * derived from this software without specific prior written permission. 23 * 24 * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR 25 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 26 * 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 OR 32 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 33 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 */ 35 /*- 36 * Written by Paul Popelka (paulp@uts.amdahl.com) 37 * 38 * You can do anything you want with this software, just don't say you wrote 39 * 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 the 44 * understanding that the author is not responsible for the correct 45 * functioning of this software in any circumstances and is not liable for 46 * any damages caused by this software. 47 * 48 * October 1992 49 */ 50 51 #ifndef _MSDOSFS_MSDOSFSMOUNT_H_ 52 #define _MSDOSFS_MSDOSFSMOUNT_H_ 53 54 #ifdef _KERNEL 55 56 #include <sys/types.h> 57 #include <sys/lock.h> 58 #include <sys/lockmgr.h> 59 #include <sys/tree.h> 60 61 #ifdef MALLOC_DECLARE 62 MALLOC_DECLARE(M_MSDOSFSMNT); 63 #endif 64 65 struct msdosfs_fileno; 66 67 /* 68 * Layout of the mount control block for a msdos filesystem. 69 */ 70 struct msdosfsmount { 71 struct mount *pm_mountp;/* vfs mount struct for this fs */ 72 struct g_consumer *pm_cp; 73 struct bufobj *pm_bo; 74 uid_t pm_uid; /* uid to set as owner of the files */ 75 gid_t pm_gid; /* gid to set as owner of the files */ 76 mode_t pm_mask; /* mask to and with file protection bits 77 for files */ 78 mode_t pm_dirmask; /* mask to and with file protection bits 79 for directories */ 80 struct vnode *pm_devvp; /* vnode for character device mounted */ 81 struct cdev *pm_dev; /* character device mounted */ 82 struct bpb50 pm_bpb; /* BIOS parameter blk for this fs */ 83 u_long pm_BlkPerSec; /* How many DEV_BSIZE blocks fit inside a physical sector */ 84 u_long pm_FATsecs; /* actual number of fat sectors */ 85 u_long pm_fatblk; /* block # of first FAT */ 86 u_long pm_rootdirblk; /* block # (cluster # for FAT32) of root directory number */ 87 u_long pm_rootdirsize; /* size in blocks (not clusters) */ 88 u_long pm_firstcluster; /* block number of first cluster */ 89 u_long pm_maxcluster; /* maximum cluster number */ 90 u_long pm_freeclustercount; /* number of free clusters */ 91 u_long pm_cnshift; /* shift file offset right this amount to get a cluster number */ 92 u_long pm_crbomask; /* and a file offset with this mask to get cluster rel offset */ 93 u_long pm_bnshift; /* shift file offset right this amount to get a block number */ 94 u_long pm_bpcluster; /* bytes per cluster */ 95 u_long pm_fmod; /* ~0 if fs is modified, this can rollover to 0 */ 96 u_long pm_fatblocksize; /* size of fat blocks in bytes */ 97 u_long pm_fatblocksec; /* size of fat blocks in sectors */ 98 u_long pm_fatsize; /* size of fat in bytes */ 99 u_int32_t pm_fatmask; /* mask to use for fat numbers */ 100 u_long pm_fsinfo; /* fsinfo block number */ 101 u_long pm_nxtfree; /* next place to search for a free cluster */ 102 u_int pm_fatmult; /* these 2 values are used in fat */ 103 u_int pm_fatdiv; /* offset computation */ 104 u_int pm_curfat; /* current fat for FAT32 (0 otherwise) */ 105 u_int *pm_inusemap; /* ptr to bitmap of in-use clusters */ 106 uint64_t pm_flags; /* see below */ 107 void *pm_u2w; /* Local->Unicode iconv handle */ 108 void *pm_w2u; /* Unicode->Local iconv handle */ 109 void *pm_u2d; /* Unicode->DOS iconv handle */ 110 void *pm_d2u; /* DOS->Local iconv handle */ 111 u_int32_t pm_nfileno; /* next 32-bit fileno */ 112 RB_HEAD(msdosfs_filenotree, msdosfs_fileno) 113 pm_filenos; /* 64<->32-bit fileno mapping */ 114 struct lock pm_fatlock; /* lockmgr protecting allocations and rb tree */ 115 }; 116 117 /* 118 * A 64-bit file number and the 32-bit file number to which it is mapped, 119 * in a red-black tree node. 120 */ 121 struct msdosfs_fileno { 122 RB_ENTRY(msdosfs_fileno) mf_tree; 123 uint32_t mf_fileno32; 124 uint64_t mf_fileno64; 125 }; 126 127 /* Byte offset in FAT on filesystem pmp, cluster cn */ 128 #define FATOFS(pmp, cn) ((cn) * (pmp)->pm_fatmult / (pmp)->pm_fatdiv) 129 130 131 #define VFSTOMSDOSFS(mp) ((struct msdosfsmount *)mp->mnt_data) 132 133 /* Number of bits in one pm_inusemap item: */ 134 #define N_INUSEBITS (8 * sizeof(u_int)) 135 136 /* 137 * Shorthand for fields in the bpb contained in the msdosfsmount structure. 138 */ 139 #define pm_BytesPerSec pm_bpb.bpbBytesPerSec 140 #define pm_ResSectors pm_bpb.bpbResSectors 141 #define pm_FATs pm_bpb.bpbFATs 142 #define pm_RootDirEnts pm_bpb.bpbRootDirEnts 143 #define pm_Sectors pm_bpb.bpbSectors 144 #define pm_Media pm_bpb.bpbMedia 145 #define pm_SecPerTrack pm_bpb.bpbSecPerTrack 146 #define pm_Heads pm_bpb.bpbHeads 147 #define pm_HiddenSects pm_bpb.bpbHiddenSecs 148 #define pm_HugeSectors pm_bpb.bpbHugeSectors 149 150 /* 151 * Convert pointer to buffer -> pointer to direntry 152 */ 153 #define bptoep(pmp, bp, dirofs) \ 154 ((struct direntry *)(((bp)->b_data) \ 155 + ((dirofs) & (pmp)->pm_crbomask))) 156 157 /* 158 * Convert block number to cluster number 159 */ 160 #define de_bn2cn(pmp, bn) \ 161 ((bn) >> ((pmp)->pm_cnshift - (pmp)->pm_bnshift)) 162 163 /* 164 * Convert cluster number to block number 165 */ 166 #define de_cn2bn(pmp, cn) \ 167 ((cn) << ((pmp)->pm_cnshift - (pmp)->pm_bnshift)) 168 169 /* 170 * Convert file offset to cluster number 171 */ 172 #define de_cluster(pmp, off) \ 173 ((off) >> (pmp)->pm_cnshift) 174 175 /* 176 * Clusters required to hold size bytes 177 */ 178 #define de_clcount(pmp, size) \ 179 (((size) + (pmp)->pm_bpcluster - 1) >> (pmp)->pm_cnshift) 180 181 /* 182 * Convert file offset to block number 183 */ 184 #define de_blk(pmp, off) \ 185 (de_cn2bn(pmp, de_cluster((pmp), (off)))) 186 187 /* 188 * Convert cluster number to file offset 189 */ 190 #define de_cn2off(pmp, cn) \ 191 ((cn) << (pmp)->pm_cnshift) 192 193 /* 194 * Convert block number to file offset 195 */ 196 #define de_bn2off(pmp, bn) \ 197 ((bn) << (pmp)->pm_bnshift) 198 /* 199 * Map a cluster number into a filesystem relative block number. 200 */ 201 #define cntobn(pmp, cn) \ 202 (de_cn2bn((pmp), (cn)-CLUST_FIRST) + (pmp)->pm_firstcluster) 203 204 /* 205 * Calculate block number for directory entry in root dir, offset dirofs 206 */ 207 #define roottobn(pmp, dirofs) \ 208 (de_blk((pmp), (dirofs)) + (pmp)->pm_rootdirblk) 209 210 /* 211 * Calculate block number for directory entry at cluster dirclu, offset 212 * dirofs 213 */ 214 #define detobn(pmp, dirclu, dirofs) \ 215 ((dirclu) == MSDOSFSROOT \ 216 ? roottobn((pmp), (dirofs)) \ 217 : cntobn((pmp), (dirclu))) 218 219 void msdosfs_fileno_init(struct mount *); 220 void msdosfs_fileno_free(struct mount *); 221 uint32_t msdosfs_fileno_map(struct mount *, uint64_t); 222 223 #define MSDOSFS_LOCK_MP(pmp) \ 224 lockmgr(&(pmp)->pm_fatlock, LK_EXCLUSIVE, NULL) 225 #define MSDOSFS_UNLOCK_MP(pmp) \ 226 lockmgr(&(pmp)->pm_fatlock, LK_RELEASE, NULL) 227 #define MSDOSFS_ASSERT_MP_LOCKED(pmp) \ 228 lockmgr_assert(&(pmp)->pm_fatlock, KA_XLOCKED) 229 230 #endif /* _KERNEL */ 231 232 /* 233 * Arguments to mount MSDOS filesystems. 234 */ 235 struct msdosfs_args { 236 char *fspec; /* blocks special holding the fs to mount */ 237 struct oexport_args export; /* network export information */ 238 uid_t uid; /* uid that owns msdosfs files */ 239 gid_t gid; /* gid that owns msdosfs files */ 240 mode_t mask; /* file mask to be applied for msdosfs perms */ 241 int flags; /* see below */ 242 int magic; /* version number */ 243 u_int16_t u2w[128]; /* Local->Unicode table */ 244 char *cs_win; /* Windows(Unicode) Charset */ 245 char *cs_dos; /* DOS Charset */ 246 char *cs_local; /* Local Charset */ 247 mode_t dirmask; /* dir mask to be applied for msdosfs perms */ 248 }; 249 250 /* 251 * Msdosfs mount options: 252 */ 253 #define MSDOSFSMNT_SHORTNAME 1 /* Force old DOS short names only */ 254 #define MSDOSFSMNT_LONGNAME 2 /* Force Win'95 long names */ 255 #define MSDOSFSMNT_NOWIN95 4 /* Completely ignore Win95 entries */ 256 #define MSDOSFSMNT_KICONV 0x10 /* Use libiconv to convert chars */ 257 /* All flags above: */ 258 #define MSDOSFSMNT_MNTOPT \ 259 (MSDOSFSMNT_SHORTNAME|MSDOSFSMNT_LONGNAME|MSDOSFSMNT_NOWIN95 \ 260 |MSDOSFSMNT_KICONV) 261 #define MSDOSFSMNT_RONLY 0x80000000 /* mounted read-only */ 262 #define MSDOSFSMNT_WAITONFAT 0x40000000 /* mounted synchronous */ 263 #define MSDOSFS_FATMIRROR 0x20000000 /* FAT is mirrored */ 264 #define MSDOSFS_LARGEFS 0x10000000 /* perform fileno mapping */ 265 266 #define MSDOSFS_ARGSMAGIC 0xe4eff300 267 268 #endif /* !_MSDOSFS_MSDOSFSMOUNT_H_ */ 269