1c3aac50fSPeter Wemm /* $FreeBSD$ */ 2952a6212SJordan K. Hubbard /* $NetBSD: fat.h,v 1.12 1997/11/17 15:36:36 ws Exp $ */ 327a0bc89SDoug Rabson 427a0bc89SDoug Rabson /*- 5952a6212SJordan K. Hubbard * Copyright (C) 1994, 1997 Wolfgang Solfrank. 6952a6212SJordan K. Hubbard * Copyright (C) 1994, 1997 TooLs GmbH. 727a0bc89SDoug Rabson * All rights reserved. 827a0bc89SDoug Rabson * Original code by Paul Popelka (paulp@uts.amdahl.com) (see below). 927a0bc89SDoug Rabson * 1027a0bc89SDoug Rabson * Redistribution and use in source and binary forms, with or without 1127a0bc89SDoug Rabson * modification, are permitted provided that the following conditions 1227a0bc89SDoug Rabson * are met: 1327a0bc89SDoug Rabson * 1. Redistributions of source code must retain the above copyright 1427a0bc89SDoug Rabson * notice, this list of conditions and the following disclaimer. 1527a0bc89SDoug Rabson * 2. Redistributions in binary form must reproduce the above copyright 1627a0bc89SDoug Rabson * notice, this list of conditions and the following disclaimer in the 1727a0bc89SDoug Rabson * documentation and/or other materials provided with the distribution. 1827a0bc89SDoug Rabson * 3. All advertising materials mentioning features or use of this software 1927a0bc89SDoug Rabson * must display the following acknowledgement: 2027a0bc89SDoug Rabson * This product includes software developed by TooLs GmbH. 2127a0bc89SDoug Rabson * 4. The name of TooLs GmbH may not be used to endorse or promote products 2227a0bc89SDoug Rabson * derived from this software without specific prior written permission. 2327a0bc89SDoug Rabson * 2427a0bc89SDoug Rabson * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR 2527a0bc89SDoug Rabson * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 2627a0bc89SDoug Rabson * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 2727a0bc89SDoug Rabson * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 2827a0bc89SDoug Rabson * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 2927a0bc89SDoug Rabson * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 3027a0bc89SDoug Rabson * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 3127a0bc89SDoug Rabson * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 3227a0bc89SDoug Rabson * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 3327a0bc89SDoug Rabson * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 3427a0bc89SDoug Rabson */ 35d167cf6fSWarner Losh /*- 3627a0bc89SDoug Rabson * Written by Paul Popelka (paulp@uts.amdahl.com) 3727a0bc89SDoug Rabson * 3827a0bc89SDoug Rabson * You can do anything you want with this software, just don't say you wrote 3927a0bc89SDoug Rabson * it, and don't remove this notice. 4027a0bc89SDoug Rabson * 4127a0bc89SDoug Rabson * This software is provided "as is". 4227a0bc89SDoug Rabson * 4327a0bc89SDoug Rabson * The author supplies this software to be publicly redistributed on the 4427a0bc89SDoug Rabson * understanding that the author is not responsible for the correct 4527a0bc89SDoug Rabson * functioning of this software in any circumstances and is not liable for 4627a0bc89SDoug Rabson * any damages caused by this software. 4727a0bc89SDoug Rabson * 4827a0bc89SDoug Rabson * October 1992 4927a0bc89SDoug Rabson */ 5027a0bc89SDoug Rabson 5127a0bc89SDoug Rabson /* 5227a0bc89SDoug Rabson * Some useful cluster numbers. 5327a0bc89SDoug Rabson */ 5427a0bc89SDoug Rabson #define MSDOSFSROOT 0 /* cluster 0 means the root dir */ 5527a0bc89SDoug Rabson #define CLUST_FREE 0 /* cluster 0 also means a free cluster */ 5627a0bc89SDoug Rabson #define MSDOSFSFREE CLUST_FREE 5727a0bc89SDoug Rabson #define CLUST_FIRST 2 /* first legal cluster number */ 58952a6212SJordan K. Hubbard #define CLUST_RSRVD 0xfffffff6 /* reserved cluster range */ 59952a6212SJordan K. Hubbard #define CLUST_BAD 0xfffffff7 /* a cluster with a defect */ 60952a6212SJordan K. Hubbard #define CLUST_EOFS 0xfffffff8 /* start of eof cluster range */ 61952a6212SJordan K. Hubbard #define CLUST_EOFE 0xffffffff /* end of eof cluster range */ 6227a0bc89SDoug Rabson 63952a6212SJordan K. Hubbard #define FAT12_MASK 0x00000fff /* mask for 12 bit cluster numbers */ 64952a6212SJordan K. Hubbard #define FAT16_MASK 0x0000ffff /* mask for 16 bit cluster numbers */ 65952a6212SJordan K. Hubbard #define FAT32_MASK 0x0fffffff /* mask for FAT32 cluster numbers */ 6627a0bc89SDoug Rabson 6727a0bc89SDoug Rabson /* 68952a6212SJordan K. Hubbard * MSDOSFS: 69*9287dbaaSEd Maste * Return true if filesystem uses 12 bit FATs. Microsoft Programmer's 7027a0bc89SDoug Rabson * Reference says if the maximum cluster number in a filesystem is greater 71952a6212SJordan K. Hubbard * than 4078 ((CLUST_RSRVS - CLUST_FIRST) & FAT12_MASK) then we've got a 72*9287dbaaSEd Maste * 16 bit FAT filesystem. While mounting, the result of this test is stored 73952a6212SJordan K. Hubbard * in pm_fatentrysize. 7427a0bc89SDoug Rabson */ 75952a6212SJordan K. Hubbard #define FAT12(pmp) (pmp->pm_fatmask == FAT12_MASK) 76952a6212SJordan K. Hubbard #define FAT16(pmp) (pmp->pm_fatmask == FAT16_MASK) 77952a6212SJordan K. Hubbard #define FAT32(pmp) (pmp->pm_fatmask == FAT32_MASK) 7827a0bc89SDoug Rabson 79952a6212SJordan K. Hubbard #define MSDOSFSEOF(pmp, cn) ((((cn) | ~(pmp)->pm_fatmask) & CLUST_EOFS) == CLUST_EOFS) 8027a0bc89SDoug Rabson 81c4473420SPeter Wemm #ifdef _KERNEL 8227a0bc89SDoug Rabson /* 8327a0bc89SDoug Rabson * These are the values for the function argument to the function 8427a0bc89SDoug Rabson * fatentry(). 8527a0bc89SDoug Rabson */ 86*9287dbaaSEd Maste #define FAT_GET 0x0001 /* get a FAT entry */ 87*9287dbaaSEd Maste #define FAT_SET 0x0002 /* set a FAT entry */ 8827a0bc89SDoug Rabson #define FAT_GET_AND_SET (FAT_GET | FAT_SET) 8927a0bc89SDoug Rabson 9027a0bc89SDoug Rabson /* 9127a0bc89SDoug Rabson * Flags to extendfile: 9227a0bc89SDoug Rabson */ 9327a0bc89SDoug Rabson #define DE_CLEAR 1 /* Zero out the blocks allocated */ 9427a0bc89SDoug Rabson 9511caded3SAlfred Perlstein int pcbmap(struct denode *dep, u_long findcn, daddr_t *bnp, u_long *cnp, int* sp); 9611caded3SAlfred Perlstein int clusterfree(struct msdosfsmount *pmp, u_long cn, u_long *oldcnp); 9711caded3SAlfred Perlstein int clusteralloc(struct msdosfsmount *pmp, u_long start, u_long count, u_long fillwith, u_long *retcluster, u_long *got); 9811caded3SAlfred Perlstein int fatentry(int function, struct msdosfsmount *pmp, u_long cluster, u_long *oldcontents, u_long newcontents); 9911caded3SAlfred Perlstein int freeclusterchain(struct msdosfsmount *pmp, u_long startchain); 10011caded3SAlfred Perlstein int extendfile(struct denode *dep, u_long count, struct buf **bpp, u_long *ncp, int flags); 10111caded3SAlfred Perlstein void fc_purge(struct denode *dep, u_int frcn); 102cede1f56STom Rhodes int markvoldirty(struct msdosfsmount *pmp, int dirty); 103c3c6d51eSPoul-Henning Kamp 104c4473420SPeter Wemm #endif /* _KERNEL */ 105