xref: /freebsd/sys/fs/msdosfs/fat.h (revision aaa3852435aee8c1b5abfe38ed7d43f9ba57e6dd)
1c3aac50fSPeter Wemm /* $FreeBSD$ */
2952a6212SJordan K. Hubbard /*	$NetBSD: fat.h,v 1.12 1997/11/17 15:36:36 ws Exp $	*/
327a0bc89SDoug Rabson 
427a0bc89SDoug Rabson /*-
5d63027b6SPedro F. Giffuni  * SPDX-License-Identifier: BSD-4-Clause
6d63027b6SPedro F. Giffuni  *
7952a6212SJordan K. Hubbard  * Copyright (C) 1994, 1997 Wolfgang Solfrank.
8952a6212SJordan K. Hubbard  * Copyright (C) 1994, 1997 TooLs GmbH.
927a0bc89SDoug Rabson  * All rights reserved.
1027a0bc89SDoug Rabson  * Original code by Paul Popelka (paulp@uts.amdahl.com) (see below).
1127a0bc89SDoug Rabson  *
1227a0bc89SDoug Rabson  * Redistribution and use in source and binary forms, with or without
1327a0bc89SDoug Rabson  * modification, are permitted provided that the following conditions
1427a0bc89SDoug Rabson  * are met:
1527a0bc89SDoug Rabson  * 1. Redistributions of source code must retain the above copyright
1627a0bc89SDoug Rabson  *    notice, this list of conditions and the following disclaimer.
1727a0bc89SDoug Rabson  * 2. Redistributions in binary form must reproduce the above copyright
1827a0bc89SDoug Rabson  *    notice, this list of conditions and the following disclaimer in the
1927a0bc89SDoug Rabson  *    documentation and/or other materials provided with the distribution.
2027a0bc89SDoug Rabson  * 3. All advertising materials mentioning features or use of this software
2127a0bc89SDoug Rabson  *    must display the following acknowledgement:
2227a0bc89SDoug Rabson  *	This product includes software developed by TooLs GmbH.
2327a0bc89SDoug Rabson  * 4. The name of TooLs GmbH may not be used to endorse or promote products
2427a0bc89SDoug Rabson  *    derived from this software without specific prior written permission.
2527a0bc89SDoug Rabson  *
2627a0bc89SDoug Rabson  * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR
2727a0bc89SDoug Rabson  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
2827a0bc89SDoug Rabson  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
2927a0bc89SDoug Rabson  * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
3027a0bc89SDoug Rabson  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
3127a0bc89SDoug Rabson  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
3227a0bc89SDoug Rabson  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
3327a0bc89SDoug Rabson  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
3427a0bc89SDoug Rabson  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
3527a0bc89SDoug Rabson  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3627a0bc89SDoug Rabson  */
37d167cf6fSWarner Losh /*-
3827a0bc89SDoug Rabson  * Written by Paul Popelka (paulp@uts.amdahl.com)
3927a0bc89SDoug Rabson  *
4027a0bc89SDoug Rabson  * You can do anything you want with this software, just don't say you wrote
4127a0bc89SDoug Rabson  * it, and don't remove this notice.
4227a0bc89SDoug Rabson  *
4327a0bc89SDoug Rabson  * This software is provided "as is".
4427a0bc89SDoug Rabson  *
4527a0bc89SDoug Rabson  * The author supplies this software to be publicly redistributed on the
4627a0bc89SDoug Rabson  * understanding that the author is not responsible for the correct
4727a0bc89SDoug Rabson  * functioning of this software in any circumstances and is not liable for
4827a0bc89SDoug Rabson  * any damages caused by this software.
4927a0bc89SDoug Rabson  *
5027a0bc89SDoug Rabson  * October 1992
5127a0bc89SDoug Rabson  */
5227a0bc89SDoug Rabson 
53db20c27dSEd Maste #ifndef _FS_MSDOSFS_FAT_H_
54db20c27dSEd Maste #define	_FS_MSDOSFS_FAT_H_
5527a0bc89SDoug Rabson /*
5627a0bc89SDoug Rabson  * Some useful cluster numbers.
5727a0bc89SDoug Rabson  */
5827a0bc89SDoug Rabson #define	MSDOSFSROOT	0		/* cluster 0 means the root dir */
5927a0bc89SDoug Rabson #define	CLUST_FREE	0		/* cluster 0 also means a free cluster */
6027a0bc89SDoug Rabson #define	MSDOSFSFREE	CLUST_FREE
6127a0bc89SDoug Rabson #define	CLUST_FIRST	2		/* first legal cluster number */
62952a6212SJordan K. Hubbard #define	CLUST_RSRVD	0xfffffff6	/* reserved cluster range */
63952a6212SJordan K. Hubbard #define	CLUST_BAD	0xfffffff7	/* a cluster with a defect */
64952a6212SJordan K. Hubbard #define	CLUST_EOFS	0xfffffff8	/* start of eof cluster range */
65952a6212SJordan K. Hubbard #define	CLUST_EOFE	0xffffffff	/* end of eof cluster range */
6627a0bc89SDoug Rabson 
67952a6212SJordan K. Hubbard #define	FAT12_MASK	0x00000fff	/* mask for 12 bit cluster numbers */
68952a6212SJordan K. Hubbard #define	FAT16_MASK	0x0000ffff	/* mask for 16 bit cluster numbers */
69952a6212SJordan K. Hubbard #define	FAT32_MASK	0x0fffffff	/* mask for FAT32 cluster numbers */
7027a0bc89SDoug Rabson 
7127a0bc89SDoug Rabson /*
72952a6212SJordan K. Hubbard  * MSDOSFS:
739287dbaaSEd Maste  * Return true if filesystem uses 12 bit FATs. Microsoft Programmer's
7427a0bc89SDoug Rabson  * Reference says if the maximum cluster number in a filesystem is greater
75c8b163b6SEd Maste  * than 4084 ((CLUST_RSRVD - CLUST_FIRST) & FAT12_MASK) then we've got a
769287dbaaSEd Maste  * 16 bit FAT filesystem. While mounting, the result of this test is stored
77952a6212SJordan K. Hubbard  * in pm_fatentrysize.
7827a0bc89SDoug Rabson  */
79952a6212SJordan K. Hubbard #define	FAT12(pmp)	(pmp->pm_fatmask == FAT12_MASK)
80952a6212SJordan K. Hubbard #define	FAT16(pmp)	(pmp->pm_fatmask == FAT16_MASK)
81952a6212SJordan K. Hubbard #define	FAT32(pmp)	(pmp->pm_fatmask == FAT32_MASK)
8227a0bc89SDoug Rabson 
83952a6212SJordan K. Hubbard #define	MSDOSFSEOF(pmp, cn)	((((cn) | ~(pmp)->pm_fatmask) & CLUST_EOFS) == CLUST_EOFS)
8427a0bc89SDoug Rabson 
8551e79affSEd Maste #if defined (_KERNEL) || defined(MAKEFS)
8627a0bc89SDoug Rabson /*
8727a0bc89SDoug Rabson  * These are the values for the function argument to the function
8827a0bc89SDoug Rabson  * fatentry().
8927a0bc89SDoug Rabson  */
909287dbaaSEd Maste #define	FAT_GET		0x0001	/* get a FAT entry */
919287dbaaSEd Maste #define	FAT_SET		0x0002	/* set a FAT entry */
9227a0bc89SDoug Rabson #define	FAT_GET_AND_SET	(FAT_GET | FAT_SET)
9327a0bc89SDoug Rabson 
9427a0bc89SDoug Rabson /*
9527a0bc89SDoug Rabson  * Flags to extendfile:
9627a0bc89SDoug Rabson  */
9727a0bc89SDoug Rabson #define	DE_CLEAR	1	/* Zero out the blocks allocated */
9827a0bc89SDoug Rabson 
9911caded3SAlfred Perlstein int pcbmap(struct denode *dep, u_long findcn, daddr_t *bnp, u_long *cnp, int* sp);
10011caded3SAlfred Perlstein int clusterfree(struct msdosfsmount *pmp, u_long cn, u_long *oldcnp);
10111caded3SAlfred Perlstein int clusteralloc(struct msdosfsmount *pmp, u_long start, u_long count, u_long fillwith, u_long *retcluster, u_long *got);
10211caded3SAlfred Perlstein int fatentry(int function, struct msdosfsmount *pmp, u_long cluster, u_long *oldcontents, u_long newcontents);
10311caded3SAlfred Perlstein int freeclusterchain(struct msdosfsmount *pmp, u_long startchain);
10411caded3SAlfred Perlstein int extendfile(struct denode *dep, u_long count, struct buf **bpp, u_long *ncp, int flags);
10511caded3SAlfred Perlstein void fc_purge(struct denode *dep, u_int frcn);
106*aaa38524SConrad Meyer int markvoldirty_upgrade(struct msdosfsmount *pmp, bool dirty, bool rw_upgrade);
107*aaa38524SConrad Meyer 
108*aaa38524SConrad Meyer static inline int
109*aaa38524SConrad Meyer markvoldirty(struct msdosfsmount *pmp, bool dirty)
110*aaa38524SConrad Meyer {
111*aaa38524SConrad Meyer 	return (markvoldirty_upgrade(pmp, dirty, false));
112*aaa38524SConrad Meyer }
113c3c6d51eSPoul-Henning Kamp 
11451e79affSEd Maste #endif	/* _KERNEL || MAKEFS */
115db20c27dSEd Maste #endif	/* !_FS_MSDOSFS_FAT_H_ */
116