From 5e0db82858387ba8c529a8fbc667a58b29b79706 Mon Sep 17 00:00:00 2001 From: Cylen Yao Date: Mon, 12 May 2014 23:29:42 +0800 Subject: libdiskconfig: set MBR signature when creating MBR When formatting a blank SD card, it needs to set MBR signature when creating MBR. If not, the 'format' operation will fail. Change-Id: I860731243797d4da83f370af52822536983009ee Signed-off-by: Cylen Yao --- libdiskconfig/config_mbr.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'libdiskconfig') diff --git a/libdiskconfig/config_mbr.c b/libdiskconfig/config_mbr.c index 7641b29..82d0066 100644 --- a/libdiskconfig/config_mbr.c +++ b/libdiskconfig/config_mbr.c @@ -208,6 +208,26 @@ fail: } +static struct write_list * +mk_mbr_sig() +{ + struct write_list *item; + if (!(item = alloc_wl(sizeof(uint16_t)))) { + ALOGE("Unable to allocate memory for MBR signature."); + return NULL; + } + + { + /* DO NOT DEREFERENCE */ + struct pc_boot_record *mbr = (void *)PC_MBR_DISK_OFFSET; + /* grab the offset in mbr where to write mbr signature. */ + item->offset = (loff_t)((uint32_t)((uint8_t *)(&mbr->mbr_sig))); + } + + *((uint16_t*)item->data) = PC_BIOS_BOOT_SIG; + return item; +} + struct write_list * config_mbr(struct disk_info *dinfo) { @@ -276,6 +296,13 @@ config_mbr(struct disk_info *dinfo) wlist_add(&wr_list, temp_wr); } + if ((temp_wr = mk_mbr_sig())) + wlist_add(&wr_list, temp_wr); + else { + ALOGE("Cannot set MBR signature"); + goto fail; + } + return wr_list; nospace: -- cgit v1.1