xref: /openbsd-src/sbin/fsck_msdos/ext.h (revision 8c63c13268086909bf9a168f87199fdf3bbe3e46)
1*8c63c132Sguenther /*	$OpenBSD: ext.h,v 1.13 2015/09/27 16:56:06 guenther Exp $	*/
2b099d67bSprovos /*	$NetBSD: ext.h,v 1.5 1997/10/17 11:19:48 ws Exp $	*/
32a4cde9cSderaadt 
49646ab25Sderaadt /*
5b099d67bSprovos  * Copyright (C) 1995, 1996, 1997 Wolfgang Solfrank
69646ab25Sderaadt  * Copyright (c) 1995 Martin Husemann
79646ab25Sderaadt  *
89646ab25Sderaadt  * Redistribution and use in source and binary forms, with or without
99646ab25Sderaadt  * modification, are permitted provided that the following conditions
109646ab25Sderaadt  * are met:
119646ab25Sderaadt  * 1. Redistributions of source code must retain the above copyright
129646ab25Sderaadt  *    notice, this list of conditions and the following disclaimer.
139646ab25Sderaadt  * 2. Redistributions in binary form must reproduce the above copyright
149646ab25Sderaadt  *    notice, this list of conditions and the following disclaimer in the
159646ab25Sderaadt  *    documentation and/or other materials provided with the distribution.
169646ab25Sderaadt  *
179646ab25Sderaadt  * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
189646ab25Sderaadt  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
199646ab25Sderaadt  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
209646ab25Sderaadt  * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT,
219646ab25Sderaadt  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
229646ab25Sderaadt  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
239646ab25Sderaadt  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
249646ab25Sderaadt  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
259646ab25Sderaadt  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
269646ab25Sderaadt  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
279646ab25Sderaadt  */
289646ab25Sderaadt 
299646ab25Sderaadt #ifndef EXT_H
309646ab25Sderaadt #define EXT_H
319646ab25Sderaadt 
329646ab25Sderaadt #include <sys/types.h>
339646ab25Sderaadt 
349646ab25Sderaadt #include "dosfs.h"
35a0dbeb59Smillert #include "fsutil.h"
369646ab25Sderaadt 
379646ab25Sderaadt #define	LOSTDIR	"LOST.DIR"
389646ab25Sderaadt 
399646ab25Sderaadt /*
409646ab25Sderaadt  * Options:
419646ab25Sderaadt  */
429646ab25Sderaadt extern int alwaysno;	/* assume "no" for all questions */
439646ab25Sderaadt extern int alwaysyes;	/* assume "yes" for all questions */
449646ab25Sderaadt extern int preen;	/* we are preening */
459646ab25Sderaadt extern int rdonly;	/* device is opened read only (supersedes above) */
469646ab25Sderaadt 
4798fba8a9Skrw extern struct disklabel lab;
489646ab25Sderaadt 
499646ab25Sderaadt /*
509646ab25Sderaadt  * function declarations
519646ab25Sderaadt  */
52*8c63c132Sguenther int ask(int, const char *, ...) __attribute__((__format__ (printf, 2, 3)));
539646ab25Sderaadt 
549646ab25Sderaadt /*
559646ab25Sderaadt  * Check filesystem given as arg
569646ab25Sderaadt  */
57c72b5b24Smillert int checkfilesys(const char *);
589646ab25Sderaadt 
599646ab25Sderaadt /*
609646ab25Sderaadt  * Return values of various functions
619646ab25Sderaadt  */
629646ab25Sderaadt #define	FSOK		0		/* Check was OK */
63b099d67bSprovos #define	FSBOOTMOD	1		/* Boot block was modified */
64b099d67bSprovos #define	FSDIRMOD	2		/* Some directory was modified */
65b099d67bSprovos #define	FSFATMOD	4		/* The FAT was modified */
66b099d67bSprovos #define	FSERROR		8		/* Some unrecovered error remains */
6761e6c220Smpech #define	FSFATAL		16		/* Some unrecoverable error occurred */
689646ab25Sderaadt 
699646ab25Sderaadt /*
7097367dacSian  * read a boot block in a machine independent fashion and translate
719646ab25Sderaadt  * it into our struct bootblock.
729646ab25Sderaadt  */
73c72b5b24Smillert int readboot(int, struct bootblock *);
749646ab25Sderaadt 
75b099d67bSprovos /*
76b099d67bSprovos  * Correct the FSInfo block.
77b099d67bSprovos  */
78c72b5b24Smillert int writefsinfo(int, struct bootblock *);
799646ab25Sderaadt 
809646ab25Sderaadt /*
819646ab25Sderaadt  * Read one of the FAT copies and return a pointer to the new
829646ab25Sderaadt  * allocated array holding our description of it.
839646ab25Sderaadt  */
84c72b5b24Smillert int readfat(int, struct bootblock *, int, struct fatEntry **);
859646ab25Sderaadt 
869646ab25Sderaadt /*
879646ab25Sderaadt  * Check two FAT copies for consistency and merge changes into the
88ed5470abSdavid  * first if necessary.
899646ab25Sderaadt  */
90c72b5b24Smillert int comparefat(struct bootblock *, struct fatEntry *, struct fatEntry *, int);
919646ab25Sderaadt 
929646ab25Sderaadt /*
939646ab25Sderaadt  * Check a FAT
949646ab25Sderaadt  */
95c72b5b24Smillert int checkfat(struct bootblock *, struct fatEntry *);
969646ab25Sderaadt 
979646ab25Sderaadt /*
989646ab25Sderaadt  * Write back FAT entries
999646ab25Sderaadt  */
100c72b5b24Smillert int writefat(int, struct bootblock *, struct fatEntry *);
1019646ab25Sderaadt 
1029646ab25Sderaadt /*
1039646ab25Sderaadt  * Read a directory
1049646ab25Sderaadt  */
105c72b5b24Smillert int resetDosDirSection(struct bootblock *, struct fatEntry *);
106c72b5b24Smillert void finishDosDirSection(void);
107c72b5b24Smillert int handleDirTree(int, struct bootblock *, struct fatEntry *);
1089646ab25Sderaadt 
1099646ab25Sderaadt /*
1109646ab25Sderaadt  * Cross-check routines run after everything is completely in memory
1119646ab25Sderaadt  */
1129646ab25Sderaadt /*
1139646ab25Sderaadt  * Check for lost cluster chains
1149646ab25Sderaadt  */
115c72b5b24Smillert int checklost(int, struct bootblock *, struct fatEntry *);
1169646ab25Sderaadt /*
1179646ab25Sderaadt  * Try to reconnect a lost cluster chain
1189646ab25Sderaadt  */
119c72b5b24Smillert int reconnect(int, struct bootblock *, struct fatEntry *, cl_t);
120c72b5b24Smillert void finishlf(void);
1219646ab25Sderaadt 
1229646ab25Sderaadt /*
1239646ab25Sderaadt  * Small helper functions
1249646ab25Sderaadt  */
1259646ab25Sderaadt /*
1269646ab25Sderaadt  * Return the type of a reserved cluster as text
1279646ab25Sderaadt  */
128c72b5b24Smillert char *rsrvdcltype(cl_t);
1299646ab25Sderaadt 
1309646ab25Sderaadt /*
1319646ab25Sderaadt  * Clear a cluster chain in a FAT
1329646ab25Sderaadt  */
133c72b5b24Smillert void clearchain(struct bootblock *, struct fatEntry *, cl_t);
1349646ab25Sderaadt 
1359646ab25Sderaadt #endif
136