msdosfsmount.h revision 118837
150477Speter/* $FreeBSD: head/sys/fs/msdosfs/msdosfsmount.h 118837 2003-08-12 20:06:56Z trhodes $ */
233548Sjkh/*	$NetBSD: msdosfsmount.h,v 1.17 1997/11/17 15:37:07 ws Exp $	*/
32893Sdfr
42893Sdfr/*-
533548Sjkh * Copyright (C) 1994, 1995, 1997 Wolfgang Solfrank.
633548Sjkh * Copyright (C) 1994, 1995, 1997 TooLs GmbH.
72893Sdfr * All rights reserved.
82893Sdfr * Original code by Paul Popelka (paulp@uts.amdahl.com) (see below).
92893Sdfr *
102893Sdfr * Redistribution and use in source and binary forms, with or without
112893Sdfr * modification, are permitted provided that the following conditions
122893Sdfr * are met:
132893Sdfr * 1. Redistributions of source code must retain the above copyright
142893Sdfr *    notice, this list of conditions and the following disclaimer.
152893Sdfr * 2. Redistributions in binary form must reproduce the above copyright
162893Sdfr *    notice, this list of conditions and the following disclaimer in the
172893Sdfr *    documentation and/or other materials provided with the distribution.
182893Sdfr * 3. All advertising materials mentioning features or use of this software
192893Sdfr *    must display the following acknowledgement:
202893Sdfr *	This product includes software developed by TooLs GmbH.
212893Sdfr * 4. The name of TooLs GmbH may not be used to endorse or promote products
222893Sdfr *    derived from this software without specific prior written permission.
232893Sdfr *
242893Sdfr * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR
252893Sdfr * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
262893Sdfr * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
272893Sdfr * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
282893Sdfr * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
292893Sdfr * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
302893Sdfr * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
312893Sdfr * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
322893Sdfr * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
332893Sdfr * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
342893Sdfr */
352893Sdfr/*
362893Sdfr * Written by Paul Popelka (paulp@uts.amdahl.com)
378876Srgrimes *
382893Sdfr * You can do anything you want with this software, just don't say you wrote
392893Sdfr * it, and don't remove this notice.
408876Srgrimes *
412893Sdfr * This software is provided "as is".
428876Srgrimes *
432893Sdfr * The author supplies this software to be publicly redistributed on the
442893Sdfr * understanding that the author is not responsible for the correct
452893Sdfr * functioning of this software in any circumstances and is not liable for
462893Sdfr * any damages caused by this software.
478876Srgrimes *
482893Sdfr * October 1992
492893Sdfr */
502893Sdfr
5123351Sbde#ifndef _MSDOSFS_MSDOSFSMOUNT_H_
5223351Sbde#define	_MSDOSFS_MSDOSFSMOUNT_H_
5323351Sbde
5455206Speter#ifdef _KERNEL
5523351Sbde
5630354Sphk#ifdef MALLOC_DECLARE
5730354SphkMALLOC_DECLARE(M_MSDOSFSMNT);
5830354Sphk#endif
5930354Sphk
602893Sdfr/*
6196755Strhodes * Layout of the mount control block for a msdos filesystem.
622893Sdfr */
632893Sdfrstruct msdosfsmount {
642893Sdfr	struct mount *pm_mountp;/* vfs mount struct for this fs */
652893Sdfr	dev_t pm_dev;		/* block special device mounted */
662893Sdfr	uid_t pm_uid;		/* uid to set as owner of the files */
672893Sdfr	gid_t pm_gid;		/* gid to set as owner of the files */
68118837Strhodes	mode_t pm_mask;		/* mask to and with file protection bits
69118837Strhodes				   for files */
70118837Strhodes	mode_t pm_dirmask;	/* mask to and with file protection bits
71118837Strhodes				   for directories */
722893Sdfr	struct vnode *pm_devvp;	/* vnode for block device mntd */
732893Sdfr	struct bpb50 pm_bpb;	/* BIOS parameter blk for this fs */
7456674Snyan	u_long pm_BlkPerSec;	/* How many DEV_BSIZE blocks fit inside a physical sector */
7533548Sjkh	u_long pm_FATsecs;	/* actual number of fat sectors */
762893Sdfr	u_long pm_fatblk;	/* block # of first FAT */
7733548Sjkh	u_long pm_rootdirblk;	/* block # (cluster # for FAT32) of root directory number */
782893Sdfr	u_long pm_rootdirsize;	/* size in blocks (not clusters) */
792893Sdfr	u_long pm_firstcluster;	/* block number of first cluster */
802893Sdfr	u_long pm_maxcluster;	/* maximum cluster number */
812893Sdfr	u_long pm_freeclustercount;	/* number of free clusters */
822893Sdfr	u_long pm_cnshift;	/* shift file offset right this amount to get a cluster number */
832893Sdfr	u_long pm_crbomask;	/* and a file offset with this mask to get cluster rel offset */
8433548Sjkh	u_long pm_bnshift;	/* shift file offset right this amount to get a block number */
852893Sdfr	u_long pm_bpcluster;	/* bytes per cluster */
862893Sdfr	u_long pm_fmod;		/* ~0 if fs is modified, this can rollover to 0	*/
872893Sdfr	u_long pm_fatblocksize;	/* size of fat blocks in bytes */
882893Sdfr	u_long pm_fatblocksec;	/* size of fat blocks in sectors */
892893Sdfr	u_long pm_fatsize;	/* size of fat in bytes */
9065075Sbde	u_int32_t pm_fatmask;	/* mask to use for fat numbers */
9133548Sjkh	u_long pm_fsinfo;	/* fsinfo block number */
9233548Sjkh	u_long pm_nxtfree;	/* next free cluster in fsinfo block */
9333548Sjkh	u_int pm_fatmult;	/* these 2 values are used in fat */
9433548Sjkh	u_int pm_fatdiv;	/*	offset computation */
9533548Sjkh	u_int pm_curfat;	/* current fat for FAT32 (0 otherwise) */
962893Sdfr	u_int *pm_inusemap;	/* ptr to bitmap of in-use clusters */
9733548Sjkh	u_int pm_flags;		/* see below */
9833747Sache	u_int16_t pm_u2w[128];  /* Local->Unicode table */
9933760Sache	u_int8_t  pm_ul[128];   /* Local upper->lower table */
10033768Sache	u_int8_t  pm_lu[128];   /* Local lower->upper table */
10133768Sache	u_int8_t  pm_d2u[128];  /* DOS->local table */
10233768Sache	u_int8_t  pm_u2d[128];  /* Local->DOS table */
1032893Sdfr};
10433548Sjkh/* Byte offset in FAT on filesystem pmp, cluster cn */
10533548Sjkh#define	FATOFS(pmp, cn)	((cn) * (pmp)->pm_fatmult / (pmp)->pm_fatdiv)
1062893Sdfr
10733548Sjkh
10833548Sjkh#define	VFSTOMSDOSFS(mp)	((struct msdosfsmount *)mp->mnt_data)
10933548Sjkh
1102893Sdfr/* Number of bits in one pm_inusemap item: */
1112893Sdfr#define	N_INUSEBITS	(8 * sizeof(u_int))
1122893Sdfr
1132893Sdfr/*
1142893Sdfr * Shorthand for fields in the bpb contained in the msdosfsmount structure.
1152893Sdfr */
1162893Sdfr#define	pm_BytesPerSec	pm_bpb.bpbBytesPerSec
1172893Sdfr#define	pm_ResSectors	pm_bpb.bpbResSectors
1182893Sdfr#define	pm_FATs		pm_bpb.bpbFATs
1192893Sdfr#define	pm_RootDirEnts	pm_bpb.bpbRootDirEnts
1202893Sdfr#define	pm_Sectors	pm_bpb.bpbSectors
1212893Sdfr#define	pm_Media	pm_bpb.bpbMedia
1222893Sdfr#define	pm_SecPerTrack	pm_bpb.bpbSecPerTrack
1232893Sdfr#define	pm_Heads	pm_bpb.bpbHeads
1242893Sdfr#define	pm_HiddenSects	pm_bpb.bpbHiddenSecs
1252893Sdfr#define	pm_HugeSectors	pm_bpb.bpbHugeSectors
1262893Sdfr
1272893Sdfr/*
12833548Sjkh * Convert pointer to buffer -> pointer to direntry
1292893Sdfr */
13033548Sjkh#define	bptoep(pmp, bp, dirofs) \
13133548Sjkh	((struct direntry *)(((bp)->b_data)	\
13233548Sjkh	 + ((dirofs) & (pmp)->pm_crbomask)))
1332893Sdfr
1342893Sdfr/*
13533548Sjkh * Convert block number to cluster number
1362893Sdfr */
13733548Sjkh#define	de_bn2cn(pmp, bn) \
13833548Sjkh	((bn) >> ((pmp)->pm_cnshift - (pmp)->pm_bnshift))
1392893Sdfr
1402893Sdfr/*
14133548Sjkh * Convert cluster number to block number
1422893Sdfr */
14333548Sjkh#define	de_cn2bn(pmp, cn) \
14433548Sjkh	((cn) << ((pmp)->pm_cnshift - (pmp)->pm_bnshift))
1452893Sdfr
1462893Sdfr/*
14733548Sjkh * Convert file offset to cluster number
1482893Sdfr */
14933548Sjkh#define de_cluster(pmp, off) \
15033548Sjkh	((off) >> (pmp)->pm_cnshift)
1512893Sdfr
1522893Sdfr/*
15333548Sjkh * Clusters required to hold size bytes
1542893Sdfr */
15533548Sjkh#define	de_clcount(pmp, size) \
15633548Sjkh	(((size) + (pmp)->pm_bpcluster - 1) >> (pmp)->pm_cnshift)
1572893Sdfr
1582893Sdfr/*
15933548Sjkh * Convert file offset to block number
1602893Sdfr */
1612893Sdfr#define de_blk(pmp, off) \
16233548Sjkh	(de_cn2bn(pmp, de_cluster((pmp), (off))))
1632893Sdfr
1642893Sdfr/*
16533548Sjkh * Convert cluster number to file offset
1662893Sdfr */
16733548Sjkh#define	de_cn2off(pmp, cn) \
16833548Sjkh	((cn) << (pmp)->pm_cnshift)
1692893Sdfr
17033548Sjkh/*
17133548Sjkh * Convert block number to file offset
17233548Sjkh */
17333548Sjkh#define	de_bn2off(pmp, bn) \
17433548Sjkh	((bn) << (pmp)->pm_bnshift)
17533548Sjkh/*
17633548Sjkh * Map a cluster number into a filesystem relative block number.
17733548Sjkh */
17833548Sjkh#define	cntobn(pmp, cn) \
17933548Sjkh	(de_cn2bn((pmp), (cn)-CLUST_FIRST) + (pmp)->pm_firstcluster)
18033548Sjkh
18133548Sjkh/*
18233548Sjkh * Calculate block number for directory entry in root dir, offset dirofs
18333548Sjkh */
18433548Sjkh#define	roottobn(pmp, dirofs) \
18533548Sjkh	(de_blk((pmp), (dirofs)) + (pmp)->pm_rootdirblk)
18633548Sjkh
18733548Sjkh/*
18833548Sjkh * Calculate block number for directory entry at cluster dirclu, offset
18933548Sjkh * dirofs
19033548Sjkh */
19133548Sjkh#define	detobn(pmp, dirclu, dirofs) \
19233548Sjkh	((dirclu) == MSDOSFSROOT \
19333548Sjkh	 ? roottobn((pmp), (dirofs)) \
19433548Sjkh	 : cntobn((pmp), (dirclu)))
19533548Sjkh
19656674Snyan/*
19756674Snyan * Calculate fsinfo block size
19856674Snyan */
19956674Snyan#define	fsi_size(pmp) \
20056674Snyan	(1024 << ((pmp)->pm_BlkPerSec >> 2))
20156674Snyan
20292727Salfredint msdosfs_init(struct vfsconf *vfsp);
20392727Salfredint msdosfs_uninit(struct vfsconf *vfsp);
20492727Salfredint msdosfs_mountroot(void);
20522521Sdyson
20655206Speter#endif /* _KERNEL */
20723351Sbde
20822521Sdyson/*
20922521Sdyson *  Arguments to mount MSDOS filesystems.
21022521Sdyson */
21122521Sdysonstruct msdosfs_args {
21222521Sdyson	char	*fspec;		/* blocks special holding the fs to mount */
21322521Sdyson	struct	export_args export;	/* network export information */
21422521Sdyson	uid_t	uid;		/* uid that owns msdosfs files */
21522521Sdyson	gid_t	gid;		/* gid that owns msdosfs files */
216118837Strhodes	mode_t	mask;		/* file mask to be applied for msdosfs perms */
217118837Strhodes	mode_t	dirmask;	/* dir  mask to be applied for msdosfs perms */
21833548Sjkh	int	flags;		/* see below */
21933548Sjkh	int magic;		/* version number */
22033747Sache	u_int16_t u2w[128];     /* Local->Unicode table */
22133760Sache	u_int8_t  ul[128];      /* Local upper->lower table */
22233768Sache	u_int8_t  lu[128];      /* Local lower->upper table */
22333768Sache	u_int8_t  d2u[128];     /* DOS->local table */
22433768Sache	u_int8_t  u2d[128];     /* Local->DOS table */
22522521Sdyson};
22622521Sdyson
22733548Sjkh/*
22833548Sjkh * Msdosfs mount options:
22933548Sjkh */
23033548Sjkh#define	MSDOSFSMNT_SHORTNAME	1	/* Force old DOS short names only */
23133548Sjkh#define	MSDOSFSMNT_LONGNAME	2	/* Force Win'95 long names */
23233548Sjkh#define	MSDOSFSMNT_NOWIN95	4	/* Completely ignore Win95 entries */
23333768Sache#define MSDOSFSMNT_U2WTABLE     0x10    /* Local->Unicode and local<->DOS   */
23433768Sache					/* tables loaded                    */
23533768Sache#define MSDOSFSMNT_ULTABLE      0x20    /* Local upper<->lower table loaded */
23633548Sjkh/* All flags above: */
23733548Sjkh#define	MSDOSFSMNT_MNTOPT \
23833548Sjkh	(MSDOSFSMNT_SHORTNAME|MSDOSFSMNT_LONGNAME|MSDOSFSMNT_NOWIN95 \
23987061Sjhb	 |MSDOSFSMNT_U2WTABLE|MSDOSFSMNT_ULTABLE)
24033548Sjkh#define	MSDOSFSMNT_RONLY	0x80000000	/* mounted read-only	*/
24133548Sjkh#define	MSDOSFSMNT_WAITONFAT	0x40000000	/* mounted synchronous	*/
24233548Sjkh#define	MSDOSFS_FATMIRROR	0x20000000	/* FAT is mirrored */
24333548Sjkh
24433548Sjkh#define MSDOSFS_ARGSMAGIC	0xe4eff300
24533548Sjkh
24623351Sbde#endif /* !_MSDOSFS_MSDOSFSMOUNT_H_ */
247