-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfat.h
More file actions
74 lines (54 loc) · 1.62 KB
/
Copy pathfat.h
File metadata and controls
74 lines (54 loc) · 1.62 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
#pragma once
#include "../constants.h"
#include "disk.h"
#define FAT_SIZE sizeof(struct FAT_STRUCT)
#define FAT_ENTRIES DISK_SIZE/BLOCK_SIZE
#define FAT_RESERVED_BLOCKS FAT_SIZE/BLOCK_SIZE +1
/*
File Allocation Table struct.
Size = 5*(DISK_SIZE/BLOCK_SIZE)
*/
typedef struct FAT_STRUCT {
char isFull[DISK_SIZE/BLOCK_SIZE];
int next[DISK_SIZE/BLOCK_SIZE];
} FAT_STRUCT;
/*
Initializes the FAT on DISK at startup, and returns the index of the first usable
block on DISK not reserved to the FAT.
If DISK is mmapped then it puts the disk FAT struct in the FAT parameter
*/
int _FAT_init(FAT_STRUCT* FAT, DISK_STRUCT* DISK, char MMAPPED_DISK_FLAG);
/*
Deallocates FAT from memory
*/
void _FAT_destroy(FAT_STRUCT* FAT);
/*
Returns 1 if the file has no next block, or 0 otherwise
*/
char _FAT_EOF(FAT_STRUCT* FAT, int block_index);
/*
Returns the index of the successive block of DISK[block_index] on disk
*/
int _FAT_getNextBlock(FAT_STRUCT* FAT, int block_index);
/*
Sets the <index> block of the FAT to the value <value> (next file block).
Returns 0 if successful
*/
int _FAT_setNextBlock(FAT_STRUCT* FAT, int block_index, int next_index);
/*
Returns the index of the first free block on DISK
*/
int _FAT_findFirstFreeBlock(FAT_STRUCT* FAT);
/*
Sets the value isFull of the corresponding block to 1.
Returns 0 if successful, -1 otherwise
*/
int _FAT_allocateBlock(FAT_STRUCT* FAT, int block_index);
/*
Sets the value isFull of the corresponding block to 0
*/
void _FAT_deallocateBlock(FAT_STRUCT* FAT, int block_index);
/*
Saves the current FAT struct in memory on DISK
*/
int _FAT_writeOnDisk(FAT_STRUCT* FAT, DISK_STRUCT* DISK);