xref: /openbsd/sbin/fsck_msdos/ext.h (revision 8c63c132)
1 /*	$OpenBSD: ext.h,v 1.13 2015/09/27 16:56:06 guenther 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  *
17  * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
18  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20  * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT,
21  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  */
28 
29 #ifndef EXT_H
30 #define EXT_H
31 
32 #include <sys/types.h>
33 
34 #include "dosfs.h"
35 #include "fsutil.h"
36 
37 #define	LOSTDIR	"LOST.DIR"
38 
39 /*
40  * Options:
41  */
42 extern int alwaysno;	/* assume "no" for all questions */
43 extern int alwaysyes;	/* assume "yes" for all questions */
44 extern int preen;	/* we are preening */
45 extern int rdonly;	/* device is opened read only (supersedes above) */
46 
47 extern struct disklabel lab;
48 
49 /*
50  * function declarations
51  */
52 int ask(int, const char *, ...) __attribute__((__format__ (printf, 2, 3)));
53 
54 /*
55  * Check filesystem given as arg
56  */
57 int checkfilesys(const char *);
58 
59 /*
60  * Return values of various functions
61  */
62 #define	FSOK		0		/* Check was OK */
63 #define	FSBOOTMOD	1		/* Boot block was modified */
64 #define	FSDIRMOD	2		/* Some directory was modified */
65 #define	FSFATMOD	4		/* The FAT was modified */
66 #define	FSERROR		8		/* Some unrecovered error remains */
67 #define	FSFATAL		16		/* Some unrecoverable error occurred */
68 
69 /*
70  * read a boot block in a machine independent fashion and translate
71  * it into our struct bootblock.
72  */
73 int readboot(int, struct bootblock *);
74 
75 /*
76  * Correct the FSInfo block.
77  */
78 int writefsinfo(int, struct bootblock *);
79 
80 /*
81  * Read one of the FAT copies and return a pointer to the new
82  * allocated array holding our description of it.
83  */
84 int readfat(int, struct bootblock *, int, struct fatEntry **);
85 
86 /*
87  * Check two FAT copies for consistency and merge changes into the
88  * first if necessary.
89  */
90 int comparefat(struct bootblock *, struct fatEntry *, struct fatEntry *, int);
91 
92 /*
93  * Check a FAT
94  */
95 int checkfat(struct bootblock *, struct fatEntry *);
96 
97 /*
98  * Write back FAT entries
99  */
100 int writefat(int, struct bootblock *, struct fatEntry *);
101 
102 /*
103  * Read a directory
104  */
105 int resetDosDirSection(struct bootblock *, struct fatEntry *);
106 void finishDosDirSection(void);
107 int handleDirTree(int, struct bootblock *, struct fatEntry *);
108 
109 /*
110  * Cross-check routines run after everything is completely in memory
111  */
112 /*
113  * Check for lost cluster chains
114  */
115 int checklost(int, struct bootblock *, struct fatEntry *);
116 /*
117  * Try to reconnect a lost cluster chain
118  */
119 int reconnect(int, struct bootblock *, struct fatEntry *, cl_t);
120 void finishlf(void);
121 
122 /*
123  * Small helper functions
124  */
125 /*
126  * Return the type of a reserved cluster as text
127  */
128 char *rsrvdcltype(cl_t);
129 
130 /*
131  * Clear a cluster chain in a FAT
132  */
133 void clearchain(struct bootblock *, struct fatEntry *, cl_t);
134 
135 #endif
136