VFS重命名操作解释
VFS rename operation explaination
我不确定这个问题是否与 SO 相关,也许线程应该在 unix stackexchange 上,但由于这是代码,所以我在这里问。
在linuxVFS中,有一个结构:
struct inode_operations {
...
int (*rename) (struct inode *, struct dentry *,
struct inode *, struct dentry *, unsigned int);
...
让我们改写签名:
int (*rename) (struct old_inode *, struct old_dentry *,
struct new_inode *, struct new_dentry *, unsigned int);
我的测试场景是:
在源目录 (inode=462251) 上,我创建了文件 (inode=516564),将其移动到目标目录 (inode=516511)。
调查对象后我发现:
old_inode = 源目录
old_dentry = 我移动的文件系统对象
new_inode = 目标目录
new_dentry = ?
如果我检查 new_dentry->d_inode,它是空的。
如果我检查 old_dentry->d_inode,它的索引节点号是我复制的文件。
我希望 old_dentry->d_inode 在移动后为空,而 new_dentry->d_inode 将具有移动文件的值。
new_dentry 对象的用途是什么?
如果我打印 old_dentry->d_iname 和 new_dentry->d_iname - 在它们上我都收到了复制文件的名称,但是为什么 new_dentry- >d_inode 是空的?它不应该包含我复制的文件的索引节点吗?
谢谢
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 将有效,如果重命名成功,该文件将被替换。类似于 mv dir1/file1 dir2/file2
,其中 file2 将替换为 file1。就您而言,没有替代品;仅重命名文件。
我不确定这个问题是否与 SO 相关,也许线程应该在 unix stackexchange 上,但由于这是代码,所以我在这里问。
在linuxVFS中,有一个结构:
struct inode_operations {
...
int (*rename) (struct inode *, struct dentry *,
struct inode *, struct dentry *, unsigned int);
...
让我们改写签名:
int (*rename) (struct old_inode *, struct old_dentry *,
struct new_inode *, struct new_dentry *, unsigned int);
我的测试场景是:
在源目录 (inode=462251) 上,我创建了文件 (inode=516564),将其移动到目标目录 (inode=516511)。
调查对象后我发现:
old_inode = 源目录
old_dentry = 我移动的文件系统对象
new_inode = 目标目录
new_dentry = ?
如果我检查 new_dentry->d_inode,它是空的。
如果我检查 old_dentry->d_inode,它的索引节点号是我复制的文件。
我希望 old_dentry->d_inode 在移动后为空,而 new_dentry->d_inode 将具有移动文件的值。
new_dentry 对象的用途是什么?
如果我打印 old_dentry->d_iname 和 new_dentry->d_iname - 在它们上我都收到了复制文件的名称,但是为什么 new_dentry- >d_inode 是空的?它不应该包含我复制的文件的索引节点吗?
谢谢
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 将有效,如果重命名成功,该文件将被替换。类似于 mv dir1/file1 dir2/file2
,其中 file2 将替换为 file1。就您而言,没有替代品;仅重命名文件。