msdosfsmount.h revision 1.16.6.4       1  1.16.6.3       tls /*	$NetBSD: msdosfsmount.h,v 1.16.6.4 2017/12/03 11:38:41 jdolecek Exp $	*/
      2       1.1  jdolecek 
      3       1.1  jdolecek /*-
      4       1.1  jdolecek  * Copyright (C) 1994, 1995, 1997 Wolfgang Solfrank.
      5       1.1  jdolecek  * Copyright (C) 1994, 1995, 1997 TooLs GmbH.
      6       1.1  jdolecek  * All rights reserved.
      7       1.1  jdolecek  * Original code by Paul Popelka (paulp (at) uts.amdahl.com) (see below).
      8       1.1  jdolecek  *
      9       1.1  jdolecek  * Redistribution and use in source and binary forms, with or without
     10       1.1  jdolecek  * modification, are permitted provided that the following conditions
     11       1.1  jdolecek  * are met:
     12       1.1  jdolecek  * 1. Redistributions of source code must retain the above copyright
     13       1.1  jdolecek  *    notice, this list of conditions and the following disclaimer.
     14       1.1  jdolecek  * 2. Redistributions in binary form must reproduce the above copyright
     15       1.1  jdolecek  *    notice, this list of conditions and the following disclaimer in the
     16       1.1  jdolecek  *    documentation and/or other materials provided with the distribution.
     17       1.1  jdolecek  * 3. All advertising materials mentioning features or use of this software
     18       1.1  jdolecek  *    must display the following acknowledgement:
     19       1.1  jdolecek  *	This product includes software developed by TooLs GmbH.
     20       1.1  jdolecek  * 4. The name of TooLs GmbH may not be used to endorse or promote products
     21       1.1  jdolecek  *    derived from this software without specific prior written permission.
     22       1.1  jdolecek  *
     23       1.1  jdolecek  * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR
     24       1.1  jdolecek  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     25       1.1  jdolecek  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     26       1.1  jdolecek  * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
     27       1.1  jdolecek  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
     28       1.1  jdolecek  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
     29       1.1  jdolecek  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
     30       1.1  jdolecek  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
     31       1.1  jdolecek  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
     32       1.1  jdolecek  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     33       1.1  jdolecek  */
     34       1.1  jdolecek /*
     35       1.1  jdolecek  * Written by Paul Popelka (paulp (at) uts.amdahl.com)
     36       1.1  jdolecek  *
     37       1.1  jdolecek  * You can do anything you want with this software, just don't say you wrote
     38       1.1  jdolecek  * it, and don't remove this notice.
     39       1.1  jdolecek  *
     40       1.1  jdolecek  * This software is provided "as is".
     41       1.1  jdolecek  *
     42       1.1  jdolecek  * The author supplies this software to be publicly redistributed on the
     43       1.1  jdolecek  * understanding that the author is not responsible for the correct
     44       1.1  jdolecek  * functioning of this software in any circumstances and is not liable for
     45       1.1  jdolecek  * any damages caused by this software.
     46       1.1  jdolecek  *
     47       1.1  jdolecek  * October 1992
     48       1.1  jdolecek  */
     49       1.1  jdolecek 
     50      1.11  christos #ifndef _MSDOSFS_MSDOSFSMOUNT_H_
     51      1.11  christos #define _MSDOSFS_MSDOSFSMOUNT_H_
     52      1.11  christos 
     53  1.16.6.2       tls #ifndef MAKEFS
     54       1.1  jdolecek /*
     55       1.1  jdolecek  *  Arguments to mount MSDOS filesystems.
     56       1.1  jdolecek  */
     57       1.1  jdolecek struct msdosfs_args {
     58       1.1  jdolecek 	char	*fspec;		/* blocks special holding the fs to mount */
     59      1.10      jmmv 	struct	export_args30 _pad1; /* compat with old userland tools */
     60       1.1  jdolecek 	uid_t	uid;		/* uid that owns msdosfs files */
     61       1.1  jdolecek 	gid_t	gid;		/* gid that owns msdosfs files */
     62       1.1  jdolecek 	mode_t  mask;		/* mask to be applied for msdosfs perms */
     63       1.1  jdolecek 	int	flags;		/* see below */
     64       1.3  jdolecek 
     65       1.3  jdolecek 	/* Following items added after versioning support */
     66       1.3  jdolecek 	int	version;	/* version of the struct */
     67       1.6  jdolecek #define MSDOSFSMNT_VERSION	3
     68       1.3  jdolecek 	mode_t  dirmask;	/* v2: mask to be applied for msdosfs perms */
     69       1.6  jdolecek 	int	gmtoff;		/* v3: offset from UTC in seconds */
     70       1.1  jdolecek };
     71  1.16.6.2       tls #endif
     72       1.1  jdolecek 
     73       1.1  jdolecek /*
     74       1.1  jdolecek  * Msdosfs mount options:
     75       1.1  jdolecek  */
     76       1.1  jdolecek #define	MSDOSFSMNT_SHORTNAME	1	/* Force old DOS short names only */
     77       1.1  jdolecek #define	MSDOSFSMNT_LONGNAME	2	/* Force Win'95 long names */
     78       1.1  jdolecek #define	MSDOSFSMNT_NOWIN95	4	/* Completely ignore Win95 entries */
     79  1.16.6.1       tls #define	MSDOSFSMNT_GEMDOSFS	8	/* This is a GEMDOS-flavour */
     80       1.3  jdolecek #define MSDOSFSMNT_VERSIONED	16	/* Struct is versioned */
     81  1.16.6.4  jdolecek #define MSDOSFSMNT_UTF8		32	/* Use UTF8 filenames */
     82       1.1  jdolecek 
     83       1.1  jdolecek /* All flags above: */
     84       1.1  jdolecek #define	MSDOSFSMNT_MNTOPT \
     85       1.1  jdolecek 	(MSDOSFSMNT_SHORTNAME|MSDOSFSMNT_LONGNAME|MSDOSFSMNT_NOWIN95 \
     86  1.16.6.4  jdolecek 	 |MSDOSFSMNT_GEMDOSFS|MSDOSFSMNT_VERSIONED|MSDOSFSMNT_UTF8)
     87       1.3  jdolecek 
     88       1.1  jdolecek #define	MSDOSFSMNT_RONLY	0x80000000	/* mounted read-only	*/
     89       1.1  jdolecek #define	MSDOSFSMNT_WAITONFAT	0x40000000	/* mounted synchronous	*/
     90       1.1  jdolecek #define	MSDOSFS_FATMIRROR	0x20000000	/* FAT is mirrored */
     91       1.1  jdolecek 
     92       1.1  jdolecek #define MSDOSFSMNT_BITS "\177\20" \
     93       1.3  jdolecek     "b\00shortname\0b\01longname\0b\02nowin95\0b\03gemdosfs\0b\04mntversioned\0" \
     94  1.16.6.4  jdolecek     "b\05utf8\0b\037ronly\0b\036waitonfat\0b\035fatmirror\0"
     95       1.1  jdolecek 
     96       1.1  jdolecek #ifdef _KERNEL
     97       1.2   thorpej #include <sys/mallocvar.h>
     98      1.16     joerg #ifdef MALLOC_DECLARE
     99       1.2   thorpej MALLOC_DECLARE(M_MSDOSFSMNT);
    100      1.14    rumble MALLOC_DECLARE(M_MSDOSFSTMP);
    101      1.16     joerg #endif
    102  1.16.6.2       tls #endif
    103       1.2   thorpej 
    104  1.16.6.2       tls #if defined(_KERNEL) || defined(MAKEFS)
    105       1.1  jdolecek /*
    106  1.16.6.1       tls  * Layout of the mount control block for a MSDOSFS file system.
    107       1.1  jdolecek  */
    108       1.1  jdolecek struct msdosfsmount {
    109       1.1  jdolecek 	struct mount *pm_mountp;/* vfs mount struct for this fs */
    110       1.1  jdolecek 	dev_t pm_dev;		/* block special device mounted */
    111       1.1  jdolecek 	uid_t pm_uid;		/* uid to set as owner of the files */
    112       1.1  jdolecek 	gid_t pm_gid;		/* gid to set as owner of the files */
    113       1.3  jdolecek 	mode_t pm_mask;		/* mask to and with file protection bits
    114       1.3  jdolecek 				   for files */
    115       1.3  jdolecek 	mode_t pm_dirmask;	/* mask to and with file protection bits
    116       1.3  jdolecek 				   for directories */
    117       1.4    itojun 	int pm_gmtoff;		/* offset from UTC in seconds */
    118       1.1  jdolecek 	struct vnode *pm_devvp;	/* vnode for block device mntd */
    119       1.1  jdolecek 	struct bpb50 pm_bpb;	/* BIOS parameter blk for this fs */
    120  1.16.6.1       tls 	u_long pm_FATsecs;	/* actual number of FAT sectors */
    121      1.12       scw 	u_long pm_fatblk;	/* sector # of first FAT */
    122      1.12       scw 	u_long pm_rootdirblk;	/* sector # (cluster # for FAT32) of root directory number */
    123      1.12       scw 	u_long pm_rootdirsize;	/* size in sectors (not clusters) */
    124      1.12       scw 	u_long pm_firstcluster;	/* sector number of first cluster */
    125       1.1  jdolecek 	u_long pm_nmbrofclusters;	/* # of clusters in filesystem */
    126       1.1  jdolecek 	u_long pm_maxcluster;	/* maximum cluster number */
    127       1.1  jdolecek 	u_long pm_freeclustercount;	/* number of free clusters */
    128       1.1  jdolecek 	u_long pm_cnshift;	/* shift file offset right this amount to get a cluster number */
    129       1.1  jdolecek 	u_long pm_crbomask;	/* and a file offset with this mask to get cluster rel offset */
    130      1.12       scw 	u_long pm_bnshift;	/* shift file offset right this amount to get a sector number */
    131       1.1  jdolecek 	u_long pm_bpcluster;	/* bytes per cluster */
    132       1.1  jdolecek 	u_long pm_fmod;		/* ~0 if fs is modified, this can rollover to 0	*/
    133  1.16.6.1       tls 	u_long pm_fatblocksize;	/* size of FAT blocks in bytes */
    134  1.16.6.1       tls 	u_long pm_fatblocksec;	/* size of FAT blocks in sectors */
    135  1.16.6.1       tls 	u_long pm_fatsize;	/* size of FAT in bytes */
    136  1.16.6.1       tls 	u_long pm_fatmask;	/* mask to use for FAT numbers */
    137       1.1  jdolecek 	u_long pm_fsinfo;	/* fsinfo block number */
    138       1.1  jdolecek 	u_long pm_nxtfree;	/* next free cluster in fsinfo block */
    139  1.16.6.1       tls 	u_int pm_fatmult;	/* these 2 values are used in FAT */
    140       1.1  jdolecek 	u_int pm_fatdiv;	/*	offset computation */
    141  1.16.6.1       tls 	u_int pm_curfat;	/* current FAT for FAT32 (0 otherwise) */
    142       1.1  jdolecek 	u_int *pm_inusemap;	/* ptr to bitmap of in-use clusters */
    143       1.1  jdolecek 	u_int pm_flags;		/* see below */
    144       1.1  jdolecek };
    145       1.1  jdolecek /* Byte offset in FAT on filesystem pmp, cluster cn */
    146       1.1  jdolecek #define	FATOFS(pmp, cn)	((cn) * (pmp)->pm_fatmult / (pmp)->pm_fatdiv)
    147       1.1  jdolecek 
    148       1.1  jdolecek #define	VFSTOMSDOSFS(mp)	((struct msdosfsmount *)mp->mnt_data)
    149       1.1  jdolecek 
    150       1.1  jdolecek /* Number of bits in one pm_inusemap item: */
    151       1.1  jdolecek #define	N_INUSEBITS	(8 * sizeof(u_int))
    152       1.1  jdolecek 
    153       1.1  jdolecek /*
    154       1.1  jdolecek  * Shorthand for fields in the bpb contained in the msdosfsmount structure.
    155       1.1  jdolecek  */
    156       1.1  jdolecek #define	pm_BytesPerSec	pm_bpb.bpbBytesPerSec
    157       1.1  jdolecek #define	pm_ResSectors	pm_bpb.bpbResSectors
    158       1.1  jdolecek #define	pm_FATs		pm_bpb.bpbFATs
    159       1.1  jdolecek #define	pm_RootDirEnts	pm_bpb.bpbRootDirEnts
    160       1.1  jdolecek #define	pm_Sectors	pm_bpb.bpbSectors
    161       1.1  jdolecek #define	pm_Media	pm_bpb.bpbMedia
    162       1.1  jdolecek #define	pm_SecPerTrack	pm_bpb.bpbSecPerTrack
    163       1.1  jdolecek #define	pm_Heads	pm_bpb.bpbHeads
    164       1.1  jdolecek #define	pm_HiddenSects	pm_bpb.bpbHiddenSecs
    165       1.1  jdolecek #define	pm_HugeSectors	pm_bpb.bpbHugeSectors
    166       1.1  jdolecek 
    167       1.1  jdolecek /*
    168       1.1  jdolecek  * Convert pointer to buffer -> pointer to direntry
    169       1.1  jdolecek  */
    170       1.1  jdolecek #define	bptoep(pmp, bp, dirofs) \
    171      1.13  christos 	((struct direntry *)(((char *)(bp)->b_data)	\
    172       1.1  jdolecek 	 + ((dirofs) & (pmp)->pm_crbomask)))
    173       1.1  jdolecek 
    174       1.1  jdolecek /*
    175      1.12       scw  * Convert sector number to cluster number
    176       1.1  jdolecek  */
    177       1.1  jdolecek #define	de_bn2cn(pmp, bn) \
    178       1.1  jdolecek 	((bn) >> ((pmp)->pm_cnshift - (pmp)->pm_bnshift))
    179       1.1  jdolecek 
    180       1.1  jdolecek /*
    181      1.12       scw  * Convert cluster number to sector number
    182       1.1  jdolecek  */
    183       1.1  jdolecek #define	de_cn2bn(pmp, cn) \
    184       1.1  jdolecek 	((cn) << ((pmp)->pm_cnshift - (pmp)->pm_bnshift))
    185       1.1  jdolecek 
    186       1.1  jdolecek /*
    187      1.12       scw  * Convert sector number to kernel block number
    188      1.12       scw  */
    189      1.12       scw #define de_bn2kb(pmp, bn) \
    190      1.12       scw 	((bn) << ((pmp)->pm_bnshift - DEV_BSHIFT))
    191      1.12       scw 
    192      1.12       scw /*
    193      1.12       scw  * Convert kernel block number to sector number
    194      1.12       scw  */
    195      1.12       scw #define de_kb2bn(pmp, kb) \
    196      1.12       scw 	((kb) >> ((pmp)->pm_bnshift - DEV_BSHIFT))
    197      1.12       scw 
    198      1.12       scw /*
    199       1.1  jdolecek  * Convert file offset to cluster number
    200       1.1  jdolecek  */
    201       1.1  jdolecek #define de_cluster(pmp, off) \
    202       1.1  jdolecek 	((off) >> (pmp)->pm_cnshift)
    203       1.1  jdolecek 
    204       1.1  jdolecek /*
    205       1.1  jdolecek  * Clusters required to hold size bytes
    206       1.1  jdolecek  */
    207       1.1  jdolecek #define	de_clcount(pmp, size) \
    208       1.1  jdolecek 	(((size) + (pmp)->pm_bpcluster - 1) >> (pmp)->pm_cnshift)
    209       1.1  jdolecek 
    210       1.1  jdolecek /*
    211      1.12       scw  * Convert file offset to sector number
    212       1.1  jdolecek  */
    213       1.1  jdolecek #define de_blk(pmp, off) \
    214       1.1  jdolecek 	(de_cn2bn(pmp, de_cluster((pmp), (off))))
    215       1.1  jdolecek 
    216       1.1  jdolecek /*
    217       1.1  jdolecek  * Convert cluster number to file offset
    218       1.1  jdolecek  */
    219       1.1  jdolecek #define	de_cn2off(pmp, cn) \
    220       1.1  jdolecek 	((cn) << (pmp)->pm_cnshift)
    221       1.1  jdolecek 
    222       1.1  jdolecek /*
    223      1.12       scw  * Convert sector number to file offset
    224       1.1  jdolecek  */
    225       1.1  jdolecek #define	de_bn2off(pmp, bn) \
    226       1.1  jdolecek 	((bn) << (pmp)->pm_bnshift)
    227       1.1  jdolecek /*
    228      1.12       scw  * Map a cluster number into a filesystem relative sector number.
    229       1.1  jdolecek  */
    230       1.1  jdolecek #define	cntobn(pmp, cn) \
    231       1.1  jdolecek 	(de_cn2bn((pmp), (cn)-CLUST_FIRST) + (pmp)->pm_firstcluster)
    232       1.1  jdolecek 
    233       1.1  jdolecek /*
    234      1.12       scw  * Calculate sector number for directory entry in root dir, offset dirofs
    235       1.1  jdolecek  */
    236       1.1  jdolecek #define	roottobn(pmp, dirofs) \
    237       1.1  jdolecek 	(de_blk((pmp), (dirofs)) + (pmp)->pm_rootdirblk)
    238       1.1  jdolecek 
    239       1.1  jdolecek /*
    240      1.12       scw  * Calculate sector number for directory entry at cluster dirclu, offset
    241       1.1  jdolecek  * dirofs
    242       1.1  jdolecek  */
    243       1.1  jdolecek #define	detobn(pmp, dirclu, dirofs) \
    244       1.1  jdolecek 	((dirclu) == MSDOSFSROOT \
    245       1.1  jdolecek 	 ? roottobn((pmp), (dirofs)) \
    246       1.1  jdolecek 	 : cntobn((pmp), (dirclu)))
    247       1.1  jdolecek 
    248       1.1  jdolecek /*
    249       1.1  jdolecek  * Prototypes for MSDOSFS virtual filesystem operations
    250       1.1  jdolecek  */
    251       1.8   xtraeme void msdosfs_init(void);
    252       1.8   xtraeme void msdosfs_reinit(void);
    253       1.8   xtraeme void msdosfs_done(void);
    254       1.1  jdolecek 
    255  1.16.6.3       tls #ifndef MAKEFS
    256  1.16.6.3       tls VFS_PROTOS(msdosfs);
    257  1.16.6.3       tls #endif
    258  1.16.6.3       tls 
    259  1.16.6.2       tls #endif /* _KERNEL || MAKEFS */
    260      1.11  christos #endif /* _MSDOSFS_MSDOSFSMOUNT_H_ */
    261