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