1330449Seadler/*- 2330449Seadler * SPDX-License-Identifier: BSD-2-Clause-FreeBSD 3330449Seadler * 479455Sobrien * Copyright (C) 1995, 1996, 1997 Wolfgang Solfrank 579455Sobrien * Copyright (c) 1995 Martin Husemann 679455Sobrien * 779455Sobrien * Redistribution and use in source and binary forms, with or without 879455Sobrien * modification, are permitted provided that the following conditions 979455Sobrien * are met: 1079455Sobrien * 1. Redistributions of source code must retain the above copyright 1179455Sobrien * notice, this list of conditions and the following disclaimer. 1279455Sobrien * 2. Redistributions in binary form must reproduce the above copyright 1379455Sobrien * notice, this list of conditions and the following disclaimer in the 1479455Sobrien * documentation and/or other materials provided with the distribution. 1579455Sobrien * 1679455Sobrien * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR 1779455Sobrien * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 1879455Sobrien * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 1979455Sobrien * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT, 2079455Sobrien * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 2179455Sobrien * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 2279455Sobrien * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 2379455Sobrien * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 2479455Sobrien * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 2579455Sobrien * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 2679455Sobrien * $NetBSD: ext.h,v 1.6 2000/04/25 23:02:51 jdolecek Exp $ 2779455Sobrien * $FreeBSD: stable/11/sbin/fsck_msdosfs/ext.h 360490 2020-04-30 06:34:34Z delphij $ 2879455Sobrien */ 2979455Sobrien 3079455Sobrien#ifndef EXT_H 31268635Spfg#define EXT_H 3279455Sobrien 3379455Sobrien#include <sys/types.h> 3479455Sobrien 35360490Sdelphij#include <stdbool.h> 36360490Sdelphij 3779455Sobrien#include "dosfs.h" 3879455Sobrien 3979455Sobrien#define LOSTDIR "LOST.DIR" 4079455Sobrien 4179455Sobrien/* 4279455Sobrien * Options: 4379455Sobrien */ 4479455Sobrienextern int alwaysno; /* assume "no" for all questions */ 4579455Sobrienextern int alwaysyes; /* assume "yes" for all questions */ 4679455Sobrienextern int preen; /* we are preening */ 4779455Sobrienextern int rdonly; /* device is opened read only (supersedes above) */ 48125486Sbdeextern int skipclean; /* skip clean file systems if preening */ 49360490Sdelphijextern int allow_mmap; /* allow the use of mmap() */ 5079455Sobrien 5179455Sobrien/* 5279455Sobrien * function declarations 5379455Sobrien */ 54143315Sstefanfint ask(int, const char *, ...) __printflike(2, 3); 5579455Sobrien 5679455Sobrien/* 57123883Sbde * Check the dirty flag. If the file system is clean, then return 1. 58123883Sbde * Otherwise, return 0 (this includes the case of FAT12 file systems -- 59123883Sbde * they have no dirty flag, so they must be assumed to be unclean). 60123883Sbde */ 61123883Sbdeint checkdirty(int, struct bootblock *); 62123883Sbde 63123883Sbde/* 64102231Strhodes * Check file system given as arg 6579455Sobrien */ 6692839Simpint checkfilesys(const char *); 6779455Sobrien 6879455Sobrien/* 6979455Sobrien * Return values of various functions 7079455Sobrien */ 7179455Sobrien#define FSOK 0 /* Check was OK */ 7279455Sobrien#define FSBOOTMOD 1 /* Boot block was modified */ 7379455Sobrien#define FSDIRMOD 2 /* Some directory was modified */ 7479455Sobrien#define FSFATMOD 4 /* The FAT was modified */ 7579455Sobrien#define FSERROR 8 /* Some unrecovered error remains */ 76203872Skib#define FSFATAL 16 /* Some unrecoverable error occurred */ 77268635Spfg#define FSDIRTY 32 /* File system is dirty */ 7879455Sobrien 7979455Sobrien/* 80203872Skib * read a boot block in a machine independent fashion and translate 8179455Sobrien * it into our struct bootblock. 8279455Sobrien */ 8392839Simpint readboot(int, struct bootblock *); 8479455Sobrien 8579455Sobrien/* 8679455Sobrien * Correct the FSInfo block. 8779455Sobrien */ 8892839Simpint writefsinfo(int, struct bootblock *); 8979455Sobrien 90360490Sdelphij/* Opaque type */ 91360490Sdelphijstruct fat_descriptor; 9279455Sobrien 93360490Sdelphijint cleardirty(struct fat_descriptor *); 9479455Sobrien 95360490Sdelphijvoid fat_clear_cl_head(struct fat_descriptor *, cl_t); 96360490Sdelphijbool fat_is_cl_head(struct fat_descriptor *, cl_t); 97360490Sdelphij 98360490Sdelphijcl_t fat_get_cl_next(struct fat_descriptor *, cl_t); 99360490Sdelphij 100360490Sdelphijint fat_set_cl_next(struct fat_descriptor *, cl_t, cl_t); 101360490Sdelphij 102360490Sdelphijcl_t fat_allocate_cluster(struct fat_descriptor *fat); 103360490Sdelphij 104360490Sdelphijstruct bootblock* fat_get_boot(struct fat_descriptor *); 105360490Sdelphijint fat_get_fd(struct fat_descriptor *); 106360490Sdelphijbool fat_is_valid_cl(struct fat_descriptor *, cl_t); 107360490Sdelphij 10879455Sobrien/* 109360490Sdelphij * Read the FAT 0 and return a pointer to the newly allocated 110360490Sdelphij * descriptor of it. 11179455Sobrien */ 112360490Sdelphijint readfat(int, struct bootblock *, struct fat_descriptor **); 11379455Sobrien 11479455Sobrien/* 11579455Sobrien * Write back FAT entries 11679455Sobrien */ 117360490Sdelphijint writefat(struct fat_descriptor *); 11879455Sobrien 11979455Sobrien/* 12079455Sobrien * Read a directory 12179455Sobrien */ 122360490Sdelphijint resetDosDirSection(struct fat_descriptor *); 12392839Simpvoid finishDosDirSection(void); 124360490Sdelphijint handleDirTree(struct fat_descriptor *); 12579455Sobrien 12679455Sobrien/* 12779455Sobrien * Cross-check routines run after everything is completely in memory 12879455Sobrien */ 129360490Sdelphijint checkchain(struct fat_descriptor *, cl_t, size_t *); 130360490Sdelphij 13179455Sobrien/* 13279455Sobrien * Check for lost cluster chains 13379455Sobrien */ 134360490Sdelphijint checklost(struct fat_descriptor *); 13579455Sobrien/* 13679455Sobrien * Try to reconnect a lost cluster chain 13779455Sobrien */ 138360490Sdelphijint reconnect(struct fat_descriptor *, cl_t, size_t); 13992839Simpvoid finishlf(void); 14079455Sobrien 14179455Sobrien/* 14279455Sobrien * Small helper functions 14379455Sobrien */ 14479455Sobrien/* 14579455Sobrien * Return the type of a reserved cluster as text 14679455Sobrien */ 147241807Suqsconst char *rsrvdcltype(cl_t); 14879455Sobrien 14979455Sobrien/* 15079455Sobrien * Clear a cluster chain in a FAT 15179455Sobrien */ 152360490Sdelphijvoid clearchain(struct fat_descriptor *, cl_t); 15379455Sobrien 15479455Sobrien#endif 155