Repository navigation
Expand file tree
/
Copy pathFreeSpaceManager.h
More file actions
69 lines (57 loc) · 3.21 KB
/
Copy pathFreeSpaceManager.h
File metadata and controls
69 lines (57 loc) · 3.21 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
/**************************************************************
* Class:: CSC-415-02 Spring 2024
* Name::Yuiel Gebredngl
* Chia-Tung Liu
* Student IDs::922729168
* 923408847
* GitHub-Name::yuiela
* Mob1001
* Group-Name::Alt+F4
* Project:: Basic File System
*
* File:: FreeSpaceManager.h
*
* Description:: Fat table funcitons
*
**************************************************************/
// Structure to represent an entry in a File Allocation Table (FAT).
typedef struct FAT_Entry {
int nextBlockRef; // Reference to the next block in the chain if the current block is part of a file or larger data structure.
short isTaken; // Boolean value (1 or 0) indicating whether this block is currently in use.
} FAT_Entry;
// Reserves a consecutive series of blocks in the FAT for storage.
// Returns the index of the initial block in the reserved series, or -1 if the operation fails.
int allocFAT(int blocks);
// Releases a series of blocks beginning from a specified block.
// Returns the count of blocks successfully freed.
int deAllocFAT(int startingBlock);
// Extends the allocation for a file starting from the specified `fileBlock` by allocating `blocks` additional blocks.
// Connects these new blocks to the end of the file's current block chain.
// Returns 0 upon successful extension or -1 if insufficient blocks could be allocated
int extAllocFAT(int fileBlock, int blocks);
// Initializes the File Allocation Table with the required number of entries to manage blocks equivalent to `blockSize`.
// Returns a pointer to the initialized FAT table.
FAT_Entry* initFATTable(int blockSize);
// Retrieves the File Allocation Table from the designated location `FAT_reference` on the disk.
// Returns a pointer to the FAT entries read from the disk.
FAT_Entry* readFATTable(int FAT_reference);
// Calculates the absolute block address in the FAT using the initial block `start` and an offset `block`.
// Returns the computed block address, or an error code if the block is unallocated.
int absoluteLBA(int start, int block);
// Transfers data from a buffer to the disk, starting from a specified block.
// Manages writing across multiple blocks if required and updates the start block to the last written block.
// Returns the total number of bytes written.
int writeToLBA(void* raw, int bufferSize, int* startBlock);
// Retrieves data into a buffer from the disk, beginning at a specified block.
// Manages reading across multiple blocks if required and updates the start block to the last block read.
// Returns the total number of bytes read.
int readFromLBA(void* raw, int bufferSize, int* startBlock);
// Transfers data from a buffer to disk starting from a specific block and an offset within that block.
// Useful for appending data within a block without overwriting existing data from the start of the block.
// Updates `startBlock` to the last block written and `index` to the position within that block.
// Returns the total number of bytes written.
int writeToLBAI(void* raw, int bufferSize, int* startBlock, int* index);
// Utility function to print the current state of the FAT, for debugging purposes.
void printFAT();
// External declaration of the global FAT table pointer.
extern FAT_Entry* FATTable;