2

Linux ramfs 使用 simple_rename(),但为什么在这样的函数中 new_dentry 和 old_inode 没有相互链接?

这是 simple_rename() 的源代码供您参考:

int simple_rename(struct inode *old_dir, struct dentry *old_dentry,
                struct inode *new_dir, struct dentry *new_dentry)
{
        struct inode *inode = old_dentry->d_inode;
        int they_are_dirs = S_ISDIR(old_dentry->d_inode->i_mode);

        if (!simple_empty(new_dentry))
                return -ENOTEMPTY;

        if (new_dentry->d_inode) {
                simple_unlink(new_dir, new_dentry);
                if (they_are_dirs)
                        drop_nlink(old_dir);
        } else if (they_are_dirs) {
                drop_nlink(old_dir);
                inc_nlink(new_dir);
        }

        old_dir->i_ctime = old_dir->i_mtime = new_dir->i_ctime =
                new_dir->i_mtime = inode->i_ctime = CURRENT_TIME;

        return 0;
}

谢谢!

4

0 回答 0