150477Speter/* $FreeBSD$ */ 233548Sjkh/* $NetBSD: fat.h,v 1.12 1997/11/17 15:36:36 ws Exp $ */ 32893Sdfr 42893Sdfr/*- 533548Sjkh * Copyright (C) 1994, 1997 Wolfgang Solfrank. 633548Sjkh * Copyright (C) 1994, 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 512893Sdfr/* 522893Sdfr * Some useful cluster numbers. 532893Sdfr */ 5433548Sjkh#define MSDOSFSROOT 0 /* cluster 0 means the root dir */ 5533548Sjkh#define CLUST_FREE 0 /* cluster 0 also means a free cluster */ 562893Sdfr#define MSDOSFSFREE CLUST_FREE 5733548Sjkh#define CLUST_FIRST 2 /* first legal cluster number */ 5833548Sjkh#define CLUST_RSRVD 0xfffffff6 /* reserved cluster range */ 5933548Sjkh#define CLUST_BAD 0xfffffff7 /* a cluster with a defect */ 6033548Sjkh#define CLUST_EOFS 0xfffffff8 /* start of eof cluster range */ 6133548Sjkh#define CLUST_EOFE 0xffffffff /* end of eof cluster range */ 622893Sdfr 6333548Sjkh#define FAT12_MASK 0x00000fff /* mask for 12 bit cluster numbers */ 6433548Sjkh#define FAT16_MASK 0x0000ffff /* mask for 16 bit cluster numbers */ 6533548Sjkh#define FAT32_MASK 0x0fffffff /* mask for FAT32 cluster numbers */ 662893Sdfr 672893Sdfr/* 6833548Sjkh * MSDOSFS: 692893Sdfr * Return true if filesystem uses 12 bit fats. Microsoft Programmer's 702893Sdfr * Reference says if the maximum cluster number in a filesystem is greater 7133548Sjkh * than 4078 ((CLUST_RSRVS - CLUST_FIRST) & FAT12_MASK) then we've got a 7233548Sjkh * 16 bit fat filesystem. While mounting, the result of this test is stored 7333548Sjkh * in pm_fatentrysize. 742893Sdfr */ 7533548Sjkh#define FAT12(pmp) (pmp->pm_fatmask == FAT12_MASK) 7633548Sjkh#define FAT16(pmp) (pmp->pm_fatmask == FAT16_MASK) 7733548Sjkh#define FAT32(pmp) (pmp->pm_fatmask == FAT32_MASK) 782893Sdfr 7933548Sjkh#define MSDOSFSEOF(pmp, cn) ((((cn) | ~(pmp)->pm_fatmask) & CLUST_EOFS) == CLUST_EOFS) 802893Sdfr 8155206Speter#ifdef _KERNEL 822893Sdfr/* 832893Sdfr * These are the values for the function argument to the function 842893Sdfr * fatentry(). 852893Sdfr */ 862893Sdfr#define FAT_GET 0x0001 /* get a fat entry */ 872893Sdfr#define FAT_SET 0x0002 /* set a fat entry */ 882893Sdfr#define FAT_GET_AND_SET (FAT_GET | FAT_SET) 892893Sdfr 902893Sdfr/* 912893Sdfr * Flags to extendfile: 922893Sdfr */ 932893Sdfr#define DE_CLEAR 1 /* Zero out the blocks allocated */ 942893Sdfr 9592727Salfredint pcbmap(struct denode *dep, u_long findcn, daddr_t *bnp, u_long *cnp, int* sp); 9692727Salfredint clusterfree(struct msdosfsmount *pmp, u_long cn, u_long *oldcnp); 9792727Salfredint clusteralloc(struct msdosfsmount *pmp, u_long start, u_long count, u_long fillwith, u_long *retcluster, u_long *got); 9892727Salfredint fatentry(int function, struct msdosfsmount *pmp, u_long cluster, u_long *oldcontents, u_long newcontents); 9992727Salfredint freeclusterchain(struct msdosfsmount *pmp, u_long startchain); 10092727Salfredint extendfile(struct denode *dep, u_long count, struct buf **bpp, u_long *ncp, int flags); 10192727Salfredvoid fc_purge(struct denode *dep, u_int frcn); 102123873Strhodesint markvoldirty(struct msdosfsmount *pmp, int dirty); 1033152Sphk 10455206Speter#endif /* _KERNEL */ 105