dumpe2fsparser breaks with latest version of dumpe2fs
Following code:
def parse_bitmaps(line):
mo = re.search(r'Block bitmap at (\S+) .*, Inode bitmap at (\S+) .*', line)
return {'block-bitmap': convert_to_range(mo.group(1)),
'inode-bitmap': convert_to_range(mo.group(2))}
breaks with:
File "pyreuse/sysutils/dumpe2fsparser.py", line 48, in parse_bitmaps
return {'block-bitmap': convert_to_range(mo.group(1)),
AttributeError: 'NoneType' object has no attribute 'group'
This would only happen with newer tools.
[rakesh@hercules ftlsim]$ dumpe2fs -V
dumpe2fs 1.43.3 (04-Sep-2016)
Using EXT2FS Library version 1.43.3
With older version it works fine:
[rakesh@dhcp-118 ftlsim]$ dumpe2fs -V
dumpe2fs 1.42.13 (17-May-2015)
Using EXT2FS Library version 1.42.13
Problem is newer version breaks this line: Block bitmap at 2 (+2), Inode bitmap at 18 (+18) into two lines: Block bitmap at 2 (+2) Inode bitmap at 18 (+18)
So solutions is to fix regular expression to parse both patterns and still extract information.
Something like this works for me. Feel free to use if you think it is appropriate. Should work for old or new dumpe2fs. Note that I didn't do any testing for older version.
diff --git a/pyreuse/sysutils/dumpe2fsparser.py b/pyreuse/sysutils/dumpe2fsparser.py
index f4b03a7..c17f9e9 100644
--- a/pyreuse/sysutils/dumpe2fsparser.py
+++ b/pyreuse/sysutils/dumpe2fsparser.py
@@ -41,6 +41,14 @@ def parse_bitmaps(line):
return {'block-bitmap': convert_to_range(mo.group(1)),
'inode-bitmap': convert_to_range(mo.group(2))}
+def parse_block_bitmap(line):
+ mo = re.search(r'Block bitmap at (\S+) .*', line)
+ return {'block-bitmap': convert_to_range(mo.group(1))}
+
+def parse_inode_bitmap(line):
+ mo = re.search(r'Inode bitmap at (\S+) .*', line)
+ return {'inode-bitmap': convert_to_range(mo.group(1))}
+
def parse_inodetable(line):
mo = re.search(r'Inode table at (\S+) .*', line)
return {'inode-table': convert_to_range(mo.group(1))}
@@ -55,9 +63,15 @@ def parse_bg_lines(bg_lines):
elif 'Reserved GDT' in line:
d = parse_gdt(line)
results.append(d)
- elif 'Block bitmap' in line:
+ elif ('Block bitmap' in line) and ('Inode bitmap' in line):
d = parse_bitmaps(line)
results.append(d)
+ elif ('Block bitmap' in line) and ('Inode bitmap' not in line):
+ d = parse_block_bitmap(line)
+ results.append(d)
+ elif ('Block bitmap' not in line) and ('Inode bitmap' in line):
+ d = parse_inode_bitmap(line)
+ results.append(d)
elif 'Inode table' in line:
d = parse_inodetable(line)
results.append(d)
Note that I haven't been using python much since years so I would skip creating patches. :)
Thanks. I'll fix it later.