RetroArch
partition.h
Go to the documentation of this file.
1 /*
2  partition.h
3  Functions for mounting and dismounting partitions
4  on various block devices.
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 _PARTITION_H
31 #define _PARTITION_H
32 
33 #include "common.h"
34 #include "cache.h"
35 #include "lock.h"
36 
37 #define MIN_SECTOR_SIZE 512
38 #define MAX_SECTOR_SIZE 4096
39 
40 // Filesystem type
42 
43 typedef struct {
44  sec_t fatStart;
45  uint32_t sectorsPerFat;
46  uint32_t lastCluster;
47  uint32_t firstFree;
48  uint32_t numberFreeCluster;
49  uint32_t numberLastAllocCluster;
50 } FAT;
51 
52 typedef struct {
53  const DISC_INTERFACE* disc;
54  CACHE* cache;
55  // Info about the partition
56  FS_TYPE filesysType;
57  uint64_t totalSize;
58  sec_t rootDirStart;
59  uint32_t rootDirCluster;
60  uint32_t numberOfSectors;
61  sec_t dataStart;
62  uint32_t bytesPerSector;
63  uint32_t sectorsPerCluster;
64  uint32_t bytesPerCluster;
65  uint32_t fsInfoSector;
66  FAT fat;
67  // Values that may change after construction
68  uint32_t cwdCluster; // Current working directory cluster
69  int openFileCount;
70  struct _FILE_STRUCT* firstOpenFile; // The start of a linked list of files
71  mutex_t lock; // A lock for partition operations
72  bool readOnly; // If this is set, then do not try writing to the disc
73  char label[12]; // Volume label
74 } PARTITION;
75 
76 /*
77 Mount the supplied device and return a pointer to the struct necessary to use it
78 */
79 PARTITION* _FAT_partition_constructor (const DISC_INTERFACE* disc, uint32_t cacheSize, uint32_t SectorsPerPage, sec_t startSector);
80 
81 /*
82 Dismount the device and free all structures used.
83 Will also attempt to synchronise all open files to disc.
84 */
86 
87 /*
88 Return the partition specified in a path, as taken from the devoptab.
89 */
91 
92 /*
93 Create the fs info sector.
94 */
96 
97 /*
98 Read the fs info sector data.
99 */
101 
102 /*
103 Write the fs info sector data.
104 */
106 
107 #endif // _PARTITION_H
Definition: fatfile.h:52
int mutex_t
typedef for the mutex handle
Definition: lock.c:6
Definition: partition.h:41
void _FAT_partition_readFSinfo(PARTITION *partition)
Definition: partition.c:394
GLsizei const GLchar ** path
Definition: glext.h:7901
GLuint GLsizei const GLchar * label
Definition: glext.h:8583
PARTITION * _FAT_partition_getPartitionFromPath(const char *path)
Definition: partition.c:353
void _FAT_partition_writeFSinfo(PARTITION *partition)
Definition: partition.c:425
static IdxT partition(lua_State *L, IdxT lo, IdxT up)
Definition: ltablib.c:310
uint32_t sec_t
Definition: iosuhax_disc_interface.h:40
Definition: partition.h:41
Definition: partition.h:52
void _FAT_partition_createFSinfo(PARTITION *partition)
Definition: partition.c:363
FS_TYPE
Definition: partition.h:41
PARTITION * _FAT_partition_constructor(const DISC_INTERFACE *disc, uint32_t cacheSize, uint32_t SectorsPerPage, sec_t startSector)
Definition: partition.c:311
Definition: cache.h:50
Definition: partition.h:41
Definition: iosuhax_disc_interface.h:52
Definition: partition.h:41
Definition: partition.h:43
unsigned __int64 uint64_t
Definition: stdint.h:136
unsigned int uint32_t
Definition: stdint.h:126
void _FAT_partition_destructor(PARTITION *partition)
Definition: partition.c:325