Figure 919 Code flow diagram for ext2create

Let us first examine how new directories are created using mkdir. The kernel passes via the VFS function vfs_mkdir to the ext2_mkdir low-level function with the following signature.

fs/ext2/namei.c static int ext2_mkdir(struct inode * dir, struct dentry * dentry, int mode)

dir is the directory in which the new subdirectory is to be created, and dentry specifies the pathname of the new directory. mode specifies the access mode of the new directory.

Once ext2_new_inode has reserved a new inode at a suitable place on the hard disk (the section below describes how the kernel finds the most suitable location with the help of the Orlov allocator), it is provided with the appropriate file, inode, and address space operations.

fs/ext2/namei.c static int ext2_mkdir(struct inode * dir, struct dentry * dentry, int mode) {

inode->i_op = &ext2_dir_inode_operations; inode->i_fop = &ext2_dir_operations; if (test_opt(inode->i_sb, NOBH))

inode->i_mapping->a_ops = &ext2_nobh_aops;

else inode->i_mapping->a_ops = &ext2_aops;

ext2_make_empty fills the inode with the default . and .. entries by generating the corresponding file structures and writing them to the data block. Then ext2_add_link adds the new directory to the existing directory data of the initial inode in the format described in Section 9.2.2.

New files are created in a similar way. The sys_open system call arrives at vfs_create, which again invokes the ext2_create low-level function of the Ext2 filesystem.

Once it has allocated a new inode on the hard disk by means of ext2_new_inode, the appropriate file, inode, and address space structures are added, this time using the variants for regular files, that is, ext2_file_inode_operations and ext2_file_operations.

Continue reading here: Registering Inodes

Was this article helpful?

0 0