Skip to contentSkip to conversation

du01.sh: Read the actual filesystem blocksize instead of pagesize

PATCH Superseded Wei Gao via ltp 1 participant 4 messages Jul 3, 2025 – Jul 7, 2025

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 du01.sh: Read the actual filesystem blocksize instead of pagesize

On PPC systems, the page size doesn't always equal the size of a symlink. Therefore, we need to update the test to read the actual filesystem blocksize instead of assuming it's equal to the page size.

---
 testcases/commands/du/du01.sh | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)
testcases/commands/du/du01.sh +4 -6
index 7977fd461..68099de9e 100755
@@ -60,18 +60,16 @@ du_test()
 }
 
 block_size=512
-page_size=$(tst_getconf PAGESIZE)
-if [ "$page_size" -lt 1024 ]; then
-	tst_brk TBROK "Page size < 1024"
-fi
-page_size=$((page_size / 1024))
+
+FS_BLOCK_SIZE_BYTES=$(stat -f --format="%s" .)
+FS_BLOCK_SIZE_KB=$((FS_BLOCK_SIZE_BYTES / 1024))
 
 # The output could be different in some systems, if we use du to
 # estimate file space usage with the same filesystem and the same size.
 # So we use the approximate value to check.
 check1="^10[2-3][0-9][0-9][[:space:]]\."
 check2="^10[2-3][0-9][0-9][[:space:]]testfile"
-check3="^\(0\|${page_size}\)[[:space:]]\.\/testdir\/testsymlink"
+check3="^\(0\|${FS_BLOCK_SIZE_KB}\)[[:space:]]\.\/testdir\/testsymlink"
 check5="^20[4-6][0-9][0-9][[:space:]]\."
 check7="^10[4-5][0-9][0-9]\{4\}[[:space:]]\."
 check9="^10[2-3][0-9][0-9][[:space:]]total"
Signature · 5 lines
2.49.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#1 lore raw

Hi!

Quoted 26 lines · Wei Gao via ltp

On PPC systems, the page size doesn't always equal the size of a symlink. Therefore, we need to update the test to read the actual filesystem blocksize instead of assuming it's equal to the page size.

---
  testcases/commands/du/du01.sh | 10 ++++------
  1 file changed, 4 insertions(+), 6 deletions(-)
testcases/commands/du/du01.sh +3 -5
index 7977fd461..68099de9e 100755
@@ -60,18 +60,16 @@ du_test()
  }
 
  block_size=512
-page_size=$(tst_getconf PAGESIZE)
-if [ "$page_size" -lt 1024 ]; then
-	tst_brk TBROK "Page size < 1024"
-fi
-page_size=$((page_size / 1024))
+
+FS_BLOCK_SIZE_BYTES=$(stat -f --format="%s" .)
+FS_BLOCK_SIZE_KB=$((FS_BLOCK_SIZE_BYTES / 1024))
 

testcases/commands/du/du01.sh du_test() · line 75

Quoted 10 lines
testcases/commands/du/du01.sh +1 -1
  # The output could be different in some systems, if we use du to
  # estimate file space usage with the same filesystem and the same size.
  # So we use the approximate value to check.
  check1="^10[2-3][0-9][0-9][[:space:]]\."
  check2="^10[2-3][0-9][0-9][[:space:]]testfile"
-check3="^\(0\|${page_size}\)[[:space:]]\.\/testdir\/testsymlink"
+check3="^\(0\|${FS_BLOCK_SIZE_KB}\)[[:space:]]\.\/testdir\/testsymlink"
  check5="^20[4-6][0-9][0-9][[:space:]]\."
  check7="^10[4-5][0-9][0-9]\{4\}[[:space:]]\."
  check9="^10[2-3][0-9][0-9][[:space:]]total"

we can just:

block_size_default=512
block_size=$(stat -f --format="%s" .)
block_size=$((block_size / 1024))
....

And then we use "block_size_default" inside do_test().

- Andrea

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#2 lore raw

PATCH v2 1/1 du01.sh: Read the actual filesystem blocksize instead of pagesize

In reply to Wei Gao via ltp

On PPC systems, the page size doesn't always equal the size of a symlink. Therefore, we need to update the test to read the actual filesystem blocksize instead of assuming it's equal to the page size.

---
 testcases/commands/du/du01.sh | 16 +++++++---------
 1 file changed, 7 insertions(+), 9 deletions(-)
testcases/commands/du/du01.sh +7 -9
index 7977fd461..04e9d7611 100755
@@ -59,19 +59,17 @@ du_test()
 	fi
 }
 
-block_size=512
-page_size=$(tst_getconf PAGESIZE)
-if [ "$page_size" -lt 1024 ]; then
-	tst_brk TBROK "Page size < 1024"
-fi
-page_size=$((page_size / 1024))
+block_size_default=512
+
+block_size=$(stat -f --format="%s" .)
+block_size=$((block_size / 1024))
 
 # The output could be different in some systems, if we use du to
 # estimate file space usage with the same filesystem and the same size.
 # So we use the approximate value to check.
 check1="^10[2-3][0-9][0-9][[:space:]]\."
 check2="^10[2-3][0-9][0-9][[:space:]]testfile"
-check3="^\(0\|${page_size}\)[[:space:]]\.\/testdir\/testsymlink"
+check3="^\(0\|${block_size}\)[[:space:]]\.\/testdir\/testsymlink"
 check5="^20[4-6][0-9][0-9][[:space:]]\."
 check7="^10[4-5][0-9][0-9]\{4\}[[:space:]]\."
 check9="^10[2-3][0-9][0-9][[:space:]]total"
@@ -88,8 +86,8 @@ do_test()
 	2) du_test "du testfile" ${check2};;
 	3) du_test "du -a" ${check3};;
 	4) du_test "du --all" ${check3};;
-	5) du_test "du -B ${block_size}" ${check5};;
-	6) du_test "du --block-size=${block_size}" ${check5};;
+	5) du_test "du -B ${block_size_default}" ${check5};;
+	6) du_test "du --block-size=${block_size_default}" ${check5};;
 	7) du_test "du -b" ${check7};;
 	8) du_test "du --bytes" ${check7};;
 	9) du_test "du -c" ${check9};;
Signature · 5 lines
2.49.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#3 lore raw

Merged, thanks!

- Andrea

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp