From e2bba11e4aabeada9e4b8bb184ffadbdf14add3c Mon Sep 17 00:00:00 2001 From: Shao Miller Date: Mon, 28 Jun 2010 00:31:08 -0400 Subject: libcom32: Introduce disk header and module An effort to move significant portions out of chain.c32 and into library is underway. We begin by simply moving SECTOR into a header and building a disk module. Note that some of this work will essentially duplicate some of what's found in Pierre-Alexandre Meyer's fine work in com32/gpllib/disk/. A difference would be the licensing, of course. Signed-off-by: Shao Miller --- com32/include/syslinux/disk.h | 41 +++++++++++++++++++++++++++++++++++++++++ com32/lib/Makefile | 4 +++- com32/lib/syslinux/disk.c | 36 ++++++++++++++++++++++++++++++++++++ com32/modules/chain.c | 3 +-- 4 files changed, 81 insertions(+), 3 deletions(-) create mode 100644 com32/include/syslinux/disk.h create mode 100644 com32/lib/syslinux/disk.c diff --git a/com32/include/syslinux/disk.h b/com32/include/syslinux/disk.h new file mode 100644 index 00000000..482dece5 --- /dev/null +++ b/com32/include/syslinux/disk.h @@ -0,0 +1,41 @@ +/* ----------------------------------------------------------------------- * + * + * Copyright 2003-2009 H. Peter Anvin - All Rights Reserved + * Copyright 2009-2010 Intel Corporation; author: H. Peter Anvin + * Copyright (C) 2010 Shao Miller + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation + * files (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, + * copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom + * the Software is furnished to do so, subject to the following + * conditions: + * + * The above copyright notice and this permission notice shall + * be included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES + * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * ----------------------------------------------------------------------- */ + +/** + * @file syslinux/disk.h + * + * Deal with disks and partitions + */ + +#ifndef _SYSLINUX_DISK_H +#define _SYSLINUX_DISK_H + +#define SECTOR 512 /* bytes/sector */ + +#endif /* _SYSLINUX_DISK_H */ diff --git a/com32/lib/Makefile b/com32/lib/Makefile index 2035df22..ed4bb31e 100644 --- a/com32/lib/Makefile +++ b/com32/lib/Makefile @@ -119,7 +119,9 @@ LIBOBJS = \ syslinux/setadv.o \ \ syslinux/video/fontquery.o syslinux/video/forcetext.o \ - syslinux/video/reportmode.o + syslinux/video/reportmode.o \ + \ + syslinux/disk.o # These are the objects which are also imported into the core LIBCOREOBJS = \ diff --git a/com32/lib/syslinux/disk.c b/com32/lib/syslinux/disk.c new file mode 100644 index 00000000..2a286e4f --- /dev/null +++ b/com32/lib/syslinux/disk.c @@ -0,0 +1,36 @@ +/* ----------------------------------------------------------------------- * + * + * Copyright 2003-2009 H. Peter Anvin - All Rights Reserved + * Copyright 2009-2010 Intel Corporation; author: H. Peter Anvin + * Copyright (C) 2010 Shao Miller + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation + * files (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, + * copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom + * the Software is furnished to do so, subject to the following + * conditions: + * + * The above copyright notice and this permission notice shall + * be included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES + * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * ----------------------------------------------------------------------- */ + +/** + * @file disk.c + * + * Deal with disks and partitions + */ + +#include diff --git a/com32/modules/chain.c b/com32/modules/chain.c index 48a83d2a..d6005e28 100644 --- a/com32/modules/chain.c +++ b/com32/modules/chain.c @@ -117,10 +117,9 @@ #include #include #include +#include #include -#define SECTOR 512 /* bytes/sector */ - static struct options { const char *loadfile; uint16_t keeppxe; -- cgit v1.2.1 From 8f0f42100f43a52e957c7c6feec0d2fcb21d0b6e Mon Sep 17 00:00:00 2001 From: Shao Miller Date: Mon, 28 Jun 2010 00:59:17 -0400 Subject: chain.c32, libcom32: Move int13_retry() as disk_int13_retry() Moving portions of chain.c32 into libcom32. Signed-off-by: Shao Miller --- com32/include/syslinux/disk.h | 4 ++++ com32/lib/syslinux/disk.c | 23 +++++++++++++++++++++++ com32/modules/chain.c | 24 ++---------------------- 3 files changed, 29 insertions(+), 22 deletions(-) diff --git a/com32/include/syslinux/disk.h b/com32/include/syslinux/disk.h index 482dece5..83db05ce 100644 --- a/com32/include/syslinux/disk.h +++ b/com32/include/syslinux/disk.h @@ -36,6 +36,10 @@ #ifndef _SYSLINUX_DISK_H #define _SYSLINUX_DISK_H +#include + #define SECTOR 512 /* bytes/sector */ +extern int disk_int13_retry(const com32sys_t * inreg, com32sys_t * outreg); + #endif /* _SYSLINUX_DISK_H */ diff --git a/com32/lib/syslinux/disk.c b/com32/lib/syslinux/disk.c index 2a286e4f..7be59f2b 100644 --- a/com32/lib/syslinux/disk.c +++ b/com32/lib/syslinux/disk.c @@ -34,3 +34,26 @@ */ #include + +/** + * Call int 13h, but with retry on failure. Especially floppies need this. + * + * @v inreg CPU register settings upon INT call + * @v outreg CPU register settings returned by INT call + */ +int disk_int13_retry(const com32sys_t * inreg, com32sys_t * outreg) +{ + int retry = 6; /* Number of retries */ + com32sys_t tmpregs; + + if (!outreg) + outreg = &tmpregs; + + while (retry--) { + __intcall(0x13, inreg, outreg); + if (!(outreg->eflags.l & EFLAGS_CF)) + return 0; /* CF=0, OK */ + } + + return -1; /* Error */ +} diff --git a/com32/modules/chain.c b/com32/modules/chain.c index d6005e28..19afa051 100644 --- a/com32/modules/chain.c +++ b/com32/modules/chain.c @@ -145,26 +145,6 @@ static inline void error(const char *msg) fputs(msg, stderr); } -/* - * Call int 13h, but with retry on failure. Especially floppies need this. - */ -static int int13_retry(const com32sys_t * inreg, com32sys_t * outreg) -{ - int retry = 6; /* Number of retries */ - com32sys_t tmpregs; - - if (!outreg) - outreg = &tmpregs; - - while (retry--) { - __intcall(0x13, inreg, outreg); - if (!(outreg->eflags.l & EFLAGS_CF)) - return 0; /* CF=0, OK */ - } - - return -1; /* Error */ -} - /* * Query disk parameters and EBIOS availability for a particular disk. */ @@ -287,7 +267,7 @@ static void *read_sectors(uint64_t lba, uint8_t count) inreg.es = SEG(buf); } - if (int13_retry(&inreg, NULL)) + if (disk_int13_retry(&inreg, NULL)) return NULL; data = malloc(count * SECTOR); @@ -347,7 +327,7 @@ static int write_sector(unsigned int lba, const void *data) inreg.es = SEG(buf); } - if (int13_retry(&inreg, NULL)) + if (disk_int13_retry(&inreg, NULL)) return -1; return 0; /* ok */ -- cgit v1.2.1 From 3549d7ecf588bc8de1cca06e750683bea251614a Mon Sep 17 00:00:00 2001 From: Shao Miller Date: Mon, 28 Jun 2010 01:03:46 -0400 Subject: chain.c32: Run Nindent on com32/modules/chain.c Signed-off-by: Shao Miller --- com32/modules/chain.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/com32/modules/chain.c b/com32/modules/chain.c index 19afa051..ffcf8c2b 100644 --- a/com32/modules/chain.c +++ b/com32/modules/chain.c @@ -400,10 +400,7 @@ static void mbr_part_dump(const struct part_entry *part) chs_head(part->end), chs_sector(part->end), chs_sector(part->end), - part->start_lba, - part->start_lba, - part->length, - part->length); + part->start_lba, part->start_lba, part->length, part->length); } /* A DOS MBR */ -- cgit v1.2.1 From 14e2dc6336a763930043baf654b3ff0f38f932fa Mon Sep 17 00:00:00 2001 From: Shao Miller Date: Mon, 28 Jun 2010 01:22:04 -0400 Subject: chain.c32, libcom32: Move get_disk_params() as disk_get_params() Also moved struct diskinfo as disk_info. Moving portions of chain.c32 into libcom32. Signed-off-by: Shao Miller --- com32/include/syslinux/disk.h | 9 ++++ com32/lib/syslinux/disk.c | 48 ++++++++++++++++++++++ com32/modules/chain.c | 95 ++++++++++--------------------------------- 3 files changed, 79 insertions(+), 73 deletions(-) diff --git a/com32/include/syslinux/disk.h b/com32/include/syslinux/disk.h index 83db05ce..f880a894 100644 --- a/com32/include/syslinux/disk.h +++ b/com32/include/syslinux/disk.h @@ -40,6 +40,15 @@ #define SECTOR 512 /* bytes/sector */ +struct disk_info { + int disk; + int ebios; /* EBIOS supported on this disk */ + int cbios; /* CHS geometry is valid */ + int head; + int sect; +}; + extern int disk_int13_retry(const com32sys_t * inreg, com32sys_t * outreg); +extern int disk_get_params(int disk, struct disk_info *diskinfo); #endif /* _SYSLINUX_DISK_H */ diff --git a/com32/lib/syslinux/disk.c b/com32/lib/syslinux/disk.c index 7be59f2b..0fd35483 100644 --- a/com32/lib/syslinux/disk.c +++ b/com32/lib/syslinux/disk.c @@ -57,3 +57,51 @@ int disk_int13_retry(const com32sys_t * inreg, com32sys_t * outreg) return -1; /* Error */ } + +/* + * Query disk parameters and EBIOS availability for a particular disk. + * + * @v disk The INT 0x13 disk drive number to process + * @v diskinfo The structure to save the queried params to + */ +int disk_get_params(int disk, struct disk_info *diskinfo) +{ + static com32sys_t getparm, parm, getebios, ebios; + + diskinfo->disk = disk; + diskinfo->ebios = diskinfo->cbios = 0; + + /* Get EBIOS support */ + getebios.eax.w[0] = 0x4100; + getebios.ebx.w[0] = 0x55aa; + getebios.edx.b[0] = disk; + getebios.eflags.b[0] = 0x3; /* CF set */ + + __intcall(0x13, &getebios, &ebios); + + if (!(ebios.eflags.l & EFLAGS_CF) && + ebios.ebx.w[0] == 0xaa55 && (ebios.ecx.b[0] & 1)) { + diskinfo->ebios = 1; + } + + /* Get disk parameters -- really only useful for + hard disks, but if we have a partitioned floppy + it's actually our best chance... */ + getparm.eax.b[1] = 0x08; + getparm.edx.b[0] = disk; + + __intcall(0x13, &getparm, &parm); + + if (parm.eflags.l & EFLAGS_CF) + return diskinfo->ebios ? 0 : -1; + + diskinfo->head = parm.edx.b[1] + 1; + diskinfo->sect = parm.ecx.b[0] & 0x3f; + if (diskinfo->sect == 0) { + diskinfo->sect = 1; + } else { + diskinfo->cbios = 1; /* Valid geometry */ + } + + return 0; +} diff --git a/com32/modules/chain.c b/com32/modules/chain.c index ffcf8c2b..738d8c71 100644 --- a/com32/modules/chain.c +++ b/com32/modules/chain.c @@ -145,62 +145,11 @@ static inline void error(const char *msg) fputs(msg, stderr); } -/* - * Query disk parameters and EBIOS availability for a particular disk. - */ -struct diskinfo { - int disk; - int ebios; /* EBIOS supported on this disk */ - int cbios; /* CHS geometry is valid */ - int head; - int sect; -} disk_info; - -static int get_disk_params(int disk) -{ - static com32sys_t getparm, parm, getebios, ebios; - - disk_info.disk = disk; - disk_info.ebios = disk_info.cbios = 0; - - /* Get EBIOS support */ - getebios.eax.w[0] = 0x4100; - getebios.ebx.w[0] = 0x55aa; - getebios.edx.b[0] = disk; - getebios.eflags.b[0] = 0x3; /* CF set */ - - __intcall(0x13, &getebios, &ebios); - - if (!(ebios.eflags.l & EFLAGS_CF) && - ebios.ebx.w[0] == 0xaa55 && (ebios.ecx.b[0] & 1)) { - disk_info.ebios = 1; - } - - /* Get disk parameters -- really only useful for - hard disks, but if we have a partitioned floppy - it's actually our best chance... */ - getparm.eax.b[1] = 0x08; - getparm.edx.b[0] = disk; - - __intcall(0x13, &getparm, &parm); - - if (parm.eflags.l & EFLAGS_CF) - return disk_info.ebios ? 0 : -1; - - disk_info.head = parm.edx.b[1] + 1; - disk_info.sect = parm.ecx.b[0] & 0x3f; - if (disk_info.sect == 0) { - disk_info.sect = 1; - } else { - disk_info.cbios = 1; /* Valid geometry */ - } - - return 0; -} +static struct disk_info diskinfo; /* * Get a disk block and return a malloc'd buffer. - * Uses the disk number and information from disk_info. + * Uses the disk number and information from diskinfo. */ struct ebios_dapa { uint16_t len; @@ -224,7 +173,7 @@ static void *read_sectors(uint64_t lba, uint8_t count) memset(&inreg, 0, sizeof inreg); - if (disk_info.ebios) { + if (diskinfo.ebios) { dapa->len = sizeof(*dapa); dapa->count = count; dapa->off = OFFS(buf); @@ -233,12 +182,12 @@ static void *read_sectors(uint64_t lba, uint8_t count) inreg.esi.w[0] = OFFS(dapa); inreg.ds = SEG(dapa); - inreg.edx.b[0] = disk_info.disk; + inreg.edx.b[0] = diskinfo.disk; inreg.eax.b[1] = 0x42; /* Extended read */ } else { unsigned int c, h, s, t; - if (!disk_info.cbios) { + if (!diskinfo.cbios) { /* We failed to get the geometry */ if (lba) @@ -248,10 +197,10 @@ static void *read_sectors(uint64_t lba, uint8_t count) h = 0; c = 0; } else { - s = (lba % disk_info.sect) + 1; - t = lba / disk_info.sect; /* Track = head*cyl */ - h = t % disk_info.head; - c = t / disk_info.head; + s = (lba % diskinfo.sect) + 1; + t = lba / diskinfo.sect; /* Track = head*cyl */ + h = t % diskinfo.head; + c = t / diskinfo.head; } if (s > 63 || h > 256 || c > 1023) @@ -262,7 +211,7 @@ static void *read_sectors(uint64_t lba, uint8_t count) inreg.ecx.b[1] = c & 0xff; inreg.ecx.b[0] = s + (c >> 6); inreg.edx.b[1] = h; - inreg.edx.b[0] = disk_info.disk; + inreg.edx.b[0] = diskinfo.disk; inreg.ebx.w[0] = OFFS(buf); inreg.es = SEG(buf); } @@ -285,7 +234,7 @@ static int write_sector(unsigned int lba, const void *data) memcpy(buf, data, SECTOR); memset(&inreg, 0, sizeof inreg); - if (disk_info.ebios) { + if (diskinfo.ebios) { dapa->len = sizeof(*dapa); dapa->count = 1; /* 1 sector */ dapa->off = OFFS(buf); @@ -294,12 +243,12 @@ static int write_sector(unsigned int lba, const void *data) inreg.esi.w[0] = OFFS(dapa); inreg.ds = SEG(dapa); - inreg.edx.b[0] = disk_info.disk; + inreg.edx.b[0] = diskinfo.disk; inreg.eax.w[0] = 0x4300; /* Extended write */ } else { unsigned int c, h, s, t; - if (!disk_info.cbios) { + if (!diskinfo.cbios) { /* We failed to get the geometry */ if (lba) @@ -309,10 +258,10 @@ static int write_sector(unsigned int lba, const void *data) h = 0; c = 0; } else { - s = (lba % disk_info.sect) + 1; - t = lba / disk_info.sect; /* Track = head*cyl */ - h = t % disk_info.head; - c = t / disk_info.head; + s = (lba % diskinfo.sect) + 1; + t = lba / diskinfo.sect; /* Track = head*cyl */ + h = t % diskinfo.head; + c = t / diskinfo.head; } if (s > 63 || h > 256 || c > 1023) @@ -322,7 +271,7 @@ static int write_sector(unsigned int lba, const void *data) inreg.ecx.b[1] = c & 0xff; inreg.ecx.b[0] = s + (c >> 6); inreg.edx.b[1] = h; - inreg.edx.b[0] = disk_info.disk; + inreg.edx.b[0] = diskinfo.disk; inreg.ebx.w[0] = OFFS(buf); inreg.es = SEG(buf); } @@ -421,7 +370,7 @@ static int find_disk(uint32_t mbr_sig) struct mbr *mbr; for (drive = 0x80; drive <= 0xff; drive++) { - if (get_disk_params(drive)) + if (disk_get_params(drive, &diskinfo)) continue; /* Drive doesn't exist */ if (!(mbr = read_sectors(0, 1))) continue; /* Cannot read sector */ @@ -951,7 +900,7 @@ static int find_by_guid(const struct guid *gpt_guid, struct gpt *header; for (drive = 0x80; drive <= 0xff; drive++) { - if (get_disk_params(drive)) + if (disk_get_params(drive, &diskinfo)) continue; /* Drive doesn't exist */ if (!(header = read_sectors(1, 1))) continue; /* Cannot read sector */ @@ -997,7 +946,7 @@ static int find_by_label(const char *label, struct disk_part_iter **boot_part) bool is_me; for (drive = 0x80; drive <= 0xff; drive++) { - if (get_disk_params(drive)) + if (disk_get_params(drive, &diskinfo)) continue; /* Drive doesn't exist */ /* Check for a GPT disk */ boot_part[0] = get_first_partition(NULL); @@ -1440,7 +1389,7 @@ int main(int argc, char *argv[]) regs.ebx.b[0] = regs.edx.b[0] = drive; /* Get the disk geometry and disk access setup */ - if (get_disk_params(drive)) { + if (disk_get_params(drive, &diskinfo)) { error("Cannot get disk parameters\n"); goto bail; } -- cgit v1.2.1 From 4d26d561031e306b0d9e6e14a2a0fe55446f218d Mon Sep 17 00:00:00 2001 From: Shao Miller Date: Mon, 28 Jun 2010 01:36:35 -0400 Subject: chain.c32, libcom32: Move struct ebios_dapa as disk_ebios_dapa Moving portions of chain.c32 into libcom32. Signed-off-by: Shao Miller --- com32/include/syslinux/disk.h | 8 ++++++++ com32/modules/chain.c | 12 ++---------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/com32/include/syslinux/disk.h b/com32/include/syslinux/disk.h index f880a894..51af728e 100644 --- a/com32/include/syslinux/disk.h +++ b/com32/include/syslinux/disk.h @@ -48,6 +48,14 @@ struct disk_info { int sect; }; +struct disk_ebios_dapa { + uint16_t len; + uint16_t count; + uint16_t off; + uint16_t seg; + uint64_t lba; +}; + extern int disk_int13_retry(const com32sys_t * inreg, com32sys_t * outreg); extern int disk_get_params(int disk, struct disk_info *diskinfo); diff --git a/com32/modules/chain.c b/com32/modules/chain.c index 738d8c71..ea04b8b9 100644 --- a/com32/modules/chain.c +++ b/com32/modules/chain.c @@ -151,19 +151,11 @@ static struct disk_info diskinfo; * Get a disk block and return a malloc'd buffer. * Uses the disk number and information from diskinfo. */ -struct ebios_dapa { - uint16_t len; - uint16_t count; - uint16_t off; - uint16_t seg; - uint64_t lba; -}; - /* Read count sectors from drive, starting at lba. Return a new buffer */ static void *read_sectors(uint64_t lba, uint8_t count) { com32sys_t inreg; - struct ebios_dapa *dapa = __com32.cs_bounce; + struct disk_ebios_dapa *dapa = __com32.cs_bounce; void *buf = (char *)__com32.cs_bounce + SECTOR; void *data; @@ -228,7 +220,7 @@ static void *read_sectors(uint64_t lba, uint8_t count) static int write_sector(unsigned int lba, const void *data) { com32sys_t inreg; - struct ebios_dapa *dapa = __com32.cs_bounce; + struct disk_ebios_dapa *dapa = __com32.cs_bounce; void *buf = (char *)__com32.cs_bounce + SECTOR; memcpy(buf, data, SECTOR); -- cgit v1.2.1 From 4a59565ca20050aece0ff84bff5afb181ec434df Mon Sep 17 00:00:00 2001 From: Shao Miller Date: Mon, 28 Jun 2010 01:53:28 -0400 Subject: chain.c32, libcom32: Move read_sectors() as disk_read_sectors() Moving portions of chain.c32 into libcom32. Signed-off-by: Shao Miller --- com32/include/syslinux/disk.h | 3 ++ com32/lib/syslinux/disk.c | 78 +++++++++++++++++++++++++++++++++++ com32/modules/chain.c | 94 +++++++------------------------------------ 3 files changed, 95 insertions(+), 80 deletions(-) diff --git a/com32/include/syslinux/disk.h b/com32/include/syslinux/disk.h index 51af728e..b6cdef0b 100644 --- a/com32/include/syslinux/disk.h +++ b/com32/include/syslinux/disk.h @@ -37,6 +37,7 @@ #define _SYSLINUX_DISK_H #include +#include #define SECTOR 512 /* bytes/sector */ @@ -58,5 +59,7 @@ struct disk_ebios_dapa { extern int disk_int13_retry(const com32sys_t * inreg, com32sys_t * outreg); extern int disk_get_params(int disk, struct disk_info *diskinfo); +extern void *disk_read_sectors(struct disk_info *diskinfo, uint64_t lba, + uint8_t count); #endif /* _SYSLINUX_DISK_H */ diff --git a/com32/lib/syslinux/disk.c b/com32/lib/syslinux/disk.c index 0fd35483..f13122e2 100644 --- a/com32/lib/syslinux/disk.c +++ b/com32/lib/syslinux/disk.c @@ -33,6 +33,8 @@ * Deal with disks and partitions */ +#include +#include #include /** @@ -105,3 +107,79 @@ int disk_get_params(int disk, struct disk_info *diskinfo) return 0; } + +/** + * Get a disk block and return a malloc'd buffer. + * + * @v diskinfo The disk drive to read from + * @v lba The logical block address to begin reading at + * @v count The number of sectors to read + * @ret data An allocated buffer with the read data + * + * Uses the disk number and information from diskinfo. Read count sectors + * from drive, starting at lba. Return a new buffer, or NULL upon failure. + */ +void *disk_read_sectors(struct disk_info *diskinfo, uint64_t lba, uint8_t count) +{ + com32sys_t inreg; + struct disk_ebios_dapa *dapa = __com32.cs_bounce; + void *buf = (char *)__com32.cs_bounce + SECTOR; + void *data; + + if (!count) + /* Silly */ + return NULL; + + memset(&inreg, 0, sizeof inreg); + + if (diskinfo->ebios) { + dapa->len = sizeof(*dapa); + dapa->count = count; + dapa->off = OFFS(buf); + dapa->seg = SEG(buf); + dapa->lba = lba; + + inreg.esi.w[0] = OFFS(dapa); + inreg.ds = SEG(dapa); + inreg.edx.b[0] = diskinfo->disk; + inreg.eax.b[1] = 0x42; /* Extended read */ + } else { + unsigned int c, h, s, t; + + if (!diskinfo->cbios) { + /* We failed to get the geometry */ + + if (lba) + return NULL; /* Can only read MBR */ + + s = 1; + h = 0; + c = 0; + } else { + s = (lba % diskinfo->sect) + 1; + t = lba / diskinfo->sect; /* Track = head*cyl */ + h = t % diskinfo->head; + c = t / diskinfo->head; + } + + if (s > 63 || h > 256 || c > 1023) + return NULL; + + inreg.eax.b[0] = count; + inreg.eax.b[1] = 0x02; /* Read */ + inreg.ecx.b[1] = c & 0xff; + inreg.ecx.b[0] = s + (c >> 6); + inreg.edx.b[1] = h; + inreg.edx.b[0] = diskinfo->disk; + inreg.ebx.w[0] = OFFS(buf); + inreg.es = SEG(buf); + } + + if (disk_int13_retry(&inreg, NULL)) + return NULL; + + data = malloc(count * SECTOR); + if (data) + memcpy(data, buf, count * SECTOR); + return data; +} diff --git a/com32/modules/chain.c b/com32/modules/chain.c index ea04b8b9..0ff1ea1f 100644 --- a/com32/modules/chain.c +++ b/com32/modules/chain.c @@ -147,76 +147,6 @@ static inline void error(const char *msg) static struct disk_info diskinfo; -/* - * Get a disk block and return a malloc'd buffer. - * Uses the disk number and information from diskinfo. - */ -/* Read count sectors from drive, starting at lba. Return a new buffer */ -static void *read_sectors(uint64_t lba, uint8_t count) -{ - com32sys_t inreg; - struct disk_ebios_dapa *dapa = __com32.cs_bounce; - void *buf = (char *)__com32.cs_bounce + SECTOR; - void *data; - - if (!count) - /* Silly */ - return NULL; - - memset(&inreg, 0, sizeof inreg); - - if (diskinfo.ebios) { - dapa->len = sizeof(*dapa); - dapa->count = count; - dapa->off = OFFS(buf); - dapa->seg = SEG(buf); - dapa->lba = lba; - - inreg.esi.w[0] = OFFS(dapa); - inreg.ds = SEG(dapa); - inreg.edx.b[0] = diskinfo.disk; - inreg.eax.b[1] = 0x42; /* Extended read */ - } else { - unsigned int c, h, s, t; - - if (!diskinfo.cbios) { - /* We failed to get the geometry */ - - if (lba) - return NULL; /* Can only read MBR */ - - s = 1; - h = 0; - c = 0; - } else { - s = (lba % diskinfo.sect) + 1; - t = lba / diskinfo.sect; /* Track = head*cyl */ - h = t % diskinfo.head; - c = t / diskinfo.head; - } - - if (s > 63 || h > 256 || c > 1023) - return NULL; - - inreg.eax.b[0] = count; - inreg.eax.b[1] = 0x02; /* Read */ - inreg.ecx.b[1] = c & 0xff; - inreg.ecx.b[0] = s + (c >> 6); - inreg.edx.b[1] = h; - inreg.edx.b[0] = diskinfo.disk; - inreg.ebx.w[0] = OFFS(buf); - inreg.es = SEG(buf); - } - - if (disk_int13_retry(&inreg, NULL)) - return NULL; - - data = malloc(count * SECTOR); - if (data) - memcpy(data, buf, count * SECTOR); - return data; -} - static int write_sector(unsigned int lba, const void *data) { com32sys_t inreg; @@ -282,7 +212,7 @@ static int write_verify_sector(unsigned int lba, const void *buf) rv = write_sector(lba, buf); if (rv) return rv; /* Write failure */ - rb = read_sectors(lba, 1); + rb = disk_read_sectors(&diskinfo, lba, 1); if (!rb) return -1; /* Readback failure */ rv = memcmp(buf, rb, SECTOR); @@ -364,7 +294,7 @@ static int find_disk(uint32_t mbr_sig) for (drive = 0x80; drive <= 0xff; drive++) { if (disk_get_params(drive, &diskinfo)) continue; /* Drive doesn't exist */ - if (!(mbr = read_sectors(0, 1))) + if (!(mbr = disk_read_sectors(&diskinfo, 0, 1))) continue; /* Cannot read sector */ is_me = (mbr->disk_sig == mbr_sig); free(mbr); @@ -453,7 +383,7 @@ static struct disk_part_iter *next_ebr_part(struct disk_part_iter *part) /* Load next EBR */ ebr_lba = ebr_table->start_lba + part->private.ebr.lba_extended; free(part->block); - part->block = read_sectors(ebr_lba, 1); + part->block = disk_read_sectors(&diskinfo, ebr_lba, 1); if (!part->block) { error("Could not load EBR!\n"); goto err_ebr; @@ -813,7 +743,7 @@ static struct disk_part_iter *get_first_partition(struct disk_part_iter *part) goto err_alloc_iter; } /* Read MBR */ - part->block = read_sectors(0, 2); + part->block = disk_read_sectors(&diskinfo, 0, 2); if (!part->block) { error("Could not read two sectors!\n"); goto err_read_mbr; @@ -851,9 +781,10 @@ static struct disk_part_iter *get_first_partition(struct disk_part_iter *part) /* Load the partition table */ free(part->block); part->block = - read_sectors(lba_table, - ((part->private.gpt.size * part->private.gpt.parts) + - SECTOR - 1) / SECTOR); + disk_read_sectors(&diskinfo, lba_table, + ((part->private.gpt.size * + part->private.gpt.parts) + SECTOR - + 1) / SECTOR); if (!part->block) { error("Could not read GPT partition list!\n"); goto err_gpt_table; @@ -894,7 +825,7 @@ static int find_by_guid(const struct guid *gpt_guid, for (drive = 0x80; drive <= 0xff; drive++) { if (disk_get_params(drive, &diskinfo)) continue; /* Drive doesn't exist */ - if (!(header = read_sectors(1, 1))) + if (!(header = disk_read_sectors(&diskinfo, 1, 1))) continue; /* Cannot read sector */ if (memcmp(&header->sig, gpt_sig_magic, sizeof(gpt_sig_magic))) { /* Not a GPT disk */ @@ -1387,7 +1318,7 @@ int main(int argc, char *argv[]) } /* Get MBR */ - if (!(mbr = read_sectors(0, 1))) { + if (!(mbr = disk_read_sectors(&diskinfo, 0, 1))) { error("Cannot read Master Boot Record or sector 0\n"); goto bail; } @@ -1621,7 +1552,10 @@ int main(int argc, char *argv[]) /* Actually read the boot sector */ if (!cur_part) { data[ndata].data = mbr; - } else if (!(data[ndata].data = read_sectors(cur_part->lba_data, 1))) { + } else + if (! + (data[ndata].data = + disk_read_sectors(&diskinfo, cur_part->lba_data, 1))) { error("Cannot read boot sector\n"); goto bail; } -- cgit v1.2.1 From 1cf649982aed3bd020909939c491ed19a412e5ea Mon Sep 17 00:00:00 2001 From: Shao Miller Date: Mon, 28 Jun 2010 01:54:38 -0400 Subject: libcom32 disk: Trivial formatting fix-up Signed-off-by: Shao Miller --- com32/lib/syslinux/disk.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/com32/lib/syslinux/disk.c b/com32/lib/syslinux/disk.c index f13122e2..a1d66976 100644 --- a/com32/lib/syslinux/disk.c +++ b/com32/lib/syslinux/disk.c @@ -40,8 +40,9 @@ /** * Call int 13h, but with retry on failure. Especially floppies need this. * - * @v inreg CPU register settings upon INT call + * @v inreg CPU register settings upon INT call * @v outreg CPU register settings returned by INT call + * @ret (int) 0 upon success, -1 upon failure */ int disk_int13_retry(const com32sys_t * inreg, com32sys_t * outreg) { @@ -60,11 +61,12 @@ int disk_int13_retry(const com32sys_t * inreg, com32sys_t * outreg) return -1; /* Error */ } -/* +/** * Query disk parameters and EBIOS availability for a particular disk. * * @v disk The INT 0x13 disk drive number to process * @v diskinfo The structure to save the queried params to + * @ret (int) 0 upon success, -1 upon failure */ int disk_get_params(int disk, struct disk_info *diskinfo) { @@ -109,7 +111,7 @@ int disk_get_params(int disk, struct disk_info *diskinfo) } /** - * Get a disk block and return a malloc'd buffer. + * Get disk block(s) and return a malloc'd buffer. * * @v diskinfo The disk drive to read from * @v lba The logical block address to begin reading at -- cgit v1.2.1 From 86bf50325b73618cd67a67d5b9a1781877493c07 Mon Sep 17 00:00:00 2001 From: Shao Miller Date: Mon, 28 Jun 2010 02:14:08 -0400 Subject: chain.c32, libcom32: Move write_sector() as disk_write_sector() Moving portions of chain.c32 into libcom32. Signed-off-by: Shao Miller --- com32/include/syslinux/disk.h | 2 ++ com32/lib/syslinux/disk.c | 69 +++++++++++++++++++++++++++++++++++++++++++ com32/modules/chain.c | 59 +----------------------------------- 3 files changed, 72 insertions(+), 58 deletions(-) diff --git a/com32/include/syslinux/disk.h b/com32/include/syslinux/disk.h index b6cdef0b..ef002e22 100644 --- a/com32/include/syslinux/disk.h +++ b/com32/include/syslinux/disk.h @@ -61,5 +61,7 @@ extern int disk_int13_retry(const com32sys_t * inreg, com32sys_t * outreg); extern int disk_get_params(int disk, struct disk_info *diskinfo); extern void *disk_read_sectors(struct disk_info *diskinfo, uint64_t lba, uint8_t count); +extern int disk_write_sector(struct disk_info *diskinfo, unsigned int lba, + const void *data); #endif /* _SYSLINUX_DISK_H */ diff --git a/com32/lib/syslinux/disk.c b/com32/lib/syslinux/disk.c index a1d66976..7b7cbe4d 100644 --- a/com32/lib/syslinux/disk.c +++ b/com32/lib/syslinux/disk.c @@ -185,3 +185,72 @@ void *disk_read_sectors(struct disk_info *diskinfo, uint64_t lba, uint8_t count) memcpy(data, buf, count * SECTOR); return data; } + +/** + * Write a disk block. + * + * @v diskinfo The disk drive to write to + * @v lba The logical block address to begin writing at + * @v data The data to write + * @ret (int) 0 upon success, -1 upon failure + * + * Uses the disk number and information from diskinfo. + * Write a sector to a disk drive, starting at lba. + */ +int disk_write_sector(struct disk_info *diskinfo, unsigned int lba, + const void *data) +{ + com32sys_t inreg; + struct disk_ebios_dapa *dapa = __com32.cs_bounce; + void *buf = (char *)__com32.cs_bounce + SECTOR; + + memcpy(buf, data, SECTOR); + memset(&inreg, 0, sizeof inreg); + + if (diskinfo->ebios) { + dapa->len = sizeof(*dapa); + dapa->count = 1; /* 1 sector */ + dapa->off = OFFS(buf); + dapa->seg = SEG(buf); + dapa->lba = lba; + + inreg.esi.w[0] = OFFS(dapa); + inreg.ds = SEG(dapa); + inreg.edx.b[0] = diskinfo->disk; + inreg.eax.w[0] = 0x4300; /* Extended write */ + } else { + unsigned int c, h, s, t; + + if (!diskinfo->cbios) { + /* We failed to get the geometry */ + + if (lba) + return -1; /* Can only write MBR */ + + s = 1; + h = 0; + c = 0; + } else { + s = (lba % diskinfo->sect) + 1; + t = lba / diskinfo->sect; /* Track = head*cyl */ + h = t % diskinfo->head; + c = t / diskinfo->head; + } + + if (s > 63 || h > 256 || c > 1023) + return -1; + + inreg.eax.w[0] = 0x0301; /* Write one sector */ + inreg.ecx.b[1] = c & 0xff; + inreg.ecx.b[0] = s + (c >> 6); + inreg.edx.b[1] = h; + inreg.edx.b[0] = diskinfo->disk; + inreg.ebx.w[0] = OFFS(buf); + inreg.es = SEG(buf); + } + + if (disk_int13_retry(&inreg, NULL)) + return -1; + + return 0; /* ok */ +} diff --git a/com32/modules/chain.c b/com32/modules/chain.c index 0ff1ea1f..de827a20 100644 --- a/com32/modules/chain.c +++ b/com32/modules/chain.c @@ -147,69 +147,12 @@ static inline void error(const char *msg) static struct disk_info diskinfo; -static int write_sector(unsigned int lba, const void *data) -{ - com32sys_t inreg; - struct disk_ebios_dapa *dapa = __com32.cs_bounce; - void *buf = (char *)__com32.cs_bounce + SECTOR; - - memcpy(buf, data, SECTOR); - memset(&inreg, 0, sizeof inreg); - - if (diskinfo.ebios) { - dapa->len = sizeof(*dapa); - dapa->count = 1; /* 1 sector */ - dapa->off = OFFS(buf); - dapa->seg = SEG(buf); - dapa->lba = lba; - - inreg.esi.w[0] = OFFS(dapa); - inreg.ds = SEG(dapa); - inreg.edx.b[0] = diskinfo.disk; - inreg.eax.w[0] = 0x4300; /* Extended write */ - } else { - unsigned int c, h, s, t; - - if (!diskinfo.cbios) { - /* We failed to get the geometry */ - - if (lba) - return -1; /* Can only write MBR */ - - s = 1; - h = 0; - c = 0; - } else { - s = (lba % diskinfo.sect) + 1; - t = lba / diskinfo.sect; /* Track = head*cyl */ - h = t % diskinfo.head; - c = t / diskinfo.head; - } - - if (s > 63 || h > 256 || c > 1023) - return -1; - - inreg.eax.w[0] = 0x0301; /* Write one sector */ - inreg.ecx.b[1] = c & 0xff; - inreg.ecx.b[0] = s + (c >> 6); - inreg.edx.b[1] = h; - inreg.edx.b[0] = diskinfo.disk; - inreg.ebx.w[0] = OFFS(buf); - inreg.es = SEG(buf); - } - - if (disk_int13_retry(&inreg, NULL)) - return -1; - - return 0; /* ok */ -} - static int write_verify_sector(unsigned int lba, const void *buf) { char *rb; int rv; - rv = write_sector(lba, buf); + rv = disk_write_sector(&diskinfo, lba, buf); if (rv) return rv; /* Write failure */ rb = disk_read_sectors(&diskinfo, lba, 1); -- cgit v1.2.1 From 3748a9dc3ead604596b7a2c94014ad3817a107cf Mon Sep 17 00:00:00 2001 From: Shao Miller Date: Mon, 28 Jun 2010 02:26:11 -0400 Subject: chain.c32, libcom32: Move write_verify_sector() as disk_write_verify_sector() Moving portions of chain.c32 into libcom32. Signed-off-by: Shao Miller --- com32/include/syslinux/disk.h | 2 ++ com32/lib/syslinux/disk.c | 29 +++++++++++++++++++++++++++++ com32/modules/chain.c | 18 +----------------- 3 files changed, 32 insertions(+), 17 deletions(-) diff --git a/com32/include/syslinux/disk.h b/com32/include/syslinux/disk.h index ef002e22..82513ced 100644 --- a/com32/include/syslinux/disk.h +++ b/com32/include/syslinux/disk.h @@ -63,5 +63,7 @@ extern void *disk_read_sectors(struct disk_info *diskinfo, uint64_t lba, uint8_t count); extern int disk_write_sector(struct disk_info *diskinfo, unsigned int lba, const void *data); +extern int disk_write_verify_sector(struct disk_info *diskinfo, + unsigned int lba, const void *buf); #endif /* _SYSLINUX_DISK_H */ diff --git a/com32/lib/syslinux/disk.c b/com32/lib/syslinux/disk.c index 7b7cbe4d..8223534e 100644 --- a/com32/lib/syslinux/disk.c +++ b/com32/lib/syslinux/disk.c @@ -254,3 +254,32 @@ int disk_write_sector(struct disk_info *diskinfo, unsigned int lba, return 0; /* ok */ } + +/** + * Write a disk block and verify it was written. + * + * @v diskinfo The disk drive to write to + * @v lba The logical block address to begin writing at + * @v buf The data to write + * @ret rv 0 upon success, -1 upon failure + * + * Uses the disk number and information from diskinfo. + * Writes a sector to a disk drive starting at lba, then reads it back + * to verify it was written correctly. + */ +int disk_write_verify_sector(struct disk_info *diskinfo, unsigned int lba, + const void *buf) +{ + char *rb; + int rv; + + rv = disk_write_sector(diskinfo, lba, buf); + if (rv) + return rv; /* Write failure */ + rb = disk_read_sectors(diskinfo, lba, 1); + if (!rb) + return -1; /* Readback failure */ + rv = memcmp(buf, rb, SECTOR); + free(rb); + return rv ? -1 : 0; +} diff --git a/com32/modules/chain.c b/com32/modules/chain.c index de827a20..6bf8827e 100644 --- a/com32/modules/chain.c +++ b/com32/modules/chain.c @@ -147,22 +147,6 @@ static inline void error(const char *msg) static struct disk_info diskinfo; -static int write_verify_sector(unsigned int lba, const void *buf) -{ - char *rb; - int rv; - - rv = disk_write_sector(&diskinfo, lba, buf); - if (rv) - return rv; /* Write failure */ - rb = disk_read_sectors(&diskinfo, lba, 1); - if (!rb) - return -1; /* Readback failure */ - rv = memcmp(buf, rb, SECTOR); - free(rb); - return rv ? -1 : 0; -} - /* * CHS (cylinder, head, sector) value extraction macros. * Taken from WinVBlock. Does not expand to an lvalue @@ -1008,7 +992,7 @@ static int hide_unhide(struct mbr *mbr, int part) } if (write_back) - return write_verify_sector(0, mbr); + return disk_write_verify_sector(&diskinfo, 0, mbr); return 0; /* ok */ } -- cgit v1.2.1 From 092b8884d54f6469dd401283d6fdc401a3481444 Mon Sep 17 00:00:00 2001 From: Shao Miller Date: Mon, 28 Jun 2010 02:30:49 -0400 Subject: libcom32 disk: A slight grunt of constipation Add const qualifier because we can. Signed-off-by: Shao Miller --- com32/include/syslinux/disk.h | 12 ++++++------ com32/lib/syslinux/disk.c | 11 ++++++----- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/com32/include/syslinux/disk.h b/com32/include/syslinux/disk.h index 82513ced..e81bd3b7 100644 --- a/com32/include/syslinux/disk.h +++ b/com32/include/syslinux/disk.h @@ -58,12 +58,12 @@ struct disk_ebios_dapa { }; extern int disk_int13_retry(const com32sys_t * inreg, com32sys_t * outreg); -extern int disk_get_params(int disk, struct disk_info *diskinfo); -extern void *disk_read_sectors(struct disk_info *diskinfo, uint64_t lba, - uint8_t count); -extern int disk_write_sector(struct disk_info *diskinfo, unsigned int lba, - const void *data); -extern int disk_write_verify_sector(struct disk_info *diskinfo, +extern int disk_get_params(int disk, struct disk_info *const diskinfo); +extern void *disk_read_sectors(const struct disk_info *const diskinfo, + uint64_t lba, uint8_t count); +extern int disk_write_sector(const struct disk_info *const diskinfo, + unsigned int lba, const void *data); +extern int disk_write_verify_sector(const struct disk_info *const diskinfo, unsigned int lba, const void *buf); #endif /* _SYSLINUX_DISK_H */ diff --git a/com32/lib/syslinux/disk.c b/com32/lib/syslinux/disk.c index 8223534e..3b23fef0 100644 --- a/com32/lib/syslinux/disk.c +++ b/com32/lib/syslinux/disk.c @@ -68,7 +68,7 @@ int disk_int13_retry(const com32sys_t * inreg, com32sys_t * outreg) * @v diskinfo The structure to save the queried params to * @ret (int) 0 upon success, -1 upon failure */ -int disk_get_params(int disk, struct disk_info *diskinfo) +int disk_get_params(int disk, struct disk_info *const diskinfo) { static com32sys_t getparm, parm, getebios, ebios; @@ -121,7 +121,8 @@ int disk_get_params(int disk, struct disk_info *diskinfo) * Uses the disk number and information from diskinfo. Read count sectors * from drive, starting at lba. Return a new buffer, or NULL upon failure. */ -void *disk_read_sectors(struct disk_info *diskinfo, uint64_t lba, uint8_t count) +void *disk_read_sectors(const struct disk_info *const diskinfo, uint64_t lba, + uint8_t count) { com32sys_t inreg; struct disk_ebios_dapa *dapa = __com32.cs_bounce; @@ -197,7 +198,7 @@ void *disk_read_sectors(struct disk_info *diskinfo, uint64_t lba, uint8_t count) * Uses the disk number and information from diskinfo. * Write a sector to a disk drive, starting at lba. */ -int disk_write_sector(struct disk_info *diskinfo, unsigned int lba, +int disk_write_sector(const struct disk_info *const diskinfo, unsigned int lba, const void *data) { com32sys_t inreg; @@ -267,8 +268,8 @@ int disk_write_sector(struct disk_info *diskinfo, unsigned int lba, * Writes a sector to a disk drive starting at lba, then reads it back * to verify it was written correctly. */ -int disk_write_verify_sector(struct disk_info *diskinfo, unsigned int lba, - const void *buf) +int disk_write_verify_sector(const struct disk_info *const diskinfo, + unsigned int lba, const void *buf) { char *rb; int rv; -- cgit v1.2.1 From 6880951cdaadf554a7536859f1a001bed9fd9c34 Mon Sep 17 00:00:00 2001 From: Shao Miller Date: Mon, 28 Jun 2010 02:40:12 -0400 Subject: chain.c32, libcom32: Move chs macros and chs typedef as disk_chs Moving portions of chain.c32 into libcom32. Signed-off-by: Shao Miller --- com32/include/syslinux/disk.h | 11 +++++++++++ com32/modules/chain.c | 15 ++------------- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/com32/include/syslinux/disk.h b/com32/include/syslinux/disk.h index e81bd3b7..d893d7f7 100644 --- a/com32/include/syslinux/disk.h +++ b/com32/include/syslinux/disk.h @@ -57,6 +57,17 @@ struct disk_ebios_dapa { uint64_t lba; }; +/** + * CHS (cylinder, head, sector) value extraction macros. + * Taken from WinVBlock. None expand to an lvalue. +*/ +#define chs_head(chs) chs[0] +#define chs_sector(chs) (chs[1] & 0x3F) +#define chs_cyl_high(chs) (((uint16_t)(chs[1] & 0xC0)) << 2) +#define chs_cyl_low(chs) ((uint16_t)chs[2]) +#define chs_cylinder(chs) (chs_cyl_high(chs) | chs_cyl_low(chs)) +typedef uint8_t disk_chs[3]; + extern int disk_int13_retry(const com32sys_t * inreg, com32sys_t * outreg); extern int disk_get_params(int disk, struct disk_info *const diskinfo); extern void *disk_read_sectors(const struct disk_info *const diskinfo, diff --git a/com32/modules/chain.c b/com32/modules/chain.c index 6bf8827e..f631d6e5 100644 --- a/com32/modules/chain.c +++ b/com32/modules/chain.c @@ -147,23 +147,12 @@ static inline void error(const char *msg) static struct disk_info diskinfo; -/* - * CHS (cylinder, head, sector) value extraction macros. - * Taken from WinVBlock. Does not expand to an lvalue -*/ -#define chs_head(chs) chs[0] -#define chs_sector(chs) (chs[1] & 0x3F) -#define chs_cyl_high(chs) (((uint16_t)(chs[1] & 0xC0)) << 2) -#define chs_cyl_low(chs) ((uint16_t)chs[2]) -#define chs_cylinder(chs) (chs_cyl_high(chs) | chs_cyl_low(chs)) -typedef uint8_t chs[3]; - /* A DOS partition table entry */ struct part_entry { uint8_t active_flag; /* 0x80 if "active" */ - chs start; + disk_chs start; uint8_t ostype; - chs end; + disk_chs end; uint32_t start_lba; uint32_t length; } __attribute__ ((packed)); -- cgit v1.2.1 From 9ed2367f8fb0f48d31f2953b8e85287259c08a18 Mon Sep 17 00:00:00 2001 From: Shao Miller Date: Mon, 28 Jun 2010 02:47:30 -0400 Subject: chain.c32, libcom32: Move struct part_entry as disk_dos_part_entry Moving portions of chain.c32 into libcom32. Signed-off-by: Shao Miller --- com32/include/syslinux/disk.h | 10 ++++++++++ com32/modules/chain.c | 34 ++++++++++++---------------------- 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/com32/include/syslinux/disk.h b/com32/include/syslinux/disk.h index d893d7f7..79adae5d 100644 --- a/com32/include/syslinux/disk.h +++ b/com32/include/syslinux/disk.h @@ -68,6 +68,16 @@ struct disk_ebios_dapa { #define chs_cylinder(chs) (chs_cyl_high(chs) | chs_cyl_low(chs)) typedef uint8_t disk_chs[3]; +/* A DOS partition table entry */ +struct disk_dos_part_entry { + uint8_t active_flag; /* 0x80 if "active" */ + disk_chs start; + uint8_t ostype; + disk_chs end; + uint32_t start_lba; + uint32_t length; +} __attribute__ ((packed)); + extern int disk_int13_retry(const com32sys_t * inreg, com32sys_t * outreg); extern int disk_get_params(int disk, struct disk_info *const diskinfo); extern void *disk_read_sectors(const struct disk_info *const diskinfo, diff --git a/com32/modules/chain.c b/com32/modules/chain.c index f631d6e5..fd5cb66a 100644 --- a/com32/modules/chain.c +++ b/com32/modules/chain.c @@ -147,17 +147,7 @@ static inline void error(const char *msg) static struct disk_info diskinfo; -/* A DOS partition table entry */ -struct part_entry { - uint8_t active_flag; /* 0x80 if "active" */ - disk_chs start; - uint8_t ostype; - disk_chs end; - uint32_t start_lba; - uint32_t length; -} __attribute__ ((packed)); - -static void mbr_part_dump(const struct part_entry *part) +static void mbr_part_dump(const struct disk_dos_part_entry *part) { (void)part; dprintf("Partition status _____ : 0x%.2x\n" @@ -195,7 +185,7 @@ struct mbr { char code[440]; uint32_t disk_sig; char pad[2]; - struct part_entry table[4]; + struct disk_dos_part_entry table[4]; uint16_t sig; } __attribute__ ((packed)); static const uint16_t mbr_sig_magic = 0xAA55; @@ -236,7 +226,7 @@ struct disk_part_iter { /* The partition number, as determined by our heuristic */ int index; /* The DOS partition record to pass, if applicable */ - const struct part_entry *record; + const struct disk_dos_part_entry *record; /* Function returning the next available partition */ disk_part_iter_func next; /* Partition-/scheme-specific details */ @@ -270,10 +260,10 @@ struct disk_part_iter { static struct disk_part_iter *next_ebr_part(struct disk_part_iter *part) { - const struct part_entry *ebr_table; - const struct part_entry *parent_table = + const struct disk_dos_part_entry *ebr_table; + const struct disk_dos_part_entry *parent_table = ((const struct mbr *)part->private.ebr.parent->block)->table; - static const struct part_entry phony = {.start_lba = 0 }; + static const struct disk_dos_part_entry phony = {.start_lba = 0 }; uint64_t ebr_lba; /* Don't look for a "next EBR" the first time around */ @@ -316,7 +306,7 @@ static struct disk_part_iter *next_ebr_part(struct disk_part_iter *part) { const struct mbr *mbr = (const struct mbr *)part->private.ebr.parent->block; - const struct part_entry *extended = + const struct disk_dos_part_entry *extended = mbr->table + part->private.ebr.parent_index; if (ebr_table[0].start_lba >= extended->start_lba + extended->length) { @@ -349,7 +339,7 @@ static struct disk_part_iter *next_mbr_part(struct disk_part_iter *part) { struct disk_part_iter *ebr_part; /* Look at the partition table */ - struct part_entry *table = ((struct mbr *)part->block)->table; + struct disk_dos_part_entry *table = ((struct mbr *)part->block)->table; /* Look for data partitions */ while (++part->private.mbr_index < 4) { @@ -955,7 +945,7 @@ enomem: static int hide_unhide(struct mbr *mbr, int part) { int i; - struct part_entry *pt; + struct disk_dos_part_entry *pt; const uint16_t mask = (1 << 0x01) | (1 << 0x04) | (1 << 0x06) | (1 << 0x07) | (1 << 0x0b) | (1 << @@ -1513,7 +1503,7 @@ int main(int argc, char *argv[]) if (cur_part) { if (cur_part->next == next_gpt_part) { /* Do GPT hand-over, if applicable (as per syslinux/doc/gpt.txt) */ - struct part_entry *record; + struct disk_dos_part_entry *record; /* Look at the GPT partition */ const struct gpt_part *gp = (const struct gpt_part *) (cur_part->block + @@ -1522,7 +1512,7 @@ int main(int argc, char *argv[]) uint64_t lba_count = gp->lba_last - gp->lba_first + 1; /* The length of the hand-over */ int synth_size = - sizeof(struct part_entry) + sizeof(uint32_t) + + sizeof(struct disk_dos_part_entry) + sizeof(uint32_t) + cur_part->private.gpt.size; /* Will point to the partition record length in the hand-over */ uint32_t *plen; @@ -1564,7 +1554,7 @@ int main(int argc, char *argv[]) gpt_part_dump((struct gpt_part *)(plen + 1)); } else if (cur_part->record) { /* MBR handover protocol */ - static struct part_entry handover_record; + static struct disk_dos_part_entry handover_record; handover_record = *cur_part->record; handover_record.start_lba = cur_part->lba_data; -- cgit v1.2.1 From 8cee41716005ff8495349241de3eeb33ae7b53a0 Mon Sep 17 00:00:00 2001 From: Shao Miller Date: Mon, 28 Jun 2010 02:54:36 -0400 Subject: chain.c32, libcom32: Move mbr_part_dump() as disk_dos_part_dump() Moving portions of chain.c32 into libcom32. Signed-off-by: Shao Miller --- com32/include/syslinux/disk.h | 1 + com32/lib/syslinux/disk.c | 39 +++++++++++++++++++++++++++++++++++++++ com32/modules/chain.c | 41 ++++------------------------------------- 3 files changed, 44 insertions(+), 37 deletions(-) diff --git a/com32/include/syslinux/disk.h b/com32/include/syslinux/disk.h index 79adae5d..6e213c5e 100644 --- a/com32/include/syslinux/disk.h +++ b/com32/include/syslinux/disk.h @@ -86,5 +86,6 @@ extern int disk_write_sector(const struct disk_info *const diskinfo, unsigned int lba, const void *data); extern int disk_write_verify_sector(const struct disk_info *const diskinfo, unsigned int lba, const void *buf); +extern void disk_dos_part_dump(const struct disk_dos_part_entry *const part); #endif /* _SYSLINUX_DISK_H */ diff --git a/com32/lib/syslinux/disk.c b/com32/lib/syslinux/disk.c index 3b23fef0..b7022070 100644 --- a/com32/lib/syslinux/disk.c +++ b/com32/lib/syslinux/disk.c @@ -33,6 +33,7 @@ * Deal with disks and partitions */ +#include #include #include #include @@ -284,3 +285,41 @@ int disk_write_verify_sector(const struct disk_info *const diskinfo, free(rb); return rv ? -1 : 0; } + +/** + * Dump info about a DOS partition entry + * + * @v part The 16-byte partition entry to examine + */ +void disk_dos_part_dump(const struct disk_dos_part_entry *const part) +{ + (void)part; + dprintf("Partition status _____ : 0x%.2x\n" + "Partition CHS start\n" + " Cylinder ___________ : 0x%.4x (%u)\n" + " Head _______________ : 0x%.2x (%u)\n" + " Sector _____________ : 0x%.2x (%u)\n" + "Partition type _______ : 0x%.2x\n" + "Partition CHS end\n" + " Cylinder ___________ : 0x%.4x (%u)\n" + " Head _______________ : 0x%.2x (%u)\n" + " Sector _____________ : 0x%.2x (%u)\n" + "Partition LBA start __ : 0x%.8x (%u)\n" + "Partition LBA count __ : 0x%.8x (%u)\n" + "-------------------------------\n", + part->active_flag, + chs_cylinder(part->start), + chs_cylinder(part->start), + chs_head(part->start), + chs_head(part->start), + chs_sector(part->start), + chs_sector(part->start), + part->ostype, + chs_cylinder(part->end), + chs_cylinder(part->end), + chs_head(part->end), + chs_head(part->end), + chs_sector(part->end), + chs_sector(part->end), + part->start_lba, part->start_lba, part->length, part->length); +} diff --git a/com32/modules/chain.c b/com32/modules/chain.c index fd5cb66a..04b15603 100644 --- a/com32/modules/chain.c +++ b/com32/modules/chain.c @@ -147,39 +147,6 @@ static inline void error(const char *msg) static struct disk_info diskinfo; -static void mbr_part_dump(const struct disk_dos_part_entry *part) -{ - (void)part; - dprintf("Partition status _____ : 0x%.2x\n" - "Partition CHS start\n" - " Cylinder ___________ : 0x%.4x (%u)\n" - " Head _______________ : 0x%.2x (%u)\n" - " Sector _____________ : 0x%.2x (%u)\n" - "Partition type _______ : 0x%.2x\n" - "Partition CHS end\n" - " Cylinder ___________ : 0x%.4x (%u)\n" - " Head _______________ : 0x%.2x (%u)\n" - " Sector _____________ : 0x%.2x (%u)\n" - "Partition LBA start __ : 0x%.8x (%u)\n" - "Partition LBA count __ : 0x%.8x (%u)\n" - "-------------------------------\n", - part->active_flag, - chs_cylinder(part->start), - chs_cylinder(part->start), - chs_head(part->start), - chs_head(part->start), - chs_sector(part->start), - chs_sector(part->start), - part->ostype, - chs_cylinder(part->end), - chs_cylinder(part->end), - chs_head(part->end), - chs_head(part->end), - chs_sector(part->end), - chs_sector(part->end), - part->start_lba, part->start_lba, part->length, part->length); -} - /* A DOS MBR */ struct mbr { char code[440]; @@ -296,7 +263,7 @@ static struct disk_part_iter *next_ebr_part(struct disk_part_iter *part) } ebr_table = ((const struct mbr *)part->block)->table; dprintf("next_ebr_part:\n"); - mbr_part_dump(ebr_table); + disk_dos_part_dump(ebr_table); /* * Sanity check entry: must not extend outside the @@ -373,7 +340,7 @@ static struct disk_part_iter *next_mbr_part(struct disk_part_iter *part) return next_ebr_part(ebr_part); } dprintf("next_mbr_part:\n"); - mbr_part_dump(table + part->private.mbr_index); + disk_dos_part_dump(table + part->private.mbr_index); /* Update parameters to reflect this new partition. Re-use iterator */ part->lba_data = table[part->private.mbr_index].start_lba; @@ -1550,7 +1517,7 @@ int main(int argc, char *argv[]) regs.esi.w[0] = 0x7be; dprintf("GPT handover:\n"); - mbr_part_dump(record); + disk_dos_part_dump(record); gpt_part_dump((struct gpt_part *)(plen + 1)); } else if (cur_part->record) { /* MBR handover protocol */ @@ -1566,7 +1533,7 @@ int main(int argc, char *argv[]) regs.esi.w[0] = 0x7be; dprintf("MBR handover:\n"); - mbr_part_dump(&handover_record); + disk_dos_part_dump(&handover_record); } } -- cgit v1.2.1 From 6ba6279507775172c5d7dfe2a3b147ee0a7a0814 Mon Sep 17 00:00:00 2001 From: Shao Miller Date: Mon, 28 Jun 2010 03:02:14 -0400 Subject: chain.c32, libcom32: Move struct mbr as disk_dos_mbr Also move mbr_sig_magic as disk_mbr_sig_magic macro. Moving portions of chain.c32 into libcom32. Signed-off-by: Shao Miller --- com32/include/syslinux/disk.h | 10 ++++++++++ com32/modules/chain.c | 40 ++++++++++++++++------------------------ 2 files changed, 26 insertions(+), 24 deletions(-) diff --git a/com32/include/syslinux/disk.h b/com32/include/syslinux/disk.h index 6e213c5e..f96e8fe7 100644 --- a/com32/include/syslinux/disk.h +++ b/com32/include/syslinux/disk.h @@ -78,6 +78,16 @@ struct disk_dos_part_entry { uint32_t length; } __attribute__ ((packed)); +/* A DOS MBR */ +struct disk_dos_mbr { + char code[440]; + uint32_t disk_sig; + char pad[2]; + struct disk_dos_part_entry table[4]; + uint16_t sig; +} __attribute__ ((packed)); +#define disk_mbr_sig_magic 0xAA55 + extern int disk_int13_retry(const com32sys_t * inreg, com32sys_t * outreg); extern int disk_get_params(int disk, struct disk_info *const diskinfo); extern void *disk_read_sectors(const struct disk_info *const diskinfo, diff --git a/com32/modules/chain.c b/com32/modules/chain.c index 04b15603..896727d1 100644 --- a/com32/modules/chain.c +++ b/com32/modules/chain.c @@ -147,22 +147,12 @@ static inline void error(const char *msg) static struct disk_info diskinfo; -/* A DOS MBR */ -struct mbr { - char code[440]; - uint32_t disk_sig; - char pad[2]; - struct disk_dos_part_entry table[4]; - uint16_t sig; -} __attribute__ ((packed)); -static const uint16_t mbr_sig_magic = 0xAA55; - /* Search for a specific drive, based on the MBR signature; bytes 440-443 */ static int find_disk(uint32_t mbr_sig) { int drive; bool is_me; - struct mbr *mbr; + struct disk_dos_mbr *mbr; for (drive = 0x80; drive <= 0xff; drive++) { if (disk_get_params(drive, &diskinfo)) @@ -229,14 +219,14 @@ static struct disk_part_iter *next_ebr_part(struct disk_part_iter *part) { const struct disk_dos_part_entry *ebr_table; const struct disk_dos_part_entry *parent_table = - ((const struct mbr *)part->private.ebr.parent->block)->table; + ((const struct disk_dos_mbr *)part->private.ebr.parent->block)->table; static const struct disk_dos_part_entry phony = {.start_lba = 0 }; uint64_t ebr_lba; /* Don't look for a "next EBR" the first time around */ if (part->private.ebr.parent_index >= 0) /* Look at the linked list */ - ebr_table = ((const struct mbr *)part->block)->table + 1; + ebr_table = ((const struct disk_dos_mbr *)part->block)->table + 1; /* Do we need to look for an extended partition? */ if (part->private.ebr.parent_index < 0 || !ebr_table->start_lba) { /* Start looking for an extended partition in the MBR */ @@ -261,7 +251,7 @@ static struct disk_part_iter *next_ebr_part(struct disk_part_iter *part) error("Could not load EBR!\n"); goto err_ebr; } - ebr_table = ((const struct mbr *)part->block)->table; + ebr_table = ((const struct disk_dos_mbr *)part->block)->table; dprintf("next_ebr_part:\n"); disk_dos_part_dump(ebr_table); @@ -271,8 +261,8 @@ static struct disk_part_iter *next_ebr_part(struct disk_part_iter *part) * put crap in some entries. */ { - const struct mbr *mbr = - (const struct mbr *)part->private.ebr.parent->block; + const struct disk_dos_mbr *mbr = + (const struct disk_dos_mbr *)part->private.ebr.parent->block; const struct disk_dos_part_entry *extended = mbr->table + part->private.ebr.parent_index; @@ -306,7 +296,8 @@ static struct disk_part_iter *next_mbr_part(struct disk_part_iter *part) { struct disk_part_iter *ebr_part; /* Look at the partition table */ - struct disk_dos_part_entry *table = ((struct mbr *)part->block)->table; + struct disk_dos_part_entry *table = + ((struct disk_dos_mbr *)part->block)->table; /* Look for data partitions */ while (++part->private.mbr_index < 4) { @@ -622,7 +613,7 @@ static struct disk_part_iter *get_first_partition(struct disk_part_iter *part) goto err_read_mbr; } /* Check for an MBR */ - if (((struct mbr *)part->block)->sig != mbr_sig_magic) { + if (((struct disk_dos_mbr *)part->block)->sig != disk_mbr_sig_magic) { error("No MBR magic!\n"); goto err_mbr; } @@ -909,7 +900,7 @@ enomem: return; } -static int hide_unhide(struct mbr *mbr, int part) +static int hide_unhide(struct disk_dos_mbr *mbr, int part) { int i; struct disk_dos_part_entry *pt; @@ -1016,7 +1007,7 @@ See syslinux/com32/modules/chain.c for more information\n"; int main(int argc, char *argv[]) { - struct mbr *mbr = NULL; + struct disk_dos_mbr *mbr = NULL; char *p; struct disk_part_iter *cur_part = NULL; struct syslinux_rm_regs regs; @@ -1436,10 +1427,11 @@ int main(int argc, char *argv[]) data[ndata].base = load_base; if (!opt.loadfile) { - const struct mbr *br = - (const struct mbr *)((char *)data[ndata].data + - data[ndata].size - sizeof(struct mbr)); - if (br->sig != mbr_sig_magic) { + const struct disk_dos_mbr *br = + (const struct disk_dos_mbr *)((char *)data[ndata].data + + data[ndata].size - + sizeof(struct disk_dos_mbr)); + if (br->sig != disk_mbr_sig_magic) { error ("Boot sector signature not found (unbootable disk/partition?)\n"); goto bail; -- cgit v1.2.1 From c7d09b7143ec4e051033cfc19ab13257e0142655 Mon Sep 17 00:00:00 2001 From: Shao Miller Date: Mon, 28 Jun 2010 03:18:09 -0400 Subject: chain.c32, libcom32: Move struct guid Moving portions of chain.c32 into libcom32. There might be a better header for struct guid to belong to. Signed-off-by: Shao Miller --- com32/include/syslinux/disk.h | 14 ++++++++++++++ com32/modules/chain.c | 12 ------------ 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/com32/include/syslinux/disk.h b/com32/include/syslinux/disk.h index f96e8fe7..221b6a9b 100644 --- a/com32/include/syslinux/disk.h +++ b/com32/include/syslinux/disk.h @@ -88,6 +88,20 @@ struct disk_dos_mbr { } __attribute__ ((packed)); #define disk_mbr_sig_magic 0xAA55 +/** + * A GPT disk/partition GUID + * + * Be careful with endianness, you must adjust it yourself + * iff you are directly using the fourth data chunk. + * There might be a better header for this... + */ +struct guid { + uint32_t data1; + uint16_t data2; + uint16_t data3; + uint64_t data4; +} __attribute__ ((packed)); + extern int disk_int13_retry(const com32sys_t * inreg, com32sys_t * outreg); extern int disk_get_params(int disk, struct disk_info *const diskinfo); extern void *disk_read_sectors(const struct disk_info *const diskinfo, diff --git a/com32/modules/chain.c b/com32/modules/chain.c index 896727d1..1d3f7baf 100644 --- a/com32/modules/chain.c +++ b/com32/modules/chain.c @@ -348,18 +348,6 @@ err_alloc: return NULL; } -/* - * GUID - * Be careful with endianness, you must adjust it yourself - * iff you are directly using the fourth data chunk - */ -struct guid { - uint32_t data1; - uint16_t data2; - uint16_t data3; - uint64_t data4; -} __attribute__ ((packed)); - /* * This walk-map effectively reverses the little-endian * portions of the GUID in the output text -- cgit v1.2.1 From f1753d9c93e7237ccd8fe587fa3aa28290f11b4d Mon Sep 17 00:00:00 2001 From: Shao Miller Date: Mon, 28 Jun 2010 03:34:55 -0400 Subject: chain.c32, libcom32: Move guid_le_walk_map Moving portions of chain.c32 into libcom32. There might be a better header for guid_le_walk_map to belong to. Signed-off-by: Shao Miller --- com32/include/syslinux/disk.h | 13 +++++++++++++ com32/modules/chain.c | 12 ------------ 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/com32/include/syslinux/disk.h b/com32/include/syslinux/disk.h index 221b6a9b..af9bf7bf 100644 --- a/com32/include/syslinux/disk.h +++ b/com32/include/syslinux/disk.h @@ -102,6 +102,19 @@ struct guid { uint64_t data4; } __attribute__ ((packed)); +/** + * This walk-map effectively reverses the little-endian + * portions of a GPT disk/partition GUID for a string representation. + * There might be a better header for this... + */ +static const char guid_le_walk_map[] = { + 3, -1, -1, -1, 0, + 5, -1, 0, + 3, -1, 0, + 2, 1, 0, + 1, 1, 1, 1, 1, 1 +}; + extern int disk_int13_retry(const com32sys_t * inreg, com32sys_t * outreg); extern int disk_get_params(int disk, struct disk_info *const diskinfo); extern void *disk_read_sectors(const struct disk_info *const diskinfo, diff --git a/com32/modules/chain.c b/com32/modules/chain.c index 1d3f7baf..1b41ba22 100644 --- a/com32/modules/chain.c +++ b/com32/modules/chain.c @@ -348,18 +348,6 @@ err_alloc: return NULL; } - /* - * This walk-map effectively reverses the little-endian - * portions of the GUID in the output text - */ -static const char guid_le_walk_map[] = { - 3, -1, -1, -1, 0, - 5, -1, 0, - 3, -1, 0, - 2, 1, 0, - 1, 1, 1, 1, 1, 1 -}; - #if DEBUG /* * Fill a buffer with a textual GUID representation. -- cgit v1.2.1 From 26c148f40d3e07519bb772625038d6634e597443 Mon Sep 17 00:00:00 2001 From: Shao Miller Date: Mon, 28 Jun 2010 03:42:44 -0400 Subject: chain.c32, libcom32: Move struct gpt_part as disk_gpt_part_entry Moving portions of chain.c32 into libcom32. Signed-off-by: Shao Miller --- com32/include/syslinux/disk.h | 10 ++++++++++ com32/modules/chain.c | 27 +++++++++------------------ 2 files changed, 19 insertions(+), 18 deletions(-) diff --git a/com32/include/syslinux/disk.h b/com32/include/syslinux/disk.h index af9bf7bf..108a5685 100644 --- a/com32/include/syslinux/disk.h +++ b/com32/include/syslinux/disk.h @@ -115,6 +115,16 @@ static const char guid_le_walk_map[] = { 1, 1, 1, 1, 1, 1 }; +/* A GPT partition */ +struct disk_gpt_part_entry { + struct guid type; + struct guid uid; + uint64_t lba_first; + uint64_t lba_last; + uint64_t attribs; + char name[72]; +} __attribute__ ((packed)); + extern int disk_int13_retry(const com32sys_t * inreg, com32sys_t * outreg); extern int disk_get_params(int disk, struct disk_info *const diskinfo); extern void *disk_read_sectors(const struct disk_info *const diskinfo, diff --git a/com32/modules/chain.c b/com32/modules/chain.c index 1b41ba22..4f198e53 100644 --- a/com32/modules/chain.c +++ b/com32/modules/chain.c @@ -438,17 +438,7 @@ static int str_to_guid(const char *buf, struct guid *id) return 0; } -/* A GPT partition */ -struct gpt_part { - struct guid type; - struct guid uid; - uint64_t lba_first; - uint64_t lba_last; - uint64_t attribs; - char name[72]; -} __attribute__ ((packed)); - -static void gpt_part_dump(const struct gpt_part *gpt_part) +static void gpt_part_dump(const struct disk_gpt_part_entry *gpt_part) { #ifdef DEBUG unsigned int i; @@ -537,13 +527,13 @@ static void gpt_dump(const struct gpt *gpt) static struct disk_part_iter *next_gpt_part(struct disk_part_iter *part) { - const struct gpt_part *gpt_part = NULL; + const struct disk_gpt_part_entry *gpt_part = NULL; while (++part->private.gpt.index < part->private.gpt.parts) { gpt_part = - (const struct gpt_part *)(part->block + - (part->private.gpt.index * - part->private.gpt.size)); + (const struct disk_gpt_part_entry *)(part->block + + (part->private.gpt.index * + part->private.gpt.size)); if (!gpt_part->lba_first) continue; break; @@ -723,7 +713,7 @@ static int find_by_label(const char *label, struct disk_part_iter **boot_part) } /* Check for a matching partition */ while (boot_part[0]) { - char gpt_label[sizeof(((struct gpt_part *) NULL)->name)]; + char gpt_label[sizeof(((struct disk_gpt_part_entry *) NULL)->name)]; const char *gpt_label_scanner = boot_part[0]->private.gpt.part_label; int j = 0; @@ -1440,7 +1430,8 @@ int main(int argc, char *argv[]) /* Do GPT hand-over, if applicable (as per syslinux/doc/gpt.txt) */ struct disk_dos_part_entry *record; /* Look at the GPT partition */ - const struct gpt_part *gp = (const struct gpt_part *) + const struct disk_gpt_part_entry *gp = + (const struct disk_gpt_part_entry *) (cur_part->block + (cur_part->private.gpt.size * cur_part->private.gpt.index)); /* Note the partition length */ @@ -1486,7 +1477,7 @@ int main(int argc, char *argv[]) dprintf("GPT handover:\n"); disk_dos_part_dump(record); - gpt_part_dump((struct gpt_part *)(plen + 1)); + gpt_part_dump((struct disk_gpt_part_entry *)(plen + 1)); } else if (cur_part->record) { /* MBR handover protocol */ static struct disk_dos_part_entry handover_record; -- cgit v1.2.1 From 7e4a36355a113c181d298d679a552d95302fa58c Mon Sep 17 00:00:00 2001 From: Shao Miller Date: Mon, 28 Jun 2010 05:30:06 -0400 Subject: chain.c32, libcom32: Move guid_to_str() and str_to_guid() Moving portions of chain.c32 into libcom32. There might be a better header for these to belong to. Signed-off-by: Shao Miller --- com32/include/syslinux/disk.h | 15 +----- com32/lib/syslinux/disk.c | 117 ++++++++++++++++++++++++++++++++++++++++++ com32/modules/chain.c | 90 -------------------------------- 3 files changed, 119 insertions(+), 103 deletions(-) diff --git a/com32/include/syslinux/disk.h b/com32/include/syslinux/disk.h index 108a5685..a1d0aeed 100644 --- a/com32/include/syslinux/disk.h +++ b/com32/include/syslinux/disk.h @@ -102,19 +102,6 @@ struct guid { uint64_t data4; } __attribute__ ((packed)); -/** - * This walk-map effectively reverses the little-endian - * portions of a GPT disk/partition GUID for a string representation. - * There might be a better header for this... - */ -static const char guid_le_walk_map[] = { - 3, -1, -1, -1, 0, - 5, -1, 0, - 3, -1, 0, - 2, 1, 0, - 1, 1, 1, 1, 1, 1 -}; - /* A GPT partition */ struct disk_gpt_part_entry { struct guid type; @@ -134,5 +121,7 @@ extern int disk_write_sector(const struct disk_info *const diskinfo, extern int disk_write_verify_sector(const struct disk_info *const diskinfo, unsigned int lba, const void *buf); extern void disk_dos_part_dump(const struct disk_dos_part_entry *const part); +extern void guid_to_str(char *buf, const struct guid *const id); +extern int str_to_guid(const char *buf, struct guid *const id); #endif /* _SYSLINUX_DISK_H */ diff --git a/com32/lib/syslinux/disk.c b/com32/lib/syslinux/disk.c index b7022070..02a1d594 100644 --- a/com32/lib/syslinux/disk.c +++ b/com32/lib/syslinux/disk.c @@ -34,6 +34,7 @@ */ #include +#include #include #include #include @@ -323,3 +324,119 @@ void disk_dos_part_dump(const struct disk_dos_part_entry *const part) chs_sector(part->end), part->start_lba, part->start_lba, part->length, part->length); } + +/* Trivial error message output */ +static inline void error(const char *msg) +{ + fputs(msg, stderr); +} + +/** + * This walk-map effectively reverses the little-endian + * portions of a GPT disk/partition GUID for a string representation. + * There might be a better header for this... + */ +static const char guid_le_walk_map[] = { + 3, -1, -1, -1, 0, + 5, -1, 0, + 3, -1, 0, + 2, 1, 0, + 1, 1, 1, 1, 1, 1 +}; + +/** + * Fill a buffer with a textual GUID representation. + * + * @v buf Points to a minimum array of 37 chars + * @v id The GUID to represent as text + * + * The buffer must be >= char[37] and will be populated + * with an ASCII NUL C string terminator. + * Example: 11111111-2222-3333-4444-444444444444 + * Endian: LLLLLLLL-LLLL-LLLL-BBBB-BBBBBBBBBBBB + */ +void guid_to_str(char *buf, const struct guid *const id) +{ + unsigned int i = 0; + const char *walker = (const char *)id; + + while (i < sizeof(guid_le_walk_map)) { + walker += guid_le_walk_map[i]; + if (!guid_le_walk_map[i]) + *buf = '-'; + else { + *buf = ((*walker & 0xF0) >> 4) + '0'; + if (*buf > '9') + *buf += 'A' - '9' - 1; + buf++; + *buf = (*walker & 0x0F) + '0'; + if (*buf > '9') + *buf += 'A' - '9' - 1; + } + buf++; + i++; + } + *buf = 0; +} + +/** + * Create a GUID structure from a textual GUID representation. + * + * @v buf Points to a GUID string to parse + * @v id Points to a GUID to be populated + * @ret (int) Returns 0 upon success, -1 upon failure + * + * The input buffer must be >= 32 hexadecimal chars and be + * terminated with an ASCII NUL. Returns non-zero on failure. + * Example: 11111111-2222-3333-4444-444444444444 + * Endian: LLLLLLLL-LLLL-LLLL-BBBB-BBBBBBBBBBBB + */ +int str_to_guid(const char *buf, struct guid *const id) +{ + char guid_seq[sizeof(struct guid) * 2]; + unsigned int i = 0; + char *walker = (char *)id; + + while (*buf && i < sizeof(guid_seq)) { + switch (*buf) { + /* Skip these three characters */ + case '{': + case '}': + case '-': + break; + default: + /* Copy something useful to the temp. sequence */ + if ((*buf >= '0') && (*buf <= '9')) + guid_seq[i] = *buf - '0'; + else if ((*buf >= 'A') && (*buf <= 'F')) + guid_seq[i] = *buf - 'A' + 10; + else if ((*buf >= 'a') && (*buf <= 'f')) + guid_seq[i] = *buf - 'a' + 10; + else { + /* Or not */ + error("Illegal character in GUID!\n"); + return -1; + } + i++; + } + buf++; + } + /* Check for insufficient valid characters */ + if (i < sizeof(guid_seq)) { + error("Too few GUID characters!\n"); + return -1; + } + buf = guid_seq; + i = 0; + while (i < sizeof(guid_le_walk_map)) { + if (!guid_le_walk_map[i]) + i++; + walker += guid_le_walk_map[i]; + *walker = *buf << 4; + buf++; + *walker |= *buf; + buf++; + i++; + } + return 0; +} diff --git a/com32/modules/chain.c b/com32/modules/chain.c index 4f198e53..1134f9db 100644 --- a/com32/modules/chain.c +++ b/com32/modules/chain.c @@ -348,96 +348,6 @@ err_alloc: return NULL; } -#if DEBUG -/* - * Fill a buffer with a textual GUID representation. - * The buffer must be >= char[37] and will be populated - * with an ASCII NUL C string terminator. - * Example: 11111111-2222-3333-4444-444444444444 - * Endian: LLLLLLLL-LLLL-LLLL-BBBB-BBBBBBBBBBBB - */ -static void guid_to_str(char *buf, const struct guid *id) -{ - unsigned int i = 0; - const char *walker = (const char *)id; - - while (i < sizeof(guid_le_walk_map)) { - walker += guid_le_walk_map[i]; - if (!guid_le_walk_map[i]) - *buf = '-'; - else { - *buf = ((*walker & 0xF0) >> 4) + '0'; - if (*buf > '9') - *buf += 'A' - '9' - 1; - buf++; - *buf = (*walker & 0x0F) + '0'; - if (*buf > '9') - *buf += 'A' - '9' - 1; - } - buf++; - i++; - } - *buf = 0; -} -#endif - -/* - * Create a GUID structure from a textual GUID representation. - * The input buffer must be >= 32 hexadecimal chars and be - * terminated with an ASCII NUL. Returns non-zero on failure. - * Example: 11111111-2222-3333-4444-444444444444 - * Endian: LLLLLLLL-LLLL-LLLL-BBBB-BBBBBBBBBBBB - */ -static int str_to_guid(const char *buf, struct guid *id) -{ - char guid_seq[sizeof(struct guid) * 2]; - unsigned int i = 0; - char *walker = (char *)id; - - while (*buf && i < sizeof(guid_seq)) { - switch (*buf) { - /* Skip these three characters */ - case '{': - case '}': - case '-': - break; - default: - /* Copy something useful to the temp. sequence */ - if ((*buf >= '0') && (*buf <= '9')) - guid_seq[i] = *buf - '0'; - else if ((*buf >= 'A') && (*buf <= 'F')) - guid_seq[i] = *buf - 'A' + 10; - else if ((*buf >= 'a') && (*buf <= 'f')) - guid_seq[i] = *buf - 'a' + 10; - else { - /* Or not */ - error("Illegal character in GUID!\n"); - return -1; - } - i++; - } - buf++; - } - /* Check for insufficient valid characters */ - if (i < sizeof(guid_seq)) { - error("Too few GUID characters!\n"); - return -1; - } - buf = guid_seq; - i = 0; - while (i < sizeof(guid_le_walk_map)) { - if (!guid_le_walk_map[i]) - i++; - walker += guid_le_walk_map[i]; - *walker = *buf << 4; - buf++; - *walker |= *buf; - buf++; - i++; - } - return 0; -} - static void gpt_part_dump(const struct disk_gpt_part_entry *gpt_part) { #ifdef DEBUG -- cgit v1.2.1 From 2cb2149a7c579ad8732053bd3391512daf253502 Mon Sep 17 00:00:00 2001 From: Shao Miller Date: Mon, 28 Jun 2010 06:07:04 -0400 Subject: chain.c32, libcom32: Move gpt_part_dump() as disk_gpt_part_dump() Moving portions of chain.c32 into libcom32. Signed-off-by: Shao Miller --- com32/include/syslinux/disk.h | 2 ++ com32/lib/syslinux/disk.c | 27 +++++++++++++++++++++++++++ com32/modules/chain.c | 33 ++++++--------------------------- 3 files changed, 35 insertions(+), 27 deletions(-) diff --git a/com32/include/syslinux/disk.h b/com32/include/syslinux/disk.h index a1d0aeed..7c4e276f 100644 --- a/com32/include/syslinux/disk.h +++ b/com32/include/syslinux/disk.h @@ -123,5 +123,7 @@ extern int disk_write_verify_sector(const struct disk_info *const diskinfo, extern void disk_dos_part_dump(const struct disk_dos_part_entry *const part); extern void guid_to_str(char *buf, const struct guid *const id); extern int str_to_guid(const char *buf, struct guid *const id); +extern void disk_gpt_part_dump(const struct disk_gpt_part_entry *const + gpt_part); #endif /* _SYSLINUX_DISK_H */ diff --git a/com32/lib/syslinux/disk.c b/com32/lib/syslinux/disk.c index 02a1d594..ef579d93 100644 --- a/com32/lib/syslinux/disk.c +++ b/com32/lib/syslinux/disk.c @@ -440,3 +440,30 @@ int str_to_guid(const char *buf, struct guid *const id) } return 0; } + +/** + * Display GPT partition details. + * + * @v gpt_part The GPT partition entry to display + */ +void disk_gpt_part_dump(const struct disk_gpt_part_entry *const gpt_part) +{ + unsigned int i; + char guid_text[37]; + + dprintf("----------------------------------\n" + "GPT part. LBA first __ : 0x%.16llx\n" + "GPT part. LBA last ___ : 0x%.16llx\n" + "GPT part. attribs ____ : 0x%.16llx\n" + "GPT part. name _______ : '", + gpt_part->lba_first, gpt_part->lba_last, gpt_part->attribs); + for (i = 0; i < sizeof(gpt_part->name); i++) { + if (gpt_part->name[i]) + dprintf("%c", gpt_part->name[i]); + } + dprintf("'"); + guid_to_str(guid_text, &gpt_part->type); + dprintf("GPT part. type GUID __ : {%s}\n", guid_text); + guid_to_str(guid_text, &gpt_part->uid); + dprintf("GPT part. unique ID __ : {%s}\n", guid_text); +} diff --git a/com32/modules/chain.c b/com32/modules/chain.c index 1134f9db..f69c9bd5 100644 --- a/com32/modules/chain.c +++ b/com32/modules/chain.c @@ -348,31 +348,6 @@ err_alloc: return NULL; } -static void gpt_part_dump(const struct disk_gpt_part_entry *gpt_part) -{ -#ifdef DEBUG - unsigned int i; - char guid_text[37]; - - dprintf("----------------------------------\n" - "GPT part. LBA first __ : 0x%.16llx\n" - "GPT part. LBA last ___ : 0x%.16llx\n" - "GPT part. attribs ____ : 0x%.16llx\n" - "GPT part. name _______ : '", - gpt_part->lba_first, gpt_part->lba_last, gpt_part->attribs); - for (i = 0; i < sizeof(gpt_part->name); i++) { - if (gpt_part->name[i]) - dprintf("%c", gpt_part->name[i]); - } - dprintf("'"); - guid_to_str(guid_text, &gpt_part->type); - dprintf("GPT part. type GUID __ : {%s}\n", guid_text); - guid_to_str(guid_text, &gpt_part->uid); - dprintf("GPT part. unique ID __ : {%s}\n", guid_text); -#endif - (void)gpt_part; -} - /* A GPT header */ struct gpt { char sig[8]; @@ -457,7 +432,9 @@ static struct disk_part_iter *next_gpt_part(struct disk_part_iter *part) part->private.gpt.part_label = gpt_part->name; /* Update our index */ part->index++; - gpt_part_dump(gpt_part); +#ifdef DEBUG + disk_gpt_part_dump(gpt_part); +#endif /* In a GPT scheme, we re-use the iterator */ return part; @@ -1387,7 +1364,9 @@ int main(int argc, char *argv[]) dprintf("GPT handover:\n"); disk_dos_part_dump(record); - gpt_part_dump((struct disk_gpt_part_entry *)(plen + 1)); +#ifdef DEBUG + disk_gpt_part_dump((struct disk_gpt_part_entry *)(plen + 1)); +#endif } else if (cur_part->record) { /* MBR handover protocol */ static struct disk_dos_part_entry handover_record; -- cgit v1.2.1 From a3e5be2ccec7c50e771f4807c8d3156c2c97330c Mon Sep 17 00:00:00 2001 From: Shao Miller Date: Mon, 28 Jun 2010 06:16:27 -0400 Subject: chain.c32, libcom32: Move struct gpt as disk_gpt_header Also moved gpt_sig_magic as disk_gpt_sig_magic. Moving portions of chain.c32 into libcom32. Signed-off-by: Shao Miller --- com32/include/syslinux/disk.h | 27 +++++++++++++++++++++++++++ com32/modules/chain.c | 41 ++++++++--------------------------------- 2 files changed, 35 insertions(+), 33 deletions(-) diff --git a/com32/include/syslinux/disk.h b/com32/include/syslinux/disk.h index 7c4e276f..37641d06 100644 --- a/com32/include/syslinux/disk.h +++ b/com32/include/syslinux/disk.h @@ -112,6 +112,33 @@ struct disk_gpt_part_entry { char name[72]; } __attribute__ ((packed)); +/* A GPT header */ +struct disk_gpt_header { + char sig[8]; + union { + struct { + uint16_t minor; + uint16_t major; + } fields __attribute__ ((packed)); + uint32_t uint32; + char raw[4]; + } rev __attribute__ ((packed)); + uint32_t hdr_size; + uint32_t chksum; + char reserved1[4]; + uint64_t lba_cur; + uint64_t lba_alt; + uint64_t lba_first_usable; + uint64_t lba_last_usable; + struct guid disk_guid; + uint64_t lba_table; + uint32_t part_count; + uint32_t part_size; + uint32_t table_chksum; + char reserved2[1]; +} __attribute__ ((packed)); +static const char disk_gpt_sig_magic[] = "EFI PART"; + extern int disk_int13_retry(const com32sys_t * inreg, com32sys_t * outreg); extern int disk_get_params(int disk, struct disk_info *const diskinfo); extern void *disk_read_sectors(const struct disk_info *const diskinfo, diff --git a/com32/modules/chain.c b/com32/modules/chain.c index f69c9bd5..a703ea09 100644 --- a/com32/modules/chain.c +++ b/com32/modules/chain.c @@ -348,35 +348,8 @@ err_alloc: return NULL; } -/* A GPT header */ -struct gpt { - char sig[8]; - union { - struct { - uint16_t minor; - uint16_t major; - } fields __attribute__ ((packed)); - uint32_t uint32; - char raw[4]; - } rev __attribute__ ((packed)); - uint32_t hdr_size; - uint32_t chksum; - char reserved1[4]; - uint64_t lba_cur; - uint64_t lba_alt; - uint64_t lba_first_usable; - uint64_t lba_last_usable; - struct guid disk_guid; - uint64_t lba_table; - uint32_t part_count; - uint32_t part_size; - uint32_t table_chksum; - char reserved2[1]; -} __attribute__ ((packed)); -static const char gpt_sig_magic[] = "EFI PART"; - #if DEBUG -static void gpt_dump(const struct gpt *gpt) +static void gpt_dump(const struct disk_gpt_header *gpt) { char guid_text[37]; @@ -448,7 +421,7 @@ err_last: static struct disk_part_iter *get_first_partition(struct disk_part_iter *part) { - const struct gpt *gpt_candidate; + const struct disk_gpt_header *gpt_candidate; /* * Ignore any passed partition iterator. The caller should @@ -476,8 +449,9 @@ static struct disk_part_iter *get_first_partition(struct disk_part_iter *part) part->private.mbr_index = -1; part->next = next_mbr_part; /* Check for a GPT disk */ - gpt_candidate = (const struct gpt *)(part->block + SECTOR); - if (!memcmp(gpt_candidate->sig, gpt_sig_magic, sizeof(gpt_sig_magic))) { + gpt_candidate = (const struct disk_gpt_header *)(part->block + SECTOR); + if (!memcmp + (gpt_candidate->sig, disk_gpt_sig_magic, sizeof(disk_gpt_sig_magic))) { /* LBA for partition table */ uint64_t lba_table; @@ -537,14 +511,15 @@ static int find_by_guid(const struct guid *gpt_guid, { int drive; bool is_me; - struct gpt *header; + struct disk_gpt_header *header; for (drive = 0x80; drive <= 0xff; drive++) { if (disk_get_params(drive, &diskinfo)) continue; /* Drive doesn't exist */ if (!(header = disk_read_sectors(&diskinfo, 1, 1))) continue; /* Cannot read sector */ - if (memcmp(&header->sig, gpt_sig_magic, sizeof(gpt_sig_magic))) { + if (memcmp + (&header->sig, disk_gpt_sig_magic, sizeof(disk_gpt_sig_magic))) { /* Not a GPT disk */ free(header); continue; -- cgit v1.2.1 From f4f4e91cc75d6f5e9b127c34b7f1829c36518455 Mon Sep 17 00:00:00 2001 From: Shao Miller Date: Mon, 28 Jun 2010 06:21:21 -0400 Subject: chain.c32, libcom32: Move gpt_dump() as disk_gpt_header_dump() Moving portions of chain.c32 into libcom32. Signed-off-by: Shao Miller --- com32/include/syslinux/disk.h | 1 + com32/lib/syslinux/disk.c | 38 ++++++++++++++++++++++++++++++++++++++ com32/modules/chain.c | 39 ++------------------------------------- 3 files changed, 41 insertions(+), 37 deletions(-) diff --git a/com32/include/syslinux/disk.h b/com32/include/syslinux/disk.h index 37641d06..ff805325 100644 --- a/com32/include/syslinux/disk.h +++ b/com32/include/syslinux/disk.h @@ -152,5 +152,6 @@ extern void guid_to_str(char *buf, const struct guid *const id); extern int str_to_guid(const char *buf, struct guid *const id); extern void disk_gpt_part_dump(const struct disk_gpt_part_entry *const gpt_part); +extern void disk_gpt_header_dump(const struct disk_gpt_header *const gpt); #endif /* _SYSLINUX_DISK_H */ diff --git a/com32/lib/syslinux/disk.c b/com32/lib/syslinux/disk.c index ef579d93..678e4bd2 100644 --- a/com32/lib/syslinux/disk.c +++ b/com32/lib/syslinux/disk.c @@ -467,3 +467,41 @@ void disk_gpt_part_dump(const struct disk_gpt_part_entry *const gpt_part) guid_to_str(guid_text, &gpt_part->uid); dprintf("GPT part. unique ID __ : {%s}\n", guid_text); } + +/** + * Display GPT header details. + * + * @v gpt The GPT header to display + */ +void disk_gpt_header_dump(const struct disk_gpt_header *const gpt) +{ + char guid_text[37]; + + printf("GPT sig ______________ : '%8.8s'\n" + "GPT major revision ___ : 0x%.4x\n" + "GPT minor revision ___ : 0x%.4x\n" + "GPT header size ______ : 0x%.8x\n" + "GPT header checksum __ : 0x%.8x\n" + "GPT reserved _________ : '%4.4s'\n" + "GPT LBA current ______ : 0x%.16llx\n" + "GPT LBA alternative __ : 0x%.16llx\n" + "GPT LBA first usable _ : 0x%.16llx\n" + "GPT LBA last usable __ : 0x%.16llx\n" + "GPT LBA part. table __ : 0x%.16llx\n" + "GPT partition count __ : 0x%.8x\n" + "GPT partition size ___ : 0x%.8x\n" + "GPT part. table chksum : 0x%.8x\n", + gpt->sig, + gpt->rev.fields.major, + gpt->rev.fields.minor, + gpt->hdr_size, + gpt->chksum, + gpt->reserved1, + gpt->lba_cur, + gpt->lba_alt, + gpt->lba_first_usable, + gpt->lba_last_usable, + gpt->lba_table, gpt->part_count, gpt->part_size, gpt->table_chksum); + guid_to_str(guid_text, &gpt->disk_guid); + printf("GPT disk GUID ________ : {%s}\n", guid_text); +} diff --git a/com32/modules/chain.c b/com32/modules/chain.c index a703ea09..5078ed3c 100644 --- a/com32/modules/chain.c +++ b/com32/modules/chain.c @@ -348,41 +348,6 @@ err_alloc: return NULL; } -#if DEBUG -static void gpt_dump(const struct disk_gpt_header *gpt) -{ - char guid_text[37]; - - printf("GPT sig ______________ : '%8.8s'\n" - "GPT major revision ___ : 0x%.4x\n" - "GPT minor revision ___ : 0x%.4x\n" - "GPT header size ______ : 0x%.8x\n" - "GPT header checksum __ : 0x%.8x\n" - "GPT reserved _________ : '%4.4s'\n" - "GPT LBA current ______ : 0x%.16llx\n" - "GPT LBA alternative __ : 0x%.16llx\n" - "GPT LBA first usable _ : 0x%.16llx\n" - "GPT LBA last usable __ : 0x%.16llx\n" - "GPT LBA part. table __ : 0x%.16llx\n" - "GPT partition count __ : 0x%.8x\n" - "GPT partition size ___ : 0x%.8x\n" - "GPT part. table chksum : 0x%.8x\n", - gpt->sig, - gpt->rev.fields.major, - gpt->rev.fields.minor, - gpt->hdr_size, - gpt->chksum, - gpt->reserved1, - gpt->lba_cur, - gpt->lba_alt, - gpt->lba_first_usable, - gpt->lba_last_usable, - gpt->lba_table, gpt->part_count, gpt->part_size, gpt->table_chksum); - guid_to_str(guid_text, &gpt->disk_guid); - printf("GPT disk GUID ________ : {%s}\n", guid_text); -} -#endif - static struct disk_part_iter *next_gpt_part(struct disk_part_iter *part) { const struct disk_gpt_part_entry *gpt_part = NULL; @@ -459,7 +424,7 @@ static struct disk_part_iter *get_first_partition(struct disk_part_iter *part) /* TODO: Check checksum. Possibly try alternative GPT */ #if DEBUG puts("Looks like a GPT disk."); - gpt_dump(gpt_candidate); + disk_gpt_header_dump(gpt_candidate); #endif /* TODO: Check table checksum (maybe) */ /* Note relevant GPT details */ @@ -525,7 +490,7 @@ static int find_by_guid(const struct guid *gpt_guid, continue; } #if DEBUG - gpt_dump(header); + disk_gpt_header_dump(header); #endif is_me = !memcmp(&header->disk_guid, &gpt_guid, sizeof(*gpt_guid)); free(header); -- cgit v1.2.1 From 8afab2175c3df81fdc532930585003c712a219f1 Mon Sep 17 00:00:00 2001 From: Michal Soltys Date: Fri, 30 Jul 2010 08:46:06 +0200 Subject: chain.c: fix public index value in mbr and gpt iterators mbr and gpt iterators skip empty / non-data partitions properly, but don't update publicly visible index. With this patch, such partitions are counted as well. Signed-off-by: Michal Soltys Signed-off-by: H. Peter Anvin --- com32/modules/chain.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/com32/modules/chain.c b/com32/modules/chain.c index 5078ed3c..60e3abce 100644 --- a/com32/modules/chain.c +++ b/com32/modules/chain.c @@ -335,8 +335,8 @@ static struct disk_part_iter *next_mbr_part(struct disk_part_iter *part) /* Update parameters to reflect this new partition. Re-use iterator */ part->lba_data = table[part->private.mbr_index].start_lba; - dprintf("Partition %d primary lba %u\n", part->index, part->lba_data); - part->index++; + dprintf("Partition %d primary lba %u\n", part->private.mbr_index, part->lba_data); + part->index = part->private.mbr_index + 1; part->record = table + part->private.mbr_index; return part; @@ -369,7 +369,7 @@ static struct disk_part_iter *next_gpt_part(struct disk_part_iter *part) part->private.gpt.part_guid = &gpt_part->uid; part->private.gpt.part_label = gpt_part->name; /* Update our index */ - part->index++; + part->index = part->private.gpt.index + 1; #ifdef DEBUG disk_gpt_part_dump(gpt_part); #endif -- cgit v1.2.1 From e1eb61603d686c7518a590b167fac5a94063acda Mon Sep 17 00:00:00 2001 From: Michal Soltys Date: Sun, 8 Aug 2010 01:13:48 +0200 Subject: split chain into chain + iterator, expand iterators' code Patch: - splits chain into chain and iterator parts and moves them into their own com32/chain directory - extensively updates iterators' code - adjusts chain.c to use new iterators - fixes mbr/sect/hand/file allocation Signed-off-by: Michal Soltys --- Makefile | 2 +- com32/Makefile | 2 +- com32/chain/Makefile | 39 ++ com32/chain/chain.c | 1066 +++++++++++++++++++++++++++++++++++++ com32/chain/partiter.c | 714 +++++++++++++++++++++++++ com32/chain/partiter.h | 94 ++++ com32/modules/Makefile | 2 +- com32/modules/chain.c | 1364 ------------------------------------------------ 8 files changed, 1916 insertions(+), 1367 deletions(-) create mode 100644 com32/chain/Makefile create mode 100644 com32/chain/chain.c create mode 100644 com32/chain/partiter.c create mode 100644 com32/chain/partiter.h delete mode 100644 com32/modules/chain.c diff --git a/Makefile b/Makefile index da90cdc4..9ab401b6 100644 --- a/Makefile +++ b/Makefile @@ -33,7 +33,7 @@ include $(topdir)/MCONFIG MODULES = memdisk/memdisk memdump/memdump.com modules/*.com \ com32/menu/*.c32 com32/modules/*.c32 com32/mboot/*.c32 \ com32/hdt/*.c32 com32/rosh/*.c32 com32/gfxboot/*.c32 \ - com32/sysdump/*.c32 com32/lua/src/*.c32 + com32/sysdump/*.c32 com32/lua/src/*.c32 com32/chain/*.c32 # syslinux.exe is BTARGET so as to not require everyone to have the # mingw suite installed diff --git a/com32/Makefile b/com32/Makefile index b090c403..43847bd4 100644 --- a/com32/Makefile +++ b/com32/Makefile @@ -1,5 +1,5 @@ SUBDIRS = tools lib gpllib libutil modules mboot menu samples rosh cmenu \ - hdt gfxboot sysdump lua/src + hdt gfxboot sysdump lua/src chain all tidy dist clean spotless install: set -e; for d in $(SUBDIRS); do $(MAKE) -C $$d $@; done diff --git a/com32/chain/Makefile b/com32/chain/Makefile new file mode 100644 index 00000000..16086ba2 --- /dev/null +++ b/com32/chain/Makefile @@ -0,0 +1,39 @@ +## ----------------------------------------------------------------------- +## +## Copyright 2001-2010 H. Peter Anvin - All Rights Reserved +## Copyright 2010 Michal Soltys +## +## This program is free software; you can redistribute it and/or modify +## it under the terms of the GNU General Public License as published by +## the Free Software Foundation, Inc., 53 Temple Place Ste 330, +## Boston MA 02111-1307, USA; either version 2 of the License, or +## (at your option) any later version; incorporated herein by reference. +## +## ----------------------------------------------------------------------- + + +topdir = ../.. +include ../MCONFIG + +OBJS = chain.o partiter.o +#GCCWARN += -Wextra -Wconversion -pedantic -Wno-error + +all: chain.c32 + +chain.elf: $(OBJS) $(LIBS) $(C_LIBS) + $(LD) $(LDFLAGS) -o $@ $^ + +tidy dist: + rm -f *.o *.lo *.a *.lst *.elf .*.d *.tmp + +clean: tidy + rm -f *.lnx + +spotless: clean + rm -f *.lss *.c32 *.com + rm -f *~ \#* + +install: + + +-include .*.d diff --git a/com32/chain/chain.c b/com32/chain/chain.c new file mode 100644 index 00000000..3bd5548c --- /dev/null +++ b/com32/chain/chain.c @@ -0,0 +1,1066 @@ +/* ----------------------------------------------------------------------- * + * + * Copyright 2003-2009 H. Peter Anvin - All Rights Reserved + * Copyright 2009-2010 Intel Corporation; author: H. Peter Anvin + * Significant portions copyright (C) 2010 Shao Miller + * [partition iteration, GPT, "fs"] + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, Inc., 53 Temple Place Ste 330, + * Boston MA 02111-1307, USA; either version 2 of the License, or + * (at your option) any later version; incorporated herein by reference. + * + * ----------------------------------------------------------------------- */ + +/* + * chain.c + * + * Chainload a hard disk (currently rather braindead.) + * + * Usage: chain [options] + * chain hd [] [options] + * chain fd [options] + * chain mbr: [] [options] + * chain guid: [] [options] + * chain label: