1 /* $NetBSD: ext.h,v 1.14 2023/09/24 20:41:52 gutteridge Exp $ */ 2 3 /* 4 * Copyright (C) 1995, 1996, 1997 Wolfgang Solfrank 5 * Copyright (c) 1995 Martin Husemann 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 16 * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR 17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19 * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT, 20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 */ 27 28 #ifndef EXT_H 29 #define EXT_H 30 31 #include <sys/types.h> 32 33 #include "dosfs.h" 34 35 #define LOSTDIR "LOST.DIR" 36 37 /* 38 * Options: 39 */ 40 extern int alwaysno; /* assume "no" for all questions */ 41 extern int alwaysyes; /* assume "yes" for all questions */ 42 extern int preen; /* we are preening */ 43 extern int rdonly; /* device is opened read only (supersedes above) */ 44 45 extern char *fname; /* filesystem currently checked */ 46 47 extern struct dosDirEntry *rootDir; 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 #define FSDIRTY 32 /* File system is dirty */ 69 #define FSFIXFAT 64 /* Fix file system FAT */ 70 71 /* 72 * Read a boot block in a machine independent fashion and translate 73 * it into our struct bootblock. 74 */ 75 int readboot(int, struct bootblock *); 76 77 /* 78 * Correct the FSInfo block. 79 */ 80 int writefsinfo(int, struct bootblock *); 81 82 /* 83 * Read one of the FAT copies and return a pointer to the new 84 * allocated array holding our description of it. 85 */ 86 int readfat(int, struct bootblock *, u_int, struct fatEntry **); 87 88 /* 89 * Check two FAT copies for consistency and merge changes into the 90 * first if necessary. 91 */ 92 int comparefat(struct bootblock *, struct fatEntry *, struct fatEntry *, u_int); 93 94 /* 95 * Check a FAT 96 */ 97 int checkfat(struct bootblock *, struct fatEntry *); 98 99 /* 100 * Write back FAT entries 101 */ 102 int writefat(int, struct bootblock *, struct fatEntry *, int); 103 104 /* 105 * Read a directory 106 */ 107 int resetDosDirSection(struct bootblock *, struct fatEntry *); 108 void finishDosDirSection(void); 109 int handleDirTree(int, struct bootblock *, struct fatEntry *); 110 111 /* 112 * Cross-check routines run after everything is completely in memory 113 */ 114 /* 115 * Check for lost cluster chains 116 */ 117 int checklost(int, struct bootblock *, struct fatEntry *); 118 /* 119 * Try to reconnect a lost cluster chain 120 */ 121 int reconnect(int, struct bootblock *, struct fatEntry *, cl_t); 122 void finishlf(void); 123 124 /* 125 * Small helper functions 126 */ 127 /* 128 * Return the type of a reserved cluster as text 129 */ 130 const char *rsrvdcltype(cl_t); 131 132 /* 133 * Clear a cluster chain in a FAT 134 */ 135 void clearchain(struct bootblock *, struct fatEntry *, cl_t); 136 137 #endif 138