forked from yutianzeabc/File-System-Design
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmy_format.c
More file actions
177 lines (160 loc) · 6.11 KB
/
Copy pathmy_format.c
File metadata and controls
177 lines (160 loc) · 6.11 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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
//
// Created by 孙鹏 on 2020/12/23.
//
//
#ifndef FILE_SYSTEM_DESIGN_FORMAT
#define FILE_SYSTEM_DESIGN_FORMAT
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "fs.h"
#include "c_operator.h"
void my_format()
{
char *char_temp = NULL;
int *int_temp = NULL;
S_free = NULL;
free_block_stack = (char *)malloc(BLOCK_SIZE);
virtualDisk = (char *)malloc(SIZE);
printf("----------Begin initial group link----------\n");
S_free = free_block_stack;
*S_free = 250;
printf("%p %d\n",S_free,*S_free);
S_free++;
for (int i = 249; i >= 0; i--)
{
*S_free = i;
printf("%p %d\n",S_free,*S_free);
S_free++;
}
printf("\n\n");
printf("%p\n",virtualDisk);
/*initial No.249*/
char_temp = virtualDisk + 249*BLOCK_SIZE;
int_temp = char_temp;
*int_temp = 250;
printf("%p %d\n",int_temp,*int_temp);
int_temp++;
for (int i = 499; i>= 250; i--)
{
*int_temp = i;
printf("%p %d\n",int_temp,*int_temp);
int_temp++;
}
printf("\n\n");
printf("%p\n",virtualDisk);
/*initial No.499*/
char_temp = virtualDisk + 499*BLOCK_SIZE;
int_temp = char_temp;
*int_temp = 250;
printf("%p %d\n",int_temp,*int_temp);
int_temp++;
for (int i = 749; i>=500; i--)
{
*int_temp = i;
printf("%p %d\n",int_temp,*int_temp);
int_temp++;
}
printf("\n\n");
printf("%p\n",virtualDisk);
/*initial No.749*/
char_temp = virtualDisk + 749*BLOCK_SIZE;
int_temp = char_temp;
*int_temp = 250;
printf("%p %d\n",int_temp,*int_temp);
int_temp++;
for (int i = 999; i>=750; i--)
{
*int_temp = i;
printf("%p %d\n",int_temp,*int_temp);
int_temp++;
}
printf("----------End initial group link----------\n\n");
int request_block0_id;
int super_block_id;
int inode_table_id;
int inode_table_id2;
int root_id;
request_block0_id = request_block(); //No.0 distribute to block0
printf("No.%d distribute to block0\n",request_block0_id);
super_block_id = request_block(); //N0.1 distribute to super_block
printf("N0.%d distribute to super_block\n",super_block_id);
inode_table_id = request_block(); //No.2 distribute to inode_table
inode_table_id2 = request_block(); //No.3 distribute to inode_table
printf("No.%d distribute to inode_table\n",inode_table_id);
printf("No.%d distribute to inode_table\n",inode_table_id2);
root_id = request_block(); //No.4 distribute to root_dir
printf("No.%d distribute to root_dir\n\n",root_id);
block0 block0_temp;
block0 *block0_point = NULL;
block0_temp.block_size = BLOCK_SIZE;
block0_temp.block_num = SIZE/BLOCK_SIZE;
block0_temp.root = root_id;
block0_temp.super_block = super_block_id;
block0_temp.inode_table = inode_table_id;
block0_temp.root_start = virtualDisk + root_id*BLOCK_SIZE;
block0_temp.super_start = virtualDisk + super_block_id*BLOCK_SIZE;
block0_temp.inode_table_start = virtualDisk + inode_table_id*BLOCK_SIZE;
block0_temp.data_start = virtualDisk + (root_id+1)*BLOCK_SIZE;
memcpy(virtualDisk, &block0_temp, sizeof(block0));
block0_point = virtualDisk;
printf("block0.block_size is %d\n",block0_point->block_size);
printf("block0.block_num is %d\n",block0_point->block_num);
printf("block0.super_block is %d\n",block0_point->super_block);
printf("block0.inode_table is %d\n",block0_point->inode_table);
printf("block0.root is %d\n",block0_point->root);
printf("block0.super_start is %p\n",block0_point->super_start);
printf("block0.inode_table_start is %p\n",block0_point->inode_table_start);
printf("block0.root_start is %p\n",block0_point->root_start);
printf("block0.data_start is %p\n\n",block0_point->data_start);
inode_id = 0;
int root_dir_inode;
int root_dir_index_label;
inode *root_dir_inode_point;
root_dir_inode = create_inode();
root_dir_index_label = request_block();
printf("the id of Root_dir's inode is %d\n",root_dir_inode);
printf("Request No.%d block as root_dir's index_label\n",root_dir_index_label);
root_dir_inode_point = get_inode_point(root_dir_inode);
root_dir_inode_point->direction_chart_id = root_dir_index_label;
root_dir_inode_point->attribute = 1;
root_dir_inode_point->length = 0;
index_element *index_label_start;
index_label_start = virtualDisk + root_dir_index_label*BLOCK_SIZE;
index_label_start->logical_id = 0;
index_label_start->physical_id = root_id;
curr_dir_inode = root_dir_inode;
fcb *fcb_temp;
char *fname1 = ".";
char *fname2 = "..";
fcb_temp = virtualDisk + root_id*BLOCK_SIZE;
memcpy(fcb_temp->filename, fname1, sizeof(char));
fcb_temp->i_ino = root_dir_inode;
fcb_temp++;
memcpy(fcb_temp->filename, fname2, sizeof(char)*2);
fcb_temp->i_ino = root_dir_inode;
root_dir_inode_point->length = sizeof(fcb)*2;
printf("Root_dir_inode's i_ino is %d\n",root_dir_inode_point->i_ino);
printf("Root_dir_inode's attribute is %d\n",root_dir_inode_point->attribute);
printf("Root_dir_inode's time is %lu\n",root_dir_inode_point->time);
printf("Root_dir_inode's date is %lu\n",root_dir_inode_point->date);
printf("Root_dir_inode's length is %lu\n",root_dir_inode_point->length);
printf("Root_dir_inode's direction_chart_id is %d\n\n",root_dir_inode_point->direction_chart_id);
printf("logical_id physical_id\n");
printf("%-8d %-8d\n\n",index_label_start->logical_id,index_label_start->physical_id);
my_ls();
//char *text = "root_dir";
//memcpy(USEROPENS[0].filename, text, sizeof(char)*strlen(text));
//USEROPENS[0].time = root_dir_inode_point->time;
//USEROPENS[0].date = root_dir_inode_point->date;
//USEROPENS[0].attribute = root_dir_inode_point->attribute;
//USEROPENS[0].direction_chart_id = root_dir_inode_point->direction_chart_id;
//USEROPENS[0].openlabel = 1;
//USEROPENS[0].length = root_dir_inode_point->length;
//printf("\n%s is opened\n\n",USEROPENS[0].filename);
for (int i=0; i<10; i++)
{
USEROPENS[i].openlabel = 0;
}
}
#endif