150477Speter/* $FreeBSD$ */ 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 */ 35139776Simp/*- 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 56204470Skib#include <sys/types.h> 57204470Skib#include <sys/lock.h> 58204470Skib#include <sys/lockmgr.h> 59131523Stjr#include <sys/tree.h> 60131523Stjr 6130354Sphk#ifdef MALLOC_DECLARE 6230354SphkMALLOC_DECLARE(M_MSDOSFSMNT); 6330354Sphk#endif 6430354Sphk 65131523Stjrstruct msdosfs_fileno; 66131523Stjr 672893Sdfr/* 6896755Strhodes * Layout of the mount control block for a msdos filesystem. 692893Sdfr */ 702893Sdfrstruct msdosfsmount { 712893Sdfr struct mount *pm_mountp;/* vfs mount struct for this fs */ 72137036Sphk struct g_consumer *pm_cp; 73137036Sphk struct bufobj *pm_bo; 742893Sdfr uid_t pm_uid; /* uid to set as owner of the files */ 752893Sdfr gid_t pm_gid; /* gid to set as owner of the files */ 76118837Strhodes mode_t pm_mask; /* mask to and with file protection bits 77118837Strhodes for files */ 78118837Strhodes mode_t pm_dirmask; /* mask to and with file protection bits 79118837Strhodes for directories */ 80189120Sjhb struct vnode *pm_devvp; /* vnode for character device mounted */ 81189120Sjhb struct cdev *pm_dev; /* character device mounted */ 822893Sdfr struct bpb50 pm_bpb; /* BIOS parameter blk for this fs */ 8356674Snyan u_long pm_BlkPerSec; /* How many DEV_BSIZE blocks fit inside a physical sector */ 8433548Sjkh u_long pm_FATsecs; /* actual number of fat sectors */ 852893Sdfr u_long pm_fatblk; /* block # of first FAT */ 8633548Sjkh u_long pm_rootdirblk; /* block # (cluster # for FAT32) of root directory number */ 872893Sdfr u_long pm_rootdirsize; /* size in blocks (not clusters) */ 882893Sdfr u_long pm_firstcluster; /* block number of first cluster */ 892893Sdfr u_long pm_maxcluster; /* maximum cluster number */ 902893Sdfr u_long pm_freeclustercount; /* number of free clusters */ 912893Sdfr u_long pm_cnshift; /* shift file offset right this amount to get a cluster number */ 922893Sdfr u_long pm_crbomask; /* and a file offset with this mask to get cluster rel offset */ 9333548Sjkh u_long pm_bnshift; /* shift file offset right this amount to get a block number */ 942893Sdfr u_long pm_bpcluster; /* bytes per cluster */ 952893Sdfr u_long pm_fmod; /* ~0 if fs is modified, this can rollover to 0 */ 962893Sdfr u_long pm_fatblocksize; /* size of fat blocks in bytes */ 972893Sdfr u_long pm_fatblocksec; /* size of fat blocks in sectors */ 982893Sdfr u_long pm_fatsize; /* size of fat in bytes */ 9965075Sbde u_int32_t pm_fatmask; /* mask to use for fat numbers */ 10033548Sjkh u_long pm_fsinfo; /* fsinfo block number */ 101171343Sbde u_long pm_nxtfree; /* next place to search for a free cluster */ 10233548Sjkh u_int pm_fatmult; /* these 2 values are used in fat */ 10333548Sjkh u_int pm_fatdiv; /* offset computation */ 10433548Sjkh u_int pm_curfat; /* current fat for FAT32 (0 otherwise) */ 1052893Sdfr u_int *pm_inusemap; /* ptr to bitmap of in-use clusters */ 106224290Smckusick uint64_t pm_flags; /* see below */ 107120492Sfjoe void *pm_u2w; /* Local->Unicode iconv handle */ 108120492Sfjoe void *pm_w2u; /* Unicode->Local iconv handle */ 109120492Sfjoe void *pm_u2d; /* Unicode->DOS iconv handle */ 110120492Sfjoe void *pm_d2u; /* DOS->Local iconv handle */ 111131523Stjr u_int32_t pm_nfileno; /* next 32-bit fileno */ 112204470Skib RB_HEAD(msdosfs_filenotree, msdosfs_fileno) 113204470Skib pm_filenos; /* 64<->32-bit fileno mapping */ 114204470Skib struct lock pm_fatlock; /* lockmgr protecting allocations and rb tree */ 1152893Sdfr}; 116131523Stjr 117131523Stjr/* 118131523Stjr * A 64-bit file number and the 32-bit file number to which it is mapped, 119131523Stjr * in a red-black tree node. 120131523Stjr */ 121131523Stjrstruct msdosfs_fileno { 122131523Stjr RB_ENTRY(msdosfs_fileno) mf_tree; 123131523Stjr uint32_t mf_fileno32; 124131523Stjr uint64_t mf_fileno64; 125131523Stjr}; 126131523Stjr 12733548Sjkh/* Byte offset in FAT on filesystem pmp, cluster cn */ 12833548Sjkh#define FATOFS(pmp, cn) ((cn) * (pmp)->pm_fatmult / (pmp)->pm_fatdiv) 1292893Sdfr 13033548Sjkh 13133548Sjkh#define VFSTOMSDOSFS(mp) ((struct msdosfsmount *)mp->mnt_data) 13233548Sjkh 1332893Sdfr/* Number of bits in one pm_inusemap item: */ 1342893Sdfr#define N_INUSEBITS (8 * sizeof(u_int)) 1352893Sdfr 1362893Sdfr/* 1372893Sdfr * Shorthand for fields in the bpb contained in the msdosfsmount structure. 1382893Sdfr */ 1392893Sdfr#define pm_BytesPerSec pm_bpb.bpbBytesPerSec 1402893Sdfr#define pm_ResSectors pm_bpb.bpbResSectors 1412893Sdfr#define pm_FATs pm_bpb.bpbFATs 1422893Sdfr#define pm_RootDirEnts pm_bpb.bpbRootDirEnts 1432893Sdfr#define pm_Sectors pm_bpb.bpbSectors 1442893Sdfr#define pm_Media pm_bpb.bpbMedia 1452893Sdfr#define pm_SecPerTrack pm_bpb.bpbSecPerTrack 1462893Sdfr#define pm_Heads pm_bpb.bpbHeads 1472893Sdfr#define pm_HiddenSects pm_bpb.bpbHiddenSecs 1482893Sdfr#define pm_HugeSectors pm_bpb.bpbHugeSectors 1492893Sdfr 1502893Sdfr/* 15133548Sjkh * Convert pointer to buffer -> pointer to direntry 1522893Sdfr */ 15333548Sjkh#define bptoep(pmp, bp, dirofs) \ 15433548Sjkh ((struct direntry *)(((bp)->b_data) \ 15533548Sjkh + ((dirofs) & (pmp)->pm_crbomask))) 1562893Sdfr 1572893Sdfr/* 15833548Sjkh * Convert block number to cluster number 1592893Sdfr */ 16033548Sjkh#define de_bn2cn(pmp, bn) \ 16133548Sjkh ((bn) >> ((pmp)->pm_cnshift - (pmp)->pm_bnshift)) 1622893Sdfr 1632893Sdfr/* 16433548Sjkh * Convert cluster number to block number 1652893Sdfr */ 16633548Sjkh#define de_cn2bn(pmp, cn) \ 16733548Sjkh ((cn) << ((pmp)->pm_cnshift - (pmp)->pm_bnshift)) 1682893Sdfr 1692893Sdfr/* 17033548Sjkh * Convert file offset to cluster number 1712893Sdfr */ 17233548Sjkh#define de_cluster(pmp, off) \ 17333548Sjkh ((off) >> (pmp)->pm_cnshift) 1742893Sdfr 1752893Sdfr/* 17633548Sjkh * Clusters required to hold size bytes 1772893Sdfr */ 17833548Sjkh#define de_clcount(pmp, size) \ 17933548Sjkh (((size) + (pmp)->pm_bpcluster - 1) >> (pmp)->pm_cnshift) 1802893Sdfr 1812893Sdfr/* 18233548Sjkh * Convert file offset to block number 1832893Sdfr */ 1842893Sdfr#define de_blk(pmp, off) \ 18533548Sjkh (de_cn2bn(pmp, de_cluster((pmp), (off)))) 1862893Sdfr 1872893Sdfr/* 18833548Sjkh * Convert cluster number to file offset 1892893Sdfr */ 19033548Sjkh#define de_cn2off(pmp, cn) \ 19133548Sjkh ((cn) << (pmp)->pm_cnshift) 1922893Sdfr 19333548Sjkh/* 19433548Sjkh * Convert block number to file offset 19533548Sjkh */ 19633548Sjkh#define de_bn2off(pmp, bn) \ 19733548Sjkh ((bn) << (pmp)->pm_bnshift) 19833548Sjkh/* 19933548Sjkh * Map a cluster number into a filesystem relative block number. 20033548Sjkh */ 20133548Sjkh#define cntobn(pmp, cn) \ 20233548Sjkh (de_cn2bn((pmp), (cn)-CLUST_FIRST) + (pmp)->pm_firstcluster) 20333548Sjkh 20433548Sjkh/* 20533548Sjkh * Calculate block number for directory entry in root dir, offset dirofs 20633548Sjkh */ 20733548Sjkh#define roottobn(pmp, dirofs) \ 20833548Sjkh (de_blk((pmp), (dirofs)) + (pmp)->pm_rootdirblk) 20933548Sjkh 21033548Sjkh/* 21133548Sjkh * Calculate block number for directory entry at cluster dirclu, offset 21233548Sjkh * dirofs 21333548Sjkh */ 21433548Sjkh#define detobn(pmp, dirclu, dirofs) \ 21533548Sjkh ((dirclu) == MSDOSFSROOT \ 21633548Sjkh ? roottobn((pmp), (dirofs)) \ 21733548Sjkh : cntobn((pmp), (dirclu))) 21833548Sjkh 219131523Stjrvoid msdosfs_fileno_init(struct mount *); 220131523Stjrvoid msdosfs_fileno_free(struct mount *); 221131523Stjruint32_t msdosfs_fileno_map(struct mount *, uint64_t); 222131523Stjr 223204470Skib#define MSDOSFS_LOCK_MP(pmp) \ 224204470Skib lockmgr(&(pmp)->pm_fatlock, LK_EXCLUSIVE, NULL) 225204470Skib#define MSDOSFS_UNLOCK_MP(pmp) \ 226204470Skib lockmgr(&(pmp)->pm_fatlock, LK_RELEASE, NULL) 227204470Skib#define MSDOSFS_ASSERT_MP_LOCKED(pmp) \ 228204470Skib lockmgr_assert(&(pmp)->pm_fatlock, KA_XLOCKED) 229204470Skib 23055206Speter#endif /* _KERNEL */ 23123351Sbde 23222521Sdyson/* 23322521Sdyson * Arguments to mount MSDOS filesystems. 23422521Sdyson */ 23522521Sdysonstruct msdosfs_args { 23622521Sdyson char *fspec; /* blocks special holding the fs to mount */ 237213664Skib struct oexport_args export; /* network export information */ 23822521Sdyson uid_t uid; /* uid that owns msdosfs files */ 23922521Sdyson gid_t gid; /* gid that owns msdosfs files */ 240118837Strhodes mode_t mask; /* file mask to be applied for msdosfs perms */ 24133548Sjkh int flags; /* see below */ 242280342Skib int unused1; /* unused, was version number */ 243280342Skib u_int16_t unused2[128]; /* no longer used, was Local->Unicode table */ 244120492Sfjoe char *cs_win; /* Windows(Unicode) Charset */ 245120492Sfjoe char *cs_dos; /* DOS Charset */ 246120492Sfjoe char *cs_local; /* Local Charset */ 247131523Stjr mode_t dirmask; /* dir mask to be applied for msdosfs perms */ 24822521Sdyson}; 24922521Sdyson 25033548Sjkh/* 25133548Sjkh * Msdosfs mount options: 25233548Sjkh */ 25333548Sjkh#define MSDOSFSMNT_SHORTNAME 1 /* Force old DOS short names only */ 25433548Sjkh#define MSDOSFSMNT_LONGNAME 2 /* Force Win'95 long names */ 25533548Sjkh#define MSDOSFSMNT_NOWIN95 4 /* Completely ignore Win95 entries */ 256120492Sfjoe#define MSDOSFSMNT_KICONV 0x10 /* Use libiconv to convert chars */ 25733548Sjkh/* All flags above: */ 25833548Sjkh#define MSDOSFSMNT_MNTOPT \ 25933548Sjkh (MSDOSFSMNT_SHORTNAME|MSDOSFSMNT_LONGNAME|MSDOSFSMNT_NOWIN95 \ 260120492Sfjoe |MSDOSFSMNT_KICONV) 26133548Sjkh#define MSDOSFSMNT_RONLY 0x80000000 /* mounted read-only */ 26233548Sjkh#define MSDOSFSMNT_WAITONFAT 0x40000000 /* mounted synchronous */ 26333548Sjkh#define MSDOSFS_FATMIRROR 0x20000000 /* FAT is mirrored */ 264131523Stjr#define MSDOSFS_LARGEFS 0x10000000 /* perform fileno mapping */ 265246921Skib#define MSDOSFS_FSIMOD 0x01000000 26633548Sjkh 26723351Sbde#endif /* !_MSDOSFS_MSDOSFSMOUNT_H_ */ 268