1*8086f46eSthorpej /* $NetBSD: fat.h,v 1.10 2021/10/23 16:58:17 thorpej Exp $ */ 298d58548Sjdolecek 398d58548Sjdolecek /*- 498d58548Sjdolecek * Copyright (C) 1994, 1997 Wolfgang Solfrank. 598d58548Sjdolecek * Copyright (C) 1994, 1997 TooLs GmbH. 698d58548Sjdolecek * All rights reserved. 798d58548Sjdolecek * Original code by Paul Popelka (paulp@uts.amdahl.com) (see below). 898d58548Sjdolecek * 998d58548Sjdolecek * Redistribution and use in source and binary forms, with or without 1098d58548Sjdolecek * modification, are permitted provided that the following conditions 1198d58548Sjdolecek * are met: 1298d58548Sjdolecek * 1. Redistributions of source code must retain the above copyright 1398d58548Sjdolecek * notice, this list of conditions and the following disclaimer. 1498d58548Sjdolecek * 2. Redistributions in binary form must reproduce the above copyright 1598d58548Sjdolecek * notice, this list of conditions and the following disclaimer in the 1698d58548Sjdolecek * documentation and/or other materials provided with the distribution. 1798d58548Sjdolecek * 3. All advertising materials mentioning features or use of this software 1898d58548Sjdolecek * must display the following acknowledgement: 1998d58548Sjdolecek * This product includes software developed by TooLs GmbH. 2098d58548Sjdolecek * 4. The name of TooLs GmbH may not be used to endorse or promote products 2198d58548Sjdolecek * derived from this software without specific prior written permission. 2298d58548Sjdolecek * 2398d58548Sjdolecek * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR 2498d58548Sjdolecek * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 2598d58548Sjdolecek * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 2698d58548Sjdolecek * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 2798d58548Sjdolecek * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 2898d58548Sjdolecek * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 2998d58548Sjdolecek * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 3098d58548Sjdolecek * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 3198d58548Sjdolecek * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 3298d58548Sjdolecek * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 3398d58548Sjdolecek */ 3498d58548Sjdolecek /* 3598d58548Sjdolecek * Written by Paul Popelka (paulp@uts.amdahl.com) 3698d58548Sjdolecek * 3798d58548Sjdolecek * You can do anything you want with this software, just don't say you wrote 3898d58548Sjdolecek * it, and don't remove this notice. 3998d58548Sjdolecek * 4098d58548Sjdolecek * This software is provided "as is". 4198d58548Sjdolecek * 4298d58548Sjdolecek * The author supplies this software to be publicly redistributed on the 4398d58548Sjdolecek * understanding that the author is not responsible for the correct 4498d58548Sjdolecek * functioning of this software in any circumstances and is not liable for 4598d58548Sjdolecek * any damages caused by this software. 4698d58548Sjdolecek * 4798d58548Sjdolecek * October 1992 4898d58548Sjdolecek */ 4998d58548Sjdolecek 504bffed72Schristos #ifndef _MSDOSFS_FAT_H_ 514bffed72Schristos #define _MSDOSFS_FAT_H_ 5298d58548Sjdolecek /* 5398d58548Sjdolecek * Some useful cluster numbers. 5498d58548Sjdolecek */ 5598d58548Sjdolecek #define MSDOSFSROOT 0 /* cluster 0 means the root dir */ 5698d58548Sjdolecek #define CLUST_FREE 0 /* cluster 0 also means a free cluster */ 5798d58548Sjdolecek #define MSDOSFSFREE CLUST_FREE 5898d58548Sjdolecek #define CLUST_FIRST 2 /* first legal cluster number */ 5998d58548Sjdolecek #define CLUST_RSRVD 0xfffffff6 /* reserved cluster range */ 6098d58548Sjdolecek #define CLUST_BAD 0xfffffff7 /* a cluster with a defect */ 6198d58548Sjdolecek #define CLUST_EOFS 0xfffffff8 /* start of eof cluster range */ 6298d58548Sjdolecek #define CLUST_EOFE 0xffffffff /* end of eof cluster range */ 6398d58548Sjdolecek #define CLUST_END CLUST_EOFE /* bigger than any valid cluster */ 6498d58548Sjdolecek 6598d58548Sjdolecek #define FAT12_MASK 0x00000fff /* mask for 12 bit cluster numbers */ 6698d58548Sjdolecek #define FAT16_MASK 0x0000ffff /* mask for 16 bit cluster numbers */ 6798d58548Sjdolecek #define FAT32_MASK 0x0fffffff /* mask for FAT32 cluster numbers */ 6898d58548Sjdolecek 6998d58548Sjdolecek /* 7098d58548Sjdolecek * MSDOSFS: 7148958e52Sjakllsch * Return true if filesystem uses 12 bit FATs. Microsoft Programmer's 7298d58548Sjdolecek * Reference says if the maximum cluster number in a filesystem is greater 731203d986Sjakllsch * than 4084 ((CLUST_RSRVD - CLUST_FIRST) & FAT12_MASK) then we've got a 7448958e52Sjakllsch * 16 bit FAT filesystem. While mounting, the result of this test is stored 7598d58548Sjdolecek * in pm_fatentrysize. 7698d58548Sjdolecek * GEMDOS-flavour (atari): 7748958e52Sjakllsch * If the filesystem is on floppy we've got a 12 bit FAT filesystem, otherwise 7898d58548Sjdolecek * 16 bit. We check the d_type field in the disklabel struct while mounting 7998d58548Sjdolecek * and store the result in the pm_fatentrysize. Note that this kind of 8098d58548Sjdolecek * detection gets flakey when mounting a vnd-device. 8198d58548Sjdolecek */ 8298d58548Sjdolecek #define FAT12(pmp) (pmp->pm_fatmask == FAT12_MASK) 8398d58548Sjdolecek #define FAT16(pmp) (pmp->pm_fatmask == FAT16_MASK) 8498d58548Sjdolecek #define FAT32(pmp) (pmp->pm_fatmask == FAT32_MASK) 8598d58548Sjdolecek 8698d58548Sjdolecek /* 87f0a7346dSsnj * M$ in its unlimited wisdom decided that EOF mark is anything 8898d58548Sjdolecek * between 0xfffffff8 and 0xffffffff (masked by appropriate fatmask, 8998d58548Sjdolecek * of course). 9098d58548Sjdolecek * Note that cn is supposed to be already adjusted accordingly to FAT type. 9198d58548Sjdolecek */ 9298d58548Sjdolecek #define MSDOSFSEOF(cn, fatmask) \ 9398d58548Sjdolecek (((cn) & CLUST_EOFS) == (CLUST_EOFS & (fatmask))) 9498d58548Sjdolecek 95929f8943Schristos #if defined(_KERNEL) || defined(MAKEFS) 9698d58548Sjdolecek /* 9798d58548Sjdolecek * These are the values for the function argument to the function 9898d58548Sjdolecek * fatentry(). 9998d58548Sjdolecek */ 10048958e52Sjakllsch #define FAT_GET 0x0001 /* get a FAT entry */ 10148958e52Sjakllsch #define FAT_SET 0x0002 /* set a FAT entry */ 10298d58548Sjdolecek #define FAT_GET_AND_SET (FAT_GET | FAT_SET) 10398d58548Sjdolecek 10498d58548Sjdolecek /* 10598d58548Sjdolecek * Flags to extendfile: 10698d58548Sjdolecek */ 10798d58548Sjdolecek #define DE_CLEAR 1 /* Zero out the blocks allocated */ 10898d58548Sjdolecek 109*8086f46eSthorpej int msdosfs_pcbmap(struct denode *, u_long, daddr_t *, u_long *, int *); 110*8086f46eSthorpej int msdosfs_clusterfree(struct msdosfsmount *, u_long, u_long *); 111*8086f46eSthorpej int msdosfs_clusteralloc(struct msdosfsmount *, u_long, u_long, u_long *, 112*8086f46eSthorpej u_long *); 113*8086f46eSthorpej int msdosfs_extendfile(struct denode *, u_long, struct buf **, u_long *, 114*8086f46eSthorpej int); 115*8086f46eSthorpej int msdosfs_fatentry(int, struct msdosfsmount *, u_long, u_long *, u_long); 116*8086f46eSthorpej void msdosfs_fc_purge(struct denode *, u_int); 117*8086f46eSthorpej void msdosfs_fc_lookup(struct denode *, u_long, u_long *, u_long *); 118*8086f46eSthorpej int msdosfs_fillinusemap(struct msdosfsmount *); 119*8086f46eSthorpej int msdosfs_freeclusterchain(struct msdosfsmount *, u_long); 120929f8943Schristos #endif /* _KERNEL || MAKEFS */ 1214bffed72Schristos #endif /* _MSDOSFS_FAT_H_ */ 122