Skip to content

Commit a6801fa

Browse files
authored
Merge pull request #67 from RoyWFHuang/bug/issue66_write
Fix user-space data write with incorrect offset
2 parents 23b373e + 3abe802 commit a6801fa

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

file.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -413,8 +413,8 @@ static ssize_t simplefs_write(struct file *file,
413413
size_t bytes_to_write =
414414
min_t(size_t, len, SIMPLEFS_BLOCK_SIZE - pos % SIMPLEFS_BLOCK_SIZE);
415415

416-
if (copy_from_user(bh_data->b_data + pos % SIMPLEFS_BLOCK_SIZE, buf,
417-
bytes_to_write)) {
416+
if (copy_from_user(bh_data->b_data + pos % SIMPLEFS_BLOCK_SIZE,
417+
buf + bytes_write, bytes_to_write)) {
418418
brelse(bh_data);
419419
bytes_write = -EFAULT;
420420
break;

script/test.sh

+12
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,18 @@ 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+
# Write the file size larger than BLOCK_SIZE
127+
# test serial to write
128+
test_op 'printf \"%.0s123456789\" {1..1600} > file.txt'
129+
count=$(awk '{count += gsub(/123456789/, "")} END {print count}' "file.txt")
130+
echo "test $count"
131+
test "$count" -eq 1600 || echo "Failed, file size not matching"
132+
# test block to write
133+
test_op 'cat file.txt > checkfile.txt'
134+
count=$(awk '{count += gsub(/123456789/, "")} END {print count}' "checkfile.txt")
135+
echo "test $count"
136+
test "$count" -eq 1600 || echo "Failed, file size not matching"
137+
126138
# test remove symbolic link
127139
test_op 'ln -s file symlink_fake'
128140
test_op 'rm -f symlink_fake'

0 commit comments

Comments
 (0)