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 * 140121b42aSDavid E. O'Brien * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR 150121b42aSDavid E. O'Brien * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 160121b42aSDavid E. O'Brien * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 170121b42aSDavid E. O'Brien * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT, 180121b42aSDavid E. O'Brien * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 190121b42aSDavid E. O'Brien * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 200121b42aSDavid E. O'Brien * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 210121b42aSDavid E. O'Brien * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 220121b42aSDavid E. O'Brien * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 230121b42aSDavid E. O'Brien * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 240121b42aSDavid E. O'Brien * $NetBSD: ext.h,v 1.6 2000/04/25 23:02:51 jdolecek Exp $ 250121b42aSDavid E. O'Brien * $FreeBSD$ 260121b42aSDavid E. O'Brien */ 270121b42aSDavid E. O'Brien 280121b42aSDavid E. O'Brien #ifndef EXT_H 290121b42aSDavid E. O'Brien #define EXT_H 300121b42aSDavid E. O'Brien 310121b42aSDavid E. O'Brien #include <sys/types.h> 320121b42aSDavid E. O'Brien 330121b42aSDavid E. O'Brien #include "dosfs.h" 340121b42aSDavid E. O'Brien 350121b42aSDavid E. O'Brien #define LOSTDIR "LOST.DIR" 360121b42aSDavid E. O'Brien 370121b42aSDavid E. O'Brien /* 380121b42aSDavid E. O'Brien * Options: 390121b42aSDavid E. O'Brien */ 400121b42aSDavid E. O'Brien extern int alwaysno; /* assume "no" for all questions */ 410121b42aSDavid E. O'Brien extern int alwaysyes; /* assume "yes" for all questions */ 420121b42aSDavid E. O'Brien extern int preen; /* we are preening */ 430121b42aSDavid E. O'Brien extern int rdonly; /* device is opened read only (supersedes above) */ 44ae62d940SBruce Evans extern int skipclean; /* skip clean file systems if preening */ 450121b42aSDavid E. O'Brien 460121b42aSDavid E. O'Brien extern struct dosDirEntry *rootDir; 470121b42aSDavid E. O'Brien 480121b42aSDavid E. O'Brien /* 490121b42aSDavid E. O'Brien * function declarations 500121b42aSDavid E. O'Brien */ 514eb55c7aSStefan Farfeleder int ask(int, const char *, ...) __printflike(2, 3); 520121b42aSDavid E. O'Brien 530121b42aSDavid E. O'Brien /* 5430b48d7fSBruce Evans * Check the dirty flag. If the file system is clean, then return 1. 5530b48d7fSBruce Evans * Otherwise, return 0 (this includes the case of FAT12 file systems -- 5630b48d7fSBruce Evans * they have no dirty flag, so they must be assumed to be unclean). 5730b48d7fSBruce Evans */ 5830b48d7fSBruce Evans int checkdirty(int, struct bootblock *); 5930b48d7fSBruce Evans 6030b48d7fSBruce Evans /* 610121b42aSDavid E. O'Brien * Check file system given as arg 620121b42aSDavid E. O'Brien */ 63b70cd7eeSWarner Losh int checkfilesys(const char *); 640121b42aSDavid E. O'Brien 650121b42aSDavid E. O'Brien /* 660121b42aSDavid E. O'Brien * Return values of various functions 670121b42aSDavid E. O'Brien */ 680121b42aSDavid E. O'Brien #define FSOK 0 /* Check was OK */ 690121b42aSDavid E. O'Brien #define FSBOOTMOD 1 /* Boot block was modified */ 700121b42aSDavid E. O'Brien #define FSDIRMOD 2 /* Some directory was modified */ 710121b42aSDavid E. O'Brien #define FSFATMOD 4 /* The FAT was modified */ 720121b42aSDavid E. O'Brien #define FSERROR 8 /* Some unrecovered error remains */ 736069db97SKonstantin Belousov #define FSFATAL 16 /* Some unrecoverable error occurred */ 740121b42aSDavid E. O'Brien #define FSDIRTY 32 /* File system is dirty */ 750121b42aSDavid E. O'Brien #define FSFIXFAT 64 /* Fix file system FAT */ 760121b42aSDavid E. O'Brien 770121b42aSDavid E. O'Brien /* 786069db97SKonstantin Belousov * read a boot block in a machine independent fashion and translate 790121b42aSDavid E. O'Brien * it into our struct bootblock. 800121b42aSDavid E. O'Brien */ 81b70cd7eeSWarner Losh int readboot(int, struct bootblock *); 820121b42aSDavid E. O'Brien 830121b42aSDavid E. O'Brien /* 840121b42aSDavid E. O'Brien * Correct the FSInfo block. 850121b42aSDavid E. O'Brien */ 86b70cd7eeSWarner Losh int writefsinfo(int, struct bootblock *); 870121b42aSDavid E. O'Brien 880121b42aSDavid E. O'Brien /* 890121b42aSDavid E. O'Brien * Read one of the FAT copies and return a pointer to the new 900121b42aSDavid E. O'Brien * allocated array holding our description of it. 910121b42aSDavid E. O'Brien */ 926069db97SKonstantin Belousov int readfat(int, struct bootblock *, u_int, struct fatEntry **); 930121b42aSDavid E. O'Brien 940121b42aSDavid E. O'Brien /* 950121b42aSDavid E. O'Brien * Check two FAT copies for consistency and merge changes into the 966069db97SKonstantin Belousov * first if necessary. 970121b42aSDavid E. O'Brien */ 986069db97SKonstantin Belousov int comparefat(struct bootblock *, struct fatEntry *, struct fatEntry *, u_int); 990121b42aSDavid E. O'Brien 1000121b42aSDavid E. O'Brien /* 1010121b42aSDavid E. O'Brien * Check a FAT 1020121b42aSDavid E. O'Brien */ 103b70cd7eeSWarner Losh int checkfat(struct bootblock *, struct fatEntry *); 1040121b42aSDavid E. O'Brien 1050121b42aSDavid E. O'Brien /* 1060121b42aSDavid E. O'Brien * Write back FAT entries 1070121b42aSDavid E. O'Brien */ 108b70cd7eeSWarner Losh int writefat(int, struct bootblock *, struct fatEntry *, int); 1090121b42aSDavid E. O'Brien 1100121b42aSDavid E. O'Brien /* 1110121b42aSDavid E. O'Brien * Read a directory 1120121b42aSDavid E. O'Brien */ 113b70cd7eeSWarner Losh int resetDosDirSection(struct bootblock *, struct fatEntry *); 114b70cd7eeSWarner Losh void finishDosDirSection(void); 115b70cd7eeSWarner Losh int handleDirTree(int, struct bootblock *, struct fatEntry *); 1160121b42aSDavid E. O'Brien 1170121b42aSDavid E. O'Brien /* 1180121b42aSDavid E. O'Brien * Cross-check routines run after everything is completely in memory 1190121b42aSDavid E. O'Brien */ 1200121b42aSDavid E. O'Brien /* 1210121b42aSDavid E. O'Brien * Check for lost cluster chains 1220121b42aSDavid E. O'Brien */ 123b70cd7eeSWarner Losh int checklost(int, struct bootblock *, struct fatEntry *); 1240121b42aSDavid E. O'Brien /* 1250121b42aSDavid E. O'Brien * Try to reconnect a lost cluster chain 1260121b42aSDavid E. O'Brien */ 127b70cd7eeSWarner Losh int reconnect(int, struct bootblock *, struct fatEntry *, cl_t); 128b70cd7eeSWarner Losh void finishlf(void); 1290121b42aSDavid E. O'Brien 1300121b42aSDavid E. O'Brien /* 1310121b42aSDavid E. O'Brien * Small helper functions 1320121b42aSDavid E. O'Brien */ 1330121b42aSDavid E. O'Brien /* 1340121b42aSDavid E. O'Brien * Return the type of a reserved cluster as text 1350121b42aSDavid E. O'Brien */ 136*3bbc4438SUlrich Spörlein const char *rsrvdcltype(cl_t); 1370121b42aSDavid E. O'Brien 1380121b42aSDavid E. O'Brien /* 1390121b42aSDavid E. O'Brien * Clear a cluster chain in a FAT 1400121b42aSDavid E. O'Brien */ 141b70cd7eeSWarner Losh void clearchain(struct bootblock *, struct fatEntry *, cl_t); 1420121b42aSDavid E. O'Brien 1430121b42aSDavid E. O'Brien #endif 144