remove trailing spaces
[libfat.git] / source / file_allocation_table.h
blob560c616d589aa30d689e61b925593ae5162ad306
1 /*
2 file_allocation_table.h
3 Reading, writing and manipulation of the FAT structure on
4 a FAT partition
6 Copyright (c) 2006 Michael "Chishm" Chisholm
8 Redistribution and use in source and binary forms, with or without modification,
9 are permitted provided that the following conditions are met:
11 1. Redistributions of source code must retain the above copyright notice,
12 this list of conditions and the following disclaimer.
13 2. Redistributions in binary form must reproduce the above copyright notice,
14 this list of conditions and the following disclaimer in the documentation and/or
15 other materials provided with the distribution.
16 3. The name of the author may not be used to endorse or promote products derived
17 from this software without specific prior written permission.
19 THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
20 WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
21 AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE
22 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
27 EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 #ifndef _FAT_H
31 #define _FAT_H
33 #include "common.h"
34 #include "partition.h"
36 #define CLUSTER_EOF_16 0xFFFF
37 #define CLUSTER_EOF 0x0FFFFFFF
38 #define CLUSTER_FREE 0x00000000
39 #define CLUSTER_ROOT 0x00000000
40 #define CLUSTER_FIRST 0x00000002
41 #define CLUSTER_ERROR 0xFFFFFFFF
43 #define CLUSTERS_PER_FAT12 4085
44 #define CLUSTERS_PER_FAT16 65525
47 uint32_t _FAT_fat_nextCluster(PARTITION* partition, uint32_t cluster);
49 uint32_t _FAT_fat_linkFreeCluster(PARTITION* partition, uint32_t cluster);
50 uint32_t _FAT_fat_linkFreeClusterCleared (PARTITION* partition, uint32_t cluster);
52 bool _FAT_fat_clearLinks (PARTITION* partition, uint32_t cluster);
54 uint32_t _FAT_fat_trimChain (PARTITION* partition, uint32_t startCluster, unsigned int chainLength);
56 uint32_t _FAT_fat_lastCluster (PARTITION* partition, uint32_t cluster);
58 unsigned int _FAT_fat_freeClusterCount (PARTITION* partition);
60 static inline sec_t _FAT_fat_clusterToSector (PARTITION* partition, uint32_t cluster) {
61 return (cluster >= CLUSTER_FIRST) ?
62 ((cluster - CLUSTER_FIRST) * (sec_t)partition->sectorsPerCluster) + partition->dataStart :
63 partition->rootDirStart;
66 static inline bool _FAT_fat_isValidCluster (PARTITION* partition, uint32_t cluster) {
67 return (cluster >= CLUSTER_FIRST) && (cluster <= partition->fat.lastCluster /* This will catch CLUSTER_ERROR */);
70 #endif // _FAT_H