1 /* $FreeBSD: src/sys/msdosfs/fat.h,v 1.9 1999/12/29 04:54:53 peter Exp $ */ 2 /* $DragonFly: src/sys/vfs/msdosfs/fat.h,v 1.3 2003/08/20 09:56:32 rob Exp $ */ 3 /* $NetBSD: fat.h,v 1.12 1997/11/17 15:36:36 ws Exp $ */ 4 5 /*- 6 * Copyright (C) 1994, 1997 Wolfgang Solfrank. 7 * Copyright (C) 1994, 1997 TooLs GmbH. 8 * All rights reserved. 9 * Original code by Paul Popelka (paulp@uts.amdahl.com) (see below). 10 * 11 * Redistribution and use in source and binary forms, with or without 12 * modification, are permitted provided that the following conditions 13 * are met: 14 * 1. Redistributions of source code must retain the above copyright 15 * notice, this list of conditions and the following disclaimer. 16 * 2. Redistributions in binary form must reproduce the above copyright 17 * notice, this list of conditions and the following disclaimer in the 18 * documentation and/or other materials provided with the distribution. 19 * 3. All advertising materials mentioning features or use of this software 20 * must display the following acknowledgement: 21 * This product includes software developed by TooLs GmbH. 22 * 4. The name of TooLs GmbH may not be used to endorse or promote products 23 * derived from this software without specific prior written permission. 24 * 25 * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR 26 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 27 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 28 * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 29 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 30 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 31 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 32 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 33 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 34 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 35 */ 36 /* 37 * Written by Paul Popelka (paulp@uts.amdahl.com) 38 * 39 * You can do anything you want with this software, just don't say you wrote 40 * it, and don't remove this notice. 41 * 42 * This software is provided "as is". 43 * 44 * The author supplies this software to be publicly redistributed on the 45 * understanding that the author is not responsible for the correct 46 * functioning of this software in any circumstances and is not liable for 47 * any damages caused by this software. 48 * 49 * October 1992 50 */ 51 52 /* 53 * Some useful cluster numbers. 54 */ 55 #define MSDOSFSROOT 0 /* cluster 0 means the root dir */ 56 #define CLUST_FREE 0 /* cluster 0 also means a free cluster */ 57 #define MSDOSFSFREE CLUST_FREE 58 #define CLUST_FIRST 2 /* first legal cluster number */ 59 #define CLUST_RSRVD 0xfffffff6 /* reserved cluster range */ 60 #define CLUST_BAD 0xfffffff7 /* a cluster with a defect */ 61 #define CLUST_EOFS 0xfffffff8 /* start of eof cluster range */ 62 #define CLUST_EOFE 0xffffffff /* end of eof cluster range */ 63 64 #define FAT12_MASK 0x00000fff /* mask for 12 bit cluster numbers */ 65 #define FAT16_MASK 0x0000ffff /* mask for 16 bit cluster numbers */ 66 #define FAT32_MASK 0x0fffffff /* mask for FAT32 cluster numbers */ 67 68 /* 69 * MSDOSFS: 70 * Return true if filesystem uses 12 bit fats. Microsoft Programmer's 71 * Reference says if the maximum cluster number in a filesystem is greater 72 * than 4078 ((CLUST_RSRVS - CLUST_FIRST) & FAT12_MASK) then we've got a 73 * 16 bit fat filesystem. While mounting, the result of this test is stored 74 * in pm_fatentrysize. 75 * GEMDOS-flavour (atari): 76 * If the filesystem is on floppy we've got a 12 bit fat filesystem, otherwise 77 * 16 bit. We check the d_type field in the disklabel struct while mounting 78 * and store the result in the pm_fatentrysize. Note that this kind of 79 * detection gets flakey when mounting a vnd-device. 80 */ 81 #define FAT12(pmp) (pmp->pm_fatmask == FAT12_MASK) 82 #define FAT16(pmp) (pmp->pm_fatmask == FAT16_MASK) 83 #define FAT32(pmp) (pmp->pm_fatmask == FAT32_MASK) 84 85 #define MSDOSFSEOF(pmp, cn) \ 86 ((((cn) | ~(pmp)->pm_fatmask) & CLUST_EOFS) == CLUST_EOFS) 87 88 #ifdef _KERNEL 89 /* 90 * These are the values for the function argument to the function 91 * fatentry(). 92 */ 93 #define FAT_GET 0x0001 /* get a fat entry */ 94 #define FAT_SET 0x0002 /* set a fat entry */ 95 #define FAT_GET_AND_SET (FAT_GET | FAT_SET) 96 97 /* 98 * Flags to extendfile: 99 */ 100 #define DE_CLEAR 1 /* Zero out the blocks allocated */ 101 102 int pcbmap(struct denode *dep, u_long findcn, daddr_t *bnp, u_long *cnp, 103 int *sp); 104 int clusterfree(struct msdosfsmount *pmp, u_long cn, u_long *oldcnp); 105 int clusteralloc(struct msdosfsmount *pmp, u_long start, u_long count, 106 u_long fillwith, u_long *retcluster, u_long *got); 107 int fatentry(int function, struct msdosfsmount *pmp, u_long cluster, 108 u_long *oldcontents, u_long newcontents); 109 int freeclusterchain(struct msdosfsmount *pmp, u_long startchain); 110 int extendfile(struct denode *dep, u_long count, struct buf **bpp, u_long *ncp, 111 int flags); 112 void fc_purge(struct denode *dep, u_int frcn); 113 114 #endif /* _KERNEL */ 115