xref: /freebsd/sbin/fsck_msdosfs/dosfs.h (revision a0ee8cc6)
1 /*
2  * Copyright (C) 1995, 1996, 1997 Wolfgang Solfrank
3  * Copyright (c) 1995 Martin Husemann
4  * Some structure declaration borrowed from Paul Popelka
5  * (paulp@uts.amdahl.com), see /sys/msdosfs/ for reference.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
17  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19  * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT,
20  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  *	$NetBSD: dosfs.h,v 1.4 1997/01/03 14:32:48 ws Exp $
27  * $FreeBSD$
28  */
29 
30 #ifndef DOSFS_H
31 #define DOSFS_H
32 
33 /* support 4Kn disk reads */
34 #define DOSBOOTBLOCKSIZE_REAL 512
35 #define DOSBOOTBLOCKSIZE 4096
36 
37 typedef	u_int32_t	cl_t;	/* type holding a cluster number */
38 
39 /*
40  * architecture independent description of all the info stored in a
41  * FAT boot block.
42  */
43 struct bootblock {
44 	u_int	bpbBytesPerSec;		/* bytes per sector */
45 	u_int	bpbSecPerClust;		/* sectors per cluster */
46 	u_int	bpbResSectors;		/* number of reserved sectors */
47 	u_int	bpbFATs;		/* number of bpbFATs */
48 	u_int	bpbRootDirEnts;		/* number of root directory entries */
49 	u_int32_t bpbSectors;		/* total number of sectors */
50 	u_int	bpbMedia;		/* media descriptor */
51 	u_int	bpbFATsmall;		/* number of sectors per FAT */
52 	u_int	SecPerTrack;		/* sectors per track */
53 	u_int	bpbHeads;		/* number of heads */
54 	u_int32_t bpbHiddenSecs;	/* # of hidden sectors */
55 	u_int32_t bpbHugeSectors;	/* # of sectors if bpbbpbSectors == 0 */
56 	cl_t	bpbRootClust;		/* Start of Root Directory */
57 	u_int	bpbFSInfo;		/* FSInfo sector */
58 	u_int	bpbBackup;		/* Backup of Bootblocks */
59 	cl_t	FSFree;			/* Number of free clusters acc. FSInfo */
60 	cl_t	FSNext;			/* Next free cluster acc. FSInfo */
61 
62 	/* and some more calculated values */
63 	u_int	flags;			/* some flags: */
64 #define	FAT32		1		/* this is a FAT32 file system */
65 					/*
66 					 * Maybe, we should separate out
67 					 * various parts of FAT32?	XXX
68 					 */
69 	int	ValidFat;		/* valid fat if FAT32 non-mirrored */
70 	cl_t	ClustMask;		/* mask for entries in FAT */
71 	cl_t	NumClusters;		/* # of entries in a FAT */
72 	u_int32_t NumSectors;		/* how many sectors are there */
73 	u_int32_t FATsecs;		/* how many sectors are in FAT */
74 	u_int32_t NumFatEntries;	/* how many entries really are there */
75 	u_int	ClusterOffset;		/* at what sector would sector 0 start */
76 	u_int	ClusterSize;		/* Cluster size in bytes */
77 
78 	/* Now some statistics: */
79 	u_int	NumFiles;		/* # of plain files */
80 	u_int	NumFree;		/* # of free clusters */
81 	u_int	NumBad;			/* # of bad clusters */
82 };
83 
84 struct fatEntry {
85 	cl_t	next;			/* pointer to next cluster */
86 	cl_t	head;			/* pointer to start of chain */
87 	u_int32_t length;		/* number of clusters on chain */
88 	int	flags;			/* see below */
89 };
90 
91 #define	CLUST_FREE	0		/* 0 means cluster is free */
92 #define	CLUST_FIRST	2		/* 2 is the minimum valid cluster number */
93 #define	CLUST_RSRVD	0xfffffff6	/* start of reserved clusters */
94 #define	CLUST_BAD	0xfffffff7	/* a cluster with a defect */
95 #define	CLUST_EOFS	0xfffffff8	/* start of EOF indicators */
96 #define	CLUST_EOF	0xffffffff	/* standard value for last cluster */
97 
98 /*
99  * Masks for cluster values
100  */
101 #define	CLUST12_MASK	0xfff
102 #define	CLUST16_MASK	0xffff
103 #define	CLUST32_MASK	0xfffffff
104 
105 #define	FAT_USED	1		/* This fat chain is used in a file */
106 
107 #define	DOSLONGNAMELEN	256		/* long name maximal length */
108 #define LRFIRST		0x40		/* first long name record */
109 #define	LRNOMASK	0x1f		/* mask to extract long record
110 					 * sequence number */
111 
112 /*
113  * Architecture independent description of a directory entry
114  */
115 struct dosDirEntry {
116 	struct dosDirEntry
117 		*parent,		/* previous tree level */
118 		*next,			/* next brother */
119 		*child;			/* if this is a directory */
120 	char name[8+1+3+1];		/* alias name first part */
121 	char lname[DOSLONGNAMELEN];	/* real name */
122 	uint flags;			/* attributes */
123 	cl_t head;			/* cluster no */
124 	u_int32_t size;			/* filesize in bytes */
125 	uint fsckflags;			/* flags during fsck */
126 };
127 /* Flags in fsckflags: */
128 #define	DIREMPTY	1
129 #define	DIREMPWARN	2
130 
131 /*
132  *  TODO-list of unread directories
133  */
134 struct dirTodoNode {
135 	struct dosDirEntry *dir;
136 	struct dirTodoNode *next;
137 };
138 
139 #endif
140