Blame SOURCES/0008-Include-mke2fs-lens-and-test-from-upstream.patch

628dc3
From 59fb794a4c47b811998273323cd49cc91f9db7e2 Mon Sep 17 00:00:00 2001
628dc3
From: "Richard W.M. Jones" <rjones@redhat.com>
628dc3
Date: Wed, 12 Jan 2022 16:11:22 +0000
693d5e
Subject: [PATCH 8/9] Include mke2fs lens and test from upstream
628dc3
628dc3
Fixes: https://bugzilla.redhat.com/show_bug.cgi?id=1807010
628dc3
---
628dc3
 lenses/mke2fs.aug            | 108 ++++++++++++++++++++++++++---------
628dc3
 lenses/tests/test_mke2fs.aug |  46 ++++++++++++++-
628dc3
 2 files changed, 124 insertions(+), 30 deletions(-)
628dc3
628dc3
diff --git a/lenses/mke2fs.aug b/lenses/mke2fs.aug
628dc3
index dc895490..46a7136e 100644
628dc3
--- a/lenses/mke2fs.aug
628dc3
+++ b/lenses/mke2fs.aug
628dc3
@@ -34,6 +34,14 @@ let sep = IniFile.sep /=[ \t]*/ "="
628dc3
 (* View: empty *)
628dc3
 let empty = IniFile.empty
628dc3
 
628dc3
+(* View: boolean
628dc3
+    The configuration parser of e2fsprogs recognizes different values
628dc3
+    for booleans, so list all the recognized values *)
628dc3
+let boolean = ("y"|"yes"|"true"|"t"|"1"|"on"|"n"|"no"|"false"|"nil"|"0"|"off")
628dc3
+
628dc3
+(* View: fspath *)
628dc3
+let fspath = /[^ \t\n"]+/
628dc3
+
628dc3
 
628dc3
 (************************************************************************
628dc3
  * Group:                 RECORD TYPES
628dc3
@@ -47,27 +55,59 @@ let entry (kw:regexp) (lns:lens) = Build.key_value_line kw sep lns
628dc3
 
628dc3
 (* View: list_sto
628dc3
     A list of values with given lens *)
628dc3
-let list_sto (kw:regexp) (lns:lens) = counter "item" .
628dc3
-                                          entry kw
628dc3
-                                            (Build.opt_list 
628dc3
-                                              [lns]
628dc3
-                                              Sep.comma)
628dc3
+let list_sto (kw:regexp) (lns:lens) =
628dc3
+  entry kw (Quote.do_dquote_opt_nil (Build.opt_list [lns] Sep.comma))
628dc3
 
628dc3
 (* View: entry_sto
628dc3
     Store a regexp as entry value *)
628dc3
-let entry_sto (kw:regexp) (val:regexp) = entry kw (store val)
628dc3
+let entry_sto (kw:regexp) (val:regexp) =
628dc3
+  entry kw (Quote.do_dquote_opt_nil (store val))
628dc3
+  | entry kw (Util.del_str "\"\"")
628dc3
 
628dc3
 
628dc3
 (************************************************************************
628dc3
  * Group:                 COMMON ENTRIES
628dc3
  *************************************************************************)
628dc3
+
628dc3
+(* View: common_entries_list
628dc3
+    Entries with a list value *)
628dc3
+let common_entries_list = ("base_features"|"default_features"|"default_mntopts")
628dc3
+
628dc3
+(* View: common_entries_int
628dc3
+    Entries with an integer value *)
628dc3
+let common_entries_int = ("cluster_size"|"flex_bg_size"|"force_undo"
628dc3
+                         |"inode_ratio"|"inode_size"|"num_backup_sb")
628dc3
+
628dc3
+(* View: common_entries_bool
628dc3
+    Entries with a boolean value *)
628dc3
+let common_entries_bool = ("auto_64-bit_support"|"discard"
628dc3
+                          |"enable_periodic_fsck"|"lazy_itable_init"
628dc3
+                          |"lazy_journal_init"|"packed_meta_blocks")
628dc3
+
628dc3
+(* View: common_entries_string
628dc3
+    Entries with a string value *)
628dc3
+let common_entries_string = ("encoding"|"journal_location")
628dc3
+
628dc3
+(* View: common_entries_double
628dc3
+    Entries with a double value *)
628dc3
+let common_entries_double = ("reserved_ratio")
628dc3
+
628dc3
 (* View: common_entry
628dc3
      Entries shared between <defaults> and <fs_types> sections *)
628dc3
-let common_entry   = list_sto ("base_features"|"default_features")
628dc3
-                        (key Rx.word)
628dc3
+let common_entry   = list_sto common_entries_list (key Rx.word)
628dc3
+                   | entry_sto common_entries_int Rx.integer
628dc3
+                   | entry_sto common_entries_bool boolean
628dc3
+                   | entry_sto common_entries_string Rx.word
628dc3
+                   | entry_sto common_entries_double Rx.decimal
628dc3
                    | entry_sto "blocksize" ("-"? . Rx.integer)
628dc3
                    | entry_sto "hash_alg" ("legacy"|"half_md4"|"tea")
628dc3
-                   | entry_sto ("inode_ratio"|"inode_size") Rx.integer
628dc3
+                   | entry_sto "errors" ("continue"|"remount-ro"|"panic")
628dc3
+                   | list_sto "features"
628dc3
+                        ([del /\^/ "^" . label "disable"]?
628dc3
+                                           . key Rx.word)
628dc3
+                   | list_sto "options"
628dc3
+                        (key Rx.word . Util.del_str "="
628dc3
+                       . store Rx.word)
628dc3
 
628dc3
 (************************************************************************
628dc3
  * Group:                 DEFAULTS SECTION
628dc3
@@ -75,11 +115,8 @@ let common_entry   = list_sto ("base_features"|"default_features")
628dc3
 
628dc3
 (* View: defaults_entry
628dc3
     Possible entries under the <defaults> section *)
628dc3
-let defaults_entry = entry_sto "force_undo" ("true"|"false")
628dc3
-                   | entry_sto "fs_type" Rx.word
628dc3
-                   | entry_sto "undo_dir" Rx.fspath
628dc3
-                   | list_sto "default_mntopts" (key Rx.word)
628dc3
-                   | entry_sto "enable_periodic_fsck" Rx.integer
628dc3
+let defaults_entry = entry_sto "fs_type" Rx.word
628dc3
+                   | entry_sto "undo_dir" fspath
628dc3
                    
628dc3
 (* View: defaults_title
628dc3
     Title for the <defaults> section *)
628dc3
@@ -95,24 +132,12 @@ let defaults = IniFile.record defaults_title
628dc3
  * Group:                 FS_TYPES SECTION
628dc3
  *************************************************************************)
628dc3
 
628dc3
-(* View: fs_types_entry
628dc3
-    Possible entries under a <fs_types_record> group *)
628dc3
-let fs_types_entry =list_sto "features"
628dc3
-                        ([del /\^/ "^" . label "disable"]?
628dc3
-                                           . key Rx.word)
628dc3
-                   | list_sto "options"
628dc3
-                        (key Rx.word . Util.del_str "="
628dc3
-                       . store Rx.word)
628dc3
-                   | entry_sto "lazy_itable_init" ("true"|"false")
628dc3
-                   | entry_sto ("flex_bg_size"|"auto_64-bit_support")
628dc3
-                       Rx.integer
628dc3
-
628dc3
 (* View: fs_types_record
628dc3
      Fs group records under the <fs_types> section *)
628dc3
 let fs_types_record = [ label "filesystem"
628dc3
                      . Util.indent . store Rx.word
628dc3
                      . del /[ \t]*=[ \t]*\{[ \t]*\n/ " = {\n"
628dc3
-                     . ((Util.indent . (fs_types_entry|common_entry)) | empty | comment)*
628dc3
+                     . ((Util.indent . common_entry) | empty | comment)*
628dc3
                      . del /[ \t]*\}[ \t]*\n/ " }\n" ]
628dc3
 
628dc3
 (* View: fs_types_title
628dc3
@@ -125,6 +150,33 @@ let fs_types = IniFile.record fs_types_title
628dc3
                   (fs_types_record | comment)
628dc3
 
628dc3
 
628dc3
+(************************************************************************
628dc3
+ * Group:                 OPTIONS SECTION
628dc3
+ *************************************************************************)
628dc3
+
628dc3
+(* View: options_entries_int
628dc3
+    Entries with an integer value *)
628dc3
+let options_entries_int = ("proceed_delay"|"sync_kludge")
628dc3
+
628dc3
+(* View: options_entries_bool
628dc3
+    Entries with a boolean value *)
628dc3
+let options_entries_bool = ("old_bitmaps")
628dc3
+
628dc3
+(* View: options_entry
628dc3
+    Possible entries under the <options> section *)
628dc3
+let options_entry = entry_sto options_entries_int Rx.integer
628dc3
+                  | entry_sto options_entries_bool boolean
628dc3
+
628dc3
+(* View: defaults_title
628dc3
+    Title for the <options> section *)
628dc3
+let options_title  = IniFile.title "options"
628dc3
+
628dc3
+(* View: options
628dc3
+    A options section *)
628dc3
+let options = IniFile.record options_title
628dc3
+                  ((Util.indent . options_entry) | comment)
628dc3
+
628dc3
+
628dc3
 (************************************************************************
628dc3
  * Group:                 LENS AND FILTER
628dc3
  *************************************************************************)
628dc3
@@ -132,7 +184,7 @@ let fs_types = IniFile.record fs_types_title
628dc3
 (* View: lns
628dc3
      The mke2fs lens
628dc3
 *)
628dc3
-let lns = (empty|comment)* . (defaults|fs_types)*
628dc3
+let lns = (empty|comment)* . (defaults|fs_types|options)*
628dc3
 
628dc3
 (* Variable: filter *)
628dc3
 let filter = incl "/etc/mke2fs.conf"
628dc3
diff --git a/lenses/tests/test_mke2fs.aug b/lenses/tests/test_mke2fs.aug
628dc3
index f1ddbe9e..bcf2fe61 100644
628dc3
--- a/lenses/tests/test_mke2fs.aug
628dc3
+++ b/lenses/tests/test_mke2fs.aug
628dc3
@@ -33,6 +33,10 @@ module Test_mke2fs =
628dc3
 		inode_ratio = 1048576
628dc3
 		blocksize = -1
628dc3
 	}
628dc3
+
628dc3
+[options]
628dc3
+	proceed_delay = 1
628dc3
+	sync_kludge = 1
628dc3
 "
628dc3
 
628dc3
    test Mke2fs.lns get conf =
628dc3
@@ -74,10 +78,48 @@ module Test_mke2fs =
628dc3
              { "inode_ratio" = "4096" } }
628dc3
         { "filesystem" = "largefile"
628dc3
              { "inode_ratio" = "1048576" }
628dc3
-             { "blocksize" = "-1" } } }
628dc3
+             { "blocksize" = "-1" } }
628dc3
+        {} }
628dc3
+     { "options"
628dc3
+        { "proceed_delay" = "1" }
628dc3
+        { "sync_kludge" = "1" } }
628dc3
 
628dc3
 
628dc3
-test Mke2fs.fs_types_entry
628dc3
+   let quoted_conf = "[defaults]
628dc3
+	base_features = \"sparse_super,filetype,resize_inode,dir_index,ext_attr\"
628dc3
+
628dc3
+[fs_types]
628dc3
+	ext4dev = {
628dc3
+		features = \"has_journal,^extent\"
628dc3
+		default_mntopts = \"user_xattr\"
628dc3
+		encoding = \"utf8\"
628dc3
+		encoding = \"\"
628dc3
+	}
628dc3
+"
628dc3
+
628dc3
+   test Mke2fs.lns get quoted_conf =
628dc3
+     { "defaults"
628dc3
+        { "base_features"
628dc3
+             { "sparse_super" }
628dc3
+             { "filetype" }
628dc3
+             { "resize_inode" }
628dc3
+             { "dir_index" }
628dc3
+             { "ext_attr" } }
628dc3
+        {} }
628dc3
+     { "fs_types"
628dc3
+        { "filesystem" = "ext4dev"
628dc3
+             { "features"
628dc3
+                { "has_journal" }
628dc3
+                { "extent"
628dc3
+                   { "disable" } } }
628dc3
+             { "default_mntopts"
628dc3
+                { "user_xattr" } }
628dc3
+             { "encoding" = "utf8" }
628dc3
+             { "encoding" }
628dc3
+             } }
628dc3
+
628dc3
+
628dc3
+test Mke2fs.common_entry
628dc3
    put "features = has_journal,^extent\n"
628dc3
    after set "/features/has_journal/disable" "";
628dc3
    rm "/features/extent/disable" = "features = ^has_journal,extent\n"
628dc3
-- 
628dc3
2.31.1
628dc3