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