forked from yutianzeabc/File-System-Design
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinode_operator.c
More file actions
77 lines (63 loc) · 1.68 KB
/
Copy pathinode_operator.c
File metadata and controls
77 lines (63 loc) · 1.68 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
//
// Created by 孙鹏 on 2020/12/26.
//
#ifndef FILE_SYSTEM_DESIGN_FS_INODE_OPERATOR
#define FILE_SYSTEM_DESIGN_FS_INODE_OPERATOR
#include <string.h>
#include <time.h>
#include "inode.h"
#include "fs.h"
#include "c_operator.h"
/*获取当前时间*/
unsigned long get_time()
{
unsigned long result = 0;
time_t timer;
struct tm *tblock;
time(&timer);
tblock = gmtime(&timer);
result = (result+tblock->tm_hour+8)*100;
result = (result+tblock->tm_min)*100;
result = (result+tblock->tm_sec);
return result;
}
/*获取当前日期*/
unsigned long get_date()
{
unsigned long result = 0;
time_t timer;
struct tm *tblock;
time(&timer);
tblock = gmtime(&timer);
result = (tblock->tm_year+1900)*100;
result = (result+tblock->tm_mon+1)*100;
result = (result+tblock->tm_mday);
return result;
}
/*创建一个索引节点并返回该索引节点编号*/
int create_inode()
{
char *next_inode_start = NULL;
next_inode_start = virtualDisk + 2*BLOCK_SIZE + inode_id*sizeof(inode);
inode inode_temp;
inode_temp.i_ino = inode_id;
inode_temp.time = get_time();
inode_temp.date = get_date();
memcpy(next_inode_start, &inode_temp, sizeof(inode)*1);
return inode_id++;
}
/*根据索引节点编号获取该索引节点的起始位置*/
inode *get_inode_point(int id)
{
inode *point_temp = NULL;
point_temp = virtualDisk + 2*BLOCK_SIZE + id*sizeof(inode);
return point_temp;
}
/*根据索引节点编号获取该索引节点*/
inode find_inode(int id)
{
inode temp;
memcpy(&temp,virtualDisk+2*BLOCK_SIZE+id*sizeof(inode),sizeof(inode)*1);
return temp;
}
#endif //FILE_SYSTEM_DESIGN_FS_INODE_OPERATOR