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