Directory Inode vs Regular File Inode

I believe it’s the mode of the inode…

umode_t            i_mode;

To access the field see stat(2) man page:

   The following POSIX macros are defined to check the file type using the st_mode field:

       S_ISREG(m)  is it a regular file?

       S_ISDIR(m)  directory?

       S_ISCHR(m)  character device?

       S_ISBLK(m)  block device?

       S_ISFIFO(m) FIFO (named pipe)?

       S_ISLNK(m)  symbolic link? (Not in POSIX.1-1996.)

       S_ISSOCK(m) socket? (Not in POSIX.1-1996.)

Here is some example code from the Linux driver for minix FS:

434 void minix_set_inode(struct inode *inode, dev_t rdev)
435 {
436         if (S_ISREG(inode->i_mode)) {
437                 inode->i_op = &minix_file_inode_operations;
438                 inode->i_fop = &minix_file_operations;
439                 inode->i_mapping->a_ops = &minix_aops;
440         } else if (S_ISDIR(inode->i_mode)) {
441                 inode->i_op = &minix_dir_inode_operations;
442                 inode->i_fop = &minix_dir_operations;
443                 inode->i_mapping->a_ops = &minix_aops;
444         } else if (S_ISLNK(inode->i_mode)) {
445                 inode->i_op = &minix_symlink_inode_operations;
446                 inode->i_mapping->a_ops = &minix_aops;
447         } else
448                 init_special_inode(inode, inode->i_mode, rdev);
449 }
450 

Leave a Comment