msdosfsmount.h revision 137036
150477Speter/* $FreeBSD: head/sys/fs/msdosfs/msdosfsmount.h 137036 2004-10-29 10:40:14Z phk $ */ 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 56131523Stjr#include <sys/tree.h> 57131523Stjr 5830354Sphk#ifdef MALLOC_DECLARE 5930354SphkMALLOC_DECLARE(M_MSDOSFSMNT); 6030354Sphk#endif 6130354Sphk 62131523Stjrstruct msdosfs_fileno; 63131523Stjr 642893Sdfr/* 6596755Strhodes * Layout of the mount control block for a msdos filesystem. 662893Sdfr */ 672893Sdfrstruct msdosfsmount { 682893Sdfr struct mount *pm_mountp;/* vfs mount struct for this fs */ 69130585Sphk struct cdev *pm_dev; /* block special device mounted */ 70137036Sphk struct g_consumer *pm_cp; 71137036Sphk struct bufobj *pm_bo; 722893Sdfr uid_t pm_uid; /* uid to set as owner of the files */ 732893Sdfr gid_t pm_gid; /* gid to set as owner of the files */ 74118837Strhodes mode_t pm_mask; /* mask to and with file protection bits 75118837Strhodes for files */ 76118837Strhodes mode_t pm_dirmask; /* mask to and with file protection bits 77118837Strhodes for directories */ 782893Sdfr struct vnode *pm_devvp; /* vnode for block device mntd */ 792893Sdfr struct bpb50 pm_bpb; /* BIOS parameter blk for this fs */ 8056674Snyan u_long pm_BlkPerSec; /* How many DEV_BSIZE blocks fit inside a physical sector */ 8133548Sjkh u_long pm_FATsecs; /* actual number of fat sectors */ 822893Sdfr u_long pm_fatblk; /* block # of first FAT */ 8333548Sjkh u_long pm_rootdirblk; /* block # (cluster # for FAT32) of root directory number */ 842893Sdfr u_long pm_rootdirsize; /* size in blocks (not clusters) */ 852893Sdfr u_long pm_firstcluster; /* block number of first cluster */ 862893Sdfr u_long pm_maxcluster; /* maximum cluster number */ 872893Sdfr u_long pm_freeclustercount; /* number of free clusters */ 882893Sdfr u_long pm_cnshift; /* shift file offset right this amount to get a cluster number */ 892893Sdfr u_long pm_crbomask; /* and a file offset with this mask to get cluster rel offset */ 9033548Sjkh u_long pm_bnshift; /* shift file offset right this amount to get a block number */ 912893Sdfr u_long pm_bpcluster; /* bytes per cluster */ 922893Sdfr u_long pm_fmod; /* ~0 if fs is modified, this can rollover to 0 */ 932893Sdfr u_long pm_fatblocksize; /* size of fat blocks in bytes */ 942893Sdfr u_long pm_fatblocksec; /* size of fat blocks in sectors */ 952893Sdfr u_long pm_fatsize; /* size of fat in bytes */ 9665075Sbde u_int32_t pm_fatmask; /* mask to use for fat numbers */ 9733548Sjkh u_long pm_fsinfo; /* fsinfo block number */ 9833548Sjkh u_long pm_nxtfree; /* next free cluster in fsinfo block */ 9933548Sjkh u_int pm_fatmult; /* these 2 values are used in fat */ 10033548Sjkh u_int pm_fatdiv; /* offset computation */ 10133548Sjkh u_int pm_curfat; /* current fat for FAT32 (0 otherwise) */ 1022893Sdfr u_int *pm_inusemap; /* ptr to bitmap of in-use clusters */ 10333548Sjkh u_int pm_flags; /* see below */ 104120492Sfjoe void *pm_u2w; /* Local->Unicode iconv handle */ 105120492Sfjoe void *pm_w2u; /* Unicode->Local iconv handle */ 106120492Sfjoe void *pm_u2d; /* Unicode->DOS iconv handle */ 107120492Sfjoe void *pm_d2u; /* DOS->Local iconv handle */ 108131523Stjr u_int32_t pm_nfileno; /* next 32-bit fileno */ 109131523Stjr RB_HEAD(msdosfs_filenotree, msdosfs_fileno) pm_filenos; /* 64<->32-bit fileno mapping */ 1102893Sdfr}; 111131523Stjr 112131523Stjr/* 113131523Stjr * A 64-bit file number and the 32-bit file number to which it is mapped, 114131523Stjr * in a red-black tree node. 115131523Stjr */ 116131523Stjrstruct msdosfs_fileno { 117131523Stjr RB_ENTRY(msdosfs_fileno) mf_tree; 118131523Stjr uint32_t mf_fileno32; 119131523Stjr uint64_t mf_fileno64; 120131523Stjr}; 121131523Stjr 12233548Sjkh/* Byte offset in FAT on filesystem pmp, cluster cn */ 12333548Sjkh#define FATOFS(pmp, cn) ((cn) * (pmp)->pm_fatmult / (pmp)->pm_fatdiv) 1242893Sdfr 12533548Sjkh 12633548Sjkh#define VFSTOMSDOSFS(mp) ((struct msdosfsmount *)mp->mnt_data) 12733548Sjkh 1282893Sdfr/* Number of bits in one pm_inusemap item: */ 1292893Sdfr#define N_INUSEBITS (8 * sizeof(u_int)) 1302893Sdfr 1312893Sdfr/* 1322893Sdfr * Shorthand for fields in the bpb contained in the msdosfsmount structure. 1332893Sdfr */ 1342893Sdfr#define pm_BytesPerSec pm_bpb.bpbBytesPerSec 1352893Sdfr#define pm_ResSectors pm_bpb.bpbResSectors 1362893Sdfr#define pm_FATs pm_bpb.bpbFATs 1372893Sdfr#define pm_RootDirEnts pm_bpb.bpbRootDirEnts 1382893Sdfr#define pm_Sectors pm_bpb.bpbSectors 1392893Sdfr#define pm_Media pm_bpb.bpbMedia 1402893Sdfr#define pm_SecPerTrack pm_bpb.bpbSecPerTrack 1412893Sdfr#define pm_Heads pm_bpb.bpbHeads 1422893Sdfr#define pm_HiddenSects pm_bpb.bpbHiddenSecs 1432893Sdfr#define pm_HugeSectors pm_bpb.bpbHugeSectors 1442893Sdfr 1452893Sdfr/* 14633548Sjkh * Convert pointer to buffer -> pointer to direntry 1472893Sdfr */ 14833548Sjkh#define bptoep(pmp, bp, dirofs) \ 14933548Sjkh ((struct direntry *)(((bp)->b_data) \ 15033548Sjkh + ((dirofs) & (pmp)->pm_crbomask))) 1512893Sdfr 1522893Sdfr/* 15333548Sjkh * Convert block number to cluster number 1542893Sdfr */ 15533548Sjkh#define de_bn2cn(pmp, bn) \ 15633548Sjkh ((bn) >> ((pmp)->pm_cnshift - (pmp)->pm_bnshift)) 1572893Sdfr 1582893Sdfr/* 15933548Sjkh * Convert cluster number to block number 1602893Sdfr */ 16133548Sjkh#define de_cn2bn(pmp, cn) \ 16233548Sjkh ((cn) << ((pmp)->pm_cnshift - (pmp)->pm_bnshift)) 1632893Sdfr 1642893Sdfr/* 16533548Sjkh * Convert file offset to cluster number 1662893Sdfr */ 16733548Sjkh#define de_cluster(pmp, off) \ 16833548Sjkh ((off) >> (pmp)->pm_cnshift) 1692893Sdfr 1702893Sdfr/* 17133548Sjkh * Clusters required to hold size bytes 1722893Sdfr */ 17333548Sjkh#define de_clcount(pmp, size) \ 17433548Sjkh (((size) + (pmp)->pm_bpcluster - 1) >> (pmp)->pm_cnshift) 1752893Sdfr 1762893Sdfr/* 17733548Sjkh * Convert file offset to block number 1782893Sdfr */ 1792893Sdfr#define de_blk(pmp, off) \ 18033548Sjkh (de_cn2bn(pmp, de_cluster((pmp), (off)))) 1812893Sdfr 1822893Sdfr/* 18333548Sjkh * Convert cluster number to file offset 1842893Sdfr */ 18533548Sjkh#define de_cn2off(pmp, cn) \ 18633548Sjkh ((cn) << (pmp)->pm_cnshift) 1872893Sdfr 18833548Sjkh/* 18933548Sjkh * Convert block number to file offset 19033548Sjkh */ 19133548Sjkh#define de_bn2off(pmp, bn) \ 19233548Sjkh ((bn) << (pmp)->pm_bnshift) 19333548Sjkh/* 19433548Sjkh * Map a cluster number into a filesystem relative block number. 19533548Sjkh */ 19633548Sjkh#define cntobn(pmp, cn) \ 19733548Sjkh (de_cn2bn((pmp), (cn)-CLUST_FIRST) + (pmp)->pm_firstcluster) 19833548Sjkh 19933548Sjkh/* 20033548Sjkh * Calculate block number for directory entry in root dir, offset dirofs 20133548Sjkh */ 20233548Sjkh#define roottobn(pmp, dirofs) \ 20333548Sjkh (de_blk((pmp), (dirofs)) + (pmp)->pm_rootdirblk) 20433548Sjkh 20533548Sjkh/* 20633548Sjkh * Calculate block number for directory entry at cluster dirclu, offset 20733548Sjkh * dirofs 20833548Sjkh */ 20933548Sjkh#define detobn(pmp, dirclu, dirofs) \ 21033548Sjkh ((dirclu) == MSDOSFSROOT \ 21133548Sjkh ? roottobn((pmp), (dirofs)) \ 21233548Sjkh : cntobn((pmp), (dirclu))) 21333548Sjkh 21456674Snyan/* 21556674Snyan * Calculate fsinfo block size 21656674Snyan */ 21756674Snyan#define fsi_size(pmp) \ 21856674Snyan (1024 << ((pmp)->pm_BlkPerSec >> 2)) 21956674Snyan 22092727Salfredint msdosfs_init(struct vfsconf *vfsp); 22192727Salfredint msdosfs_uninit(struct vfsconf *vfsp); 22292727Salfredint msdosfs_mountroot(void); 22322521Sdyson 224131523Stjrvoid msdosfs_fileno_init(struct mount *); 225131523Stjrvoid msdosfs_fileno_free(struct mount *); 226131523Stjruint32_t msdosfs_fileno_map(struct mount *, uint64_t); 227131523Stjr 22855206Speter#endif /* _KERNEL */ 22923351Sbde 23022521Sdyson/* 23122521Sdyson * Arguments to mount MSDOS filesystems. 23222521Sdyson */ 23322521Sdysonstruct msdosfs_args { 23422521Sdyson char *fspec; /* blocks special holding the fs to mount */ 23522521Sdyson struct export_args export; /* network export information */ 23622521Sdyson uid_t uid; /* uid that owns msdosfs files */ 23722521Sdyson gid_t gid; /* gid that owns msdosfs files */ 238118837Strhodes mode_t mask; /* file mask to be applied for msdosfs perms */ 23933548Sjkh int flags; /* see below */ 24033548Sjkh int magic; /* version number */ 24133747Sache u_int16_t u2w[128]; /* Local->Unicode table */ 242120492Sfjoe char *cs_win; /* Windows(Unicode) Charset */ 243120492Sfjoe char *cs_dos; /* DOS Charset */ 244120492Sfjoe char *cs_local; /* Local Charset */ 245131523Stjr mode_t dirmask; /* dir mask to be applied for msdosfs perms */ 24622521Sdyson}; 24722521Sdyson 24833548Sjkh/* 24933548Sjkh * Msdosfs mount options: 25033548Sjkh */ 25133548Sjkh#define MSDOSFSMNT_SHORTNAME 1 /* Force old DOS short names only */ 25233548Sjkh#define MSDOSFSMNT_LONGNAME 2 /* Force Win'95 long names */ 25333548Sjkh#define MSDOSFSMNT_NOWIN95 4 /* Completely ignore Win95 entries */ 254120492Sfjoe#define MSDOSFSMNT_KICONV 0x10 /* Use libiconv to convert chars */ 25533548Sjkh/* All flags above: */ 25633548Sjkh#define MSDOSFSMNT_MNTOPT \ 25733548Sjkh (MSDOSFSMNT_SHORTNAME|MSDOSFSMNT_LONGNAME|MSDOSFSMNT_NOWIN95 \ 258120492Sfjoe |MSDOSFSMNT_KICONV) 25933548Sjkh#define MSDOSFSMNT_RONLY 0x80000000 /* mounted read-only */ 26033548Sjkh#define MSDOSFSMNT_WAITONFAT 0x40000000 /* mounted synchronous */ 26133548Sjkh#define MSDOSFS_FATMIRROR 0x20000000 /* FAT is mirrored */ 262131523Stjr#define MSDOSFS_LARGEFS 0x10000000 /* perform fileno mapping */ 26333548Sjkh 26433548Sjkh#define MSDOSFS_ARGSMAGIC 0xe4eff300 26533548Sjkh 26623351Sbde#endif /* !_MSDOSFS_MSDOSFSMOUNT_H_ */ 267