-
Notifications
You must be signed in to change notification settings - Fork 0
/
blocks.c
51 lines (45 loc) · 1.25 KB
/
blocks.c
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
#define DIR_ENTRY_SIZE 110
#define BITMAP_SIZE 4096
#define BIT_OFFSET 8
struct DIR {
char name[DIR_ENTRY_SIZE];
int index;
};
struct FCB {
int available;
int index_block;
int size;
};
struct FILES {
int free;
char name[DIR_ENTRY_SIZE];
int index;
int mode;
int offset;
int size;
int total;
};
void set_bit(void *bitmap, int nblock, unsigned int bit_index) {
void *curr = bitmap + BITMAP_SIZE * nblock;
int char_index = bit_index / BIT_OFFSET;
int index = (BIT_OFFSET-1) - (bit_index % BIT_OFFSET);
curr = curr + char_index * sizeof(char);
*(char *) curr |= 1UL << index;
}
int get_bit(void *bitmap, int nblock, unsigned int bit_index) {
void *curr = bitmap + BITMAP_SIZE * nblock;
int char_index = bit_index / BIT_OFFSET;
int index = 7 - (bit_index % BIT_OFFSET);
curr = curr + char_index * sizeof(char);
if ((*(char *) curr & 1UL << index) == 0)
return 0;
else
return 1;
}
void clear_bit(void *bitmap, int nblock, unsigned int bit_index) {
void *curr = bitmap + BITMAP_SIZE * nblock;
int char_index = bit_index / BIT_OFFSET;
int index = 7 - (bit_index % BIT_OFFSET);
curr = curr + char_index * sizeof(char);
*(char *) curr &= ~(1UL << index);
}