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