Skip to contentSkip to conversation

rwtest: Confirm df is a symlink to busybox

PATCH In review Mengchi Cheng via ltp 2 participants 5 messages Nov 30, 2023 – Dec 1, 2023

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 rwtest: Confirm df is a symlink to busybox

/bin/df can be a symlink to coreutils. It returns correct info with dir arguments.
Just checking if df is a symlink will include such cases. Need to make sure it is linking to busybox before ignoring options.

---
 testcases/kernel/fs/doio/rwtest | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
testcases/kernel/fs/doio/rwtest +4 -4
index 6725e1426..26659e9d3 100644
@@ -329,10 +329,10 @@ do
 		else
 			# If df is a symlink (to busybox) then do not pass the $dir and $dfOpts
 			# parameters because they don't work as expected
-                        if test -h $(which df)
-                           then
-                               dir=""; dfOpts="";
-                        fi
+			if [[ "$(readlink -f "$(which df)")" == *"busybox"* ]]
+			then
+				dir=""; dfOpts="";
+			fi
 
 			blks=$(df $dfOpts $dir |
 			(while read fs blks used avail cap mountpoint
Signature · 5 lines
2.25.1


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

Hi Mengchi,

Quoted 15 lines

/bin/df can be a symlink to coreutils. It returns correct info with dir arguments.
Just checking if df is a symlink will include such cases. Need to make sure it is linking to busybox before ignoring options.

---
 testcases/kernel/fs/doio/rwtest | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
testcases/kernel/fs/doio/rwtest +0 -0
index 6725e1426..26659e9d3 100644

testcases/kernel/fs/doio/rwtest do · line 332

Quoted 8 lines
testcases/kernel/fs/doio/rwtest +1 -4
@@ -329,10 +329,10 @@ do
 		else
 			# If df is a symlink (to busybox) then do not pass the $dir and $dfOpts
 			# parameters because they don't work as expected
-                        if test -h $(which df)
-                           then
-                               dir=""; dfOpts="";
-                        fi
+			if [[ "$(readlink -f "$(which df)")" == *"busybox"* ]]

Could you please test if this works?

			if [ "$(readlink -f "$(which df)")" = "busybox" ]

Although this script uses bash, we generally don't want to use it. Thus it'd be better to not introduce any bash specific code.

BTW this is very old and very ugly script, we should cleanup it or delete:
https://github.com/linux-test-project/ltp/issues/1110

Kind regards,
Petr

Quoted 6 lines
testcases/kernel/fs/doio/rwtest +3 -0
+			then
+				dir=""; dfOpts="";
+			fi
 
 			blks=$(df $dfOpts $dir |
 			(while read fs blks used avail cap mountpoint
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#3 lore raw
In reply to Petr Vorel
Quoted 28 lines · Petr Vorel

Hi Mengchi,

Quoted 15 lines

/bin/df can be a symlink to coreutils. It returns correct info with dir arguments.
Just checking if df is a symlink will include such cases. Need to make sure it is linking to busybox before ignoring options.

---
 testcases/kernel/fs/doio/rwtest | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
testcases/kernel/fs/doio/rwtest +0 -0
index 6725e1426..26659e9d3 100644

testcases/kernel/fs/doio/rwtest do · line 332

Quoted 8 lines
testcases/kernel/fs/doio/rwtest +1 -4
@@ -329,10 +329,10 @@ do
 		else
 			# If df is a symlink (to busybox) then do not pass the $dir and $dfOpts
 			# parameters because they don't work as expected
-                        if test -h $(which df)
-                           then
-                               dir=""; dfOpts="";
-                        fi
+			if [[ "$(readlink -f "$(which df)")" == *"busybox"* ]]

Could you please test if this works?

Quoted 1 line
			if [ "$(readlink -f "$(which df)")" = "busybox" ]

I just replaced df with a symlink cmd and the string such as zstdmt/zstd in ubuntu. It does not work..
But below should work

			if echo "$(readlink -f "$(which df)")" | grep -q "busybox"

However, I linked df to /bin/busybox on my device, df -P ${dir} seems fine. The original code may be for a very old version of busybox.

:/# ls -l /bin/df
lrwxrwxrwx 1 root root 12 2023-11-16 17:49 /bin/df -> /bin/busybox
:/# df -P tmp
Filesystem           1024-blocks    Used Available Capacity Mounted on
tmpfs                   280848         4    280844   0% /tmp
:/# /usr/bin/df.coreutils -P tmp
Filesystem     1024-blocks  Used Available Capacity Mounted on
tmpfs               280848     4    280844       1% /tmp

My busybox version is v1.35.0. It might be ok to remove the check completely.

Best,
Mengchi

Quoted 20 lines

Although this script uses bash, we generally don't want to use it. Thus it'd be better to not introduce any bash specific code.

BTW this is very old and very ugly script, we should cleanup it or delete:
https://github.com/linux-test-project/ltp/issues/1110

Kind regards,
Petr

Quoted 6 lines
testcases/kernel/fs/doio/rwtest +3 -0
+			then
+				dir=""; dfOpts="";
+			fi
 
 			blks=$(df $dfOpts $dir |
 			(while read fs blks used avail cap mountpoint
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#4 lore raw
Quoted 29 lines · Petr Vorel
Quoted 27 lines

Hi Mengchi,

Quoted 15 lines

/bin/df can be a symlink to coreutils. It returns correct info with dir arguments.
Just checking if df is a symlink will include such cases. Need to make sure it is linking to busybox before ignoring options.

---
 testcases/kernel/fs/doio/rwtest | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
testcases/kernel/fs/doio/rwtest +0 -0
index 6725e1426..26659e9d3 100644

testcases/kernel/fs/doio/rwtest do · line 332

Quoted 8 lines
testcases/kernel/fs/doio/rwtest +1 -4
@@ -329,10 +329,10 @@ do
 		else
 			# If df is a symlink (to busybox) then do not pass the $dir and $dfOpts
 			# parameters because they don't work as expected
-                        if test -h $(which df)
-                           then
-                               dir=""; dfOpts="";
-                        fi
+			if [[ "$(readlink -f "$(which df)")" == *"busybox"* ]]

Could you please test if this works?

Quoted 6 lines
Quoted 1 line
			if [ "$(readlink -f "$(which df)")" = "busybox" ]

I just replaced df with a symlink cmd and the string such as zstdmt/zstd in ubuntu. It does not work..
But below should work

			if echo "$(readlink -f "$(which df)")" | grep -q "busybox"

Yes, this would work, but this would be better:

if df --version 2>&1 | grep -q 'BusyBox'

this is way simpler and this detection is already used elsewhere.

BTW how can happen that df is symlink on coreutils? They provide a binary, right?

Quoted 11 lines

However, I linked df to /bin/busybox on my device, df -P ${dir} seems fine. The original code may be for a very old version of busybox.

:/# ls -l /bin/df
lrwxrwxrwx 1 root root 12 2023-11-16 17:49 /bin/df -> /bin/busybox
:/# df -P tmp
Filesystem           1024-blocks    Used Available Capacity Mounted on
tmpfs                   280848         4    280844   0% /tmp
:/# /usr/bin/df.coreutils -P tmp
Filesystem     1024-blocks  Used Available Capacity Mounted on
tmpfs               280848     4    280844       1% /tmp
Quoted 1 line

My busybox version is v1.35.0. It might be ok to remove the check completely.

-P was implemented in 2008
https://github.com/mirror/busybox/commit/d66aa3c701ffb83343239e71a8b294407ff5df86

BusyBox has often some features configurable (feature can be disabled), but if I look correctly -P is not guarded to any config option

https://github.com/mirror/busybox/blob/master/coreutils/df.c

Therefore I'm for removing this option entirely. Please send v2.

Kind regards,
Petr

Quoted 2 lines

Best,
Mengchi

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