The open( ) system call is serviced by the sys_open( ) function, which receives as parameters the pathname filename of the file to be opened, some access mode flags flags, and a permission bit mask mode if the file must be created. If the system call succeeds, it returns a file descriptor—that is, the index assigned to the new file in the current->files->fd array of pointers to file objects; otherwise, it returns -1.
In our example, open( ) is invoked twice; the first time to open /floppy/TEST for reading (o_rdonly flag) and the second time to open /tmp/test for writing (o_wronly flag). If /tmp/test does not already exist, it is created (o_creat flag) with exclusive read and write access for the owner (octal 0600 number in the third parameter).
Conversely, if the file already exists, it is rewritten from scratch (o_trunc flag). Table 12-17 lists all flags of the open( ) system call.
Was this article helpful?