179455Sobrien/*
279455Sobrien * Copyright (C) 1995, 1996, 1997 Wolfgang Solfrank
379455Sobrien * Copyright (c) 1995 Martin Husemann
479455Sobrien *
579455Sobrien * Redistribution and use in source and binary forms, with or without
679455Sobrien * modification, are permitted provided that the following conditions
779455Sobrien * are met:
879455Sobrien * 1. Redistributions of source code must retain the above copyright
979455Sobrien *    notice, this list of conditions and the following disclaimer.
1079455Sobrien * 2. Redistributions in binary form must reproduce the above copyright
1179455Sobrien *    notice, this list of conditions and the following disclaimer in the
1279455Sobrien *    documentation and/or other materials provided with the distribution.
1379455Sobrien *
1479455Sobrien * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
1579455Sobrien * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
1679455Sobrien * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
1779455Sobrien * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT,
1879455Sobrien * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
1979455Sobrien * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2079455Sobrien * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2179455Sobrien * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2279455Sobrien * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
2379455Sobrien * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2479455Sobrien *	$NetBSD: ext.h,v 1.6 2000/04/25 23:02:51 jdolecek Exp $
2579455Sobrien * $FreeBSD$
2679455Sobrien */
2779455Sobrien
2879455Sobrien#ifndef EXT_H
2979455Sobrien#define EXT_H
3079455Sobrien
3179455Sobrien#include <sys/types.h>
3279455Sobrien
3379455Sobrien#include "dosfs.h"
3479455Sobrien
3579455Sobrien#define	LOSTDIR	"LOST.DIR"
3679455Sobrien
3779455Sobrien/*
3879455Sobrien * Options:
3979455Sobrien */
4079455Sobrienextern int alwaysno;	/* assume "no" for all questions */
4179455Sobrienextern int alwaysyes;	/* assume "yes" for all questions */
4279455Sobrienextern int preen;	/* we are preening */
4379455Sobrienextern int rdonly;	/* device is opened read only (supersedes above) */
44125486Sbdeextern int skipclean;	/* skip clean file systems if preening */
4579455Sobrien
4679455Sobrienextern struct dosDirEntry *rootDir;
4779455Sobrien
4879455Sobrien/*
4979455Sobrien * function declarations
5079455Sobrien */
51143315Sstefanfint ask(int, const char *, ...) __printflike(2, 3);
5279455Sobrien
5379455Sobrien/*
54123883Sbde * Check the dirty flag.  If the file system is clean, then return 1.
55123883Sbde * Otherwise, return 0 (this includes the case of FAT12 file systems --
56123883Sbde * they have no dirty flag, so they must be assumed to be unclean).
57123883Sbde */
58123883Sbdeint checkdirty(int, struct bootblock *);
59123883Sbde
60123883Sbde/*
61102231Strhodes * Check file system given as arg
6279455Sobrien */
6392839Simpint checkfilesys(const char *);
6479455Sobrien
6579455Sobrien/*
6679455Sobrien * Return values of various functions
6779455Sobrien */
6879455Sobrien#define	FSOK		0		/* Check was OK */
6979455Sobrien#define	FSBOOTMOD	1		/* Boot block was modified */
7079455Sobrien#define	FSDIRMOD	2		/* Some directory was modified */
7179455Sobrien#define	FSFATMOD	4		/* The FAT was modified */
7279455Sobrien#define	FSERROR		8		/* Some unrecovered error remains */
73203872Skib#define	FSFATAL		16		/* Some unrecoverable error occurred */
7479455Sobrien#define FSDIRTY		32		/* File system is dirty */
75102231Strhodes#define FSFIXFAT	64		/* Fix file system FAT */
7679455Sobrien
7779455Sobrien/*
78203872Skib * read a boot block in a machine independent fashion and translate
7979455Sobrien * it into our struct bootblock.
8079455Sobrien */
8192839Simpint readboot(int, struct bootblock *);
8279455Sobrien
8379455Sobrien/*
8479455Sobrien * Correct the FSInfo block.
8579455Sobrien */
8692839Simpint writefsinfo(int, struct bootblock *);
8779455Sobrien
8879455Sobrien/*
8979455Sobrien * Read one of the FAT copies and return a pointer to the new
9079455Sobrien * allocated array holding our description of it.
9179455Sobrien */
92203872Skibint readfat(int, struct bootblock *, u_int, struct fatEntry **);
9379455Sobrien
9479455Sobrien/*
9579455Sobrien * Check two FAT copies for consistency and merge changes into the
96203872Skib * first if necessary.
9779455Sobrien */
98203872Skibint comparefat(struct bootblock *, struct fatEntry *, struct fatEntry *, u_int);
9979455Sobrien
10079455Sobrien/*
10179455Sobrien * Check a FAT
10279455Sobrien */
10392839Simpint checkfat(struct bootblock *, struct fatEntry *);
10479455Sobrien
10579455Sobrien/*
10679455Sobrien * Write back FAT entries
10779455Sobrien */
10892839Simpint writefat(int, struct bootblock *, struct fatEntry *, int);
10979455Sobrien
11079455Sobrien/*
11179455Sobrien * Read a directory
11279455Sobrien */
11392839Simpint resetDosDirSection(struct bootblock *, struct fatEntry *);
11492839Simpvoid finishDosDirSection(void);
11592839Simpint handleDirTree(int, struct bootblock *, struct fatEntry *);
11679455Sobrien
11779455Sobrien/*
11879455Sobrien * Cross-check routines run after everything is completely in memory
11979455Sobrien */
12079455Sobrien/*
12179455Sobrien * Check for lost cluster chains
12279455Sobrien */
12392839Simpint checklost(int, struct bootblock *, struct fatEntry *);
12479455Sobrien/*
12579455Sobrien * Try to reconnect a lost cluster chain
12679455Sobrien */
12792839Simpint reconnect(int, struct bootblock *, struct fatEntry *, cl_t);
12892839Simpvoid finishlf(void);
12979455Sobrien
13079455Sobrien/*
13179455Sobrien * Small helper functions
13279455Sobrien */
13379455Sobrien/*
13479455Sobrien * Return the type of a reserved cluster as text
13579455Sobrien */
13692839Simpchar *rsrvdcltype(cl_t);
13779455Sobrien
13879455Sobrien/*
13979455Sobrien * Clear a cluster chain in a FAT
14079455Sobrien */
14192839Simpvoid clearchain(struct bootblock *, struct fatEntry *, cl_t);
14279455Sobrien
14379455Sobrien#endif
144