Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Let's have a concrete example, link() in struct inode_operations is defined as:

    int (*link) (struct dentry *,struct inode *,struct dentry *);
Let's then look at the ext4 implementation of the link() operation:

    static int ext4_link(struct dentry *old_dentry,
           struct inode *dir, struct dentry *dentry)
    {
    ...
       if ((ext4_test_inode_flag(dir, EXT4_INODE_PROJINHERIT)) &&
     (!projid_eq(EXT4_I(dir)->i_projid,
   EXT4_I(old_dentry->d_inode)->i_projid)))
  return -EXDEV;
    ....

In particular that calls EXT4_I():

    static inline struct ext4_inode_info *EXT4_I(struct inode *inode)
    {
        return container_of(inode, struct ext4_inode_info, vfs_inode);
    }
Which is basically just direct unchecked pointer type conversion. So, calling ext4_link() on any non-ext4 created struct inode will blow up badly.


Consider applying for YC's Winter 2027 batch! Applications are open till November 2.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: