MFC r1.3 r1.13 r1.8 (HEAD):
[dragonfly.git] / sys / vfs / msdosfs / msdosfsmount.h
blob90ac06f9d36def919ff19cdcaa4cbbe2b96767b3
1 /* $FreeBSD: src/sys/msdosfs/msdosfsmount.h,v 1.20.2.2 2000/10/27 09:45:07 bde Exp $ */
2 /* $DragonFly: src/sys/vfs/msdosfs/msdosfsmount.h,v 1.9 2007/08/08 00:23:40 swildner Exp $ */
3 /* $NetBSD: msdosfsmount.h,v 1.17 1997/11/17 15:37:07 ws Exp $ */
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).
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.
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.
37 * Written by Paul Popelka (paulp@uts.amdahl.com)
39 * You can do anything you want with this software, just don't say you wrote
40 * it, and don't remove this notice.
42 * This software is provided "as is".
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.
49 * October 1992
52 #ifndef _MSDOSFS_MSDOSFSMOUNT_H_
53 #define _MSDOSFS_MSDOSFSMOUNT_H_
55 #ifdef _KERNEL
56 #include "opt_msdosfs.h"
57 #ifdef MALLOC_DECLARE
58 MALLOC_DECLARE(M_MSDOSFSMNT);
59 #endif
60 #endif
62 #if defined(_KERNEL) || defined(_KERNEL_STRUCTURES)
65 * Layout of the mount control block for a msdos file system.
67 struct msdosfsmount {
68 struct mount *pm_mountp;/* vfs mount struct for this fs */
69 cdev_t pm_dev; /* block special device mounted */
70 uid_t pm_uid; /* uid to set as owner of the files */
71 gid_t pm_gid; /* gid to set as owner of the files */
72 mode_t pm_mask; /* mask to and with file protection bits */
73 struct vnode *pm_devvp; /* vnode for block device mntd */
74 struct bpb50 pm_bpb; /* BIOS parameter blk for this fs */
75 u_long pm_BlkPerSec; /* How many DEV_BSIZE blocks fit inside a physical sector */
76 u_long pm_FATsecs; /* actual number of fat sectors */
77 u_long pm_fatblk; /* block # of first FAT */
78 u_long pm_rootdirblk; /* block # (cluster # for FAT32) of root directory number */
79 u_long pm_rootdirsize; /* size in blocks (not clusters) */
80 u_long pm_firstcluster; /* block number of first cluster */
81 u_long pm_maxcluster; /* maximum cluster number */
82 u_long pm_freeclustercount; /* number of free clusters */
83 u_long pm_cnshift; /* shift file offset right this amount to get a cluster number */
84 u_long pm_crbomask; /* and a file offset with this mask to get cluster rel offset */
85 u_long pm_bnshift; /* shift file offset right this amount to get a block number */
86 u_long pm_bpcluster; /* bytes per cluster */
87 u_long pm_fmod; /* ~0 if fs is modified, this can rollover to 0 */
88 u_long pm_fatblocksize; /* size of fat blocks in bytes */
89 u_long pm_fatblocksec; /* size of fat blocks in sectors */
90 u_long pm_fatsize; /* size of fat in bytes */
91 u_int32_t pm_fatmask; /* mask to use for fat numbers */
92 u_long pm_fsinfo; /* fsinfo block number */
93 u_long pm_nxtfree; /* next free cluster in fsinfo block */
94 u_int pm_fatmult; /* these 2 values are used in fat */
95 u_int pm_fatdiv; /* offset computation */
96 u_int pm_curfat; /* current fat for FAT32 (0 otherwise) */
97 u_int *pm_inusemap; /* ptr to bitmap of in-use clusters */
98 u_int pm_flags; /* see below */
99 struct netexport pm_export; /* export information */
100 u_int16_t pm_u2w[128]; /* Local->Unicode table */
101 u_int8_t pm_ul[128]; /* Local upper->lower table */
102 u_int8_t pm_lu[128]; /* Local lower->upper table */
103 u_int8_t pm_d2u[128]; /* DOS->local table */
104 u_int8_t pm_u2d[128]; /* Local->DOS table */
106 /* Byte offset in FAT on filesystem pmp, cluster cn */
107 #define FATOFS(pmp, cn) ((cn) * (pmp)->pm_fatmult / (pmp)->pm_fatdiv)
110 #define VFSTOMSDOSFS(mp) ((struct msdosfsmount *)mp->mnt_data)
112 /* Number of bits in one pm_inusemap item: */
113 #define N_INUSEBITS (8 * sizeof(u_int))
116 * Shorthand for fields in the bpb contained in the msdosfsmount structure.
118 #define pm_BytesPerSec pm_bpb.bpbBytesPerSec
119 #define pm_ResSectors pm_bpb.bpbResSectors
120 #define pm_FATs pm_bpb.bpbFATs
121 #define pm_RootDirEnts pm_bpb.bpbRootDirEnts
122 #define pm_Sectors pm_bpb.bpbSectors
123 #define pm_Media pm_bpb.bpbMedia
124 #define pm_SecPerTrack pm_bpb.bpbSecPerTrack
125 #define pm_Heads pm_bpb.bpbHeads
126 #define pm_HiddenSects pm_bpb.bpbHiddenSecs
127 #define pm_HugeSectors pm_bpb.bpbHugeSectors
130 * Convert pointer to buffer -> pointer to direntry
132 #define bptoep(pmp, bp, dirofs) \
133 ((struct direntry *)(((bp)->b_data) \
134 + ((dirofs) & (pmp)->pm_crbomask)))
137 * Convert block number to cluster number
139 #define de_bn2cn(pmp, bn) \
140 ((bn) >> ((pmp)->pm_cnshift - (pmp)->pm_bnshift))
143 * Convert cluster number to block number
145 #define de_cn2bn(pmp, cn) \
146 ((cn) << ((pmp)->pm_cnshift - (pmp)->pm_bnshift))
149 * Convert file 32 bit offset to cluster number
151 #define de_cluster(pmp, off) \
152 ((off) >> (pmp)->pm_cnshift)
155 * Clusters required to hold size bytes
157 #define de_clcount(pmp, size) \
158 (((size) + (pmp)->pm_bpcluster - 1) >> (pmp)->pm_cnshift)
161 * Convert file 32 bit offset to block number
163 #define de_blk(pmp, off) \
164 (de_cn2bn(pmp, de_cluster((pmp), (off))))
167 * Convert a logical cluster number to file offset. This typically
168 * represents a logical cluster number relative to a file, not relative
169 * to the device.
171 #define de_cn2off(pmp, cn) \
172 ((cn) << (pmp)->pm_cnshift)
175 * Convert a device block number to a file offset.
177 #define de_bn2off(pmp, bn) \
178 ((bn) << (pmp)->pm_bnshift)
181 * Convert a device block number to a 64 bit offset, used for getblk(),
182 * bread(), etc.
184 #define de_bntodoff(pmp, bn) \
185 ((off_t)(bn) << (pmp)->pm_bnshift)
187 #define de_cn2doff(pmp, cn) \
188 ((off_t)(cn) << (pmp)->pm_cnshift)
190 #define de_off2bn(pmp, off) \
191 ((daddr_t)((off) >> (pmp)->pm_bnshift))
193 #define de_off2cn(pmp, off) \
194 ((daddr_t)((off) >> (pmp)->pm_cnshift))
197 * Map an on-disk cluster number into a device relative block number or
198 * a device relative offset. This is different from a logical cluster
199 * number. The cluster numbers stored on-disk are not relative to block 0
200 * on the disk.
202 #define xcntodoff(pmp, cn) \
203 de_bntodoff(pmp, xcntobn(pmp, cn))
205 #define xcntobn(pmp, cn) \
206 (de_cn2bn((pmp), (cn)-CLUST_FIRST) + (pmp)->pm_firstcluster)
210 * Calculate block number for directory entry in root dir, offset dirofs
212 #define roottobn(pmp, dirofs) \
213 (de_blk((pmp), (dirofs)) + (pmp)->pm_rootdirblk)
216 * Calculate block number for directory entry at cluster dirclu, offset
217 * dirofs
219 #define detobn(pmp, dirclu, dirofs) \
220 ((dirclu) == MSDOSFSROOT \
221 ? roottobn((pmp), (dirofs)) \
222 : xcntobn((pmp), (dirclu)))
225 * Calculate fsinfo block size
227 #define fsi_size(pmp) \
228 (1024 << ((pmp)->pm_BlkPerSec >> 2))
230 #endif /* _KERNEL || _KERNEL_STRUCTURES */
232 #ifdef _KERNEL
234 int msdosfs_init (struct vfsconf *vfsp);
235 int msdosfs_uninit (struct vfsconf *vfsp);
236 int msdosfs_mountroot (void);
238 #endif
241 * Arguments to mount MSDOS filesystems.
243 struct msdosfs_args {
244 char *fspec; /* blocks special holding the fs to mount */
245 struct export_args export; /* network export information */
246 uid_t uid; /* uid that owns msdosfs files */
247 gid_t gid; /* gid that owns msdosfs files */
248 mode_t mask; /* mask to be applied for msdosfs perms */
249 int flags; /* see below */
250 int magic; /* version number */
251 u_int16_t u2w[128]; /* Local->Unicode table */
252 u_int8_t ul[128]; /* Local upper->lower table */
253 u_int8_t lu[128]; /* Local lower->upper table */
254 u_int8_t d2u[128]; /* DOS->local table */
255 u_int8_t u2d[128]; /* Local->DOS table */
259 * Msdosfs mount options:
261 #define MSDOSFSMNT_SHORTNAME 1 /* Force old DOS short names only */
262 #define MSDOSFSMNT_LONGNAME 2 /* Force Win'95 long names */
263 #define MSDOSFSMNT_NOWIN95 4 /* Completely ignore Win95 entries */
264 #ifndef __DragonFly__
265 #define MSDOSFSMNT_GEMDOSFS 8 /* This is a gemdos-flavour */
266 #endif
267 #define MSDOSFSMNT_U2WTABLE 0x10 /* Local->Unicode and local<->DOS */
268 /* tables loaded */
269 #define MSDOSFSMNT_ULTABLE 0x20 /* Local upper<->lower table loaded */
270 /* All flags above: */
271 #define MSDOSFSMNT_MNTOPT \
272 (MSDOSFSMNT_SHORTNAME|MSDOSFSMNT_LONGNAME|MSDOSFSMNT_NOWIN95 \
273 /*|MSDOSFSMNT_GEMDOSFS*/|MSDOSFSMNT_U2WTABLE|MSDOSFSMNT_ULTABLE)
274 #define MSDOSFSMNT_RONLY 0x80000000 /* mounted read-only */
275 #define MSDOSFSMNT_WAITONFAT 0x40000000 /* mounted synchronous */
276 #define MSDOSFS_FATMIRROR 0x20000000 /* FAT is mirrored */
278 #define MSDOSFS_ARGSMAGIC 0xe4eff300
280 #endif /* !_MSDOSFS_MSDOSFSMOUNT_H_ */