xref: /freebsd/sbin/fsck_msdosfs/ext.h (revision 42b388439bd3795e09258c57a74ce9eec3651c7b)
11de7b4b8SPedro F. Giffuni /*-
2*4d846d26SWarner Losh  * SPDX-License-Identifier: BSD-2-Clause
31de7b4b8SPedro F. Giffuni  *
40121b42aSDavid E. O'Brien  * Copyright (C) 1995, 1996, 1997 Wolfgang Solfrank
50121b42aSDavid E. O'Brien  * Copyright (c) 1995 Martin Husemann
60121b42aSDavid E. O'Brien  *
70121b42aSDavid E. O'Brien  * Redistribution and use in source and binary forms, with or without
80121b42aSDavid E. O'Brien  * modification, are permitted provided that the following conditions
90121b42aSDavid E. O'Brien  * are met:
100121b42aSDavid E. O'Brien  * 1. Redistributions of source code must retain the above copyright
110121b42aSDavid E. O'Brien  *    notice, this list of conditions and the following disclaimer.
120121b42aSDavid E. O'Brien  * 2. Redistributions in binary form must reproduce the above copyright
130121b42aSDavid E. O'Brien  *    notice, this list of conditions and the following disclaimer in the
140121b42aSDavid E. O'Brien  *    documentation and/or other materials provided with the distribution.
150121b42aSDavid E. O'Brien  *
160121b42aSDavid E. O'Brien  * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
170121b42aSDavid E. O'Brien  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
180121b42aSDavid E. O'Brien  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
190121b42aSDavid E. O'Brien  * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT,
200121b42aSDavid E. O'Brien  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
210121b42aSDavid E. O'Brien  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
220121b42aSDavid E. O'Brien  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
230121b42aSDavid E. O'Brien  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
240121b42aSDavid E. O'Brien  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
250121b42aSDavid E. O'Brien  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
260121b42aSDavid E. O'Brien  *	$NetBSD: ext.h,v 1.6 2000/04/25 23:02:51 jdolecek Exp $
270121b42aSDavid E. O'Brien  */
280121b42aSDavid E. O'Brien 
290121b42aSDavid E. O'Brien #ifndef EXT_H
300121b42aSDavid E. O'Brien #define	EXT_H
310121b42aSDavid E. O'Brien 
320121b42aSDavid E. O'Brien #include <sys/types.h>
330121b42aSDavid E. O'Brien 
349708ba9fSXin LI #include <stdbool.h>
359708ba9fSXin LI 
360121b42aSDavid E. O'Brien #include "dosfs.h"
370121b42aSDavid E. O'Brien 
380121b42aSDavid E. O'Brien #define	LOSTDIR	"LOST.DIR"
390121b42aSDavid E. O'Brien 
400121b42aSDavid E. O'Brien /*
410121b42aSDavid E. O'Brien  * Options:
420121b42aSDavid E. O'Brien  */
430121b42aSDavid E. O'Brien extern int alwaysno;	/* assume "no" for all questions */
440121b42aSDavid E. O'Brien extern int alwaysyes;	/* assume "yes" for all questions */
450121b42aSDavid E. O'Brien extern int preen;	/* we are preening */
460121b42aSDavid E. O'Brien extern int rdonly;	/* device is opened read only (supersedes above) */
47ae62d940SBruce Evans extern int skipclean;	/* skip clean file systems if preening */
489708ba9fSXin LI extern int allow_mmap;  /* allow the use of mmap() */
490121b42aSDavid E. O'Brien 
500121b42aSDavid E. O'Brien /*
510121b42aSDavid E. O'Brien  * function declarations
520121b42aSDavid E. O'Brien  */
534eb55c7aSStefan Farfeleder int ask(int, const char *, ...) __printflike(2, 3);
540121b42aSDavid E. O'Brien 
550121b42aSDavid E. O'Brien /*
5630b48d7fSBruce Evans  * Check the dirty flag.  If the file system is clean, then return 1.
5730b48d7fSBruce Evans  * Otherwise, return 0 (this includes the case of FAT12 file systems --
5830b48d7fSBruce Evans  * they have no dirty flag, so they must be assumed to be unclean).
5930b48d7fSBruce Evans  */
6030b48d7fSBruce Evans int checkdirty(int, struct bootblock *);
6130b48d7fSBruce Evans 
6230b48d7fSBruce Evans /*
630121b42aSDavid E. O'Brien  * Check file system given as arg
640121b42aSDavid E. O'Brien  */
65b70cd7eeSWarner Losh int checkfilesys(const char *);
660121b42aSDavid E. O'Brien 
670121b42aSDavid E. O'Brien /*
680121b42aSDavid E. O'Brien  * Return values of various functions
690121b42aSDavid E. O'Brien  */
700121b42aSDavid E. O'Brien #define	FSOK		0		/* Check was OK */
710121b42aSDavid E. O'Brien #define	FSBOOTMOD	1		/* Boot block was modified */
720121b42aSDavid E. O'Brien #define	FSDIRMOD	2		/* Some directory was modified */
730121b42aSDavid E. O'Brien #define	FSFATMOD	4		/* The FAT was modified */
740121b42aSDavid E. O'Brien #define	FSERROR		8		/* Some unrecovered error remains */
756069db97SKonstantin Belousov #define	FSFATAL		16		/* Some unrecoverable error occurred */
760121b42aSDavid E. O'Brien #define	FSDIRTY		32		/* File system is dirty */
770121b42aSDavid E. O'Brien 
780121b42aSDavid E. O'Brien /*
796069db97SKonstantin Belousov  * read a boot block in a machine independent fashion and translate
800121b42aSDavid E. O'Brien  * it into our struct bootblock.
810121b42aSDavid E. O'Brien  */
82b70cd7eeSWarner Losh int readboot(int, struct bootblock *);
830121b42aSDavid E. O'Brien 
840121b42aSDavid E. O'Brien /*
850121b42aSDavid E. O'Brien  * Correct the FSInfo block.
860121b42aSDavid E. O'Brien  */
87b70cd7eeSWarner Losh int writefsinfo(int, struct bootblock *);
880121b42aSDavid E. O'Brien 
899708ba9fSXin LI /* Opaque type */
909708ba9fSXin LI struct fat_descriptor;
919708ba9fSXin LI 
92401475f5SXin LI int cleardirty(struct fat_descriptor *);
93401475f5SXin LI 
949708ba9fSXin LI void fat_clear_cl_head(struct fat_descriptor *, cl_t);
959708ba9fSXin LI bool fat_is_cl_head(struct fat_descriptor *, cl_t);
969708ba9fSXin LI 
979708ba9fSXin LI cl_t fat_get_cl_next(struct fat_descriptor *, cl_t);
989708ba9fSXin LI 
999708ba9fSXin LI int fat_set_cl_next(struct fat_descriptor *, cl_t, cl_t);
1009708ba9fSXin LI 
1019708ba9fSXin LI cl_t fat_allocate_cluster(struct fat_descriptor *fat);
1029708ba9fSXin LI 
1039708ba9fSXin LI struct bootblock* fat_get_boot(struct fat_descriptor *);
1049708ba9fSXin LI int fat_get_fd(struct fat_descriptor *);
1059708ba9fSXin LI bool fat_is_valid_cl(struct fat_descriptor *, cl_t);
1060121b42aSDavid E. O'Brien 
1070121b42aSDavid E. O'Brien /*
1089708ba9fSXin LI  * Read the FAT 0 and return a pointer to the newly allocated
1099708ba9fSXin LI  * descriptor of it.
1100121b42aSDavid E. O'Brien  */
1119708ba9fSXin LI int readfat(int, struct bootblock *, struct fat_descriptor **);
1120121b42aSDavid E. O'Brien 
1130121b42aSDavid E. O'Brien /*
1140121b42aSDavid E. O'Brien  * Write back FAT entries
1150121b42aSDavid E. O'Brien  */
1169708ba9fSXin LI int writefat(struct fat_descriptor *);
1170121b42aSDavid E. O'Brien 
1180121b42aSDavid E. O'Brien /*
1190121b42aSDavid E. O'Brien  * Read a directory
1200121b42aSDavid E. O'Brien  */
1219708ba9fSXin LI int resetDosDirSection(struct fat_descriptor *);
122b70cd7eeSWarner Losh void finishDosDirSection(void);
1239708ba9fSXin LI int handleDirTree(struct fat_descriptor *);
1240121b42aSDavid E. O'Brien 
1250121b42aSDavid E. O'Brien /*
1260121b42aSDavid E. O'Brien  * Cross-check routines run after everything is completely in memory
1270121b42aSDavid E. O'Brien  */
1289708ba9fSXin LI int checkchain(struct fat_descriptor *, cl_t, size_t *);
1299708ba9fSXin LI 
1300121b42aSDavid E. O'Brien /*
1310121b42aSDavid E. O'Brien  * Check for lost cluster chains
1320121b42aSDavid E. O'Brien  */
1339708ba9fSXin LI int checklost(struct fat_descriptor *);
1340121b42aSDavid E. O'Brien /*
1350121b42aSDavid E. O'Brien  * Try to reconnect a lost cluster chain
1360121b42aSDavid E. O'Brien  */
1379708ba9fSXin LI int reconnect(struct fat_descriptor *, cl_t, size_t);
138b70cd7eeSWarner Losh void finishlf(void);
1390121b42aSDavid E. O'Brien 
1400121b42aSDavid E. O'Brien /*
1410121b42aSDavid E. O'Brien  * Small helper functions
1420121b42aSDavid E. O'Brien  */
1430121b42aSDavid E. O'Brien /*
1440121b42aSDavid E. O'Brien  * Return the type of a reserved cluster as text
1450121b42aSDavid E. O'Brien  */
1463bbc4438SUlrich Spörlein const char *rsrvdcltype(cl_t);
1470121b42aSDavid E. O'Brien 
1480121b42aSDavid E. O'Brien /*
1490121b42aSDavid E. O'Brien  * Clear a cluster chain in a FAT
1500121b42aSDavid E. O'Brien  */
1519708ba9fSXin LI void clearchain(struct fat_descriptor *, cl_t);
1520121b42aSDavid E. O'Brien 
1530121b42aSDavid E. O'Brien #endif
154