mapping of inode and file structure in Open System call

Saket Sinha saket.sinha89 at gmail.com
Mon Nov 17 02:05:41 EST 2014


Hi Lokesh,

                I am putting down the entire call flow from the
userspace open to the driver implementation below -

1. touch program is used to create an empty file. touch is part of the
fileutils package, and is implemented in src/touch.c. What it
basically does is set some flags and invoke the open() syscall, then
calls close().

2. sys_open() in fs/open.c - it grabs the filename from userland, if
the filename seems OK - grab the next free file descriptor, actually
open the file with function filp_open() and give the file descriptor
to the user.

3. filp open() in fs/open.c - Create a nameidata struct (which creates
the file), opens the dentry associated with the nameidata structure in
function path_openat() and returns a file pointer to the file itself.

4.path_openat in fs/namei.c - Standard path init(), path walk() dance,
if the inode does not yet exist, we actually create it in
do_last->lookup_open() by vfs_create().

5. vfs_create() in fs/namei.c - This triggers filesystem specific
create by the statement dir->i_op->create.

6. Now go to filesystem specific create in the inode_opetations
structure for example for ext2-
Inode operations for Ext2 are defined in fs/ext2/namei.c:

struct inode_operations ext2_dir_inode_operations = {
create: ext2_create,
lookup: ext2_lookup,
link: ext2_link,
unlink: ext2_unlink,
symlink: ext2_symlink,
mkdir: ext2_mkdir,
rmdir: ext2_rmdir,
. . . . . . . . . . .
};

Hope this helps.

Regards,
Saket Sinha


On Thu, Nov 13, 2014 at 11:14 AM, Pranay Srivastava <pranjas at gmail.com> wrote:
> Hi Lokesh
>
> On Wed, Nov 12, 2014 at 6:42 PM, lokesh kumar <lokeshkumar.222 at gmail.com> wrote:
>> Hi,
>>
>> I have a question regarding  open systemcall
>>
>> "open(dev_name, O_RDWR, 0)"    -->userspace
>>
>> suppose devname is /dev/my_device
>>
>> Now when we look into open file operation, we have prototype
>> "int (*open) (struct inode *, struct file *);"
>>
>> could anyone tell me how inode and file structure pointer are filled.
>>
>> I think logic is written in fs/open.c
>>
>> but i got confused in callbacks used in it.could anyone please tell me
>> which topics should i cover to understand open system call.
>>
>
> You should probably first understand how the file is located. See the
> role of lookup.
>
>> Thanks.
>>
>> _______________________________________________
>> Kernelnewbies mailing list
>> Kernelnewbies at kernelnewbies.org
>> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
>
>
>
> --
>         ---P.K.S
>
> _______________________________________________
> Kernelnewbies mailing list
> Kernelnewbies at kernelnewbies.org
> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies



More information about the Kernelnewbies mailing list