-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsuper_block.c
More file actions
47 lines (35 loc) · 1.29 KB
/
super_block.c
File metadata and controls
47 lines (35 loc) · 1.29 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
#include "globaldata.h"
/*
* Low Level function required for
* the implementation.
*
*/
/*************************************************************************
* isBlockFree(int blockNum)
* The sisBlockFree function is used to check if a give block number is free
**************************************************************************/
int isBlockFree(int blockNum)
{
return SuperBlock0.free[blockNum>>3]&(1<<(blockNum&7)); // bitwise shift.
}
/*************************************************************************
* setBlock_asUsed(int blockNum,int used)
* The setBlock_asUsed function is used to set the given block to used
**************************************************************************/
int setBlock_asUsed(int blockNum,int used)
{
used = used>0;
SuperBlock0.free[blockNum>>3]&=0xFF^(1<<(blockNum&7));
SuperBlock0.free[blockNum>>3]|=used<<(blockNum&7);
put_block(0,(char*)&SuperBlock0);
return 1;
}
/*************************************************************************
* writeFCB(int index)
* The writeFCB function is used to put the given File Control Block on to
* the disk
**************************************************************************/
int writeFCB(int index)
{
put_block((InodeTable[0][index]),(char*)&FILE_CONTROL_BLOCK0[index]);
}