-
Notifications
You must be signed in to change notification settings - Fork 0
/
File.cpp
97 lines (81 loc) · 1.86 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
90
91
92
93
94
95
96
//kyf
#include "File.h"
#include "SecondFileKernel.h"
/*==============================class File===================================*/
File::File()
{
this->f_count = 0;
this->f_flag = 0;
this->f_offset = 0;
this->f_inode = NULL;
}
File::~File()
{
//nothing to do here
}
/*==============================class OpenFiles===================================*/
OpenFiles::OpenFiles()
{
}
OpenFiles::~OpenFiles()
{
}
int OpenFiles::AllocFreeSlot()
{
int i;
User& u = SecondFileKernel::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 = EMFILE;
return -1;
}
int OpenFiles::Clone(int fd)
{
return 0;
}
File* OpenFiles::GetF(int fd)
{
File* pFile;
User& u = SecondFileKernel::Instance().GetUser();
/* 如果打开文件描述符的值超出了范围 */
if(fd < 0 || fd >= OpenFiles::NOFILES)
{
u.u_error = EBADF;
return NULL;
}
pFile = this->ProcessOpenFileTable[fd];
if(pFile == NULL)
{
u.u_error = 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;
}
/*==============================class IOParameter===================================*/
IOParameter::IOParameter()
{
this->m_Base = 0;
this->m_Count = 0;
this->m_Offset = 0;
}
IOParameter::~IOParameter()
{
//nothing to do here
}