Filesystems 如何在Minix mfs中通过索引节点重命名文件?

Filesystems 如何在Minix mfs中通过索引节点重命名文件?,filesystems,rename,inode,minix,Filesystems,Rename,Inode,Minix,作为大学对齐的一部分,我必须修改位于中的函数unlink_file,因此在某些情况下,它不会删除文件,而只是更改其名称 我将父目录的inode、文件的inode及其名称作为参数传递给函数: static int unlink_file(dirp, rip, file_name) struct inode *dirp; /* parent directory of file */ struct inode *rip; /* inode of file, may be NULL t

作为大学对齐的一部分,我必须修改位于中的函数unlink_file,因此在某些情况下,它不会删除文件,而只是更改其名称

我将父目录的inode、文件的inode及其名称作为参数传递给函数:

static int unlink_file(dirp, rip, file_name)
struct inode *dirp;     /* parent directory of file */
struct inode *rip;      /* inode of file, may be NULL too. */
char file_name[MFS_NAME_MAX];   /* name of file to be removed */
我曾想过使用syscall,它的实现位于函数fs_rename中的同一个文件中,但我需要文件的绝对路径才能这样做。不幸的是,我不知道如何从inode结构中检索它


我的问题是:如何通过inode检索文件的绝对路径?或者有没有其他方法可以从unlink_file函数内部重命名文件?

请注意fs_rename对消息的作用,它获取指向inode的指针

取消链接的_文件已经有指向文件inode的指针和指向文件所在目录的指针。如果您只需要重命名它,那么可以检查在旧dirp和新dirp都相同的情况下fs_rename是如何工作的

same_pdir == (old_dip == new_dirp); //somewhere in fs_rename()
(bunch of error checks..)
if(same_pdir){
r = search_dir(old_dirp, old_name, NULL, DELETE, IGN_PERM); // this deletes the file from directory
if(r == OK)
(void)search_dir(old_dirp, new_name, &numb, ENTER, IGN_PERM); //this creates file with new_name in the directory
}
请记住,这部分代码假定目录中当前不存在名为new_name的文件,因为在我跳过的错误检查中,此类文件将被删除