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