ext.h revision 92839
1114987Speter/* 2114987Speter * Copyright (C) 1995, 1996, 1997 Wolfgang Solfrank 3114987Speter * Copyright (c) 1995 Martin Husemann 4114987Speter * 5114987Speter * Redistribution and use in source and binary forms, with or without 6114987Speter * modification, are permitted provided that the following conditions 7114987Speter * are met: 8114987Speter * 1. Redistributions of source code must retain the above copyright 9114987Speter * notice, this list of conditions and the following disclaimer. 10114987Speter * 2. Redistributions in binary form must reproduce the above copyright 11114987Speter * notice, this list of conditions and the following disclaimer in the 12114987Speter * documentation and/or other materials provided with the distribution. 13114987Speter * 3. All advertising materials mentioning features or use of this software 14114987Speter * must display the following acknowledgement: 15114987Speter * This product includes software developed by Martin Husemann 16114987Speter * and Wolfgang Solfrank. 17114987Speter * 4. Neither the name of the University nor the names of its contributors 18114987Speter * may be used to endorse or promote products derived from this software 19114987Speter * without specific prior written permission. 20114987Speter * 21114987Speter * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR 22114987Speter * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 23114987Speter * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 24114987Speter * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT, 25114987Speter * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 26114987Speter * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27114987Speter * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28114987Speter * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29114987Speter * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 30114987Speter * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31114987Speter * $NetBSD: ext.h,v 1.6 2000/04/25 23:02:51 jdolecek Exp $ 32114987Speter * $FreeBSD: head/sbin/fsck_msdosfs/ext.h 92839 2002-03-20 22:57:10Z imp $ 33114987Speter */ 34114987Speter 35114987Speter#ifndef EXT_H 36114987Speter#define EXT_H 37114987Speter 38118031Sobrien#include <sys/types.h> 39118031Sobrien 40118031Sobrien#include "dosfs.h" 41114987Speter 42114987Speter#define LOSTDIR "LOST.DIR" 43114987Speter 44114987Speter/* 45114987Speter * Options: 46220238Skib */ 47114987Speterextern int alwaysno; /* assume "no" for all questions */ 48114987Speterextern int alwaysyes; /* assume "yes" for all questions */ 49114987Speterextern int preen; /* we are preening */ 50114987Speterextern int rdonly; /* device is opened read only (supersedes above) */ 51114987Speter 52114987Speterextern char *fname; /* filesystem currently checked */ 53114987Speter 54114987Speterextern struct dosDirEntry *rootDir; 55114987Speter 56114987Speter/* 57114987Speter * function declarations 58114987Speter */ 59208453Skibint ask(int, const char *, ...) __attribute__((__format__(__printf__,2,3))); 60160764Sjhb 61114987Speter/* 62114987Speter * Check filesystem given as arg 63114987Speter */ 64114987Speterint checkfilesys(const char *); 65114987Speter 66114987Speter/* 67114987Speter * Return values of various functions 68155313Swsalamon */ 69114987Speter#define FSOK 0 /* Check was OK */ 70114987Speter#define FSBOOTMOD 1 /* Boot block was modified */ 71114987Speter#define FSDIRMOD 2 /* Some directory was modified */ 72114987Speter#define FSFATMOD 4 /* The FAT was modified */ 73114987Speter#define FSERROR 8 /* Some unrecovered error remains */ 74114987Speter#define FSFATAL 16 /* Some unrecoverable error occured */ 75114987Speter#define FSDIRTY 32 /* File system is dirty */ 76114987Speter#define FSFIXFAT 64 /* Fix file system FAT */ 77114987Speter 78114987Speter/* 79122849Speter * read a boot block in a machine independend fashion and translate 80114987Speter * it into our struct bootblock. 81114987Speter */ 82220238Skibint readboot(int, struct bootblock *); 83208453Skib 84220238Skib/* 85220238Skib * Correct the FSInfo block. 86220238Skib */ 87220238Skibint writefsinfo(int, struct bootblock *); 88220238Skib 89220238Skib/* 90220238Skib * Read one of the FAT copies and return a pointer to the new 91220238Skib * allocated array holding our description of it. 92220238Skib */ 93208453Skibint readfat(int, struct bootblock *, int, struct fatEntry **); 94114987Speter 95114987Speter/* 96114987Speter * Check two FAT copies for consistency and merge changes into the 97114987Speter * first if neccessary. 98165303Skmacy */ 99114987Speterint comparefat(struct bootblock *, struct fatEntry *, struct fatEntry *, int); 100208453Skib 101208453Skib/* 102208453Skib * Check a FAT 103202882Skib */ 104208453Skibint checkfat(struct bootblock *, struct fatEntry *); 105208453Skib 106208453Skib/* 107208453Skib * Write back FAT entries 108208453Skib */ 109202882Skibint writefat(int, struct bootblock *, struct fatEntry *, int); 110202882Skib 111202882Skib/* 112208453Skib * Read a directory 113274648Skib */ 114202882Skibint resetDosDirSection(struct bootblock *, struct fatEntry *); 115114987Spetervoid finishDosDirSection(void); 116202882Skibint handleDirTree(int, struct bootblock *, struct fatEntry *); 117202882Skib 118114987Speter/* 119208453Skib * Cross-check routines run after everything is completely in memory 120202882Skib */ 121202882Skib/* 122208453Skib * Check for lost cluster chains 123208453Skib */ 124208453Skibint checklost(int, struct bootblock *, struct fatEntry *); 125208453Skib/* 126114987Speter * Try to reconnect a lost cluster chain 127208453Skib */ 128114987Speterint reconnect(int, struct bootblock *, struct fatEntry *, cl_t); 129274648Skibvoid finishlf(void); 130274648Skib 131274648Skib/* 132274648Skib * Small helper functions 133208453Skib */ 134208453Skib/* 135114987Speter * Return the type of a reserved cluster as text 136208453Skib */ 137208453Skibchar *rsrvdcltype(cl_t); 138208453Skib 139208453Skib/* 140114987Speter * Clear a cluster chain in a FAT 141274648Skib */ 142274648Skibvoid clearchain(struct bootblock *, struct fatEntry *, cl_t); 143274648Skib 144274648Skib#endif 145208453Skib