As a part of an alignement at university I have to modify the function unlink_file
located in /usr/src/minix/fs/mfs/link.c
, so (under certain conditions) instead of removing files it just changes their name.
I have parent directory's inode, file's inode and its name passed to the function as parameters:
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 */
I thought of using the rename(2)
syscall (which implementation is located in the same file in the function fs_rename
), but I need an absolute path of the file in order to do so. Unfortunately, I don't know how to retrieve it from inode structure.
My question is: how can I retrieve an absolute path to the file by its inode? Or is there another way to rename a file from inside the unlink_file
function?