Skip to content

Commit

Permalink
Merge pull request #64 from RoyWFHuang/master
Browse files Browse the repository at this point in the history
Fix symlink block allocation mismatch causing unlink bitmap errors
  • Loading branch information
jserv authored Aug 20, 2024
2 parents 56d2ca0 + 96fca81 commit 31258fc
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
7 changes: 3 additions & 4 deletions inode.c
Original file line number Diff line number Diff line change
Expand Up @@ -640,7 +640,6 @@ static int simplefs_unlink(struct inode *dir, struct dentry *dentry)
inode->i_size = 0;
i_uid_write(inode, 0);
i_gid_write(inode, 0);
inode->i_mode = 0;

#if SIMPLEFS_AT_LEAST(6, 7, 0)
inode_set_mtime(inode, 0, 0);
Expand All @@ -654,11 +653,11 @@ static int simplefs_unlink(struct inode *dir, struct dentry *dentry)
#endif

inode_dec_link_count(inode);
drop_nlink(inode);
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);
inode->i_mode = 0;
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 31258fc

Please sign in to comment.