RetroArch
file_allocation_table.h
Go to the documentation of this file.
1 /*
2  file_allocation_table.h
3  Reading, writing and manipulation of the FAT structure on
4  a FAT partition
5 
6  Copyright (c) 2006 Michael "Chishm" Chisholm
7 
8  Redistribution and use in source and binary forms, with or without modification,
9  are permitted provided that the following conditions are met:
10 
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.
18 
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.
28 */
29 
30 #ifndef _FAT_H
31 #define _FAT_H
32 
33 #include "common.h"
34 #include "partition.h"
35 
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
42 
43 #define CLUSTERS_PER_FAT12 4085
44 #define CLUSTERS_PER_FAT16 65525
45 
46 
48 
51 
53 
55 
57 
59 
61  return (cluster >= CLUSTER_FIRST) ?
62  ((cluster - CLUSTER_FIRST) * (sec_t)partition->sectorsPerCluster) + partition->dataStart :
63  partition->rootDirStart;
64 }
65 
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 */);
68 }
69 
70 #endif // _FAT_H
uint32_t _FAT_fat_linkFreeCluster(PARTITION *partition, uint32_t cluster)
Definition: file_allocation_table.c:206
static sec_t _FAT_fat_clusterToSector(PARTITION *partition, uint32_t cluster)
Definition: file_allocation_table.h:60
#define CLUSTER_FIRST
Definition: file_allocation_table.h:40
uint32_t _FAT_fat_lastCluster(PARTITION *partition, uint32_t cluster)
Definition: file_allocation_table.c:371
uint32_t startCluster
Definition: fatfile.h:54
uint32_t _FAT_fat_trimChain(PARTITION *partition, uint32_t startCluster, unsigned int chainLength)
Definition: file_allocation_table.c:336
static IdxT partition(lua_State *L, IdxT lo, IdxT up)
Definition: ltablib.c:310
uint32_t sec_t
Definition: iosuhax_disc_interface.h:40
uint32_t _FAT_fat_linkFreeClusterCleared(PARTITION *partition, uint32_t cluster)
Definition: file_allocation_table.c:268
Definition: partition.h:52
bool _FAT_fat_clearLinks(PARTITION *partition, uint32_t cluster)
Definition: file_allocation_table.c:300
uint32_t _FAT_fat_nextCluster(PARTITION *partition, uint32_t cluster)
Definition: file_allocation_table.c:39
unsigned int _FAT_fat_freeClusterCount(PARTITION *partition)
Definition: file_allocation_table.c:382
static bool _FAT_fat_isValidCluster(PARTITION *partition, uint32_t cluster)
Definition: file_allocation_table.h:66
unsigned int uint32_t
Definition: stdint.h:126