IMPORT openssh-9.8p1
[dragonfly.git] / sys / vfs / msdosfs / msdosfsmount.h
blob07060f75110c1458a016e2556c5addcd4a587bb8
1 /* $FreeBSD$ */
2 /* $NetBSD: msdosfsmount.h,v 1.17 1997/11/17 15:37:07 ws Exp $ */
4 /*-
5 * SPDX-License-Identifier: BSD-4-Clause
7 * Copyright (C) 1994, 1995, 1997 Wolfgang Solfrank.
8 * Copyright (C) 1994, 1995, 1997 TooLs GmbH.
9 * All rights reserved.
10 * Original code by Paul Popelka (paulp@uts.amdahl.com) (see below).
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
14 * are met:
15 * 1. Redistributions of source code must retain the above copyright
16 * notice, this list of conditions and the following disclaimer.
17 * 2. Redistributions in binary form must reproduce the above copyright
18 * notice, this list of conditions and the following disclaimer in the
19 * documentation and/or other materials provided with the distribution.
20 * 3. All advertising materials mentioning features or use of this software
21 * must display the following acknowledgement:
22 * This product includes software developed by TooLs GmbH.
23 * 4. The name of TooLs GmbH may not be used to endorse or promote products
24 * derived from this software without specific prior written permission.
26 * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR
27 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
28 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
29 * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
30 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
32 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
33 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
34 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
35 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 /*-
38 * Written by Paul Popelka (paulp@uts.amdahl.com)
40 * You can do anything you want with this software, just don't say you wrote
41 * it, and don't remove this notice.
43 * This software is provided "as is".
45 * The author supplies this software to be publicly redistributed on the
46 * understanding that the author is not responsible for the correct
47 * functioning of this software in any circumstances and is not liable for
48 * any damages caused by this software.
50 * October 1992
53 #ifndef _MSDOSFS_MSDOSFSMOUNT_H_
54 #define _MSDOSFS_MSDOSFSMOUNT_H_
56 #ifdef _KERNEL
57 #include "opt_msdosfs.h"
58 #ifdef MALLOC_DECLARE
59 MALLOC_DECLARE(M_MSDOSFSMNT);
60 #endif
61 #endif
62 #include <sys/iconv.h>
63 #if defined(_KERNEL) || defined(_KERNEL_STRUCTURES) || defined(MAKEFS)
65 #define msdosfs_iconv msdos_iconv
68 * Layout of the mount control block for a MSDOSFS filesystem.
70 struct msdosfsmount {
71 struct mount *pm_mountp;/* vfs mount struct for this fs */
72 uid_t pm_uid; /* uid to set as owner of the files */
73 gid_t pm_gid; /* gid to set as owner of the files */
74 mode_t pm_mask; /* mask to and with file protection bits
75 for files */
76 mode_t pm_dirmask; /* mask to and with file protection bits
77 for directories */
78 struct vnode *pm_devvp; /* vnode for character device mounted */
79 #ifndef MAKEFS
80 cdev_t pm_dev; /* character device mounted */
81 #endif /* MAKEFS */
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 uint32_t pm_fatmask; /* mask to use for FAT numbers */
99 u_long pm_fsinfo; /* fsinfo block number */
100 u_long pm_nxtfree; /* next place to search for a free cluster */
101 u_int pm_fatmult; /* these 2 values are used in FAT */
102 u_int pm_fatdiv; /* offset computation */
103 u_int pm_curfat; /* current FAT for FAT32 (0 otherwise) */
104 u_int *pm_inusemap; /* ptr to bitmap of in-use clusters */
105 u_int pm_flags; /* see below */
106 #ifndef MAKEFS
107 struct netexport pm_export; /* export information */
108 #endif /* MAKEFS */
109 void *pm_u2w; /* Local->Unicode iconv handle */
110 void *pm_w2u; /* Unicode->Local iconv handle */
111 void *pm_u2d; /* Unicode->DOS iconv handle */
112 void *pm_d2u; /* DOS->Local iconv handle */
114 /* Byte offset in FAT on filesystem pmp, cluster cn */
115 #define FATOFS(pmp, cn) ((cn) * (pmp)->pm_fatmult / (pmp)->pm_fatdiv)
117 #define VFSTOMSDOSFS(mp) ((struct msdosfsmount *)mp->mnt_data)
119 /* Number of bits in one pm_inusemap item: */
120 #define N_INUSEBITS (8 * sizeof(u_int))
123 * Shorthand for fields in the bpb contained in the msdosfsmount structure.
125 #define pm_BytesPerSec pm_bpb.bpbBytesPerSec
126 #define pm_ResSectors pm_bpb.bpbResSectors
127 #define pm_FATs pm_bpb.bpbFATs
128 #define pm_RootDirEnts pm_bpb.bpbRootDirEnts
129 #define pm_Sectors pm_bpb.bpbSectors
130 #define pm_Media pm_bpb.bpbMedia
131 #define pm_SecPerTrack pm_bpb.bpbSecPerTrack
132 #define pm_Heads pm_bpb.bpbHeads
133 #define pm_HiddenSects pm_bpb.bpbHiddenSecs
134 #define pm_HugeSectors pm_bpb.bpbHugeSectors
137 * Convert pointer to buffer -> pointer to direntry
139 #define bptoep(pmp, bp, dirofs) \
140 ((struct direntry *)(((bp)->b_data) \
141 + ((dirofs) & (pmp)->pm_crbomask)))
144 * Convert block number to cluster number
146 #define de_bn2cn(pmp, bn) \
147 ((bn) >> ((pmp)->pm_cnshift - (pmp)->pm_bnshift))
150 * Convert cluster number to block number
152 #define de_cn2bn(pmp, cn) \
153 ((cn) << ((pmp)->pm_cnshift - (pmp)->pm_bnshift))
156 * Convert file 32 bit offset to cluster number
158 #define de_cluster(pmp, off) \
159 ((off) >> (pmp)->pm_cnshift)
162 * Clusters required to hold size bytes
164 #define de_clcount(pmp, size) \
165 (((size) + (pmp)->pm_bpcluster - 1) >> (pmp)->pm_cnshift)
168 * Convert file 32 bit offset to block number
170 #define de_blk(pmp, off) \
171 (de_cn2bn(pmp, de_cluster((pmp), (off))))
174 * Convert a logical cluster number to file offset.
176 #define de_cn2off(pmp, cn) \
177 ((cn) << (pmp)->pm_cnshift)
180 * Convert a device block number to a file offset.
182 #define de_bn2off(pmp, bn) \
183 ((bn) << (pmp)->pm_bnshift)
186 * Convert a device block number to a 64 bit offset, used for getblk(),
187 * bread(), etc. These are DragonFly specific macros.
189 #define de_bn2doff(pmp, bn) \
190 ((off_t)(bn) << (pmp)->pm_bnshift)
192 #define de_cn2doff(pmp, cn) \
193 ((off_t)(cn) << (pmp)->pm_cnshift)
196 * Map a cluster number into a filesystem relative block number.
198 #define cntobn(pmp, cn) \
199 (de_cn2bn((pmp), (cn)-CLUST_FIRST) + (pmp)->pm_firstcluster)
202 * Calculate block number for directory entry in root dir, offset dirofs
204 #define roottobn(pmp, dirofs) \
205 (de_blk((pmp), (dirofs)) + (pmp)->pm_rootdirblk)
208 * Calculate block number for directory entry at cluster dirclu, offset
209 * dirofs
211 #define detobn(pmp, dirclu, dirofs) \
212 ((dirclu) == MSDOSFSROOT \
213 ? roottobn((pmp), (dirofs)) \
214 : cntobn((pmp), (dirclu)))
216 #define MSDOSFS_LOCK_MP(pmp)
217 #define MSDOSFS_UNLOCK_MP(pmp)
218 #define MSDOSFS_ASSERT_MP_LOCKED(pmp)
220 #endif /* _KERNEL || _KERNEL_STRUCTURES || MAKEFS */
222 #ifndef MAKEFS
224 * Arguments to mount MSDOS filesystems.
226 struct msdosfs_args {
227 char *fspec; /* blocks special holding the fs to mount */
228 struct export_args export; /* network export information */
229 uid_t uid; /* uid that owns msdosfs files */
230 gid_t gid; /* gid that owns msdosfs files */
231 mode_t mask; /* file mask to be applied for msdosfs perms */
232 int flags; /* see below */
233 char cs_local[ICONV_CSNMAXLEN];
234 char cs_dos[ICONV_CSNMAXLEN];
235 mode_t dirmask; /* dir mask to be applied for msdosfs perms */
237 #endif /* MAKEFS */
240 * Msdosfs mount options:
242 #define MSDOSFSMNT_SHORTNAME 1 /* Force old DOS short names only */
243 #define MSDOSFSMNT_LONGNAME 2 /* Force Win'95 long names */
244 #define MSDOSFSMNT_NOWIN95 4 /* Completely ignore Win95 entries */
245 #define MSDOSFSMNT_KICONV 0x10 /* Use libiconv to convert chars */
246 /* All flags above: */
247 #define MSDOSFSMNT_MNTOPT \
248 (MSDOSFSMNT_SHORTNAME|MSDOSFSMNT_LONGNAME|MSDOSFSMNT_NOWIN95 \
249 |MSDOSFSMNT_KICONV)
250 #define MSDOSFSMNT_RONLY 0x80000000 /* mounted read-only */
251 #define MSDOSFSMNT_WAITONFAT 0x40000000 /* mounted synchronous */
252 #define MSDOSFS_FATMIRROR 0x20000000 /* FAT is mirrored */
253 #define MSDOSFS_FSIMOD 0x01000000
255 #define MSDOSFS_ARGSMAGIC 0xe4eff300
257 #ifdef MSDOSFS_DEBUG
258 #define mprintf(fmt, ...) kprintf(fmt, ## __VA_ARGS__)
259 #else
260 #define mprintf(fmt, ...)
261 #endif
263 #define ASSERT_VOP_ELOCKED(vp, str) KASSERT(vn_islocked(vp), (str))
264 #define ASSERT_VOP_LOCKED(vp, str) KASSERT(vn_islocked(vp), (str))
266 #define DOINGASYNC(vp) (((vp)->v_mount->mnt_kern_flag & MNT_ASYNC) != 0)
268 #endif /* !_MSDOSFS_MSDOSFSMOUNT_H_ */