1*0a6a1f1dSLionel Sambuc /* $NetBSD: fat.h,v 1.9 2014/10/18 08:33:28 snj Exp $ */ 284d9c625SLionel Sambuc 384d9c625SLionel Sambuc /*- 484d9c625SLionel Sambuc * Copyright (C) 1994, 1997 Wolfgang Solfrank. 584d9c625SLionel Sambuc * Copyright (C) 1994, 1997 TooLs GmbH. 684d9c625SLionel Sambuc * All rights reserved. 784d9c625SLionel Sambuc * Original code by Paul Popelka (paulp@uts.amdahl.com) (see below). 884d9c625SLionel Sambuc * 984d9c625SLionel Sambuc * Redistribution and use in source and binary forms, with or without 1084d9c625SLionel Sambuc * modification, are permitted provided that the following conditions 1184d9c625SLionel Sambuc * are met: 1284d9c625SLionel Sambuc * 1. Redistributions of source code must retain the above copyright 1384d9c625SLionel Sambuc * notice, this list of conditions and the following disclaimer. 1484d9c625SLionel Sambuc * 2. Redistributions in binary form must reproduce the above copyright 1584d9c625SLionel Sambuc * notice, this list of conditions and the following disclaimer in the 1684d9c625SLionel Sambuc * documentation and/or other materials provided with the distribution. 1784d9c625SLionel Sambuc * 3. All advertising materials mentioning features or use of this software 1884d9c625SLionel Sambuc * must display the following acknowledgement: 1984d9c625SLionel Sambuc * This product includes software developed by TooLs GmbH. 2084d9c625SLionel Sambuc * 4. The name of TooLs GmbH may not be used to endorse or promote products 2184d9c625SLionel Sambuc * derived from this software without specific prior written permission. 2284d9c625SLionel Sambuc * 2384d9c625SLionel Sambuc * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR 2484d9c625SLionel Sambuc * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 2584d9c625SLionel Sambuc * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 2684d9c625SLionel Sambuc * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 2784d9c625SLionel Sambuc * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 2884d9c625SLionel Sambuc * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 2984d9c625SLionel Sambuc * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 3084d9c625SLionel Sambuc * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 3184d9c625SLionel Sambuc * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 3284d9c625SLionel Sambuc * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 3384d9c625SLionel Sambuc */ 3484d9c625SLionel Sambuc /* 3584d9c625SLionel Sambuc * Written by Paul Popelka (paulp@uts.amdahl.com) 3684d9c625SLionel Sambuc * 3784d9c625SLionel Sambuc * You can do anything you want with this software, just don't say you wrote 3884d9c625SLionel Sambuc * it, and don't remove this notice. 3984d9c625SLionel Sambuc * 4084d9c625SLionel Sambuc * This software is provided "as is". 4184d9c625SLionel Sambuc * 4284d9c625SLionel Sambuc * The author supplies this software to be publicly redistributed on the 4384d9c625SLionel Sambuc * understanding that the author is not responsible for the correct 4484d9c625SLionel Sambuc * functioning of this software in any circumstances and is not liable for 4584d9c625SLionel Sambuc * any damages caused by this software. 4684d9c625SLionel Sambuc * 4784d9c625SLionel Sambuc * October 1992 4884d9c625SLionel Sambuc */ 4984d9c625SLionel Sambuc 5084d9c625SLionel Sambuc #ifndef _MSDOSFS_FAT_H_ 5184d9c625SLionel Sambuc #define _MSDOSFS_FAT_H_ 5284d9c625SLionel Sambuc /* 5384d9c625SLionel Sambuc * Some useful cluster numbers. 5484d9c625SLionel Sambuc */ 5584d9c625SLionel Sambuc #define MSDOSFSROOT 0 /* cluster 0 means the root dir */ 5684d9c625SLionel Sambuc #define CLUST_FREE 0 /* cluster 0 also means a free cluster */ 5784d9c625SLionel Sambuc #define MSDOSFSFREE CLUST_FREE 5884d9c625SLionel Sambuc #define CLUST_FIRST 2 /* first legal cluster number */ 5984d9c625SLionel Sambuc #define CLUST_RSRVD 0xfffffff6 /* reserved cluster range */ 6084d9c625SLionel Sambuc #define CLUST_BAD 0xfffffff7 /* a cluster with a defect */ 6184d9c625SLionel Sambuc #define CLUST_EOFS 0xfffffff8 /* start of eof cluster range */ 6284d9c625SLionel Sambuc #define CLUST_EOFE 0xffffffff /* end of eof cluster range */ 6384d9c625SLionel Sambuc #define CLUST_END CLUST_EOFE /* bigger than any valid cluster */ 6484d9c625SLionel Sambuc 6584d9c625SLionel Sambuc #define FAT12_MASK 0x00000fff /* mask for 12 bit cluster numbers */ 6684d9c625SLionel Sambuc #define FAT16_MASK 0x0000ffff /* mask for 16 bit cluster numbers */ 6784d9c625SLionel Sambuc #define FAT32_MASK 0x0fffffff /* mask for FAT32 cluster numbers */ 6884d9c625SLionel Sambuc 6984d9c625SLionel Sambuc /* 7084d9c625SLionel Sambuc * MSDOSFS: 7184d9c625SLionel Sambuc * Return true if filesystem uses 12 bit FATs. Microsoft Programmer's 7284d9c625SLionel Sambuc * Reference says if the maximum cluster number in a filesystem is greater 7384d9c625SLionel Sambuc * than 4084 ((CLUST_RSRVD - CLUST_FIRST) & FAT12_MASK) then we've got a 7484d9c625SLionel Sambuc * 16 bit FAT filesystem. While mounting, the result of this test is stored 7584d9c625SLionel Sambuc * in pm_fatentrysize. 7684d9c625SLionel Sambuc * GEMDOS-flavour (atari): 7784d9c625SLionel Sambuc * If the filesystem is on floppy we've got a 12 bit FAT filesystem, otherwise 7884d9c625SLionel Sambuc * 16 bit. We check the d_type field in the disklabel struct while mounting 7984d9c625SLionel Sambuc * and store the result in the pm_fatentrysize. Note that this kind of 8084d9c625SLionel Sambuc * detection gets flakey when mounting a vnd-device. 8184d9c625SLionel Sambuc */ 8284d9c625SLionel Sambuc #define FAT12(pmp) (pmp->pm_fatmask == FAT12_MASK) 8384d9c625SLionel Sambuc #define FAT16(pmp) (pmp->pm_fatmask == FAT16_MASK) 8484d9c625SLionel Sambuc #define FAT32(pmp) (pmp->pm_fatmask == FAT32_MASK) 8584d9c625SLionel Sambuc 8684d9c625SLionel Sambuc /* 87*0a6a1f1dSLionel Sambuc * M$ in its unlimited wisdom decided that EOF mark is anything 8884d9c625SLionel Sambuc * between 0xfffffff8 and 0xffffffff (masked by appropriate fatmask, 8984d9c625SLionel Sambuc * of course). 9084d9c625SLionel Sambuc * Note that cn is supposed to be already adjusted accordingly to FAT type. 9184d9c625SLionel Sambuc */ 9284d9c625SLionel Sambuc #define MSDOSFSEOF(cn, fatmask) \ 9384d9c625SLionel Sambuc (((cn) & CLUST_EOFS) == (CLUST_EOFS & (fatmask))) 9484d9c625SLionel Sambuc 9584d9c625SLionel Sambuc #if defined(_KERNEL) || defined(MAKEFS) 9684d9c625SLionel Sambuc /* 9784d9c625SLionel Sambuc * These are the values for the function argument to the function 9884d9c625SLionel Sambuc * fatentry(). 9984d9c625SLionel Sambuc */ 10084d9c625SLionel Sambuc #define FAT_GET 0x0001 /* get a FAT entry */ 10184d9c625SLionel Sambuc #define FAT_SET 0x0002 /* set a FAT entry */ 10284d9c625SLionel Sambuc #define FAT_GET_AND_SET (FAT_GET | FAT_SET) 10384d9c625SLionel Sambuc 10484d9c625SLionel Sambuc /* 10584d9c625SLionel Sambuc * Flags to extendfile: 10684d9c625SLionel Sambuc */ 10784d9c625SLionel Sambuc #define DE_CLEAR 1 /* Zero out the blocks allocated */ 10884d9c625SLionel Sambuc 10984d9c625SLionel Sambuc int pcbmap(struct denode *, u_long, daddr_t *, u_long *, int *); 11084d9c625SLionel Sambuc int clusterfree(struct msdosfsmount *, u_long, u_long *); 11184d9c625SLionel Sambuc int clusteralloc(struct msdosfsmount *, u_long, u_long,u_long *,u_long *); 11284d9c625SLionel Sambuc int extendfile(struct denode *, u_long, struct buf **, u_long *, int); 11384d9c625SLionel Sambuc int fatentry(int, struct msdosfsmount *, u_long, u_long *, u_long); 11484d9c625SLionel Sambuc void fc_purge(struct denode *, u_int); 11584d9c625SLionel Sambuc void fc_lookup(struct denode *, u_long, u_long *, u_long *); 11684d9c625SLionel Sambuc int fillinusemap(struct msdosfsmount *); 11784d9c625SLionel Sambuc int freeclusterchain(struct msdosfsmount *, u_long); 11884d9c625SLionel Sambuc #endif /* _KERNEL || MAKEFS */ 11984d9c625SLionel Sambuc #endif /* _MSDOSFS_FAT_H_ */ 120