xref: /freebsd/sys/fs/msdosfs/fat.h (revision 27a0bc89a433a500c7c8befb01ac54596858cdad)
127a0bc89SDoug Rabson /*	$Id$ */
227a0bc89SDoug Rabson /*	$NetBSD: fat.h,v 1.4 1994/08/21 18:43:57 ws Exp $	*/
327a0bc89SDoug Rabson 
427a0bc89SDoug Rabson /*-
527a0bc89SDoug Rabson  * Copyright (C) 1994 Wolfgang Solfrank.
627a0bc89SDoug Rabson  * Copyright (C) 1994 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 */
5827a0bc89SDoug Rabson #define	CLUST_RSRVS	0xfff0	/* start of reserved cluster range */
5927a0bc89SDoug Rabson #define	CLUST_RSRVE	0xfff6	/* end of reserved cluster range */
6027a0bc89SDoug Rabson #define	CLUST_BAD	0xfff7	/* a cluster with a defect */
6127a0bc89SDoug Rabson #define	CLUST_EOFS	0xfff8	/* start of eof cluster range */
6227a0bc89SDoug Rabson #define	CLUST_EOFE	0xffff	/* end of eof cluster range */
6327a0bc89SDoug Rabson 
6427a0bc89SDoug Rabson #define	FAT12_MASK	0x0fff	/* mask for 12 bit cluster numbers */
6527a0bc89SDoug Rabson #define	FAT16_MASK	0xffff	/* mask for 16 bit cluster numbers */
6627a0bc89SDoug Rabson 
6727a0bc89SDoug Rabson /*
6827a0bc89SDoug Rabson  * Return true if filesystem uses 12 bit fats. Microsoft Programmer's
6927a0bc89SDoug Rabson  * Reference says if the maximum cluster number in a filesystem is greater
7027a0bc89SDoug Rabson  * than 4086 then we've got a 16 bit fat filesystem.
7127a0bc89SDoug Rabson  */
7227a0bc89SDoug Rabson #define	FAT12(pmp)	(pmp->pm_maxcluster <= 4086)
7327a0bc89SDoug Rabson #define	FAT16(pmp)	(pmp->pm_maxcluster >  4086)
7427a0bc89SDoug Rabson 
7527a0bc89SDoug Rabson #define	MSDOSFSEOF(cn)	(((cn) & 0xfff8) == 0xfff8)
7627a0bc89SDoug Rabson 
7727a0bc89SDoug Rabson #ifdef KERNEL
7827a0bc89SDoug Rabson /*
7927a0bc89SDoug Rabson  * These are the values for the function argument to the function
8027a0bc89SDoug Rabson  * fatentry().
8127a0bc89SDoug Rabson  */
8227a0bc89SDoug Rabson #define	FAT_GET		0x0001	/* get a fat entry */
8327a0bc89SDoug Rabson #define	FAT_SET		0x0002	/* set a fat entry */
8427a0bc89SDoug Rabson #define	FAT_GET_AND_SET	(FAT_GET | FAT_SET)
8527a0bc89SDoug Rabson 
8627a0bc89SDoug Rabson /*
8727a0bc89SDoug Rabson  * Flags to extendfile:
8827a0bc89SDoug Rabson  */
8927a0bc89SDoug Rabson #define	DE_CLEAR	1	/* Zero out the blocks allocated */
9027a0bc89SDoug Rabson 
9127a0bc89SDoug Rabson int pcbmap __P((struct denode *dep, u_long findcn, daddr_t *bnp, u_long *cnp));
9227a0bc89SDoug Rabson int clusterfree __P((struct msdosfsmount *pmp, u_long cn, u_long *oldcnp));
9327a0bc89SDoug Rabson int clusteralloc __P((struct msdosfsmount *pmp, u_long start, u_long count, u_long fillwith, u_long *retcluster, u_long *got));
9427a0bc89SDoug Rabson int fatentry __P((int function, struct msdosfsmount *pmp, u_long cluster, u_long *oldcontents, u_long newcontents));
9527a0bc89SDoug Rabson int freeclusterchain __P((struct msdosfsmount *pmp, u_long startchain));
9627a0bc89SDoug Rabson int extendfile __P((struct denode *dep, u_long count, struct buf **bpp, u_long *ncp, int flags));
9727a0bc89SDoug Rabson #endif	/* KERNEL */
98