msdosfsmount.h revision 120492
1259698Sdim/* $FreeBSD: head/sys/fs/msdosfs/msdosfsmount.h 120492 2003-09-26 20:26:25Z fjoe $ */ 2259698Sdim/* $NetBSD: msdosfsmount.h,v 1.17 1997/11/17 15:37:07 ws Exp $ */ 3259698Sdim 4259698Sdim/*- 5259698Sdim * Copyright (C) 1994, 1995, 1997 Wolfgang Solfrank. 6259698Sdim * Copyright (C) 1994, 1995, 1997 TooLs GmbH. 7259698Sdim * All rights reserved. 8259698Sdim * Original code by Paul Popelka (paulp@uts.amdahl.com) (see below). 9259698Sdim * 10259698Sdim * Redistribution and use in source and binary forms, with or without 11259698Sdim * modification, are permitted provided that the following conditions 12259698Sdim * are met: 13259698Sdim * 1. Redistributions of source code must retain the above copyright 14259698Sdim * notice, this list of conditions and the following disclaimer. 15259698Sdim * 2. Redistributions in binary form must reproduce the above copyright 16259698Sdim * notice, this list of conditions and the following disclaimer in the 17259698Sdim * documentation and/or other materials provided with the distribution. 18259698Sdim * 3. All advertising materials mentioning features or use of this software 19259698Sdim * must display the following acknowledgement: 20259698Sdim * This product includes software developed by TooLs GmbH. 21259698Sdim * 4. The name of TooLs GmbH may not be used to endorse or promote products 22259698Sdim * derived from this software without specific prior written permission. 23259698Sdim * 24259698Sdim * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR 25259698Sdim * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 26259698Sdim * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 27259698Sdim * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 28259698Sdim * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 29259698Sdim * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 30259698Sdim * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 31259698Sdim * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 32259698Sdim * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 33259698Sdim * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34259698Sdim */ 35259698Sdim/* 36259698Sdim * Written by Paul Popelka (paulp@uts.amdahl.com) 37259698Sdim * 38259698Sdim * You can do anything you want with this software, just don't say you wrote 39259698Sdim * it, and don't remove this notice. 40259698Sdim * 41259698Sdim * This software is provided "as is". 42259698Sdim * 43259698Sdim * The author supplies this software to be publicly redistributed on the 44259698Sdim * understanding that the author is not responsible for the correct 45259698Sdim * functioning of this software in any circumstances and is not liable for 46259698Sdim * any damages caused by this software. 47259698Sdim * 48259698Sdim * October 1992 49259698Sdim */ 50259698Sdim 51259698Sdim#ifndef _MSDOSFS_MSDOSFSMOUNT_H_ 52259698Sdim#define _MSDOSFS_MSDOSFSMOUNT_H_ 53259698Sdim 54259698Sdim#ifdef _KERNEL 55259698Sdim 56259698Sdim#ifdef MALLOC_DECLARE 57259698SdimMALLOC_DECLARE(M_MSDOSFSMNT); 58259698Sdim#endif 59259698Sdim 60259698Sdim/* 61 * Layout of the mount control block for a msdos filesystem. 62 */ 63struct msdosfsmount { 64 struct mount *pm_mountp;/* vfs mount struct for this fs */ 65 dev_t pm_dev; /* block special device mounted */ 66 uid_t pm_uid; /* uid to set as owner of the files */ 67 gid_t pm_gid; /* gid to set as owner of the files */ 68 mode_t pm_mask; /* mask to and with file protection bits 69 for files */ 70 mode_t pm_dirmask; /* mask to and with file protection bits 71 for directories */ 72 struct vnode *pm_devvp; /* vnode for block device mntd */ 73 struct bpb50 pm_bpb; /* BIOS parameter blk for this fs */ 74 u_long pm_BlkPerSec; /* How many DEV_BSIZE blocks fit inside a physical sector */ 75 u_long pm_FATsecs; /* actual number of fat sectors */ 76 u_long pm_fatblk; /* block # of first FAT */ 77 u_long pm_rootdirblk; /* block # (cluster # for FAT32) of root directory number */ 78 u_long pm_rootdirsize; /* size in blocks (not clusters) */ 79 u_long pm_firstcluster; /* block number of first cluster */ 80 u_long pm_maxcluster; /* maximum cluster number */ 81 u_long pm_freeclustercount; /* number of free clusters */ 82 u_long pm_cnshift; /* shift file offset right this amount to get a cluster number */ 83 u_long pm_crbomask; /* and a file offset with this mask to get cluster rel offset */ 84 u_long pm_bnshift; /* shift file offset right this amount to get a block number */ 85 u_long pm_bpcluster; /* bytes per cluster */ 86 u_long pm_fmod; /* ~0 if fs is modified, this can rollover to 0 */ 87 u_long pm_fatblocksize; /* size of fat blocks in bytes */ 88 u_long pm_fatblocksec; /* size of fat blocks in sectors */ 89 u_long pm_fatsize; /* size of fat in bytes */ 90 u_int32_t pm_fatmask; /* mask to use for fat numbers */ 91 u_long pm_fsinfo; /* fsinfo block number */ 92 u_long pm_nxtfree; /* next free cluster in fsinfo block */ 93 u_int pm_fatmult; /* these 2 values are used in fat */ 94 u_int pm_fatdiv; /* offset computation */ 95 u_int pm_curfat; /* current fat for FAT32 (0 otherwise) */ 96 u_int *pm_inusemap; /* ptr to bitmap of in-use clusters */ 97 u_int pm_flags; /* see below */ 98 void *pm_u2w; /* Local->Unicode iconv handle */ 99 void *pm_w2u; /* Unicode->Local iconv handle */ 100 void *pm_u2d; /* Unicode->DOS iconv handle */ 101 void *pm_d2u; /* DOS->Local iconv handle */ 102}; 103/* Byte offset in FAT on filesystem pmp, cluster cn */ 104#define FATOFS(pmp, cn) ((cn) * (pmp)->pm_fatmult / (pmp)->pm_fatdiv) 105 106 107#define VFSTOMSDOSFS(mp) ((struct msdosfsmount *)mp->mnt_data) 108 109/* Number of bits in one pm_inusemap item: */ 110#define N_INUSEBITS (8 * sizeof(u_int)) 111 112/* 113 * Shorthand for fields in the bpb contained in the msdosfsmount structure. 114 */ 115#define pm_BytesPerSec pm_bpb.bpbBytesPerSec 116#define pm_ResSectors pm_bpb.bpbResSectors 117#define pm_FATs pm_bpb.bpbFATs 118#define pm_RootDirEnts pm_bpb.bpbRootDirEnts 119#define pm_Sectors pm_bpb.bpbSectors 120#define pm_Media pm_bpb.bpbMedia 121#define pm_SecPerTrack pm_bpb.bpbSecPerTrack 122#define pm_Heads pm_bpb.bpbHeads 123#define pm_HiddenSects pm_bpb.bpbHiddenSecs 124#define pm_HugeSectors pm_bpb.bpbHugeSectors 125 126/* 127 * Convert pointer to buffer -> pointer to direntry 128 */ 129#define bptoep(pmp, bp, dirofs) \ 130 ((struct direntry *)(((bp)->b_data) \ 131 + ((dirofs) & (pmp)->pm_crbomask))) 132 133/* 134 * Convert block number to cluster number 135 */ 136#define de_bn2cn(pmp, bn) \ 137 ((bn) >> ((pmp)->pm_cnshift - (pmp)->pm_bnshift)) 138 139/* 140 * Convert cluster number to block number 141 */ 142#define de_cn2bn(pmp, cn) \ 143 ((cn) << ((pmp)->pm_cnshift - (pmp)->pm_bnshift)) 144 145/* 146 * Convert file offset to cluster number 147 */ 148#define de_cluster(pmp, off) \ 149 ((off) >> (pmp)->pm_cnshift) 150 151/* 152 * Clusters required to hold size bytes 153 */ 154#define de_clcount(pmp, size) \ 155 (((size) + (pmp)->pm_bpcluster - 1) >> (pmp)->pm_cnshift) 156 157/* 158 * Convert file offset to block number 159 */ 160#define de_blk(pmp, off) \ 161 (de_cn2bn(pmp, de_cluster((pmp), (off)))) 162 163/* 164 * Convert cluster number to file offset 165 */ 166#define de_cn2off(pmp, cn) \ 167 ((cn) << (pmp)->pm_cnshift) 168 169/* 170 * Convert block number to file offset 171 */ 172#define de_bn2off(pmp, bn) \ 173 ((bn) << (pmp)->pm_bnshift) 174/* 175 * Map a cluster number into a filesystem relative block number. 176 */ 177#define cntobn(pmp, cn) \ 178 (de_cn2bn((pmp), (cn)-CLUST_FIRST) + (pmp)->pm_firstcluster) 179 180/* 181 * Calculate block number for directory entry in root dir, offset dirofs 182 */ 183#define roottobn(pmp, dirofs) \ 184 (de_blk((pmp), (dirofs)) + (pmp)->pm_rootdirblk) 185 186/* 187 * Calculate block number for directory entry at cluster dirclu, offset 188 * dirofs 189 */ 190#define detobn(pmp, dirclu, dirofs) \ 191 ((dirclu) == MSDOSFSROOT \ 192 ? roottobn((pmp), (dirofs)) \ 193 : cntobn((pmp), (dirclu))) 194 195/* 196 * Calculate fsinfo block size 197 */ 198#define fsi_size(pmp) \ 199 (1024 << ((pmp)->pm_BlkPerSec >> 2)) 200 201int msdosfs_init(struct vfsconf *vfsp); 202int msdosfs_uninit(struct vfsconf *vfsp); 203int msdosfs_mountroot(void); 204 205#endif /* _KERNEL */ 206 207/* 208 * Arguments to mount MSDOS filesystems. 209 */ 210struct msdosfs_args { 211 char *fspec; /* blocks special holding the fs to mount */ 212 struct export_args export; /* network export information */ 213 uid_t uid; /* uid that owns msdosfs files */ 214 gid_t gid; /* gid that owns msdosfs files */ 215 mode_t mask; /* file mask to be applied for msdosfs perms */ 216 mode_t dirmask; /* dir mask to be applied for msdosfs perms */ 217 int flags; /* see below */ 218 int magic; /* version number */ 219 u_int16_t u2w[128]; /* Local->Unicode table */ 220 char *cs_win; /* Windows(Unicode) Charset */ 221 char *cs_dos; /* DOS Charset */ 222 char *cs_local; /* Local Charset */ 223}; 224 225/* 226 * Msdosfs mount options: 227 */ 228#define MSDOSFSMNT_SHORTNAME 1 /* Force old DOS short names only */ 229#define MSDOSFSMNT_LONGNAME 2 /* Force Win'95 long names */ 230#define MSDOSFSMNT_NOWIN95 4 /* Completely ignore Win95 entries */ 231#define MSDOSFSMNT_KICONV 0x10 /* Use libiconv to convert chars */ 232/* All flags above: */ 233#define MSDOSFSMNT_MNTOPT \ 234 (MSDOSFSMNT_SHORTNAME|MSDOSFSMNT_LONGNAME|MSDOSFSMNT_NOWIN95 \ 235 |MSDOSFSMNT_KICONV) 236#define MSDOSFSMNT_RONLY 0x80000000 /* mounted read-only */ 237#define MSDOSFSMNT_WAITONFAT 0x40000000 /* mounted synchronous */ 238#define MSDOSFS_FATMIRROR 0x20000000 /* FAT is mirrored */ 239 240#define MSDOSFS_ARGSMAGIC 0xe4eff300 241 242#endif /* !_MSDOSFS_MSDOSFSMOUNT_H_ */ 243