Skip to content

Commit dee5da3

Browse files
committed
Fix Symbolic link remove problem
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
1 parent 56d2ca0 commit dee5da3

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

inode.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -658,7 +658,8 @@ static int simplefs_unlink(struct inode *dir, struct dentry *dentry)
658658
mark_inode_dirty(inode);
659659

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

664665
return ret;

script/test.sh

+15-5
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ MAXFILES=40920 # max files per dir
1313
MOUNT_TEST=100
1414

1515
test_op() {
16-
local op=$1
16+
local op=$1
1717
echo
1818
echo -n "Testing cmd: $op..."
1919
sudo sh -c "$op" >/dev/null && echo "Success"
@@ -26,15 +26,15 @@ check_exist() {
2626
echo
2727
echo -n "Check if exist: $mode $nlink $name..."
2828
sudo ls -lR | grep -e "$mode $nlink".*$name >/dev/null && echo "Success" || \
29-
echo "Failed"
29+
echo "Failed"
3030
}
3131

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

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

126+
# test remove symbolic link
127+
test_op 'ln -s file symlink_fake'
128+
test_op 'rm -f symlink_fake'
129+
test_op 'touch symlink_fake'
130+
test_op 'ln file symlink_hard_fake'
131+
test_op 'rm -f symlink_hard_fake'
132+
test_op 'touch symlink_hard_fake'
133+
126134
# test if exist
127-
check_exist $D_MOD 3 dir
135+
check_exist $D_MOD 3 dir
128136
check_exist $F_MOD 2 file
129137
check_exist $F_MOD 2 hdlink
130138
check_exist $D_MOD 2 dir
131-
check_exist $S_MOD 1 symlink
139+
check_exist $S_MOD 1 symlink
140+
check_exist $F_MOD 1 symlink_fake
141+
check_exist $F_MOD 1 symlink_hard_fake
132142

133143
sleep 1
134144
popd >/dev/null

0 commit comments

Comments
 (0)