1 /** $MirOS: src/sys/msdosfs/msdosfsmount.h,v 1.2 2005/03/06 21:28:13 tg Exp $ */ 2 /* $OpenBSD: msdosfsmount.h,v 1.16 2004/05/14 04:05:05 tedu Exp $ */ 3 /* $NetBSD: msdosfsmount.h,v 1.16 1997/10/17 11:24:24 ws Exp $ */ 4 5 /*- 6 * Copyright (C) 1994, 1995, 1997 Wolfgang Solfrank. 7 * Copyright (C) 1994, 1995, 1997 TooLs GmbH. 8 * All rights reserved. 9 * Original code by Paul Popelka (paulp@uts.amdahl.com) (see below). 10 * 11 * Redistribution and use in source and binary forms, with or without 12 * modification, are permitted provided that the following conditions 13 * are met: 14 * 1. Redistributions of source code must retain the above copyright 15 * notice, this list of conditions and the following disclaimer. 16 * 2. Redistributions in binary form must reproduce the above copyright 17 * notice, this list of conditions and the following disclaimer in the 18 * documentation and/or other materials provided with the distribution. 19 * 3. All advertising materials mentioning features or use of this software 20 * must display the following acknowledgement: 21 * This product includes software developed by TooLs GmbH. 22 * 4. The name of TooLs GmbH may not be used to endorse or promote products 23 * derived from this software without specific prior written permission. 24 * 25 * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR 26 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 27 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 28 * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 29 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 30 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 31 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 32 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 33 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 34 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 35 */ 36 /* 37 * Written by Paul Popelka (paulp@uts.amdahl.com) 38 * 39 * You can do anything you want with this software, just don't say you wrote 40 * it, and don't remove this notice. 41 * 42 * This software is provided "as is". 43 * 44 * The author supplies this software to be publicly redistributed on the 45 * understanding that the author is not responsible for the correct 46 * functioning of this software in any circumstances and is not liable for 47 * any damages caused by this software. 48 * 49 * October 1992 50 */ 51 52 #ifndef _MSDOSFS_MOUNT_H 53 #define _MSDOSFS_MOUNT_H 54 55 /* 56 * Layout of the mount control block for a msdos file system. 57 */ 58 struct msdosfsmount { 59 struct mount *pm_mountp;/* vfs mount struct for this fs */ 60 dev_t pm_dev; /* block special device mounted */ 61 uid_t pm_uid; /* uid to set as owner of the files */ 62 gid_t pm_gid; /* gid to set as owner of the files */ 63 mode_t pm_mask; /* mask to and with file protection bits */ 64 struct vnode *pm_devvp; /* vnode for block device mntd */ 65 struct bpb50 pm_bpb; /* BIOS parameter blk for this fs */ 66 uint32_t pm_FATsecs; /* actual number of fat sectors */ 67 uint32_t pm_fatblk; /* block # of first FAT */ 68 uint32_t pm_rootdirblk; /* block # (cluster # for FAT32) of root directory number */ 69 uint32_t pm_rootdirsize; /* size in blocks (not clusters) */ 70 uint32_t pm_firstcluster; /* block number of first cluster */ 71 uint32_t pm_nmbrofclusters; /* # of clusters in filesystem */ 72 uint32_t pm_maxcluster; /* maximum cluster number */ 73 uint32_t pm_freeclustercount; /* number of free clusters */ 74 uint32_t pm_cnshift; /* shift file offset right this amount to get a cluster number */ 75 uint32_t pm_crbomask; /* and a file offset with this mask to get cluster rel offset */ 76 uint32_t pm_bnshift; /* shift file offset right this amount to get a block number */ 77 uint32_t pm_bpcluster; /* bytes per cluster */ 78 uint32_t pm_fmod; /* ~0 if fs is modified, this can rollover to 0 */ 79 uint32_t pm_fatblocksize; /* size of fat blocks in bytes */ 80 uint32_t pm_fatblocksec; /* size of fat blocks in sectors */ 81 uint32_t pm_fatsize; /* size of fat in bytes */ 82 uint32_t pm_fatmask; /* mask to use for fat numbers */ 83 uint32_t pm_fsinfo; /* fsinfo block number */ 84 uint32_t pm_nxtfree; /* next free cluster in fsinfo block */ 85 u_int pm_fatmult; /* these 2 values are used in fat */ 86 u_int pm_fatdiv; /* offset computation */ 87 u_int pm_curfat; /* current fat for FAT32 (0 otherwise) */ 88 u_int *pm_inusemap; /* ptr to bitmap of in-use clusters */ 89 u_int pm_flags; /* see below */ 90 struct netexport pm_export; /* export information */ 91 }; 92 /* Byte offset in FAT on filesystem pmp, cluster cn */ 93 #define FATOFS(pmp, cn) ((cn) * (pmp)->pm_fatmult / (pmp)->pm_fatdiv) 94 95 /* 96 * Mount point flags: 97 */ 98 #if 0 99 /* Defined in <sys/mount.h> */ 100 #define MSDOSFSMNT_SHORTNAME 0x01 101 #define MSDOSFSMNT_LONGNAME 0x02 102 #define MSDOSFSMNT_NOWIN95 0x04 103 #define MSDOSFSMNT_GEMDOSFS 0x08 104 #define MSDOSFSMNT_ALLOWDIRX 0x10 105 #endif 106 107 /* All flags above: */ 108 #define MSDOSFSMNT_MNTOPT \ 109 (MSDOSFSMNT_SHORTNAME|MSDOSFSMNT_LONGNAME|MSDOSFSMNT_NOWIN95 \ 110 |MSDOSFSMNT_GEMDOSFS|MSDOSFSMNT_ALLOWDIRX) 111 #define MSDOSFSMNT_RONLY 0x80000000 /* mounted read-only */ 112 #define MSDOSFSMNT_WAITONFAT 0x40000000 /* mounted synchronous */ 113 #define MSDOSFS_FATMIRROR 0x20000000 /* FAT is mirrored */ 114 115 #define VFSTOMSDOSFS(mp) ((struct msdosfsmount *)mp->mnt_data) 116 117 /* Number of bits in one pm_inusemap item: */ 118 #define N_INUSEBITS (8 * sizeof(u_int)) 119 120 /* 121 * Shorthand for fields in the bpb contained in the msdosfsmount structure. 122 */ 123 #define pm_BytesPerSec pm_bpb.bpbBytesPerSec 124 #define pm_ResSectors pm_bpb.bpbResSectors 125 #define pm_FATs pm_bpb.bpbFATs 126 #define pm_RootDirEnts pm_bpb.bpbRootDirEnts 127 #define pm_Sectors pm_bpb.bpbSectors 128 #define pm_Media pm_bpb.bpbMedia 129 #define pm_SecPerTrack pm_bpb.bpbSecPerTrack 130 #define pm_Heads pm_bpb.bpbHeads 131 #define pm_HiddenSects pm_bpb.bpbHiddenSecs 132 #define pm_HugeSectors pm_bpb.bpbHugeSectors 133 134 /* 135 * Convert pointer to buffer -> pointer to direntry 136 */ 137 #define bptoep(pmp, bp, dirofs) \ 138 ((struct direntry *)(((bp)->b_data) \ 139 + ((dirofs) & (pmp)->pm_crbomask))) 140 141 /* 142 * Convert block number to cluster number 143 */ 144 #define de_bn2cn(pmp, bn) \ 145 ((bn) >> ((pmp)->pm_cnshift - (pmp)->pm_bnshift)) 146 147 /* 148 * Convert cluster number to block number 149 */ 150 #define de_cn2bn(pmp, cn) \ 151 ((cn) << ((pmp)->pm_cnshift - (pmp)->pm_bnshift)) 152 153 /* 154 * Convert file offset to cluster number 155 */ 156 #define de_cluster(pmp, off) \ 157 ((off) >> (pmp)->pm_cnshift) 158 159 /* 160 * Clusters required to hold size bytes 161 */ 162 #define de_clcount(pmp, size) \ 163 (((size) + (pmp)->pm_bpcluster - 1) >> (pmp)->pm_cnshift) 164 165 /* 166 * Convert file offset to block number 167 */ 168 #define de_blk(pmp, off) \ 169 (de_cn2bn(pmp, de_cluster((pmp), (off)))) 170 171 /* 172 * Convert cluster number to file offset 173 */ 174 #define de_cn2off(pmp, cn) \ 175 ((cn) << (pmp)->pm_cnshift) 176 177 /* 178 * Convert block number to file offset 179 */ 180 #define de_bn2off(pmp, bn) \ 181 ((bn) << (pmp)->pm_bnshift) 182 /* 183 * Map a cluster number into a filesystem relative block number. 184 */ 185 #define cntobn(pmp, cn) \ 186 (de_cn2bn((pmp), (cn)-CLUST_FIRST) + (pmp)->pm_firstcluster) 187 188 /* 189 * Calculate block number for directory entry in root dir, offset dirofs 190 */ 191 #define roottobn(pmp, dirofs) \ 192 (de_blk((pmp), (dirofs)) + (pmp)->pm_rootdirblk) 193 194 /* 195 * Calculate block number for directory entry at cluster dirclu, offset 196 * dirofs 197 */ 198 #define detobn(pmp, dirclu, dirofs) \ 199 ((dirclu) == MSDOSFSROOT \ 200 ? roottobn((pmp), (dirofs)) \ 201 : cntobn((pmp), (dirclu))) 202 203 /* 204 * Prototypes for MSDOSFS virtual filesystem operations 205 */ 206 int msdosfs_mount(struct mount *, const char *, void *, struct nameidata *, struct proc *); 207 int msdosfs_start(struct mount *, int, struct proc *); 208 int msdosfs_unmount(struct mount *, int, struct proc *); 209 int msdosfs_root(struct mount *, struct vnode **); 210 int msdosfs_quotactl(struct mount *, int, uid_t, caddr_t, struct proc *); 211 int msdosfs_statfs(struct mount *, struct statfs *, struct proc *); 212 int msdosfs_sync(struct mount *, int, struct ucred *, struct proc *); 213 int msdosfs_fhtovp(struct mount *, struct fid *, struct vnode **); 214 int msdosfs_vptofh(struct vnode *, struct fid *); 215 int msdosfs_init(struct vfsconf *); 216 217 #endif 218