-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfile_reader.h
More file actions
146 lines (112 loc) · 2.85 KB
/
Copy pathfile_reader.h
File metadata and controls
146 lines (112 loc) · 2.85 KB
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#pragma once
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <errno.h>
#include <string.h>
struct disk_t {
FILE *f;
};
struct volume_t {
struct fat_super_t *SuperSector;
struct disk_t *disk;
int FAT1_Pos;
int FAT2_Pos;
int FAT_sectors;
int ROOT_Dir_Pos;
int ROOT_Sectors;
int volume_size;
int user_size;
int number_of_cluster_per_volume;
int cluster2_position;
int DATA_Pos;
};
struct time_godziny_t{
uint16_t sekundy:5;
uint16_t minuty:6;
uint16_t godziny:5;
};
struct time_dzien_t{
uint16_t dzien:5;
uint16_t miesiac:4;
uint16_t rok:7;
};
enum atribute_t{
read_only = 0x01,
hidden_file = 0x02,
system_file = 0x04,
volume_label = 0x08,
directory = 0x10,
archived = 0x20,
lfn = 0x0F
};
struct fat_entry_t {
char name[8];
char extenstion[3];
uint8_t attributes;
uint8_t __some_data[6];
uint16_t __some_data2;
uint16_t high_cluster_index;
uint16_t __some_data3[2];
uint16_t low_cluster_index;
uint32_t file_size;
} __attribute__(( packed ));
struct file_t{
struct volume_t* vol;
struct cluster_t* clus;
struct fat_entry_t *entry;
int file_pos;
char *buff;
};
struct dir_t {
struct volume_t* vol;
uint16_t dir_position;
int is_file_open;
};
struct dir_entry_t {
char name[13];
int size;
int is_archived;
int is_readonly;
int is_system;
int is_hidden;
int is_directory;
};
struct cluster_t {
uint16_t* handle;
size_t size;
};
struct fat_super_t {
uint8_t __jump_code[3];
char oem_name[8];
uint16_t bytes_per_sector;
uint8_t sectors_per_cluster;
uint16_t reserved_sectors;
uint8_t fat_count;
uint16_t root_dir_capacity;
uint16_t logical_sectors16;
uint8_t __reserved;
uint16_t sectors_per_fat;
uint32_t __reserved2;
uint32_t hidden_sectors;
uint32_t logical_sectors32;
uint16_t __reserved3;
uint8_t __reserved4;
uint32_t serial_number;
char label[11];
char fsid[8];
uint8_t __boot_code[448];
uint16_t magic;
} __attribute__(( packed ));
struct disk_t* disk_open_from_file(const char* volume_file_name);
int disk_read(struct disk_t* pdisk, int32_t first_sector, void* buffer, int32_t sectors_to_read);
int disk_close(struct disk_t* pdisk);
struct volume_t* fat_open(struct disk_t* pdisk, uint32_t first_sector);
int fat_close(struct volume_t* pvolume);
struct file_t* file_open(struct volume_t* pvolume, const char* file_name);
int file_close(struct file_t* stream);
size_t file_read(void *ptr, size_t size, size_t nmemb, struct file_t *stream);
int32_t file_seek(struct file_t* stream, int32_t offset, int whence);
struct dir_t* dir_open(struct volume_t* pvolume, const char* dir_path);
int dir_read(struct dir_t* pdir, struct dir_entry_t* pentry);
int dir_close(struct dir_t* pdir);