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