-
Notifications
You must be signed in to change notification settings - Fork 0
/
File.cpp
89 lines (63 loc) · 1.71 KB
/
File.cpp
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
#include "Global.h"
#include "Common.h"
#include <cstring>
/*============================== File ==============================*/
File::File() {
this->f_count = f_count_init;
this->f_flag = f_flag_init;
this->f_offset = f_offset_init;
this->f_inode = NULL;
}
File::~File() {
}
/*============================== File ==============================*/
/*============================== OpenFiles ==============================*/
OpenFiles::OpenFiles() {
memset(this->ProcessOpenFileTable, NULL, sizeof(this->ProcessOpenFileTable));
}
OpenFiles::~OpenFiles() {
}
int OpenFiles::AllocFreeSlot() {
/* 引用全局变量 */
User& user = globalUser;
/* 遍历进程打开文件描述符表 */
for (int i = 0; i < OPEN_FILES_NUM; i++) {
/* 判断是否是空闲项 */
if (this->ProcessOpenFileTable[i] == NULL) {
user.u_ar0[User::EAX] = i;
return i;
}
}
user.u_ar0[User::EAX] = NOT_FOUND;
user.u_error = User::myEMFILE;
return NOT_FOUND;
}
File* OpenFiles::GetF(const int& fd) {
/* 引用全局变量 */
User& user = globalUser;
/* 判断fd的特殊范围 */
if (fd < 0 || fd >= OPEN_FILES_NUM) {
user.u_error = User::myEBADF;
return NULL;
}
File* fp = this->ProcessOpenFileTable[fd];
if (fp == NULL) {
user.u_error = User::myEBADF;
}
return fp;
}
void OpenFiles::SetF(const int& fd, File* fp) {
/* 判断fd的特殊范围 */
if (fd < 0 || fd >= OPEN_FILES_NUM) {
return;
}
/* 更新进程打开文件描述符表 */
this->ProcessOpenFileTable[fd] = fp;
}
/*============================== OpenFiles ==============================*/
/*============================== IOParameter ==============================*/
IOParameter::IOParameter() {
}
IOParameter::~IOParameter() {
}
/*============================== IOParameter ==============================*/