Permalink
Browse files

Vfstab: new lens for /etc/vfstab config on Solaris

  • Loading branch information...
1 parent 396a8de commit 8c73190b8b7aaa65774d3d93105fa7e87dccaff5 @domcleal domcleal committed Jan 27, 2012
Showing with 157 additions and 0 deletions.
  1. +88 −0 lenses/tests/test_vfstab.aug
  2. +68 −0 lenses/vfstab.aug
  3. +1 −0 tests/Makefile.am
View
88 lenses/tests/test_vfstab.aug
@@ -0,0 +1,88 @@
+module Test_vfstab =
+
+ let simple = "/dev/dsk/c0t0d0s1 /dev/rdsk/c0t0d0s1 /test ufs 1 yes ro\n"
+ let simple_tree =
+ { "1"
+ { "spec" = "/dev/dsk/c0t0d0s1" }
+ { "fsck" = "/dev/rdsk/c0t0d0s1" }
+ { "file" = "/test" }
+ { "vfstype" = "ufs" }
+ { "passno" = "1" }
+ { "atboot" = "yes" }
+ { "opt" = "ro" } }
+ test Vfstab.lns get simple = simple_tree
+
+ let trailing_ws = "/dev/dsk/c0t0d0s1\t /dev/rdsk/c0t0d0s1\t /test\t ufs\t 1\t yes\t ro \t \n"
+ test Vfstab.lns get trailing_ws = simple_tree
+
+ (* Now test combinations where unneeded fields can be replaced by dashes and
+ then should not appear in the tree. *)
+ let gen_empty_field(fsck:string) (passno:string) (opt:string) =
+ "/dev/dsk/c0t0d0s1\t " . fsck . "\t /test\t ufs\t " . passno . " yes " . opt . "\t\n"
+
+ (* Missing fsck *)
+ let no_fsck = gen_empty_field "-" "1" "ro"
+ test Vfstab.lns get no_fsck =
+ { "1"
+ { "spec" = "/dev/dsk/c0t0d0s1" }
+ { "file" = "/test" }
+ { "vfstype" = "ufs" }
+ { "passno" = "1" }
+ { "atboot" = "yes" }
+ { "opt" = "ro" } }
+
+ test Vfstab.lns put no_fsck after
+ insa "fsck" "/1/spec" ;
+ set "/1/fsck" "/dev/rdsk/c0t0d0s1" = gen_empty_field "/dev/rdsk/c0t0d0s1" "1" "ro"
+
+ (* Missing passno *)
+ let no_passno = gen_empty_field "/dev/rdsk/c0t0d0s1" "-" "ro"
+ test Vfstab.lns get no_passno =
+ { "1"
+ { "spec" = "/dev/dsk/c0t0d0s1" }
+ { "fsck" = "/dev/rdsk/c0t0d0s1" }
+ { "file" = "/test" }
+ { "vfstype" = "ufs" }
+ { "atboot" = "yes" }
+ { "opt" = "ro" } }
+
+ test Vfstab.lns put no_passno after
+ insa "passno" "/1/vfstype" ;
+ set "/1/passno" "1" = gen_empty_field "/dev/rdsk/c0t0d0s1" "1" "ro"
+
+ (* Missing opts *)
+ let no_opts = gen_empty_field "/dev/rdsk/c0t0d0s1" "1" "-"
+ test Vfstab.lns get no_opts =
+ { "1"
+ { "spec" = "/dev/dsk/c0t0d0s1" }
+ { "fsck" = "/dev/rdsk/c0t0d0s1" }
+ { "file" = "/test" }
+ { "vfstype" = "ufs" }
+ { "passno" = "1" }
+ { "atboot" = "yes" } }
+
+ test Vfstab.lns put no_opts after
+ insa "opt" "/1/atboot" ;
+ insa "opt" "/1/atboot" ;
+ set "/1/opt[1]" "ro" ;
+ set "/1/opt[2]" "fg" = gen_empty_field "/dev/rdsk/c0t0d0s1" "1" "ro,fg"
+
+ let multi_opts = "/dev/dsk/c0t0d0s1 /dev/rdsk/c0t0d0s1 /test ufs 1 yes ro,nosuid,retry=5,fg\n"
+ let multi_opts_tree =
+ { "1"
+ { "spec" = "/dev/dsk/c0t0d0s1" }
+ { "fsck" = "/dev/rdsk/c0t0d0s1" }
+ { "file" = "/test" }
+ { "vfstype" = "ufs" }
+ { "passno" = "1" }
+ { "atboot" = "yes" }
+ { "opt" = "ro" }
+ { "opt" = "nosuid" }
+ { "opt" = "retry"
+ { "value" = "5" } }
+ { "opt" = "fg" } }
+ test Vfstab.lns get multi_opts = multi_opts_tree
+
+(* Local Variables: *)
+(* mode: caml *)
+(* End: *)
View
68 lenses/vfstab.aug
@@ -0,0 +1,68 @@
+(*
+Module: Vfstab
+ Parses Solaris vfstab config file, based on Fstab lens
+
+Author: Dominic Cleal <dcleal@redhat.com>
+
+About: Reference
+ See vfstab(4)
+
+About: License
+ This file is licenced under the LGPLv2+, like the rest of Augeas.
+
+About: Lens Usage
+ To be documented
+
+About: Configuration files
+ This lens applies to /etc/vfstab.
+
+About: Examples
+ The <Test_Vfstab> file contains various examples and tests.
+*)
+
+module Vfstab =
+ autoload xfm
+
+ let sep_tab = Sep.tab
+ let sep_spc = Sep.space
+ let comma = Sep.comma
+ let eol = Util.eol
+
+ let comment = Util.comment
+ let empty = Util.empty
+
+ let file = /[^# \t\n]+/
+
+ let int = Rx.integer
+ let bool = "yes" | "no"
+
+ (* An option label can't contain comma, comment, equals, or space *)
+ let optlabel = /[^,#= \n\t]+/ - "-"
+ let spec = /[^-,# \n\t][^ \n\t]*/
+
+ let optional = Util.del_str "-"
+
+ let comma_sep_list (l:string) =
+ let value = [ label "value" . Util.del_str "=" . store Rx.neg1 ] in
+ let lns = [ label l . store optlabel . value? ] in
+ Build.opt_list lns comma
+
+ let record = [ seq "mntent" .
+ [ label "spec" . store spec ] . sep_tab .
+ ( [ label "fsck" . store spec ] | optional ). sep_tab .
+ [ label "file" . store file ] . sep_tab .
+ comma_sep_list "vfstype" . sep_tab .
+ ( [ label "passno" . store int ] | optional ) . sep_spc .
+ [ label "atboot" . store bool ] . sep_tab .
+ ( comma_sep_list "opt" | optional ) .
+ eol ]
+
+ let lns = ( empty | comment | record ) *
+ let filter = incl "/etc/vfstab"
+ . Util.stdexcl
+
+ let xfm = transform lns filter
+
+(* Local Variables: *)
+(* mode: caml *)
+(* End: *)
View
1 tests/Makefile.am
@@ -118,6 +118,7 @@ lens_tests = \
lens-syslog.sh \
lens-sysctl.sh \
lens-util.sh \
+ lens-vfstab.sh \
lens-vsftpd.sh \
lens-webmin.sh \
lens-wine.sh \

0 comments on commit 8c73190

Please sign in to comment.