blob: 13ac1b345fb7011d8ca59000f49bf27cf011c3e1 [file] [log] [blame]
bigbiff bigbiff9c754052013-01-09 09:09:08 -05001/* fat.h - Read/write access to the FAT
2
3 Copyright (C) 1993 Werner Almesberger <werner.almesberger@lrc.di.epfl.ch>
4
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 On Debian systems, the complete text of the GNU General Public License
19 can be found in /usr/share/common-licenses/GPL-3 file.
20*/
21
22#ifndef _FAT_H
23#define _FAT_H
24
25void read_fat(DOS_FS * fs);
26
27/* Loads the FAT of the file system described by FS. Initializes the FAT,
28 replaces broken FATs and rejects invalid cluster entries. */
29
30void get_fat(FAT_ENTRY * entry, void *fat, unsigned long cluster, DOS_FS * fs);
31
32/* Retrieve the FAT entry (next chained cluster) for CLUSTER. */
33
34void set_fat(DOS_FS * fs, unsigned long cluster, unsigned long new);
35
36/* Changes the value of the CLUSTERth cluster of the FAT of FS to NEW. Special
37 values of NEW are -1 (EOF, 0xff8 or 0xfff8) and -2 (bad sector, 0xff7 or
38 0xfff7) */
39
40int bad_cluster(DOS_FS * fs, unsigned long cluster);
41
42/* Returns a non-zero integer if the CLUSTERth cluster is marked as bad or zero
43 otherwise. */
44
45unsigned long next_cluster(DOS_FS * fs, unsigned long cluster);
46
47/* Returns the number of the cluster following CLUSTER, or -1 if this is the
48 last cluster of the respective cluster chain. CLUSTER must not be a bad
49 cluster. */
50
51loff_t cluster_start(DOS_FS * fs, unsigned long cluster);
52
53/* Returns the byte offset of CLUSTER, relative to the respective device. */
54
55void set_owner(DOS_FS * fs, unsigned long cluster, DOS_FILE * owner);
56
57/* Sets the owner pointer of the respective cluster to OWNER. If OWNER was NULL
58 before, it can be set to NULL or any non-NULL value. Otherwise, only NULL is
59 accepted as the new value. */
60
61DOS_FILE *get_owner(DOS_FS * fs, unsigned long cluster);
62
63/* Returns the owner of the repective cluster or NULL if the cluster has no
64 owner. */
65
66void fix_bad(DOS_FS * fs);
67
68/* Scans the disk for currently unused bad clusters and marks them as bad. */
69
70void reclaim_free(DOS_FS * fs);
71
72/* Marks all allocated, but unused clusters as free. */
73
74void reclaim_file(DOS_FS * fs);
75
76/* Scans the FAT for chains of allocated, but unused clusters and creates files
77 for them in the root directory. Also tries to fix all inconsistencies (e.g.
78 loops, shared clusters, etc.) in the process. */
79
80unsigned long update_free(DOS_FS * fs);
81
82/* Updates free cluster count in FSINFO sector. */
83
84#endif