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