1*9558e6acSTreehugger Robot /*- 2*9558e6acSTreehugger Robot * SPDX-License-Identifier: BSD-2-Clause-FreeBSD 3*9558e6acSTreehugger Robot * 4*9558e6acSTreehugger Robot * Copyright (C) 1995, 1996, 1997 Wolfgang Solfrank 5*9558e6acSTreehugger Robot * Copyright (c) 1995 Martin Husemann 6*9558e6acSTreehugger Robot * 7*9558e6acSTreehugger Robot * Redistribution and use in source and binary forms, with or without 8*9558e6acSTreehugger Robot * modification, are permitted provided that the following conditions 9*9558e6acSTreehugger Robot * are met: 10*9558e6acSTreehugger Robot * 1. Redistributions of source code must retain the above copyright 11*9558e6acSTreehugger Robot * notice, this list of conditions and the following disclaimer. 12*9558e6acSTreehugger Robot * 2. Redistributions in binary form must reproduce the above copyright 13*9558e6acSTreehugger Robot * notice, this list of conditions and the following disclaimer in the 14*9558e6acSTreehugger Robot * documentation and/or other materials provided with the distribution. 15*9558e6acSTreehugger Robot * 16*9558e6acSTreehugger Robot * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR 17*9558e6acSTreehugger Robot * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18*9558e6acSTreehugger Robot * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19*9558e6acSTreehugger Robot * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT, 20*9558e6acSTreehugger Robot * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21*9558e6acSTreehugger Robot * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22*9558e6acSTreehugger Robot * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23*9558e6acSTreehugger Robot * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24*9558e6acSTreehugger Robot * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25*9558e6acSTreehugger Robot * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26*9558e6acSTreehugger Robot * $NetBSD: ext.h,v 1.6 2000/04/25 23:02:51 jdolecek Exp $ 27*9558e6acSTreehugger Robot * $FreeBSD$ 28*9558e6acSTreehugger Robot */ 29*9558e6acSTreehugger Robot 30*9558e6acSTreehugger Robot #ifndef EXT_H 31*9558e6acSTreehugger Robot #define EXT_H 32*9558e6acSTreehugger Robot 33*9558e6acSTreehugger Robot #include <sys/types.h> 34*9558e6acSTreehugger Robot 35*9558e6acSTreehugger Robot #include <stdbool.h> 36*9558e6acSTreehugger Robot 37*9558e6acSTreehugger Robot #include "dosfs.h" 38*9558e6acSTreehugger Robot 39*9558e6acSTreehugger Robot #define LOSTDIR "LOST.DIR" 40*9558e6acSTreehugger Robot 41*9558e6acSTreehugger Robot /* 42*9558e6acSTreehugger Robot * Options: 43*9558e6acSTreehugger Robot */ 44*9558e6acSTreehugger Robot extern int alwaysno; /* assume "no" for all questions */ 45*9558e6acSTreehugger Robot extern int alwaysyes; /* assume "yes" for all questions */ 46*9558e6acSTreehugger Robot extern int preen; /* we are preening */ 47*9558e6acSTreehugger Robot extern int rdonly; /* device is opened read only (supersedes above) */ 48*9558e6acSTreehugger Robot extern int skipclean; /* skip clean file systems if preening */ 49*9558e6acSTreehugger Robot extern int allow_mmap; /* allow the use of mmap() */ 50*9558e6acSTreehugger Robot 51*9558e6acSTreehugger Robot /* 52*9558e6acSTreehugger Robot * function declarations 53*9558e6acSTreehugger Robot */ 54*9558e6acSTreehugger Robot int ask(int, const char *, ...) __printflike(2, 3); 55*9558e6acSTreehugger Robot 56*9558e6acSTreehugger Robot /* 57*9558e6acSTreehugger Robot * Check the dirty flag. If the file system is clean, then return 1. 58*9558e6acSTreehugger Robot * Otherwise, return 0 (this includes the case of FAT12 file systems -- 59*9558e6acSTreehugger Robot * they have no dirty flag, so they must be assumed to be unclean). 60*9558e6acSTreehugger Robot */ 61*9558e6acSTreehugger Robot int checkdirty(int, struct bootblock *); 62*9558e6acSTreehugger Robot 63*9558e6acSTreehugger Robot /* 64*9558e6acSTreehugger Robot * Check file system given as arg 65*9558e6acSTreehugger Robot */ 66*9558e6acSTreehugger Robot int checkfilesys(const char *); 67*9558e6acSTreehugger Robot 68*9558e6acSTreehugger Robot /* 69*9558e6acSTreehugger Robot * Return values of various functions 70*9558e6acSTreehugger Robot */ 71*9558e6acSTreehugger Robot #define FSOK 0 /* Check was OK */ 72*9558e6acSTreehugger Robot #define FSBOOTMOD 1 /* Boot block was modified */ 73*9558e6acSTreehugger Robot #define FSDIRMOD 2 /* Some directory was modified */ 74*9558e6acSTreehugger Robot #define FSFATMOD 4 /* The FAT was modified */ 75*9558e6acSTreehugger Robot #define FSERROR 8 /* Some unrecovered error remains */ 76*9558e6acSTreehugger Robot #define FSFATAL 16 /* Some unrecoverable error occurred */ 77*9558e6acSTreehugger Robot #define FSDIRTY 32 /* File system is dirty */ 78*9558e6acSTreehugger Robot 79*9558e6acSTreehugger Robot /* 80*9558e6acSTreehugger Robot * read a boot block in a machine independent fashion and translate 81*9558e6acSTreehugger Robot * it into our struct bootblock. 82*9558e6acSTreehugger Robot */ 83*9558e6acSTreehugger Robot int readboot(int, struct bootblock *); 84*9558e6acSTreehugger Robot 85*9558e6acSTreehugger Robot /* 86*9558e6acSTreehugger Robot * Correct the FSInfo block. 87*9558e6acSTreehugger Robot */ 88*9558e6acSTreehugger Robot int writefsinfo(int, struct bootblock *); 89*9558e6acSTreehugger Robot 90*9558e6acSTreehugger Robot /* Opaque type */ 91*9558e6acSTreehugger Robot struct fat_descriptor; 92*9558e6acSTreehugger Robot 93*9558e6acSTreehugger Robot int cleardirty(struct fat_descriptor *); 94*9558e6acSTreehugger Robot 95*9558e6acSTreehugger Robot void fat_clear_cl_head(struct fat_descriptor *, cl_t); 96*9558e6acSTreehugger Robot bool fat_is_cl_head(struct fat_descriptor *, cl_t); 97*9558e6acSTreehugger Robot 98*9558e6acSTreehugger Robot cl_t fat_get_cl_next(struct fat_descriptor *, cl_t); 99*9558e6acSTreehugger Robot 100*9558e6acSTreehugger Robot int fat_set_cl_next(struct fat_descriptor *, cl_t, cl_t); 101*9558e6acSTreehugger Robot 102*9558e6acSTreehugger Robot cl_t fat_allocate_cluster(struct fat_descriptor *fat); 103*9558e6acSTreehugger Robot 104*9558e6acSTreehugger Robot struct bootblock* fat_get_boot(struct fat_descriptor *); 105*9558e6acSTreehugger Robot int fat_get_fd(struct fat_descriptor *); 106*9558e6acSTreehugger Robot bool fat_is_valid_cl(struct fat_descriptor *, cl_t); 107*9558e6acSTreehugger Robot 108*9558e6acSTreehugger Robot /* 109*9558e6acSTreehugger Robot * Read the FAT 0 and return a pointer to the newly allocated 110*9558e6acSTreehugger Robot * descriptor of it. 111*9558e6acSTreehugger Robot */ 112*9558e6acSTreehugger Robot int readfat(int, struct bootblock *, struct fat_descriptor **); 113*9558e6acSTreehugger Robot 114*9558e6acSTreehugger Robot /* 115*9558e6acSTreehugger Robot * Write back FAT entries 116*9558e6acSTreehugger Robot */ 117*9558e6acSTreehugger Robot int writefat(struct fat_descriptor *); 118*9558e6acSTreehugger Robot 119*9558e6acSTreehugger Robot /* 120*9558e6acSTreehugger Robot * Read a directory 121*9558e6acSTreehugger Robot */ 122*9558e6acSTreehugger Robot int resetDosDirSection(struct fat_descriptor *); 123*9558e6acSTreehugger Robot void finishDosDirSection(void); 124*9558e6acSTreehugger Robot int handleDirTree(struct fat_descriptor *); 125*9558e6acSTreehugger Robot 126*9558e6acSTreehugger Robot /* 127*9558e6acSTreehugger Robot * Cross-check routines run after everything is completely in memory 128*9558e6acSTreehugger Robot */ 129*9558e6acSTreehugger Robot int checkchain(struct fat_descriptor *, cl_t, size_t *); 130*9558e6acSTreehugger Robot 131*9558e6acSTreehugger Robot /* 132*9558e6acSTreehugger Robot * Check for lost cluster chains 133*9558e6acSTreehugger Robot */ 134*9558e6acSTreehugger Robot int checklost(struct fat_descriptor *); 135*9558e6acSTreehugger Robot /* 136*9558e6acSTreehugger Robot * Try to reconnect a lost cluster chain 137*9558e6acSTreehugger Robot */ 138*9558e6acSTreehugger Robot int reconnect(struct fat_descriptor *, cl_t, size_t); 139*9558e6acSTreehugger Robot void finishlf(void); 140*9558e6acSTreehugger Robot 141*9558e6acSTreehugger Robot /* 142*9558e6acSTreehugger Robot * Small helper functions 143*9558e6acSTreehugger Robot */ 144*9558e6acSTreehugger Robot /* 145*9558e6acSTreehugger Robot * Return the type of a reserved cluster as text 146*9558e6acSTreehugger Robot */ 147*9558e6acSTreehugger Robot const char *rsrvdcltype(cl_t); 148*9558e6acSTreehugger Robot 149*9558e6acSTreehugger Robot /* 150*9558e6acSTreehugger Robot * Clear a cluster chain in a FAT 151*9558e6acSTreehugger Robot */ 152*9558e6acSTreehugger Robot void clearchain(struct fat_descriptor *, cl_t); 153*9558e6acSTreehugger Robot 154*9558e6acSTreehugger Robot #endif 155