1*0a6a1f1dSLionel Sambuc /* $NetBSD: msdosfsmount.h,v 1.20 2014/07/08 09:21:52 hannken Exp $ */ 284d9c625SLionel Sambuc 384d9c625SLionel Sambuc /*- 484d9c625SLionel Sambuc * Copyright (C) 1994, 1995, 1997 Wolfgang Solfrank. 584d9c625SLionel Sambuc * Copyright (C) 1994, 1995, 1997 TooLs GmbH. 684d9c625SLionel Sambuc * All rights reserved. 784d9c625SLionel Sambuc * Original code by Paul Popelka (paulp@uts.amdahl.com) (see below). 884d9c625SLionel Sambuc * 984d9c625SLionel Sambuc * Redistribution and use in source and binary forms, with or without 1084d9c625SLionel Sambuc * modification, are permitted provided that the following conditions 1184d9c625SLionel Sambuc * are met: 1284d9c625SLionel Sambuc * 1. Redistributions of source code must retain the above copyright 1384d9c625SLionel Sambuc * notice, this list of conditions and the following disclaimer. 1484d9c625SLionel Sambuc * 2. Redistributions in binary form must reproduce the above copyright 1584d9c625SLionel Sambuc * notice, this list of conditions and the following disclaimer in the 1684d9c625SLionel Sambuc * documentation and/or other materials provided with the distribution. 1784d9c625SLionel Sambuc * 3. All advertising materials mentioning features or use of this software 1884d9c625SLionel Sambuc * must display the following acknowledgement: 1984d9c625SLionel Sambuc * This product includes software developed by TooLs GmbH. 2084d9c625SLionel Sambuc * 4. The name of TooLs GmbH may not be used to endorse or promote products 2184d9c625SLionel Sambuc * derived from this software without specific prior written permission. 2284d9c625SLionel Sambuc * 2384d9c625SLionel Sambuc * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR 2484d9c625SLionel Sambuc * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 2584d9c625SLionel Sambuc * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 2684d9c625SLionel Sambuc * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 2784d9c625SLionel Sambuc * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 2884d9c625SLionel Sambuc * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 2984d9c625SLionel Sambuc * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 3084d9c625SLionel Sambuc * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 3184d9c625SLionel Sambuc * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 3284d9c625SLionel Sambuc * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 3384d9c625SLionel Sambuc */ 3484d9c625SLionel Sambuc /* 3584d9c625SLionel Sambuc * Written by Paul Popelka (paulp@uts.amdahl.com) 3684d9c625SLionel Sambuc * 3784d9c625SLionel Sambuc * You can do anything you want with this software, just don't say you wrote 3884d9c625SLionel Sambuc * it, and don't remove this notice. 3984d9c625SLionel Sambuc * 4084d9c625SLionel Sambuc * This software is provided "as is". 4184d9c625SLionel Sambuc * 4284d9c625SLionel Sambuc * The author supplies this software to be publicly redistributed on the 4384d9c625SLionel Sambuc * understanding that the author is not responsible for the correct 4484d9c625SLionel Sambuc * functioning of this software in any circumstances and is not liable for 4584d9c625SLionel Sambuc * any damages caused by this software. 4684d9c625SLionel Sambuc * 4784d9c625SLionel Sambuc * October 1992 4884d9c625SLionel Sambuc */ 4984d9c625SLionel Sambuc 5084d9c625SLionel Sambuc #ifndef _MSDOSFS_MSDOSFSMOUNT_H_ 5184d9c625SLionel Sambuc #define _MSDOSFS_MSDOSFSMOUNT_H_ 5284d9c625SLionel Sambuc 5384d9c625SLionel Sambuc #ifndef MAKEFS 5484d9c625SLionel Sambuc /* 5584d9c625SLionel Sambuc * Arguments to mount MSDOS filesystems. 5684d9c625SLionel Sambuc */ 5784d9c625SLionel Sambuc struct msdosfs_args { 5884d9c625SLionel Sambuc char *fspec; /* blocks special holding the fs to mount */ 5984d9c625SLionel Sambuc struct export_args30 _pad1; /* compat with old userland tools */ 6084d9c625SLionel Sambuc uid_t uid; /* uid that owns msdosfs files */ 6184d9c625SLionel Sambuc gid_t gid; /* gid that owns msdosfs files */ 6284d9c625SLionel Sambuc mode_t mask; /* mask to be applied for msdosfs perms */ 6384d9c625SLionel Sambuc int flags; /* see below */ 6484d9c625SLionel Sambuc 6584d9c625SLionel Sambuc /* Following items added after versioning support */ 6684d9c625SLionel Sambuc int version; /* version of the struct */ 6784d9c625SLionel Sambuc #define MSDOSFSMNT_VERSION 3 6884d9c625SLionel Sambuc mode_t dirmask; /* v2: mask to be applied for msdosfs perms */ 6984d9c625SLionel Sambuc int gmtoff; /* v3: offset from UTC in seconds */ 7084d9c625SLionel Sambuc }; 7184d9c625SLionel Sambuc #endif 7284d9c625SLionel Sambuc 7384d9c625SLionel Sambuc /* 7484d9c625SLionel Sambuc * Msdosfs mount options: 7584d9c625SLionel Sambuc */ 7684d9c625SLionel Sambuc #define MSDOSFSMNT_SHORTNAME 1 /* Force old DOS short names only */ 7784d9c625SLionel Sambuc #define MSDOSFSMNT_LONGNAME 2 /* Force Win'95 long names */ 7884d9c625SLionel Sambuc #define MSDOSFSMNT_NOWIN95 4 /* Completely ignore Win95 entries */ 7984d9c625SLionel Sambuc #define MSDOSFSMNT_GEMDOSFS 8 /* This is a GEMDOS-flavour */ 8084d9c625SLionel Sambuc #define MSDOSFSMNT_VERSIONED 16 /* Struct is versioned */ 8184d9c625SLionel Sambuc 8284d9c625SLionel Sambuc /* All flags above: */ 8384d9c625SLionel Sambuc #define MSDOSFSMNT_MNTOPT \ 8484d9c625SLionel Sambuc (MSDOSFSMNT_SHORTNAME|MSDOSFSMNT_LONGNAME|MSDOSFSMNT_NOWIN95 \ 8584d9c625SLionel Sambuc |MSDOSFSMNT_GEMDOSFS|MSDOSFSMNT_VERSIONED) 8684d9c625SLionel Sambuc 8784d9c625SLionel Sambuc #define MSDOSFSMNT_RONLY 0x80000000 /* mounted read-only */ 8884d9c625SLionel Sambuc #define MSDOSFSMNT_WAITONFAT 0x40000000 /* mounted synchronous */ 8984d9c625SLionel Sambuc #define MSDOSFS_FATMIRROR 0x20000000 /* FAT is mirrored */ 9084d9c625SLionel Sambuc 9184d9c625SLionel Sambuc #define MSDOSFSMNT_BITS "\177\20" \ 9284d9c625SLionel Sambuc "b\00shortname\0b\01longname\0b\02nowin95\0b\03gemdosfs\0b\04mntversioned\0" \ 9384d9c625SLionel Sambuc "b\037ronly\0b\036waitonfat\0b\035fatmirror\0" 9484d9c625SLionel Sambuc 9584d9c625SLionel Sambuc #ifdef _KERNEL 9684d9c625SLionel Sambuc #include <sys/mallocvar.h> 9784d9c625SLionel Sambuc #ifdef MALLOC_DECLARE 9884d9c625SLionel Sambuc MALLOC_DECLARE(M_MSDOSFSMNT); 9984d9c625SLionel Sambuc MALLOC_DECLARE(M_MSDOSFSTMP); 10084d9c625SLionel Sambuc #endif 10184d9c625SLionel Sambuc #endif 10284d9c625SLionel Sambuc 10384d9c625SLionel Sambuc #if defined(_KERNEL) || defined(MAKEFS) 10484d9c625SLionel Sambuc /* 10584d9c625SLionel Sambuc * Layout of the mount control block for a MSDOSFS file system. 10684d9c625SLionel Sambuc */ 10784d9c625SLionel Sambuc struct msdosfsmount { 10884d9c625SLionel Sambuc struct mount *pm_mountp;/* vfs mount struct for this fs */ 10984d9c625SLionel Sambuc dev_t pm_dev; /* block special device mounted */ 11084d9c625SLionel Sambuc uid_t pm_uid; /* uid to set as owner of the files */ 11184d9c625SLionel Sambuc gid_t pm_gid; /* gid to set as owner of the files */ 11284d9c625SLionel Sambuc mode_t pm_mask; /* mask to and with file protection bits 11384d9c625SLionel Sambuc for files */ 11484d9c625SLionel Sambuc mode_t pm_dirmask; /* mask to and with file protection bits 11584d9c625SLionel Sambuc for directories */ 11684d9c625SLionel Sambuc int pm_gmtoff; /* offset from UTC in seconds */ 11784d9c625SLionel Sambuc struct vnode *pm_devvp; /* vnode for block device mntd */ 11884d9c625SLionel Sambuc struct bpb50 pm_bpb; /* BIOS parameter blk for this fs */ 11984d9c625SLionel Sambuc u_long pm_FATsecs; /* actual number of FAT sectors */ 12084d9c625SLionel Sambuc u_long pm_fatblk; /* sector # of first FAT */ 12184d9c625SLionel Sambuc u_long pm_rootdirblk; /* sector # (cluster # for FAT32) of root directory number */ 12284d9c625SLionel Sambuc u_long pm_rootdirsize; /* size in sectors (not clusters) */ 12384d9c625SLionel Sambuc u_long pm_firstcluster; /* sector number of first cluster */ 12484d9c625SLionel Sambuc u_long pm_nmbrofclusters; /* # of clusters in filesystem */ 12584d9c625SLionel Sambuc u_long pm_maxcluster; /* maximum cluster number */ 12684d9c625SLionel Sambuc u_long pm_freeclustercount; /* number of free clusters */ 12784d9c625SLionel Sambuc u_long pm_cnshift; /* shift file offset right this amount to get a cluster number */ 12884d9c625SLionel Sambuc u_long pm_crbomask; /* and a file offset with this mask to get cluster rel offset */ 12984d9c625SLionel Sambuc u_long pm_bnshift; /* shift file offset right this amount to get a sector number */ 13084d9c625SLionel Sambuc u_long pm_bpcluster; /* bytes per cluster */ 13184d9c625SLionel Sambuc u_long pm_fmod; /* ~0 if fs is modified, this can rollover to 0 */ 13284d9c625SLionel Sambuc u_long pm_fatblocksize; /* size of FAT blocks in bytes */ 13384d9c625SLionel Sambuc u_long pm_fatblocksec; /* size of FAT blocks in sectors */ 13484d9c625SLionel Sambuc u_long pm_fatsize; /* size of FAT in bytes */ 13584d9c625SLionel Sambuc u_long pm_fatmask; /* mask to use for FAT numbers */ 13684d9c625SLionel Sambuc u_long pm_fsinfo; /* fsinfo block number */ 13784d9c625SLionel Sambuc u_long pm_nxtfree; /* next free cluster in fsinfo block */ 13884d9c625SLionel Sambuc u_int pm_fatmult; /* these 2 values are used in FAT */ 13984d9c625SLionel Sambuc u_int pm_fatdiv; /* offset computation */ 14084d9c625SLionel Sambuc u_int pm_curfat; /* current FAT for FAT32 (0 otherwise) */ 14184d9c625SLionel Sambuc u_int *pm_inusemap; /* ptr to bitmap of in-use clusters */ 14284d9c625SLionel Sambuc u_int pm_flags; /* see below */ 14384d9c625SLionel Sambuc }; 14484d9c625SLionel Sambuc /* Byte offset in FAT on filesystem pmp, cluster cn */ 14584d9c625SLionel Sambuc #define FATOFS(pmp, cn) ((cn) * (pmp)->pm_fatmult / (pmp)->pm_fatdiv) 14684d9c625SLionel Sambuc 14784d9c625SLionel Sambuc #define VFSTOMSDOSFS(mp) ((struct msdosfsmount *)mp->mnt_data) 14884d9c625SLionel Sambuc 14984d9c625SLionel Sambuc /* Number of bits in one pm_inusemap item: */ 15084d9c625SLionel Sambuc #define N_INUSEBITS (8 * sizeof(u_int)) 15184d9c625SLionel Sambuc 15284d9c625SLionel Sambuc /* 15384d9c625SLionel Sambuc * Shorthand for fields in the bpb contained in the msdosfsmount structure. 15484d9c625SLionel Sambuc */ 15584d9c625SLionel Sambuc #define pm_BytesPerSec pm_bpb.bpbBytesPerSec 15684d9c625SLionel Sambuc #define pm_ResSectors pm_bpb.bpbResSectors 15784d9c625SLionel Sambuc #define pm_FATs pm_bpb.bpbFATs 15884d9c625SLionel Sambuc #define pm_RootDirEnts pm_bpb.bpbRootDirEnts 15984d9c625SLionel Sambuc #define pm_Sectors pm_bpb.bpbSectors 16084d9c625SLionel Sambuc #define pm_Media pm_bpb.bpbMedia 16184d9c625SLionel Sambuc #define pm_SecPerTrack pm_bpb.bpbSecPerTrack 16284d9c625SLionel Sambuc #define pm_Heads pm_bpb.bpbHeads 16384d9c625SLionel Sambuc #define pm_HiddenSects pm_bpb.bpbHiddenSecs 16484d9c625SLionel Sambuc #define pm_HugeSectors pm_bpb.bpbHugeSectors 16584d9c625SLionel Sambuc 16684d9c625SLionel Sambuc /* 16784d9c625SLionel Sambuc * Convert pointer to buffer -> pointer to direntry 16884d9c625SLionel Sambuc */ 16984d9c625SLionel Sambuc #define bptoep(pmp, bp, dirofs) \ 17084d9c625SLionel Sambuc ((struct direntry *)(((char *)(bp)->b_data) \ 17184d9c625SLionel Sambuc + ((dirofs) & (pmp)->pm_crbomask))) 17284d9c625SLionel Sambuc 17384d9c625SLionel Sambuc /* 17484d9c625SLionel Sambuc * Convert sector number to cluster number 17584d9c625SLionel Sambuc */ 17684d9c625SLionel Sambuc #define de_bn2cn(pmp, bn) \ 17784d9c625SLionel Sambuc ((bn) >> ((pmp)->pm_cnshift - (pmp)->pm_bnshift)) 17884d9c625SLionel Sambuc 17984d9c625SLionel Sambuc /* 18084d9c625SLionel Sambuc * Convert cluster number to sector number 18184d9c625SLionel Sambuc */ 18284d9c625SLionel Sambuc #define de_cn2bn(pmp, cn) \ 18384d9c625SLionel Sambuc ((cn) << ((pmp)->pm_cnshift - (pmp)->pm_bnshift)) 18484d9c625SLionel Sambuc 18584d9c625SLionel Sambuc /* 18684d9c625SLionel Sambuc * Convert sector number to kernel block number 18784d9c625SLionel Sambuc */ 18884d9c625SLionel Sambuc #define de_bn2kb(pmp, bn) \ 18984d9c625SLionel Sambuc ((bn) << ((pmp)->pm_bnshift - DEV_BSHIFT)) 19084d9c625SLionel Sambuc 19184d9c625SLionel Sambuc /* 19284d9c625SLionel Sambuc * Convert kernel block number to sector number 19384d9c625SLionel Sambuc */ 19484d9c625SLionel Sambuc #define de_kb2bn(pmp, kb) \ 19584d9c625SLionel Sambuc ((kb) >> ((pmp)->pm_bnshift - DEV_BSHIFT)) 19684d9c625SLionel Sambuc 19784d9c625SLionel Sambuc /* 19884d9c625SLionel Sambuc * Convert file offset to cluster number 19984d9c625SLionel Sambuc */ 20084d9c625SLionel Sambuc #define de_cluster(pmp, off) \ 20184d9c625SLionel Sambuc ((off) >> (pmp)->pm_cnshift) 20284d9c625SLionel Sambuc 20384d9c625SLionel Sambuc /* 20484d9c625SLionel Sambuc * Clusters required to hold size bytes 20584d9c625SLionel Sambuc */ 20684d9c625SLionel Sambuc #define de_clcount(pmp, size) \ 20784d9c625SLionel Sambuc (((size) + (pmp)->pm_bpcluster - 1) >> (pmp)->pm_cnshift) 20884d9c625SLionel Sambuc 20984d9c625SLionel Sambuc /* 21084d9c625SLionel Sambuc * Convert file offset to sector number 21184d9c625SLionel Sambuc */ 21284d9c625SLionel Sambuc #define de_blk(pmp, off) \ 21384d9c625SLionel Sambuc (de_cn2bn(pmp, de_cluster((pmp), (off)))) 21484d9c625SLionel Sambuc 21584d9c625SLionel Sambuc /* 21684d9c625SLionel Sambuc * Convert cluster number to file offset 21784d9c625SLionel Sambuc */ 21884d9c625SLionel Sambuc #define de_cn2off(pmp, cn) \ 21984d9c625SLionel Sambuc ((cn) << (pmp)->pm_cnshift) 22084d9c625SLionel Sambuc 22184d9c625SLionel Sambuc /* 22284d9c625SLionel Sambuc * Convert sector number to file offset 22384d9c625SLionel Sambuc */ 22484d9c625SLionel Sambuc #define de_bn2off(pmp, bn) \ 22584d9c625SLionel Sambuc ((bn) << (pmp)->pm_bnshift) 22684d9c625SLionel Sambuc /* 22784d9c625SLionel Sambuc * Map a cluster number into a filesystem relative sector number. 22884d9c625SLionel Sambuc */ 22984d9c625SLionel Sambuc #define cntobn(pmp, cn) \ 23084d9c625SLionel Sambuc (de_cn2bn((pmp), (cn)-CLUST_FIRST) + (pmp)->pm_firstcluster) 23184d9c625SLionel Sambuc 23284d9c625SLionel Sambuc /* 23384d9c625SLionel Sambuc * Calculate sector number for directory entry in root dir, offset dirofs 23484d9c625SLionel Sambuc */ 23584d9c625SLionel Sambuc #define roottobn(pmp, dirofs) \ 23684d9c625SLionel Sambuc (de_blk((pmp), (dirofs)) + (pmp)->pm_rootdirblk) 23784d9c625SLionel Sambuc 23884d9c625SLionel Sambuc /* 23984d9c625SLionel Sambuc * Calculate sector number for directory entry at cluster dirclu, offset 24084d9c625SLionel Sambuc * dirofs 24184d9c625SLionel Sambuc */ 24284d9c625SLionel Sambuc #define detobn(pmp, dirclu, dirofs) \ 24384d9c625SLionel Sambuc ((dirclu) == MSDOSFSROOT \ 24484d9c625SLionel Sambuc ? roottobn((pmp), (dirofs)) \ 24584d9c625SLionel Sambuc : cntobn((pmp), (dirclu))) 24684d9c625SLionel Sambuc 24784d9c625SLionel Sambuc /* 24884d9c625SLionel Sambuc * Prototypes for MSDOSFS virtual filesystem operations 24984d9c625SLionel Sambuc */ 25084d9c625SLionel Sambuc void msdosfs_init(void); 25184d9c625SLionel Sambuc void msdosfs_reinit(void); 25284d9c625SLionel Sambuc void msdosfs_done(void); 25384d9c625SLionel Sambuc 254*0a6a1f1dSLionel Sambuc #ifndef MAKEFS 255*0a6a1f1dSLionel Sambuc VFS_PROTOS(msdosfs); 256*0a6a1f1dSLionel Sambuc #endif 257*0a6a1f1dSLionel Sambuc 25884d9c625SLionel Sambuc #endif /* _KERNEL || MAKEFS */ 25984d9c625SLionel Sambuc #endif /* _MSDOSFS_MSDOSFSMOUNT_H_ */ 260