blob: b50ed4a963d1bfc1cdfbc16afb592fc888c6dbda [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>
Matt Mower18794c82015-11-11 16:22:45 -06004 Copyright (C) 2008-2014 Daniel Baumann <mail@daniel-baumann.ch>
bigbiff bigbiff9c754052013-01-09 09:09:08 -05005
6 This program is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
18
Matt Mower18794c82015-11-11 16:22:45 -060019 THe complete text of the GNU General Public License
bigbiff bigbiff9c754052013-01-09 09:09:08 -050020 can be found in /usr/share/common-licenses/GPL-3 file.
21*/
22
23#ifndef _FAT_H
24#define _FAT_H
25
26void read_fat(DOS_FS * fs);
27
Matt Mower18794c82015-11-11 16:22:45 -060028/* Loads the FAT of the filesystem described by FS. Initializes the FAT,
bigbiff bigbiff9c754052013-01-09 09:09:08 -050029 replaces broken FATs and rejects invalid cluster entries. */
30
Matt Mower18794c82015-11-11 16:22:45 -060031void get_fat(FAT_ENTRY * entry, void *fat, uint32_t cluster, DOS_FS * fs);
bigbiff bigbiff9c754052013-01-09 09:09:08 -050032
33/* Retrieve the FAT entry (next chained cluster) for CLUSTER. */
34
Matt Mower18794c82015-11-11 16:22:45 -060035void set_fat(DOS_FS * fs, uint32_t cluster, int32_t new);
bigbiff bigbiff9c754052013-01-09 09:09:08 -050036
37/* Changes the value of the CLUSTERth cluster of the FAT of FS to NEW. Special
38 values of NEW are -1 (EOF, 0xff8 or 0xfff8) and -2 (bad sector, 0xff7 or
39 0xfff7) */
40
Matt Mower18794c82015-11-11 16:22:45 -060041int bad_cluster(DOS_FS * fs, uint32_t cluster);
bigbiff bigbiff9c754052013-01-09 09:09:08 -050042
43/* Returns a non-zero integer if the CLUSTERth cluster is marked as bad or zero
44 otherwise. */
45
Matt Mower18794c82015-11-11 16:22:45 -060046uint32_t next_cluster(DOS_FS * fs, uint32_t cluster);
bigbiff bigbiff9c754052013-01-09 09:09:08 -050047
48/* Returns the number of the cluster following CLUSTER, or -1 if this is the
49 last cluster of the respective cluster chain. CLUSTER must not be a bad
50 cluster. */
51
Matt Mower18794c82015-11-11 16:22:45 -060052loff_t cluster_start(DOS_FS * fs, uint32_t cluster);
bigbiff bigbiff9c754052013-01-09 09:09:08 -050053
54/* Returns the byte offset of CLUSTER, relative to the respective device. */
55
Matt Mower18794c82015-11-11 16:22:45 -060056void set_owner(DOS_FS * fs, uint32_t cluster, DOS_FILE * owner);
bigbiff bigbiff9c754052013-01-09 09:09:08 -050057
58/* Sets the owner pointer of the respective cluster to OWNER. If OWNER was NULL
59 before, it can be set to NULL or any non-NULL value. Otherwise, only NULL is
60 accepted as the new value. */
61
Matt Mower18794c82015-11-11 16:22:45 -060062DOS_FILE *get_owner(DOS_FS * fs, uint32_t cluster);
bigbiff bigbiff9c754052013-01-09 09:09:08 -050063
64/* Returns the owner of the repective cluster or NULL if the cluster has no
65 owner. */
66
67void fix_bad(DOS_FS * fs);
68
69/* Scans the disk for currently unused bad clusters and marks them as bad. */
70
71void reclaim_free(DOS_FS * fs);
72
73/* Marks all allocated, but unused clusters as free. */
74
75void reclaim_file(DOS_FS * fs);
76
77/* Scans the FAT for chains of allocated, but unused clusters and creates files
78 for them in the root directory. Also tries to fix all inconsistencies (e.g.
79 loops, shared clusters, etc.) in the process. */
80
Matt Mower18794c82015-11-11 16:22:45 -060081uint32_t update_free(DOS_FS * fs);
bigbiff bigbiff9c754052013-01-09 09:09:08 -050082
83/* Updates free cluster count in FSINFO sector. */
84
85#endif