remove trailing spaces
[libfat.git] / source / partition.h
blobb0cfea72c138ea0345f8ea41e9c469c6f21c23b7
1 /*
2 partition.h
3 Functions for mounting and dismounting partitions
4 on various block devices.
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 _PARTITION_H
31 #define _PARTITION_H
33 #include "common.h"
34 #include "cache.h"
35 #include "lock.h"
37 // Device name
38 extern const char* DEVICE_NAME;
40 // Filesystem type
41 typedef enum {FS_UNKNOWN, FS_FAT12, FS_FAT16, FS_FAT32} FS_TYPE;
43 typedef struct {
44 sec_t fatStart;
45 uint32_t sectorsPerFat;
46 uint32_t lastCluster;
47 uint32_t firstFree;
48 } FAT;
50 typedef struct {
51 const DISC_INTERFACE* disc;
52 CACHE* cache;
53 // Info about the partition
54 FS_TYPE filesysType;
55 uint64_t totalSize;
56 sec_t rootDirStart;
57 uint32_t rootDirCluster;
58 uint32_t numberOfSectors;
59 sec_t dataStart;
60 uint32_t bytesPerSector;
61 uint32_t sectorsPerCluster;
62 uint32_t bytesPerCluster;
63 FAT fat;
64 // Values that may change after construction
65 uint32_t cwdCluster; // Current working directory cluster
66 int openFileCount;
67 struct _FILE_STRUCT* firstOpenFile; // The start of a linked list of files
68 mutex_t lock; // A lock for partition operations
69 bool readOnly; // If this is set, then do not try writing to the disc
70 } PARTITION;
73 Mount the supplied device and return a pointer to the struct necessary to use it
75 PARTITION* _FAT_partition_constructor (const DISC_INTERFACE* disc, uint32_t cacheSize, sec_t startSector);
78 Dismount the device and free all structures used.
79 Will also attempt to synchronise all open files to disc.
81 void _FAT_partition_destructor (PARTITION* partition);
84 Return the partition specified in a path, as taken from the devoptab.
86 PARTITION* _FAT_partition_getPartitionFromPath (const char* path);
88 #endif // _PARTITION_H