sysprog21 / simplefs

A simple native file system for Linux kernel
Other
362 stars 91 forks source link

Fix rm hard link bug #37

Closed RoyWFHuang closed 6 months ago

RoyWFHuang commented 6 months ago

Description

When create a hard link and then remove this hard link, at this time we use "ls" to list all files, the file lists will not correct showing the result

here is showing result:

.: ls: cannot access 'hdlink': No such file or directory total 1 -rw-r--r-- 1 root root 0 Feb 19 03:32 file2 ?????????? ? ? ? ? ? hdlink

this means the rm hard link remove the original file, not remove hard link file

Root cause

In unlink function, we not only need to check ino number is the same, but also check the the inode block name is the same

Fix solution

Add to check the find block's name is the same with remove name

How has this been tested:

run: touch file1 run: touch file2 run:ln file1 hdlink run:ls -lR .: total 2 -rw-r--r-- 2 root root 0 Feb 19 15:00 file1 -rw-r--r-- 1 root root 0 Feb 19 15:00 file2 -rw-r--r-- 2 root root 0 Feb 19 15:00 hdlink run:rm hdlink run:ls -lR .: total 1 -rw-r--r-- 1 root root 0 Feb 19 15:00 file1 -rw-r--r-- 1 root root 0 Feb 19 15:00 file2

Yueh-Wang commented 6 months ago

您好,您的邮件我已收到,我会尽快给您回复。