msdosfsmount.h revision 131523
150477Speter/* $FreeBSD: head/sys/fs/msdosfs/msdosfsmount.h 131523 2004-07-03 13:22:38Z tjr $ */ 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 */ 702893Sdfr uid_t pm_uid; /* uid to set as owner of the files */ 712893Sdfr gid_t pm_gid; /* gid to set as owner of the files */ 72118837Strhodes mode_t pm_mask; /* mask to and with file protection bits 73118837Strhodes for files */ 74118837Strhodes mode_t pm_dirmask; /* mask to and with file protection bits 75118837Strhodes for directories */ 762893Sdfr struct vnode *pm_devvp; /* vnode for block device mntd */ 772893Sdfr struct bpb50 pm_bpb; /* BIOS parameter blk for this fs */ 7856674Snyan u_long pm_BlkPerSec; /* How many DEV_BSIZE blocks fit inside a physical sector */ 7933548Sjkh u_long pm_FATsecs; /* actual number of fat sectors */ 802893Sdfr u_long pm_fatblk; /* block # of first FAT */ 8133548Sjkh u_long pm_rootdirblk; /* block # (cluster # for FAT32) of root directory number */ 822893Sdfr u_long pm_rootdirsize; /* size in blocks (not clusters) */ 832893Sdfr u_long pm_firstcluster; /* block number of first cluster */ 842893Sdfr u_long pm_maxcluster; /* maximum cluster number */ 852893Sdfr u_long pm_freeclustercount; /* number of free clusters */ 862893Sdfr u_long pm_cnshift; /* shift file offset right this amount to get a cluster number */ 872893Sdfr u_long pm_crbomask; /* and a file offset with this mask to get cluster rel offset */ 8833548Sjkh u_long pm_bnshift; /* shift file offset right this amount to get a block number */ 892893Sdfr u_long pm_bpcluster; /* bytes per cluster */ 902893Sdfr u_long pm_fmod; /* ~0 if fs is modified, this can rollover to 0 */ 912893Sdfr u_long pm_fatblocksize; /* size of fat blocks in bytes */ 922893Sdfr u_long pm_fatblocksec; /* size of fat blocks in sectors */ 932893Sdfr u_long pm_fatsize; /* size of fat in bytes */ 9465075Sbde u_int32_t pm_fatmask; /* mask to use for fat numbers */ 9533548Sjkh u_long pm_fsinfo; /* fsinfo block number */ 9633548Sjkh u_long pm_nxtfree; /* next free cluster in fsinfo block */ 9733548Sjkh u_int pm_fatmult; /* these 2 values are used in fat */ 9833548Sjkh u_int pm_fatdiv; /* offset computation */ 9933548Sjkh u_int pm_curfat; /* current fat for FAT32 (0 otherwise) */ 1002893Sdfr u_int *pm_inusemap; /* ptr to bitmap of in-use clusters */ 10133548Sjkh u_int pm_flags; /* see below */ 102120492Sfjoe void *pm_u2w; /* Local->Unicode iconv handle */ 103120492Sfjoe void *pm_w2u; /* Unicode->Local iconv handle */ 104120492Sfjoe void *pm_u2d; /* Unicode->DOS iconv handle */ 105120492Sfjoe void *pm_d2u; /* DOS->Local iconv handle */ 106131523Stjr u_int32_t pm_nfileno; /* next 32-bit fileno */ 107131523Stjr RB_HEAD(msdosfs_filenotree, msdosfs_fileno) pm_filenos; /* 64<->32-bit fileno mapping */ 1082893Sdfr}; 109131523Stjr 110131523Stjr/* 111131523Stjr * A 64-bit file number and the 32-bit file number to which it is mapped, 112131523Stjr * in a red-black tree node. 113131523Stjr */ 114131523Stjrstruct msdosfs_fileno { 115131523Stjr RB_ENTRY(msdosfs_fileno) mf_tree; 116131523Stjr uint32_t mf_fileno32; 117131523Stjr uint64_t mf_fileno64; 118131523Stjr}; 119131523Stjr 12033548Sjkh/* Byte offset in FAT on filesystem pmp, cluster cn */ 12133548Sjkh#define FATOFS(pmp, cn) ((cn) * (pmp)->pm_fatmult / (pmp)->pm_fatdiv) 1222893Sdfr 12333548Sjkh 12433548Sjkh#define VFSTOMSDOSFS(mp) ((struct msdosfsmount *)mp->mnt_data) 12533548Sjkh 1262893Sdfr/* Number of bits in one pm_inusemap item: */ 1272893Sdfr#define N_INUSEBITS (8 * sizeof(u_int)) 1282893Sdfr 1292893Sdfr/* 1302893Sdfr * Shorthand for fields in the bpb contained in the msdosfsmount structure. 1312893Sdfr */ 1322893Sdfr#define pm_BytesPerSec pm_bpb.bpbBytesPerSec 1332893Sdfr#define pm_ResSectors pm_bpb.bpbResSectors 1342893Sdfr#define pm_FATs pm_bpb.bpbFATs 1352893Sdfr#define pm_RootDirEnts pm_bpb.bpbRootDirEnts 1362893Sdfr#define pm_Sectors pm_bpb.bpbSectors 1372893Sdfr#define pm_Media pm_bpb.bpbMedia 1382893Sdfr#define pm_SecPerTrack pm_bpb.bpbSecPerTrack 1392893Sdfr#define pm_Heads pm_bpb.bpbHeads 1402893Sdfr#define pm_HiddenSects pm_bpb.bpbHiddenSecs 1412893Sdfr#define pm_HugeSectors pm_bpb.bpbHugeSectors 1422893Sdfr 1432893Sdfr/* 14433548Sjkh * Convert pointer to buffer -> pointer to direntry 1452893Sdfr */ 14633548Sjkh#define bptoep(pmp, bp, dirofs) \ 14733548Sjkh ((struct direntry *)(((bp)->b_data) \ 14833548Sjkh + ((dirofs) & (pmp)->pm_crbomask))) 1492893Sdfr 1502893Sdfr/* 15133548Sjkh * Convert block number to cluster number 1522893Sdfr */ 15333548Sjkh#define de_bn2cn(pmp, bn) \ 15433548Sjkh ((bn) >> ((pmp)->pm_cnshift - (pmp)->pm_bnshift)) 1552893Sdfr 1562893Sdfr/* 15733548Sjkh * Convert cluster number to block number 1582893Sdfr */ 15933548Sjkh#define de_cn2bn(pmp, cn) \ 16033548Sjkh ((cn) << ((pmp)->pm_cnshift - (pmp)->pm_bnshift)) 1612893Sdfr 1622893Sdfr/* 16333548Sjkh * Convert file offset to cluster number 1642893Sdfr */ 16533548Sjkh#define de_cluster(pmp, off) \ 16633548Sjkh ((off) >> (pmp)->pm_cnshift) 1672893Sdfr 1682893Sdfr/* 16933548Sjkh * Clusters required to hold size bytes 1702893Sdfr */ 17133548Sjkh#define de_clcount(pmp, size) \ 17233548Sjkh (((size) + (pmp)->pm_bpcluster - 1) >> (pmp)->pm_cnshift) 1732893Sdfr 1742893Sdfr/* 17533548Sjkh * Convert file offset to block number 1762893Sdfr */ 1772893Sdfr#define de_blk(pmp, off) \ 17833548Sjkh (de_cn2bn(pmp, de_cluster((pmp), (off)))) 1792893Sdfr 1802893Sdfr/* 18133548Sjkh * Convert cluster number to file offset 1822893Sdfr */ 18333548Sjkh#define de_cn2off(pmp, cn) \ 18433548Sjkh ((cn) << (pmp)->pm_cnshift) 1852893Sdfr 18633548Sjkh/* 18733548Sjkh * Convert block number to file offset 18833548Sjkh */ 18933548Sjkh#define de_bn2off(pmp, bn) \ 19033548Sjkh ((bn) << (pmp)->pm_bnshift) 19133548Sjkh/* 19233548Sjkh * Map a cluster number into a filesystem relative block number. 19333548Sjkh */ 19433548Sjkh#define cntobn(pmp, cn) \ 19533548Sjkh (de_cn2bn((pmp), (cn)-CLUST_FIRST) + (pmp)->pm_firstcluster) 19633548Sjkh 19733548Sjkh/* 19833548Sjkh * Calculate block number for directory entry in root dir, offset dirofs 19933548Sjkh */ 20033548Sjkh#define roottobn(pmp, dirofs) \ 20133548Sjkh (de_blk((pmp), (dirofs)) + (pmp)->pm_rootdirblk) 20233548Sjkh 20333548Sjkh/* 20433548Sjkh * Calculate block number for directory entry at cluster dirclu, offset 20533548Sjkh * dirofs 20633548Sjkh */ 20733548Sjkh#define detobn(pmp, dirclu, dirofs) \ 20833548Sjkh ((dirclu) == MSDOSFSROOT \ 20933548Sjkh ? roottobn((pmp), (dirofs)) \ 21033548Sjkh : cntobn((pmp), (dirclu))) 21133548Sjkh 21256674Snyan/* 21356674Snyan * Calculate fsinfo block size 21456674Snyan */ 21556674Snyan#define fsi_size(pmp) \ 21656674Snyan (1024 << ((pmp)->pm_BlkPerSec >> 2)) 21756674Snyan 21892727Salfredint msdosfs_init(struct vfsconf *vfsp); 21992727Salfredint msdosfs_uninit(struct vfsconf *vfsp); 22092727Salfredint msdosfs_mountroot(void); 22122521Sdyson 222131523Stjrvoid msdosfs_fileno_init(struct mount *); 223131523Stjrvoid msdosfs_fileno_free(struct mount *); 224131523Stjruint32_t msdosfs_fileno_map(struct mount *, uint64_t); 225131523Stjr 22655206Speter#endif /* _KERNEL */ 22723351Sbde 22822521Sdyson/* 22922521Sdyson * Arguments to mount MSDOS filesystems. 23022521Sdyson */ 23122521Sdysonstruct msdosfs_args { 23222521Sdyson char *fspec; /* blocks special holding the fs to mount */ 23322521Sdyson struct export_args export; /* network export information */ 23422521Sdyson uid_t uid; /* uid that owns msdosfs files */ 23522521Sdyson gid_t gid; /* gid that owns msdosfs files */ 236118837Strhodes mode_t mask; /* file mask to be applied for msdosfs perms */ 23733548Sjkh int flags; /* see below */ 23833548Sjkh int magic; /* version number */ 23933747Sache u_int16_t u2w[128]; /* Local->Unicode table */ 240120492Sfjoe char *cs_win; /* Windows(Unicode) Charset */ 241120492Sfjoe char *cs_dos; /* DOS Charset */ 242120492Sfjoe char *cs_local; /* Local Charset */ 243131523Stjr mode_t dirmask; /* dir mask to be applied for msdosfs perms */ 24422521Sdyson}; 24522521Sdyson 24633548Sjkh/* 24733548Sjkh * Msdosfs mount options: 24833548Sjkh */ 24933548Sjkh#define MSDOSFSMNT_SHORTNAME 1 /* Force old DOS short names only */ 25033548Sjkh#define MSDOSFSMNT_LONGNAME 2 /* Force Win'95 long names */ 25133548Sjkh#define MSDOSFSMNT_NOWIN95 4 /* Completely ignore Win95 entries */ 252120492Sfjoe#define MSDOSFSMNT_KICONV 0x10 /* Use libiconv to convert chars */ 25333548Sjkh/* All flags above: */ 25433548Sjkh#define MSDOSFSMNT_MNTOPT \ 25533548Sjkh (MSDOSFSMNT_SHORTNAME|MSDOSFSMNT_LONGNAME|MSDOSFSMNT_NOWIN95 \ 256120492Sfjoe |MSDOSFSMNT_KICONV) 25733548Sjkh#define MSDOSFSMNT_RONLY 0x80000000 /* mounted read-only */ 25833548Sjkh#define MSDOSFSMNT_WAITONFAT 0x40000000 /* mounted synchronous */ 25933548Sjkh#define MSDOSFS_FATMIRROR 0x20000000 /* FAT is mirrored */ 260131523Stjr#define MSDOSFS_LARGEFS 0x10000000 /* perform fileno mapping */ 26133548Sjkh 26233548Sjkh#define MSDOSFS_ARGSMAGIC 0xe4eff300 26333548Sjkh 26423351Sbde#endif /* !_MSDOSFS_MSDOSFSMOUNT_H_ */ 265