-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFile.cpp
More file actions
93 lines (74 loc) · 1.76 KB
/
File.cpp
File metadata and controls
93 lines (74 loc) · 1.76 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
//
// Created by roy on 27/03/2023.
//
#include "File.h"
#include "Kernel.h"
#include "User.h"
File::File() {
f_count = 0;
f_inode = NULL;
f_offset = 0;
}
File::~File() { }
void File::Reset()
{
f_count = 0;
f_inode = NULL;
f_offset = 0;
}
OpenFiles::OpenFiles() {
memset(ProcessOpenFileTable, 0, sizeof(ProcessOpenFileTable));
}
OpenFiles::~OpenFiles() {
}
int OpenFiles::AllocFreeSlot() {
int i;
User& u = Kernel::Instance().GetUser();
for(i = 0; i < OpenFiles::NOFILES; i++)
{
/* 进程打开文件描述符表中找到空闲项,则返回之 */
if(this->ProcessOpenFileTable[i] == NULL)
{
/* 设置核心栈现场保护区中的EAX寄存器的值,即系统调用返回值 */
u.u_ar0[User::EAX] = i;
return i;
}
}
u.u_ar0[User::EAX] = -1; /* Open1,需要一个标志。当打开文件结构创建失败时,可以回收系统资源*/
u.u_error = User::U_EMFILE;
return -1;
}
int OpenFiles::Clone(int fd) {
return 0;
}
File *OpenFiles::GetF(int fd) {
File* pFile;
User& u = Kernel::Instance().GetUser();
/* 如果打开文件描述符的值超出了范围 */
if(fd < 0 || fd >= OpenFiles::NOFILES)
{
u.u_error = User::U_EBADF;
return NULL;
}
pFile = this->ProcessOpenFileTable[fd];
if(pFile == NULL)
{
u.u_error = User::U_EBADF;
}
return pFile; /* 即使pFile==NULL也返回它,由调用GetF的函数来判断返回值 */
}
void OpenFiles::SetF(int fd, File *pFile) {
if(fd < 0 || fd >= OpenFiles::NOFILES)
{
return;
}
/* 进程打开文件描述符指向系统打开文件表中相应的File结构 */
this->ProcessOpenFileTable[fd] = pFile;
}
IOParameter::IOParameter() {
this->m_Base = nullptr;
this->m_Count = 0;
this->m_Offset = 0;
}
IOParameter::~IOParameter() {
}