forked from yutianzeabc/File-System-Design
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgroup_link_operator.c
More file actions
108 lines (100 loc) · 2.19 KB
/
Copy pathgroup_link_operator.c
File metadata and controls
108 lines (100 loc) · 2.19 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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
//
// Created by 孙鹏 on 2020/12/23.
//
#ifndef FILE_SYSTEM_DESIGN_FS_GROUP_LINK_OPERATOR
#define FILE_SYSTEM_DESIGN_FS_GROUP_LINK_OPERATOR
#include <string.h>
#include "fs.h"
#include "c_operator.h"
int request_block() {
int *temp = free_block_stack;
int count = *temp;
int result;
S_free--;
result = *S_free;
if (count > 1) {
count--;
*temp = count;
return result;
} else if (count == 1) {
if (result == 999) {
return -1;
} else {
memcpy(free_block_stack, virtualDisk + result * 1024, sizeof(char) * 1024);
temp = free_block_stack;
count = *temp;
S_free = temp + count + 1;
return result;
}
}
}
void recycle_block(int id) {
int *temp = free_block_stack;
int count = *temp;
if (count < 250) {
*S_free = id;
count++;
S_free++;
*temp = count;
} else if (count == 250) {
memcpy(virtualDisk + id * 1024, free_block_stack, sizeof(char) * 1024);
S_free = free_block_stack;
*S_free = 1;
S_free++;
*S_free = id;
S_free++;
}
}
#endif //FILE_SYSTEM_DESIGN_FS_GROUP_LINK_OPERATOR
/*
int request_block()
{
int *temp = free_block_stack;
int count = *temp;
int result;
S_free--;
result = *S_free;
if (count > 1)
{
count--;
*temp = count;
return result;
}
else if (count==1)
{
if(result == 999)
{
return -1;
}
else
{
memcpy(free_block_stack, virtualDisk+result*1024, sizeof(char)*1024);
temp = free_block_stack;
count = *temp;
S_free = temp + count + 1;
return result;
}
}
}
void recycle_block(int id)
{
int *temp = free_block_stack;
int count = *temp;
if (count<250)
{
*S_free = id;
count++;
S_free++;
*temp = count;
}
else if (count==250)
{
memcpy(virtualDisk+id*1024, free_block_stack, sizeof(char)*1024);
S_free = free_block_stack;
*S_free = 1;
S_free++;
*S_free = id;
S_free++;
}
}
*/