【发布时间】:2015-01-06 01:41:00
【问题描述】:
我必须更正 posix 操作系统的 open() 系统调用的返回值。我从 man-Pages 了解到它必须返回 文件描述符,并且,如果出现错误,系统调用将返回 -1 并设置 errno 值。问题是我不知道如何获取打开的节点的文件描述符。我检查了所有文件,没有找到可以将 fd 分配给进程的方法。
方法如下:
int syscalls::open(const char *path, int oflags, mode_t mode){
syscall_message msg;
msg.call.type = syscalls::open_call;
msg.open_data.path_name = &path[0];
msg.open_data.flags = oflags;
msg.open_data.create_mode = mode;
syscaller::call_system(msg);
return msg.error.number;
}
syscall_message 是一个保存系统调用数据信息的结构。 syscalls 是所有系统调用所在的namesapace。 syscaller 用于将调用发送到内核,取消 call_system 方法。
call_system 方法:
syscalls::open_call:
{
//get the file
i_fs_node_ptr file = i_fs::open_node( msg.open_data.path_name );
//add the file handle
if ( file )
{
cur_process->push_filehandle(
file,
msg.open_data.flags,
msg.open_data.create_mode );
}
else
{
msg.error.type = syscalls::e_no_such_entry;
}
}
【问题讨论】:
-
syscall_message、syscalls和syscaller是什么?它们是您正在使用的某个库或框架的一部分吗?
标签: c++ operating-system system-calls