xref: /illumos-gate/usr/src/cmd/fs.d/pcfs/fsck/fsck_pcfs.h (revision 7c478bd9)
1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate  * CDDL HEADER START
3*7c478bd9Sstevel@tonic-gate  *
4*7c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*7c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*7c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*7c478bd9Sstevel@tonic-gate  * with the License.
8*7c478bd9Sstevel@tonic-gate  *
9*7c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*7c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*7c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*7c478bd9Sstevel@tonic-gate  * and limitations under the License.
13*7c478bd9Sstevel@tonic-gate  *
14*7c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*7c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*7c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*7c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*7c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*7c478bd9Sstevel@tonic-gate  *
20*7c478bd9Sstevel@tonic-gate  * CDDL HEADER END
21*7c478bd9Sstevel@tonic-gate  */
22*7c478bd9Sstevel@tonic-gate /*
23*7c478bd9Sstevel@tonic-gate  * Copyright (c) 1999,2000 by Sun Microsystems, Inc.
24*7c478bd9Sstevel@tonic-gate  * All rights reserved.
25*7c478bd9Sstevel@tonic-gate  */
26*7c478bd9Sstevel@tonic-gate 
27*7c478bd9Sstevel@tonic-gate #ifndef _FSCK_PCFS_H
28*7c478bd9Sstevel@tonic-gate #define	_FSCK_PCFS_H
29*7c478bd9Sstevel@tonic-gate 
30*7c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
31*7c478bd9Sstevel@tonic-gate 
32*7c478bd9Sstevel@tonic-gate /*
33*7c478bd9Sstevel@tonic-gate  * Structures used by the pcfs file system checker.
34*7c478bd9Sstevel@tonic-gate  */
35*7c478bd9Sstevel@tonic-gate 
36*7c478bd9Sstevel@tonic-gate #ifdef __cplusplus
37*7c478bd9Sstevel@tonic-gate extern "C" {
38*7c478bd9Sstevel@tonic-gate #endif
39*7c478bd9Sstevel@tonic-gate 
40*7c478bd9Sstevel@tonic-gate #include <sys/types.h>
41*7c478bd9Sstevel@tonic-gate 
42*7c478bd9Sstevel@tonic-gate /*
43*7c478bd9Sstevel@tonic-gate  *  The root directory of FAT12/16 file systems doesn't sit in
44*7c478bd9Sstevel@tonic-gate  *  a cluster.
45*7c478bd9Sstevel@tonic-gate  */
46*7c478bd9Sstevel@tonic-gate #define	FAKE_ROOTDIR_CLUST	-1
47*7c478bd9Sstevel@tonic-gate 
48*7c478bd9Sstevel@tonic-gate /*
49*7c478bd9Sstevel@tonic-gate  *  The first available cluster number for a FAT fs is always the same, 2.
50*7c478bd9Sstevel@tonic-gate  */
51*7c478bd9Sstevel@tonic-gate #define	FIRST_CLUSTER		2
52*7c478bd9Sstevel@tonic-gate 
53*7c478bd9Sstevel@tonic-gate #define	RETURN_ON_OPEN_FAILURE	0
54*7c478bd9Sstevel@tonic-gate #define	EXIT_ON_OPEN_FAILURE	1
55*7c478bd9Sstevel@tonic-gate 
56*7c478bd9Sstevel@tonic-gate #define	NO_FAT_IN_SUMMARY	0
57*7c478bd9Sstevel@tonic-gate #define	INCLUDE_FAT_IN_SUMMARY	1
58*7c478bd9Sstevel@tonic-gate 
59*7c478bd9Sstevel@tonic-gate #define	RDCLUST_DONT_CACHE	0
60*7c478bd9Sstevel@tonic-gate #define	RDCLUST_DO_CACHE	1
61*7c478bd9Sstevel@tonic-gate 
62*7c478bd9Sstevel@tonic-gate /*
63*7c478bd9Sstevel@tonic-gate  *  Return values for sanityCheckSize()
64*7c478bd9Sstevel@tonic-gate  */
65*7c478bd9Sstevel@tonic-gate #define	SIZE_MATCHED	0
66*7c478bd9Sstevel@tonic-gate #define	TRUNCATED	1
67*7c478bd9Sstevel@tonic-gate 
68*7c478bd9Sstevel@tonic-gate #define	RDCLUST_MAX_RETRY 3
69*7c478bd9Sstevel@tonic-gate #define	RDCLUST_GOOD 0
70*7c478bd9Sstevel@tonic-gate #define	RDCLUST_FAIL -1
71*7c478bd9Sstevel@tonic-gate #define	RDCLUST_MEMERR -2
72*7c478bd9Sstevel@tonic-gate #define	RDCLUST_BADINPUT -3
73*7c478bd9Sstevel@tonic-gate 
74*7c478bd9Sstevel@tonic-gate typedef union clustDataTypes {
75*7c478bd9Sstevel@tonic-gate     struct pcdir	*dirp;
76*7c478bd9Sstevel@tonic-gate     uchar_t		*bytes;
77*7c478bd9Sstevel@tonic-gate } ClusterContents;
78*7c478bd9Sstevel@tonic-gate 
79*7c478bd9Sstevel@tonic-gate struct cached {
80*7c478bd9Sstevel@tonic-gate     int32_t	clusterNum;
81*7c478bd9Sstevel@tonic-gate     ClusterContents clusterData;
82*7c478bd9Sstevel@tonic-gate     short	modified;
83*7c478bd9Sstevel@tonic-gate     struct cached *next;
84*7c478bd9Sstevel@tonic-gate };
85*7c478bd9Sstevel@tonic-gate 
86*7c478bd9Sstevel@tonic-gate typedef struct cached CachedCluster;
87*7c478bd9Sstevel@tonic-gate 
88*7c478bd9Sstevel@tonic-gate struct nameinfo {
89*7c478bd9Sstevel@tonic-gate 	char *fullName;
90*7c478bd9Sstevel@tonic-gate 	int references;
91*7c478bd9Sstevel@tonic-gate };
92*7c478bd9Sstevel@tonic-gate 
93*7c478bd9Sstevel@tonic-gate /*
94*7c478bd9Sstevel@tonic-gate  * This structure is shared between all structures belonging to
95*7c478bd9Sstevel@tonic-gate  * a single file.  The refcnt is a 24 bit integer, that should be
96*7c478bd9Sstevel@tonic-gate  * sufficient for 4GB files, even when someone uses 256 byte clusters
97*7c478bd9Sstevel@tonic-gate  * (4K is the typical cluster size, 512 bytes is probably the minimum)
98*7c478bd9Sstevel@tonic-gate  * The inefficiency of using a bit field is compensated by the memory
99*7c478bd9Sstevel@tonic-gate  * savings and prevented paging on large filesystems.
100*7c478bd9Sstevel@tonic-gate  */
101*7c478bd9Sstevel@tonic-gate struct clinfo {
102*7c478bd9Sstevel@tonic-gate 	struct pcdir	*dirent;
103*7c478bd9Sstevel@tonic-gate 	union {
104*7c478bd9Sstevel@tonic-gate 	    struct clinfo	*_nextfree;
105*7c478bd9Sstevel@tonic-gate 	    struct pcdir	*_longent;
106*7c478bd9Sstevel@tonic-gate 	}		_unionelem;
107*7c478bd9Sstevel@tonic-gate 	int32_t		longEntStartClust;
108*7c478bd9Sstevel@tonic-gate 	int		refcnt:24;
109*7c478bd9Sstevel@tonic-gate 	uint_t		flags:8;
110*7c478bd9Sstevel@tonic-gate 	uchar_t		*saved;
111*7c478bd9Sstevel@tonic-gate 	struct nameinfo	*path;
112*7c478bd9Sstevel@tonic-gate };
113*7c478bd9Sstevel@tonic-gate 
114*7c478bd9Sstevel@tonic-gate /*
115*7c478bd9Sstevel@tonic-gate  * #define dirent conflicts with other dirent uses, so we used the
116*7c478bd9Sstevel@tonic-gate  * second element instead of the first one one as union for the free
117*7c478bd9Sstevel@tonic-gate  * list
118*7c478bd9Sstevel@tonic-gate  */
119*7c478bd9Sstevel@tonic-gate #define	longent		_unionelem._longent
120*7c478bd9Sstevel@tonic-gate #define	nextfree	_unionelem._nextfree
121*7c478bd9Sstevel@tonic-gate 
122*7c478bd9Sstevel@tonic-gate typedef struct clinfo ClusterInfo;
123*7c478bd9Sstevel@tonic-gate 
124*7c478bd9Sstevel@tonic-gate /*
125*7c478bd9Sstevel@tonic-gate  *  Return values for allocInUse
126*7c478bd9Sstevel@tonic-gate  */
127*7c478bd9Sstevel@tonic-gate #define	CLINFO_PREVIOUSLY_ALLOCED	1
128*7c478bd9Sstevel@tonic-gate #define	CLINFO_NEWLY_ALLOCED		0
129*7c478bd9Sstevel@tonic-gate 
130*7c478bd9Sstevel@tonic-gate #define	CLINFO_BAD	0x1
131*7c478bd9Sstevel@tonic-gate #define	CLINFO_ORPHAN	0x2
132*7c478bd9Sstevel@tonic-gate #define	CLINFO_HIDDEN	0x4
133*7c478bd9Sstevel@tonic-gate 
134*7c478bd9Sstevel@tonic-gate /*
135*7c478bd9Sstevel@tonic-gate  *	Traversal operations for wandering the file system metadata
136*7c478bd9Sstevel@tonic-gate  */
137*7c478bd9Sstevel@tonic-gate #define	PCFS_NO_SUBDIRS		0
138*7c478bd9Sstevel@tonic-gate #define	PCFS_VISIT_SUBDIRS	1
139*7c478bd9Sstevel@tonic-gate 
140*7c478bd9Sstevel@tonic-gate #define	PCFS_TRAVERSE_ALL	1	/* visit all nodes */
141*7c478bd9Sstevel@tonic-gate #define	PCFS_FIND_ATTR		2	/* search for matching attribute */
142*7c478bd9Sstevel@tonic-gate #define	PCFS_FIND_STATUS	3	/* search for same status */
143*7c478bd9Sstevel@tonic-gate #define	PCFS_FIND_CHKS		4	/* find FILENNNN.CHK files */
144*7c478bd9Sstevel@tonic-gate 
145*7c478bd9Sstevel@tonic-gate /*
146*7c478bd9Sstevel@tonic-gate  *  Booleans for markInUse, whether or not file is marked hidden.
147*7c478bd9Sstevel@tonic-gate  */
148*7c478bd9Sstevel@tonic-gate #define	VISIBLE 0
149*7c478bd9Sstevel@tonic-gate #define	HIDDEN  1
150*7c478bd9Sstevel@tonic-gate 
151*7c478bd9Sstevel@tonic-gate /*
152*7c478bd9Sstevel@tonic-gate  * Indices for various parts of the FILEnnnn.CHK name
153*7c478bd9Sstevel@tonic-gate  */
154*7c478bd9Sstevel@tonic-gate #define	CHKNAME_F	0
155*7c478bd9Sstevel@tonic-gate #define	CHKNAME_I	1
156*7c478bd9Sstevel@tonic-gate #define	CHKNAME_L	2
157*7c478bd9Sstevel@tonic-gate #define	CHKNAME_E	3
158*7c478bd9Sstevel@tonic-gate #define	CHKNAME_THOUSANDS	4
159*7c478bd9Sstevel@tonic-gate #define	CHKNAME_HUNDREDS	5
160*7c478bd9Sstevel@tonic-gate #define	CHKNAME_TENS	6
161*7c478bd9Sstevel@tonic-gate #define	CHKNAME_ONES	7
162*7c478bd9Sstevel@tonic-gate #define	CHKNAME_C	0
163*7c478bd9Sstevel@tonic-gate #define	CHKNAME_H	1
164*7c478bd9Sstevel@tonic-gate #define	CHKNAME_K	2
165*7c478bd9Sstevel@tonic-gate 
166*7c478bd9Sstevel@tonic-gate /*
167*7c478bd9Sstevel@tonic-gate  *  Largest value that will fit into our lost+found naming scheme of
168*7c478bd9Sstevel@tonic-gate  *  FILEnnnn.CHK.
169*7c478bd9Sstevel@tonic-gate  */
170*7c478bd9Sstevel@tonic-gate #define	MAXCHKVAL	9999
171*7c478bd9Sstevel@tonic-gate 
172*7c478bd9Sstevel@tonic-gate /*
173*7c478bd9Sstevel@tonic-gate  * Function prototypes
174*7c478bd9Sstevel@tonic-gate  */
175*7c478bd9Sstevel@tonic-gate extern struct pcdir *addRootDirEnt(int fd, struct pcdir *copyme);
176*7c478bd9Sstevel@tonic-gate extern struct pcdir *newDirEnt(struct pcdir *copyme);
177*7c478bd9Sstevel@tonic-gate extern int32_t extractStartCluster(struct pcdir *dp);
178*7c478bd9Sstevel@tonic-gate extern int32_t findImpactedCluster(struct pcdir *modified);
179*7c478bd9Sstevel@tonic-gate extern int32_t readFATEntry(int32_t currentCluster);
180*7c478bd9Sstevel@tonic-gate extern uint32_t extractSize(struct pcdir *dp);
181*7c478bd9Sstevel@tonic-gate extern int32_t nextInChain(int32_t currentCluster);
182*7c478bd9Sstevel@tonic-gate extern char *nextAvailableCHKName(int *chosen);
183*7c478bd9Sstevel@tonic-gate extern void truncChainWithBadCluster(int fd, struct pcdir *dp,
184*7c478bd9Sstevel@tonic-gate     int32_t startCluster);
185*7c478bd9Sstevel@tonic-gate extern void mountSanityCheckFails(void);
186*7c478bd9Sstevel@tonic-gate extern void markClusterModified(int32_t clusterNum);
187*7c478bd9Sstevel@tonic-gate extern void scanAndFixMetadata(int fd);
188*7c478bd9Sstevel@tonic-gate extern void updateDirEnt_Start(struct pcdir *dp, int32_t newStart);
189*7c478bd9Sstevel@tonic-gate extern void addEntryToCHKList(int chkNumber);
190*7c478bd9Sstevel@tonic-gate extern void createCHKNameList(int fd);
191*7c478bd9Sstevel@tonic-gate extern void updateDirEnt_Name(struct pcdir *dp, char *newName);
192*7c478bd9Sstevel@tonic-gate extern void updateDirEnt_Size(struct pcdir *dp, uint32_t newSize);
193*7c478bd9Sstevel@tonic-gate extern void getRootDirectory(int fd);
194*7c478bd9Sstevel@tonic-gate extern void writeClusterMods(int fd);
195*7c478bd9Sstevel@tonic-gate extern void writeRootDirMods(int fd);
196*7c478bd9Sstevel@tonic-gate extern void traverseFromRoot(int fd, int depth, int descend, int operation,
197*7c478bd9Sstevel@tonic-gate     char matchRequired,  struct pcdir **found, int32_t *lastDirCluster,
198*7c478bd9Sstevel@tonic-gate     struct pcdir **dirEnd, char *recordPath, int *pathLen);
199*7c478bd9Sstevel@tonic-gate extern void findBadClusters(int fd);
200*7c478bd9Sstevel@tonic-gate extern void markFreeInFAT(int32_t clusterNum);
201*7c478bd9Sstevel@tonic-gate extern void markLastInFAT(int32_t clusterNum);
202*7c478bd9Sstevel@tonic-gate extern void writeFATEntry(int32_t currentCluster, int32_t value);
203*7c478bd9Sstevel@tonic-gate extern void markBadInFAT(int32_t clusterNum);
204*7c478bd9Sstevel@tonic-gate extern void printSummary(FILE *outDest);
205*7c478bd9Sstevel@tonic-gate extern void squirrelPath(struct nameinfo *pathInfo, int32_t clusterNum);
206*7c478bd9Sstevel@tonic-gate extern void usingCHKName(void *nameCookie);
207*7c478bd9Sstevel@tonic-gate extern void writeFATMods(int fd);
208*7c478bd9Sstevel@tonic-gate extern void traverseDir(int fd, int32_t startAt, int depth, int descend,
209*7c478bd9Sstevel@tonic-gate     int operation, char matchRequired,  struct pcdir **found,
210*7c478bd9Sstevel@tonic-gate     int32_t *lastDirCluster, struct pcdir **dirEnd, char *recordPath,
211*7c478bd9Sstevel@tonic-gate     int *pathLen);
212*7c478bd9Sstevel@tonic-gate extern void splitChain(int fd, struct pcdir *dp, int32_t problemCluster,
213*7c478bd9Sstevel@tonic-gate     struct pcdir **newdp, int32_t *orphanStart);
214*7c478bd9Sstevel@tonic-gate extern void preenBail(char *outString);
215*7c478bd9Sstevel@tonic-gate extern void readBPB(int fd);
216*7c478bd9Sstevel@tonic-gate extern void getFAT(int fd);
217*7c478bd9Sstevel@tonic-gate extern int checkFAT32CleanBit(int fd);
218*7c478bd9Sstevel@tonic-gate extern int reservedInFAT(int32_t clusterNum);
219*7c478bd9Sstevel@tonic-gate extern int isMarkedBad(int32_t clusterNum);
220*7c478bd9Sstevel@tonic-gate extern int readCluster(int fd, int32_t clusterNum, uchar_t **data,
221*7c478bd9Sstevel@tonic-gate     int32_t *datasize, int shouldCache);
222*7c478bd9Sstevel@tonic-gate extern int freeInFAT(int32_t clusterNum);
223*7c478bd9Sstevel@tonic-gate extern int lastInFAT(int32_t clusterNum);
224*7c478bd9Sstevel@tonic-gate extern int markInUse(int fd, int32_t clusterNum, struct pcdir *referencer,
225*7c478bd9Sstevel@tonic-gate     struct pcdir *longRef, int32_t longStartCluster, int isHidden,
226*7c478bd9Sstevel@tonic-gate     ClusterInfo **template);
227*7c478bd9Sstevel@tonic-gate extern int badInFAT(int32_t clusterNum);
228*7c478bd9Sstevel@tonic-gate 
229*7c478bd9Sstevel@tonic-gate #ifdef __cplusplus
230*7c478bd9Sstevel@tonic-gate }
231*7c478bd9Sstevel@tonic-gate #endif
232*7c478bd9Sstevel@tonic-gate 
233*7c478bd9Sstevel@tonic-gate #endif /* _FSCK_PCFS_H */
234