-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.c
More file actions
81 lines (73 loc) · 1.56 KB
/
test.c
File metadata and controls
81 lines (73 loc) · 1.56 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
#include "btree.c"
int readData(char *s1, int length) {
char ch;
int i;
i = 0;
ch = '\0';
while (i < length && ch != '\n') {
ch = getc(stdin);
s1[i] = ch;
++i;
}
s1[i] = '\0';
return strlen(s1);
}
void test(int f1, int nblocks)
{
struct block b;
struct block b1;
char data[INODEDATA];
char name[80];
int n;
int i;
int k;
printf("Enter K :");
scanf("%d", &k);
b1.type = 0;
for (i = 0; i < k; ++i) {
printf("Name: ");
scanf("%s", name);
readData(data, INODEDATA);
btree_insert(f1, name, data, 0);
}
n = 1 + nblocks / sizeof(struct block) ;
for (i = 1; i <= n; ++i) {
readBlock(f1, i, &b1);
for (k = 0; k < MAXFREE; ++k) {
if (b1.blk.f.free[k] == true) {
continue;
}
readBlock(f1, (i - 1) * MAXFREE + k, &b);
printf("Block no: %d Type: %d ", b.blockno, b.type);
if (b.type == 2) {
printf("N : %d [%d %d ..]\n", b.blk.f.n,
b.blk.f.free[0],
b.blk.f.free[1]);
} else if (b.type == 1) {
printf("count : %d isleaf: %d\n",
b.blk.b.count,
b.blk.b.is_leaf);
} else if (b.type == 0) {
printf("Inode no: %d Size: %ld data: %s\n",
b.blk.i.inode_no,
b.blk.i.size,
b.blk.i.data);
} else {
printf("Invalid type!\n");
}
}
}
}
int main()
{
int f1;
printf("Block Size :%lu\n", sizeof(struct block));
printf("Inode Size :%lu\n", sizeof(struct inode));
printf("Free list Size :%lu\n", sizeof(struct freeList));
printf("Bnode Size :%lu\n", sizeof(struct bnode));
f1 = openDisk("hd1", DISKSIZE);
test(f1, DISKSIZE);
inorder(f1, 0);
closeDisk(f1);
return 0;
}