1952a6212SJordan K. Hubbard /* $Id: fat.h,v 1.6 1997/02/22 09:40:45 peter Exp $ */ 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 */ 3527a0bc89SDoug Rabson /* 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: 6927a0bc89SDoug Rabson * 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 72952a6212SJordan K. Hubbard * 16 bit fat filesystem. While mounting, the result of this test is stored 73952a6212SJordan K. Hubbard * in pm_fatentrysize. 74952a6212SJordan K. Hubbard * GEMDOS-flavour (atari): 75952a6212SJordan K. Hubbard * If the filesystem is on floppy we've got a 12 bit fat filesystem, otherwise 76952a6212SJordan K. Hubbard * 16 bit. We check the d_type field in the disklabel struct while mounting 77952a6212SJordan K. Hubbard * and store the result in the pm_fatentrysize. Note that this kind of 78952a6212SJordan K. Hubbard * detection gets flakey when mounting a vnd-device. 7927a0bc89SDoug Rabson */ 80952a6212SJordan K. Hubbard #define FAT12(pmp) (pmp->pm_fatmask == FAT12_MASK) 81952a6212SJordan K. Hubbard #define FAT16(pmp) (pmp->pm_fatmask == FAT16_MASK) 82952a6212SJordan K. Hubbard #define FAT32(pmp) (pmp->pm_fatmask == FAT32_MASK) 8327a0bc89SDoug Rabson 84952a6212SJordan K. Hubbard #define MSDOSFSEOF(pmp, cn) ((((cn) | ~(pmp)->pm_fatmask) & CLUST_EOFS) == CLUST_EOFS) 8527a0bc89SDoug Rabson 8627a0bc89SDoug Rabson #ifdef KERNEL 8727a0bc89SDoug Rabson /* 8827a0bc89SDoug Rabson * These are the values for the function argument to the function 8927a0bc89SDoug Rabson * fatentry(). 9027a0bc89SDoug Rabson */ 9127a0bc89SDoug Rabson #define FAT_GET 0x0001 /* get a fat entry */ 9227a0bc89SDoug Rabson #define FAT_SET 0x0002 /* set a fat entry */ 9327a0bc89SDoug Rabson #define FAT_GET_AND_SET (FAT_GET | FAT_SET) 9427a0bc89SDoug Rabson 9527a0bc89SDoug Rabson /* 9627a0bc89SDoug Rabson * Flags to extendfile: 9727a0bc89SDoug Rabson */ 9827a0bc89SDoug Rabson #define DE_CLEAR 1 /* Zero out the blocks allocated */ 9927a0bc89SDoug Rabson 100952a6212SJordan K. Hubbard int pcbmap __P((struct denode *dep, u_long findcn, daddr_t *bnp, u_long *cnp, int* sp)); 10127a0bc89SDoug Rabson int clusterfree __P((struct msdosfsmount *pmp, u_long cn, u_long *oldcnp)); 10227a0bc89SDoug Rabson int clusteralloc __P((struct msdosfsmount *pmp, u_long start, u_long count, u_long fillwith, u_long *retcluster, u_long *got)); 10327a0bc89SDoug Rabson int fatentry __P((int function, struct msdosfsmount *pmp, u_long cluster, u_long *oldcontents, u_long newcontents)); 10427a0bc89SDoug Rabson int freeclusterchain __P((struct msdosfsmount *pmp, u_long startchain)); 10527a0bc89SDoug Rabson int extendfile __P((struct denode *dep, u_long count, struct buf **bpp, u_long *ncp, int flags)); 106c3c6d51eSPoul-Henning Kamp void fc_purge __P((struct denode *dep, u_int frcn)); 107c3c6d51eSPoul-Henning Kamp 10827a0bc89SDoug Rabson #endif /* KERNEL */ 109