-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathballfre.c
More file actions
56 lines (50 loc) · 1.37 KB
/
ballfre.c
File metadata and controls
56 lines (50 loc) · 1.37 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
#include "stdio.h"
#include "filesys.h"
static unsigned int block_buf[BLOCKSIZ];
unsigned int balloc()
{
unsigned int free_block, free_block_num;
int i;
if (filsys.s_nfree == 0)
{
printf("\n Disk Full!!!\n");
return DISKFULL;
}
free_block = filsys.s_free[filsys.s_pfree];
if (filsys.s_pfree == NICFREE - 1)
{
fseek(fd, DATASTART + BLOCKSIZ * (iCur_free_block_index + NICFREE - 1), SEEK_SET);
fread(block_buf, 1, BLOCKSIZ, fd);
free_block_num = block_buf[NICFREE]; /*the total block num in the group */
for (i = 0; i < free_block_num; i++)
filsys.s_free[NICFREE - 1 - i] = block_buf[i];
filsys.s_pfree = NICFREE - free_block_num;
}
else
filsys.s_pfree += 1;
filsys.s_nfree -= 1;
filsys.s_fmod = SUPDATE;
return free_block;
}
void bfree(unsigned int block_num)
{
int i;
if (block_num >= 0 && block_num <= 3)
return;
filsys.s_pfree -= 1;
if (filsys.s_pfree == 0 && iCur_free_block_index != 11) /*s_free full */
{
block_buf[NICFREE] = NICFREE;
for (i = 0; i < NICFREE; i++)
block_buf[i] = filsys.s_free[NICFREE - 1 - i];
filsys.s_pfree = NICFREE - 1;
}
if (iCur_free_block_index != 11)
{
iCur_free_block_index -= NICFREE;
fseek(fd, DATASTART + BLOCKSIZ * (iCur_free_block_index - 1), SEEK_SET);
fread(block_buf, 1, BLOCKSIZ, fd);
filsys.s_nfree++;
filsys.s_fmod = SUPDATE;
}
}