Xin Li | 1e1dad6 | 2019-04-10 13:38:23 -0700 | [diff] [blame] | 1 | /*- |
| 2 | * SPDX-License-Identifier: BSD-2-Clause-FreeBSD |
| 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 | * $NetBSD: ext.h,v 1.6 2000/04/25 23:02:51 jdolecek Exp $ |
| 27 | * $FreeBSD$ |
| 28 | */ |
| 29 | |
| 30 | #ifndef EXT_H |
| 31 | #define EXT_H |
| 32 | |
| 33 | #include <sys/types.h> |
| 34 | |
Xin Li | 21386e0 | 2020-01-03 09:22:03 -0800 | [diff] [blame] | 35 | #include <stdbool.h> |
| 36 | |
Xin Li | 1e1dad6 | 2019-04-10 13:38:23 -0700 | [diff] [blame] | 37 | #include "dosfs.h" |
| 38 | |
| 39 | #define LOSTDIR "LOST.DIR" |
| 40 | |
| 41 | /* |
| 42 | * Options: |
| 43 | */ |
| 44 | extern int alwaysno; /* assume "no" for all questions */ |
| 45 | extern int alwaysyes; /* assume "yes" for all questions */ |
| 46 | extern int preen; /* we are preening */ |
| 47 | extern int rdonly; /* device is opened read only (supersedes above) */ |
| 48 | extern int skipclean; /* skip clean file systems if preening */ |
Xin Li | 21386e0 | 2020-01-03 09:22:03 -0800 | [diff] [blame] | 49 | extern int allow_mmap; /* allow the use of mmap() */ |
Xin Li | 1e1dad6 | 2019-04-10 13:38:23 -0700 | [diff] [blame] | 50 | |
| 51 | /* |
| 52 | * function declarations |
| 53 | */ |
| 54 | int ask(int, const char *, ...) __printflike(2, 3); |
| 55 | |
| 56 | /* |
| 57 | * Check the dirty flag. If the file system is clean, then return 1. |
| 58 | * Otherwise, return 0 (this includes the case of FAT12 file systems -- |
| 59 | * they have no dirty flag, so they must be assumed to be unclean). |
| 60 | */ |
| 61 | int checkdirty(int, struct bootblock *); |
| 62 | |
| 63 | /* |
| 64 | * Check file system given as arg |
| 65 | */ |
| 66 | int checkfilesys(const char *); |
| 67 | |
| 68 | /* |
| 69 | * Return values of various functions |
| 70 | */ |
| 71 | #define FSOK 0 /* Check was OK */ |
| 72 | #define FSBOOTMOD 1 /* Boot block was modified */ |
| 73 | #define FSDIRMOD 2 /* Some directory was modified */ |
| 74 | #define FSFATMOD 4 /* The FAT was modified */ |
| 75 | #define FSERROR 8 /* Some unrecovered error remains */ |
| 76 | #define FSFATAL 16 /* Some unrecoverable error occurred */ |
| 77 | #define FSDIRTY 32 /* File system is dirty */ |
Xin Li | 1e1dad6 | 2019-04-10 13:38:23 -0700 | [diff] [blame] | 78 | |
| 79 | /* |
| 80 | * read a boot block in a machine independent fashion and translate |
| 81 | * it into our struct bootblock. |
| 82 | */ |
| 83 | int readboot(int, struct bootblock *); |
| 84 | |
| 85 | /* |
| 86 | * Correct the FSInfo block. |
| 87 | */ |
| 88 | int writefsinfo(int, struct bootblock *); |
| 89 | |
Xin Li | 21386e0 | 2020-01-03 09:22:03 -0800 | [diff] [blame] | 90 | /* Opaque type */ |
| 91 | struct fat_descriptor; |
| 92 | |
Xin Li | 05ca3f4 | 2020-04-27 09:01:09 -0700 | [diff] [blame] | 93 | int cleardirty(struct fat_descriptor *); |
| 94 | |
Xin Li | 21386e0 | 2020-01-03 09:22:03 -0800 | [diff] [blame] | 95 | void fat_clear_cl_head(struct fat_descriptor *, cl_t); |
| 96 | bool fat_is_cl_head(struct fat_descriptor *, cl_t); |
| 97 | |
| 98 | cl_t fat_get_cl_next(struct fat_descriptor *, cl_t); |
| 99 | |
| 100 | int fat_set_cl_next(struct fat_descriptor *, cl_t, cl_t); |
| 101 | |
| 102 | cl_t fat_allocate_cluster(struct fat_descriptor *fat); |
| 103 | |
| 104 | struct bootblock* fat_get_boot(struct fat_descriptor *); |
| 105 | int fat_get_fd(struct fat_descriptor *); |
| 106 | bool fat_is_valid_cl(struct fat_descriptor *, cl_t); |
Xin Li | 1e1dad6 | 2019-04-10 13:38:23 -0700 | [diff] [blame] | 107 | |
| 108 | /* |
Xin Li | 21386e0 | 2020-01-03 09:22:03 -0800 | [diff] [blame] | 109 | * Read the FAT 0 and return a pointer to the newly allocated |
| 110 | * descriptor of it. |
Xin Li | 1e1dad6 | 2019-04-10 13:38:23 -0700 | [diff] [blame] | 111 | */ |
Xin Li | 21386e0 | 2020-01-03 09:22:03 -0800 | [diff] [blame] | 112 | int readfat(int, struct bootblock *, struct fat_descriptor **); |
Xin Li | 1e1dad6 | 2019-04-10 13:38:23 -0700 | [diff] [blame] | 113 | |
| 114 | /* |
| 115 | * Write back FAT entries |
| 116 | */ |
Xin Li | 21386e0 | 2020-01-03 09:22:03 -0800 | [diff] [blame] | 117 | int writefat(struct fat_descriptor *); |
Xin Li | 1e1dad6 | 2019-04-10 13:38:23 -0700 | [diff] [blame] | 118 | |
| 119 | /* |
| 120 | * Read a directory |
| 121 | */ |
Xin Li | 21386e0 | 2020-01-03 09:22:03 -0800 | [diff] [blame] | 122 | int resetDosDirSection(struct fat_descriptor *); |
Xin Li | 1e1dad6 | 2019-04-10 13:38:23 -0700 | [diff] [blame] | 123 | void finishDosDirSection(void); |
Xin Li | 21386e0 | 2020-01-03 09:22:03 -0800 | [diff] [blame] | 124 | int handleDirTree(struct fat_descriptor *); |
Xin Li | 1e1dad6 | 2019-04-10 13:38:23 -0700 | [diff] [blame] | 125 | |
| 126 | /* |
| 127 | * Cross-check routines run after everything is completely in memory |
| 128 | */ |
Xin Li | 21386e0 | 2020-01-03 09:22:03 -0800 | [diff] [blame] | 129 | int checkchain(struct fat_descriptor *, cl_t, size_t *); |
| 130 | |
Xin Li | 1e1dad6 | 2019-04-10 13:38:23 -0700 | [diff] [blame] | 131 | /* |
| 132 | * Check for lost cluster chains |
| 133 | */ |
Xin Li | 21386e0 | 2020-01-03 09:22:03 -0800 | [diff] [blame] | 134 | int checklost(struct fat_descriptor *); |
Xin Li | 1e1dad6 | 2019-04-10 13:38:23 -0700 | [diff] [blame] | 135 | /* |
| 136 | * Try to reconnect a lost cluster chain |
| 137 | */ |
Xin Li | 21386e0 | 2020-01-03 09:22:03 -0800 | [diff] [blame] | 138 | int reconnect(struct fat_descriptor *, cl_t, size_t); |
Xin Li | 1e1dad6 | 2019-04-10 13:38:23 -0700 | [diff] [blame] | 139 | void finishlf(void); |
| 140 | |
| 141 | /* |
| 142 | * Small helper functions |
| 143 | */ |
| 144 | /* |
| 145 | * Return the type of a reserved cluster as text |
| 146 | */ |
| 147 | const char *rsrvdcltype(cl_t); |
| 148 | |
| 149 | /* |
| 150 | * Clear a cluster chain in a FAT |
| 151 | */ |
Xin Li | 21386e0 | 2020-01-03 09:22:03 -0800 | [diff] [blame] | 152 | void clearchain(struct fat_descriptor *, cl_t); |
Xin Li | 1e1dad6 | 2019-04-10 13:38:23 -0700 | [diff] [blame] | 153 | |
| 154 | #endif |