xref: /freebsd/sbin/fsck_msdosfs/ext.h (revision bc96366c864c07ef352edb92017357917c75b36c)
1 /*
2  * Copyright (C) 1995, 1996, 1997 Wolfgang Solfrank
3  * Copyright (c) 1995 Martin Husemann
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  *
14  * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
15  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
16  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17  * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT,
18  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
19  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
20  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
21  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24  *	$NetBSD: ext.h,v 1.6 2000/04/25 23:02:51 jdolecek Exp $
25  * $FreeBSD$
26  */
27 
28 #ifndef EXT_H
29 #define	EXT_H
30 
31 #include <sys/types.h>
32 
33 #include "dosfs.h"
34 
35 #define	LOSTDIR	"LOST.DIR"
36 
37 /*
38  * Options:
39  */
40 extern int alwaysno;	/* assume "no" for all questions */
41 extern int alwaysyes;	/* assume "yes" for all questions */
42 extern int preen;	/* we are preening */
43 extern int rdonly;	/* device is opened read only (supersedes above) */
44 extern int skipclean;	/* skip clean file systems if preening */
45 
46 /*
47  * function declarations
48  */
49 int ask(int, const char *, ...) __printflike(2, 3);
50 
51 /*
52  * Check the dirty flag.  If the file system is clean, then return 1.
53  * Otherwise, return 0 (this includes the case of FAT12 file systems --
54  * they have no dirty flag, so they must be assumed to be unclean).
55  */
56 int checkdirty(int, struct bootblock *);
57 
58 /*
59  * Check file system given as arg
60  */
61 int checkfilesys(const char *);
62 
63 /*
64  * Return values of various functions
65  */
66 #define	FSOK		0		/* Check was OK */
67 #define	FSBOOTMOD	1		/* Boot block was modified */
68 #define	FSDIRMOD	2		/* Some directory was modified */
69 #define	FSFATMOD	4		/* The FAT was modified */
70 #define	FSERROR		8		/* Some unrecovered error remains */
71 #define	FSFATAL		16		/* Some unrecoverable error occurred */
72 #define	FSDIRTY		32		/* File system is dirty */
73 #define	FSFIXFAT	64		/* Fix file system FAT */
74 
75 /*
76  * read a boot block in a machine independent fashion and translate
77  * it into our struct bootblock.
78  */
79 int readboot(int, struct bootblock *);
80 
81 /*
82  * Correct the FSInfo block.
83  */
84 int writefsinfo(int, struct bootblock *);
85 
86 /*
87  * Read one of the FAT copies and return a pointer to the new
88  * allocated array holding our description of it.
89  */
90 int readfat(int, struct bootblock *, u_int, struct fatEntry **);
91 
92 /*
93  * Check two FAT copies for consistency and merge changes into the
94  * first if necessary.
95  */
96 int comparefat(struct bootblock *, struct fatEntry *, struct fatEntry *, u_int);
97 
98 /*
99  * Check a FAT
100  */
101 int checkfat(struct bootblock *, struct fatEntry *);
102 
103 /*
104  * Write back FAT entries
105  */
106 int writefat(int, struct bootblock *, struct fatEntry *, int);
107 
108 /*
109  * Read a directory
110  */
111 int resetDosDirSection(struct bootblock *, struct fatEntry *);
112 void finishDosDirSection(void);
113 int handleDirTree(int, struct bootblock *, struct fatEntry *);
114 
115 /*
116  * Cross-check routines run after everything is completely in memory
117  */
118 /*
119  * Check for lost cluster chains
120  */
121 int checklost(int, struct bootblock *, struct fatEntry *);
122 /*
123  * Try to reconnect a lost cluster chain
124  */
125 int reconnect(int, struct bootblock *, struct fatEntry *, cl_t);
126 void finishlf(void);
127 
128 /*
129  * Small helper functions
130  */
131 /*
132  * Return the type of a reserved cluster as text
133  */
134 const char *rsrvdcltype(cl_t);
135 
136 /*
137  * Clear a cluster chain in a FAT
138  */
139 void clearchain(struct bootblock *, struct fatEntry *, cl_t);
140 
141 #endif
142