xref: /freebsd/sys/fs/msdosfs/msdosfsmount.h (revision c98a31cad3be5e324706ef5df99da87bcb688f47)
1c3aac50fSPeter Wemm /* $FreeBSD$ */
2952a6212SJordan K. Hubbard /*	$NetBSD: msdosfsmount.h,v 1.17 1997/11/17 15:37:07 ws Exp $	*/
327a0bc89SDoug Rabson 
427a0bc89SDoug Rabson /*-
5952a6212SJordan K. Hubbard  * Copyright (C) 1994, 1995, 1997 Wolfgang Solfrank.
6952a6212SJordan K. Hubbard  * Copyright (C) 1994, 1995, 1997 TooLs GmbH.
727a0bc89SDoug Rabson  * All rights reserved.
827a0bc89SDoug Rabson  * Original code by Paul Popelka (paulp@uts.amdahl.com) (see below).
927a0bc89SDoug Rabson  *
1027a0bc89SDoug Rabson  * Redistribution and use in source and binary forms, with or without
1127a0bc89SDoug Rabson  * modification, are permitted provided that the following conditions
1227a0bc89SDoug Rabson  * are met:
1327a0bc89SDoug Rabson  * 1. Redistributions of source code must retain the above copyright
1427a0bc89SDoug Rabson  *    notice, this list of conditions and the following disclaimer.
1527a0bc89SDoug Rabson  * 2. Redistributions in binary form must reproduce the above copyright
1627a0bc89SDoug Rabson  *    notice, this list of conditions and the following disclaimer in the
1727a0bc89SDoug Rabson  *    documentation and/or other materials provided with the distribution.
1827a0bc89SDoug Rabson  * 3. All advertising materials mentioning features or use of this software
1927a0bc89SDoug Rabson  *    must display the following acknowledgement:
2027a0bc89SDoug Rabson  *	This product includes software developed by TooLs GmbH.
2127a0bc89SDoug Rabson  * 4. The name of TooLs GmbH may not be used to endorse or promote products
2227a0bc89SDoug Rabson  *    derived from this software without specific prior written permission.
2327a0bc89SDoug Rabson  *
2427a0bc89SDoug Rabson  * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR
2527a0bc89SDoug Rabson  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
2627a0bc89SDoug Rabson  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
2727a0bc89SDoug Rabson  * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
2827a0bc89SDoug Rabson  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
2927a0bc89SDoug Rabson  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
3027a0bc89SDoug Rabson  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
3127a0bc89SDoug Rabson  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
3227a0bc89SDoug Rabson  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
3327a0bc89SDoug Rabson  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3427a0bc89SDoug Rabson  */
3527a0bc89SDoug Rabson /*
3627a0bc89SDoug Rabson  * Written by Paul Popelka (paulp@uts.amdahl.com)
3727a0bc89SDoug Rabson  *
3827a0bc89SDoug Rabson  * You can do anything you want with this software, just don't say you wrote
3927a0bc89SDoug Rabson  * it, and don't remove this notice.
4027a0bc89SDoug Rabson  *
4127a0bc89SDoug Rabson  * This software is provided "as is".
4227a0bc89SDoug Rabson  *
4327a0bc89SDoug Rabson  * The author supplies this software to be publicly redistributed on the
4427a0bc89SDoug Rabson  * understanding that the author is not responsible for the correct
4527a0bc89SDoug Rabson  * functioning of this software in any circumstances and is not liable for
4627a0bc89SDoug Rabson  * any damages caused by this software.
4727a0bc89SDoug Rabson  *
4827a0bc89SDoug Rabson  * October 1992
4927a0bc89SDoug Rabson  */
5027a0bc89SDoug Rabson 
5160e0f7e2SBruce Evans #ifndef _MSDOSFS_MSDOSFSMOUNT_H_
5260e0f7e2SBruce Evans #define	_MSDOSFS_MSDOSFSMOUNT_H_
5360e0f7e2SBruce Evans 
54c4473420SPeter Wemm #ifdef _KERNEL
5560e0f7e2SBruce Evans 
56a1c995b6SPoul-Henning Kamp #ifdef MALLOC_DECLARE
57a1c995b6SPoul-Henning Kamp MALLOC_DECLARE(M_MSDOSFSMNT);
58a1c995b6SPoul-Henning Kamp #endif
59a1c995b6SPoul-Henning Kamp 
6027a0bc89SDoug Rabson /*
6127a0bc89SDoug Rabson  * Layout of the mount control block for a msdos filesystem.
6227a0bc89SDoug Rabson  */
6327a0bc89SDoug Rabson struct msdosfsmount {
6427a0bc89SDoug Rabson 	struct mount *pm_mountp;/* vfs mount struct for this fs */
6527a0bc89SDoug Rabson 	dev_t pm_dev;		/* block special device mounted */
6627a0bc89SDoug Rabson 	uid_t pm_uid;		/* uid to set as owner of the files */
6727a0bc89SDoug Rabson 	gid_t pm_gid;		/* gid to set as owner of the files */
68c98a31caSTom Rhodes 	mode_t pm_mask;		/* mask to and with file protection bits
69c98a31caSTom Rhodes 				   for files */
70c98a31caSTom Rhodes 	mode_t pm_dirmask;	/* mask to and with file protection bits
71c98a31caSTom Rhodes 				   for directories */
7227a0bc89SDoug Rabson 	struct vnode *pm_devvp;	/* vnode for block device mntd */
7327a0bc89SDoug Rabson 	struct bpb50 pm_bpb;	/* BIOS parameter blk for this fs */
7401f6cfbaSYoshihiro Takahashi 	u_long pm_BlkPerSec;	/* How many DEV_BSIZE blocks fit inside a physical sector */
75952a6212SJordan K. Hubbard 	u_long pm_FATsecs;	/* actual number of fat sectors */
7627a0bc89SDoug Rabson 	u_long pm_fatblk;	/* block # of first FAT */
77952a6212SJordan K. Hubbard 	u_long pm_rootdirblk;	/* block # (cluster # for FAT32) of root directory number */
7827a0bc89SDoug Rabson 	u_long pm_rootdirsize;	/* size in blocks (not clusters) */
7927a0bc89SDoug Rabson 	u_long pm_firstcluster;	/* block number of first cluster */
8027a0bc89SDoug Rabson 	u_long pm_maxcluster;	/* maximum cluster number */
8127a0bc89SDoug Rabson 	u_long pm_freeclustercount;	/* number of free clusters */
8227a0bc89SDoug Rabson 	u_long pm_cnshift;	/* shift file offset right this amount to get a cluster number */
8327a0bc89SDoug Rabson 	u_long pm_crbomask;	/* and a file offset with this mask to get cluster rel offset */
84952a6212SJordan K. Hubbard 	u_long pm_bnshift;	/* shift file offset right this amount to get a block number */
8527a0bc89SDoug Rabson 	u_long pm_bpcluster;	/* bytes per cluster */
8627a0bc89SDoug Rabson 	u_long pm_fmod;		/* ~0 if fs is modified, this can rollover to 0	*/
8727a0bc89SDoug Rabson 	u_long pm_fatblocksize;	/* size of fat blocks in bytes */
8827a0bc89SDoug Rabson 	u_long pm_fatblocksec;	/* size of fat blocks in sectors */
8927a0bc89SDoug Rabson 	u_long pm_fatsize;	/* size of fat in bytes */
90ff4ad0c4SBruce Evans 	u_int32_t pm_fatmask;	/* mask to use for fat numbers */
91952a6212SJordan K. Hubbard 	u_long pm_fsinfo;	/* fsinfo block number */
92952a6212SJordan K. Hubbard 	u_long pm_nxtfree;	/* next free cluster in fsinfo block */
93952a6212SJordan K. Hubbard 	u_int pm_fatmult;	/* these 2 values are used in fat */
94952a6212SJordan K. Hubbard 	u_int pm_fatdiv;	/*	offset computation */
95952a6212SJordan K. Hubbard 	u_int pm_curfat;	/* current fat for FAT32 (0 otherwise) */
9627a0bc89SDoug Rabson 	u_int *pm_inusemap;	/* ptr to bitmap of in-use clusters */
97952a6212SJordan K. Hubbard 	u_int pm_flags;		/* see below */
9813df76f2SAndrey A. Chernov 	u_int16_t pm_u2w[128];  /* Local->Unicode table */
99b998efa9SAndrey A. Chernov 	u_int8_t  pm_ul[128];   /* Local upper->lower table */
1007391f611SAndrey A. Chernov 	u_int8_t  pm_lu[128];   /* Local lower->upper table */
1017391f611SAndrey A. Chernov 	u_int8_t  pm_d2u[128];  /* DOS->local table */
1027391f611SAndrey A. Chernov 	u_int8_t  pm_u2d[128];  /* Local->DOS table */
10327a0bc89SDoug Rabson };
104952a6212SJordan K. Hubbard /* Byte offset in FAT on filesystem pmp, cluster cn */
105952a6212SJordan K. Hubbard #define	FATOFS(pmp, cn)	((cn) * (pmp)->pm_fatmult / (pmp)->pm_fatdiv)
106952a6212SJordan K. Hubbard 
107952a6212SJordan K. Hubbard 
108952a6212SJordan K. Hubbard #define	VFSTOMSDOSFS(mp)	((struct msdosfsmount *)mp->mnt_data)
10927a0bc89SDoug Rabson 
11027a0bc89SDoug Rabson /* Number of bits in one pm_inusemap item: */
11127a0bc89SDoug Rabson #define	N_INUSEBITS	(8 * sizeof(u_int))
11227a0bc89SDoug Rabson 
11327a0bc89SDoug Rabson /*
11427a0bc89SDoug Rabson  * Shorthand for fields in the bpb contained in the msdosfsmount structure.
11527a0bc89SDoug Rabson  */
11627a0bc89SDoug Rabson #define	pm_BytesPerSec	pm_bpb.bpbBytesPerSec
11727a0bc89SDoug Rabson #define	pm_ResSectors	pm_bpb.bpbResSectors
11827a0bc89SDoug Rabson #define	pm_FATs		pm_bpb.bpbFATs
11927a0bc89SDoug Rabson #define	pm_RootDirEnts	pm_bpb.bpbRootDirEnts
12027a0bc89SDoug Rabson #define	pm_Sectors	pm_bpb.bpbSectors
12127a0bc89SDoug Rabson #define	pm_Media	pm_bpb.bpbMedia
12227a0bc89SDoug Rabson #define	pm_SecPerTrack	pm_bpb.bpbSecPerTrack
12327a0bc89SDoug Rabson #define	pm_Heads	pm_bpb.bpbHeads
12427a0bc89SDoug Rabson #define	pm_HiddenSects	pm_bpb.bpbHiddenSecs
12527a0bc89SDoug Rabson #define	pm_HugeSectors	pm_bpb.bpbHugeSectors
12627a0bc89SDoug Rabson 
12727a0bc89SDoug Rabson /*
128952a6212SJordan K. Hubbard  * Convert pointer to buffer -> pointer to direntry
129952a6212SJordan K. Hubbard  */
130952a6212SJordan K. Hubbard #define	bptoep(pmp, bp, dirofs) \
131952a6212SJordan K. Hubbard 	((struct direntry *)(((bp)->b_data)	\
132952a6212SJordan K. Hubbard 	 + ((dirofs) & (pmp)->pm_crbomask)))
133952a6212SJordan K. Hubbard 
134952a6212SJordan K. Hubbard /*
135952a6212SJordan K. Hubbard  * Convert block number to cluster number
136952a6212SJordan K. Hubbard  */
137952a6212SJordan K. Hubbard #define	de_bn2cn(pmp, bn) \
138952a6212SJordan K. Hubbard 	((bn) >> ((pmp)->pm_cnshift - (pmp)->pm_bnshift))
139952a6212SJordan K. Hubbard 
140952a6212SJordan K. Hubbard /*
141952a6212SJordan K. Hubbard  * Convert cluster number to block number
142952a6212SJordan K. Hubbard  */
143952a6212SJordan K. Hubbard #define	de_cn2bn(pmp, cn) \
144952a6212SJordan K. Hubbard 	((cn) << ((pmp)->pm_cnshift - (pmp)->pm_bnshift))
145952a6212SJordan K. Hubbard 
146952a6212SJordan K. Hubbard /*
147952a6212SJordan K. Hubbard  * Convert file offset to cluster number
148952a6212SJordan K. Hubbard  */
149952a6212SJordan K. Hubbard #define de_cluster(pmp, off) \
150952a6212SJordan K. Hubbard 	((off) >> (pmp)->pm_cnshift)
151952a6212SJordan K. Hubbard 
152952a6212SJordan K. Hubbard /*
153952a6212SJordan K. Hubbard  * Clusters required to hold size bytes
154952a6212SJordan K. Hubbard  */
155952a6212SJordan K. Hubbard #define	de_clcount(pmp, size) \
156952a6212SJordan K. Hubbard 	(((size) + (pmp)->pm_bpcluster - 1) >> (pmp)->pm_cnshift)
157952a6212SJordan K. Hubbard 
158952a6212SJordan K. Hubbard /*
159952a6212SJordan K. Hubbard  * Convert file offset to block number
160952a6212SJordan K. Hubbard  */
161952a6212SJordan K. Hubbard #define de_blk(pmp, off) \
162952a6212SJordan K. Hubbard 	(de_cn2bn(pmp, de_cluster((pmp), (off))))
163952a6212SJordan K. Hubbard 
164952a6212SJordan K. Hubbard /*
165952a6212SJordan K. Hubbard  * Convert cluster number to file offset
166952a6212SJordan K. Hubbard  */
167952a6212SJordan K. Hubbard #define	de_cn2off(pmp, cn) \
168952a6212SJordan K. Hubbard 	((cn) << (pmp)->pm_cnshift)
169952a6212SJordan K. Hubbard 
170952a6212SJordan K. Hubbard /*
171952a6212SJordan K. Hubbard  * Convert block number to file offset
172952a6212SJordan K. Hubbard  */
173952a6212SJordan K. Hubbard #define	de_bn2off(pmp, bn) \
174952a6212SJordan K. Hubbard 	((bn) << (pmp)->pm_bnshift)
175952a6212SJordan K. Hubbard /*
17627a0bc89SDoug Rabson  * Map a cluster number into a filesystem relative block number.
17727a0bc89SDoug Rabson  */
17827a0bc89SDoug Rabson #define	cntobn(pmp, cn) \
179952a6212SJordan K. Hubbard 	(de_cn2bn((pmp), (cn)-CLUST_FIRST) + (pmp)->pm_firstcluster)
18027a0bc89SDoug Rabson 
18127a0bc89SDoug Rabson /*
18227a0bc89SDoug Rabson  * Calculate block number for directory entry in root dir, offset dirofs
18327a0bc89SDoug Rabson  */
18427a0bc89SDoug Rabson #define	roottobn(pmp, dirofs) \
185952a6212SJordan K. Hubbard 	(de_blk((pmp), (dirofs)) + (pmp)->pm_rootdirblk)
18627a0bc89SDoug Rabson 
18727a0bc89SDoug Rabson /*
18827a0bc89SDoug Rabson  * Calculate block number for directory entry at cluster dirclu, offset
18927a0bc89SDoug Rabson  * dirofs
19027a0bc89SDoug Rabson  */
19127a0bc89SDoug Rabson #define	detobn(pmp, dirclu, dirofs) \
19227a0bc89SDoug Rabson 	((dirclu) == MSDOSFSROOT \
19327a0bc89SDoug Rabson 	 ? roottobn((pmp), (dirofs)) \
19427a0bc89SDoug Rabson 	 : cntobn((pmp), (dirclu)))
19527a0bc89SDoug Rabson 
19601f6cfbaSYoshihiro Takahashi /*
19701f6cfbaSYoshihiro Takahashi  * Calculate fsinfo block size
19801f6cfbaSYoshihiro Takahashi  */
19901f6cfbaSYoshihiro Takahashi #define	fsi_size(pmp) \
20001f6cfbaSYoshihiro Takahashi 	(1024 << ((pmp)->pm_BlkPerSec >> 2))
20101f6cfbaSYoshihiro Takahashi 
20211caded3SAlfred Perlstein int msdosfs_init(struct vfsconf *vfsp);
20311caded3SAlfred Perlstein int msdosfs_uninit(struct vfsconf *vfsp);
20411caded3SAlfred Perlstein int msdosfs_mountroot(void);
205996c772fSJohn Dyson 
206c4473420SPeter Wemm #endif /* _KERNEL */
20760e0f7e2SBruce Evans 
208996c772fSJohn Dyson /*
209996c772fSJohn Dyson  *  Arguments to mount MSDOS filesystems.
210996c772fSJohn Dyson  */
211996c772fSJohn Dyson struct msdosfs_args {
212996c772fSJohn Dyson 	char	*fspec;		/* blocks special holding the fs to mount */
213996c772fSJohn Dyson 	struct	export_args export;	/* network export information */
214996c772fSJohn Dyson 	uid_t	uid;		/* uid that owns msdosfs files */
215996c772fSJohn Dyson 	gid_t	gid;		/* gid that owns msdosfs files */
216c98a31caSTom Rhodes 	mode_t	mask;		/* file mask to be applied for msdosfs perms */
217c98a31caSTom Rhodes 	mode_t	dirmask;	/* dir  mask to be applied for msdosfs perms */
218952a6212SJordan K. Hubbard 	int	flags;		/* see below */
219952a6212SJordan K. Hubbard 	int magic;		/* version number */
22013df76f2SAndrey A. Chernov 	u_int16_t u2w[128];     /* Local->Unicode table */
221b998efa9SAndrey A. Chernov 	u_int8_t  ul[128];      /* Local upper->lower table */
2227391f611SAndrey A. Chernov 	u_int8_t  lu[128];      /* Local lower->upper table */
2237391f611SAndrey A. Chernov 	u_int8_t  d2u[128];     /* DOS->local table */
2247391f611SAndrey A. Chernov 	u_int8_t  u2d[128];     /* Local->DOS table */
225996c772fSJohn Dyson };
226996c772fSJohn Dyson 
227952a6212SJordan K. Hubbard /*
228952a6212SJordan K. Hubbard  * Msdosfs mount options:
229952a6212SJordan K. Hubbard  */
230952a6212SJordan K. Hubbard #define	MSDOSFSMNT_SHORTNAME	1	/* Force old DOS short names only */
231952a6212SJordan K. Hubbard #define	MSDOSFSMNT_LONGNAME	2	/* Force Win'95 long names */
232952a6212SJordan K. Hubbard #define	MSDOSFSMNT_NOWIN95	4	/* Completely ignore Win95 entries */
2337391f611SAndrey A. Chernov #define MSDOSFSMNT_U2WTABLE     0x10    /* Local->Unicode and local<->DOS   */
2347391f611SAndrey A. Chernov 					/* tables loaded                    */
2357391f611SAndrey A. Chernov #define MSDOSFSMNT_ULTABLE      0x20    /* Local upper<->lower table loaded */
236952a6212SJordan K. Hubbard /* All flags above: */
237952a6212SJordan K. Hubbard #define	MSDOSFSMNT_MNTOPT \
238952a6212SJordan K. Hubbard 	(MSDOSFSMNT_SHORTNAME|MSDOSFSMNT_LONGNAME|MSDOSFSMNT_NOWIN95 \
239d3990d58SJohn Baldwin 	 |MSDOSFSMNT_U2WTABLE|MSDOSFSMNT_ULTABLE)
240952a6212SJordan K. Hubbard #define	MSDOSFSMNT_RONLY	0x80000000	/* mounted read-only	*/
241952a6212SJordan K. Hubbard #define	MSDOSFSMNT_WAITONFAT	0x40000000	/* mounted synchronous	*/
242952a6212SJordan K. Hubbard #define	MSDOSFS_FATMIRROR	0x20000000	/* FAT is mirrored */
243952a6212SJordan K. Hubbard 
244952a6212SJordan K. Hubbard #define MSDOSFS_ARGSMAGIC	0xe4eff300
245952a6212SJordan K. Hubbard 
24660e0f7e2SBruce Evans #endif /* !_MSDOSFS_MSDOSFSMOUNT_H_ */
247