[1/4] initscripts: Add generic function to get the filesystem type of a volume

Message ID 20240327051520.8231-1-stefan.schantl@ipfire.org
State Superseded
Headers
Series [1/4] initscripts: Add generic function to get the filesystem type of a volume |

Commit Message

Stefan Schantl March 27, 2024, 5:15 a.m. UTC
  Signed-off-by: Stefan Schantl <stefan.schantl@ipfire.org>
---
 src/initscripts/system/functions | 8 ++++++++
 1 file changed, 8 insertions(+)
  

Comments

Michael Tremer March 27, 2024, 10:15 a.m. UTC | #1
Hello Stefan,

> On 27 Mar 2024, at 05:15, Stefan Schantl <stefan.schantl@ipfire.org> wrote:
> 
> Signed-off-by: Stefan Schantl <stefan.schantl@ipfire.org>
> ---
> src/initscripts/system/functions | 8 ++++++++
> 1 file changed, 8 insertions(+)
> 
> diff --git a/src/initscripts/system/functions b/src/initscripts/system/functions
> index 5a26aef45..0fa825000 100644
> --- a/src/initscripts/system/functions
> +++ b/src/initscripts/system/functions
> @@ -883,3 +883,11 @@ running_on_oci() {
> # We are not running on OCI
> return 1
> }
> +
> +volume_fs_type() {
> + if [ ! -d "${1}" ]; then
> + return
> + fi
> +
> + echo "$(stat -f --format="%T" ${1})"

You don’t need to run a sub shell for this and echo the result. It would be enough to just call stat with its arguments.

> +}
> -- 
> 2.39.2
>
  
Stefan Schantl March 27, 2024, 7:43 p.m. UTC | #2
Am Mittwoch, dem 27.03.2024 um 10:15 +0000 schrieb Michael Tremer:
> Hello Stefan,
> 
> > On 27 Mar 2024, at 05:15, Stefan Schantl
> > <stefan.schantl@ipfire.org> wrote:
> > 
> > Signed-off-by: Stefan Schantl <stefan.schantl@ipfire.org>
> > ---
> > src/initscripts/system/functions | 8 ++++++++
> > 1 file changed, 8 insertions(+)
> > 
> > diff --git a/src/initscripts/system/functions
> > b/src/initscripts/system/functions
> > index 5a26aef45..0fa825000 100644
> > --- a/src/initscripts/system/functions
> > +++ b/src/initscripts/system/functions
> > @@ -883,3 +883,11 @@ running_on_oci() {
> > # We are not running on OCI
> > return 1
> > }
> > +
> > +volume_fs_type() {
> > + if [ ! -d "${1}" ]; then
> > + return
> > + fi
> > +
> > + echo "$(stat -f --format="%T" ${1})"
> 
> You don’t need to run a sub shell for this and echo the result. It
> would be enough to just call stat with its arguments.

Thanks for pointing this out,

I'll remove the subshell call in a v2 patch.
> 
> > +}
> > -- 
> > 2.39.2
> > 
>
  

Patch

diff --git a/src/initscripts/system/functions b/src/initscripts/system/functions
index 5a26aef45..0fa825000 100644
--- a/src/initscripts/system/functions
+++ b/src/initscripts/system/functions
@@ -883,3 +883,11 @@  running_on_oci() {
 	# We are not running on OCI
 	return 1
 }
+
+volume_fs_type() {
+	if [ ! -d "${1}" ]; then
+		return
+	fi
+
+	echo "$(stat -f --format="%T" ${1})"
+}