[augeas-devel] [PATCH] Device_map: new lens for grub's device.map

Matthew Booth mbooth at redhat.com
Mon Jun 28 14:24:50 UTC 2010


---
 lenses/device_map.aug            |   28 ++++++++++++++++++++++++++++
 lenses/tests/test_device_map.aug |   34 ++++++++++++++++++++++++++++++++++
 2 files changed, 62 insertions(+), 0 deletions(-)
 create mode 100644 lenses/device_map.aug
 create mode 100644 lenses/tests/test_device_map.aug

diff --git a/lenses/device_map.aug b/lenses/device_map.aug
new file mode 100644
index 0000000..090edd5
--- /dev/null
+++ b/lenses/device_map.aug
@@ -0,0 +1,28 @@
+(* Parsing grub's device.map *)
+
+module Device_map =
+  autoload xfm
+
+  let sep_tab = Sep.tab
+  let eol     = Util.eol
+  let fspath  = Rx.fspath
+  let del_str = Util.del_str
+
+  let comment = Util.comment
+  let empty   = Util.empty
+
+  let dev_name = /(h|f|c)d[0-9]+(,[0-9a-zA-Z]+){0,2}/
+  let dev_hex  = /0x[0-9a-fA-F]+/
+  let dev_dec  = /[0-9]+/
+
+  let device = del_str "(" . key ( dev_name | dev_hex | dev_dec ) .  del_str ")"
+
+  let map = [ device . sep_tab . store fspath . eol ]
+
+  let lns = ( empty | comment | map ) *
+
+  let xfm = transform lns (incl "/boot/grub/device.map")
+
+(* Local Variables: *)
+(* mode: caml *)
+(* End: *)
diff --git a/lenses/tests/test_device_map.aug b/lenses/tests/test_device_map.aug
new file mode 100644
index 0000000..2a7810a
--- /dev/null
+++ b/lenses/tests/test_device_map.aug
@@ -0,0 +1,34 @@
+module Test_device_map =
+
+  let conf = "# this device map was generated by anaconda
+(fd0)     /dev/fda
+(hd0)     /dev/sda
+(cd0)     /dev/cdrom
+(hd1,1)   /dev/sdb1
+(hd0,a)   /dev/sda1
+(0x80)    /dev/sda
+(128)     /dev/sda
+"
+
+  test Device_map.lns get conf =
+    { "#comment" = "this device map was generated by anaconda" }
+    { "fd0" = "/dev/fda" }
+    { "hd0" = "/dev/sda" }
+    { "cd0" = "/dev/cdrom" }
+    { "hd1,1" = "/dev/sdb1" }
+    { "hd0,a" = "/dev/sda1" }
+    { "0x80"  = "/dev/sda" }
+    { "128"   = "/dev/sda" }
+
+  test Device_map.lns put conf after
+    set "hd2,1" "/dev/sdb1"
+  = "# this device map was generated by anaconda
+(fd0)     /dev/fda
+(hd0)     /dev/sda
+(cd0)     /dev/cdrom
+(hd1,1)   /dev/sdb1
+(hd0,a)   /dev/sda1
+(0x80)    /dev/sda
+(128)     /dev/sda
+(hd2,1)\t/dev/sdb1
+"
-- 
1.7.1




More information about the augeas-devel mailing list