bigbiff bigbiff | 9c75405 | 2013-01-09 09:09:08 -0500 | [diff] [blame] | 1 | /* fat.h - Read/write access to the FAT |
| 2 | |
| 3 | Copyright (C) 1993 Werner Almesberger <werner.almesberger@lrc.di.epfl.ch> |
Matt Mower | 18794c8 | 2015-11-11 16:22:45 -0600 | [diff] [blame] | 4 | Copyright (C) 2008-2014 Daniel Baumann <mail@daniel-baumann.ch> |
bigbiff bigbiff | 9c75405 | 2013-01-09 09:09:08 -0500 | [diff] [blame] | 5 | |
| 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 Mower | 18794c8 | 2015-11-11 16:22:45 -0600 | [diff] [blame] | 19 | THe complete text of the GNU General Public License |
bigbiff bigbiff | 9c75405 | 2013-01-09 09:09:08 -0500 | [diff] [blame] | 20 | can be found in /usr/share/common-licenses/GPL-3 file. |
| 21 | */ |
| 22 | |
| 23 | #ifndef _FAT_H |
| 24 | #define _FAT_H |
| 25 | |
| 26 | void read_fat(DOS_FS * fs); |
| 27 | |
Matt Mower | 18794c8 | 2015-11-11 16:22:45 -0600 | [diff] [blame] | 28 | /* Loads the FAT of the filesystem described by FS. Initializes the FAT, |
bigbiff bigbiff | 9c75405 | 2013-01-09 09:09:08 -0500 | [diff] [blame] | 29 | replaces broken FATs and rejects invalid cluster entries. */ |
| 30 | |
Matt Mower | 18794c8 | 2015-11-11 16:22:45 -0600 | [diff] [blame] | 31 | void get_fat(FAT_ENTRY * entry, void *fat, uint32_t cluster, DOS_FS * fs); |
bigbiff bigbiff | 9c75405 | 2013-01-09 09:09:08 -0500 | [diff] [blame] | 32 | |
| 33 | /* Retrieve the FAT entry (next chained cluster) for CLUSTER. */ |
| 34 | |
Matt Mower | 18794c8 | 2015-11-11 16:22:45 -0600 | [diff] [blame] | 35 | void set_fat(DOS_FS * fs, uint32_t cluster, int32_t new); |
bigbiff bigbiff | 9c75405 | 2013-01-09 09:09:08 -0500 | [diff] [blame] | 36 | |
| 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 Mower | 18794c8 | 2015-11-11 16:22:45 -0600 | [diff] [blame] | 41 | int bad_cluster(DOS_FS * fs, uint32_t cluster); |
bigbiff bigbiff | 9c75405 | 2013-01-09 09:09:08 -0500 | [diff] [blame] | 42 | |
| 43 | /* Returns a non-zero integer if the CLUSTERth cluster is marked as bad or zero |
| 44 | otherwise. */ |
| 45 | |
Matt Mower | 18794c8 | 2015-11-11 16:22:45 -0600 | [diff] [blame] | 46 | uint32_t next_cluster(DOS_FS * fs, uint32_t cluster); |
bigbiff bigbiff | 9c75405 | 2013-01-09 09:09:08 -0500 | [diff] [blame] | 47 | |
| 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 Mower | 18794c8 | 2015-11-11 16:22:45 -0600 | [diff] [blame] | 52 | loff_t cluster_start(DOS_FS * fs, uint32_t cluster); |
bigbiff bigbiff | 9c75405 | 2013-01-09 09:09:08 -0500 | [diff] [blame] | 53 | |
| 54 | /* Returns the byte offset of CLUSTER, relative to the respective device. */ |
| 55 | |
Matt Mower | 18794c8 | 2015-11-11 16:22:45 -0600 | [diff] [blame] | 56 | void set_owner(DOS_FS * fs, uint32_t cluster, DOS_FILE * owner); |
bigbiff bigbiff | 9c75405 | 2013-01-09 09:09:08 -0500 | [diff] [blame] | 57 | |
| 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 Mower | 18794c8 | 2015-11-11 16:22:45 -0600 | [diff] [blame] | 62 | DOS_FILE *get_owner(DOS_FS * fs, uint32_t cluster); |
bigbiff bigbiff | 9c75405 | 2013-01-09 09:09:08 -0500 | [diff] [blame] | 63 | |
| 64 | /* Returns the owner of the repective cluster or NULL if the cluster has no |
| 65 | owner. */ |
| 66 | |
| 67 | void fix_bad(DOS_FS * fs); |
| 68 | |
| 69 | /* Scans the disk for currently unused bad clusters and marks them as bad. */ |
| 70 | |
| 71 | void reclaim_free(DOS_FS * fs); |
| 72 | |
| 73 | /* Marks all allocated, but unused clusters as free. */ |
| 74 | |
| 75 | void 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 Mower | 18794c8 | 2015-11-11 16:22:45 -0600 | [diff] [blame] | 81 | uint32_t update_free(DOS_FS * fs); |
bigbiff bigbiff | 9c75405 | 2013-01-09 09:09:08 -0500 | [diff] [blame] | 82 | |
| 83 | /* Updates free cluster count in FSINFO sector. */ |
| 84 | |
| 85 | #endif |