xref: /freebsd/sys/fs/msdosfs/fat.h (revision 8e6b01171e30297084bb0b4457c4183c2746aacc)
1 /*	$Id: fat.h,v 1.2 1994/09/27 20:42:41 phk Exp $ */
2 /*	$NetBSD: fat.h,v 1.4 1994/08/21 18:43:57 ws Exp $	*/
3 
4 /*-
5  * Copyright (C) 1994 Wolfgang Solfrank.
6  * Copyright (C) 1994 TooLs GmbH.
7  * All rights reserved.
8  * Original code by Paul Popelka (paulp@uts.amdahl.com) (see below).
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  * 1. Redistributions of source code must retain the above copyright
14  *    notice, this list of conditions and the following disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright
16  *    notice, this list of conditions and the following disclaimer in the
17  *    documentation and/or other materials provided with the distribution.
18  * 3. All advertising materials mentioning features or use of this software
19  *    must display the following acknowledgement:
20  *	This product includes software developed by TooLs GmbH.
21  * 4. The name of TooLs GmbH may not be used to endorse or promote products
22  *    derived from this software without specific prior written permission.
23  *
24  * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR
25  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
26  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
27  * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
29  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
30  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
31  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
32  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
33  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34  */
35 /*
36  * Written by Paul Popelka (paulp@uts.amdahl.com)
37  *
38  * You can do anything you want with this software, just don't say you wrote
39  * it, and don't remove this notice.
40  *
41  * This software is provided "as is".
42  *
43  * The author supplies this software to be publicly redistributed on the
44  * understanding that the author is not responsible for the correct
45  * functioning of this software in any circumstances and is not liable for
46  * any damages caused by this software.
47  *
48  * October 1992
49  */
50 
51 /*
52  * Some useful cluster numbers.
53  */
54 #define	MSDOSFSROOT	0	/* cluster 0 means the root dir */
55 #define	CLUST_FREE	0	/* cluster 0 also means a free cluster */
56 #define	MSDOSFSFREE	CLUST_FREE
57 #define	CLUST_FIRST	2	/* first legal cluster number */
58 #define	CLUST_RSRVS	0xfff0	/* start of reserved cluster range */
59 #define	CLUST_RSRVE	0xfff6	/* end of reserved cluster range */
60 #define	CLUST_BAD	0xfff7	/* a cluster with a defect */
61 #define	CLUST_EOFS	0xfff8	/* start of eof cluster range */
62 #define	CLUST_EOFE	0xffff	/* end of eof cluster range */
63 
64 #define	FAT12_MASK	0x0fff	/* mask for 12 bit cluster numbers */
65 #define	FAT16_MASK	0xffff	/* mask for 16 bit cluster numbers */
66 
67 /*
68  * Return true if filesystem uses 12 bit fats. Microsoft Programmer's
69  * Reference says if the maximum cluster number in a filesystem is greater
70  * than 4086 then we've got a 16 bit fat filesystem.
71  */
72 #define	FAT12(pmp)	(pmp->pm_maxcluster <= 4086)
73 #define	FAT16(pmp)	(pmp->pm_maxcluster >  4086)
74 
75 #define	MSDOSFSEOF(cn)	(((cn) & 0xfff8) == 0xfff8)
76 
77 #ifdef KERNEL
78 /*
79  * These are the values for the function argument to the function
80  * fatentry().
81  */
82 #define	FAT_GET		0x0001	/* get a fat entry */
83 #define	FAT_SET		0x0002	/* set a fat entry */
84 #define	FAT_GET_AND_SET	(FAT_GET | FAT_SET)
85 
86 /*
87  * Flags to extendfile:
88  */
89 #define	DE_CLEAR	1	/* Zero out the blocks allocated */
90 
91 int pcbmap __P((struct denode *dep, u_long findcn, daddr_t *bnp, u_long *cnp));
92 int clusterfree __P((struct msdosfsmount *pmp, u_long cn, u_long *oldcnp));
93 int clusteralloc __P((struct msdosfsmount *pmp, u_long start, u_long count, u_long fillwith, u_long *retcluster, u_long *got));
94 int fatentry __P((int function, struct msdosfsmount *pmp, u_long cluster, u_long *oldcontents, u_long newcontents));
95 int freeclusterchain __P((struct msdosfsmount *pmp, u_long startchain));
96 int extendfile __P((struct denode *dep, u_long count, struct buf **bpp, u_long *ncp, int flags));
97 void fc_purge __P((struct denode *dep, u_int frcn));
98 void fc_lookup __P((struct denode *dep, u_long findcn, u_long *frcnp, u_long *fsrcnp));
99 
100 int readep __P((struct msdosfsmount *pmp, u_long dirclu, u_long dirofs,  struct buf **bpp, struct direntry **epp));
101 int readde __P((struct denode *dep, struct buf **bpp, struct direntry **epp));
102 int deextend __P((struct denode *dep, off_t length, struct ucred *cred));
103 int fillinusemap __P((struct msdosfsmount *pmp));
104 int reinsert __P((struct denode *dep));
105 int dosdirempty __P((struct denode *dep));
106 int createde __P((struct denode *dep, struct denode *ddep, struct denode **depp));
107 int deupdat __P((struct denode *dep, struct timespec *tp, int waitfor));
108 int removede __P((struct denode *pdep, struct denode *dep));
109 int detrunc __P((struct denode *dep, u_long length, int flags, struct ucred *cred, struct proc *p));
110 int doscheckpath __P(( struct denode *source, struct denode *target));
111 #endif	/* KERNEL */
112