I am not sure the question is relevant to SO, maybe thread should be on unix stackexchange, but since this is code, I ask here.
In linux VFS, there is a struct:
struct inode_operations {
...
int (*rename) (struct inode *, struct dentry *,
struct inode *, struct dentry *, unsigned int);
...
Lets rephrase the singature:
int (*rename) (struct old_inode *, struct old_dentry *,
struct new_inode *, struct new_dentry *, unsigned int);
My test scenario is:
On source directory (inode=462251), I created file (inode=516564), Moved it to destination directory (inode=516511).
After investigated the objects I found that:
old_inode = source directory
old_dentry = file system object that I move
new_inode = destination directory
new_dentry = ?
If i inspect new_dentry->d_inode, it is null.
If i inspect old_dentry->d_inode, its inode number is of the file I copied.
I would expect that old_dentry->d_inode will be null after the move and new_dentry->d_inode will have value of the moved file.
What is the purpose of new_dentry object ?
If i print old_dentry->d_iname and new_dentry->d_iname - on both of them I received the name of the copied file, But why new_dentry->d_inode is empty ? shouldn't it contain the inode of the file I copied ?
Thanks
What is the purpose of new_dentry object ? But why new_dentry->d_inode is empty ? shouldn't it contain the inode of the file I copied ?
new_dentry->inode will be valid if the destination already contains a file, which will be replaced if the rename succeeds. Something like mv dir1/file1 dir2/file2
where file2 will be replaced with file1. In your case, there was no replacement; only renaming the file.