-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathfat_device.h
91 lines (78 loc) · 2.62 KB
/
fat_device.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/*
* Copyright 2009 Luis Henrique O. Rios
*
* This file is part of YAFS.
*
* YAFS is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* YAFS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with YAFS. If not, see <http://www.gnu.org/licenses/>.
*/
/**
* FAT Device Module: deals with FAT Devices writing and reading the file system.
*/
#ifndef YAFS_FAT_DEVICE_H
#define YAFS_FAT_DEVICE_H
#include "exception.h"
#include "fat.h"
#include "fat_device_type.h"
#include "fat_elements.h"
#include "file_io.h"
#include "types.h"
#include <vector>
#include <string>
using namespace std;
class FATDevice {
public:
FATDevice(const char* path, const char *access_mode);
~FATDevice();
RootDirectory* ReadDirectoriesTree();
void WriteDirectoriesTree(RootDirectory* );
operator string();
class FATDeviceException : public Exception {
public:
FATDeviceException(string message = ""):Exception(message){}
};
enum FATType {
FAT12 = 0,
FAT16 = 1,
FAT32 = 2
};
private:
FileIO *device_file;
BootSectorBIOSParameterBlock bs_bpb;
BIOSParameterBlockFAT32 *bpb_fat32;
BootSectorFAT bs_fat;
uint32 fat_size , first_data_sector , sectors_root_directory , total_sectors ,
data_sectors , total_clusters , cluster_size , fat_buffer_sector;
vector<uint32> fats_first_sector;
FATType fat_type;
uint8 *fat_buffer;
static uint32 file_last_cluster[];
bool IsLastCluster(uint32 cluster){
cluster = cluster & 0x0FFFFFFF;
return cluster >= file_last_cluster[(uint32)fat_type] || cluster == 0;
}
void ReadDirectory(FATDirectory*);
void WriteDirectory(FATDirectory*);
uint64 GetClusterOffset(uint32 cluster);
void ReadSector(void* buffer , uint32 sector);
void ReadCluster(void* buffer , uint32 cluster);
void WriteSector(void* buffer , uint32 sector);
void WriteCluster(void* buffer , uint32 cluster);
uint32 ReadFAT(uint32 cluster);
friend ostream &operator<<(ostream &stream , FATDevice &fat_device);
void ThrowNotFATFileSystemException(){
throw FATDeviceException("The device does not have a FAT file system.");
}
};
ostream &operator<<(ostream &stream , FATDevice &fat_device);
#endif