Repository navigation
Expand file tree
/
Copy pathVCB.c
More file actions
67 lines (58 loc) · 1.9 KB
/
Copy pathVCB.c
File metadata and controls
67 lines (58 loc) · 1.9 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
/**************************************************************
* Class:: CSC-415-02 Spring 2024
* Name::Jiqing Liu
* Chia-Tung Liu
* Student IDs::922056041
* 923408847
* GitHub-Name::YTDY3867
* Mob1001
* Group-Name::Alt+F4
* Project:: Basic File System
*
* File:: VCB.c
*
* Description:: Volume Control Blocks funcitons
*
**************************************************************/
#include "VCB.h"
#include "fsLow.h"
#include "Directory.h"
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
VCB_Block* createVCB(int numberOfBlocks, int blockSize) {
VCB_Block* blockHolder = malloc(sizeof(VCB_Block));
if (!blockHolder) {
return NULL;
}
blockHolder->magic_number = MAGIC_NUMBER;
strncpy(blockHolder->label, "BB", sizeof(blockHolder->label) - 1);
blockHolder->block_count = numberOfBlocks;
blockHolder->block_size = blockSize;
blockHolder->FAT_reference = 1;
return blockHolder;
}
void TestDirectory(VCB_Block *VCBHolder) {
printf("TEST ----------------------------------\n");
DIR_Entry root[MAX_DIR_ENTRIES];
int rootSize = sizeof(root);
int blocksContained = (rootSize / VCBHolder->block_size) + (rootSize % VCBHolder->block_size != 0);
char *buffer = malloc(blocksContained * VCBHolder->block_size);
if (!buffer) {
printf("Memory allocation failed\n");
return;
}
LBAread(buffer, blocksContained, VCBHolder->root_reference);
memcpy(root, buffer, sizeof(root));
free(buffer);
buffer=NULL;
printf("FINISHED READING ----------------------\n");
for (int i = 0; i < 2; i++) {
printf("%d's ENTRY ----------> %s\n", i + 1, root[i].name);
printf("----------------------> %d\n", root[i].size);
printf("----------------------> %d\n", root[i].isDirectory);
}
}
int getRootBlock() {
return 0;
}