Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix symlink block allocation mismatch causing unlink bitmap errors #64

Merged
merged 2 commits into from
Aug 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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