xref: /freebsd/sbin/fsck_msdosfs/ext.h (revision 30b48d7f6de2d40c9ead5862ee207592f1ff2e10)
10121b42aSDavid E. O'Brien /*
20121b42aSDavid E. O'Brien  * Copyright (C) 1995, 1996, 1997 Wolfgang Solfrank
30121b42aSDavid E. O'Brien  * Copyright (c) 1995 Martin Husemann
40121b42aSDavid E. O'Brien  *
50121b42aSDavid E. O'Brien  * Redistribution and use in source and binary forms, with or without
60121b42aSDavid E. O'Brien  * modification, are permitted provided that the following conditions
70121b42aSDavid E. O'Brien  * are met:
80121b42aSDavid E. O'Brien  * 1. Redistributions of source code must retain the above copyright
90121b42aSDavid E. O'Brien  *    notice, this list of conditions and the following disclaimer.
100121b42aSDavid E. O'Brien  * 2. Redistributions in binary form must reproduce the above copyright
110121b42aSDavid E. O'Brien  *    notice, this list of conditions and the following disclaimer in the
120121b42aSDavid E. O'Brien  *    documentation and/or other materials provided with the distribution.
130121b42aSDavid E. O'Brien  * 3. All advertising materials mentioning features or use of this software
140121b42aSDavid E. O'Brien  *    must display the following acknowledgement:
150121b42aSDavid E. O'Brien  *	This product includes software developed by Martin Husemann
160121b42aSDavid E. O'Brien  *	and Wolfgang Solfrank.
170121b42aSDavid E. O'Brien  * 4. Neither the name of the University nor the names of its contributors
180121b42aSDavid E. O'Brien  *    may be used to endorse or promote products derived from this software
190121b42aSDavid E. O'Brien  *    without specific prior written permission.
200121b42aSDavid E. O'Brien  *
210121b42aSDavid E. O'Brien  * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
220121b42aSDavid E. O'Brien  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
230121b42aSDavid E. O'Brien  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
240121b42aSDavid E. O'Brien  * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT,
250121b42aSDavid E. O'Brien  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
260121b42aSDavid E. O'Brien  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
270121b42aSDavid E. O'Brien  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
280121b42aSDavid E. O'Brien  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
290121b42aSDavid E. O'Brien  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
300121b42aSDavid E. O'Brien  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
310121b42aSDavid E. O'Brien  *	$NetBSD: ext.h,v 1.6 2000/04/25 23:02:51 jdolecek Exp $
320121b42aSDavid E. O'Brien  * $FreeBSD$
330121b42aSDavid E. O'Brien  */
340121b42aSDavid E. O'Brien 
350121b42aSDavid E. O'Brien #ifndef EXT_H
360121b42aSDavid E. O'Brien #define EXT_H
370121b42aSDavid E. O'Brien 
380121b42aSDavid E. O'Brien #include <sys/types.h>
390121b42aSDavid E. O'Brien 
400121b42aSDavid E. O'Brien #include "dosfs.h"
410121b42aSDavid E. O'Brien 
420121b42aSDavid E. O'Brien #define	LOSTDIR	"LOST.DIR"
430121b42aSDavid E. O'Brien 
440121b42aSDavid E. O'Brien /*
450121b42aSDavid E. O'Brien  * Options:
460121b42aSDavid E. O'Brien  */
470121b42aSDavid E. O'Brien extern int alwaysno;	/* assume "no" for all questions */
480121b42aSDavid E. O'Brien extern int alwaysyes;	/* assume "yes" for all questions */
4930b48d7fSBruce Evans extern int force;	/* force check even the fs is clean */
500121b42aSDavid E. O'Brien extern int preen;	/* we are preening */
510121b42aSDavid E. O'Brien extern int rdonly;	/* device is opened read only (supersedes above) */
520121b42aSDavid E. O'Brien 
530121b42aSDavid E. O'Brien extern struct dosDirEntry *rootDir;
540121b42aSDavid E. O'Brien 
550121b42aSDavid E. O'Brien /*
560121b42aSDavid E. O'Brien  * function declarations
570121b42aSDavid E. O'Brien  */
58b70cd7eeSWarner Losh int ask(int, const char *, ...) __attribute__((__format__(__printf__,2,3)));
590121b42aSDavid E. O'Brien 
600121b42aSDavid E. O'Brien /*
6130b48d7fSBruce Evans  * Check the dirty flag.  If the file system is clean, then return 1.
6230b48d7fSBruce Evans  * Otherwise, return 0 (this includes the case of FAT12 file systems --
6330b48d7fSBruce Evans  * they have no dirty flag, so they must be assumed to be unclean).
6430b48d7fSBruce Evans  */
6530b48d7fSBruce Evans int checkdirty(int, struct bootblock *);
6630b48d7fSBruce Evans 
6730b48d7fSBruce Evans /*
680121b42aSDavid E. O'Brien  * Check file system given as arg
690121b42aSDavid E. O'Brien  */
70b70cd7eeSWarner Losh int checkfilesys(const char *);
710121b42aSDavid E. O'Brien 
720121b42aSDavid E. O'Brien /*
730121b42aSDavid E. O'Brien  * Return values of various functions
740121b42aSDavid E. O'Brien  */
750121b42aSDavid E. O'Brien #define	FSOK		0		/* Check was OK */
760121b42aSDavid E. O'Brien #define	FSBOOTMOD	1		/* Boot block was modified */
770121b42aSDavid E. O'Brien #define	FSDIRMOD	2		/* Some directory was modified */
780121b42aSDavid E. O'Brien #define	FSFATMOD	4		/* The FAT was modified */
790121b42aSDavid E. O'Brien #define	FSERROR		8		/* Some unrecovered error remains */
800121b42aSDavid E. O'Brien #define	FSFATAL		16		/* Some unrecoverable error occured */
810121b42aSDavid E. O'Brien #define FSDIRTY		32		/* File system is dirty */
820121b42aSDavid E. O'Brien #define FSFIXFAT	64		/* Fix file system FAT */
830121b42aSDavid E. O'Brien 
840121b42aSDavid E. O'Brien /*
850121b42aSDavid E. O'Brien  * read a boot block in a machine independend fashion and translate
860121b42aSDavid E. O'Brien  * it into our struct bootblock.
870121b42aSDavid E. O'Brien  */
88b70cd7eeSWarner Losh int readboot(int, struct bootblock *);
890121b42aSDavid E. O'Brien 
900121b42aSDavid E. O'Brien /*
910121b42aSDavid E. O'Brien  * Correct the FSInfo block.
920121b42aSDavid E. O'Brien  */
93b70cd7eeSWarner Losh int writefsinfo(int, struct bootblock *);
940121b42aSDavid E. O'Brien 
950121b42aSDavid E. O'Brien /*
960121b42aSDavid E. O'Brien  * Read one of the FAT copies and return a pointer to the new
970121b42aSDavid E. O'Brien  * allocated array holding our description of it.
980121b42aSDavid E. O'Brien  */
99b70cd7eeSWarner Losh int readfat(int, struct bootblock *, int, struct fatEntry **);
1000121b42aSDavid E. O'Brien 
1010121b42aSDavid E. O'Brien /*
1020121b42aSDavid E. O'Brien  * Check two FAT copies for consistency and merge changes into the
1030121b42aSDavid E. O'Brien  * first if neccessary.
1040121b42aSDavid E. O'Brien  */
105b70cd7eeSWarner Losh int comparefat(struct bootblock *, struct fatEntry *, struct fatEntry *, int);
1060121b42aSDavid E. O'Brien 
1070121b42aSDavid E. O'Brien /*
1080121b42aSDavid E. O'Brien  * Check a FAT
1090121b42aSDavid E. O'Brien  */
110b70cd7eeSWarner Losh int checkfat(struct bootblock *, struct fatEntry *);
1110121b42aSDavid E. O'Brien 
1120121b42aSDavid E. O'Brien /*
1130121b42aSDavid E. O'Brien  * Write back FAT entries
1140121b42aSDavid E. O'Brien  */
115b70cd7eeSWarner Losh int writefat(int, struct bootblock *, struct fatEntry *, int);
1160121b42aSDavid E. O'Brien 
1170121b42aSDavid E. O'Brien /*
1180121b42aSDavid E. O'Brien  * Read a directory
1190121b42aSDavid E. O'Brien  */
120b70cd7eeSWarner Losh int resetDosDirSection(struct bootblock *, struct fatEntry *);
121b70cd7eeSWarner Losh void finishDosDirSection(void);
122b70cd7eeSWarner Losh int handleDirTree(int, struct bootblock *, struct fatEntry *);
1230121b42aSDavid E. O'Brien 
1240121b42aSDavid E. O'Brien /*
1250121b42aSDavid E. O'Brien  * Cross-check routines run after everything is completely in memory
1260121b42aSDavid E. O'Brien  */
1270121b42aSDavid E. O'Brien /*
1280121b42aSDavid E. O'Brien  * Check for lost cluster chains
1290121b42aSDavid E. O'Brien  */
130b70cd7eeSWarner Losh int checklost(int, struct bootblock *, struct fatEntry *);
1310121b42aSDavid E. O'Brien /*
1320121b42aSDavid E. O'Brien  * Try to reconnect a lost cluster chain
1330121b42aSDavid E. O'Brien  */
134b70cd7eeSWarner Losh int reconnect(int, struct bootblock *, struct fatEntry *, cl_t);
135b70cd7eeSWarner Losh void finishlf(void);
1360121b42aSDavid E. O'Brien 
1370121b42aSDavid E. O'Brien /*
1380121b42aSDavid E. O'Brien  * Small helper functions
1390121b42aSDavid E. O'Brien  */
1400121b42aSDavid E. O'Brien /*
1410121b42aSDavid E. O'Brien  * Return the type of a reserved cluster as text
1420121b42aSDavid E. O'Brien  */
143b70cd7eeSWarner Losh char *rsrvdcltype(cl_t);
1440121b42aSDavid E. O'Brien 
1450121b42aSDavid E. O'Brien /*
1460121b42aSDavid E. O'Brien  * Clear a cluster chain in a FAT
1470121b42aSDavid E. O'Brien  */
148b70cd7eeSWarner Losh void clearchain(struct bootblock *, struct fatEntry *, cl_t);
1490121b42aSDavid E. O'Brien 
1500121b42aSDavid E. O'Brien #endif
151