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