I have to correct the return value of the open()
syscall of a posix OS. I understood from the man-Pages that it has to return the file descriptor, and , in case of an error the system call will return -1 and set the errno
value. The problem is that I do not know how to get the file descriptor for the opened nod. I checked all the files and didn't found a method that can assign a fd to processes.
Here is the method :
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
is a struct that holds the data info for the system call. syscalls
is the namesapace
where all the system calls are. syscaller
is used to send the call to the kernel, unsing the call_system
method.
The call_system
method:
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;
}
}