Skip to content

Commit

Permalink
Fix Symbolic link remove problem
Browse files Browse the repository at this point in the history
    When we create symbolic link, in simplefs_new_inode function, the symbolic
does not use ei_block to record the using block. But in simplefs_unlink functoin
we use the ei_block to clean the bitmap, this makes the unlink will clean the "0"
bit in bitmap.

Close #58
  • Loading branch information
RoyWFHuang committed Aug 19, 2024
1 parent 56d2ca0 commit dee5da3
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
3 changes: 2 additions & 1 deletion inode.c
Original file line number Diff line number Diff line change
Expand Up @@ -658,7 +658,8 @@ static int simplefs_unlink(struct inode *dir, struct dentry *dentry)
mark_inode_dirty(inode);

/* Free inode and index block from bitmap */
put_blocks(sbi, bno, 1);
if (S_ISLNK(inode->i_mode))
put_blocks(sbi, bno, 1);
put_inode(sbi, ino);

return ret;
Expand Down
20 changes: 15 additions & 5 deletions script/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ MAXFILES=40920 # max files per dir
MOUNT_TEST=100

test_op() {
local op=$1
local op=$1
echo
echo -n "Testing cmd: $op..."
sudo sh -c "$op" >/dev/null && echo "Success"
Expand All @@ -26,15 +26,15 @@ check_exist() {
echo
echo -n "Check if exist: $mode $nlink $name..."
sudo ls -lR | grep -e "$mode $nlink".*$name >/dev/null && echo "Success" || \
echo "Failed"
echo "Failed"
}

if [ "$EUID" -eq 0 ]
then echo "Don't run this script as root"
exit
fi

mkdir -p test
mkdir -p test
sudo umount test 2>/dev/null
sleep 1
sudo rmmod simplefs 2>/dev/null
Expand Down Expand Up @@ -123,12 +123,22 @@ test_op 'dd if=/dev/zero of=file bs=1M count=12 status=none'
filesize=$(sudo ls -lR | grep -e "$F_MOD 2".*file | awk '{print $5}')
test $filesize -le $MAXFILESIZE || echo "Failed, file size over the limit"

# test remove symbolic link
test_op 'ln -s file symlink_fake'
test_op 'rm -f symlink_fake'
test_op 'touch symlink_fake'
test_op 'ln file symlink_hard_fake'
test_op 'rm -f symlink_hard_fake'
test_op 'touch symlink_hard_fake'

# test if exist
check_exist $D_MOD 3 dir
check_exist $D_MOD 3 dir
check_exist $F_MOD 2 file
check_exist $F_MOD 2 hdlink
check_exist $D_MOD 2 dir
check_exist $S_MOD 1 symlink
check_exist $S_MOD 1 symlink
check_exist $F_MOD 1 symlink_fake
check_exist $F_MOD 1 symlink_hard_fake

sleep 1
popd >/dev/null
Expand Down

0 comments on commit dee5da3

Please sign in to comment.