From 51b6bd0fdf007f069e62a32d44b2a72f1656ecca Mon Sep 17 00:00:00 2001 From: 2Shirt <2xShirt@gmail.com> Date: Mon, 13 May 2019 18:23:47 -0600 Subject: [PATCH] Added 4K alignment check to disk reports * Addresses issue #73 --- .bin/Scripts/functions/hw_diags.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/.bin/Scripts/functions/hw_diags.py b/.bin/Scripts/functions/hw_diags.py index bcfdcd2e..c2e42b8f 100644 --- a/.bin/Scripts/functions/hw_diags.py +++ b/.bin/Scripts/functions/hw_diags.py @@ -319,6 +319,11 @@ class DiskObj(): attr_type=self.attr_type, **COLORS)) report.extend(sorted(self.nvme_smart_notes.keys())) + # 4K alignment check + if not self.is_4k_aligned(): + report.append('{YELLOW}Warning{CLEAR}'.format(**COLORS)) + report.append(' One or more partitions are not 4K aligned') + # Tests for test in self.tests.values(): report.extend(test.report) @@ -422,6 +427,26 @@ class DiskObj(): 'self_test', {}).get( k, {}) + def is_4k_aligned(self): + """Check if partitions are 4K aligned, returns bool.""" + cmd = [ + 'sudo', + 'sfdisk', + '--json', + self.path, + ] + aligned = True + + # Get partition details + json_data = get_json_from_command(cmd) + + # Check partitions + for part in json_data.get('partitiontable', {}).get('partitions', []): + aligned &= part.get('start', -1) % 4096 == 0 + + # Done + return aligned + def safety_check(self, silent=False): """Run safety checks and disable tests if necessary.""" test_running = False