diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index e8067b4..8edb577 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -22,7 +22,7 @@ jobs: uses: actions/checkout@v4 - name: coding convention run: | - sudo apt-get install -q -y clang-format-12 + sudo apt-get install -q -y clang-format .ci/check-newline.sh .ci/check-format.sh shell: bash diff --git a/file.c b/file.c index b6cfc6d..f6868c0 100644 --- a/file.c +++ b/file.c @@ -413,8 +413,8 @@ static ssize_t simplefs_write(struct file *file, size_t bytes_to_write = min_t(size_t, len, SIMPLEFS_BLOCK_SIZE - pos % SIMPLEFS_BLOCK_SIZE); - if (copy_from_user(bh_data->b_data + pos % SIMPLEFS_BLOCK_SIZE, buf, - bytes_to_write)) { + if (copy_from_user(bh_data->b_data + pos % SIMPLEFS_BLOCK_SIZE, + buf + bytes_write, bytes_to_write)) { brelse(bh_data); bytes_write = -EFAULT; break; diff --git a/mkfs.c b/mkfs.c index 01a6e0b..59dd967 100644 --- a/mkfs.c +++ b/mkfs.c @@ -26,7 +26,7 @@ _Static_assert(sizeof(struct superblock) == SIMPLEFS_BLOCK_SIZE); * * Return the result of n / d, rounded up to the nearest integer. */ -#define DIV_ROUND_UP(n, d) (((n) + (d) -1) / (d)) +#define DIV_ROUND_UP(n, d) (((n) + (d) - 1) / (d)) static struct superblock *write_superblock(int fd, struct stat *fstats) { diff --git a/script/test.sh b/script/test.sh index b1df6fc..6ba5ad0 100755 --- a/script/test.sh +++ b/script/test.sh @@ -123,6 +123,18 @@ 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" +# Write the file size larger than BLOCK_SIZE +# test serial to write +test_op 'bash -c "printf \"%.0s123456789\" {1..1600} > file.txt"' +count=$(awk '{count += gsub(/123456789/, "")} END {print count}' "file.txt") +echo "test $count" +test "$count" -eq 1600 || echo "Failed, file size not matching" +# test block to write +test_op 'cat file.txt > checkfile.txt' +count=$(awk '{count += gsub(/123456789/, "")} END {print count}' "checkfile.txt") +echo "test $count" +test "$count" -eq 1600 || echo "Failed, file size not matching" + # test remove symbolic link test_op 'ln -s file symlink_fake' test_op 'rm -f symlink_fake'