c++ - Open() syscall filedesriptor -



c++ - Open() syscall filedesriptor -

i have right homecoming value of open() syscall of posix os. understood man-pages has homecoming file descriptor, , , in case of error scheme phone call homecoming -1 , set errno value. problem not know how file descriptor opened nod. checked files , didn't found method can assign fd processes.

here 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); homecoming msg.error.number; }

syscall_message struct holds info info scheme call. syscalls namesapace scheme calls are. syscaller used send phone call kernel, unsing call_system method.

the call_system method:

syscalls::open_call: { //get file i_fs_node_ptr file = i_fs::open_node( msg.open_data.path_name ); //add 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; } }

i don't know mean "i can't file descriptor". have mentioned open() returns it. it's stored in integer variable. if variable equal -1, has gone wrong. illustration if have

int file = open(path, o_sync, o_direct, o_rdonly);

but not have reading permissions file named path variable file value of -1. additional manipulation on opened file can done via read() (if file opened in read mode) , write() (if file opened in write mode). suggest read documentation on open() function more carefully. if need more command on file descriptor suggest utilize fopen():

discussion on difference between open() , fopen() tutorial on fopen() documentation on fopen()

c++ operating-system system-calls

Comments

Popular posts from this blog

assembly - What is the addressing mode for ld, add, and rjmp instructions? -

vowpalwabbit - Interpreting Vowpal Wabbit results: Why are some lines appended by "h"? -

Is there a way to convert an HTML page styled with Bootstrap CSS into email-compatible html? -