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