From 1a2c85c7b631cb2a702c0c81fcf796a2f6d1f048 Mon Sep 17 00:00:00 2001 From: John Paul Morrison Date: Sun, 17 Jan 2021 17:11:56 -0800 Subject: [PATCH 1/4] Fix for scanning for LDM when OEM parition is present --- src/ldm.c | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/src/ldm.c b/src/ldm.c index 4766bb0..a0b99dc 100644 --- a/src/ldm.c +++ b/src/ldm.c @@ -1296,7 +1296,7 @@ _read_privhead_off(const int fd, const gchar * const path, sizeof(*privhead) - read, ph_start + read); if (in == 0) { - g_set_error(err, LDM_ERROR, LDM_ERROR_INVALID, + g_set_error(err, LDM_ERROR, LDM_ERROR_INVALID, "%s contains invalid LDM metadata", path); return FALSE; } @@ -1422,6 +1422,7 @@ _read_privhead(const int fd, const gchar * const path, const guint secsize, { // Whether the disk is MBR or GPT, we expect to find an MBR at the beginning mbr_t mbr; + int i; int r = mbr_read(fd, &mbr); if (r < 0) { switch (-r) { @@ -1440,18 +1441,28 @@ _read_privhead(const int fd, const gchar * const path, const guint secsize, } } - switch (mbr.part[0].type) { - case MBR_PART_WINDOWS_LDM: - return _read_privhead_mbr(fd, path, secsize, privhead, err); + // Check all primary partitions on MBR - OEM and other partition types can co-exist with LDM + // FIXME: should check what the last primary partition is instead of assuming 4. + // not sure if LDM works on extended partitions but it might + // not sure how GPT handles a MIX of LDM and other partition types + for (i=0; i < 4; i++) { + switch (mbr.part[i].type) { + case MBR_PART_WINDOWS_LDM: + printf(" test MBR \n"); + return _read_privhead_mbr(fd, path, secsize, privhead, err); - case MBR_PART_EFI_PROTECTIVE: - return _read_privhead_gpt(fd, path, secsize, privhead, err); + case MBR_PART_EFI_PROTECTIVE: + printf(" test EFI \n"); + return _read_privhead_gpt(fd, path, secsize, privhead, err); - default: - g_set_error(err, LDM_ERROR, LDM_ERROR_NOT_LDM, - "%s does not contain LDM metadata", path); - return FALSE; + default: + g_set_error(err, LDM_ERROR, LDM_ERROR_NOT_LDM, + "partition %d type=%x does not contain LDM metadata, skipping", i+1, mbr.part[i].type); + } } + g_set_error(err, LDM_ERROR, LDM_ERROR_NOT_LDM, + "%s does not contain LDM metadata", path); + return FALSE; } #define PARSE_VAR_INT(func_name, out_type) \ From 199c48cdccc59b6f081dc554e33d84194af52dc6 Mon Sep 17 00:00:00 2001 From: John Paul Morrison Date: Sun, 17 Jan 2021 17:18:38 -0800 Subject: [PATCH 2/4] inden --- src/ldm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ldm.c b/src/ldm.c index a0b99dc..5a4d8a6 100644 --- a/src/ldm.c +++ b/src/ldm.c @@ -1296,7 +1296,7 @@ _read_privhead_off(const int fd, const gchar * const path, sizeof(*privhead) - read, ph_start + read); if (in == 0) { - g_set_error(err, LDM_ERROR, LDM_ERROR_INVALID, + g_set_error(err, LDM_ERROR, LDM_ERROR_INVALID, "%s contains invalid LDM metadata", path); return FALSE; } From dc99a33181e4244a855c918e11435c01a6274b66 Mon Sep 17 00:00:00 2001 From: John Paul Morrison Date: Mon, 22 Mar 2021 09:50:25 -0700 Subject: [PATCH 3/4] remove debugging --- src/ldm.c | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/ldm.c b/src/ldm.c index 5a4d8a6..a309b68 100644 --- a/src/ldm.c +++ b/src/ldm.c @@ -1442,17 +1442,12 @@ _read_privhead(const int fd, const gchar * const path, const guint secsize, } // Check all primary partitions on MBR - OEM and other partition types can co-exist with LDM - // FIXME: should check what the last primary partition is instead of assuming 4. - // not sure if LDM works on extended partitions but it might - // not sure how GPT handles a MIX of LDM and other partition types for (i=0; i < 4; i++) { switch (mbr.part[i].type) { case MBR_PART_WINDOWS_LDM: - printf(" test MBR \n"); return _read_privhead_mbr(fd, path, secsize, privhead, err); case MBR_PART_EFI_PROTECTIVE: - printf(" test EFI \n"); return _read_privhead_gpt(fd, path, secsize, privhead, err); default: From f782ce283bcb63eda6306039d9ba04e8a210281d Mon Sep 17 00:00:00 2001 From: John Paul Morrison Date: Wed, 24 Mar 2021 13:49:44 -0700 Subject: [PATCH 4/4] \t --- src/ldm.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ldm.c b/src/ldm.c index a309b68..e679eda 100644 --- a/src/ldm.c +++ b/src/ldm.c @@ -1451,9 +1451,9 @@ _read_privhead(const int fd, const gchar * const path, const guint secsize, return _read_privhead_gpt(fd, path, secsize, privhead, err); default: - g_set_error(err, LDM_ERROR, LDM_ERROR_NOT_LDM, + g_set_error(err, LDM_ERROR, LDM_ERROR_NOT_LDM, "partition %d type=%x does not contain LDM metadata, skipping", i+1, mbr.part[i].type); - } + } } g_set_error(err, LDM_ERROR, LDM_ERROR_NOT_LDM, "%s does not contain LDM metadata", path);