1/*
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
11 * file.
12 *
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
20 *
21 * @APPLE_LICENSE_HEADER_END@
22 */
23/*
24 * Copyright (C) 1995, 1996, 1997 Wolfgang Solfrank
25 * Copyright (c) 1995 Martin Husemann
26 *
27 * Redistribution and use in source and binary forms, with or without
28 * modification, are permitted provided that the following conditions
29 * are met:
30 * 1. Redistributions of source code must retain the above copyright
31 *    notice, this list of conditions and the following disclaimer.
32 * 2. Redistributions in binary form must reproduce the above copyright
33 *    notice, this list of conditions and the following disclaimer in the
34 *    documentation and/or other materials provided with the distribution.
35 * 3. All advertising materials mentioning features or use of this software
36 *    must display the following acknowledgement:
37 *	This product includes software developed by Martin Husemann
38 *	and Wolfgang Solfrank.
39 * 4. Neither the name of the University nor the names of its contributors
40 *    may be used to endorse or promote products derived from this software
41 *    without specific prior written permission.
42 *
43 * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
44 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
45 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
46 * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT,
47 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
48 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
49 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
50 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
51 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
52 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
53 */
54
55#ifndef EXT_H
56#define EXT_H
57
58#include <sys/types.h>
59
60#include "dosfs.h"
61
62#define	LOSTDIR	"LOST.DIR"
63
64/*
65 * Options:
66 */
67extern int alwaysno;	/* assume "no" for all questions */
68extern int alwaysyes;	/* assume "yes" for all questions */
69extern int preen;	/* we are preening */
70extern int rdonly;	/* device is opened read only (supersedes above) */
71extern int quick;	/* set to quickly check if volume is dirty */
72extern int quiet;	/* set to suppress most messages */
73extern size_t maxmem;	/* If non-zero, limit major allocations to this many bytes */
74
75extern char *fname;	/* filesystem currently checked */
76
77extern struct dosDirEntry *rootDir;
78
79/*
80 * function declarations
81 */
82int ask __P((int, const char *, ...));
83
84/*
85 * Check filesystem given as arg
86 */
87int checkfilesys __P((const char *));
88
89/*
90 * Return values of various functions
91 */
92#define	FSOK		0		/* Check was OK */
93#define	FSBOOTMOD	1		/* Boot block was modified */
94#define	FSDIRMOD	2		/* Some directory was modified */
95#define	FSFATMOD	4		/* The FAT was modified */
96#define	FSERROR		8		/* Some unrecovered error remains */
97#define	FSFATAL		16		/* Some unrecoverable error occured */
98#define FSDIRTY		32		/* File system is dirty */
99#define FSFIXFAT	64		/* Fix file system FAT */
100
101/*
102 * read a boot block in a machine independend fashion and translate
103 * it into our struct bootblock.
104 */
105int readboot __P((int, struct bootblock *));
106
107/*
108 * Correct the FSInfo block.
109 */
110int writefsinfo __P((int, struct bootblock *));
111
112/*
113 * Read a directory
114 */
115int resetDosDirSection(struct bootblock *boot);
116void finishDosDirSection __P((void));
117int handleDirTree(int, struct bootblock *boot);
118
119/*
120 * Small helper functions
121 */
122/*
123 * Return the type of a reserved cluster as text
124 */
125char *rsrvdcltype __P((cl_t));
126
127/*
128 * Routines to read/write the FAT
129 */
130int fat_init(int fs, struct bootblock *boot);
131void fat_uninit(void);
132extern cl_t (*fat_get)(cl_t cluster);
133extern int (*fat_set)(cl_t cluster, cl_t value);
134int fat_free_unused(void);
135int fat_flush(void);
136/*
137 * Determine whether a volume is dirty, without reading the entire FAT.
138 */
139int isdirty(int fs, struct bootblock *boot, int fat);
140/*
141 * Mark the volume "clean."
142 */
143int fat_mark_clean(void);
144
145
146/*
147 * Routines to track which clusters are in use (referenced by some directory entry).
148 */
149/* Returns error if memory cannot be allocated */
150int initUseMap(struct bootblock *boot);
151void freeUseMap(void);
152/* Returns non-zero if block is marked allocated */
153int isUsed(cl_t cluster);
154/* Returns non-zero if cluster already marked allocated */
155int markUsed(cl_t cluster);
156/* Returns non-zero if cluster already marked free */
157int markFree(cl_t cluster);
158
159#endif
160