msdosfsmount.h revision 56674
150477Speter/* $FreeBSD: head/sys/fs/msdosfs/msdosfsmount.h 56674 2000-01-27 14:43:07Z nyan $ */ 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/* 612893Sdfr * Layout of the mount control block for a msdos file system. 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 */ 682893Sdfr mode_t pm_mask; /* mask to and with file protection bits */ 692893Sdfr struct vnode *pm_devvp; /* vnode for block device mntd */ 702893Sdfr struct bpb50 pm_bpb; /* BIOS parameter blk for this fs */ 7156674Snyan u_long pm_BlkPerSec; /* How many DEV_BSIZE blocks fit inside a physical sector */ 7233548Sjkh u_long pm_FATsecs; /* actual number of fat sectors */ 732893Sdfr u_long pm_fatblk; /* block # of first FAT */ 7433548Sjkh u_long pm_rootdirblk; /* block # (cluster # for FAT32) of root directory number */ 752893Sdfr u_long pm_rootdirsize; /* size in blocks (not clusters) */ 762893Sdfr u_long pm_firstcluster; /* block number of first cluster */ 772893Sdfr u_long pm_maxcluster; /* maximum cluster number */ 782893Sdfr u_long pm_freeclustercount; /* number of free clusters */ 792893Sdfr u_long pm_cnshift; /* shift file offset right this amount to get a cluster number */ 802893Sdfr u_long pm_crbomask; /* and a file offset with this mask to get cluster rel offset */ 8133548Sjkh u_long pm_bnshift; /* shift file offset right this amount to get a block number */ 822893Sdfr u_long pm_bpcluster; /* bytes per cluster */ 832893Sdfr u_long pm_fmod; /* ~0 if fs is modified, this can rollover to 0 */ 842893Sdfr u_long pm_fatblocksize; /* size of fat blocks in bytes */ 852893Sdfr u_long pm_fatblocksec; /* size of fat blocks in sectors */ 862893Sdfr u_long pm_fatsize; /* size of fat in bytes */ 8733548Sjkh u_long pm_fatmask; /* mask to use for fat numbers */ 8833548Sjkh u_long pm_fsinfo; /* fsinfo block number */ 8933548Sjkh u_long pm_nxtfree; /* next free cluster in fsinfo block */ 9033548Sjkh u_int pm_fatmult; /* these 2 values are used in fat */ 9133548Sjkh u_int pm_fatdiv; /* offset computation */ 9233548Sjkh u_int pm_curfat; /* current fat for FAT32 (0 otherwise) */ 932893Sdfr u_int *pm_inusemap; /* ptr to bitmap of in-use clusters */ 9433548Sjkh u_int pm_flags; /* see below */ 952893Sdfr struct netexport pm_export; /* export information */ 9633747Sache u_int16_t pm_u2w[128]; /* Local->Unicode table */ 9733760Sache u_int8_t pm_ul[128]; /* Local upper->lower table */ 9833768Sache u_int8_t pm_lu[128]; /* Local lower->upper table */ 9933768Sache u_int8_t pm_d2u[128]; /* DOS->local table */ 10033768Sache u_int8_t pm_u2d[128]; /* Local->DOS table */ 1012893Sdfr}; 10233548Sjkh/* Byte offset in FAT on filesystem pmp, cluster cn */ 10333548Sjkh#define FATOFS(pmp, cn) ((cn) * (pmp)->pm_fatmult / (pmp)->pm_fatdiv) 1042893Sdfr 10533548Sjkh 10633548Sjkh#define VFSTOMSDOSFS(mp) ((struct msdosfsmount *)mp->mnt_data) 10733548Sjkh 1082893Sdfr/* Number of bits in one pm_inusemap item: */ 1092893Sdfr#define N_INUSEBITS (8 * sizeof(u_int)) 1102893Sdfr 1112893Sdfr/* 1122893Sdfr * Shorthand for fields in the bpb contained in the msdosfsmount structure. 1132893Sdfr */ 1142893Sdfr#define pm_BytesPerSec pm_bpb.bpbBytesPerSec 1152893Sdfr#define pm_ResSectors pm_bpb.bpbResSectors 1162893Sdfr#define pm_FATs pm_bpb.bpbFATs 1172893Sdfr#define pm_RootDirEnts pm_bpb.bpbRootDirEnts 1182893Sdfr#define pm_Sectors pm_bpb.bpbSectors 1192893Sdfr#define pm_Media pm_bpb.bpbMedia 1202893Sdfr#define pm_SecPerTrack pm_bpb.bpbSecPerTrack 1212893Sdfr#define pm_Heads pm_bpb.bpbHeads 1222893Sdfr#define pm_HiddenSects pm_bpb.bpbHiddenSecs 1232893Sdfr#define pm_HugeSectors pm_bpb.bpbHugeSectors 1242893Sdfr 1252893Sdfr/* 12633548Sjkh * Convert pointer to buffer -> pointer to direntry 1272893Sdfr */ 12833548Sjkh#define bptoep(pmp, bp, dirofs) \ 12933548Sjkh ((struct direntry *)(((bp)->b_data) \ 13033548Sjkh + ((dirofs) & (pmp)->pm_crbomask))) 1312893Sdfr 1322893Sdfr/* 13333548Sjkh * Convert block number to cluster number 1342893Sdfr */ 13533548Sjkh#define de_bn2cn(pmp, bn) \ 13633548Sjkh ((bn) >> ((pmp)->pm_cnshift - (pmp)->pm_bnshift)) 1372893Sdfr 1382893Sdfr/* 13933548Sjkh * Convert cluster number to block number 1402893Sdfr */ 14133548Sjkh#define de_cn2bn(pmp, cn) \ 14233548Sjkh ((cn) << ((pmp)->pm_cnshift - (pmp)->pm_bnshift)) 1432893Sdfr 1442893Sdfr/* 14533548Sjkh * Convert file offset to cluster number 1462893Sdfr */ 14733548Sjkh#define de_cluster(pmp, off) \ 14833548Sjkh ((off) >> (pmp)->pm_cnshift) 1492893Sdfr 1502893Sdfr/* 15133548Sjkh * Clusters required to hold size bytes 1522893Sdfr */ 15333548Sjkh#define de_clcount(pmp, size) \ 15433548Sjkh (((size) + (pmp)->pm_bpcluster - 1) >> (pmp)->pm_cnshift) 1552893Sdfr 1562893Sdfr/* 15733548Sjkh * Convert file offset to block number 1582893Sdfr */ 1592893Sdfr#define de_blk(pmp, off) \ 16033548Sjkh (de_cn2bn(pmp, de_cluster((pmp), (off)))) 1612893Sdfr 1622893Sdfr/* 16333548Sjkh * Convert cluster number to file offset 1642893Sdfr */ 16533548Sjkh#define de_cn2off(pmp, cn) \ 16633548Sjkh ((cn) << (pmp)->pm_cnshift) 1672893Sdfr 16833548Sjkh/* 16933548Sjkh * Convert block number to file offset 17033548Sjkh */ 17133548Sjkh#define de_bn2off(pmp, bn) \ 17233548Sjkh ((bn) << (pmp)->pm_bnshift) 17333548Sjkh/* 17433548Sjkh * Map a cluster number into a filesystem relative block number. 17533548Sjkh */ 17633548Sjkh#define cntobn(pmp, cn) \ 17733548Sjkh (de_cn2bn((pmp), (cn)-CLUST_FIRST) + (pmp)->pm_firstcluster) 17833548Sjkh 17933548Sjkh/* 18033548Sjkh * Calculate block number for directory entry in root dir, offset dirofs 18133548Sjkh */ 18233548Sjkh#define roottobn(pmp, dirofs) \ 18333548Sjkh (de_blk((pmp), (dirofs)) + (pmp)->pm_rootdirblk) 18433548Sjkh 18533548Sjkh/* 18633548Sjkh * Calculate block number for directory entry at cluster dirclu, offset 18733548Sjkh * dirofs 18833548Sjkh */ 18933548Sjkh#define detobn(pmp, dirclu, dirofs) \ 19033548Sjkh ((dirclu) == MSDOSFSROOT \ 19133548Sjkh ? roottobn((pmp), (dirofs)) \ 19233548Sjkh : cntobn((pmp), (dirclu))) 19333548Sjkh 19456674Snyan/* 19556674Snyan * Calculate fsinfo block size 19656674Snyan */ 19756674Snyan#define fsi_size(pmp) \ 19856674Snyan (1024 << ((pmp)->pm_BlkPerSec >> 2)) 19956674Snyan 20022601Smppint msdosfs_init __P((struct vfsconf *vfsp)); 20133548Sjkhint msdosfs_mountroot __P((void)); 20222521Sdyson 20355206Speter#endif /* _KERNEL */ 20423351Sbde 20522521Sdyson/* 20622521Sdyson * Arguments to mount MSDOS filesystems. 20722521Sdyson */ 20822521Sdysonstruct msdosfs_args { 20922521Sdyson char *fspec; /* blocks special holding the fs to mount */ 21022521Sdyson struct export_args export; /* network export information */ 21122521Sdyson uid_t uid; /* uid that owns msdosfs files */ 21222521Sdyson gid_t gid; /* gid that owns msdosfs files */ 21322521Sdyson mode_t mask; /* mask to be applied for msdosfs perms */ 21433548Sjkh int flags; /* see below */ 21533548Sjkh int magic; /* version number */ 21633747Sache u_int16_t u2w[128]; /* Local->Unicode table */ 21733760Sache u_int8_t ul[128]; /* Local upper->lower table */ 21833768Sache u_int8_t lu[128]; /* Local lower->upper table */ 21933768Sache u_int8_t d2u[128]; /* DOS->local table */ 22033768Sache u_int8_t u2d[128]; /* Local->DOS table */ 22122521Sdyson}; 22222521Sdyson 22333548Sjkh/* 22433548Sjkh * Msdosfs mount options: 22533548Sjkh */ 22633548Sjkh#define MSDOSFSMNT_SHORTNAME 1 /* Force old DOS short names only */ 22733548Sjkh#define MSDOSFSMNT_LONGNAME 2 /* Force Win'95 long names */ 22833548Sjkh#define MSDOSFSMNT_NOWIN95 4 /* Completely ignore Win95 entries */ 22933548Sjkh#ifndef __FreeBSD__ 23033548Sjkh#define MSDOSFSMNT_GEMDOSFS 8 /* This is a gemdos-flavour */ 23133548Sjkh#endif 23233768Sache#define MSDOSFSMNT_U2WTABLE 0x10 /* Local->Unicode and local<->DOS */ 23333768Sache /* tables loaded */ 23433768Sache#define MSDOSFSMNT_ULTABLE 0x20 /* Local upper<->lower table loaded */ 23533548Sjkh/* All flags above: */ 23633548Sjkh#define MSDOSFSMNT_MNTOPT \ 23733548Sjkh (MSDOSFSMNT_SHORTNAME|MSDOSFSMNT_LONGNAME|MSDOSFSMNT_NOWIN95 \ 23833760Sache /*|MSDOSFSMNT_GEMDOSFS*/|MSDOSFSMNT_U2WTABLE|MSDOSFSMNT_ULTABLE) 23933548Sjkh#define MSDOSFSMNT_RONLY 0x80000000 /* mounted read-only */ 24033548Sjkh#define MSDOSFSMNT_WAITONFAT 0x40000000 /* mounted synchronous */ 24133548Sjkh#define MSDOSFS_FATMIRROR 0x20000000 /* FAT is mirrored */ 24233548Sjkh 24333548Sjkh#define MSDOSFS_ARGSMAGIC 0xe4eff300 24433548Sjkh 24523351Sbde#endif /* !_MSDOSFS_MSDOSFSMOUNT_H_ */ 246