[PATCH 1/2] common/config: add _check_mkfs_block_options

[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]



Add a helper to check MKFS_OPTIONS to use pure integer in bytes, and
create variable FS_BLOCK_SIZE=blocksize.
For example, set MKFS_OPTIONS="-b 4096" but not "-b 4k", then
FS_BLOCK_SIZE=4096.

Signed-off-by: An Long <lan@xxxxxxxx>
---
 README        |  4 ++++
 common/config | 30 ++++++++++++++++++++++++++++++
 2 files changed, 34 insertions(+)

diff --git a/README b/README
index 80d148be..e80b8457 100644
--- a/README
+++ b/README
@@ -241,6 +241,10 @@ Misc:
    this option is supported for all filesystems currently only -overlay is
    expected to run without issues. For other filesystems additional patches
    and fixes to the test suite might be needed.
+ - If MKFS_OPTIONS contains block size, the value must be an integer number of
+   bytes without units. And the variable FS_BLOCK_SIZE will be created.
+   For example, set MKFS_OPTIONS="-b 4096" but not "-b 4k", then
+   FS_BLOCK_SIZE=4096.
 
 ______________________
 USING THE FSQA SUITE
diff --git a/common/config b/common/config
index de3aba15..d34b1bf3 100644
--- a/common/config
+++ b/common/config
@@ -623,6 +623,34 @@ _check_device()
 	esac
 }
 
+# Check block size in $MKFS_OPTIONS is a valid integer
+# And then set the value in $FS_BLOCK_SIZE
+_check_mkfs_block_options()
+{
+        # Avoid that FS_BLOCK_SIZE is different from MKFS_OPTIONS
+        # Otherwise it will cause confusion
+        unset FS_BLOCK_SIZE
+
+        case $FSTYP in
+        xfs)
+                FS_BLOCK_SIZE=`echo $MKFS_OPTIONS | sed -rn 's/.*-b ?size= ?+([0-9]+[a-zA-Z]?).*/\1/p'`
+                ;;
+        btrfs)
+                FS_BLOCK_SIZE=`echo $MKFS_OPTIONS | sed -rn 's/.*-s ?+([0-9]+[a-zA-Z]?).*/\1/p'`
+                ;;
+        ext2|ext3|ext4|ext4dev|udf|reiser4|ocfs2|reiserfs)
+                FS_BLOCK_SIZE=`echo $MKFS_OPTIONS | sed -rn 's/.*-b ?+([0-9]+[a-zA-Z]?).*/\1/p'`
+                ;;
+        jfs)
+                FS_BLOCK_SIZE=4096
+                ;;
+        esac
+
+        if [ -n "$FS_BLOCK_SIZE" ] && ! [[ $FS_BLOCK_SIZE =~ ^[0-9]+$ ]] ; then
+		_fatal "\$MKFS_OPTIONS: block size \"$FS_BLOCK_SIZE\" not an integer."
+        fi
+}
+
 # check and return a canonical mount point path
 _canonicalize_mountpoint()
 {
@@ -896,5 +924,7 @@ else
 	fi
 fi
 
+_check_mkfs_block_options
+
 # make sure this script returns success
 /bin/true
-- 
2.35.3




[Index of Archives]     [Linux Filesystems Development]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux