Skip to content

Commit f18a398

Browse files
committed
Fix rm hard link problem
Add the inode name compration in the unlink function Since the hard link uses the same inode number as the original file inode, it's necessary to check the name to prevent deletion of the wrong inode.
1 parent d6f3656 commit f18a398

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

inode.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,8 @@ static int simplefs_remove_from_dir(struct inode *dir, struct dentry *dentry)
472472
}
473473
/* Remove file from parent directory */
474474
for (fi = 0; fi < SIMPLEFS_FILES_PER_BLOCK; fi++) {
475-
if (dblock->files[fi].inode == inode->i_ino) {
475+
if (dblock->files[fi].inode == inode->i_ino &&
476+
!strcmp(dblock->files[fi].filename, dentry->d_name.name) ) {
476477
found = true;
477478
if (fi != SIMPLEFS_FILES_PER_BLOCK - 1) {
478479
memmove(dblock->files + fi, dblock->files + fi + 1,

0 commit comments

Comments
 (0)