Skip to contentSkip to conversation

ver_linux: Print filesystems

PATCH In review Petr Vorel 2 participants 8 messages Oct 27, 2021 – Nov 3, 2021

lore
Share & tools
lore

Petr Vorel

author
#0 lore raw

PATCH v2 1/1 ver_linux: Print filesystems

both available and mounted.

check for options as aosp toybox does not support -h, -T option requires IF_FEATURE_HUMAN_READABLE on busybox.

---
changes v1->v2:
properly check options

 ver_linux | 15 +++++++++++++++
 1 file changed, 15 insertions(+)
ver_linux +15 -0
index 824c39510..82b7468a6 100755
@@ -138,6 +138,21 @@ echo
 echo 'cpuinfo:'
 tst_cmd_run lscpu || cat /proc/cpuinfo
 
+echo
+echo 'available filesystems:'
+echo $(cut -f2 /proc/filesystems | sort -u)
+
+echo
+echo 'mounted filesystems (/proc/mounts):'
+cat /proc/mounts
+
+echo
+echo 'mounted filesystems (df):'
+df_opt=
+if ! (df -h 2>&1 | grep -i -q -e 'unknown option' -e 'invalid option'); then df_opt="$df_opt -h"; fi
+if ! (df -T 2>&1 | grep -i -q -e 'unknown option' -e 'invalid option'); then df_opt="$df_opt -T"; fi
+df $df_opt
+
 echo
 if is_enabled /sys/module/apparmor/parameters/enabled; then
 	echo 'AppArmor enabled'
Signature · 5 lines
2.33.1


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

Hi!

ver_linux echo · line 153

Quoted 4 lines
ver_linux +4 -0
+echo 'mounted filesystems (df):'
+df_opt=
+if ! (df -h 2>&1 | grep -i -q -e 'unknown option' -e 'invalid option'); then df_opt="$df_opt -h"; fi
+if ! (df -T 2>&1 | grep -i -q -e 'unknown option' -e 'invalid option'); then df_opt="$df_opt -T"; fi

Uff that's ugly, can't we simply depend on df returning non-zero on invalid option?

Quoted 11 lines
ver_linux +2 -0
+df $df_opt
+
 echo
 if is_enabled /sys/module/apparmor/parameters/enabled; then
 	echo 'AppArmor enabled'
Signature · 5 lines
2.33.1


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
Signature · 5 lines
Cyril Hrubis
[email protected]

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

Hi Cyril,

Quoted 8 lines

Hi!

ver_linux echo · line 153

Quoted 4 lines
ver_linux +4 -0
+echo 'mounted filesystems (df):'
+df_opt=
+if ! (df -h 2>&1 | grep -i -q -e 'unknown option' -e 'invalid option'); then df_opt="$df_opt -h"; fi
+if ! (df -T 2>&1 | grep -i -q -e 'unknown option' -e 'invalid option'); then df_opt="$df_opt -T"; fi

Uff that's ugly, can't we simply depend on df returning non-zero on invalid option?

On real HW (2 laptops with different linux distros) it fails for something else:

$ df -hT; echo $?
df: /run/user/1000/doc: Operation not permitted
1

If you want simpler form, I suggest
df -hT 2>/dev/null || df

instead of:
df -hT 2>/dev/null || df -h

Which version should I merge?

Kind regards,
Petr

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

Hi!

Quoted 2 lines

If you want simpler form, I suggest
df -hT 2>/dev/null || df

Looks good.

Signature · 5 lines
Cyril Hrubis
[email protected]

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
author
#4 lore raw
Quoted 5 lines

Hi!

Quoted 2 lines

If you want simpler form, I suggest
df -hT 2>/dev/null || df

Looks good.

Ah, sorry, I see why I checked it more complicated way:
with simply checking exit code you have output twice:

df -hT 2>/dev/null || df

Filesystem                     Type      Size  Used Avail Use% Mounted on
devtmpfs                       devtmpfs   16G  8,0K   16G   1% /dev
tmpfs                          tmpfs      16G   91M   16G   1% /dev/shm
tmpfs                          tmpfs     6,2G  4,1M  6,2G   1% /run
...
df: /run/user/1000/doc: Operation not permitted
Filesystem                     Type      Size  Used Avail Use% Mounted on
devtmpfs                       devtmpfs   16G  8,0K   16G   1% /dev
tmpfs                          tmpfs      16G   91M   16G   1% /dev/shm
tmpfs                          tmpfs     6,2G  4,1M  6,2G   1% /run

...

=> which is IMHO nogo. I could redirect to a file and cut it after, but in that case v2 is IMHO much better.

Kind regards,
Petr

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

Hi!

Quoted 14 lines

Ah, sorry, I see why I checked it more complicated way:
with simply checking exit code you have output twice:

df -hT 2>/dev/null || df

Filesystem                     Type      Size  Used Avail Use% Mounted on
devtmpfs                       devtmpfs   16G  8,0K   16G   1% /dev
tmpfs                          tmpfs      16G   91M   16G   1% /dev/shm
tmpfs                          tmpfs     6,2G  4,1M  6,2G   1% /run
...
df: /run/user/1000/doc: Operation not permitted
Filesystem                     Type      Size  Used Avail Use% Mounted on
devtmpfs                       devtmpfs   16G  8,0K   16G   1% /dev
tmpfs                          tmpfs      16G   91M   16G   1% /dev/shm
tmpfs                          tmpfs     6,2G  4,1M  6,2G   1% /run
Quoted 4 lines

...

=> which is IMHO nogo. I could redirect to a file and cut it after, but in that case v2 is IMHO much better.

But still we don't need that grep part, right?

So it should be something as:

	if `df -hT 2>/dev/null >/dev/null`; then
		df -hT
	else
		df
	fi
Signature · 5 lines
Cyril Hrubis
[email protected]

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
author
#6 lore raw
Quoted 22 lines

Hi!

Quoted 14 lines

Ah, sorry, I see why I checked it more complicated way:
with simply checking exit code you have output twice:

df -hT 2>/dev/null || df

Filesystem                     Type      Size  Used Avail Use% Mounted on
devtmpfs                       devtmpfs   16G  8,0K   16G   1% /dev
tmpfs                          tmpfs      16G   91M   16G   1% /dev/shm
tmpfs                          tmpfs     6,2G  4,1M  6,2G   1% /run
...
df: /run/user/1000/doc: Operation not permitted
Filesystem                     Type      Size  Used Avail Use% Mounted on
devtmpfs                       devtmpfs   16G  8,0K   16G   1% /dev
tmpfs                          tmpfs      16G   91M   16G   1% /dev/shm
tmpfs                          tmpfs     6,2G  4,1M  6,2G   1% /run
Quoted 4 lines

...

=> which is IMHO nogo. I could redirect to a file and cut it after, but in that case v2 is IMHO much better.

But still we don't need that grep part, right?

Quoted 7 lines

So it should be something as:

	if `df -hT 2>/dev/null >/dev/null`; then
		df -hT
	else
		df
	fi

Yep, how simple, thanks!

Kind regards,
Petr

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
author
#7 lore raw
In reply to Cyril Hrubis
Quoted 5 lines
Quoted 2 lines

=> which is IMHO nogo. I could redirect to a file and cut it after, but in that case v2 is IMHO much better.

But still we don't need that grep part, right?

Quoted 7 lines

So it should be something as:

	if `df -hT 2>/dev/null >/dev/null`; then
		df -hT
	else
		df
	fi

Merged this version, thanks!

Kind regards,
Petr

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