This is a bit updated set of chain.c32 changes that simplifies a few things (and in partiter part), fixes few minor issues and adds a few new features. Details are in the following commits, below is the summary and pull details at the end. Shao - any chance to peek over them ? Most of those are relatively simple changes and well tested, though of course something might have slipped my attention. Summary of the more important changes: - partiter simplifications and updates Following brief off-list discussion - this simplifies overkill generalizations, so the code should be easier to follow and modify. - add relax flag Relax option tones down sanity checks which can help with broken layouts and disk sizes reported differently between machines - tolerate and handle hybrid GPT+MBR layouts, add prefmbr flag This recognizes disks with both layouts at the same time, and introduces 'prefmbr' flag to force the use of MBR layout in case GPT is present. - recognize exFAT This makes chain exFAT aware by adding yet another "BPB" variation with the usual stuff (partition offset - now 64bit, drive). - com32/chain: manglepe_fixchs() correction Previously fixchs also included start/length 0/0 entries (holes), so this patch makes it a bit more careful. - use disk_guid for part_guid for 0th partition (under GPT layouts) - partiter: make sure 'index' is (-1) also for empty primary partitions The following changes since commit 7307d60063ee4303da4de45f9d984fdc8df92146: memdisk: Fix order of sectors/track and bytes/sector (2012-10-23 10:53:17 +0100) are available in the git repository at: git://git.hasevolq.net/syslinux.git chain_update for you to fetch changes up to 55f9ae015ae44a5687c80a1d95f822bc48206bec: com32/chain: use single value for partiter related options (flags) (2012-11-06 00:42:34 +0100) ---------------------------------------------------------------- Michal Soltys (23): com32/chain: update licenses com32/chain: comments, minor adjustments com32/chain: use anonymous and unnamed aggregates com32/chain: change stepall into flags com32/chain: shuffle code before partiter simplifications com32/chain: partiter - simplifications and updates com32/chain: remove redundant rawindex com32/chain: partiter - more precise comments / output com32/chain: remove unused ebr_start com32/chain: add pi_errored() in partiter com32/chain: mangle and related updates com32/chain: cleaner variable names com32/chain: use disk_guid for part_guid for 0th partition com32/chain: warning/error/help/doc tidying com32/chain: implement relax flag com32/chain: implement handling of non-standard hybrid GPT+MBR layouts com32/chain: recognize exFAT com32/chain: remove common.h com32/chain: rely more on addr_t, replace ADDR* com32/chain: index -1 partiter adjustment com32/chain: manglepe_fixchs() correction com32/chain: partiter: rename start_lba com32/chain: use single value for partiter related options (flags) com32/chain/Makefile | 6 +- com32/chain/chain.c | 139 ++++++----- com32/chain/chain.h | 15 ++ com32/chain/common.h | 9 - com32/chain/mangle.c | 207 +++++++++++------ com32/chain/mangle.h | 30 +++ com32/chain/options.c | 228 ++++++++++-------- com32/chain/options.h | 48 +++- com32/chain/partiter.c | 608 ++++++++++++++++++------------------------------ com32/chain/partiter.h | 85 ++++--- com32/chain/utility.c | 85 +++++-- com32/chain/utility.h | 67 +++++- doc/chain.txt | 41 ++-- 13 files changed, 861 insertions(+), 707 deletions(-) delete mode 100644 com32/chain/common.h -- 1.7.10.4
chain.[ch] Makefile: GPLv2+ the rest: MIT Signed-off-by: Michal Soltys <soltys at ziu.info> --- com32/chain/Makefile | 6 ++++-- com32/chain/chain.c | 2 +- com32/chain/chain.h | 15 +++++++++++++++ com32/chain/common.h | 30 ++++++++++++++++++++++++++++++ com32/chain/mangle.c | 30 ++++++++++++++++++++++++++++++ com32/chain/mangle.h | 30 ++++++++++++++++++++++++++++++ com32/chain/options.c | 30 ++++++++++++++++++++++++++++++ com32/chain/options.h | 30 ++++++++++++++++++++++++++++++ com32/chain/partiter.c | 5 +++-- com32/chain/partiter.h | 5 +++-- com32/chain/utility.c | 30 ++++++++++++++++++++++++++++++ com32/chain/utility.h | 30 ++++++++++++++++++++++++++++++ 12 files changed, 236 insertions(+), 7 deletions(-) diff --git a/com32/chain/Makefile b/com32/chain/Makefile index 9d398a8..ef0929e 100644 --- a/com32/chain/Makefile +++ b/com32/chain/Makefile @@ -1,7 +1,9 @@ ## ----------------------------------------------------------------------- ## -## Copyright 2001-2010 H. Peter Anvin - All Rights Reserved -## Copyright 2010 Michal Soltys +## Copyright 2003-2009 H. Peter Anvin - All Rights Reserved +## Copyright 2009-2010 Intel Corporation; author: H. Peter Anvin +## Copyright 2010 Shao Miller +## Copyright 2010-2012 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 diff --git a/com32/chain/chain.c b/com32/chain/chain.c index 30153c4..f0ccd97 100644 --- a/com32/chain/chain.c +++ b/com32/chain/chain.c @@ -3,7 +3,7 @@ * Copyright 2003-2009 H. Peter Anvin - All Rights Reserved * Copyright 2009-2010 Intel Corporation; author: H. Peter Anvin * Copyright 2010 Shao Miller - * Copyright 2010 Michal Soltys + * Copyright 2010-2012 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 diff --git a/com32/chain/chain.h b/com32/chain/chain.h index fc481bc..1d08b0e 100644 --- a/com32/chain/chain.h +++ b/com32/chain/chain.h @@ -1,3 +1,18 @@ +/* ----------------------------------------------------------------------- * + * + * Copyright 2003-2009 H. Peter Anvin - All Rights Reserved + * Copyright 2009-2010 Intel Corporation; author: H. Peter Anvin + * Copyright 2010 Shao Miller + * Copyright 2010-2012 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. + * + * ----------------------------------------------------------------------- */ + #ifndef _COM32_CHAIN_CHAIN_H #define _COM32_CHAIN_CHAIN_H diff --git a/com32/chain/common.h b/com32/chain/common.h index b170a73..8437bc4 100644 --- a/com32/chain/common.h +++ b/com32/chain/common.h @@ -1,3 +1,33 @@ +/* ----------------------------------------------------------------------- * + * + * Copyright 2003-2009 H. Peter Anvin - All Rights Reserved + * Copyright 2009-2010 Intel Corporation; author: H. Peter Anvin + * Copyright 2010 Shao Miller + * Copyright 2010-2012 Michal Soltys + * + * 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. + * + * ----------------------------------------------------------------------- */ + #ifndef _COM32_CHAIN_COMMON_H #define _COM32_CHAIN_COMMON_H diff --git a/com32/chain/mangle.c b/com32/chain/mangle.c index 8358106..e3c494c 100644 --- a/com32/chain/mangle.c +++ b/com32/chain/mangle.c @@ -1,3 +1,33 @@ +/* ----------------------------------------------------------------------- * + * + * Copyright 2003-2009 H. Peter Anvin - All Rights Reserved + * Copyright 2009-2010 Intel Corporation; author: H. Peter Anvin + * Copyright 2010 Shao Miller + * Copyright 2010-2012 Michal Soltys + * + * 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. + * + * ----------------------------------------------------------------------- */ + #include <com32.h> #include <stdlib.h> #include <stdio.h> diff --git a/com32/chain/mangle.h b/com32/chain/mangle.h index bcefea3..5b1ed5a 100644 --- a/com32/chain/mangle.h +++ b/com32/chain/mangle.h @@ -1,3 +1,33 @@ +/* ----------------------------------------------------------------------- * + * + * Copyright 2003-2009 H. Peter Anvin - All Rights Reserved + * Copyright 2009-2010 Intel Corporation; author: H. Peter Anvin + * Copyright 2010 Shao Miller + * Copyright 2010-2012 Michal Soltys + * + * 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. + * + * ----------------------------------------------------------------------- */ + #ifndef _COM32_CHAIN_MANGLE_H #define _COM32_CHAIN_MANGLE_H diff --git a/com32/chain/options.c b/com32/chain/options.c index 658a45c..5f7433d 100644 --- a/com32/chain/options.c +++ b/com32/chain/options.c @@ -1,3 +1,33 @@ +/* ----------------------------------------------------------------------- * + * + * Copyright 2003-2009 H. Peter Anvin - All Rights Reserved + * Copyright 2009-2010 Intel Corporation; author: H. Peter Anvin + * Copyright 2010 Shao Miller + * Copyright 2010-2012 Michal Soltys + * + * 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. + * + * ----------------------------------------------------------------------- */ + #include <stdint.h> #include <stdlib.h> #include <string.h> diff --git a/com32/chain/options.h b/com32/chain/options.h index 4493ef1..083713b 100644 --- a/com32/chain/options.h +++ b/com32/chain/options.h @@ -1,3 +1,33 @@ +/* ----------------------------------------------------------------------- * + * + * Copyright 2003-2009 H. Peter Anvin - All Rights Reserved + * Copyright 2009-2010 Intel Corporation; author: H. Peter Anvin + * Copyright 2010 Shao Miller + * Copyright 2010-2012 Michal Soltys + * + * 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. + * + * ----------------------------------------------------------------------- */ + #ifndef _COM32_CHAIN_OPTIONS_H #define _COM32_CHAIN_OPTIONS_H diff --git a/com32/chain/partiter.c b/com32/chain/partiter.c index 1acd195..7a6006b 100644 --- a/com32/chain/partiter.c +++ b/com32/chain/partiter.c @@ -1,8 +1,9 @@ /* ----------------------------------------------------------------------- * * - * Copyright 2003-2010 H. Peter Anvin - All Rights Reserved + * Copyright 2003-2009 H. Peter Anvin - All Rights Reserved + * Copyright 2009-2010 Intel Corporation; author: H. Peter Anvin * Copyright 2010 Shao Miller - * Copyright 2010 Michal Soltys + * Copyright 2010-2012 Michal Soltys * * Permission is hereby granted, free of charge, to any person * obtaining a copy of this software and associated documentation diff --git a/com32/chain/partiter.h b/com32/chain/partiter.h index 7deeb53..e03fbbc 100644 --- a/com32/chain/partiter.h +++ b/com32/chain/partiter.h @@ -1,8 +1,9 @@ /* ----------------------------------------------------------------------- * * - * Copyright 2003-2010 H. Peter Anvin - All Rights Reserved - * Copyright 2010 Michal Soltys + * Copyright 2003-2009 H. Peter Anvin - All Rights Reserved + * Copyright 2009-2010 Intel Corporation; author: H. Peter Anvin * Copyright 2010 Shao Miller + * Copyright 2010-2012 Michal Soltys * * Permission is hereby granted, free of charge, to any person * obtaining a copy of this software and associated documentation diff --git a/com32/chain/utility.c b/com32/chain/utility.c index fb59551..bc5b81a 100644 --- a/com32/chain/utility.c +++ b/com32/chain/utility.c @@ -1,3 +1,33 @@ +/* ----------------------------------------------------------------------- * + * + * Copyright 2003-2009 H. Peter Anvin - All Rights Reserved + * Copyright 2009-2010 Intel Corporation; author: H. Peter Anvin + * Copyright 2010 Shao Miller + * Copyright 2010-2012 Michal Soltys + * + * 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. + * + * ----------------------------------------------------------------------- */ + #include <com32.h> #include <stdint.h> #include <stdio.h> diff --git a/com32/chain/utility.h b/com32/chain/utility.h index 8a08be7..8b49122 100644 --- a/com32/chain/utility.h +++ b/com32/chain/utility.h @@ -1,3 +1,33 @@ +/* ----------------------------------------------------------------------- * + * + * Copyright 2003-2009 H. Peter Anvin - All Rights Reserved + * Copyright 2009-2010 Intel Corporation; author: H. Peter Anvin + * Copyright 2010 Shao Miller + * Copyright 2010-2012 Michal Soltys + * + * 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. + * + * ----------------------------------------------------------------------- */ + #ifndef _COM32_CHAIN_UTILITY_H #define _COM32_CHAIN_UTILITY_H -- 1.7.10.4
Michal Soltys
2012-Nov-06 00:32 UTC
[syslinux] [PATCH 02/23] com32/chain: comments, minor adjustments
- add some comments to clarify c{nul,add,max} modes - resilient against -Wconversion (uint8_t casts) - minor handover comment/flow changes - clean up some old comment-outs Signed-off-by: Michal Soltys <soltys at ziu.info> --- com32/chain/chain.c | 12 +++++++----- com32/chain/options.c | 16 +--------------- com32/chain/utility.c | 37 ++++++++++++++++++++----------------- com32/chain/utility.h | 19 ++++++++++++++++--- 4 files changed, 44 insertions(+), 40 deletions(-) diff --git a/com32/chain/chain.c b/com32/chain/chain.c index f0ccd97..060043c 100644 --- a/com32/chain/chain.c +++ b/com32/chain/chain.c @@ -404,7 +404,11 @@ static int setup_handover(const struct part_iter *iter, uint32_t synth_size; uint32_t *plen; - if (!iter->index) { /* implies typeraw or non-iterated */ + /* + * we have to cover both non-iterated but otherwise properly detected + * gpt/dos schemes as well as raw disks; checking index for 0 covers both + */ + if (iter->index == 0) { uint32_t len; /* RAW handover protocol */ synth_size = sizeof(struct disk_dos_part_entry); @@ -453,7 +457,8 @@ static int setup_handover(const struct part_iter *iter, disk_dos_part_dump(ha); disk_gpt_part_dump((struct disk_gpt_part_entry *)(plen + 1)); #endif - } else if (iter->type == typedos) { + /* the only possible case left is dos scheme */ + } else { /* MBR handover protocol */ synth_size = sizeof(struct disk_dos_part_entry); ha = malloc(synth_size); @@ -472,9 +477,6 @@ static int setup_handover(const struct part_iter *iter, dprintf("MBR handover:\n"); disk_dos_part_dump(ha); #endif - } else { - /* shouldn't ever happen */ - goto bail; } data->base = 0x7be; diff --git a/com32/chain/options.c b/com32/chain/options.c index 5f7433d..b831afa 100644 --- a/com32/chain/options.c +++ b/com32/chain/options.c @@ -166,7 +166,7 @@ void opt_set_defs(void) int opt_parse_args(int argc, char *argv[]) { int i; - unsigned int v; + size_t v; char *p; for (i = 1; i < argc; i++) { @@ -182,7 +182,6 @@ int opt_parse_args(int argc, char *argv[]) opt.bss = true; opt.maps = false; opt.setbpb = true; - /* opt.save = true; */ } else if (!strncmp(argv[i], "bs=", 3)) { opt.file = argv[i] + 3; opt.sect = false; @@ -198,7 +197,6 @@ int opt_parse_args(int argc, char *argv[]) opt.fip = 0; opt.file = argv[i] + 6; opt.setbpb = true; - /* opt.save = true; */ opt.hand = false; } else if (!strncmp(argv[i], "reactos=", 8)) { /* @@ -212,7 +210,6 @@ int opt_parse_args(int argc, char *argv[]) opt.fip = 0x8100; opt.file = argv[i] + 8; opt.setbpb = true; - /* opt.save = true; */ opt.hand = false; } else if (!strncmp(argv[i], "cmldr=", 6)) { opt.fseg = 0x2000; /* CMLDR wants this address */ @@ -221,7 +218,6 @@ int opt_parse_args(int argc, char *argv[]) opt.file = argv[i] + 6; opt.cmldr = true; opt.setbpb = true; - /* opt.save = true; */ opt.hand = false; } else if (!strncmp(argv[i], "freedos=", 8)) { opt.fseg = 0x60; /* FREEDOS wants this address */ @@ -230,7 +226,6 @@ int opt_parse_args(int argc, char *argv[]) opt.sseg = 0x1FE0; opt.file = argv[i] + 8; opt.setbpb = true; - /* opt.save = true; */ opt.hand = false; } else if ( (v = 6, !strncmp(argv[i], "msdos=", v) || !strncmp(argv[i], "pcdos=", v)) || @@ -241,7 +236,6 @@ int opt_parse_args(int argc, char *argv[]) opt.sseg = 0x8000; opt.file = argv[i] + v; opt.setbpb = true; - /* opt.save = true; */ opt.hand = false; } else if (!strncmp(argv[i], "drmk=", 5)) { opt.fseg = 0x70; /* DRMK wants this address */ @@ -253,7 +247,6 @@ int opt_parse_args(int argc, char *argv[]) opt.file = argv[i] + 5; /* opt.drmk = true; */ opt.setbpb = true; - /* opt.save = true; */ opt.hand = false; } else if (!strncmp(argv[i], "grub=", 5)) { opt.fseg = 0x800; /* stage2 wants this address */ @@ -371,13 +364,6 @@ int opt_parse_args(int argc, char *argv[]) goto bail; } -#if 0 - if ((!opt.maps || !opt.sect) && !opt.file) { - error("You have to load something.\n"); - goto bail; - } -#endif - if (opt.filebpb && !opt.file) { error("Option 'filebpb' requires a file.\n"); goto bail; diff --git a/com32/chain/utility.c b/com32/chain/utility.c index bc5b81a..d40c0dd 100644 --- a/com32/chain/utility.c +++ b/com32/chain/utility.c @@ -48,16 +48,6 @@ static const char *bpbtypes[] = { [7] = "7.0", }; -void error(const char *msg) -{ - fputs(msg, stderr); -} - -int guid_is0(const struct guid *guid) -{ - return !*(const uint64_t *)guid && !*((const uint64_t *)guid + 1); -} - void wait_key(void) { int cnt; @@ -76,7 +66,19 @@ void wait_key(void) } while (!cnt || (cnt < 0 && errno == EAGAIN)); } -void lba2chs(disk_chs *dst, const struct disk_info *di, uint64_t lba, uint32_t mode) +/* + * mode explanation: + * + * cnul - "strict" mode, never returning higher value than obtained from cbios + * cadd - if the disk is larger than reported geometry /and/ if the geometry has + * less cylinders than 1024 - it means that the total size is somewhere + * between cs and cs+1; in this particular case, we bump the cs to be able + * to return matching chs triplet + * cmax - assume we can use any cylinder value + * + * by default, lba2chs() calls use cadd + */ +void lba2chs(disk_chs *dst, const struct disk_info *di, uint64_t lba, int mode) { uint32_t c, h, s, t; uint32_t cs, hs, ss; @@ -89,9 +91,10 @@ void lba2chs(disk_chs *dst, const struct disk_info *di, uint64_t lba, uint32_t m cs = di->cyl; hs = di->head; ss = di->spt; - if (mode == l2c_cadd && cs < 1024 && di->lbacnt > cs*hs*ss) - cs++; - else if (mode == l2c_cmax) + if (mode == l2c_cadd) { + if (cs < 1024 && di->lbacnt > cs*hs*ss) + cs++; + } else if (mode == l2c_cmax) cs = 1024; } else { if (di->disk & 0x80) { @@ -116,9 +119,9 @@ void lba2chs(disk_chs *dst, const struct disk_info *di, uint64_t lba, uint32_t m c = t / hs; } - (*dst)[0] = h; - (*dst)[1] = s | ((c & 0x300) >> 2); - (*dst)[2] = c; + (*dst)[0] = (uint8_t)h; + (*dst)[1] = (uint8_t)(s | ((c & 0x300) >> 2)); + (*dst)[2] = (uint8_t)c; } uint32_t get_file_lba(const char *filename) diff --git a/com32/chain/utility.h b/com32/chain/utility.h index 8b49122..a0519b7 100644 --- a/com32/chain/utility.h +++ b/com32/chain/utility.h @@ -32,6 +32,7 @@ #define _COM32_CHAIN_UTILITY_H #include <stdint.h> +#include <stdio.h> #include <syslinux/disk.h> #define bpbUNK 0 @@ -43,18 +44,30 @@ #define bpbVNT 6 #define bpbV70 7 +/* see utility.c for details */ #define l2c_cnul 0 #define l2c_cadd 1 #define l2c_cmax 2 -void error(const char *msg); -int guid_is0(const struct guid *guid); void wait_key(void); -void lba2chs(disk_chs *dst, const struct disk_info *di, uint64_t lba, uint32_t mode); +void lba2chs(disk_chs *dst, const struct disk_info *di, uint64_t lba, int mode); uint32_t get_file_lba(const char *filename); int drvoff_detect(int type, unsigned int *off); int bpb_detect(const uint8_t *bpb, const char *tag); +static inline +void error(const char *msg) +{ + fputs(msg, stderr); +} + +static inline +int guid_is0(const struct guid *guid) +{ + return !*(const uint64_t *)guid && !*((const uint64_t *)guid + 1); +} + + #endif /* vim: set ts=8 sts=4 sw=4 noet: */ -- 1.7.10.4
Michal Soltys
2012-Nov-06 00:32 UTC
[syslinux] [PATCH 03/23] com32/chain: use anonymous and unnamed aggregates
Signed-off-by: Michal Soltys <soltys at ziu.info> --- com32/chain/chain.c | 12 +++---- com32/chain/mangle.c | 12 +++---- com32/chain/partiter.c | 84 ++++++++++++++++++++++++------------------------ com32/chain/partiter.h | 8 ++--- 4 files changed, 58 insertions(+), 58 deletions(-) diff --git a/com32/chain/chain.c b/com32/chain/chain.c index 060043c..6c01a87 100644 --- a/com32/chain/chain.c +++ b/com32/chain/chain.c @@ -79,7 +79,7 @@ static int find_by_sig(uint32_t mbr_sig, pi_del(&boot_part); continue; } - if (boot_part->sub.dos.disk_sig == mbr_sig) { + if (boot_part->dos.disk_sig == mbr_sig) { goto ok; } } @@ -111,12 +111,12 @@ static int find_by_guid(const struct guid *gpt_guid, continue; } /* Check for a matching GPT disk guid */ - if (!memcmp(&boot_part->sub.gpt.disk_guid, gpt_guid, sizeof(*gpt_guid))) { + if (!memcmp(&boot_part->gpt.disk_guid, gpt_guid, sizeof(*gpt_guid))) { goto ok; } /* disk guid doesn't match, maybe partition guid will */ while (!pi_next(&boot_part)) { - if (!memcmp(&boot_part->sub.gpt.part_guid, gpt_guid, sizeof(*gpt_guid))) + if (!memcmp(&boot_part->gpt.part_guid, gpt_guid, sizeof(*gpt_guid))) goto ok; } } @@ -148,7 +148,7 @@ static int find_by_label(const char *label, struct part_iter **_boot_part) } /* Check for a matching partition */ while (!pi_next(&boot_part)) { - if (!strcmp(label, boot_part->sub.gpt.part_label)) + if (!strcmp(label, boot_part->gpt.part_label)) goto ok; } } @@ -429,7 +429,7 @@ static int setup_handover(const struct part_iter *iter, } else if (iter->type == typegpt) { /* GPT handover protocol */ synth_size = sizeof(struct disk_dos_part_entry) + - sizeof(uint32_t) + (uint32_t)iter->sub.gpt.pe_size; + sizeof(uint32_t) + (uint32_t)iter->gpt.pe_size; ha = malloc(synth_size); if (!ha) { error("Could not build GPT hand-over record!\n"); @@ -449,7 +449,7 @@ static int setup_handover(const struct part_iter *iter, ha->length = (uint32_t)iter->length; /* Next comes the GPT partition record length */ plen = (uint32_t *) (ha + 1); - plen[0] = (uint32_t)iter->sub.gpt.pe_size; + plen[0] = (uint32_t)iter->gpt.pe_size; /* Next comes the GPT partition record copy */ memcpy(plen + 1, iter->record, plen[0]); #ifdef DEBUG diff --git a/com32/chain/mangle.c b/com32/chain/mangle.c index e3c494c..5cec46f 100644 --- a/com32/chain/mangle.c +++ b/com32/chain/mangle.c @@ -482,7 +482,7 @@ int mangler_grldr(const struct part_iter *iter) */ static void push_embr(struct part_iter *diter, struct part_iter *siter) { - if (diter->sub.dos.cebr_lba == siter->sub.dos.cebr_lba && + if (diter->dos.cebr_lba == siter->dos.cebr_lba && diter->di.disk == siter->di.disk) { memcpy(diter->data, siter->data, sizeof(struct disk_dos_mbr)); } @@ -555,7 +555,7 @@ int manglepe_hide(struct part_iter *miter) if (ridx >= 4 && wb && !werr) { push_embr(miter, iter); - werr |= disk_write_sectors(&iter->di, iter->sub.dos.cebr_lba, iter->data, 1); + werr |= disk_write_sectors(&iter->di, iter->dos.cebr_lba, iter->data, 1); wb = 0; } } @@ -566,7 +566,7 @@ int manglepe_hide(struct part_iter *miter) /* last write */ if (wb && !werr) { push_embr(miter, iter); - werr |= disk_write_sectors(&iter->di, iter->sub.dos.cebr_lba, iter->data, 1); + werr |= disk_write_sectors(&iter->di, iter->dos.cebr_lba, iter->data, 1); } if (werr) error("WARNING: failed to write E/MBR during '*hide*'\n"); @@ -620,11 +620,11 @@ int manglepe_fixchs(struct part_iter *miter) wb |= mpe_setchs(&iter->di, dp, (uint32_t)iter->start_lba); if (ridx > 4) - wb |= mpe_setchs(&iter->di, dp + 1, iter->sub.dos.nebr_lba); + wb |= mpe_setchs(&iter->di, dp + 1, iter->dos.nebr_lba); if (ridx >= 4 && wb && !werr) { push_embr(miter, iter); - werr |= disk_write_sectors(&iter->di, iter->sub.dos.cebr_lba, iter->data, 1); + werr |= disk_write_sectors(&iter->di, iter->dos.cebr_lba, iter->data, 1); wb = 0; } } @@ -635,7 +635,7 @@ int manglepe_fixchs(struct part_iter *miter) /* last write */ if (wb && !werr) { push_embr(miter, iter); - werr |= disk_write_sectors(&iter->di, iter->sub.dos.cebr_lba, iter->data, 1); + werr |= disk_write_sectors(&iter->di, iter->dos.cebr_lba, iter->data, 1); } if (werr) error("WARNING: failed to write E/MBR during 'fixchs'\n"); diff --git a/com32/chain/partiter.c b/com32/chain/partiter.c index 7a6006b..ce42f5c 100644 --- a/com32/chain/partiter.c +++ b/com32/chain/partiter.c @@ -155,8 +155,8 @@ static int iter_dos_ctor(struct part_iter *iter, va_list *args) memcpy(iter->data, mbr, sizeof(struct disk_dos_mbr)); - iter->sub.dos.bebr_index0 = -1; - iter->sub.dos.disk_sig = mbr->disk_sig; + iter->dos.bebr_index0 = -1; + iter->dos.disk_sig = mbr->disk_sig; return 0; bail: @@ -207,12 +207,12 @@ static int iter_gpt_ctor(struct part_iter *iter, va_list *args) memcpy(iter->data, gptl, (size_t)siz); - iter->sub.gpt.pe_count = (int)gpth->part_count; - iter->sub.gpt.pe_size = (int)gpth->part_size; - iter->sub.gpt.ufirst = gpth->lba_first_usable; - iter->sub.gpt.ulast = gpth->lba_last_usable; + iter->gpt.pe_count = (int)gpth->part_count; + iter->gpt.pe_size = (int)gpth->part_size; + iter->gpt.ufirst = gpth->lba_first_usable; + iter->gpt.ulast = gpth->lba_last_usable; - memcpy(&iter->sub.gpt.disk_guid, &gpth->disk_guid, sizeof(struct guid)); + memcpy(&iter->gpt.disk_guid, &gpth->disk_guid, sizeof(struct guid)); return 0; bail: @@ -247,7 +247,7 @@ static int notsane_logical(const struct part_iter *iter) if (!dp[0].start_lba || !dp[0].length || !sane(dp[0].start_lba, dp[0].length) || - end_log > iter->sub.dos.ebr_size) { + end_log > iter->dos.ebr_size) { error("Insane logical partition.\n"); return -1; @@ -283,7 +283,7 @@ static int notsane_extended(const struct part_iter *iter) if (!dp[1].start_lba || !dp[1].length || !sane(dp[1].start_lba, dp[1].length) || - end_ebr > iter->sub.dos.bebr_size) { + end_ebr > iter->dos.bebr_size) { error("Insane extended partition.\n"); return -1; @@ -320,13 +320,13 @@ static int notsane_gpt(const struct part_iter *iter) { const struct disk_gpt_part_entry *gp; gp = (const struct disk_gpt_part_entry *) - (iter->data + iter->index0 * iter->sub.gpt.pe_size); + (iter->data + iter->index0 * iter->gpt.pe_size); if (guid_is0(&gp->type)) return 0; - if (gp->lba_first < iter->sub.gpt.ufirst || - gp->lba_last > iter->sub.gpt.ulast) { + if (gp->lba_first < iter->gpt.ufirst || + gp->lba_last > iter->gpt.ulast) { error("Insane GPT partition.\n"); return -1; } @@ -348,13 +348,13 @@ static int pi_dos_next_mbr(struct part_iter *iter, uint32_t *lba, } if (ost_is_ext(dp->ostype)) { - if (iter->sub.dos.bebr_index0 >= 0) { + if (iter->dos.bebr_index0 >= 0) { error("You have more than 1 extended partition.\n"); iter->status = PI_INSANE; goto bail; } /* record base EBR index */ - iter->sub.dos.bebr_index0 = iter->index0; + iter->dos.bebr_index0 = iter->index0; } if (!ost_is_nondata(dp->ostype) || iter->stepall) { *lba = dp->start_lba; @@ -372,19 +372,19 @@ static int prep_base_ebr(struct part_iter *iter) { struct disk_dos_part_entry *dp; - if (iter->sub.dos.bebr_index0 < 0) /* if we don't have base extended partition at all */ + if (iter->dos.bebr_index0 < 0) /* if we don't have base extended partition at all */ return -1; - else if (!iter->sub.dos.bebr_start) { /* if not initialized yet */ - dp = ((struct disk_dos_mbr *)iter->data)->table + iter->sub.dos.bebr_index0; + else if (!iter->dos.bebr_start) { /* if not initialized yet */ + dp = ((struct disk_dos_mbr *)iter->data)->table + iter->dos.bebr_index0; - iter->sub.dos.bebr_start = dp->start_lba; - iter->sub.dos.bebr_size = dp->length; + iter->dos.bebr_start = dp->start_lba; + iter->dos.bebr_size = dp->length; - iter->sub.dos.ebr_start = 0; - iter->sub.dos.ebr_size = iter->sub.dos.bebr_size; + iter->dos.ebr_start = 0; + iter->dos.ebr_size = iter->dos.bebr_size; - iter->sub.dos.cebr_lba = 0; - iter->sub.dos.nebr_lba = iter->sub.dos.bebr_start; + iter->dos.cebr_lba = 0; + iter->dos.nebr_lba = iter->dos.bebr_start; iter->index0--; } @@ -401,10 +401,10 @@ static int pi_dos_next_ebr(struct part_iter *iter, uint32_t *lba, return -1; } - while (++iter->index0 < 1024 && iter->sub.dos.nebr_lba) { + while (++iter->index0 < 1024 && iter->dos.nebr_lba) { free(iter->data); if (!(iter->data - disk_read_sectors(&iter->di, iter->sub.dos.nebr_lba, 1))) { + disk_read_sectors(&iter->di, iter->dos.nebr_lba, 1))) { error("Couldn't load EBR.\n"); iter->status = PI_ERRLOAD; return -1; @@ -417,24 +417,24 @@ static int pi_dos_next_ebr(struct part_iter *iter, uint32_t *lba, dp = ((struct disk_dos_mbr *)iter->data)->table; - iter->sub.dos.cebr_lba = iter->sub.dos.nebr_lba; + iter->dos.cebr_lba = iter->dos.nebr_lba; /* setup next frame values */ if (dp[1].ostype) { - iter->sub.dos.ebr_start = dp[1].start_lba; - iter->sub.dos.ebr_size = dp[1].length; - iter->sub.dos.nebr_lba = iter->sub.dos.bebr_start + dp[1].start_lba; + iter->dos.ebr_start = dp[1].start_lba; + iter->dos.ebr_size = dp[1].length; + iter->dos.nebr_lba = iter->dos.bebr_start + dp[1].start_lba; } else { - iter->sub.dos.ebr_start = 0; - iter->sub.dos.ebr_size = 0; - iter->sub.dos.nebr_lba = 0; + iter->dos.ebr_start = 0; + iter->dos.ebr_size = 0; + iter->dos.nebr_lba = 0; } if (!dp[0].ostype) - iter->sub.dos.skipcnt++; + iter->dos.skipcnt++; if (dp[0].ostype || iter->stepall) { - *lba = iter->sub.dos.cebr_lba + dp[0].start_lba; + *lba = iter->dos.cebr_lba + dp[0].start_lba; *_dp = dp; return 0; } @@ -477,7 +477,7 @@ static struct part_iter *pi_dos_next(struct part_iter *iter) if (iter->index0 >= 4 && !dos_part->ostype) iter->index = -1; else - iter->index = iter->index0 - iter->sub.dos.skipcnt + 1; + iter->index = iter->index0 - iter->dos.skipcnt + 1; iter->rawindex = iter->index0 + 1; iter->start_lba = start_lba; iter->length = dos_part->length; @@ -498,14 +498,14 @@ static void gpt_conv_label(struct part_iter *iter) const int16_t *orig_lab; gp = (const struct disk_gpt_part_entry *) - (iter->data + iter->index0 * iter->sub.gpt.pe_size); + (iter->data + iter->index0 * iter->gpt.pe_size); orig_lab = (const int16_t *)gp->name; /* caveat: this is very crude conversion */ for (int i = 0; i < PI_GPTLABSIZE/2; i++) { - iter->sub.gpt.part_label[i] = (char)orig_lab[i]; + iter->gpt.part_label[i] = (char)orig_lab[i]; } - iter->sub.gpt.part_label[PI_GPTLABSIZE/2] = 0; + iter->gpt.part_label[PI_GPTLABSIZE/2] = 0; } static struct part_iter *pi_gpt_next(struct part_iter *iter) @@ -515,9 +515,9 @@ static struct part_iter *pi_gpt_next(struct part_iter *iter) if (iter->status) goto bail; - while (++iter->index0 < iter->sub.gpt.pe_count) { + while (++iter->index0 < iter->gpt.pe_count) { gpt_part = (const struct disk_gpt_part_entry *) - (iter->data + iter->index0 * iter->sub.gpt.pe_size); + (iter->data + iter->index0 * iter->gpt.pe_size); if (notsane_gpt(iter)) { iter->status = PI_INSANE; @@ -528,7 +528,7 @@ static struct part_iter *pi_gpt_next(struct part_iter *iter) break; } /* no more partitions ? */ - if (iter->index0 == iter->sub.gpt.pe_count) { + if (iter->index0 == iter->gpt.pe_count) { iter->status = PI_DONE; goto bail; } @@ -538,7 +538,7 @@ static struct part_iter *pi_gpt_next(struct part_iter *iter) iter->start_lba = gpt_part->lba_first; iter->length = gpt_part->lba_last - gpt_part->lba_first + 1; iter->record = (char *)gpt_part; - memcpy(&iter->sub.gpt.part_guid, &gpt_part->uid, sizeof(struct guid)); + memcpy(&iter->gpt.part_guid, &gpt_part->uid, sizeof(struct guid)); gpt_conv_label(iter); #ifdef DEBUG diff --git a/com32/chain/partiter.h b/com32/chain/partiter.h index e03fbbc..bce7814 100644 --- a/com32/chain/partiter.h +++ b/com32/chain/partiter.h @@ -69,8 +69,8 @@ struct part_iter { int status; /* internal */ int index0; - union _sub { - struct _dos { + union { + struct { uint32_t disk_sig; uint32_t nebr_lba; uint32_t cebr_lba; @@ -82,7 +82,7 @@ struct part_iter { int bebr_index0; int skipcnt; } dos; - struct _gpt { + struct { struct guid disk_guid; struct guid part_guid; char part_label[PI_GPTLABSIZE/2+1]; @@ -91,7 +91,7 @@ struct part_iter { uint64_t ufirst; uint64_t ulast; } gpt; - } sub; + }; }; extern const struct itertype * const typedos; -- 1.7.10.4
Michal Soltys
2012-Nov-06 00:32 UTC
[syslinux] [PATCH 04/23] com32/chain: change stepall into flags
Signed-off-by: Michal Soltys <soltys at ziu.info> --- com32/chain/mangle.c | 4 ++-- com32/chain/partiter.c | 20 ++++++++++---------- com32/chain/partiter.h | 8 ++++++-- 3 files changed, 18 insertions(+), 14 deletions(-) diff --git a/com32/chain/mangle.c b/com32/chain/mangle.c index 5cec46f..0464199 100644 --- a/com32/chain/mangle.c +++ b/com32/chain/mangle.c @@ -541,7 +541,7 @@ int manglepe_hide(struct part_iter *miter) if (miter->index > 4 && !(opt.hide & 2)) error("WARNING: your partition is beyond mbr, so it can't be unhidden without '*hideall'.\n"); - if (!(iter = pi_begin(&miter->di, 1))) /* turn stepall on */ + if (!(iter = pi_begin(&miter->di, PIF_STEPALL))) return -1; while (!pi_next(&iter) && !werr) { @@ -611,7 +611,7 @@ int manglepe_fixchs(struct part_iter *miter) return -1; } - if (!(iter = pi_begin(&miter->di, 1))) /* turn stepall on */ + if (!(iter = pi_begin(&miter->di, PIF_STEPALL))) return -1; while (!pi_next(&iter) && !werr) { diff --git a/com32/chain/partiter.c b/com32/chain/partiter.c index ce42f5c..8037a4b 100644 --- a/com32/chain/partiter.c +++ b/com32/chain/partiter.c @@ -93,14 +93,14 @@ static int inv_type(const void *type) * iter_ctor() - common iterator initialization * @iter: iterator pointer * @args(0): disk_info structure used for disk functions - * @args(1): stepall modifier + * @args(1): flags modifier * * Second and further arguments are passed as a pointer to va_list **/ static int iter_ctor(struct part_iter *iter, va_list *args) { const struct disk_info *di = va_arg(*args, const struct disk_info *); - int stepall = va_arg(*args, int); + int flags = va_arg(*args, int); #ifdef DEBUG if (!di) @@ -108,7 +108,7 @@ static int iter_ctor(struct part_iter *iter, va_list *args) #endif memcpy(&iter->di, di, sizeof(struct disk_info)); - iter->stepall = stepall; + iter->flags = flags; iter->index0 = -1; iter->length = di->lbacnt; @@ -356,7 +356,7 @@ static int pi_dos_next_mbr(struct part_iter *iter, uint32_t *lba, /* record base EBR index */ iter->dos.bebr_index0 = iter->index0; } - if (!ost_is_nondata(dp->ostype) || iter->stepall) { + if (!ost_is_nondata(dp->ostype) || (iter->flags & PIF_STEPALL)) { *lba = dp->start_lba; *_dp = dp; break; @@ -433,7 +433,7 @@ static int pi_dos_next_ebr(struct part_iter *iter, uint32_t *lba, if (!dp[0].ostype) iter->dos.skipcnt++; - if (dp[0].ostype || iter->stepall) { + if (dp[0].ostype || (iter->flags & PIF_STEPALL)) { *lba = iter->dos.cebr_lba + dp[0].start_lba; *_dp = dp; return 0; @@ -524,7 +524,7 @@ static struct part_iter *pi_gpt_next(struct part_iter *iter) goto bail; } - if (!guid_is0(&gpt_part->type) || iter->stepall) + if (!guid_is0(&gpt_part->type) || (iter->flags & PIF_STEPALL)) break; } /* no more partitions ? */ @@ -701,7 +701,7 @@ void pi_del(struct part_iter **_iter) * This function checks the disk for GPT or legacy partition table and allocates * an appropriate iterator. **/ -struct part_iter *pi_begin(const struct disk_info *di, int stepall) +struct part_iter *pi_begin(const struct disk_info *di, int flags) { int setraw = 0; struct part_iter *iter = NULL; @@ -784,17 +784,17 @@ struct part_iter *pi_begin(const struct disk_info *di, int stepall) } } /* allocate iterator and exit */ - iter = pi_new(typegpt, di, stepall, gpth, gptl); + iter = pi_new(typegpt, di, flags, gpth, gptl); } else { /* looks like MBR */ - iter = pi_new(typedos, di, stepall, mbr); + iter = pi_new(typedos, di, flags, mbr); } setraw = 0; bail: if (setraw) { error("WARNING: treating disk as raw.\n"); - iter = pi_new(typeraw, di, stepall); + iter = pi_new(typeraw, di, flags); } free(mbr); free(gpth); diff --git a/com32/chain/partiter.h b/com32/chain/partiter.h index bce7814..a394b6e 100644 --- a/com32/chain/partiter.h +++ b/com32/chain/partiter.h @@ -45,6 +45,10 @@ #define PI_DONE 1 #define PI_OK 0 +/* behaviour flags */ + +#define PIF_STEPALL 0x01 + struct itertype; struct part_iter; @@ -65,7 +69,7 @@ struct part_iter { int index; int rawindex; struct disk_info di; - int stepall; + int flags; int status; /* internal */ int index0; @@ -98,7 +102,7 @@ extern const struct itertype * const typedos; extern const struct itertype * const typegpt; extern const struct itertype * const typeraw; -struct part_iter *pi_begin(const struct disk_info *, int stepall); +struct part_iter *pi_begin(const struct disk_info *, int flags); struct part_iter *pi_new(const struct itertype *, ...); void pi_del(struct part_iter **); int pi_next(struct part_iter **); -- 1.7.10.4
Michal Soltys
2012-Nov-06 00:32 UTC
[syslinux] [PATCH 05/23] com32/chain: shuffle code before partiter simplifications
Signed-off-by: Michal Soltys <soltys at ziu.info> --- com32/chain/partiter.c | 124 ++++++++++++++++++++++++------------------------ 1 file changed, 62 insertions(+), 62 deletions(-) diff --git a/com32/chain/partiter.c b/com32/chain/partiter.c index 8037a4b..037236f 100644 --- a/com32/chain/partiter.c +++ b/com32/chain/partiter.c @@ -450,6 +450,68 @@ static int pi_dos_next_ebr(struct part_iter *iter, uint32_t *lba, return -1; } +static void gpt_conv_label(struct part_iter *iter) +{ + const struct disk_gpt_part_entry *gp; + const int16_t *orig_lab; + + gp = (const struct disk_gpt_part_entry *) + (iter->data + iter->index0 * iter->gpt.pe_size); + orig_lab = (const int16_t *)gp->name; + + /* caveat: this is very crude conversion */ + for (int i = 0; i < PI_GPTLABSIZE/2; i++) { + iter->gpt.part_label[i] = (char)orig_lab[i]; + } + iter->gpt.part_label[PI_GPTLABSIZE/2] = 0; +} + +static int check_crc(uint32_t crc_match, const uint8_t *buf, unsigned int siz) +{ + uint32_t crc; + + crc = crc32(0, NULL, 0); + crc = crc32(crc, buf, siz); + + return crc_match != crc; +} + +static int gpt_check_hdr_crc(const struct disk_info * const diskinfo, struct disk_gpt_header **_gh) +{ + struct disk_gpt_header *gh = *_gh; + uint64_t lba_alt; + uint32_t hold_crc32; + + hold_crc32 = gh->chksum; + gh->chksum = 0; + if (check_crc(hold_crc32, (const uint8_t *)gh, gh->hdr_size)) { + error("WARNING: Primary GPT header checksum invalid.\n"); + /* retry with backup */ + lba_alt = gh->lba_alt; + free(gh); + if (!(gh = *_gh = disk_read_sectors(diskinfo, lba_alt, 1))) { + error("Couldn't read backup GPT header.\n"); + return -1; + } + hold_crc32 = gh->chksum; + gh->chksum = 0; + if (check_crc(hold_crc32, (const uint8_t *)gh, gh->hdr_size)) { + error("Secondary GPT header checksum invalid.\n"); + return -1; + } + } + /* restore old checksum */ + gh->chksum = hold_crc32; + + return 0; +} + +static struct part_iter *pi_raw_next(struct part_iter *iter) +{ + iter->status = PI_DONE; + return NULL; +} + static struct part_iter *pi_dos_next(struct part_iter *iter) { uint32_t start_lba = 0; @@ -492,22 +554,6 @@ bail: return NULL; } -static void gpt_conv_label(struct part_iter *iter) -{ - const struct disk_gpt_part_entry *gp; - const int16_t *orig_lab; - - gp = (const struct disk_gpt_part_entry *) - (iter->data + iter->index0 * iter->gpt.pe_size); - orig_lab = (const int16_t *)gp->name; - - /* caveat: this is very crude conversion */ - for (int i = 0; i < PI_GPTLABSIZE/2; i++) { - iter->gpt.part_label[i] = (char)orig_lab[i]; - } - iter->gpt.part_label[PI_GPTLABSIZE/2] = 0; -} - static struct part_iter *pi_gpt_next(struct part_iter *iter) { const struct disk_gpt_part_entry *gpt_part = NULL; @@ -550,52 +596,6 @@ bail: return NULL; } -static struct part_iter *pi_raw_next(struct part_iter *iter) -{ - iter->status = PI_DONE; - return NULL; -} - -static int check_crc(uint32_t crc_match, const uint8_t *buf, unsigned int siz) -{ - uint32_t crc; - - crc = crc32(0, NULL, 0); - crc = crc32(crc, buf, siz); - - return crc_match != crc; -} - -static int gpt_check_hdr_crc(const struct disk_info * const diskinfo, struct disk_gpt_header **_gh) -{ - struct disk_gpt_header *gh = *_gh; - uint64_t lba_alt; - uint32_t hold_crc32; - - hold_crc32 = gh->chksum; - gh->chksum = 0; - if (check_crc(hold_crc32, (const uint8_t *)gh, gh->hdr_size)) { - error("WARNING: Primary GPT header checksum invalid.\n"); - /* retry with backup */ - lba_alt = gh->lba_alt; - free(gh); - if (!(gh = *_gh = disk_read_sectors(diskinfo, lba_alt, 1))) { - error("Couldn't read backup GPT header.\n"); - return -1; - } - hold_crc32 = gh->chksum; - gh->chksum = 0; - if (check_crc(hold_crc32, (const uint8_t *)gh, gh->hdr_size)) { - error("Secondary GPT header checksum invalid.\n"); - return -1; - } - } - /* restore old checksum */ - gh->chksum = hold_crc32; - - return 0; -} - /* * ---------------------------------------------------------------------------- * Following functions are for users to call. -- 1.7.10.4
Michal Soltys
2012-Nov-06 00:32 UTC
[syslinux] [PATCH 06/23] com32/chain: partiter - simplifications and updates
The code uses more abstractions than it's really worth or necessary, so these patches simplify the code a bit. Partially suggested by Shao as well. Additionally, there're some added comments and more consistent naming used. Signed-off-by: Michal Soltys <soltys at ziu.info> --- com32/chain/chain.c | 8 +- com32/chain/mangle.c | 4 +- com32/chain/partiter.c | 350 +++++++++++++----------------------------------- com32/chain/partiter.h | 39 +++--- 4 files changed, 122 insertions(+), 279 deletions(-) diff --git a/com32/chain/chain.c b/com32/chain/chain.c index 6c01a87..f2f6719 100644 --- a/com32/chain/chain.c +++ b/com32/chain/chain.c @@ -115,7 +115,7 @@ static int find_by_guid(const struct guid *gpt_guid, goto ok; } /* disk guid doesn't match, maybe partition guid will */ - while (!pi_next(&boot_part)) { + while (!pi_next(boot_part)) { if (!memcmp(&boot_part->gpt.part_guid, gpt_guid, sizeof(*gpt_guid))) goto ok; } @@ -147,7 +147,7 @@ static int find_by_label(const char *label, struct part_iter **_boot_part) continue; } /* Check for a matching partition */ - while (!pi_next(&boot_part)) { + while (!pi_next(boot_part)) { if (!strcmp(label, boot_part->gpt.part_label)) goto ok; } @@ -353,7 +353,7 @@ int find_dp(struct part_iter **_iter) /* 'fs' => we should lookup the syslinux partition number and use it */ if (!strcmp(opt.drivename, "fs")) { - while (!pi_next(&iter)) { + while (!pi_next(iter)) { if (iter->start_lba == fs_lba) break; } @@ -377,7 +377,7 @@ int find_dp(struct part_iter **_iter) do { if (iter->index == partition) break; - } while (!pi_next(&iter)); + } while (!pi_next(iter)); if (iter->status) { error("Requested disk / partition combination not found.\n"); goto bail; diff --git a/com32/chain/mangle.c b/com32/chain/mangle.c index 0464199..fe446b0 100644 --- a/com32/chain/mangle.c +++ b/com32/chain/mangle.c @@ -544,7 +544,7 @@ int manglepe_hide(struct part_iter *miter) if (!(iter = pi_begin(&miter->di, PIF_STEPALL))) return -1; - while (!pi_next(&iter) && !werr) { + while (!pi_next(iter) && !werr) { ridx = iter->rawindex; if (!(opt.hide & 2) && ridx > 4) break; /* skip when we're constrained to pri only */ @@ -614,7 +614,7 @@ int manglepe_fixchs(struct part_iter *miter) if (!(iter = pi_begin(&miter->di, PIF_STEPALL))) return -1; - while (!pi_next(&iter) && !werr) { + while (!pi_next(iter) && !werr) { ridx = iter->rawindex; dp = (struct disk_dos_part_entry *)iter->record; diff --git a/com32/chain/partiter.c b/com32/chain/partiter.c index 037236f..dffe83f 100644 --- a/com32/chain/partiter.c +++ b/com32/chain/partiter.c @@ -48,108 +48,61 @@ #define ost_is_nondata(type) (ost_is_ext(type) || (type) == 0x00) #define sane(s,l) ((s)+(l) > (s)) -/* forwards */ +/* virtual forwards */ -static int iter_ctor(struct part_iter *, va_list *); -static int iter_dos_ctor(struct part_iter *, va_list *); -static int iter_gpt_ctor(struct part_iter *, va_list *); -static void iter_dtor(struct part_iter *); -static struct part_iter *pi_dos_next(struct part_iter *); -static struct part_iter *pi_gpt_next(struct part_iter *); -static struct part_iter *pi_raw_next(struct part_iter *); +static void pi_dtor_(struct part_iter *); +static int pi_next_(struct part_iter *); +static int pi_dos_next(struct part_iter *); +static int pi_gpt_next(struct part_iter *); + +/* vtab and types */ static struct itertype types[] = { [0] = { - .ctor = &iter_dos_ctor, - .dtor = &iter_dtor, + .dtor = &pi_dtor_, .next = &pi_dos_next, }, [1] = { - .ctor = &iter_gpt_ctor, - .dtor = &iter_dtor, + .dtor = &pi_dtor_, .next = &pi_gpt_next, }, [2] = { - .ctor = &iter_ctor, - .dtor = &iter_dtor, - .next = &pi_raw_next, + .dtor = &pi_dtor_, + .next = &pi_next_, }}; const struct itertype * const typedos = types; const struct itertype * const typegpt = types+1; const struct itertype * const typeraw = types+2; -#ifdef DEBUG -static int inv_type(const void *type) +/* pi_dtor_() - common/raw iterator cleanup */ +static void pi_dtor_(struct part_iter *iter) { - int i, cnt = sizeof(types)/sizeof(types[0]); - for (i = 0; i < cnt; i++) { - if (type == types + i) - return 0; - } - return -1; + /* syslinux's free is null resilient */ + free(iter->data); } -#endif -/** - * iter_ctor() - common iterator initialization - * @iter: iterator pointer - * @args(0): disk_info structure used for disk functions - * @args(1): flags modifier - * - * Second and further arguments are passed as a pointer to va_list - **/ -static int iter_ctor(struct part_iter *iter, va_list *args) +/* pi_ctor() - common/raw iterator initialization */ +static int pi_ctor(struct part_iter *iter, + const struct disk_info *di, int flags +) { - const struct disk_info *di = va_arg(*args, const struct disk_info *); - int flags = va_arg(*args, int); - -#ifdef DEBUG - if (!di) - return -1; -#endif - memcpy(&iter->di, di, sizeof(struct disk_info)); iter->flags = flags; iter->index0 = -1; iter->length = di->lbacnt; + iter->type = typeraw; return 0; } -/** - * iter_dtor() - common iterator cleanup - * @iter: iterator pointer - * - **/ -static void iter_dtor(struct part_iter *iter) +/* pi_dos_ctor() - MBR/EBR iterator specific initialization */ +static int pi_dos_ctor(struct part_iter *iter, + const struct disk_info *di, int flags, + const struct disk_dos_mbr *mbr +) { - free(iter->data); -} - -/** - * iter_dos_ctor() - MBR/EBR iterator specific initialization - * @iter: iterator pointer - * @args(0): disk_info structure used for disk functions - * @args(1): pointer to buffer with loaded valid MBR - * - * Second and further arguments are passed as a pointer to va_list. - * This function only makes rudimentary checks. If user uses - * pi_new(), he/she is responsible for doing proper sanity checks. - **/ -static int iter_dos_ctor(struct part_iter *iter, va_list *args) -{ - const struct disk_dos_mbr *mbr; - - /* uses args(0) */ - if (iter_ctor(iter, args)) + if (pi_ctor(iter, di, flags)) return -1; - mbr = va_arg(*args, const struct disk_dos_mbr *); - -#ifdef DEBUG - if (!mbr) - goto bail; -#endif - if (!(iter->data = malloc(sizeof(struct disk_dos_mbr)))) goto bail; @@ -158,50 +111,26 @@ static int iter_dos_ctor(struct part_iter *iter, va_list *args) iter->dos.bebr_index0 = -1; iter->dos.disk_sig = mbr->disk_sig; + iter->type = typedos; return 0; bail: - iter->type->dtor(iter); + pi_dtor_(iter); return -1; } -/** - * iter_gpt_ctor() - GPT iterator specific initialization - * @iter: iterator pointer - * @args(0): ptr to disk_info structure - * @args(1): ptr to buffer with GPT header - * @args(2): ptr to buffer with GPT partition list - * - * Second and further arguments are passed as a pointer to va_list. - * This function only makes rudimentary checks. If user uses - * pi_new(), he/she is responsible for doing proper sanity checks. - **/ -static int iter_gpt_ctor(struct part_iter *iter, va_list *args) +/* pi_gpt_ctor() - GPT iterator specific initialization */ +static int pi_gpt_ctor(struct part_iter *iter, + const struct disk_info *di, int flags, + const struct disk_gpt_header *gpth, const struct disk_gpt_part_entry *gptl +) { uint64_t siz; - const struct disk_gpt_header *gpth; - const struct disk_gpt_part_entry *gptl; - /* uses args(0) */ - if (iter_ctor(iter, args)) + if (pi_ctor(iter, di, flags)) return -1; - gpth = va_arg(*args, const struct disk_gpt_header *); - gptl = va_arg(*args, const struct disk_gpt_part_entry *); - -#ifdef DEBUG - if (!gpth || !gptl) - goto bail; -#endif - siz = (uint64_t)gpth->part_count * gpth->part_size; -#ifdef DEBUG - if (!siz || (siz + iter->di.bps - 1) / iter->di.bps > 255u || - gpth->part_size < sizeof(struct disk_gpt_part_entry)) { - goto bail; - } -#endif - if (!(iter->data = malloc((size_t)siz))) goto bail; @@ -214,9 +143,10 @@ static int iter_gpt_ctor(struct part_iter *iter, va_list *args) memcpy(&iter->gpt.disk_guid, &gpth->disk_guid, sizeof(struct guid)); + iter->type = typegpt; return 0; bail: - iter->type->dtor(iter); + pi_dtor_(iter); return -1; } @@ -309,7 +239,7 @@ static int notsane_primary(const struct part_iter *iter) !dp->length || !sane(dp->start_lba, dp->length) || dp->start_lba + dp->length > iter->di.lbacnt) { - error("Insane primary (MBR) partition.\n"); + error("Primary (MBR) with invalid offset and/or length.\n"); return -1; } @@ -327,14 +257,14 @@ static int notsane_gpt(const struct part_iter *iter) if (gp->lba_first < iter->gpt.ufirst || gp->lba_last > iter->gpt.ulast) { - error("Insane GPT partition.\n"); + error("LBA sectors of GPT partition are beyond the range allowed in GPT header.\n"); return -1; } return 0; } -static int pi_dos_next_mbr(struct part_iter *iter, uint32_t *lba, +static int dos_next_mbr(struct part_iter *iter, uint32_t *lba, struct disk_dos_part_entry **_dp) { struct disk_dos_part_entry *dp; @@ -344,14 +274,14 @@ static int pi_dos_next_mbr(struct part_iter *iter, uint32_t *lba, if (notsane_primary(iter)) { iter->status = PI_INSANE; - goto bail; + return -1; } if (ost_is_ext(dp->ostype)) { if (iter->dos.bebr_index0 >= 0) { error("You have more than 1 extended partition.\n"); iter->status = PI_INSANE; - goto bail; + return -1; } /* record base EBR index */ iter->dos.bebr_index0 = iter->index0; @@ -364,8 +294,6 @@ static int pi_dos_next_mbr(struct part_iter *iter, uint32_t *lba, } return 0; -bail: - return -1; } static int prep_base_ebr(struct part_iter *iter) @@ -391,12 +319,12 @@ static int prep_base_ebr(struct part_iter *iter) return 0; } -static int pi_dos_next_ebr(struct part_iter *iter, uint32_t *lba, +static int dos_next_ebr(struct part_iter *iter, uint32_t *lba, struct disk_dos_part_entry **_dp) { struct disk_dos_part_entry *dp; - if (prep_base_ebr(iter)) { + if (prep_base_ebr(iter) < 0) { iter->status = PI_DONE; return -1; } @@ -442,8 +370,8 @@ static int pi_dos_next_ebr(struct part_iter *iter, uint32_t *lba, * This way it's possible to continue, if some crazy soft left a "hole" * - EBR with a valid extended partition without a logical one. In * such case, linux will not reserve a number for such hole - so we - * don't increase index0. If stepall flag is set, we will never reach - * this place. + * don't increase index0. If PIF_STEPALL flag is set, we will never + * reach this place. */ } iter->status = PI_DONE; @@ -466,14 +394,9 @@ static void gpt_conv_label(struct part_iter *iter) iter->gpt.part_label[PI_GPTLABSIZE/2] = 0; } -static int check_crc(uint32_t crc_match, const uint8_t *buf, unsigned int siz) +static inline int valid_crc(uint32_t crc, const uint8_t *buf, unsigned int siz) { - uint32_t crc; - - crc = crc32(0, NULL, 0); - crc = crc32(crc, buf, siz); - - return crc_match != crc; + return crc == crc32(crc32(0, NULL, 0), buf, siz); } static int gpt_check_hdr_crc(const struct disk_info * const diskinfo, struct disk_gpt_header **_gh) @@ -484,7 +407,7 @@ static int gpt_check_hdr_crc(const struct disk_info * const diskinfo, struct dis hold_crc32 = gh->chksum; gh->chksum = 0; - if (check_crc(hold_crc32, (const uint8_t *)gh, gh->hdr_size)) { + if (!valid_crc(hold_crc32, (const uint8_t *)gh, gh->hdr_size)) { error("WARNING: Primary GPT header checksum invalid.\n"); /* retry with backup */ lba_alt = gh->lba_alt; @@ -495,7 +418,7 @@ static int gpt_check_hdr_crc(const struct disk_info * const diskinfo, struct dis } hold_crc32 = gh->chksum; gh->chksum = 0; - if (check_crc(hold_crc32, (const uint8_t *)gh, gh->hdr_size)) { + if (!valid_crc(hold_crc32, (const uint8_t *)gh, gh->hdr_size)) { error("Secondary GPT header checksum invalid.\n"); return -1; } @@ -506,34 +429,33 @@ static int gpt_check_hdr_crc(const struct disk_info * const diskinfo, struct dis return 0; } -static struct part_iter *pi_raw_next(struct part_iter *iter) +static int pi_next_(struct part_iter *iter) { iter->status = PI_DONE; - return NULL; + return iter->status; } -static struct part_iter *pi_dos_next(struct part_iter *iter) +static int pi_dos_next(struct part_iter *iter) { uint32_t start_lba = 0; struct disk_dos_part_entry *dos_part = NULL; if (iter->status) - goto bail; + return iter->status; /* look for primary partitions */ if (iter->index0 < 4 && - pi_dos_next_mbr(iter, &start_lba, &dos_part)) - goto bail; + dos_next_mbr(iter, &start_lba, &dos_part) < 0) + return iter->status; /* look for logical partitions */ if (iter->index0 >= 4 && - pi_dos_next_ebr(iter, &start_lba, &dos_part)) - goto bail; + dos_next_ebr(iter, &start_lba, &dos_part) < 0) + return iter->status; /* - * note special index handling, if we have stepall set - - * this is made to keep index consistent with non-stepall - * iterators + * note special index handling, if we have PIF_STEPALL set - this is made + * to keep index consistent with non-PIF_STEPALL iterators */ if (iter->index0 >= 4 && !dos_part->ostype) @@ -549,17 +471,15 @@ static struct part_iter *pi_dos_next(struct part_iter *iter) disk_dos_part_dump(dos_part); #endif - return iter; -bail: - return NULL; + return iter->status; } -static struct part_iter *pi_gpt_next(struct part_iter *iter) +static int pi_gpt_next(struct part_iter *iter) { const struct disk_gpt_part_entry *gpt_part = NULL; if (iter->status) - goto bail; + return iter->status; while (++iter->index0 < iter->gpt.pe_count) { gpt_part = (const struct disk_gpt_part_entry *) @@ -567,7 +487,7 @@ static struct part_iter *pi_gpt_next(struct part_iter *iter) if (notsane_gpt(iter)) { iter->status = PI_INSANE; - goto bail; + return iter->status; } if (!guid_is0(&gpt_part->type) || (iter->flags & PIF_STEPALL)) @@ -576,7 +496,7 @@ static struct part_iter *pi_gpt_next(struct part_iter *iter) /* no more partitions ? */ if (iter->index0 == iter->gpt.pe_count) { iter->status = PI_DONE; - goto bail; + return iter->status; } /* gpt_part is guaranteed to be valid here */ iter->index = iter->index0 + 1; @@ -591,135 +511,53 @@ static struct part_iter *pi_gpt_next(struct part_iter *iter) disk_gpt_part_dump(gpt_part); #endif - return iter; -bail: - return NULL; + return iter->status; } -/* - * ---------------------------------------------------------------------------- - * Following functions are for users to call. - * ---------------------------------------------------------------------------- - */ - - -int pi_next(struct part_iter **_iter) +static struct part_iter *pi_alloc(void) { struct part_iter *iter; - - if(!_iter || !*_iter) - return 0; - iter = *_iter; -#ifdef DEBUG - if (inv_type(iter->type)) { - error("This is not a valid iterator.\n"); - return 0; - } -#endif - if ((iter = iter->type->next(iter))) { - *_iter = iter; - } - return (*_iter)->status; -} - -/** - * pi_new() - get new iterator - * @itertype: iterator type - * @...: variable arguments passed to ctors - * - * Variable arguments depend on the type. Please see functions: - * iter_gpt_ctor() and iter_dos_ctor() for details. - **/ -struct part_iter *pi_new(const struct itertype *type, ...) -{ - int badctor = 0; - struct part_iter *iter = NULL; - va_list ap; - - va_start(ap, type); - -#ifdef DEBUG - if (inv_type(type)) { - error("Unknown iterator requested.\n"); - goto bail; - } -#endif - - if (!(iter = malloc(sizeof(struct part_iter)))) { + if (!(iter = malloc(sizeof(struct part_iter)))) error("Couldn't allocate memory for the iterator.\n"); - goto bail; - } - - memset(iter, 0, sizeof(struct part_iter)); - iter->type = type; - - if (type->ctor(iter, &ap)) { - badctor = -1; - error("Cannot initialize the iterator.\n"); - goto bail; - } - -bail: - va_end(ap); - if (badctor) { - free(iter); - iter = NULL; - } + else + memset(iter, 0, sizeof(struct part_iter)); return iter; } -/** - * pi_del() - delete iterator - * @iter: iterator double pointer - * - **/ - +/* pi_del() - delete iterator */ void pi_del(struct part_iter **_iter) { - struct part_iter *iter; - if(!_iter || !*_iter) return; - iter = *_iter; - -#ifdef DEBUG - if (inv_type(iter->type)) { - error("This is not a valid iterator.\n"); - return; - } -#endif - - iter->type->dtor(iter); - free(iter); + pi_dtor(*_iter); + free(*_iter); *_iter = NULL; } -/** - * pi_begin() - check disk, validate, and get proper iterator - * @di: diskinfo struct pointer - * - * This function checks the disk for GPT or legacy partition table and allocates - * an appropriate iterator. - **/ +/* pi_begin() - validate and and get proper iterator for a disk described by di */ struct part_iter *pi_begin(const struct disk_info *di, int flags) { - int setraw = 0; - struct part_iter *iter = NULL; + int ret = -1; + struct part_iter *iter; struct disk_dos_mbr *mbr = NULL; struct disk_gpt_header *gpth = NULL; struct disk_gpt_part_entry *gptl = NULL; + /* Preallocate iterator */ + if (!(iter = pi_alloc())) + goto bail; + /* Read MBR */ if (!(mbr = disk_read_sectors(di, 0, 1))) { error("Couldn't read first disk sector.\n"); goto bail; } - setraw = -1; - - /* Check for MBR magic*/ + /* Check for MBR magic */ if (mbr->sig != disk_mbr_sig_magic) { - error("No MBR magic.\n"); + error("WARNING: no MBR magic, treating disk as raw.\n"); + /* looks like RAW */ + ret = pi_ctor(iter, di, flags); goto bail; } @@ -770,32 +608,28 @@ struct part_iter *pi_begin(const struct disk_info *di, int flags) goto bail; } /* Check array checksum(s). */ - if (check_crc(gpth->table_chksum, (const uint8_t *)gptl, (unsigned int)gpt_lsiz)) { - error("WARNING: GPT partition list checksum invalid, trying backup.\n"); + if (!valid_crc(gpth->table_chksum, (const uint8_t *)gptl, (unsigned int)gpt_lsiz)) { + error("Main GPT partition list's checksum invalid, trying backup.\n"); free(gptl); /* secondary array directly precedes secondary header */ if (!(gptl = disk_read_sectors(di, gpth->lba_alt - gpt_lcnt, (uint8_t)gpt_lcnt))) { error("Couldn't read backup GPT partition list.\n"); goto bail; } - if (check_crc(gpth->table_chksum, (const uint8_t *)gptl, (unsigned int)gpt_lsiz)) { - error("Backup GPT partition list checksum invalid.\n"); + if (!valid_crc(gpth->table_chksum, (const uint8_t *)gptl, (unsigned int)gpt_lsiz)) { + error("Backup GPT partition list's checksum invalid.\n"); goto bail; } } - /* allocate iterator and exit */ - iter = pi_new(typegpt, di, flags, gpth, gptl); + /* looks like GPT */ + ret = pi_gpt_ctor(iter, di, flags, gpth, gptl); } else { /* looks like MBR */ - iter = pi_new(typedos, di, flags, mbr); + ret = pi_dos_ctor(iter, di, flags, mbr); } - - setraw = 0; bail: - if (setraw) { - error("WARNING: treating disk as raw.\n"); - iter = pi_new(typeraw, di, flags); - } + if (ret < 0) + free(iter); free(mbr); free(gpth); free(gptl); diff --git a/com32/chain/partiter.h b/com32/chain/partiter.h index a394b6e..f441e46 100644 --- a/com32/chain/partiter.h +++ b/com32/chain/partiter.h @@ -40,12 +40,14 @@ #include <stdint.h> #include <syslinux/disk.h> -#define PI_ERRLOAD 3 -#define PI_INSANE 2 -#define PI_DONE 1 -#define PI_OK 0 +/* status */ -/* behaviour flags */ +#define PI_ERRLOAD 3 +#define PI_INSANE 2 +#define PI_DONE 1 +#define PI_OK 0 + +/* flags */ #define PIF_STEPALL 0x01 @@ -53,9 +55,8 @@ struct itertype; struct part_iter; struct itertype { - int (*ctor)(struct part_iter *, va_list *); void (*dtor)(struct part_iter *); - struct part_iter *(*next) (struct part_iter *); + int (*next)(struct part_iter *); }; #define PI_GPTLABSIZE ((int)sizeof(((struct disk_gpt_part_entry *)0)->name)) @@ -66,13 +67,12 @@ struct part_iter { char *record; uint64_t start_lba; uint64_t length; - int index; - int rawindex; + int index0; /* including holes, from -1 (disk, then parts from 0) */ + int rawindex; /* including holes, from 0 (disk, then parts from 1) */ + int index; /* excluding holes, from 0 (disk) (-1) means hole, if PIF_STEPALL is set */ + int flags; /* flags, see #defines above */ + int status; /* current status, see #defines above */ struct disk_info di; - int flags; - int status; - /* internal */ - int index0; union { struct { uint32_t disk_sig; @@ -103,9 +103,18 @@ extern const struct itertype * const typegpt; extern const struct itertype * const typeraw; struct part_iter *pi_begin(const struct disk_info *, int flags); -struct part_iter *pi_new(const struct itertype *, ...); void pi_del(struct part_iter **); -int pi_next(struct part_iter **); + +/* inline virtuals */ +static inline int pi_next(struct part_iter *iter) +{ + return iter->type->next(iter); +} + +static inline void pi_dtor(struct part_iter *iter) +{ + iter->type->dtor(iter); +} #endif -- 1.7.10.4
Michal Soltys
2012-Nov-06 00:32 UTC
[syslinux] [PATCH 07/23] com32/chain: remove redundant rawindex
'index0' provides the same "raw" info, complementing standard 'index'. Signed-off-by: Michal Soltys <soltys at ziu.info> --- com32/chain/mangle.c | 4 ++-- com32/chain/partiter.c | 2 -- com32/chain/partiter.h | 5 ++--- 3 files changed, 4 insertions(+), 7 deletions(-) diff --git a/com32/chain/mangle.c b/com32/chain/mangle.c index fe446b0..89996d0 100644 --- a/com32/chain/mangle.c +++ b/com32/chain/mangle.c @@ -545,7 +545,7 @@ int manglepe_hide(struct part_iter *miter) return -1; while (!pi_next(iter) && !werr) { - ridx = iter->rawindex; + ridx = iter->index0 + 1; if (!(opt.hide & 2) && ridx > 4) break; /* skip when we're constrained to pri only */ @@ -615,7 +615,7 @@ int manglepe_fixchs(struct part_iter *miter) return -1; while (!pi_next(iter) && !werr) { - ridx = iter->rawindex; + ridx = iter->index0 + 1; dp = (struct disk_dos_part_entry *)iter->record; wb |= mpe_setchs(&iter->di, dp, (uint32_t)iter->start_lba); diff --git a/com32/chain/partiter.c b/com32/chain/partiter.c index dffe83f..3ecaecf 100644 --- a/com32/chain/partiter.c +++ b/com32/chain/partiter.c @@ -462,7 +462,6 @@ static int pi_dos_next(struct part_iter *iter) iter->index = -1; else iter->index = iter->index0 - iter->dos.skipcnt + 1; - iter->rawindex = iter->index0 + 1; iter->start_lba = start_lba; iter->length = dos_part->length; iter->record = (char *)dos_part; @@ -500,7 +499,6 @@ static int pi_gpt_next(struct part_iter *iter) } /* gpt_part is guaranteed to be valid here */ iter->index = iter->index0 + 1; - iter->rawindex = iter->index0 + 1; iter->start_lba = gpt_part->lba_first; iter->length = gpt_part->lba_last - gpt_part->lba_first + 1; iter->record = (char *)gpt_part; diff --git a/com32/chain/partiter.h b/com32/chain/partiter.h index f441e46..e9b158b 100644 --- a/com32/chain/partiter.h +++ b/com32/chain/partiter.h @@ -68,9 +68,8 @@ struct part_iter { uint64_t start_lba; uint64_t length; int index0; /* including holes, from -1 (disk, then parts from 0) */ - int rawindex; /* including holes, from 0 (disk, then parts from 1) */ - int index; /* excluding holes, from 0 (disk) (-1) means hole, if PIF_STEPALL is set */ - int flags; /* flags, see #defines above */ + int index; /* excluding holes, from 0 (disk, then parts from 1), -1 means hole, if PIF_STEPALL is set */ + int flags; /* flags, see #defines above */ int status; /* current status, see #defines above */ struct disk_info di; union { -- 1.7.10.4
Michal Soltys
2012-Nov-06 00:32 UTC
[syslinux] [PATCH 08/23] com32/chain: partiter - more precise comments / output
Signed-off-by: Michal Soltys <soltys at ziu.info> --- com32/chain/partiter.c | 19 ++++++++++--------- com32/chain/partiter.h | 23 +++++++++++++---------- 2 files changed, 23 insertions(+), 19 deletions(-) diff --git a/com32/chain/partiter.c b/com32/chain/partiter.c index 3ecaecf..250cb2c 100644 --- a/com32/chain/partiter.c +++ b/com32/chain/partiter.c @@ -179,7 +179,7 @@ static int notsane_logical(const struct part_iter *iter) !sane(dp[0].start_lba, dp[0].length) || end_log > iter->dos.ebr_size) { - error("Insane logical partition.\n"); + error("Logical partition (in EBR) with invalid offset and/or length.\n"); return -1; } @@ -204,7 +204,7 @@ static int notsane_extended(const struct part_iter *iter) return 0; if (!ost_is_nondata(dp[1].ostype)) { - error("2nd EBR entry must be extended or empty.\n"); + error("The 2nd EBR entry must be extended or empty.\n"); return -1; } @@ -215,7 +215,7 @@ static int notsane_extended(const struct part_iter *iter) !sane(dp[1].start_lba, dp[1].length) || end_ebr > iter->dos.bebr_size) { - error("Insane extended partition.\n"); + error("Extended partition (EBR) with invalid offset and/or length.\n"); return -1; } @@ -239,7 +239,7 @@ static int notsane_primary(const struct part_iter *iter) !dp->length || !sane(dp->start_lba, dp->length) || dp->start_lba + dp->length > iter->di.lbacnt) { - error("Primary (MBR) with invalid offset and/or length.\n"); + error("Primary partition (in MBR) with invalid offset and/or length.\n"); return -1; } @@ -279,7 +279,7 @@ static int dos_next_mbr(struct part_iter *iter, uint32_t *lba, if (ost_is_ext(dp->ostype)) { if (iter->dos.bebr_index0 >= 0) { - error("You have more than 1 extended partition.\n"); + error("More than 1 extended partition.\n"); iter->status = PI_INSANE; return -1; } @@ -454,8 +454,9 @@ static int pi_dos_next(struct part_iter *iter) return iter->status; /* - * note special index handling, if we have PIF_STEPALL set - this is made - * to keep index consistent with non-PIF_STEPALL iterators + * note special index handling: + * in case PIF_STEPALL is set - this makes the index consistent with + * non-PIF_STEPALL iterators */ if (iter->index0 >= 4 && !dos_part->ostype) @@ -607,7 +608,7 @@ struct part_iter *pi_begin(const struct disk_info *di, int flags) } /* Check array checksum(s). */ if (!valid_crc(gpth->table_chksum, (const uint8_t *)gptl, (unsigned int)gpt_lsiz)) { - error("Main GPT partition list's checksum invalid, trying backup.\n"); + error("Checksum of the main GPT partition list is invalid, trying backup.\n"); free(gptl); /* secondary array directly precedes secondary header */ if (!(gptl = disk_read_sectors(di, gpth->lba_alt - gpt_lcnt, (uint8_t)gpt_lcnt))) { @@ -615,7 +616,7 @@ struct part_iter *pi_begin(const struct disk_info *di, int flags) goto bail; } if (!valid_crc(gpth->table_chksum, (const uint8_t *)gptl, (unsigned int)gpt_lsiz)) { - error("Backup GPT partition list's checksum invalid.\n"); + error("Checksum of the backup GPT partition list is invalid, giving up.\n"); goto bail; } } diff --git a/com32/chain/partiter.h b/com32/chain/partiter.h index e9b158b..4acf1d2 100644 --- a/com32/chain/partiter.h +++ b/com32/chain/partiter.h @@ -74,16 +74,19 @@ struct part_iter { struct disk_info di; union { struct { - uint32_t disk_sig; - uint32_t nebr_lba; - uint32_t cebr_lba; - /* internal */ - uint32_t ebr_start; - uint32_t ebr_size; - uint32_t bebr_start; - uint32_t bebr_size; - int bebr_index0; - int skipcnt; + uint32_t disk_sig; /* 32bit disk signature as stored in MBR */ + + uint32_t bebr_start; /* abs lba of base extended partition */ + uint32_t bebr_size; /* size of base extended partition */ + + uint32_t cebr_lba; /* absolute lba of curr ext. partition */ + uint32_t nebr_lba; /* absolute lba of next ext. partition */ + + uint32_t ebr_start; /* relative (to bebr) lba of next extended partition */ + uint32_t ebr_size; /* size of next extended partition */ + + int bebr_index0; /* index of (0-3) of base ext. part., -1 of not present in MBR */ + int skipcnt; /* how many logical holes were skipped */ } dos; struct { struct guid disk_guid; -- 1.7.10.4
Michal Soltys
2012-Nov-06 00:32 UTC
[syslinux] [PATCH 09/23] com32/chain: remove unused ebr_start
Signed-off-by: Michal Soltys <soltys at ziu.info> --- com32/chain/partiter.c | 3 --- com32/chain/partiter.h | 1 - 2 files changed, 4 deletions(-) diff --git a/com32/chain/partiter.c b/com32/chain/partiter.c index 250cb2c..da96b3d 100644 --- a/com32/chain/partiter.c +++ b/com32/chain/partiter.c @@ -308,7 +308,6 @@ static int prep_base_ebr(struct part_iter *iter) iter->dos.bebr_start = dp->start_lba; iter->dos.bebr_size = dp->length; - iter->dos.ebr_start = 0; iter->dos.ebr_size = iter->dos.bebr_size; iter->dos.cebr_lba = 0; @@ -349,11 +348,9 @@ static int dos_next_ebr(struct part_iter *iter, uint32_t *lba, /* setup next frame values */ if (dp[1].ostype) { - iter->dos.ebr_start = dp[1].start_lba; iter->dos.ebr_size = dp[1].length; iter->dos.nebr_lba = iter->dos.bebr_start + dp[1].start_lba; } else { - iter->dos.ebr_start = 0; iter->dos.ebr_size = 0; iter->dos.nebr_lba = 0; } diff --git a/com32/chain/partiter.h b/com32/chain/partiter.h index 4acf1d2..958be51 100644 --- a/com32/chain/partiter.h +++ b/com32/chain/partiter.h @@ -82,7 +82,6 @@ struct part_iter { uint32_t cebr_lba; /* absolute lba of curr ext. partition */ uint32_t nebr_lba; /* absolute lba of next ext. partition */ - uint32_t ebr_start; /* relative (to bebr) lba of next extended partition */ uint32_t ebr_size; /* size of next extended partition */ int bebr_index0; /* index of (0-3) of base ext. part., -1 of not present in MBR */ -- 1.7.10.4
Michal Soltys
2012-Nov-06 00:32 UTC
[syslinux] [PATCH 10/23] com32/chain: add pi_errored() in partiter
Signed-off-by: Michal Soltys <soltys at ziu.info> --- com32/chain/mangle.c | 4 ++-- com32/chain/partiter.h | 5 +++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/com32/chain/mangle.c b/com32/chain/mangle.c index 89996d0..60cee13 100644 --- a/com32/chain/mangle.c +++ b/com32/chain/mangle.c @@ -560,7 +560,7 @@ int manglepe_hide(struct part_iter *miter) } } - if (iter->status > PI_DONE) + if (pi_errored(iter)) goto bail; /* last write */ @@ -629,7 +629,7 @@ int manglepe_fixchs(struct part_iter *miter) } } - if (iter->status > PI_DONE) + if (pi_errored(iter)) goto bail; /* last write */ diff --git a/com32/chain/partiter.h b/com32/chain/partiter.h index 958be51..61869de 100644 --- a/com32/chain/partiter.h +++ b/com32/chain/partiter.h @@ -106,6 +106,11 @@ extern const struct itertype * const typeraw; struct part_iter *pi_begin(const struct disk_info *, int flags); void pi_del(struct part_iter **); +static inline int pi_errored(struct part_iter *iter) +{ + return iter->status > PI_DONE; +} + /* inline virtuals */ static inline int pi_next(struct part_iter *iter) { -- 1.7.10.4
Michal Soltys
2012-Nov-06 00:32 UTC
[syslinux] [PATCH 11/23] com32/chain: mangle and related updates
Comments, output and minor adjustments. Signed-off-by: Michal Soltys <soltys at ziu.info> --- com32/chain/mangle.c | 65 ++++++++++++++++++++++++++----------------------- com32/chain/options.c | 6 ++--- com32/chain/utility.c | 9 +++---- com32/chain/utility.h | 2 +- 4 files changed, 43 insertions(+), 39 deletions(-) diff --git a/com32/chain/mangle.c b/com32/chain/mangle.c index 60cee13..0eb35b3 100644 --- a/com32/chain/mangle.c +++ b/com32/chain/mangle.c @@ -276,8 +276,8 @@ bail: /* Adjust BPB common function */ static int mangle_bpb(const struct part_iter *iter, struct data_area *data, const char *tag) { - unsigned int off; int type = bpb_detect(data->data, tag); + int off = drvoff_detect(type); /* BPB: hidden sectors 32bit*/ if (type >= bpbV34) { @@ -307,7 +307,7 @@ static int mangle_bpb(const struct part_iter *iter, struct data_area *data, cons } } /* BPB: drive */ - if (drvoff_detect(type, &off)) { + if (off >= 0) { *(uint8_t *)((char *)data->data + off) = (uint8_t) (opt.swap ? iter->di.disk & 0x80 : iter->di.disk); } @@ -344,7 +344,7 @@ int mangles_bpb(const struct part_iter *iter, struct data_area *data) int manglesf_bss(struct data_area *sec, struct data_area *fil) { int type1, type2; - unsigned int cnt = 0; + size_t cnt = 0; if (!(opt.sect && opt.file && opt.bss)) return 0; @@ -480,7 +480,7 @@ int mangler_grldr(const struct part_iter *iter) /* * try to copy values from temporary iterator, if positions match */ -static void push_embr(struct part_iter *diter, struct part_iter *siter) +static void mbrcpy(struct part_iter *diter, struct part_iter *siter) { if (diter->dos.cebr_lba == siter->dos.cebr_lba && diter->di.disk == siter->di.disk) { @@ -488,7 +488,7 @@ static void push_embr(struct part_iter *diter, struct part_iter *siter) } } -static int mpe_sethide(struct part_iter *iter, struct part_iter *miter) +static int fliphide(struct part_iter *iter, struct part_iter *miter) { struct disk_dos_part_entry *dp; static const uint16_t mask @@ -527,34 +527,35 @@ int manglepe_hide(struct part_iter *miter) struct disk_dos_part_entry *dp; int ridx; - if (!opt.hide) + if (!(opt.hide & 1)) return 0; if (miter->type != typedos) { - error("Options '*hide*' is meaningful only for legacy partition scheme.\n"); + error("Option '[un]hide[all]' is meaningful only for legacy (DOS) partition scheme.\n"); return -1; } - if (miter->index < 1) - error("WARNING: It's impossible to unhide a disk.\n"); - if (miter->index > 4 && !(opt.hide & 2)) - error("WARNING: your partition is beyond mbr, so it can't be unhidden without '*hideall'.\n"); + error("WARNING: your partition is logical, so it can't be unhidden without 'unhideall'.\n"); if (!(iter = pi_begin(&miter->di, PIF_STEPALL))) return -1; while (!pi_next(iter) && !werr) { - ridx = iter->index0 + 1; - if (!(opt.hide & 2) && ridx > 4) + ridx = iter->index0; + if (!(opt.hide & 2) && ridx > 3) break; /* skip when we're constrained to pri only */ dp = (struct disk_dos_part_entry *)iter->record; if (dp->ostype) - wb |= mpe_sethide(iter, miter); - - if (ridx >= 4 && wb && !werr) { - push_embr(miter, iter); + wb |= fliphide(iter, miter); + + /* + * we have to update mbr and each extended partition, but only if + * changes (wb) were detected and there was no prior write error (werr) + */ + if (ridx >= 3 && wb && !werr) { + mbrcpy(miter, iter); werr |= disk_write_sectors(&iter->di, iter->dos.cebr_lba, iter->data, 1); wb = 0; } @@ -563,20 +564,20 @@ int manglepe_hide(struct part_iter *miter) if (pi_errored(iter)) goto bail; - /* last write */ + /* last update */ if (wb && !werr) { - push_embr(miter, iter); + mbrcpy(miter, iter); werr |= disk_write_sectors(&iter->di, iter->dos.cebr_lba, iter->data, 1); } if (werr) - error("WARNING: failed to write E/MBR during '*hide*'\n"); + error("WARNING: failed to write E/MBR during '[un]hide[all]'\n"); bail: pi_del(&iter); return 0; } -static int mpe_setchs(const struct disk_info *di, +static int updchs(const struct disk_info *di, struct disk_dos_part_entry *dp, uint32_t lba1) { @@ -607,7 +608,7 @@ int manglepe_fixchs(struct part_iter *miter) return 0; if (miter->type != typedos) { - error("Options 'fixchs' is meaningful only for legacy partition scheme.\n"); + error("Option 'fixchs' is meaningful only for legacy (DOS) partition scheme.\n"); return -1; } @@ -615,15 +616,19 @@ int manglepe_fixchs(struct part_iter *miter) return -1; while (!pi_next(iter) && !werr) { - ridx = iter->index0 + 1; + ridx = iter->index0; dp = (struct disk_dos_part_entry *)iter->record; - wb |= mpe_setchs(&iter->di, dp, (uint32_t)iter->start_lba); - if (ridx > 4) - wb |= mpe_setchs(&iter->di, dp + 1, iter->dos.nebr_lba); + wb |= updchs(&iter->di, dp, (uint32_t)iter->start_lba); + if (ridx > 3) + wb |= updchs(&iter->di, dp + 1, iter->dos.nebr_lba); - if (ridx >= 4 && wb && !werr) { - push_embr(miter, iter); + /* + * we have to update mbr and each extended partition, but only if + * changes (wb) were detected and there was no prior write error (werr) + */ + if (ridx >= 3 && wb && !werr) { + mbrcpy(miter, iter); werr |= disk_write_sectors(&iter->di, iter->dos.cebr_lba, iter->data, 1); wb = 0; } @@ -632,9 +637,9 @@ int manglepe_fixchs(struct part_iter *miter) if (pi_errored(iter)) goto bail; - /* last write */ + /* last update */ if (wb && !werr) { - push_embr(miter, iter); + mbrcpy(miter, iter); werr |= disk_write_sectors(&iter->di, iter->dos.cebr_lba, iter->data, 1); } if (werr) diff --git a/com32/chain/options.c b/com32/chain/options.c index b831afa..d8c601c 100644 --- a/com32/chain/options.c +++ b/com32/chain/options.c @@ -284,15 +284,15 @@ int opt_parse_args(int argc, char *argv[]) } else if (!strcmp(argv[i], "noswap")) { opt.swap = false; } else if (!strcmp(argv[i], "nohide")) { - opt.hide = 0; + opt.hide = 0; /* bit 0 means disabled */ } else if (!strcmp(argv[i], "hide")) { opt.hide = 1; /* 001b */ } else if (!strcmp(argv[i], "hideall")) { - opt.hide = 2; /* 010b */ + opt.hide = 3; /* 011b */ } else if (!strcmp(argv[i], "unhide")) { opt.hide = 5; /* 101b */ } else if (!strcmp(argv[i], "unhideall")) { - opt.hide = 6; /* 110b */ + opt.hide = 7; /* 111b */ } else if (!strcmp(argv[i], "setbpb")) { opt.setbpb = true; } else if (!strcmp(argv[i], "nosetbpb")) { diff --git a/com32/chain/utility.c b/com32/chain/utility.c index d40c0dd..9ec829a 100644 --- a/com32/chain/utility.c +++ b/com32/chain/utility.c @@ -166,14 +166,13 @@ uint32_t get_file_lba(const char *filename) } /* drive offset detection */ -int drvoff_detect(int type, unsigned int *off) +int drvoff_detect(int type) { if (bpbV40 <= type && type <= bpbVNT) { - *off = 0x24; + return 0x24; } else if (type == bpbV70) { - *off = 0x40; - } else - return 0; + return 0x40; + } return -1; } diff --git a/com32/chain/utility.h b/com32/chain/utility.h index a0519b7..4cca1c9 100644 --- a/com32/chain/utility.h +++ b/com32/chain/utility.h @@ -52,7 +52,7 @@ void wait_key(void); void lba2chs(disk_chs *dst, const struct disk_info *di, uint64_t lba, int mode); uint32_t get_file_lba(const char *filename); -int drvoff_detect(int type, unsigned int *off); +int drvoff_detect(int type); int bpb_detect(const uint8_t *bpb, const char *tag); static inline -- 1.7.10.4
Michal Soltys
2012-Nov-06 00:32 UTC
[syslinux] [PATCH 12/23] com32/chain: cleaner variable names
Signed-off-by: Michal Soltys <soltys at ziu.info> --- com32/chain/partiter.c | 23 +++++++++++------------ com32/chain/partiter.h | 7 +++---- 2 files changed, 14 insertions(+), 16 deletions(-) diff --git a/com32/chain/partiter.c b/com32/chain/partiter.c index da96b3d..14e74de 100644 --- a/com32/chain/partiter.c +++ b/com32/chain/partiter.c @@ -177,7 +177,7 @@ static int notsane_logical(const struct part_iter *iter) if (!dp[0].start_lba || !dp[0].length || !sane(dp[0].start_lba, dp[0].length) || - end_log > iter->dos.ebr_size) { + end_log > iter->dos.nebr_siz) { error("Logical partition (in EBR) with invalid offset and/or length.\n"); return -1; @@ -213,7 +213,7 @@ static int notsane_extended(const struct part_iter *iter) if (!dp[1].start_lba || !dp[1].length || !sane(dp[1].start_lba, dp[1].length) || - end_ebr > iter->dos.bebr_size) { + end_ebr > iter->dos.bebr_siz) { error("Extended partition (EBR) with invalid offset and/or length.\n"); return -1; @@ -302,16 +302,14 @@ static int prep_base_ebr(struct part_iter *iter) if (iter->dos.bebr_index0 < 0) /* if we don't have base extended partition at all */ return -1; - else if (!iter->dos.bebr_start) { /* if not initialized yet */ + else if (!iter->dos.bebr_lba) { /* if not initialized yet */ dp = ((struct disk_dos_mbr *)iter->data)->table + iter->dos.bebr_index0; - iter->dos.bebr_start = dp->start_lba; - iter->dos.bebr_size = dp->length; + iter->dos.bebr_lba = dp->start_lba; + iter->dos.bebr_siz = dp->length; - iter->dos.ebr_size = iter->dos.bebr_size; - - iter->dos.cebr_lba = 0; - iter->dos.nebr_lba = iter->dos.bebr_start; + iter->dos.nebr_lba = dp->start_lba; + iter->dos.nebr_siz = dp->length; iter->index0--; } @@ -337,6 +335,7 @@ static int dos_next_ebr(struct part_iter *iter, uint32_t *lba, return -1; } + /* check sanity of loaded data */ if (notsane_logical(iter) || notsane_extended(iter)) { iter->status = PI_INSANE; return -1; @@ -348,11 +347,11 @@ static int dos_next_ebr(struct part_iter *iter, uint32_t *lba, /* setup next frame values */ if (dp[1].ostype) { - iter->dos.ebr_size = dp[1].length; - iter->dos.nebr_lba = iter->dos.bebr_start + dp[1].start_lba; + iter->dos.nebr_lba = iter->dos.bebr_lba + dp[1].start_lba; + iter->dos.nebr_siz = dp[1].length; } else { - iter->dos.ebr_size = 0; iter->dos.nebr_lba = 0; + iter->dos.nebr_siz = 0; } if (!dp[0].ostype) diff --git a/com32/chain/partiter.h b/com32/chain/partiter.h index 61869de..a277ba9 100644 --- a/com32/chain/partiter.h +++ b/com32/chain/partiter.h @@ -76,13 +76,12 @@ struct part_iter { struct { uint32_t disk_sig; /* 32bit disk signature as stored in MBR */ - uint32_t bebr_start; /* abs lba of base extended partition */ - uint32_t bebr_size; /* size of base extended partition */ + uint32_t bebr_lba; /* absolute lba of base extended partition */ + uint32_t bebr_siz; /* size of base extended partition */ uint32_t cebr_lba; /* absolute lba of curr ext. partition */ uint32_t nebr_lba; /* absolute lba of next ext. partition */ - - uint32_t ebr_size; /* size of next extended partition */ + uint32_t nebr_siz; /* size of next ext. partition */ int bebr_index0; /* index of (0-3) of base ext. part., -1 of not present in MBR */ int skipcnt; /* how many logical holes were skipped */ -- 1.7.10.4
Michal Soltys
2012-Nov-06 00:32 UTC
[syslinux] [PATCH 13/23] com32/chain: use disk_guid for part_guid for 0th partition
Initial position of each itarator is whole disk, so this actually matches. Signed-off-by: Michal Soltys <soltys at ziu.info> --- com32/chain/chain.c | 10 +++------- com32/chain/partiter.c | 1 + 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/com32/chain/chain.c b/com32/chain/chain.c index f2f6719..97e1cf8 100644 --- a/com32/chain/chain.c +++ b/com32/chain/chain.c @@ -110,15 +110,11 @@ static int find_by_guid(const struct guid *gpt_guid, pi_del(&boot_part); continue; } - /* Check for a matching GPT disk guid */ - if (!memcmp(&boot_part->gpt.disk_guid, gpt_guid, sizeof(*gpt_guid))) { - goto ok; - } - /* disk guid doesn't match, maybe partition guid will */ - while (!pi_next(boot_part)) { + /* Check for a matching GPT disk/partition guid */ + do { if (!memcmp(&boot_part->gpt.part_guid, gpt_guid, sizeof(*gpt_guid))) goto ok; - } + } while (!pi_next(boot_part)); } drive = -1; ok: diff --git a/com32/chain/partiter.c b/com32/chain/partiter.c index 14e74de..0ebf62d 100644 --- a/com32/chain/partiter.c +++ b/com32/chain/partiter.c @@ -142,6 +142,7 @@ static int pi_gpt_ctor(struct part_iter *iter, iter->gpt.ulast = gpth->lba_last_usable; memcpy(&iter->gpt.disk_guid, &gpth->disk_guid, sizeof(struct guid)); + memcpy(&iter->gpt.part_guid, &gpth->disk_guid, sizeof(struct guid)); iter->type = typegpt; return 0; -- 1.7.10.4
Michal Soltys
2012-Nov-06 00:32 UTC
[syslinux] [PATCH 14/23] com32/chain: warning/error/help/doc tidying
Trivial change that tidies a bit warning / error reporting through fatal()/error()/warn(). Also small doc/help updates. Signed-off-by: Michal Soltys <soltys at ziu.info> --- com32/chain/chain.c | 60 ++++++++++---------- com32/chain/mangle.c | 30 +++++----- com32/chain/options.c | 147 +++++++++++++++++++++++++----------------------- com32/chain/partiter.c | 50 ++++++++-------- com32/chain/utility.h | 20 +++++-- doc/chain.txt | 21 +++---- 6 files changed, 172 insertions(+), 156 deletions(-) diff --git a/com32/chain/chain.c b/com32/chain/chain.c index 97e1cf8..7e1c9d2 100644 --- a/com32/chain/chain.c +++ b/com32/chain/chain.c @@ -168,7 +168,7 @@ static void do_boot(struct data_area *data, int ndata) mmap = syslinux_memory_map(); if (!mmap) { - error("Cannot read system memory map\n"); + error("Cannot read system memory map."); return; } @@ -269,17 +269,17 @@ static void do_boot(struct data_area *data, int ndata) /* Force text mode */ syslinux_force_text_mode(); - fputs("Booting...\n", stdout); + puts("Booting..."); syslinux_shuffle_boot_rm(mlist, mmap, opt.keeppxe, &opt.regs); - error("Chainboot failed!\n"); + error("Chainboot failed !"); return; too_big: - error("Loader file too large\n"); + error("Loader file too large."); return; enomem: - error("Out of memory\n"); + error("Out of memory."); return; } @@ -296,23 +296,23 @@ int find_dp(struct part_iter **_iter) if (!strncmp(opt.drivename, "mbr", 3)) { if (find_by_sig(strtoul(opt.drivename + 4, NULL, 0), &iter) < 0) { - error("Unable to find requested MBR signature.\n"); + error("Unable to find requested MBR signature."); goto bail; } } else if (!strncmp(opt.drivename, "guid", 4)) { if (str_to_guid(opt.drivename + 5, &gpt_guid)) goto bail; if (find_by_guid(&gpt_guid, &iter) < 0) { - error("Unable to find requested GPT disk or partition by guid.\n"); + error("Unable to find requested GPT disk or partition by guid."); goto bail; } } else if (!strncmp(opt.drivename, "label", 5)) { if (!opt.drivename[6]) { - error("No label specified.\n"); + error("No label specified."); goto bail; } if (find_by_label(opt.drivename + 6, &iter) < 0) { - error("Unable to find requested GPT partition by label.\n"); + error("Unable to find requested GPT partition by label."); goto bail; } } else if ((opt.drivename[0] == 'h' || opt.drivename[0] == 'f') && @@ -330,7 +330,7 @@ int find_dp(struct part_iter **_iter) } else if (!strcmp(opt.drivename, "boot") || !strcmp(opt.drivename, "fs")) { if (!is_phys(sdi->c.filesystem)) { error("When syslinux is not booted from physical disk (or its emulation),\n" - "'boot' and 'fs' are meaningless.\n"); + "'boot' and 'fs' are meaningless."); goto bail; } /* offsets match, but in case it changes in the future */ @@ -355,12 +355,12 @@ int find_dp(struct part_iter **_iter) } /* broken part structure or other problems */ if (iter->status) { - error("Can't find myself on the drive I booted from.\n"); + error("Can't find myself on the drive I booted from."); goto bail; } } } else { - error("Unparsable drive specification.\n"); + error("Unparsable drive specification."); goto bail; } /* main options done - only thing left is explicit partition specification, @@ -375,13 +375,13 @@ int find_dp(struct part_iter **_iter) break; } while (!pi_next(iter)); if (iter->status) { - error("Requested disk / partition combination not found.\n"); + error("Requested disk / partition combination not found."); goto bail; } } if (!(iter->di.disk & 0x80) && iter->index) { - error("WARNING: Partitions on floppy devices may not work.\n"); + warn("Partitions on floppy devices may not work."); } *_iter = iter; @@ -410,7 +410,7 @@ static int setup_handover(const struct part_iter *iter, synth_size = sizeof(struct disk_dos_part_entry); ha = malloc(synth_size); if (!ha) { - error("Could not build RAW hand-over record!\n"); + critm(); goto bail; } len = ~0u; @@ -428,7 +428,7 @@ static int setup_handover(const struct part_iter *iter, sizeof(uint32_t) + (uint32_t)iter->gpt.pe_size; ha = malloc(synth_size); if (!ha) { - error("Could not build GPT hand-over record!\n"); + critm(); goto bail; } lba2chs(&ha->start, &iter->di, iter->start_lba, l2c_cadd); @@ -459,7 +459,7 @@ static int setup_handover(const struct part_iter *iter, synth_size = sizeof(struct disk_dos_part_entry); ha = malloc(synth_size); if (!ha) { - error("Could not build MBR hand-over record!\n"); + critm(); goto bail; } memcpy(ha, iter->record, synth_size); @@ -528,11 +528,11 @@ int main(int argc, char *argv[]) fdat.base = (opt.fseg << 4) + opt.foff; if (loadfile(opt.file, &fdat.data, &fdat.size)) { - error("Couldn't read the boot file.\n"); + error("Couldn't read the boot file."); goto bail; } if (fdat.base + fdat.size - 1 > ADDRMAX) { - error("The boot file is too big to load at this address.\n"); + error("The boot file is too big to load at this address."); goto bail; } } @@ -543,22 +543,22 @@ int main(int argc, char *argv[]) sdat.size = iter->di.bps; if (sdat.base + sdat.size - 1 > ADDRMAX) { - error("The sector cannot be loaded at such high address.\n"); + error("The sector cannot be loaded at such high address."); goto bail; } if (!(sdat.data = disk_read_sectors(&iter->di, iter->start_lba, 1))) { - error("Couldn't read the sector.\n"); + error("Couldn't read the sector."); goto bail; } if (opt.save) { if (!(sbck = malloc(sdat.size))) { - error("Couldn't allocate cmp-buf for option 'save'.\n"); + critm(); goto bail; } memcpy(sbck, sdat.data, sdat.size); } if (opt.file && opt.maps && overlap(&fdat, &sdat)) { - error("WARNING: The sector won't be mmapped, as it would conflict with the boot file.\n"); + warn("The sector won't be mmapped, as it would conflict with the boot file."); opt.maps = false; } } @@ -570,8 +570,8 @@ int main(int argc, char *argv[]) /* Verify possible conflicts */ if ( ( opt.file && overlap(&fdat, &hdat)) || ( opt.maps && overlap(&sdat, &hdat)) ) { - error("WARNING: Handover area won't be prepared,\n" - "as it would conflict with the boot file and/or the sector.\n"); + warn("Handover area won't be prepared,\n" + "as it would conflict with the boot file and/or the sector."); opt.hand = false; } } @@ -622,15 +622,15 @@ int main(int argc, char *argv[]) memcpy(data + ndata++, &hdat, sizeof(hdat)); #ifdef DEBUG - printf("iter->di dsk, bps: %X, %u\niter->di lbacnt, C*H*S: %"PRIu64", %u\n" + dprintf("iter->di dsk, bps: %X, %u\niter->di lbacnt, C*H*S: %"PRIu64", %u\n" "iter->di C, H, S: %u, %u, %u\n", iter->di.disk, iter->di.bps, iter->di.lbacnt, iter->di.cyl * iter->di.head * iter->di.spt, iter->di.cyl, iter->di.head, iter->di.spt); - printf("iter idx: %d\n", iter->index); - printf("iter lba: %"PRIu64"\n", iter->start_lba); + dprintf("iter idx: %d\n", iter->index); + dprintf("iter lba: %"PRIu64"\n", iter->start_lba); if (opt.hand) - printf("hand lba: %u\n", + dprintf("hand lba: %u\n", ((struct disk_dos_part_entry *)hdat.data)->start_lba); #endif @@ -642,7 +642,7 @@ int main(int argc, char *argv[]) if (ndata && !opt.brkchain) /* boot only if we actually chainload */ do_boot(data, ndata); else - error("Service-only run completed, exiting.\n"); + puts("Service-only run completed, exiting."); bail: pi_del(&iter); /* Free allocated areas */ diff --git a/com32/chain/mangle.c b/com32/chain/mangle.c index 0eb35b3..f74038d 100644 --- a/com32/chain/mangle.c +++ b/com32/chain/mangle.c @@ -62,7 +62,7 @@ int manglef_isolinux(struct data_area *data) sdi = syslinux_derivative_info(); if (sdi->c.filesystem != SYSLINUX_FS_ISOLINUX) { - error ("The isolinux= option is only valid when run from ISOLINUX.\n"); + error("The isolinux= option is only valid when run from ISOLINUX."); goto bail; } @@ -88,7 +88,7 @@ int manglef_isolinux(struct data_area *data) file_lba = get_file_lba(opt.file); if (file_lba == 0) { - error("Failed to find LBA offset of the boot file\n"); + error("Failed to find LBA offset of the boot file."); goto bail; } /* Set it */ @@ -163,7 +163,7 @@ int manglef_grub(const struct part_iter *iter, struct data_area *data) return 0; if (data->size < sizeof(struct grub_stage2_patch_area)) { - error("The file specified by grub=<loader> is too small to be stage2 of GRUB Legacy.\n"); + error("The file specified by grub=<loader> is too small to be stage2 of GRUB Legacy."); goto bail; } stage2 = data->data; @@ -174,7 +174,7 @@ int manglef_grub(const struct part_iter *iter, struct data_area *data) */ if (stage2->compat_version_major != 3 || stage2->compat_version_minor != 2) { - error("The file specified by grub=<loader> is not a supported stage2 GRUB Legacy binary.\n"); + error("The file specified by grub=<loader> is not a supported stage2 GRUB Legacy binary."); goto bail; } @@ -213,7 +213,7 @@ int manglef_grub(const struct part_iter *iter, struct data_area *data) */ if (opt.grubcfg) { if (strlen(opt.grubcfg) > sizeof(stage2->config_file) - 1) { - error ("The config filename length can't exceed 88 characters.\n"); + error("The config filename length can't exceed 88 characters."); goto bail; } @@ -254,11 +254,11 @@ int manglef_drmk(struct data_area *data) dprintf(" fs_lba offset is %d\n", fs_lba); /* DRMK only uses a DWORD */ if (fs_lba > 0xffffffff) { - error("LBA very large; Only using lower 32 bits; DRMK will probably fail\n"); + error("LBA very large; Only using lower 32 bits; DRMK will probably fail."); } opt.regs.ss = opt.regs.fs = opt.regs.gs = 0; /* Used before initialized */ if (!realloc(data->data, tsize)) { - error("Failed to realloc for DRMK.\n"); + error("Failed to realloc for DRMK."); goto bail; } data->size = tsize; @@ -353,12 +353,12 @@ int manglesf_bss(struct data_area *sec, struct data_area *fil) type2 = bpb_detect(sec->data, "bss/sect"); if (!type1 || !type2) { - error("Couldn't determine the BPB type for option 'bss'.\n"); + error("Couldn't determine the BPB type for option 'bss'."); goto bail; } if (type1 != type2) { error("Option 'bss' can't be used,\n" - "when a sector and a file have incompatible BPBs.\n"); + "when a sector and a file have incompatible BPBs."); goto bail; } @@ -396,7 +396,7 @@ int mangles_save(const struct part_iter *iter, const struct data_area *data, voi if (memcmp(org, data->data, data->size)) { if (disk_write_sectors(&iter->di, iter->start_lba, data->data, 1)) { - error("Cannot write the updated sector.\n"); + error("Cannot write the updated sector."); goto bail; } /* function can be called again */ @@ -531,12 +531,12 @@ int manglepe_hide(struct part_iter *miter) return 0; if (miter->type != typedos) { - error("Option '[un]hide[all]' is meaningful only for legacy (DOS) partition scheme.\n"); + error("Option '[un]hide[all]' works only for legacy (DOS) partition scheme."); return -1; } if (miter->index > 4 && !(opt.hide & 2)) - error("WARNING: your partition is logical, so it can't be unhidden without 'unhideall'.\n"); + warn("Specified partition is logical, so it can't be unhidden without 'unhideall'."); if (!(iter = pi_begin(&miter->di, PIF_STEPALL))) return -1; @@ -570,7 +570,7 @@ int manglepe_hide(struct part_iter *miter) werr |= disk_write_sectors(&iter->di, iter->dos.cebr_lba, iter->data, 1); } if (werr) - error("WARNING: failed to write E/MBR during '[un]hide[all]'\n"); + warn("Failed to write E/MBR during '[un]hide[all]'."); bail: pi_del(&iter); @@ -608,7 +608,7 @@ int manglepe_fixchs(struct part_iter *miter) return 0; if (miter->type != typedos) { - error("Option 'fixchs' is meaningful only for legacy (DOS) partition scheme.\n"); + error("Option 'fixchs' works only for legacy (DOS) partition scheme."); return -1; } @@ -643,7 +643,7 @@ int manglepe_fixchs(struct part_iter *miter) werr |= disk_write_sectors(&iter->di, iter->dos.cebr_lba, iter->data, 1); } if (werr) - error("WARNING: failed to write E/MBR during 'fixchs'\n"); + warn("Failed to write E/MBR during 'fixchs'."); bail: pi_del(&iter); diff --git a/com32/chain/options.c b/com32/chain/options.c index d8c601c..47f63d0 100644 --- a/com32/chain/options.c +++ b/com32/chain/options.c @@ -58,14 +58,14 @@ static int soi_s2n(char *ptr, unsigned int *seg, val = (segval << 4) + offval; if (val < ADDRMIN || val > ADDRMAX) { - error("Invalid seg:off:* address specified..\n"); + error("Invalid seg:off:* address specified."); goto bail; } val = (segval << 4) + ipval; if (ipval > 0xFFFE || val < ADDRMIN || val > ADDRMAX) { - error("Invalid seg:*:ip address specified.\n"); + error("Invalid seg:*:ip address specified."); goto bail; } @@ -83,69 +83,74 @@ bail: static void usage(void) { - unsigned int i; - static const char key[] = "Press any key...\n"; + size_t i; static const char *const usage[] = { -"\ -Usage:\n\ - chain.c32 [options]\n\ - chain.c32 {fd|hd}<disk#>{,| }[<part#>] [options]\n\ - chain.c32 mbr{:|=}<id>{,| }[<part#>] [options]\n\ - chain.c32 guid{:|=}<guid>{,| }[<part#>] [options]\n\ - chain.c32 label{:|=}<label> [<part#>] [options]\n\ - chain.c32 boot{,| }[<part#>] [options]\n\ - chain.c32 fs [options]\n\ -", "\ -\nOptions ('no' prefix specifies default value):\n\ - sect[=<s[:o[:i]]>] Load sector at <s:o>, jump to <s:i>\n\ - - defaults to 0:0x7C00:0x7C00\n\ - - ommited o/i values default to 0\n\ - maps Map loaded sector into real memory\n\ - nosetbpb Fix BPB fields in loaded sector\n\ - nofilebpb Apply 'setbpb' to loaded file\n\ - nosave Write adjusted sector back to disk\n\ - hand Prepare handover area\n\ - nohptr Force ds:si and ds:bp to point to handover area\n\ - noswap Swap drive numbers, if bootdisk is not fd0/hd0\n\ - nohide Disable all hide variations (also the default)\n\ - hide Hide primary partitions, unhide selected partition\n\ - hideall Hide *all* partitions, unhide selected partition\n\ - unhide Unhide primary partitions\n\ - unhideall Unhide *all* partitions\n\ - nofixchs Walk *all* partitions and fix E/MBRs' chs values\n\ - nokeeppxe Keep the PXE and UNDI stacks in memory (PXELINUX)\n\ - nowarn Wait for a keypress to continue chainloading\n\ - - useful to see emited warnings\n\ - nobreak Actually perform the chainloading\n\ -", "\ -\nOptions continued ...\n\ - file=<file> Load and execute <file>\n\ - seg=<s[:o[:i]]> Load file at <s:o>, jump to <s:i>\n\ - - defaults to 0:0x7C00:0x7C00\n\ - - ommited o/i values default to 0\n\ - isolinux=<loader> Load another version of ISOLINUX\n\ - ntldr=<loader> Load Windows NTLDR, SETUPLDR.BIN or BOOTMGR\n\ - reactos=<loader> Load ReactOS's loader\n\ - cmldr=<loader> Load Recovery Console of Windows NT/2K/XP/2003\n\ - freedos=<loader> Load FreeDOS KERNEL.SYS\n\ - msdos=<loader> Load MS-DOS 2.xx - 6.xx IO.SYS\n\ - msdos7=<loader> Load MS-DOS 7+ IO.SYS\n\ - pcdos=<loader> Load PC-DOS IBMBIO.COM\n\ - drmk=<loader> Load DRMK DELLBIO.BIN\n\ - grub=<loader> Load GRUB Legacy stage2\n\ - grubcfg=<filename> Set alternative config filename for GRUB Legacy\n\ - grldr=<loader> Load GRUB4DOS grldr\n\ - bss=<filename> Emulate syslinux's BSS\n\ - bs=<filename> Emulate syslinux's BS\n\ -\nPlease see doc/chain.txt for the detailed documentation.\n\ -" - }; +"Usage:", +"", +" disk + partition selection:", +" chain.c32 [options]", +" chain.c32 hd#[,#] [options]", +" chain.c32 fd#[,#] [options]", +" chain.c32 mbr=<id>[,#] [options]", +" chain.c32 guid=<guid>[,#] [options]", +" chain.c32 boot[,#] [options]", +"", +" direct partition selection:", +" chain.c32 guid=<guid> [options]", +" chain.c32 label=<label> [options]", +" chain.c32 fs [options]", +"", +"You can use ':' instead of '=' and ' ' instead of ','.", +"The default is 'boot,0'.", +"", +"Options:", +" sect[=<s[:o[:i]]>] Load sector at <s:o>, jump to <s:i>", +" - defaults to 0:0x7C00:0x7C00", +" - omitted o/i values default to 0", +" maps Map loaded sector into real memory", +" setbpb Fix BPB fields in loaded sector", +" filebpb Apply 'setbpb' to loaded file", +" save Write adjusted sector back to disk", +" hand Prepare handover area", +" hptr Force ds:si and ds:bp to point to handover area", +" swap Swap drive numbers, if bootdisk is not fd0/hd0", +" nohide Disable all hide variations (default)", +" hide Hide primary partitions, unhide selected partition", +" hideall Hide *all* partitions, unhide selected partition", +" unhide Unhide primary partitions", +" unhideall Unhide *all* partitions", +" fixchs Walk *all* partitions and fix E/MBRs' CHS values", +" keeppxe Keep the PXE and UNDI stacks in memory (PXELINUX)", +" warn Wait for a keypress to continue chainloading", +" break Don't chainload", +"", +" file=<file> Load and execute <file>", +" seg=<s[:o[:i]]> Load file at <s:o>, jump to <s:i>", +" - defaults to 0:0x7C00:0x7C00", +" - omitted o/i values default to 0", +" isolinux=<loader> Load another version of ISOLINUX", +" ntldr=<loader> Load Windows NTLDR, SETUPLDR.BIN or BOOTMGR", +" reactos=<loader> Load ReactOS's loader", +" cmldr=<loader> Load Recovery Console of Windows NT/2K/XP/2003", +" freedos=<loader> Load FreeDOS KERNEL.SYS", +" msdos=<loader> Load MS-DOS 2.xx - 6.xx IO.SYS", +" msdos7=<loader> Load MS-DOS 7+ IO.SYS", +" pcdos=<loader> Load PC-DOS IBMBIO.COM", +" drmk=<loader> Load DRMK DELLBIO.BIN", +" grub=<loader> Load GRUB Legacy stage2", +" grubcfg=<config> Set alternative config filename for GRUB Legacy", +" grldr=<loader> Load GRUB4DOS grldr", +" bss=<sectimage> Emulate syslinux's BSS", +" bs=<sectimage> Emulate syslinux's BS", +"", +"Please see doc/chain.txt for the detailed documentation." +}; for (i = 0; i < sizeof(usage)/sizeof(usage[0]); i++) { - if (i) { - error(key); + if (i % 20 == 19) { + puts("Press any key..."); wait_key(); } - error(usage[i]); + puts(usage[i]); } } @@ -284,15 +289,15 @@ int opt_parse_args(int argc, char *argv[]) } else if (!strcmp(argv[i], "noswap")) { opt.swap = false; } else if (!strcmp(argv[i], "nohide")) { - opt.hide = 0; /* bit 0 means disabled */ + opt.hide = 0b000; } else if (!strcmp(argv[i], "hide")) { - opt.hide = 1; /* 001b */ + opt.hide = 0b001; } else if (!strcmp(argv[i], "hideall")) { - opt.hide = 3; /* 011b */ + opt.hide = 0b011; } else if (!strcmp(argv[i], "unhide")) { - opt.hide = 5; /* 101b */ + opt.hide = 0b101; } else if (!strcmp(argv[i], "unhideall")) { - opt.hide = 7; /* 111b */ + opt.hide = 0b111; } else if (!strcmp(argv[i], "setbpb")) { opt.setbpb = true; } else if (!strcmp(argv[i], "nosetbpb")) { @@ -360,27 +365,27 @@ int opt_parse_args(int argc, char *argv[]) } if (opt.grubcfg && !opt.grub) { - error("grubcfg=<filename> must be used together with grub=<loader>.\n"); + error("grubcfg=<filename> must be used together with grub=<loader>."); goto bail; } if (opt.filebpb && !opt.file) { - error("Option 'filebpb' requires a file.\n"); + error("Option 'filebpb' requires a file."); goto bail; } if (opt.save && !opt.sect) { - error("Option 'save' requires a sector.\n"); + error("Option 'save' requires a sector."); goto bail; } if (opt.setbpb && !opt.sect) { - error("Option 'setbpb' requires a sector.\n"); + error("Option 'setbpb' requires a sector."); goto bail; } if (opt.maps && !opt.sect) { - error("Option 'maps' requires a sector.\n"); + error("Option 'maps' requires a sector."); goto bail; } diff --git a/com32/chain/partiter.c b/com32/chain/partiter.c index 0ebf62d..8ee00f8 100644 --- a/com32/chain/partiter.c +++ b/com32/chain/partiter.c @@ -103,8 +103,10 @@ static int pi_dos_ctor(struct part_iter *iter, if (pi_ctor(iter, di, flags)) return -1; - if (!(iter->data = malloc(sizeof(struct disk_dos_mbr)))) + if (!(iter->data = malloc(sizeof(struct disk_dos_mbr)))) { + critm(); goto bail; + } memcpy(iter->data, mbr, sizeof(struct disk_dos_mbr)); @@ -131,8 +133,10 @@ static int pi_gpt_ctor(struct part_iter *iter, siz = (uint64_t)gpth->part_count * gpth->part_size; - if (!(iter->data = malloc((size_t)siz))) + if (!(iter->data = malloc((size_t)siz))) { + critm(); goto bail; + } memcpy(iter->data, gptl, (size_t)siz); @@ -169,7 +173,7 @@ static int notsane_logical(const struct part_iter *iter) return 0; if (ost_is_ext(dp[0].ostype)) { - error("1st EBR entry must be data or empty.\n"); + error("The 1st EBR entry must be data or empty."); return -1; } @@ -180,7 +184,7 @@ static int notsane_logical(const struct part_iter *iter) !sane(dp[0].start_lba, dp[0].length) || end_log > iter->dos.nebr_siz) { - error("Logical partition (in EBR) with invalid offset and/or length.\n"); + error("Logical partition (in EBR) with invalid offset and/or length."); return -1; } @@ -205,7 +209,7 @@ static int notsane_extended(const struct part_iter *iter) return 0; if (!ost_is_nondata(dp[1].ostype)) { - error("The 2nd EBR entry must be extended or empty.\n"); + error("The 2nd EBR entry must be extended or empty."); return -1; } @@ -216,7 +220,7 @@ static int notsane_extended(const struct part_iter *iter) !sane(dp[1].start_lba, dp[1].length) || end_ebr > iter->dos.bebr_siz) { - error("Extended partition (EBR) with invalid offset and/or length.\n"); + error("Extended partition (EBR) with invalid offset and/or length."); return -1; } @@ -240,7 +244,7 @@ static int notsane_primary(const struct part_iter *iter) !dp->length || !sane(dp->start_lba, dp->length) || dp->start_lba + dp->length > iter->di.lbacnt) { - error("Primary partition (in MBR) with invalid offset and/or length.\n"); + error("Primary partition (in MBR) with invalid offset and/or length."); return -1; } @@ -258,7 +262,7 @@ static int notsane_gpt(const struct part_iter *iter) if (gp->lba_first < iter->gpt.ufirst || gp->lba_last > iter->gpt.ulast) { - error("LBA sectors of GPT partition are beyond the range allowed in GPT header.\n"); + error("LBA sectors of GPT partition are beyond the range allowed in GPT header."); return -1; } @@ -280,7 +284,7 @@ static int dos_next_mbr(struct part_iter *iter, uint32_t *lba, if (ost_is_ext(dp->ostype)) { if (iter->dos.bebr_index0 >= 0) { - error("More than 1 extended partition.\n"); + error("More than 1 extended partition."); iter->status = PI_INSANE; return -1; } @@ -331,7 +335,7 @@ static int dos_next_ebr(struct part_iter *iter, uint32_t *lba, free(iter->data); if (!(iter->data disk_read_sectors(&iter->di, iter->dos.nebr_lba, 1))) { - error("Couldn't load EBR.\n"); + error("Couldn't load EBR."); iter->status = PI_ERRLOAD; return -1; } @@ -405,18 +409,18 @@ static int gpt_check_hdr_crc(const struct disk_info * const diskinfo, struct dis hold_crc32 = gh->chksum; gh->chksum = 0; if (!valid_crc(hold_crc32, (const uint8_t *)gh, gh->hdr_size)) { - error("WARNING: Primary GPT header checksum invalid.\n"); + warn("Primary GPT header checksum invalid."); /* retry with backup */ lba_alt = gh->lba_alt; free(gh); if (!(gh = *_gh = disk_read_sectors(diskinfo, lba_alt, 1))) { - error("Couldn't read backup GPT header.\n"); + error("Couldn't read backup GPT header."); return -1; } hold_crc32 = gh->chksum; gh->chksum = 0; if (!valid_crc(hold_crc32, (const uint8_t *)gh, gh->hdr_size)) { - error("Secondary GPT header checksum invalid.\n"); + error("Secondary GPT header checksum invalid."); return -1; } } @@ -514,7 +518,7 @@ static struct part_iter *pi_alloc(void) { struct part_iter *iter; if (!(iter = malloc(sizeof(struct part_iter)))) - error("Couldn't allocate memory for the iterator.\n"); + critm(); else memset(iter, 0, sizeof(struct part_iter)); return iter; @@ -545,13 +549,13 @@ struct part_iter *pi_begin(const struct disk_info *di, int flags) /* Read MBR */ if (!(mbr = disk_read_sectors(di, 0, 1))) { - error("Couldn't read first disk sector.\n"); + error("Couldn't read the first disk sector."); goto bail; } /* Check for MBR magic */ if (mbr->sig != disk_mbr_sig_magic) { - error("WARNING: no MBR magic, treating disk as raw.\n"); + warn("No MBR magic, treating disk as raw."); /* looks like RAW */ ret = pi_ctor(iter, di, flags); goto bail; @@ -560,7 +564,7 @@ struct part_iter *pi_begin(const struct disk_info *di, int flags) /* Check for GPT protective MBR */ if (mbr->table[0].ostype == 0xEE) { if (!(gpth = disk_read_sectors(di, 1, 1))) { - error("Couldn't read potential GPT header.\n"); + error("Couldn't read potential GPT header."); goto bail; } } @@ -572,7 +576,7 @@ struct part_iter *pi_begin(const struct disk_info *di, int flags) uint64_t gpt_lsiz; /* size of GPT partition list in bytes */ uint64_t gpt_lcnt; /* size of GPT partition in sectors */ #ifdef DEBUG - puts("Looks like a GPT v1.0 disk."); + dprintf("Looks like a GPT v1.0 disk.\n"); disk_gpt_header_dump(gpth); #endif /* Verify checksum, fallback to backup, then bail if invalid */ @@ -596,24 +600,24 @@ struct part_iter *pi_begin(const struct disk_info *di, int flags) gpth->lba_last_usable + gpt_lcnt >= gpth->lba_alt || gpth->lba_alt >= di->lbacnt || gpth->part_size < sizeof(struct disk_gpt_part_entry)) { - error("Invalid GPT header's values.\n"); + error("Invalid GPT header's values."); goto bail; } if (!(gptl = disk_read_sectors(di, gpt_loff, (uint8_t)gpt_lcnt))) { - error("Couldn't read GPT partition list.\n"); + error("Couldn't read GPT partition list."); goto bail; } /* Check array checksum(s). */ if (!valid_crc(gpth->table_chksum, (const uint8_t *)gptl, (unsigned int)gpt_lsiz)) { - error("Checksum of the main GPT partition list is invalid, trying backup.\n"); + warn("Checksum of the main GPT partition list is invalid, trying backup."); free(gptl); /* secondary array directly precedes secondary header */ if (!(gptl = disk_read_sectors(di, gpth->lba_alt - gpt_lcnt, (uint8_t)gpt_lcnt))) { - error("Couldn't read backup GPT partition list.\n"); + error("Couldn't read backup GPT partition list."); goto bail; } if (!valid_crc(gpth->table_chksum, (const uint8_t *)gptl, (unsigned int)gpt_lsiz)) { - error("Checksum of the backup GPT partition list is invalid, giving up.\n"); + error("Checksum of the backup GPT partition list is invalid, giving up."); goto bail; } } diff --git a/com32/chain/utility.h b/com32/chain/utility.h index 4cca1c9..24959d3 100644 --- a/com32/chain/utility.h +++ b/com32/chain/utility.h @@ -55,14 +55,24 @@ uint32_t get_file_lba(const char *filename); int drvoff_detect(int type); int bpb_detect(const uint8_t *bpb, const char *tag); -static inline -void error(const char *msg) +static inline int warn(const char *x) { - fputs(msg, stderr); + return fprintf(stderr, "WARN: %s\n", x); } -static inline -int guid_is0(const struct guid *guid) +static inline int error(const char *x) +{ + return fprintf(stderr, "ERR: %s\n", x); +} + +static inline int crit(const char *x) +{ + return fprintf(stderr, "CRIT: %s @%s:%d\n", x, __FILE__, __LINE__); +} + +#define critm() crit("Malloc failure.") + +static inline int guid_is0(const struct guid *guid) { return !*(const uint64_t *)guid && !*((const uint64_t *)guid + 1); } diff --git a/doc/chain.txt b/doc/chain.txt index 6dd0632..e71b1c0 100644 --- a/doc/chain.txt +++ b/doc/chain.txt @@ -53,29 +53,27 @@ Module invocation: chain [drive/partition] [options] +In case of repeated arguments, rightmost ones take precedence. + + DRIVE / PARTITION SPECIFICATION Drive can be specified as 'hd#', 'fd#', 'boot', 'mbr', or 'guid'. -- 'mbr' will select a drive by a signature. -- 'guid' will select a drive by a guid +- 'mbr' will select a drive by its signature. +- 'guid' will select a drive by its guid (GPT only). - 'boot' is the drive syslinux was booted from. This is the default value, if nothing else is specified. - 'hd#' and 'fd#' are standard ways to specify drive number as seen by bios, starting from 0. -Option 'guid' is shared with partition selection (see below). If you happened +Option 'guid' is shared with partition selection (see below). If you happen to have non-unique guids, they are searched in disk0, partitions of disk0, disk1 ... order. -The priority of those options are the same as in the above list. - -If you specify the same value more than once, the last value will be used. - 'mbr' and 'guid' take extra parameter - you should use ':' or '=' as a delimiter. - Partition can be specified as '#', 'guid', 'label' or 'fs'. - 'guid' option will select a partition by a guid (not a type guid !) @@ -85,11 +83,10 @@ Partition can be specified as '#', 'guid', 'label' or 'fs'. - '#' is the standard method. Partitions 1-4 are primary, 5+ logical, 0 = boot MBR (default). -The priority of those options are the same as in the above list. - If you use a number to select a partition it should be specified after a drive using space or comma as delimiters (after 'hd#', 'fd#', 'mbr', 'guid' or 'boot'). + OPTIONS file=<file> *nofile @@ -110,7 +107,7 @@ This triplet lets you alter the addresses a file will use. It's loaded at other bootloader or kernel, it's almost always mandatory. The defaults, if option is not specified, are 0:0x7c00:0x7c00 -If any of the fields are ommited (e.g. 0x2000::), they default to 0. +If any of the fields are omitted (e.g. 0x2000::), they default to 0. sect=<segment>:<offset>:<ip> nosect @@ -126,7 +123,7 @@ expect relocated sector at some particular address (e.g. DRKM). is being chainloaded, sector is not necessary. The defaults if option is not specified, are 0:0x7c00:0x7c00. -If some of the fields are ommited (e.g. 0x2000::), they default to 0. +If some of the fields are omitted (e.g. 0x2000::), they default to 0. *maps nomaps -- 1.7.10.4
Michal Soltys
2012-Nov-06 00:32 UTC
[syslinux] [PATCH 15/23] com32/chain: implement relax flag
This flag tones down sanity checks during partition iteration. This is useful in situations such as: - inconsistent layouts, but with some partition still in sane bootable state - usb sticks/disks moved between different PCs might return different size, which might cause problems if the partitions span the whole disk Signed-off-by: Michal Soltys <soltys at ziu.info> --- com32/chain/chain.c | 10 +++++----- com32/chain/mangle.c | 4 ++-- com32/chain/options.c | 6 ++++++ com32/chain/options.h | 1 + com32/chain/partiter.c | 17 +++++++++++++++-- com32/chain/partiter.h | 1 + doc/chain.txt | 14 ++++++++++++-- 7 files changed, 42 insertions(+), 11 deletions(-) diff --git a/com32/chain/chain.c b/com32/chain/chain.c index 7e1c9d2..2c8c583 100644 --- a/com32/chain/chain.c +++ b/com32/chain/chain.c @@ -72,7 +72,7 @@ static int find_by_sig(uint32_t mbr_sig, for (drive = 0x80; drive < 0x80 + fixed_cnt; drive++) { if (disk_get_params(drive, &diskinfo)) continue; /* Drive doesn't exist */ - if (!(boot_part = pi_begin(&diskinfo, 0))) + if (!(boot_part = pi_begin(&diskinfo, opt.relax))) continue; /* Check for a MBR disk */ if (boot_part->type != typedos) { @@ -103,7 +103,7 @@ static int find_by_guid(const struct guid *gpt_guid, for (drive = 0x80; drive < 0x80 + fixed_cnt; drive++) { if (disk_get_params(drive, &diskinfo)) continue; /* Drive doesn't exist */ - if (!(boot_part = pi_begin(&diskinfo, 0))) + if (!(boot_part = pi_begin(&diskinfo, opt.relax))) continue; /* Check for a GPT disk */ if (boot_part->type != typegpt) { @@ -135,7 +135,7 @@ static int find_by_label(const char *label, struct part_iter **_boot_part) for (drive = 0x80; drive < 0x80 + fixed_cnt; drive++) { if (disk_get_params(drive, &diskinfo)) continue; /* Drive doesn't exist */ - if (!(boot_part = pi_begin(&diskinfo, 0))) + if (!(boot_part = pi_begin(&diskinfo, opt.relax))) continue; /* Check for a GPT disk */ if (!(boot_part->type == typegpt)) { @@ -324,7 +324,7 @@ int find_dp(struct part_iter **_iter) if (disk_get_params(drive, &diskinfo)) goto bail; /* this will start iteration over FDD, possibly raw */ - if (!(iter = pi_begin(&diskinfo, 0))) + if (!(iter = pi_begin(&diskinfo, opt.relax))) goto bail; } else if (!strcmp(opt.drivename, "boot") || !strcmp(opt.drivename, "fs")) { @@ -344,7 +344,7 @@ int find_dp(struct part_iter **_iter) if (disk_get_params(drive, &diskinfo)) goto bail; /* this will start iteration over disk emulation, possibly raw */ - if (!(iter = pi_begin(&diskinfo, 0))) + if (!(iter = pi_begin(&diskinfo, opt.relax))) goto bail; /* 'fs' => we should lookup the syslinux partition number and use it */ diff --git a/com32/chain/mangle.c b/com32/chain/mangle.c index f74038d..ca83d93 100644 --- a/com32/chain/mangle.c +++ b/com32/chain/mangle.c @@ -538,7 +538,7 @@ int manglepe_hide(struct part_iter *miter) if (miter->index > 4 && !(opt.hide & 2)) warn("Specified partition is logical, so it can't be unhidden without 'unhideall'."); - if (!(iter = pi_begin(&miter->di, PIF_STEPALL))) + if (!(iter = pi_begin(&miter->di, PIF_STEPALL | opt.relax))) return -1; while (!pi_next(iter) && !werr) { @@ -612,7 +612,7 @@ int manglepe_fixchs(struct part_iter *miter) return -1; } - if (!(iter = pi_begin(&miter->di, PIF_STEPALL))) + if (!(iter = pi_begin(&miter->di, PIF_STEPALL | opt.relax))) return -1; while (!pi_next(iter) && !werr) { diff --git a/com32/chain/options.c b/com32/chain/options.c index 47f63d0..ac715bb 100644 --- a/com32/chain/options.c +++ b/com32/chain/options.c @@ -33,6 +33,7 @@ #include <string.h> #include "common.h" #include "chain.h" +#include "partiter.h" #include "utility.h" #include "options.h" @@ -123,6 +124,7 @@ static void usage(void) " keeppxe Keep the PXE and UNDI stacks in memory (PXELINUX)", " warn Wait for a keypress to continue chainloading", " break Don't chainload", +" relax Relax sanity checks", "", " file=<file> Load and execute <file>", " seg=<s[:o[:i]]> Load file at <s:o>, jump to <s:i>", @@ -324,6 +326,10 @@ int opt_parse_args(int argc, char *argv[]) opt.fixchs = true; } else if (!strcmp(argv[i], "nofixchs")) { opt.fixchs = false; + } else if (!strcmp(argv[i], "relax")) { + opt.relax = PIF_RELAX; + } else if (!strcmp(argv[i], "norelax")) { + opt.relax = 0; } else if (!strcmp(argv[i], "warn")) { opt.warn = true; } else if (!strcmp(argv[i], "nowarn")) { diff --git a/com32/chain/options.h b/com32/chain/options.h index 083713b..4367e18 100644 --- a/com32/chain/options.h +++ b/com32/chain/options.h @@ -62,6 +62,7 @@ struct options { bool filebpb; bool fixchs; bool warn; + int relax; bool brkchain; uint16_t keeppxe; struct syslinux_rm_regs regs; diff --git a/com32/chain/partiter.c b/com32/chain/partiter.c index 8ee00f8..9ff0c65 100644 --- a/com32/chain/partiter.c +++ b/com32/chain/partiter.c @@ -177,6 +177,9 @@ static int notsane_logical(const struct part_iter *iter) return -1; } + if (iter->flags & PIF_RELAX) + return 0; + end_log = dp[0].start_lba + dp[0].length; if (!dp[0].start_lba || @@ -213,6 +216,9 @@ static int notsane_extended(const struct part_iter *iter) return -1; } + if (iter->flags & PIF_RELAX) + return 0; + end_ebr = dp[1].start_lba + dp[1].length; if (!dp[1].start_lba || @@ -240,6 +246,9 @@ static int notsane_primary(const struct part_iter *iter) if (!dp->ostype) return 0; + if (iter->flags & PIF_RELAX) + return 0; + if (!dp->start_lba || !dp->length || !sane(dp->start_lba, dp->length) || @@ -260,6 +269,9 @@ static int notsane_gpt(const struct part_iter *iter) if (guid_is0(&gp->type)) return 0; + if (iter->flags & PIF_RELAX) + return 0; + if (gp->lba_first < iter->gpt.ufirst || gp->lba_last > iter->gpt.ulast) { error("LBA sectors of GPT partition are beyond the range allowed in GPT header."); @@ -592,14 +604,15 @@ struct part_iter *pi_begin(const struct disk_info *di, int flags) * it as a sanity check base. EFI doesn't specify max (AFAIK). * Apart from that, some extensive sanity checks. */ - if (!gpt_loff || !gpt_lsiz || gpt_lcnt > 255u || + if (!(flags & PIF_RELAX) && ( + !gpt_loff || !gpt_lsiz || gpt_lcnt > 255u || gpth->lba_first_usable > gpth->lba_last_usable || !sane(gpt_loff, gpt_lcnt) || gpt_loff + gpt_lcnt > gpth->lba_first_usable || !sane(gpth->lba_last_usable, gpt_lcnt) || gpth->lba_last_usable + gpt_lcnt >= gpth->lba_alt || gpth->lba_alt >= di->lbacnt || - gpth->part_size < sizeof(struct disk_gpt_part_entry)) { + gpth->part_size < sizeof(struct disk_gpt_part_entry))) { error("Invalid GPT header's values."); goto bail; } diff --git a/com32/chain/partiter.h b/com32/chain/partiter.h index a277ba9..67ac9af 100644 --- a/com32/chain/partiter.h +++ b/com32/chain/partiter.h @@ -50,6 +50,7 @@ /* flags */ #define PIF_STEPALL 0x01 +#define PIF_RELAX 0x02 struct itertype; struct part_iter; diff --git a/doc/chain.txt b/doc/chain.txt index e71b1c0..d3c012c 100644 --- a/doc/chain.txt +++ b/doc/chain.txt @@ -110,8 +110,8 @@ The defaults, if option is not specified, are 0:0x7c00:0x7c00 If any of the fields are omitted (e.g. 0x2000::), they default to 0. sect=<segment>:<offset>:<ip> - nosect *sect=0:0x7c00:0x7c00 + nosect nosect sets: nomaps This triplet lets you alter the addresses a sector will use. It's loaded at @@ -226,8 +226,18 @@ stacks in memory (pxelinux only). This option will wait for a keypress right before continuing the chainloading. Useful to see warnings emited by the chain module. - *nobreak + relax + *norelax + +This option inhibits sanity checks during the traversal of the partition table. +This is potentially useful in corner cases, when for example an usb stick moved +to some different computer would report smaller size than previously with +partitions spanning the whole space. Normally partition iterator would report +an error and abort in such case. Another case scenario is disk corruption in +some later EMBR partition. + break + *nobreak break sets: nofile nomaps nohand It is possible to trigger a "service-only" run - The chain module will do -- 1.7.10.4
Michal Soltys
2012-Nov-06 00:32 UTC
[syslinux] [PATCH 16/23] com32/chain: implement handling of non-standard hybrid GPT+MBR layouts
We also take a bit relaxed approach - so we check for presence of 0xEE at any place, then attempt to read GPT header only if prefmbr is not set. Signed-off-by: Michal Soltys <soltys at ziu.info> --- com32/chain/chain.c | 10 +++++----- com32/chain/mangle.c | 4 ++-- com32/chain/options.c | 5 +++++ com32/chain/options.h | 15 ++++++++------- com32/chain/partiter.c | 7 +++++-- com32/chain/partiter.h | 5 +++-- doc/chain.txt | 6 ++++++ 7 files changed, 34 insertions(+), 18 deletions(-) diff --git a/com32/chain/chain.c b/com32/chain/chain.c index 2c8c583..5c7b36f 100644 --- a/com32/chain/chain.c +++ b/com32/chain/chain.c @@ -72,7 +72,7 @@ static int find_by_sig(uint32_t mbr_sig, for (drive = 0x80; drive < 0x80 + fixed_cnt; drive++) { if (disk_get_params(drive, &diskinfo)) continue; /* Drive doesn't exist */ - if (!(boot_part = pi_begin(&diskinfo, opt.relax))) + if (!(boot_part = pi_begin(&diskinfo, opt.relax | opt.prefmbr))) continue; /* Check for a MBR disk */ if (boot_part->type != typedos) { @@ -103,7 +103,7 @@ static int find_by_guid(const struct guid *gpt_guid, for (drive = 0x80; drive < 0x80 + fixed_cnt; drive++) { if (disk_get_params(drive, &diskinfo)) continue; /* Drive doesn't exist */ - if (!(boot_part = pi_begin(&diskinfo, opt.relax))) + if (!(boot_part = pi_begin(&diskinfo, opt.relax | opt.prefmbr))) continue; /* Check for a GPT disk */ if (boot_part->type != typegpt) { @@ -135,7 +135,7 @@ static int find_by_label(const char *label, struct part_iter **_boot_part) for (drive = 0x80; drive < 0x80 + fixed_cnt; drive++) { if (disk_get_params(drive, &diskinfo)) continue; /* Drive doesn't exist */ - if (!(boot_part = pi_begin(&diskinfo, opt.relax))) + if (!(boot_part = pi_begin(&diskinfo, opt.relax | opt.prefmbr))) continue; /* Check for a GPT disk */ if (!(boot_part->type == typegpt)) { @@ -324,7 +324,7 @@ int find_dp(struct part_iter **_iter) if (disk_get_params(drive, &diskinfo)) goto bail; /* this will start iteration over FDD, possibly raw */ - if (!(iter = pi_begin(&diskinfo, opt.relax))) + if (!(iter = pi_begin(&diskinfo, opt.relax | opt.prefmbr))) goto bail; } else if (!strcmp(opt.drivename, "boot") || !strcmp(opt.drivename, "fs")) { @@ -344,7 +344,7 @@ int find_dp(struct part_iter **_iter) if (disk_get_params(drive, &diskinfo)) goto bail; /* this will start iteration over disk emulation, possibly raw */ - if (!(iter = pi_begin(&diskinfo, opt.relax))) + if (!(iter = pi_begin(&diskinfo, opt.relax | opt.prefmbr))) goto bail; /* 'fs' => we should lookup the syslinux partition number and use it */ diff --git a/com32/chain/mangle.c b/com32/chain/mangle.c index ca83d93..c7e09eb 100644 --- a/com32/chain/mangle.c +++ b/com32/chain/mangle.c @@ -538,7 +538,7 @@ int manglepe_hide(struct part_iter *miter) if (miter->index > 4 && !(opt.hide & 2)) warn("Specified partition is logical, so it can't be unhidden without 'unhideall'."); - if (!(iter = pi_begin(&miter->di, PIF_STEPALL | opt.relax))) + if (!(iter = pi_begin(&miter->di, PIF_STEPALL | opt.relax | opt.prefmbr))) return -1; while (!pi_next(iter) && !werr) { @@ -612,7 +612,7 @@ int manglepe_fixchs(struct part_iter *miter) return -1; } - if (!(iter = pi_begin(&miter->di, PIF_STEPALL | opt.relax))) + if (!(iter = pi_begin(&miter->di, PIF_STEPALL | opt.relax | opt.prefmbr))) return -1; while (!pi_next(iter) && !werr) { diff --git a/com32/chain/options.c b/com32/chain/options.c index ac715bb..942a398 100644 --- a/com32/chain/options.c +++ b/com32/chain/options.c @@ -125,6 +125,7 @@ static void usage(void) " warn Wait for a keypress to continue chainloading", " break Don't chainload", " relax Relax sanity checks", +" prefmbr On hybrid MBR/GPT disks, prefer legacy layout", "", " file=<file> Load and execute <file>", " seg=<s[:o[:i]]> Load file at <s:o>, jump to <s:i>", @@ -334,6 +335,10 @@ int opt_parse_args(int argc, char *argv[]) opt.warn = true; } else if (!strcmp(argv[i], "nowarn")) { opt.warn = false; + } else if (!strcmp(argv[i], "prefmbr")) { + opt.prefmbr = PIF_PREFMBR; + } else if (!strcmp(argv[i], "noprefmbr")) { + opt.prefmbr = 0; } else if (!strcmp(argv[i], "nobreak")) { opt.brkchain = false; } else if (!strcmp(argv[i], "break")) { diff --git a/com32/chain/options.h b/com32/chain/options.h index 4367e18..bec1e2c 100644 --- a/com32/chain/options.h +++ b/com32/chain/options.h @@ -35,16 +35,20 @@ #include <syslinux/bootrm.h> struct options { + const char *drivename; + const char *partition; + const char *file; + const char *grubcfg; unsigned int fseg; unsigned int foff; unsigned int fip; unsigned int sseg; unsigned int soff; unsigned int sip; - const char *drivename; - const char *partition; - const char *file; - const char *grubcfg; + int hide; + int relax; + int prefmbr; + uint16_t keeppxe; bool isolinux; bool cmldr; bool drmk; @@ -54,7 +58,6 @@ struct options { bool hand; bool hptr; bool swap; - int hide; bool sect; bool save; bool bss; @@ -62,9 +65,7 @@ struct options { bool filebpb; bool fixchs; bool warn; - int relax; bool brkchain; - uint16_t keeppxe; struct syslinux_rm_regs regs; }; diff --git a/com32/chain/partiter.c b/com32/chain/partiter.c index 9ff0c65..d8d65e7 100644 --- a/com32/chain/partiter.c +++ b/com32/chain/partiter.c @@ -549,7 +549,7 @@ void pi_del(struct part_iter **_iter) /* pi_begin() - validate and and get proper iterator for a disk described by di */ struct part_iter *pi_begin(const struct disk_info *di, int flags) { - int ret = -1; + int gptprot, ret = -1; struct part_iter *iter; struct disk_dos_mbr *mbr = NULL; struct disk_gpt_header *gpth = NULL; @@ -574,7 +574,10 @@ struct part_iter *pi_begin(const struct disk_info *di, int flags) } /* Check for GPT protective MBR */ - if (mbr->table[0].ostype == 0xEE) { + gptprot = 0; + for (size_t i = 0; i < 4; i++) + gptprot |= (mbr->table[i].ostype == 0xEE); + if (gptprot && !(flags & PIF_PREFMBR)) { if (!(gpth = disk_read_sectors(di, 1, 1))) { error("Couldn't read potential GPT header."); goto bail; diff --git a/com32/chain/partiter.h b/com32/chain/partiter.h index 67ac9af..21444e1 100644 --- a/com32/chain/partiter.h +++ b/com32/chain/partiter.h @@ -49,8 +49,9 @@ /* flags */ -#define PIF_STEPALL 0x01 -#define PIF_RELAX 0x02 +#define PIF_STEPALL 0b001 +#define PIF_RELAX 0b010 +#define PIF_PREFMBR 0b100 struct itertype; struct part_iter; diff --git a/doc/chain.txt b/doc/chain.txt index d3c012c..2321c10 100644 --- a/doc/chain.txt +++ b/doc/chain.txt @@ -226,6 +226,12 @@ stacks in memory (pxelinux only). This option will wait for a keypress right before continuing the chainloading. Useful to see warnings emited by the chain module. + prefmbr + *noprefmbr + +In the case of presence of non-standard hybrid MBR/GPT layout, this flag makes +chain module prefer MBR layout over GPT. + relax *norelax -- 1.7.10.4
The usual stuff - hidden sectors (now 64bit at different offset), drive offest, "BPB" type. Formally (?) region from 0x0B to 0x3F should be 0, but ... it's tempting to fill "old" values there. Might be worth adding a switch to handle such behavior. Signed-off-by: Michal Soltys <soltys at ziu.info> --- com32/chain/mangle.c | 13 +++++++++---- com32/chain/utility.c | 9 +++++++++ com32/chain/utility.h | 1 + 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/com32/chain/mangle.c b/com32/chain/mangle.c index c7e09eb..bcd31e0 100644 --- a/com32/chain/mangle.c +++ b/com32/chain/mangle.c @@ -279,24 +279,27 @@ static int mangle_bpb(const struct part_iter *iter, struct data_area *data, cons int type = bpb_detect(data->data, tag); int off = drvoff_detect(type); + /* BPB: hidden sectors 64bit - exFAT only for now */ + if (type == bpbEXF) + *(uint64_t *) ((char *)data->data + 0x40) = iter->start_lba; /* BPB: hidden sectors 32bit*/ - if (type >= bpbV34) { + else if (bpbV34 <= type && type <= bpbV70) { if (iter->start_lba < ~0u) *(uint32_t *) ((char *)data->data + 0x1c) = (uint32_t)iter->start_lba; else /* won't really help much, but ... */ *(uint32_t *) ((char *)data->data + 0x1c) = ~0u; - } /* BPB: hidden sectors 16bit*/ - if (bpbV30 <= type && type <= bpbV32) { + } else if (bpbV30 <= type && type <= bpbV32) { if (iter->start_lba < 0xFFFF) *(uint16_t *) ((char *)data->data + 0x1c) = (uint16_t)iter->start_lba; else /* won't really help much, but ... */ *(uint16_t *) ((char *)data->data + 0x1c) = (uint16_t)~0u; } + /* BPB: legacy geometry */ - if (type >= bpbV30) { + if (bpbV30 <= type && type <= bpbV70) { if (iter->di.cbios) *(uint32_t *)((char *)data->data + 0x18) = (uint32_t)((iter->di.head << 16) | iter->di.spt); else { @@ -378,6 +381,8 @@ int manglesf_bss(struct data_area *sec, struct data_area *fil) cnt = 0x3C; } else if (type1 <= bpbV70) { cnt = 0x42; + } else if (type1 <= bpbEXF) { + cnt = 0x60; } memcpy((char *)fil->data + 0x18, (char *)sec->data + 0x18, cnt); diff --git a/com32/chain/utility.c b/com32/chain/utility.c index 9ec829a..abf642c 100644 --- a/com32/chain/utility.c +++ b/com32/chain/utility.c @@ -46,6 +46,7 @@ static const char *bpbtypes[] = { [5] = "4.0", [6] = "8.0 (NT+)", [7] = "7.0", + [8] = "exFAT", }; void wait_key(void) @@ -172,6 +173,8 @@ int drvoff_detect(int type) return 0x24; } else if (type == bpbV70) { return 0x40; + } else if (type == bpbEXF) { + return 0x6F; } return -1; @@ -184,6 +187,12 @@ int bpb_detect(const uint8_t *sec, const char *tag) { int a, b, c, jmp = -1, rev = 0; + /* exFAT mess first (media descriptor is 0 here) */ + if (!memcmp(sec + 0x03, "EXFAT ", 8)) { + rev = bpbEXF; + goto out; + } + /* media descriptor check */ if ((sec[0x15] & 0xF0) != 0xF0) goto out; diff --git a/com32/chain/utility.h b/com32/chain/utility.h index 24959d3..a5b06cc 100644 --- a/com32/chain/utility.h +++ b/com32/chain/utility.h @@ -43,6 +43,7 @@ #define bpbV40 5 #define bpbVNT 6 #define bpbV70 7 +#define bpbEXF 8 /* see utility.c for details */ #define l2c_cnul 0 -- 1.7.10.4
Only 2 defines there related to preliminary options.c's and chain.c's hecks (real checks come later during mapping to real memory). So move them to options.h and remove common.h. Signed-off-by: Michal Soltys <soltys at ziu.info> --- com32/chain/chain.c | 1 - com32/chain/common.h | 39 --------------------------------------- com32/chain/mangle.c | 1 - com32/chain/options.c | 1 - com32/chain/options.h | 3 +++ com32/chain/partiter.c | 1 - 6 files changed, 3 insertions(+), 43 deletions(-) delete mode 100644 com32/chain/common.h diff --git a/com32/chain/chain.c b/com32/chain/chain.c index 5c7b36f..38e647c 100644 --- a/com32/chain/chain.c +++ b/com32/chain/chain.c @@ -34,7 +34,6 @@ #include <syslinux/config.h> #include <syslinux/disk.h> #include <syslinux/video.h> -#include "common.h" #include "chain.h" #include "utility.h" #include "options.h" diff --git a/com32/chain/common.h b/com32/chain/common.h deleted file mode 100644 index 8437bc4..0000000 --- a/com32/chain/common.h +++ /dev/null @@ -1,39 +0,0 @@ -/* ----------------------------------------------------------------------- * - * - * Copyright 2003-2009 H. Peter Anvin - All Rights Reserved - * Copyright 2009-2010 Intel Corporation; author: H. Peter Anvin - * Copyright 2010 Shao Miller - * Copyright 2010-2012 Michal Soltys - * - * 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. - * - * ----------------------------------------------------------------------- */ - -#ifndef _COM32_CHAIN_COMMON_H -#define _COM32_CHAIN_COMMON_H - -#define ADDRMAX 0x9EFFFu -#define ADDRMIN 0x500u - -#endif - -/* vim: set ts=8 sts=4 sw=4 noet: */ diff --git a/com32/chain/mangle.c b/com32/chain/mangle.c index bcd31e0..cb0462f 100644 --- a/com32/chain/mangle.c +++ b/com32/chain/mangle.c @@ -35,7 +35,6 @@ #include <stdint.h> #include <dprintf.h> #include <syslinux/config.h> -#include "common.h" #include "chain.h" #include "options.h" #include "utility.h" diff --git a/com32/chain/options.c b/com32/chain/options.c index 942a398..4df2459 100644 --- a/com32/chain/options.c +++ b/com32/chain/options.c @@ -31,7 +31,6 @@ #include <stdint.h> #include <stdlib.h> #include <string.h> -#include "common.h" #include "chain.h" #include "partiter.h" #include "utility.h" diff --git a/com32/chain/options.h b/com32/chain/options.h index bec1e2c..db33df3 100644 --- a/com32/chain/options.h +++ b/com32/chain/options.h @@ -34,6 +34,9 @@ #include <stdint.h> #include <syslinux/bootrm.h> +#define ADDRMAX 0x9EFFFu +#define ADDRMIN 0x500u + struct options { const char *drivename; const char *partition; diff --git a/com32/chain/partiter.c b/com32/chain/partiter.c index d8d65e7..84fddec 100644 --- a/com32/chain/partiter.c +++ b/com32/chain/partiter.c @@ -40,7 +40,6 @@ #include <stdarg.h> #include <zlib.h> #include <syslinux/disk.h> -#include "common.h" #include "partiter.h" #include "utility.h" -- 1.7.10.4
Michal Soltys
2012-Nov-06 00:32 UTC
[syslinux] [PATCH 19/23] com32/chain: rely more on addr_t, replace ADDR*
Whenever the computation imply use of that type, even if it's just uint32_t. Add dosmax (using 40:13) and dosmin (0x500) instead of separate ADDR* and dosmem (in do_boot()). Signed-off-by: Michal Soltys <soltys at ziu.info> --- com32/chain/chain.c | 10 ++++------ com32/chain/options.c | 23 ++++++++++++++++------- com32/chain/options.h | 16 +++++++--------- com32/chain/utility.h | 5 +++++ 4 files changed, 32 insertions(+), 22 deletions(-) diff --git a/com32/chain/chain.c b/com32/chain/chain.c index 38e647c..748c8c0 100644 --- a/com32/chain/chain.c +++ b/com32/chain/chain.c @@ -155,8 +155,6 @@ ok: static void do_boot(struct data_area *data, int ndata) { - uint16_t *const bios_fbm = (uint16_t *) 0x413; - addr_t dosmem = (addr_t)(*bios_fbm << 10); /* Technically a low bound */ struct syslinux_memmap *mmap; struct syslinux_movelist *mlist = NULL; addr_t endimage; @@ -176,7 +174,7 @@ static void do_boot(struct data_area *data, int ndata) if (data[i].base + data[i].size > endimage) endimage = data[i].base + data[i].size; } - if (endimage > dosmem) + if (endimage > dosmax) goto too_big; for (i = 0; i < ndata; i++) { @@ -222,7 +220,7 @@ static void do_boot(struct data_area *data, int ndata) static uint8_t swapstub[1024]; uint8_t *p; - /* Note: we can't rely on either INT 13h nor the dosmem + /* Note: we can't rely on either INT 13h nor the dosmax vector to be correct at this stage, so we have to use an installer stub to put things in the right place. Round the installer location to a 1K boundary so the only @@ -530,7 +528,7 @@ int main(int argc, char *argv[]) error("Couldn't read the boot file."); goto bail; } - if (fdat.base + fdat.size - 1 > ADDRMAX) { + if (fdat.base + fdat.size > dosmax) { error("The boot file is too big to load at this address."); goto bail; } @@ -541,7 +539,7 @@ int main(int argc, char *argv[]) sdat.base = (opt.sseg << 4) + opt.soff; sdat.size = iter->di.bps; - if (sdat.base + sdat.size - 1 > ADDRMAX) { + if (sdat.base + sdat.size > dosmax) { error("The sector cannot be loaded at such high address."); goto bail; } diff --git a/com32/chain/options.c b/com32/chain/options.c index 4df2459..5d76219 100644 --- a/com32/chain/options.c +++ b/com32/chain/options.c @@ -28,6 +28,7 @@ * * ----------------------------------------------------------------------- */ +#include <syslinux/movebits.h> #include <stdint.h> #include <stdlib.h> #include <string.h> @@ -38,14 +39,17 @@ struct options opt; -static int soi_s2n(char *ptr, unsigned int *seg, - unsigned int *off, - unsigned int *ip, - unsigned int def) +static int soi_s2n(char *ptr, + addr_t *seg, + addr_t *off, + addr_t *ip, + addr_t def) { - unsigned int segval = 0, offval, ipval, val; + addr_t segval, offval, ipval, val; char *p; + /* defaults */ + segval = 0; offval = def; ipval = def; @@ -55,16 +59,21 @@ static int soi_s2n(char *ptr, unsigned int *seg, if (p[0] == ':' && p[1] && p[1] != ':') ipval = strtoul(p+1, NULL, 0); + /* verify if load address is within [dosmin, dosmax) */ val = (segval << 4) + offval; - if (val < ADDRMIN || val > ADDRMAX) { + if (val < dosmin || val >= dosmax) { error("Invalid seg:off:* address specified."); goto bail; } + /* + * verify if jump address is within [dosmin, dosmax) and offset is 16bit + * sane + */ val = (segval << 4) + ipval; - if (ipval > 0xFFFE || val < ADDRMIN || val > ADDRMAX) { + if (ipval > 0xFFFE || val < dosmin || val >= dosmax) { error("Invalid seg:*:ip address specified."); goto bail; } diff --git a/com32/chain/options.h b/com32/chain/options.h index db33df3..008c9cb 100644 --- a/com32/chain/options.h +++ b/com32/chain/options.h @@ -33,21 +33,19 @@ #include <stdint.h> #include <syslinux/bootrm.h> - -#define ADDRMAX 0x9EFFFu -#define ADDRMIN 0x500u +#include <syslinux/movebits.h> struct options { const char *drivename; const char *partition; const char *file; const char *grubcfg; - unsigned int fseg; - unsigned int foff; - unsigned int fip; - unsigned int sseg; - unsigned int soff; - unsigned int sip; + addr_t fseg; + addr_t foff; + addr_t fip; + addr_t sseg; + addr_t soff; + addr_t sip; int hide; int relax; int prefmbr; diff --git a/com32/chain/utility.h b/com32/chain/utility.h index a5b06cc..49c7946 100644 --- a/com32/chain/utility.h +++ b/com32/chain/utility.h @@ -34,6 +34,7 @@ #include <stdint.h> #include <stdio.h> #include <syslinux/disk.h> +#include <syslinux/movebits.h> #define bpbUNK 0 #define bpbV20 1 @@ -50,6 +51,10 @@ #define l2c_cadd 1 #define l2c_cmax 2 +/* first usable and first unusable offsets */ +#define dosmin ((addr_t)0x500u) +#define dosmax ((addr_t)(*(uint16_t *) 0x413 << 10)) + void wait_key(void); void lba2chs(disk_chs *dst, const struct disk_info *di, uint64_t lba, int mode); uint32_t get_file_lba(const char *filename); -- 1.7.10.4
Michal Soltys
2012-Nov-06 00:32 UTC
[syslinux] [PATCH 20/23] com32/chain: index -1 partiter adjustment
Currently, the only situation when index could be set to -1 was empty logical partition (with stepall flag active). To keep things consistent (and with index0 already providing "full" info), adjust the partiter to also set -1 on empty main partition. This change also allows simple index check to see whether we're are at the empty partition or not, without digging into disk_dos_part_entry data and retesting ostype field. We rely on it now in manglepe_hide(). Also some retab! changes in partiter.h and one variable rename. Signed-off-by: Michal Soltys <soltys at ziu.info> --- com32/chain/mangle.c | 4 +--- com32/chain/partiter.c | 6 +++--- com32/chain/partiter.h | 16 ++++++++-------- 3 files changed, 12 insertions(+), 14 deletions(-) diff --git a/com32/chain/mangle.c b/com32/chain/mangle.c index cb0462f..88c4e1c 100644 --- a/com32/chain/mangle.c +++ b/com32/chain/mangle.c @@ -528,7 +528,6 @@ int manglepe_hide(struct part_iter *miter) { int wb = 0, werr = 0; struct part_iter *iter = NULL; - struct disk_dos_part_entry *dp; int ridx; if (!(opt.hide & 1)) @@ -550,8 +549,7 @@ int manglepe_hide(struct part_iter *miter) if (!(opt.hide & 2) && ridx > 3) break; /* skip when we're constrained to pri only */ - dp = (struct disk_dos_part_entry *)iter->record; - if (dp->ostype) + if (iter->index != -1) wb |= fliphide(iter, miter); /* diff --git a/com32/chain/partiter.c b/com32/chain/partiter.c index 84fddec..259a389 100644 --- a/com32/chain/partiter.c +++ b/com32/chain/partiter.c @@ -371,7 +371,7 @@ static int dos_next_ebr(struct part_iter *iter, uint32_t *lba, } if (!dp[0].ostype) - iter->dos.skipcnt++; + iter->dos.logskipcnt++; if (dp[0].ostype || (iter->flags & PIF_STEPALL)) { *lba = iter->dos.cebr_lba + dp[0].start_lba; @@ -471,10 +471,10 @@ static int pi_dos_next(struct part_iter *iter) * non-PIF_STEPALL iterators */ - if (iter->index0 >= 4 && !dos_part->ostype) + if (!dos_part->ostype) iter->index = -1; else - iter->index = iter->index0 - iter->dos.skipcnt + 1; + iter->index = iter->index0 + 1 - iter->dos.logskipcnt; iter->start_lba = start_lba; iter->length = dos_part->length; iter->record = (char *)dos_part; diff --git a/com32/chain/partiter.h b/com32/chain/partiter.h index 21444e1..c2448c2 100644 --- a/com32/chain/partiter.h +++ b/com32/chain/partiter.h @@ -76,17 +76,17 @@ struct part_iter { struct disk_info di; union { struct { - uint32_t disk_sig; /* 32bit disk signature as stored in MBR */ + uint32_t disk_sig; /* 32bit disk signature as stored in MBR */ - uint32_t bebr_lba; /* absolute lba of base extended partition */ - uint32_t bebr_siz; /* size of base extended partition */ + uint32_t bebr_lba; /* absolute lba of base extended partition */ + uint32_t bebr_siz; /* size of base extended partition */ - uint32_t cebr_lba; /* absolute lba of curr ext. partition */ - uint32_t nebr_lba; /* absolute lba of next ext. partition */ - uint32_t nebr_siz; /* size of next ext. partition */ + uint32_t cebr_lba; /* absolute lba of curr ext. partition */ + uint32_t nebr_lba; /* absolute lba of next ext. partition */ + uint32_t nebr_siz; /* size of next ext. partition */ - int bebr_index0; /* index of (0-3) of base ext. part., -1 of not present in MBR */ - int skipcnt; /* how many logical holes were skipped */ + int bebr_index0; /* index of (0-3) of base ext. part., -1 of not present in MBR */ + int logskipcnt; /* how many logical holes were skipped */ } dos; struct { struct guid disk_guid; -- 1.7.10.4
Michal Soltys
2012-Nov-06 00:32 UTC
[syslinux] [PATCH 21/23] com32/chain: manglepe_fixchs() correction
We have to be more careful, when in-entry start/length values are 0 (one or both). Firstly they are relative to the disk or the [B]EBR (while CHS are absolute). Secondly, length 0 would imply the end CHS being lower than the start CHS. Under normal circumstances, partiter would complain about corrupt layout (unless relax flag is set) and value 0 in any of those fields generally imply a hole, so the adjustments were harmless - nontheless they made everything look silly and not really correct. Adjusted approach is: - for start entry - if the os entry is 0 /and/ the beginning is 0 - reset to 0, otherwise calculate chs - for end entry - as above /or/ length is 0 - reset to 0, otherwise calculate chs Signed-off-by: Michal Soltys <soltys at ziu.info> --- com32/chain/mangle.c | 48 ++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 38 insertions(+), 10 deletions(-) diff --git a/com32/chain/mangle.c b/com32/chain/mangle.c index 88c4e1c..68a9c72 100644 --- a/com32/chain/mangle.c +++ b/com32/chain/mangle.c @@ -579,17 +579,47 @@ bail: return 0; } -static int updchs(const struct disk_info *di, - struct disk_dos_part_entry *dp, - uint32_t lba1) +static int updchs(struct part_iter *iter, int ext) { - uint32_t ochs1, ochs2; + struct disk_dos_part_entry *dp; + uint32_t ochs1, ochs2, lba; + dp = (struct disk_dos_part_entry *)iter->record; + if (!ext) { + /* primary or logical */ + lba = (uint32_t)iter->start_lba; + } else { + /* extended */ + dp += 1; + lba = iter->dos.nebr_lba; + } ochs1 = *(uint32_t *)dp->start; ochs2 = *(uint32_t *)dp->end; - lba2chs(&dp->start, di, lba1, l2c_cadd); - lba2chs(&dp->end, di, lba1 + dp->length - 1, l2c_cadd); + /* + * We have to be a bit more careful here in case of 0 start and/or length; + * start = 0 would be converted to the beginning of the disk (C/H/S + * 0/0/1) or the [B]EBR, length = 0 would actually set the end CHS to be + * lower than the start CHS. + * + * Both are harmless in case of a hole (and in non-hole case will make + * partiter complain about corrupt layout unless PIF_RELAX is set), but it + * makes everything look silly and not really correct. + * + * Thus the approach as seen below. + */ + + if (dp->start_lba || iter->index != -1) { + lba2chs(&dp->start, &iter->di, lba, l2c_cadd); + } else { + memset(&dp->start, 0, sizeof dp->start); + } + + if ((dp->start_lba || iter->index != -1) && dp->length) { + lba2chs(&dp->end, &iter->di, lba + dp->length - 1, l2c_cadd); + } else { + memset(&dp->end, 0, sizeof dp->end); + } return *(uint32_t *)dp->start != ochs1 || @@ -603,7 +633,6 @@ int manglepe_fixchs(struct part_iter *miter) { int wb = 0, werr = 0; struct part_iter *iter = NULL; - struct disk_dos_part_entry *dp; int ridx; if (!opt.fixchs) @@ -619,11 +648,10 @@ int manglepe_fixchs(struct part_iter *miter) while (!pi_next(iter) && !werr) { ridx = iter->index0; - dp = (struct disk_dos_part_entry *)iter->record; - wb |= updchs(&iter->di, dp, (uint32_t)iter->start_lba); + wb |= updchs(iter, 0); if (ridx > 3) - wb |= updchs(&iter->di, dp + 1, iter->dos.nebr_lba); + wb |= updchs(iter, 1); /* * we have to update mbr and each extended partition, but only if -- 1.7.10.4
Michal Soltys
2012-Nov-06 00:32 UTC
[syslinux] [PATCH 22/23] com32/chain: partiter: rename start_lba
disk.c also uses start_lba and it can mean few different things depending on context (disk relative, BEBR relative, current EBR relative). partiter's main offset is always a disk relative value. To make it more distinct and avoid suggestion the value is simply a copy of the one from disk_dos_part_entry, we rename it to more fitting abs_lba. Signed-off-by: Michal Soltys <soltys at ziu.info> --- com32/chain/chain.c | 20 ++++++++++---------- com32/chain/mangle.c | 14 +++++++------- com32/chain/partiter.c | 10 +++++----- com32/chain/partiter.h | 2 +- 4 files changed, 23 insertions(+), 23 deletions(-) diff --git a/com32/chain/chain.c b/com32/chain/chain.c index 748c8c0..f205872 100644 --- a/com32/chain/chain.c +++ b/com32/chain/chain.c @@ -347,7 +347,7 @@ int find_dp(struct part_iter **_iter) /* 'fs' => we should lookup the syslinux partition number and use it */ if (!strcmp(opt.drivename, "fs")) { while (!pi_next(iter)) { - if (iter->start_lba == fs_lba) + if (iter->abs_lba == fs_lba) break; } /* broken part structure or other problems */ @@ -428,16 +428,16 @@ static int setup_handover(const struct part_iter *iter, critm(); goto bail; } - lba2chs(&ha->start, &iter->di, iter->start_lba, l2c_cadd); - lba2chs(&ha->end, &iter->di, iter->start_lba + iter->length - 1, l2c_cadd); + lba2chs(&ha->start, &iter->di, iter->abs_lba, l2c_cadd); + lba2chs(&ha->end, &iter->di, iter->abs_lba + iter->length - 1, l2c_cadd); ha->active_flag = 0x80; ha->ostype = 0xED; /* All bits set by default */ ha->start_lba = ~0u; ha->length = ~0u; /* If these fit the precision, pass them on */ - if (iter->start_lba < ha->start_lba) - ha->start_lba = (uint32_t)iter->start_lba; + if (iter->abs_lba < ha->start_lba) + ha->start_lba = (uint32_t)iter->abs_lba; if (iter->length < ha->length) ha->length = (uint32_t)iter->length; /* Next comes the GPT partition record length */ @@ -461,9 +461,9 @@ static int setup_handover(const struct part_iter *iter, } memcpy(ha, iter->record, synth_size); /* make sure these match bios imaginations and are ebr agnostic */ - lba2chs(&ha->start, &iter->di, iter->start_lba, l2c_cadd); - lba2chs(&ha->end, &iter->di, iter->start_lba + iter->length - 1, l2c_cadd); - ha->start_lba = (uint32_t)iter->start_lba; + lba2chs(&ha->start, &iter->di, iter->abs_lba, l2c_cadd); + lba2chs(&ha->end, &iter->di, iter->abs_lba + iter->length - 1, l2c_cadd); + ha->start_lba = (uint32_t)iter->abs_lba; ha->length = (uint32_t)iter->length; #ifdef DEBUG @@ -543,7 +543,7 @@ int main(int argc, char *argv[]) error("The sector cannot be loaded at such high address."); goto bail; } - if (!(sdat.data = disk_read_sectors(&iter->di, iter->start_lba, 1))) { + if (!(sdat.data = disk_read_sectors(&iter->di, iter->abs_lba, 1))) { error("Couldn't read the sector."); goto bail; } @@ -625,7 +625,7 @@ int main(int argc, char *argv[]) iter->di.lbacnt, iter->di.cyl * iter->di.head * iter->di.spt, iter->di.cyl, iter->di.head, iter->di.spt); dprintf("iter idx: %d\n", iter->index); - dprintf("iter lba: %"PRIu64"\n", iter->start_lba); + dprintf("iter lba: %"PRIu64"\n", iter->abs_lba); if (opt.hand) dprintf("hand lba: %u\n", ((struct disk_dos_part_entry *)hdat.data)->start_lba); diff --git a/com32/chain/mangle.c b/com32/chain/mangle.c index 68a9c72..b87aa8e 100644 --- a/com32/chain/mangle.c +++ b/com32/chain/mangle.c @@ -280,18 +280,18 @@ static int mangle_bpb(const struct part_iter *iter, struct data_area *data, cons /* BPB: hidden sectors 64bit - exFAT only for now */ if (type == bpbEXF) - *(uint64_t *) ((char *)data->data + 0x40) = iter->start_lba; + *(uint64_t *) ((char *)data->data + 0x40) = iter->abs_lba; /* BPB: hidden sectors 32bit*/ else if (bpbV34 <= type && type <= bpbV70) { - if (iter->start_lba < ~0u) - *(uint32_t *) ((char *)data->data + 0x1c) = (uint32_t)iter->start_lba; + if (iter->abs_lba < ~0u) + *(uint32_t *) ((char *)data->data + 0x1c) = (uint32_t)iter->abs_lba; else /* won't really help much, but ... */ *(uint32_t *) ((char *)data->data + 0x1c) = ~0u; /* BPB: hidden sectors 16bit*/ } else if (bpbV30 <= type && type <= bpbV32) { - if (iter->start_lba < 0xFFFF) - *(uint16_t *) ((char *)data->data + 0x1c) = (uint16_t)iter->start_lba; + if (iter->abs_lba < 0xFFFF) + *(uint16_t *) ((char *)data->data + 0x1c) = (uint16_t)iter->abs_lba; else /* won't really help much, but ... */ *(uint16_t *) ((char *)data->data + 0x1c) = (uint16_t)~0u; @@ -399,7 +399,7 @@ int mangles_save(const struct part_iter *iter, const struct data_area *data, voi return 0; if (memcmp(org, data->data, data->size)) { - if (disk_write_sectors(&iter->di, iter->start_lba, data->data, 1)) { + if (disk_write_sectors(&iter->di, iter->abs_lba, data->data, 1)) { error("Cannot write the updated sector."); goto bail; } @@ -587,7 +587,7 @@ static int updchs(struct part_iter *iter, int ext) dp = (struct disk_dos_part_entry *)iter->record; if (!ext) { /* primary or logical */ - lba = (uint32_t)iter->start_lba; + lba = (uint32_t)iter->abs_lba; } else { /* extended */ dp += 1; diff --git a/com32/chain/partiter.c b/com32/chain/partiter.c index 259a389..d5a06b7 100644 --- a/com32/chain/partiter.c +++ b/com32/chain/partiter.c @@ -449,7 +449,7 @@ static int pi_next_(struct part_iter *iter) static int pi_dos_next(struct part_iter *iter) { - uint32_t start_lba = 0; + uint32_t abs_lba = 0; struct disk_dos_part_entry *dos_part = NULL; if (iter->status) @@ -457,12 +457,12 @@ static int pi_dos_next(struct part_iter *iter) /* look for primary partitions */ if (iter->index0 < 4 && - dos_next_mbr(iter, &start_lba, &dos_part) < 0) + dos_next_mbr(iter, &abs_lba, &dos_part) < 0) return iter->status; /* look for logical partitions */ if (iter->index0 >= 4 && - dos_next_ebr(iter, &start_lba, &dos_part) < 0) + dos_next_ebr(iter, &abs_lba, &dos_part) < 0) return iter->status; /* @@ -475,7 +475,7 @@ static int pi_dos_next(struct part_iter *iter) iter->index = -1; else iter->index = iter->index0 + 1 - iter->dos.logskipcnt; - iter->start_lba = start_lba; + iter->abs_lba = abs_lba; iter->length = dos_part->length; iter->record = (char *)dos_part; @@ -512,7 +512,7 @@ static int pi_gpt_next(struct part_iter *iter) } /* gpt_part is guaranteed to be valid here */ iter->index = iter->index0 + 1; - iter->start_lba = gpt_part->lba_first; + iter->abs_lba = gpt_part->lba_first; iter->length = gpt_part->lba_last - gpt_part->lba_first + 1; iter->record = (char *)gpt_part; memcpy(&iter->gpt.part_guid, &gpt_part->uid, sizeof(struct guid)); diff --git a/com32/chain/partiter.h b/com32/chain/partiter.h index c2448c2..e223333 100644 --- a/com32/chain/partiter.h +++ b/com32/chain/partiter.h @@ -67,7 +67,7 @@ struct part_iter { const struct itertype *type; char *data; char *record; - uint64_t start_lba; + uint64_t abs_lba; uint64_t length; int index0; /* including holes, from -1 (disk, then parts from 0) */ int index; /* excluding holes, from 0 (disk, then parts from 1), -1 means hole, if PIF_STEPALL is set */ -- 1.7.10.4
Michal Soltys
2012-Nov-06 00:32 UTC
[syslinux] [PATCH 23/23] com32/chain: use single value for partiter related options (flags)
Signed-off-by: Michal Soltys <soltys at ziu.info> --- com32/chain/chain.c | 10 +++++----- com32/chain/mangle.c | 4 ++-- com32/chain/options.c | 8 ++++---- com32/chain/options.h | 3 +-- 4 files changed, 12 insertions(+), 13 deletions(-) diff --git a/com32/chain/chain.c b/com32/chain/chain.c index f205872..dcf6d0b 100644 --- a/com32/chain/chain.c +++ b/com32/chain/chain.c @@ -71,7 +71,7 @@ static int find_by_sig(uint32_t mbr_sig, for (drive = 0x80; drive < 0x80 + fixed_cnt; drive++) { if (disk_get_params(drive, &diskinfo)) continue; /* Drive doesn't exist */ - if (!(boot_part = pi_begin(&diskinfo, opt.relax | opt.prefmbr))) + if (!(boot_part = pi_begin(&diskinfo, opt.piflags))) continue; /* Check for a MBR disk */ if (boot_part->type != typedos) { @@ -102,7 +102,7 @@ static int find_by_guid(const struct guid *gpt_guid, for (drive = 0x80; drive < 0x80 + fixed_cnt; drive++) { if (disk_get_params(drive, &diskinfo)) continue; /* Drive doesn't exist */ - if (!(boot_part = pi_begin(&diskinfo, opt.relax | opt.prefmbr))) + if (!(boot_part = pi_begin(&diskinfo, opt.piflags))) continue; /* Check for a GPT disk */ if (boot_part->type != typegpt) { @@ -134,7 +134,7 @@ static int find_by_label(const char *label, struct part_iter **_boot_part) for (drive = 0x80; drive < 0x80 + fixed_cnt; drive++) { if (disk_get_params(drive, &diskinfo)) continue; /* Drive doesn't exist */ - if (!(boot_part = pi_begin(&diskinfo, opt.relax | opt.prefmbr))) + if (!(boot_part = pi_begin(&diskinfo, opt.piflags))) continue; /* Check for a GPT disk */ if (!(boot_part->type == typegpt)) { @@ -321,7 +321,7 @@ int find_dp(struct part_iter **_iter) if (disk_get_params(drive, &diskinfo)) goto bail; /* this will start iteration over FDD, possibly raw */ - if (!(iter = pi_begin(&diskinfo, opt.relax | opt.prefmbr))) + if (!(iter = pi_begin(&diskinfo, opt.piflags))) goto bail; } else if (!strcmp(opt.drivename, "boot") || !strcmp(opt.drivename, "fs")) { @@ -341,7 +341,7 @@ int find_dp(struct part_iter **_iter) if (disk_get_params(drive, &diskinfo)) goto bail; /* this will start iteration over disk emulation, possibly raw */ - if (!(iter = pi_begin(&diskinfo, opt.relax | opt.prefmbr))) + if (!(iter = pi_begin(&diskinfo, opt.piflags))) goto bail; /* 'fs' => we should lookup the syslinux partition number and use it */ diff --git a/com32/chain/mangle.c b/com32/chain/mangle.c index b87aa8e..6eab95d 100644 --- a/com32/chain/mangle.c +++ b/com32/chain/mangle.c @@ -541,7 +541,7 @@ int manglepe_hide(struct part_iter *miter) if (miter->index > 4 && !(opt.hide & 2)) warn("Specified partition is logical, so it can't be unhidden without 'unhideall'."); - if (!(iter = pi_begin(&miter->di, PIF_STEPALL | opt.relax | opt.prefmbr))) + if (!(iter = pi_begin(&miter->di, PIF_STEPALL | opt.piflags))) return -1; while (!pi_next(iter) && !werr) { @@ -643,7 +643,7 @@ int manglepe_fixchs(struct part_iter *miter) return -1; } - if (!(iter = pi_begin(&miter->di, PIF_STEPALL | opt.relax | opt.prefmbr))) + if (!(iter = pi_begin(&miter->di, PIF_STEPALL | opt.piflags))) return -1; while (!pi_next(iter) && !werr) { diff --git a/com32/chain/options.c b/com32/chain/options.c index 5d76219..42519be 100644 --- a/com32/chain/options.c +++ b/com32/chain/options.c @@ -336,17 +336,17 @@ int opt_parse_args(int argc, char *argv[]) } else if (!strcmp(argv[i], "nofixchs")) { opt.fixchs = false; } else if (!strcmp(argv[i], "relax")) { - opt.relax = PIF_RELAX; + opt.piflags |= PIF_RELAX; } else if (!strcmp(argv[i], "norelax")) { - opt.relax = 0; + opt.piflags &= ~PIF_RELAX; } else if (!strcmp(argv[i], "warn")) { opt.warn = true; } else if (!strcmp(argv[i], "nowarn")) { opt.warn = false; } else if (!strcmp(argv[i], "prefmbr")) { - opt.prefmbr = PIF_PREFMBR; + opt.piflags |= PIF_PREFMBR; } else if (!strcmp(argv[i], "noprefmbr")) { - opt.prefmbr = 0; + opt.piflags &= ~PIF_PREFMBR; } else if (!strcmp(argv[i], "nobreak")) { opt.brkchain = false; } else if (!strcmp(argv[i], "break")) { diff --git a/com32/chain/options.h b/com32/chain/options.h index 008c9cb..d245aa7 100644 --- a/com32/chain/options.h +++ b/com32/chain/options.h @@ -47,8 +47,7 @@ struct options { addr_t soff; addr_t sip; int hide; - int relax; - int prefmbr; + int piflags; uint16_t keeppxe; bool isolinux; bool cmldr; -- 1.7.10.4
On 11/5/2012 19:32, Michal Soltys wrote:> This is a bit updated set of chain.c32 changes that simplifies a few things > (and in partiter part), fixes few minor issues and adds a few new features. > > Details are in the following commits, below is the summary and pull details at > the end. > > Shao - any chance to peek over them ? Most of those are relatively simple > changes and well tested, though of course something might have slipped my > attention.Thanks for this. Sure thing; will do on Wednesday. - Shao
Shao Miller
2012-Nov-08 02:31 UTC
[syslinux] [PATCH 08/23] com32/chain: partiter - more precise comments / output
On 11/5/2012 19:32, Michal Soltys wrote:> Signed-off-by: Michal Soltys <soltys at ziu.info> > --- > com32/chain/partiter.c | 19 ++++++++++--------- > com32/chain/partiter.h | 23 +++++++++++++---------- > 2 files changed, 23 insertions(+), 19 deletions(-) > > diff --git a/com32/chain/partiter.c b/com32/chain/partiter.c > index 3ecaecf..250cb2c 100644 > --- a/com32/chain/partiter.c > +++ b/com32/chain/partiter.c > diff --git a/com32/chain/partiter.h b/com32/chain/partiter.h > index e9b158b..4acf1d2 100644 > --- a/com32/chain/partiter.h > +++ b/com32/chain/partiter.h > @@ -74,16 +74,19 @@ struct part_iter { > struct disk_info di; > union { > struct { > - uint32_t disk_sig; > - uint32_t nebr_lba; > - uint32_t cebr_lba; > - /* internal */ > - uint32_t ebr_start; > - uint32_t ebr_size; > - uint32_t bebr_start; > - uint32_t bebr_size; > - int bebr_index0; > - int skipcnt; > + uint32_t disk_sig; /* 32bit disk signature as stored in MBR */ > + > + uint32_t bebr_start; /* abs lba of base extended partition */ > + uint32_t bebr_size; /* size of base extended partition */ > + > + uint32_t cebr_lba; /* absolute lba of curr ext. partition */ > + uint32_t nebr_lba; /* absolute lba of next ext. partition */ > + > + uint32_t ebr_start; /* relative (to bebr) lba of next extended partition */ > + uint32_t ebr_size; /* size of next extended partition */ > + > + int bebr_index0; /* index of (0-3) of base ext. part., -1 of not present in MBR */"-1 if not present..." ^- ? - Shao Miller
Shao Miller
2012-Nov-08 02:34 UTC
[syslinux] [PATCH 09/23] com32/chain: remove unused ebr_start
On 11/5/2012 19:32, Michal Soltys wrote:> Signed-off-by: Michal Soltys <soltys at ziu.info> > --- > com32/chain/partiter.c | 3 --- > com32/chain/partiter.h | 1 - > 2 files changed, 4 deletions(-) > > diff --git a/com32/chain/partiter.c b/com32/chain/partiter.c > index 250cb2c..da96b3d 100644 > --- a/com32/chain/partiter.c > +++ b/com32/chain/partiter.c > @@ -308,7 +308,6 @@ static int prep_base_ebr(struct part_iter *iter) > iter->dos.bebr_start = dp->start_lba; > iter->dos.bebr_size = dp->length; > > - iter->dos.ebr_start = 0; > iter->dos.ebr_size = iter->dos.bebr_size; > > iter->dos.cebr_lba = 0;This member could still be useful if debugging/dumping. Was this change prompted by GCC warnings? - Shao Miller
Michal Soltys
2012-Nov-08 09:15 UTC
[syslinux] [PATCH 08/23] com32/chain: partiter - more precise comments / output
On 08.11.2012 03:31, Shao Miller wrote:> On 11/5/2012 19:32, Michal Soltys wrote: >> + int bebr_index0; /* index of (0-3) of base ext. part., -1 of not >> present in MBR */ > > "-1 if not present..." > ^- ? > > - Shao Miller >The initial value of this filed is (before these patches as well) set to -1, until the actual extended partition is found. This field is used in dos_next_mbr() and one-shot setup prep_base_ebr(). The choice of -1 and >=0 values was iirc to match index0 behavior. Can be adjusted to 0 and 1 - 4 if it looks more natural (with rename to bebr_index).
On 11/5/2012 19:32, Michal Soltys wrote:> This is a bit updated set of chain.c32 changes that simplifies a few things > (and in partiter part), fixes few minor issues and adds a few new features. > > Details are in the following commits, below is the summary and pull details at > the end. >Still reviewing! :) On 11/8/2012 03:45, Michal Soltys wrote:> On 08.11.2012 02:44, Shao Miller wrote: >> Personally, I'd rather not, but anonymous members of this sort are in >> C11... At least it removes the reserved identifier usage. :) >> >> Did you spot anonymous members being used elsewhere in the code-base, or >> will this be the first such usage that you're aware of? >> > > They were previously present in chain.c, when iterators were still part > of it (that is, before my split patches were merged). I looked back at > it and thought that perhaps I overdid earlier changes. For reference: > > git show 4c3e2f0e:com32/modules/chain.c > around line 470On 11/8/2012 03:51, Michal Soltys wrote:> On 08.11.2012 02:52, Shao Miller wrote: >> On 11/7/2012 20:44, Shao Miller wrote: >>> Personally, I'd rather not, but anonymous members of this sort are in >>> C11... At least it removes the reserved identifier usage. :) >> >> What is the benefit? Less typing? >> > > In essence, yes. And with this approach it's as it was originally in > your code. For the record, I'm fine with either approach. >The union member was named 'private' at that time, if I'm not mistaken. It's 2012, but I still prefer C89, for portability habits. :) Would it be a huge deal to 'git checkout -b feedback && git rebase -i HEAD~23' and drop this? It might be, if it causes you to have to deal with conflicts in the subsequent commits. On 11/8/2012 04:05, Michal Soltys wrote:> On 08.11.2012 03:34, Shao Miller wrote: >> >> This member could still be useful if debugging/dumping. Was this change >> prompted by GCC warnings? >> >> - Shao Miller >> > > Good point, I actually readded in two tiny patches after #23. Warnings > were not the reason here, just wasn't used anywhere in chain module > (though if it's moved outside chain, then such field is certainly useful).Ok. On 11/8/2012 04:15, Michal Soltys wrote:> On 08.11.2012 03:31, Shao Miller wrote: >> On 11/5/2012 19:32, Michal Soltys wrote: >>> + int bebr_index0; /* index of (0-3) of base ext. part., -1 of not >>> present in MBR */ >> >> "-1 if not present..." >> ^- ? >> >> - Shao Miller >> > > The initial value of this filed is (before these patches as well) set to > -1, until the actual extended partition is found. This field is used in > dos_next_mbr() and one-shot setup prep_base_ebr(). The choice of -1 and > >=0 values was iirc to match index0 behavior. > > Can be adjusted to 0 and 1 - 4 if it looks more natural (with rename to > bebr_index).-1 is fine by me. :) I was actually asking about "-1 of not present..." versus "-1 if not present..." (A typographical question.) On 11/8/2012 04:49, Michal Soltys wrote:>> On 11/5/2012 19:32, Michal Soltys wrote: >>> #ifndef _COM32_CHAIN_CHAIN_H >>> #define _COM32_CHAIN_CHAIN_H > > Good catch and no problems, one sed and it's fixed =) > > OTOH, what about using #pragma once ? Seems much cleaner and anything > that could be used for compiling syslinux supports it (I think). From > other projects, I think systemd has recently switched from #ifdefs pairs > to #pragma >I'd be inclined towards C89, once more. It doesn't have '#pragma once', as far as I know. But COM32_CHAIN_CHAIN_H_ works! On 11/8/2012 10:32, Michal Soltys wrote:> On 2012-11-08 02:34, Shao Miller wrote: >> >> An alternative to this would be a final 'else' that bails with an error. >> While unlikely, it _could_ be useful for chain.c32 to understand APM, >> some day. That'll be even more useful once chain.c32 stuff is further >> librarized for use with future multiple FS support. If APM support were >> introduced, this recent hunk would change back the way it was. > > Allright, will go back to earlier version.I hope it's not a big chore as a rebase. Else, it can be re-introduced if and when that day for APM support comes.
This is updated version including Shao's comments (though I skipped anonymous struct/unions, as per HPA's comment they were acceptable). The summary diff between old and new version is below - the changes are cosmetic except the very last commit addressing (hopefully) 'fs' option behavior from whole disk point of view. The following changes since commit 7307d60063ee4303da4de45f9d984fdc8df92146: memdisk: Fix order of sectors/track and bytes/sector (2012-10-23 10:53:17 +0100) are available in the git repository at: git://hasevolq.net/syslinux.git chain_upd_v3 for you to fetch changes up to 2d2c5ad19ed5cfad7f4b36d45684a833ee721faf: com32/chain: fix potential problem with 'fs' option (2013-01-29 14:50:22 +0100) ---------------------------------------------------------------- Michal Soltys (28): com32/chain: update licenses and #ifndef stanzas com32/chain: comments, minor adjustment com32/chain: use anonymous and unnamed aggregates com32/chain: change stepall into flags com32/chain: shuffle code before partiter simplifications com32/chain: partiter - simplifications and updates com32/chain: remove redundant rawindex com32/chain: partiter - more precise comments / output com32/chain: remove unused ebr_start com32/chain: add pi_errored() in partiter com32/chain: mangle and related updates com32/chain: cleaner variable names com32/chain: use disk_guid for part_guid for 0th partition com32/chain: warning/error/help/doc tidying com32/chain: implement relax flag com32/chain: implement handling of non-standard hybrid GPT+MBR layouts com32/chain: recognize exFAT com32/chain: remove common.h com32/chain: rely more on addr_t, replace ADDR* com32/chain: index -1 partiter adjustment com32/chain: manglepe_fixchs() correction com32/chain: partiter: rename start_lba com32/chain: use single value for partiter related options (flags) com32/chain: (partiter) dos_next_ebr() fixup com32/chain: (partiter) add cebr_siz for completness com32/chain: (utility) use enum for BPB types com32/chain: sizeof style change (trivial) com32/chain: fix potential problem with 'fs' option com32/chain/Makefile | 6 +- com32/chain/chain.c | 171 +++++++------ com32/chain/chain.h | 19 +- com32/chain/common.h | 9 - com32/chain/mangle.c | 244 ++++++++++++------- com32/chain/mangle.h | 34 ++- com32/chain/options.c | 230 ++++++++++-------- com32/chain/options.h | 54 ++++- com32/chain/partiter.c | 619 ++++++++++++++++++------------------------------ com32/chain/partiter.h | 85 ++++--- com32/chain/utility.c | 97 ++++++-- com32/chain/utility.h | 79 ++++-- doc/chain.txt | 41 ++-- 13 files changed, 918 insertions(+), 770 deletions(-) delete mode 100644 com32/chain/common.h Summary diff between old and current versions: diff --git a/com32/chain/Makefile b/com32/chain/Makefile index ef0929e..00b3323 100644 --- a/com32/chain/Makefile +++ b/com32/chain/Makefile @@ -1,6 +1,6 @@ ## ----------------------------------------------------------------------- ## -## Copyright 2003-2009 H. Peter Anvin - All Rights Reserved +## Copyright 2001-2009 H. Peter Anvin - All Rights Reserved ## Copyright 2009-2010 Intel Corporation; author: H. Peter Anvin ## Copyright 2010 Shao Miller ## Copyright 2010-2012 Michal Soltys diff --git a/com32/chain/chain.c b/com32/chain/chain.c index dcf6d0b..ae95d45 100644 --- a/com32/chain/chain.c +++ b/com32/chain/chain.c @@ -111,7 +111,7 @@ static int find_by_guid(const struct guid *gpt_guid, } /* Check for a matching GPT disk/partition guid */ do { - if (!memcmp(&boot_part->gpt.part_guid, gpt_guid, sizeof(*gpt_guid))) + if (!memcmp(&boot_part->gpt.part_guid, gpt_guid, sizeof *gpt_guid)) goto ok; } while (!pi_next(boot_part)); } @@ -240,14 +240,14 @@ static void do_boot(struct data_area *data, int ndata) /* Mapping table; start out with identity mapping everything */ for (i = 0; i < 256; i++) - p[i] = (uint8_t)i; + p[i] = i; /* And the actual swap */ p[driveno] = swapdrive; p[swapdrive] = driveno; /* Adjust registers */ - opt.regs.ds = opt.regs.cs = (uint16_t)(endimage >> 4); + opt.regs.ds = opt.regs.cs = endimage >> 4; opt.regs.esi.l = opt.regs.es = 0; opt.regs.ecx.l = sizeof swapstub >> 2; opt.regs.ip = 0x10; /* Installer offset */ @@ -346,10 +346,10 @@ int find_dp(struct part_iter **_iter) /* 'fs' => we should lookup the syslinux partition number and use it */ if (!strcmp(opt.drivename, "fs")) { - while (!pi_next(iter)) { + do { if (iter->abs_lba == fs_lba) break; - } + } while (!pi_next(iter)); /* broken part structure or other problems */ if (iter->status) { error("Can't find myself on the drive I booted from."); @@ -394,8 +394,7 @@ static int setup_handover(const struct part_iter *iter, struct data_area *data) { struct disk_dos_part_entry *ha; - uint32_t synth_size; - uint32_t *plen; + uint32_t synth_size = sizeof *ha; /* * we have to cover both non-iterated but otherwise properly detected @@ -404,7 +403,6 @@ static int setup_handover(const struct part_iter *iter, if (iter->index == 0) { uint32_t len; /* RAW handover protocol */ - synth_size = sizeof(struct disk_dos_part_entry); ha = malloc(synth_size); if (!ha) { critm(); @@ -412,24 +410,24 @@ static int setup_handover(const struct part_iter *iter, } len = ~0u; if (iter->length < len) - len = (uint32_t)iter->length; - lba2chs(&ha->start, &iter->di, 0, l2c_cadd); - lba2chs(&ha->end, &iter->di, len - 1, l2c_cadd); + len = iter->length; + lba2chs(&ha->start, &iter->di, 0, L2C_CADD); + lba2chs(&ha->end, &iter->di, len - 1, L2C_CADD); ha->active_flag = 0x80; ha->ostype = 0xDA; /* "Non-FS Data", anything is good here though ... */ ha->start_lba = 0; ha->length = len; } else if (iter->type == typegpt) { + uint32_t *plen; /* GPT handover protocol */ - synth_size = sizeof(struct disk_dos_part_entry) + - sizeof(uint32_t) + (uint32_t)iter->gpt.pe_size; + synth_size += sizeof *plen + iter->gpt.pe_size; ha = malloc(synth_size); if (!ha) { critm(); goto bail; } - lba2chs(&ha->start, &iter->di, iter->abs_lba, l2c_cadd); - lba2chs(&ha->end, &iter->di, iter->abs_lba + iter->length - 1, l2c_cadd); + lba2chs(&ha->start, &iter->di, iter->abs_lba, L2C_CADD); + lba2chs(&ha->end, &iter->di, iter->abs_lba + iter->length - 1, L2C_CADD); ha->active_flag = 0x80; ha->ostype = 0xED; /* All bits set by default */ @@ -437,12 +435,12 @@ static int setup_handover(const struct part_iter *iter, ha->length = ~0u; /* If these fit the precision, pass them on */ if (iter->abs_lba < ha->start_lba) - ha->start_lba = (uint32_t)iter->abs_lba; + ha->start_lba = iter->abs_lba; if (iter->length < ha->length) - ha->length = (uint32_t)iter->length; + ha->length = iter->length; /* Next comes the GPT partition record length */ - plen = (uint32_t *) (ha + 1); - plen[0] = (uint32_t)iter->gpt.pe_size; + plen = (uint32_t *)(ha + 1); + plen[0] = iter->gpt.pe_size; /* Next comes the GPT partition record copy */ memcpy(plen + 1, iter->record, plen[0]); #ifdef DEBUG @@ -451,9 +449,8 @@ static int setup_handover(const struct part_iter *iter, disk_gpt_part_dump((struct disk_gpt_part_entry *)(plen + 1)); #endif /* the only possible case left is dos scheme */ - } else { + } else if (iter->type == typedos) { /* MBR handover protocol */ - synth_size = sizeof(struct disk_dos_part_entry); ha = malloc(synth_size); if (!ha) { critm(); @@ -461,15 +458,18 @@ static int setup_handover(const struct part_iter *iter, } memcpy(ha, iter->record, synth_size); /* make sure these match bios imaginations and are ebr agnostic */ - lba2chs(&ha->start, &iter->di, iter->abs_lba, l2c_cadd); - lba2chs(&ha->end, &iter->di, iter->abs_lba + iter->length - 1, l2c_cadd); - ha->start_lba = (uint32_t)iter->abs_lba; - ha->length = (uint32_t)iter->length; + lba2chs(&ha->start, &iter->di, iter->abs_lba, L2C_CADD); + lba2chs(&ha->end, &iter->di, iter->abs_lba + iter->length - 1, L2C_CADD); + ha->start_lba = iter->abs_lba; + ha->length = iter->length; #ifdef DEBUG dprintf("MBR handover:\n"); disk_dos_part_dump(ha); #endif + } else { + /* shouldn't ever happen */ + goto bail; } data->base = 0x7be; @@ -490,9 +490,9 @@ int main(int argc, char *argv[]) console_ansi_raw(); - memset(&fdat, 0, sizeof(fdat)); - memset(&hdat, 0, sizeof(hdat)); - memset(&sdat, 0, sizeof(sdat)); + memset(&fdat, 0, sizeof fdat); + memset(&hdat, 0, sizeof hdat); + memset(&sdat, 0, sizeof sdat); opt_set_defs(); if (opt_parse_args(argc, argv)) @@ -612,11 +612,11 @@ int main(int argc, char *argv[]) */ if (opt.file) - memcpy(data + ndata++, &fdat, sizeof(fdat)); + memcpy(data + ndata++, &fdat, sizeof fdat); if (opt.maps) - memcpy(data + ndata++, &sdat, sizeof(sdat)); + memcpy(data + ndata++, &sdat, sizeof sdat); if (opt.hand) - memcpy(data + ndata++, &hdat, sizeof(hdat)); + memcpy(data + ndata++, &hdat, sizeof hdat); #ifdef DEBUG dprintf("iter->di dsk, bps: %X, %u\niter->di lbacnt, C*H*S: %"PRIu64", %u\n" diff --git a/com32/chain/chain.h b/com32/chain/chain.h index 1d08b0e..fb5914b 100644 --- a/com32/chain/chain.h +++ b/com32/chain/chain.h @@ -13,8 +13,8 @@ * * ----------------------------------------------------------------------- */ -#ifndef _COM32_CHAIN_CHAIN_H -#define _COM32_CHAIN_CHAIN_H +#ifndef COM32_CHAIN_CHAIN_H +#define COM32_CHAIN_CHAIN_H #include <syslinux/movebits.h> diff --git a/com32/chain/mangle.c b/com32/chain/mangle.c index 6eab95d..ffdaab8 100644 --- a/com32/chain/mangle.c +++ b/com32/chain/mangle.c @@ -161,7 +161,7 @@ int manglef_grub(const struct part_iter *iter, struct data_area *data) if (!(opt.file && opt.grub)) return 0; - if (data->size < sizeof(struct grub_stage2_patch_area)) { + if (data->size < sizeof *stage2) { error("The file specified by grub=<loader> is too small to be stage2 of GRUB Legacy."); goto bail; } @@ -203,7 +203,7 @@ int manglef_grub(const struct part_iter *iter, struct data_area *data) * 0-3: primary partitions * 4-*: logical partitions */ - stage2->install_partition.part1 = (uint8_t)(iter->index - 1); + stage2->install_partition.part1 = iter->index - 1; /* * Grub Legacy reserves 89 bytes (from 0x8217 to 0x826f) for the @@ -211,7 +211,7 @@ int manglef_grub(const struct part_iter *iter, struct data_area *data) * the default config filename "/boot/grub/menu.lst". */ if (opt.grubcfg) { - if (strlen(opt.grubcfg) > sizeof(stage2->config_file) - 1) { + if (strlen(opt.grubcfg) >= sizeof stage2->config_file) { error("The config filename length can't exceed 88 characters."); goto bail; } @@ -263,9 +263,9 @@ int manglef_drmk(struct data_area *data) data->size = tsize; /* ds:bp is assumed by DRMK to be the boot sector */ /* offset 28 is the FAT HiddenSectors value */ - opt.regs.ds = (uint16_t)((tsize >> 4) + (opt.fseg - 2)); + opt.regs.ds = (tsize >> 4) + (opt.fseg - 2); /* "Patch" into tail of the new space */ - *(uint32_t *)((char*)data->data + tsize - 4) = (uint32_t)fs_lba; + *(uint32_t *)((char*)data->data + tsize - 4) = fs_lba; return 0; bail: @@ -284,14 +284,14 @@ static int mangle_bpb(const struct part_iter *iter, struct data_area *data, cons /* BPB: hidden sectors 32bit*/ else if (bpbV34 <= type && type <= bpbV70) { if (iter->abs_lba < ~0u) - *(uint32_t *) ((char *)data->data + 0x1c) = (uint32_t)iter->abs_lba; + *(uint32_t *) ((char *)data->data + 0x1c) = iter->abs_lba; else /* won't really help much, but ... */ *(uint32_t *) ((char *)data->data + 0x1c) = ~0u; /* BPB: hidden sectors 16bit*/ } else if (bpbV30 <= type && type <= bpbV32) { if (iter->abs_lba < 0xFFFF) - *(uint16_t *) ((char *)data->data + 0x1c) = (uint16_t)iter->abs_lba; + *(uint16_t *) ((char *)data->data + 0x1c) = iter->abs_lba; else /* won't really help much, but ... */ *(uint16_t *) ((char *)data->data + 0x1c) = (uint16_t)~0u; @@ -300,7 +300,7 @@ static int mangle_bpb(const struct part_iter *iter, struct data_area *data, cons /* BPB: legacy geometry */ if (bpbV30 <= type && type <= bpbV70) { if (iter->di.cbios) - *(uint32_t *)((char *)data->data + 0x18) = (uint32_t)((iter->di.head << 16) | iter->di.spt); + *(uint32_t *)((char *)data->data + 0x18) = (iter->di.head << 16) | iter->di.spt; else { if (iter->di.disk & 0x80) *(uint32_t *)((char *)data->data + 0x18) = 0x00FF003F; @@ -310,8 +310,7 @@ static int mangle_bpb(const struct part_iter *iter, struct data_area *data, cons } /* BPB: drive */ if (off >= 0) { - *(uint8_t *)((char *)data->data + off) = (uint8_t) - (opt.swap ? iter->di.disk & 0x80 : iter->di.disk); + *(uint8_t *)((char *)data->data + off) = (opt.swap ? iter->di.disk & 0x80 : iter->di.disk); } return 0; @@ -422,7 +421,7 @@ int mangles_cmldr(struct data_area *data) if (!(opt.sect && opt.cmldr)) return 0; - memcpy((char *)data->data + 3, cmldr_signature, sizeof(cmldr_signature)); + memcpy((char *)data->data + 3, cmldr_signature, sizeof cmldr_signature); return 0; } @@ -431,18 +430,18 @@ int mangler_init(const struct part_iter *iter) { /* Set initial registry values */ if (opt.file) { - opt.regs.cs = opt.regs.ds = opt.regs.ss = (uint16_t)opt.fseg; - opt.regs.ip = (uint16_t)opt.fip; + opt.regs.cs = opt.regs.ds = opt.regs.ss = opt.fseg; + opt.regs.ip = opt.fip; } else { - opt.regs.cs = opt.regs.ds = opt.regs.ss = (uint16_t)opt.sseg; - opt.regs.ip = (uint16_t)opt.sip; + opt.regs.cs = opt.regs.ds = opt.regs.ss = opt.sseg; + opt.regs.ip = opt.sip; } if (opt.regs.ip == 0x7C00 && !opt.regs.cs) opt.regs.esp.l = 0x7C00; /* DOS kernels want the drive number in BL instead of DL. Indulge them. */ - opt.regs.ebx.b[0] = opt.regs.edx.b[0] = (uint8_t)iter->di.disk; + opt.regs.ebx.b[0] = opt.regs.edx.b[0] = iter->di.disk; return 0; } @@ -452,7 +451,7 @@ int mangler_handover(const struct part_iter *iter, const struct data_area *data) { if (opt.file && opt.maps && !opt.hptr) { opt.regs.esi.l = opt.regs.ebp.l = opt.soff; - opt.regs.ds = (uint16_t)opt.sseg; + opt.regs.ds = opt.sseg; opt.regs.eax.l = 0; } else if (opt.hand) { /* base is really 0x7be */ @@ -476,7 +475,7 @@ int mangler_handover(const struct part_iter *iter, const struct data_area *data) int mangler_grldr(const struct part_iter *iter) { if (opt.grldr) - opt.regs.edx.b[1] = (uint8_t)(iter->index - 1); + opt.regs.edx.b[1] = iter->index - 1; return 0; } @@ -505,8 +504,8 @@ static int fliphide(struct part_iter *iter, struct part_iter *miter) if ((t <= 0x1f) && ((mask >> (t & ~0x10u)) & 1)) { /* It's a hideable partition type */ - if (miter->index == iter->index || opt.hide & 4) - t &= (uint8_t)(~0x10u); /* unhide */ + if (miter->index == iter->index || opt.hide & HIDE_REV) + t &= ~0x10u; /* unhide */ else t |= 0x10u; /* hide */ } @@ -530,7 +529,7 @@ int manglepe_hide(struct part_iter *miter) struct part_iter *iter = NULL; int ridx; - if (!(opt.hide & 1)) + if (!(opt.hide & HIDE_ON)) return 0; if (miter->type != typedos) { @@ -538,7 +537,7 @@ int manglepe_hide(struct part_iter *miter) return -1; } - if (miter->index > 4 && !(opt.hide & 2)) + if (miter->index > 4 && !(opt.hide & HIDE_EXT)) warn("Specified partition is logical, so it can't be unhidden without 'unhideall'."); if (!(iter = pi_begin(&miter->di, PIF_STEPALL | opt.piflags))) @@ -546,7 +545,7 @@ int manglepe_hide(struct part_iter *miter) while (!pi_next(iter) && !werr) { ridx = iter->index0; - if (!(opt.hide & 2) && ridx > 3) + if (!(opt.hide & HIDE_EXT) && ridx > 3) break; /* skip when we're constrained to pri only */ if (iter->index != -1) @@ -610,13 +609,13 @@ static int updchs(struct part_iter *iter, int ext) */ if (dp->start_lba || iter->index != -1) { - lba2chs(&dp->start, &iter->di, lba, l2c_cadd); + lba2chs(&dp->start, &iter->di, lba, L2C_CADD); } else { memset(&dp->start, 0, sizeof dp->start); } if ((dp->start_lba || iter->index != -1) && dp->length) { - lba2chs(&dp->end, &iter->di, lba + dp->length - 1, l2c_cadd); + lba2chs(&dp->end, &iter->di, lba + dp->length - 1, L2C_CADD); } else { memset(&dp->end, 0, sizeof dp->end); } diff --git a/com32/chain/mangle.h b/com32/chain/mangle.h index 5b1ed5a..d4a5b75 100644 --- a/com32/chain/mangle.h +++ b/com32/chain/mangle.h @@ -28,8 +28,8 @@ * * ----------------------------------------------------------------------- */ -#ifndef _COM32_CHAIN_MANGLE_H -#define _COM32_CHAIN_MANGLE_H +#ifndef COM32_CHAIN_MANGLE_H +#define COM32_CHAIN_MANGLE_H #include "chain.h" #include "partiter.h" diff --git a/com32/chain/options.c b/com32/chain/options.c index 42519be..4e722a0 100644 --- a/com32/chain/options.c +++ b/com32/chain/options.c @@ -167,7 +167,7 @@ static void usage(void) void opt_set_defs(void) { - memset(&opt, 0, sizeof(opt)); + memset(&opt, 0, sizeof opt); opt.sect = true; /* by def. load sector */ opt.maps = true; /* by def. map sector */ opt.hand = true; /* by def. prepare handover */ @@ -300,15 +300,15 @@ int opt_parse_args(int argc, char *argv[]) } else if (!strcmp(argv[i], "noswap")) { opt.swap = false; } else if (!strcmp(argv[i], "nohide")) { - opt.hide = 0b000; + opt.hide = HIDE_OFF; } else if (!strcmp(argv[i], "hide")) { - opt.hide = 0b001; + opt.hide = HIDE_ON; } else if (!strcmp(argv[i], "hideall")) { - opt.hide = 0b011; + opt.hide = HIDE_ON | HIDE_EXT; } else if (!strcmp(argv[i], "unhide")) { - opt.hide = 0b101; + opt.hide = HIDE_ON | HIDE_REV; } else if (!strcmp(argv[i], "unhideall")) { - opt.hide = 0b111; + opt.hide = HIDE_ON | HIDE_EXT | HIDE_REV; } else if (!strcmp(argv[i], "setbpb")) { opt.setbpb = true; } else if (!strcmp(argv[i], "nosetbpb")) { diff --git a/com32/chain/options.h b/com32/chain/options.h index d245aa7..df96e2d 100644 --- a/com32/chain/options.h +++ b/com32/chain/options.h @@ -28,13 +28,15 @@ * * ----------------------------------------------------------------------- */ -#ifndef _COM32_CHAIN_OPTIONS_H -#define _COM32_CHAIN_OPTIONS_H +#ifndef COM32_CHAIN_OPTIONS_H +#define COM32_CHAIN_OPTIONS_H #include <stdint.h> #include <syslinux/bootrm.h> #include <syslinux/movebits.h> +enum {HIDE_OFF = 0, HIDE_ON = 1, HIDE_EXT = 2, HIDE_REV = 4}; + struct options { const char *drivename; const char *partition; diff --git a/com32/chain/partiter.c b/com32/chain/partiter.c index bd61bdf..1eb5350 100644 --- a/com32/chain/partiter.c +++ b/com32/chain/partiter.c @@ -84,7 +84,7 @@ static int pi_ctor(struct part_iter *iter, const struct disk_info *di, int flags ) { - memcpy(&iter->di, di, sizeof(struct disk_info)); + memcpy(&iter->di, di, sizeof *di); iter->flags = flags; iter->index0 = -1; iter->length = di->lbacnt; @@ -102,12 +102,12 @@ static int pi_dos_ctor(struct part_iter *iter, if (pi_ctor(iter, di, flags)) return -1; - if (!(iter->data = malloc(sizeof(struct disk_dos_mbr)))) { + if (!(iter->data = malloc(sizeof *mbr))) { critm(); goto bail; } - memcpy(iter->data, mbr, sizeof(struct disk_dos_mbr)); + memcpy(iter->data, mbr, sizeof *mbr); iter->dos.bebr_index0 = -1; iter->dos.disk_sig = mbr->disk_sig; @@ -144,8 +144,8 @@ static int pi_gpt_ctor(struct part_iter *iter, iter->gpt.ufirst = gpth->lba_first_usable; iter->gpt.ulast = gpth->lba_last_usable; - memcpy(&iter->gpt.disk_guid, &gpth->disk_guid, sizeof(struct guid)); - memcpy(&iter->gpt.part_guid, &gpth->disk_guid, sizeof(struct guid)); + memcpy(&iter->gpt.disk_guid, &gpth->disk_guid, sizeof gpth->disk_guid); + memcpy(&iter->gpt.part_guid, &gpth->disk_guid, sizeof gpth->disk_guid); iter->type = typegpt; return 0; @@ -529,10 +529,10 @@ static int pi_gpt_next(struct part_iter *iter) static struct part_iter *pi_alloc(void) { struct part_iter *iter; - if (!(iter = malloc(sizeof(struct part_iter)))) + if (!(iter = malloc(sizeof *iter))) critm(); else - memset(iter, 0, sizeof(struct part_iter)); + memset(iter, 0, sizeof *iter); return iter; } @@ -585,7 +585,7 @@ struct part_iter *pi_begin(const struct disk_info *di, int flags) } if (gpth && gpth->rev.uint32 == 0x00010000 && - !memcmp(gpth->sig, disk_gpt_sig_magic, sizeof(disk_gpt_sig_magic))) { + !memcmp(gpth->sig, disk_gpt_sig_magic, sizeof gpth->sig)) { /* looks like GPT v1.0 */ uint64_t gpt_loff; /* offset to GPT partition list in sectors */ uint64_t gpt_lsiz; /* size of GPT partition list in bytes */ @@ -615,11 +615,11 @@ struct part_iter *pi_begin(const struct disk_info *di, int flags) !sane(gpth->lba_last_usable, gpt_lcnt) || gpth->lba_last_usable + gpt_lcnt >= gpth->lba_alt || gpth->lba_alt >= di->lbacnt || - gpth->part_size < sizeof(struct disk_gpt_part_entry))) { + gpth->part_size < sizeof *gptl)) { error("Invalid GPT header's values."); goto bail; } - if (!(gptl = disk_read_sectors(di, gpt_loff, (uint8_t)gpt_lcnt))) { + if (!(gptl = disk_read_sectors(di, gpt_loff, gpt_lcnt))) { error("Couldn't read GPT partition list."); goto bail; } @@ -628,11 +628,11 @@ struct part_iter *pi_begin(const struct disk_info *di, int flags) warn("Checksum of the main GPT partition list is invalid, trying backup."); free(gptl); /* secondary array directly precedes secondary header */ - if (!(gptl = disk_read_sectors(di, gpth->lba_alt - gpt_lcnt, (uint8_t)gpt_lcnt))) { + if (!(gptl = disk_read_sectors(di, gpth->lba_alt - gpt_lcnt, gpt_lcnt))) { error("Couldn't read backup GPT partition list."); goto bail; } - if (!valid_crc(gpth->table_chksum, (const uint8_t *)gptl, (unsigned int)gpt_lsiz)) { + if (!valid_crc(gpth->table_chksum, (const uint8_t *)gptl, gpt_lsiz)) { error("Checksum of the backup GPT partition list is invalid, giving up."); goto bail; } diff --git a/com32/chain/partiter.h b/com32/chain/partiter.h index 78cd0d9..13dec84 100644 --- a/com32/chain/partiter.h +++ b/com32/chain/partiter.h @@ -34,24 +34,19 @@ * Provides disk / partition iteration. */ -#ifndef _COM32_CHAIN_PARTITER_H -#define _COM32_CHAIN_PARTITER_H +#ifndef COM32_CHAIN_PARTITER_H +#define COM32_CHAIN_PARTITER_H #include <stdint.h> #include <syslinux/disk.h> /* status */ -#define PI_ERRLOAD 3 -#define PI_INSANE 2 -#define PI_DONE 1 -#define PI_OK 0 +enum {PI_OK, PI_DONE, PI_INSANE, PI_ERRLOAD}; /* flags */ -#define PIF_STEPALL 0b001 -#define PIF_RELAX 0b010 -#define PIF_PREFMBR 0b100 +enum {PIF_STEPALL = 1, PIF_RELAX = 2, PIF_PREFMBR = 4}; struct itertype; struct part_iter; @@ -72,7 +67,7 @@ struct part_iter { int index0; /* including holes, from -1 (disk, then parts from 0) */ int index; /* excluding holes, from 0 (disk, then parts from 1), -1 means hole, if PIF_STEPALL is set */ int flags; /* flags, see #defines above */ - int status; /* current status, see #defines above */ + int status; /* current status, see enums above */ struct disk_info di; union { struct { @@ -86,7 +81,7 @@ struct part_iter { uint32_t nebr_lba; /* absolute lba of next ext. partition */ uint32_t nebr_siz; /* size of next ext. partition */ - int bebr_index0; /* index of (0-3) of base ext. part., -1 of not present in MBR */ + int bebr_index0; /* index of (0-3) of base ext. part., -1 if not present in MBR */ int logskipcnt; /* how many logical holes were skipped */ } dos; struct { diff --git a/com32/chain/utility.c b/com32/chain/utility.c index abf642c..1c2c033 100644 --- a/com32/chain/utility.c +++ b/com32/chain/utility.c @@ -67,6 +67,15 @@ void wait_key(void) } while (!cnt || (cnt < 0 && errno == EAGAIN)); } +int guid_is0(const struct guid *guid) +{ + return + !(guid->data1 || + guid->data2 || + guid->data3 || + guid->data4); +} + /* * mode explanation: * @@ -77,7 +86,8 @@ void wait_key(void) * to return matching chs triplet * cmax - assume we can use any cylinder value * - * by default, lba2chs() calls use cadd + * by default cadd seems most reasonable, giving consistent results with e.g. + * sfdisk's behavior */ void lba2chs(disk_chs *dst, const struct disk_info *di, uint64_t lba, int mode) { @@ -92,10 +102,10 @@ void lba2chs(disk_chs *dst, const struct disk_info *di, uint64_t lba, int mode) cs = di->cyl; hs = di->head; ss = di->spt; - if (mode == l2c_cadd) { + if (mode == L2C_CADD) { if (cs < 1024 && di->lbacnt > cs*hs*ss) cs++; - } else if (mode == l2c_cmax) + } else if (mode == L2C_CMAX) cs = 1024; } else { if (di->disk & 0x80) { @@ -114,15 +124,15 @@ void lba2chs(disk_chs *dst, const struct disk_info *di, uint64_t lba, int mode) h = hs - 1; c = cs - 1; } else { - s = ((uint32_t)lba % ss) + 1; - t = (uint32_t)lba / ss; + s = (lba % ss) + 1; + t = lba / ss; h = t % hs; c = t / hs; } - (*dst)[0] = (uint8_t)h; - (*dst)[1] = (uint8_t)(s | ((c & 0x300) >> 2)); - (*dst)[2] = (uint8_t)c; + (*dst)[0] = h; + (*dst)[1] = s | ((c & 0x300) >> 2); + (*dst)[2] = c; } uint32_t get_file_lba(const char *filename) @@ -131,7 +141,7 @@ uint32_t get_file_lba(const char *filename) uint32_t lba; /* Start with clean registers */ - memset(&inregs, 0, sizeof(com32sys_t)); + memset(&inregs, 0, sizeof inregs); /* Put the filename in the bounce buffer */ strlcpy(__com32.cs_bounce, filename, __com32.cs_bounce_size); @@ -152,7 +162,7 @@ uint32_t get_file_lba(const char *filename) lba = *((uint32_t *) MK_PTR(inregs.ds, inregs.esi.w[0])); /* Clean the registers for the next call */ - memset(&inregs, 0, sizeof(com32sys_t)); + memset(&inregs, 0, sizeof inregs); /* Put the filename in the bounce buffer */ strlcpy(__com32.cs_bounce, filename, __com32.cs_bounce_size); diff --git a/com32/chain/utility.h b/com32/chain/utility.h index 49c7946..596017b 100644 --- a/com32/chain/utility.h +++ b/com32/chain/utility.h @@ -28,28 +28,19 @@ * * ----------------------------------------------------------------------- */ -#ifndef _COM32_CHAIN_UTILITY_H -#define _COM32_CHAIN_UTILITY_H +#ifndef COM32_CHAIN_UTILITY_H +#define COM32_CHAIN_UTILITY_H #include <stdint.h> #include <stdio.h> #include <syslinux/disk.h> #include <syslinux/movebits.h> -#define bpbUNK 0 -#define bpbV20 1 -#define bpbV30 2 -#define bpbV32 3 -#define bpbV34 4 -#define bpbV40 5 -#define bpbVNT 6 -#define bpbV70 7 -#define bpbEXF 8 +/* most (all ?) bpb "types" known to humankind as of 2012 */ +enum {bpbUNK, bpbV20, bpbV30, bpbV32, bpbV34, bpbV40, bpbVNT, bpbV70, bpbEXF}; /* see utility.c for details */ -#define l2c_cnul 0 -#define l2c_cadd 1 -#define l2c_cmax 2 +enum {L2C_CNUL, L2C_CADD, L2C_CMAX}; /* first usable and first unusable offsets */ #define dosmin ((addr_t)0x500u) @@ -60,6 +51,7 @@ void lba2chs(disk_chs *dst, const struct disk_info *di, uint64_t lba, int mode); uint32_t get_file_lba(const char *filename); int drvoff_detect(int type); int bpb_detect(const uint8_t *bpb, const char *tag); +int guid_is0(const struct guid *guid); static inline int warn(const char *x) { @@ -78,12 +70,6 @@ static inline int crit(const char *x) #define critm() crit("Malloc failure.") -static inline int guid_is0(const struct guid *guid) -{ - return !*(const uint64_t *)guid && !*((const uint64_t *)guid + 1); -} - - #endif /* vim: set ts=8 sts=4 sw=4 noet: */
Michal Soltys
2013-Jan-29 14:05 UTC
[syslinux] [PATCH 01/28] com32/chain: update licenses and #ifndef stanzas
Licenses: chain.[ch] Makefile: GPLv2+ the rest: MIT Defines: Avoid prefixing with _ Signed-off-by: Michal Soltys <soltys at ziu.info> --- com32/chain/Makefile | 6 ++++-- com32/chain/chain.c | 2 +- com32/chain/chain.h | 19 +++++++++++++++++-- com32/chain/common.h | 34 ++++++++++++++++++++++++++++++++-- com32/chain/mangle.c | 30 ++++++++++++++++++++++++++++++ com32/chain/mangle.h | 34 ++++++++++++++++++++++++++++++++-- com32/chain/options.c | 30 ++++++++++++++++++++++++++++++ com32/chain/options.h | 34 ++++++++++++++++++++++++++++++++-- com32/chain/partiter.c | 5 +++-- com32/chain/partiter.h | 9 +++++---- com32/chain/utility.c | 30 ++++++++++++++++++++++++++++++ com32/chain/utility.h | 34 ++++++++++++++++++++++++++++++++-- 12 files changed, 248 insertions(+), 19 deletions(-) diff --git a/com32/chain/Makefile b/com32/chain/Makefile index 9d398a8..00b3323 100644 --- a/com32/chain/Makefile +++ b/com32/chain/Makefile @@ -1,7 +1,9 @@ ## ----------------------------------------------------------------------- ## -## Copyright 2001-2010 H. Peter Anvin - All Rights Reserved -## Copyright 2010 Michal Soltys +## Copyright 2001-2009 H. Peter Anvin - All Rights Reserved +## Copyright 2009-2010 Intel Corporation; author: H. Peter Anvin +## Copyright 2010 Shao Miller +## Copyright 2010-2012 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 diff --git a/com32/chain/chain.c b/com32/chain/chain.c index 30153c4..f0ccd97 100644 --- a/com32/chain/chain.c +++ b/com32/chain/chain.c @@ -3,7 +3,7 @@ * Copyright 2003-2009 H. Peter Anvin - All Rights Reserved * Copyright 2009-2010 Intel Corporation; author: H. Peter Anvin * Copyright 2010 Shao Miller - * Copyright 2010 Michal Soltys + * Copyright 2010-2012 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 diff --git a/com32/chain/chain.h b/com32/chain/chain.h index fc481bc..fb5914b 100644 --- a/com32/chain/chain.h +++ b/com32/chain/chain.h @@ -1,5 +1,20 @@ -#ifndef _COM32_CHAIN_CHAIN_H -#define _COM32_CHAIN_CHAIN_H +/* ----------------------------------------------------------------------- * + * + * Copyright 2003-2009 H. Peter Anvin - All Rights Reserved + * Copyright 2009-2010 Intel Corporation; author: H. Peter Anvin + * Copyright 2010 Shao Miller + * Copyright 2010-2012 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. + * + * ----------------------------------------------------------------------- */ + +#ifndef COM32_CHAIN_CHAIN_H +#define COM32_CHAIN_CHAIN_H #include <syslinux/movebits.h> diff --git a/com32/chain/common.h b/com32/chain/common.h index b170a73..65f78f0 100644 --- a/com32/chain/common.h +++ b/com32/chain/common.h @@ -1,5 +1,35 @@ -#ifndef _COM32_CHAIN_COMMON_H -#define _COM32_CHAIN_COMMON_H +/* ----------------------------------------------------------------------- * + * + * Copyright 2003-2009 H. Peter Anvin - All Rights Reserved + * Copyright 2009-2010 Intel Corporation; author: H. Peter Anvin + * Copyright 2010 Shao Miller + * Copyright 2010-2012 Michal Soltys + * + * 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. + * + * ----------------------------------------------------------------------- */ + +#ifndef COM32_CHAIN_COMMON_H +#define COM32_CHAIN_COMMON_H #define ADDRMAX 0x9EFFFu #define ADDRMIN 0x500u diff --git a/com32/chain/mangle.c b/com32/chain/mangle.c index 8358106..e3c494c 100644 --- a/com32/chain/mangle.c +++ b/com32/chain/mangle.c @@ -1,3 +1,33 @@ +/* ----------------------------------------------------------------------- * + * + * Copyright 2003-2009 H. Peter Anvin - All Rights Reserved + * Copyright 2009-2010 Intel Corporation; author: H. Peter Anvin + * Copyright 2010 Shao Miller + * Copyright 2010-2012 Michal Soltys + * + * 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. + * + * ----------------------------------------------------------------------- */ + #include <com32.h> #include <stdlib.h> #include <stdio.h> diff --git a/com32/chain/mangle.h b/com32/chain/mangle.h index bcefea3..d4a5b75 100644 --- a/com32/chain/mangle.h +++ b/com32/chain/mangle.h @@ -1,5 +1,35 @@ -#ifndef _COM32_CHAIN_MANGLE_H -#define _COM32_CHAIN_MANGLE_H +/* ----------------------------------------------------------------------- * + * + * Copyright 2003-2009 H. Peter Anvin - All Rights Reserved + * Copyright 2009-2010 Intel Corporation; author: H. Peter Anvin + * Copyright 2010 Shao Miller + * Copyright 2010-2012 Michal Soltys + * + * 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. + * + * ----------------------------------------------------------------------- */ + +#ifndef COM32_CHAIN_MANGLE_H +#define COM32_CHAIN_MANGLE_H #include "chain.h" #include "partiter.h" diff --git a/com32/chain/options.c b/com32/chain/options.c index 658a45c..5f7433d 100644 --- a/com32/chain/options.c +++ b/com32/chain/options.c @@ -1,3 +1,33 @@ +/* ----------------------------------------------------------------------- * + * + * Copyright 2003-2009 H. Peter Anvin - All Rights Reserved + * Copyright 2009-2010 Intel Corporation; author: H. Peter Anvin + * Copyright 2010 Shao Miller + * Copyright 2010-2012 Michal Soltys + * + * 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. + * + * ----------------------------------------------------------------------- */ + #include <stdint.h> #include <stdlib.h> #include <string.h> diff --git a/com32/chain/options.h b/com32/chain/options.h index 4493ef1..c3e1af6 100644 --- a/com32/chain/options.h +++ b/com32/chain/options.h @@ -1,5 +1,35 @@ -#ifndef _COM32_CHAIN_OPTIONS_H -#define _COM32_CHAIN_OPTIONS_H +/* ----------------------------------------------------------------------- * + * + * Copyright 2003-2009 H. Peter Anvin - All Rights Reserved + * Copyright 2009-2010 Intel Corporation; author: H. Peter Anvin + * Copyright 2010 Shao Miller + * Copyright 2010-2012 Michal Soltys + * + * 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. + * + * ----------------------------------------------------------------------- */ + +#ifndef COM32_CHAIN_OPTIONS_H +#define COM32_CHAIN_OPTIONS_H #include <stdint.h> #include <syslinux/bootrm.h> diff --git a/com32/chain/partiter.c b/com32/chain/partiter.c index 1acd195..7a6006b 100644 --- a/com32/chain/partiter.c +++ b/com32/chain/partiter.c @@ -1,8 +1,9 @@ /* ----------------------------------------------------------------------- * * - * Copyright 2003-2010 H. Peter Anvin - All Rights Reserved + * Copyright 2003-2009 H. Peter Anvin - All Rights Reserved + * Copyright 2009-2010 Intel Corporation; author: H. Peter Anvin * Copyright 2010 Shao Miller - * Copyright 2010 Michal Soltys + * Copyright 2010-2012 Michal Soltys * * Permission is hereby granted, free of charge, to any person * obtaining a copy of this software and associated documentation diff --git a/com32/chain/partiter.h b/com32/chain/partiter.h index 7deeb53..8b47822 100644 --- a/com32/chain/partiter.h +++ b/com32/chain/partiter.h @@ -1,8 +1,9 @@ /* ----------------------------------------------------------------------- * * - * Copyright 2003-2010 H. Peter Anvin - All Rights Reserved - * Copyright 2010 Michal Soltys + * Copyright 2003-2009 H. Peter Anvin - All Rights Reserved + * Copyright 2009-2010 Intel Corporation; author: H. Peter Anvin * Copyright 2010 Shao Miller + * Copyright 2010-2012 Michal Soltys * * Permission is hereby granted, free of charge, to any person * obtaining a copy of this software and associated documentation @@ -33,8 +34,8 @@ * Provides disk / partition iteration. */ -#ifndef _COM32_CHAIN_PARTITER_H -#define _COM32_CHAIN_PARTITER_H +#ifndef COM32_CHAIN_PARTITER_H +#define COM32_CHAIN_PARTITER_H #include <stdint.h> #include <syslinux/disk.h> diff --git a/com32/chain/utility.c b/com32/chain/utility.c index fb59551..bc5b81a 100644 --- a/com32/chain/utility.c +++ b/com32/chain/utility.c @@ -1,3 +1,33 @@ +/* ----------------------------------------------------------------------- * + * + * Copyright 2003-2009 H. Peter Anvin - All Rights Reserved + * Copyright 2009-2010 Intel Corporation; author: H. Peter Anvin + * Copyright 2010 Shao Miller + * Copyright 2010-2012 Michal Soltys + * + * 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. + * + * ----------------------------------------------------------------------- */ + #include <com32.h> #include <stdint.h> #include <stdio.h> diff --git a/com32/chain/utility.h b/com32/chain/utility.h index 8a08be7..4e32dcd 100644 --- a/com32/chain/utility.h +++ b/com32/chain/utility.h @@ -1,5 +1,35 @@ -#ifndef _COM32_CHAIN_UTILITY_H -#define _COM32_CHAIN_UTILITY_H +/* ----------------------------------------------------------------------- * + * + * Copyright 2003-2009 H. Peter Anvin - All Rights Reserved + * Copyright 2009-2010 Intel Corporation; author: H. Peter Anvin + * Copyright 2010 Shao Miller + * Copyright 2010-2012 Michal Soltys + * + * 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. + * + * ----------------------------------------------------------------------- */ + +#ifndef COM32_CHAIN_UTILITY_H +#define COM32_CHAIN_UTILITY_H #include <stdint.h> #include <syslinux/disk.h> -- 1.7.10.4
Michal Soltys
2013-Jan-29 14:05 UTC
[syslinux] [PATCH 02/28] com32/chain: comments, minor adjustment
- add some comments to clarify c{nul,add,max} modes - use enums instead of defines - remove unnecessary integer casts - avoid casts and uninline guid_is0() - minor handover comment/flow changes - clean up some old comment-outs Signed-off-by: Michal Soltys <soltys at ziu.info> --- com32/chain/chain.c | 46 ++++++++++++++++++++++++---------------------- com32/chain/mangle.c | 37 ++++++++++++++++++------------------- com32/chain/options.c | 16 +--------------- com32/chain/partiter.c | 6 +++--- com32/chain/utility.c | 45 +++++++++++++++++++++++++++++---------------- com32/chain/utility.h | 17 +++++++++++------ 6 files changed, 86 insertions(+), 81 deletions(-) diff --git a/com32/chain/chain.c b/com32/chain/chain.c index f0ccd97..617e9e3 100644 --- a/com32/chain/chain.c +++ b/com32/chain/chain.c @@ -247,14 +247,14 @@ static void do_boot(struct data_area *data, int ndata) /* Mapping table; start out with identity mapping everything */ for (i = 0; i < 256; i++) - p[i] = (uint8_t)i; + p[i] = i; /* And the actual swap */ p[driveno] = swapdrive; p[swapdrive] = driveno; /* Adjust registers */ - opt.regs.ds = opt.regs.cs = (uint16_t)(endimage >> 4); + opt.regs.ds = opt.regs.cs = endimage >> 4; opt.regs.esi.l = opt.regs.es = 0; opt.regs.ecx.l = sizeof swapstub >> 2; opt.regs.ip = 0x10; /* Installer offset */ @@ -401,13 +401,15 @@ static int setup_handover(const struct part_iter *iter, struct data_area *data) { struct disk_dos_part_entry *ha; - uint32_t synth_size; - uint32_t *plen; + uint32_t synth_size = sizeof *ha; - if (!iter->index) { /* implies typeraw or non-iterated */ + /* + * we have to cover both non-iterated but otherwise properly detected + * gpt/dos schemes as well as raw disks; checking index for 0 covers both + */ + if (iter->index == 0) { uint32_t len; /* RAW handover protocol */ - synth_size = sizeof(struct disk_dos_part_entry); ha = malloc(synth_size); if (!ha) { error("Could not build RAW hand-over record!\n"); @@ -415,24 +417,24 @@ static int setup_handover(const struct part_iter *iter, } len = ~0u; if (iter->length < len) - len = (uint32_t)iter->length; - lba2chs(&ha->start, &iter->di, 0, l2c_cadd); - lba2chs(&ha->end, &iter->di, len - 1, l2c_cadd); + len = iter->length; + lba2chs(&ha->start, &iter->di, 0, L2C_CADD); + lba2chs(&ha->end, &iter->di, len - 1, L2C_CADD); ha->active_flag = 0x80; ha->ostype = 0xDA; /* "Non-FS Data", anything is good here though ... */ ha->start_lba = 0; ha->length = len; } else if (iter->type == typegpt) { + uint32_t *plen; /* GPT handover protocol */ - synth_size = sizeof(struct disk_dos_part_entry) + - sizeof(uint32_t) + (uint32_t)iter->sub.gpt.pe_size; + synth_size += sizeof *plen + iter->sub.gpt.pe_size; ha = malloc(synth_size); if (!ha) { error("Could not build GPT hand-over record!\n"); goto bail; } - lba2chs(&ha->start, &iter->di, iter->start_lba, l2c_cadd); - lba2chs(&ha->end, &iter->di, iter->start_lba + iter->length - 1, l2c_cadd); + lba2chs(&ha->start, &iter->di, iter->start_lba, L2C_CADD); + lba2chs(&ha->end, &iter->di, iter->start_lba + iter->length - 1, L2C_CADD); ha->active_flag = 0x80; ha->ostype = 0xED; /* All bits set by default */ @@ -440,12 +442,12 @@ static int setup_handover(const struct part_iter *iter, ha->length = ~0u; /* If these fit the precision, pass them on */ if (iter->start_lba < ha->start_lba) - ha->start_lba = (uint32_t)iter->start_lba; + ha->start_lba = iter->start_lba; if (iter->length < ha->length) - ha->length = (uint32_t)iter->length; + ha->length = iter->length; /* Next comes the GPT partition record length */ - plen = (uint32_t *) (ha + 1); - plen[0] = (uint32_t)iter->sub.gpt.pe_size; + plen = (uint32_t *)(ha + 1); + plen[0] = iter->sub.gpt.pe_size; /* Next comes the GPT partition record copy */ memcpy(plen + 1, iter->record, plen[0]); #ifdef DEBUG @@ -453,9 +455,9 @@ static int setup_handover(const struct part_iter *iter, disk_dos_part_dump(ha); disk_gpt_part_dump((struct disk_gpt_part_entry *)(plen + 1)); #endif + /* the only possible case left is dos scheme */ } else if (iter->type == typedos) { /* MBR handover protocol */ - synth_size = sizeof(struct disk_dos_part_entry); ha = malloc(synth_size); if (!ha) { error("Could not build MBR hand-over record!\n"); @@ -463,10 +465,10 @@ static int setup_handover(const struct part_iter *iter, } memcpy(ha, iter->record, synth_size); /* make sure these match bios imaginations and are ebr agnostic */ - lba2chs(&ha->start, &iter->di, iter->start_lba, l2c_cadd); - lba2chs(&ha->end, &iter->di, iter->start_lba + iter->length - 1, l2c_cadd); - ha->start_lba = (uint32_t)iter->start_lba; - ha->length = (uint32_t)iter->length; + lba2chs(&ha->start, &iter->di, iter->start_lba, L2C_CADD); + lba2chs(&ha->end, &iter->di, iter->start_lba + iter->length - 1, L2C_CADD); + ha->start_lba = iter->start_lba; + ha->length = iter->length; #ifdef DEBUG dprintf("MBR handover:\n"); diff --git a/com32/chain/mangle.c b/com32/chain/mangle.c index e3c494c..69004b8 100644 --- a/com32/chain/mangle.c +++ b/com32/chain/mangle.c @@ -204,7 +204,7 @@ int manglef_grub(const struct part_iter *iter, struct data_area *data) * 0-3: primary partitions * 4-*: logical partitions */ - stage2->install_partition.part1 = (uint8_t)(iter->index - 1); + stage2->install_partition.part1 = iter->index - 1; /* * Grub Legacy reserves 89 bytes (from 0x8217 to 0x826f) for the @@ -264,9 +264,9 @@ int manglef_drmk(struct data_area *data) data->size = tsize; /* ds:bp is assumed by DRMK to be the boot sector */ /* offset 28 is the FAT HiddenSectors value */ - opt.regs.ds = (uint16_t)((tsize >> 4) + (opt.fseg - 2)); + opt.regs.ds = (tsize >> 4) + (opt.fseg - 2); /* "Patch" into tail of the new space */ - *(uint32_t *)((char*)data->data + tsize - 4) = (uint32_t)fs_lba; + *(uint32_t *)((char*)data->data + tsize - 4) = fs_lba; return 0; bail: @@ -282,7 +282,7 @@ static int mangle_bpb(const struct part_iter *iter, struct data_area *data, cons /* BPB: hidden sectors 32bit*/ if (type >= bpbV34) { if (iter->start_lba < ~0u) - *(uint32_t *) ((char *)data->data + 0x1c) = (uint32_t)iter->start_lba; + *(uint32_t *) ((char *)data->data + 0x1c) = iter->start_lba; else /* won't really help much, but ... */ *(uint32_t *) ((char *)data->data + 0x1c) = ~0u; @@ -290,7 +290,7 @@ static int mangle_bpb(const struct part_iter *iter, struct data_area *data, cons /* BPB: hidden sectors 16bit*/ if (bpbV30 <= type && type <= bpbV32) { if (iter->start_lba < 0xFFFF) - *(uint16_t *) ((char *)data->data + 0x1c) = (uint16_t)iter->start_lba; + *(uint16_t *) ((char *)data->data + 0x1c) = iter->start_lba; else /* won't really help much, but ... */ *(uint16_t *) ((char *)data->data + 0x1c) = (uint16_t)~0u; @@ -298,7 +298,7 @@ static int mangle_bpb(const struct part_iter *iter, struct data_area *data, cons /* BPB: legacy geometry */ if (type >= bpbV30) { if (iter->di.cbios) - *(uint32_t *)((char *)data->data + 0x18) = (uint32_t)((iter->di.head << 16) | iter->di.spt); + *(uint32_t *)((char *)data->data + 0x18) = (iter->di.head << 16) | iter->di.spt; else { if (iter->di.disk & 0x80) *(uint32_t *)((char *)data->data + 0x18) = 0x00FF003F; @@ -308,8 +308,7 @@ static int mangle_bpb(const struct part_iter *iter, struct data_area *data, cons } /* BPB: drive */ if (drvoff_detect(type, &off)) { - *(uint8_t *)((char *)data->data + off) = (uint8_t) - (opt.swap ? iter->di.disk & 0x80 : iter->di.disk); + *(uint8_t *)((char *)data->data + off) = (opt.swap ? iter->di.disk & 0x80 : iter->di.disk); } return 0; @@ -427,18 +426,18 @@ int mangler_init(const struct part_iter *iter) { /* Set initial registry values */ if (opt.file) { - opt.regs.cs = opt.regs.ds = opt.regs.ss = (uint16_t)opt.fseg; - opt.regs.ip = (uint16_t)opt.fip; + opt.regs.cs = opt.regs.ds = opt.regs.ss = opt.fseg; + opt.regs.ip = opt.fip; } else { - opt.regs.cs = opt.regs.ds = opt.regs.ss = (uint16_t)opt.sseg; - opt.regs.ip = (uint16_t)opt.sip; + opt.regs.cs = opt.regs.ds = opt.regs.ss = opt.sseg; + opt.regs.ip = opt.sip; } if (opt.regs.ip == 0x7C00 && !opt.regs.cs) opt.regs.esp.l = 0x7C00; /* DOS kernels want the drive number in BL instead of DL. Indulge them. */ - opt.regs.ebx.b[0] = opt.regs.edx.b[0] = (uint8_t)iter->di.disk; + opt.regs.ebx.b[0] = opt.regs.edx.b[0] = iter->di.disk; return 0; } @@ -448,7 +447,7 @@ int mangler_handover(const struct part_iter *iter, const struct data_area *data) { if (opt.file && opt.maps && !opt.hptr) { opt.regs.esi.l = opt.regs.ebp.l = opt.soff; - opt.regs.ds = (uint16_t)opt.sseg; + opt.regs.ds = opt.sseg; opt.regs.eax.l = 0; } else if (opt.hand) { /* base is really 0x7be */ @@ -472,7 +471,7 @@ int mangler_handover(const struct part_iter *iter, const struct data_area *data) int mangler_grldr(const struct part_iter *iter) { if (opt.grldr) - opt.regs.edx.b[1] = (uint8_t)(iter->index - 1); + opt.regs.edx.b[1] = iter->index - 1; return 0; } @@ -502,7 +501,7 @@ static int mpe_sethide(struct part_iter *iter, struct part_iter *miter) if ((t <= 0x1f) && ((mask >> (t & ~0x10u)) & 1)) { /* It's a hideable partition type */ if (miter->index == iter->index || opt.hide & 4) - t &= (uint8_t)(~0x10u); /* unhide */ + t &= ~0x10u; /* unhide */ else t |= 0x10u; /* hide */ } @@ -585,8 +584,8 @@ static int mpe_setchs(const struct disk_info *di, ochs1 = *(uint32_t *)dp->start; ochs2 = *(uint32_t *)dp->end; - lba2chs(&dp->start, di, lba1, l2c_cadd); - lba2chs(&dp->end, di, lba1 + dp->length - 1, l2c_cadd); + lba2chs(&dp->start, di, lba1, L2C_CADD); + lba2chs(&dp->end, di, lba1 + dp->length - 1, L2C_CADD); return *(uint32_t *)dp->start != ochs1 || @@ -618,7 +617,7 @@ int manglepe_fixchs(struct part_iter *miter) ridx = iter->rawindex; dp = (struct disk_dos_part_entry *)iter->record; - wb |= mpe_setchs(&iter->di, dp, (uint32_t)iter->start_lba); + wb |= mpe_setchs(&iter->di, dp, iter->start_lba); if (ridx > 4) wb |= mpe_setchs(&iter->di, dp + 1, iter->sub.dos.nebr_lba); diff --git a/com32/chain/options.c b/com32/chain/options.c index 5f7433d..b831afa 100644 --- a/com32/chain/options.c +++ b/com32/chain/options.c @@ -166,7 +166,7 @@ void opt_set_defs(void) int opt_parse_args(int argc, char *argv[]) { int i; - unsigned int v; + size_t v; char *p; for (i = 1; i < argc; i++) { @@ -182,7 +182,6 @@ int opt_parse_args(int argc, char *argv[]) opt.bss = true; opt.maps = false; opt.setbpb = true; - /* opt.save = true; */ } else if (!strncmp(argv[i], "bs=", 3)) { opt.file = argv[i] + 3; opt.sect = false; @@ -198,7 +197,6 @@ int opt_parse_args(int argc, char *argv[]) opt.fip = 0; opt.file = argv[i] + 6; opt.setbpb = true; - /* opt.save = true; */ opt.hand = false; } else if (!strncmp(argv[i], "reactos=", 8)) { /* @@ -212,7 +210,6 @@ int opt_parse_args(int argc, char *argv[]) opt.fip = 0x8100; opt.file = argv[i] + 8; opt.setbpb = true; - /* opt.save = true; */ opt.hand = false; } else if (!strncmp(argv[i], "cmldr=", 6)) { opt.fseg = 0x2000; /* CMLDR wants this address */ @@ -221,7 +218,6 @@ int opt_parse_args(int argc, char *argv[]) opt.file = argv[i] + 6; opt.cmldr = true; opt.setbpb = true; - /* opt.save = true; */ opt.hand = false; } else if (!strncmp(argv[i], "freedos=", 8)) { opt.fseg = 0x60; /* FREEDOS wants this address */ @@ -230,7 +226,6 @@ int opt_parse_args(int argc, char *argv[]) opt.sseg = 0x1FE0; opt.file = argv[i] + 8; opt.setbpb = true; - /* opt.save = true; */ opt.hand = false; } else if ( (v = 6, !strncmp(argv[i], "msdos=", v) || !strncmp(argv[i], "pcdos=", v)) || @@ -241,7 +236,6 @@ int opt_parse_args(int argc, char *argv[]) opt.sseg = 0x8000; opt.file = argv[i] + v; opt.setbpb = true; - /* opt.save = true; */ opt.hand = false; } else if (!strncmp(argv[i], "drmk=", 5)) { opt.fseg = 0x70; /* DRMK wants this address */ @@ -253,7 +247,6 @@ int opt_parse_args(int argc, char *argv[]) opt.file = argv[i] + 5; /* opt.drmk = true; */ opt.setbpb = true; - /* opt.save = true; */ opt.hand = false; } else if (!strncmp(argv[i], "grub=", 5)) { opt.fseg = 0x800; /* stage2 wants this address */ @@ -371,13 +364,6 @@ int opt_parse_args(int argc, char *argv[]) goto bail; } -#if 0 - if ((!opt.maps || !opt.sect) && !opt.file) { - error("You have to load something.\n"); - goto bail; - } -#endif - if (opt.filebpb && !opt.file) { error("Option 'filebpb' requires a file.\n"); goto bail; diff --git a/com32/chain/partiter.c b/com32/chain/partiter.c index 7a6006b..092cca2 100644 --- a/com32/chain/partiter.c +++ b/com32/chain/partiter.c @@ -765,7 +765,7 @@ struct part_iter *pi_begin(const struct disk_info *di, int stepall) error("Invalid GPT header's values.\n"); goto bail; } - if (!(gptl = disk_read_sectors(di, gpt_loff, (uint8_t)gpt_lcnt))) { + if (!(gptl = disk_read_sectors(di, gpt_loff, gpt_lcnt))) { error("Couldn't read GPT partition list.\n"); goto bail; } @@ -774,11 +774,11 @@ struct part_iter *pi_begin(const struct disk_info *di, int stepall) error("WARNING: GPT partition list checksum invalid, trying backup.\n"); free(gptl); /* secondary array directly precedes secondary header */ - if (!(gptl = disk_read_sectors(di, gpth->lba_alt - gpt_lcnt, (uint8_t)gpt_lcnt))) { + if (!(gptl = disk_read_sectors(di, gpth->lba_alt - gpt_lcnt, gpt_lcnt))) { error("Couldn't read backup GPT partition list.\n"); goto bail; } - if (check_crc(gpth->table_chksum, (const uint8_t *)gptl, (unsigned int)gpt_lsiz)) { + if (check_crc(gpth->table_chksum, (const uint8_t *)gptl, gpt_lsiz)) { error("Backup GPT partition list checksum invalid.\n"); goto bail; } diff --git a/com32/chain/utility.c b/com32/chain/utility.c index bc5b81a..172707e 100644 --- a/com32/chain/utility.c +++ b/com32/chain/utility.c @@ -48,16 +48,6 @@ static const char *bpbtypes[] = { [7] = "7.0", }; -void error(const char *msg) -{ - fputs(msg, stderr); -} - -int guid_is0(const struct guid *guid) -{ - return !*(const uint64_t *)guid && !*((const uint64_t *)guid + 1); -} - void wait_key(void) { int cnt; @@ -76,7 +66,29 @@ void wait_key(void) } while (!cnt || (cnt < 0 && errno == EAGAIN)); } -void lba2chs(disk_chs *dst, const struct disk_info *di, uint64_t lba, uint32_t mode) +int guid_is0(const struct guid *guid) +{ + return + !(guid->data1 || + guid->data2 || + guid->data3 || + guid->data4); +} + +/* + * mode explanation: + * + * cnul - "strict" mode, never returning higher value than obtained from cbios + * cadd - if the disk is larger than reported geometry /and/ if the geometry has + * less cylinders than 1024 - it means that the total size is somewhere + * between cs and cs+1; in this particular case, we bump the cs to be able + * to return matching chs triplet + * cmax - assume we can use any cylinder value + * + * by default cadd seems most reasonable, giving consistent results with e.g. + * sfdisk's behavior + */ +void lba2chs(disk_chs *dst, const struct disk_info *di, uint64_t lba, int mode) { uint32_t c, h, s, t; uint32_t cs, hs, ss; @@ -89,9 +101,10 @@ void lba2chs(disk_chs *dst, const struct disk_info *di, uint64_t lba, uint32_t m cs = di->cyl; hs = di->head; ss = di->spt; - if (mode == l2c_cadd && cs < 1024 && di->lbacnt > cs*hs*ss) - cs++; - else if (mode == l2c_cmax) + if (mode == L2C_CADD) { + if (cs < 1024 && di->lbacnt > cs*hs*ss) + cs++; + } else if (mode == L2C_CMAX) cs = 1024; } else { if (di->disk & 0x80) { @@ -110,8 +123,8 @@ void lba2chs(disk_chs *dst, const struct disk_info *di, uint64_t lba, uint32_t m h = hs - 1; c = cs - 1; } else { - s = ((uint32_t)lba % ss) + 1; - t = (uint32_t)lba / ss; + s = (lba % ss) + 1; + t = lba / ss; h = t % hs; c = t / hs; } diff --git a/com32/chain/utility.h b/com32/chain/utility.h index 4e32dcd..769c4d1 100644 --- a/com32/chain/utility.h +++ b/com32/chain/utility.h @@ -32,6 +32,7 @@ #define COM32_CHAIN_UTILITY_H #include <stdint.h> +#include <stdio.h> #include <syslinux/disk.h> #define bpbUNK 0 @@ -43,17 +44,21 @@ #define bpbVNT 6 #define bpbV70 7 -#define l2c_cnul 0 -#define l2c_cadd 1 -#define l2c_cmax 2 +/* see utility.c for details */ +enum {L2C_CNUL, L2C_CADD, L2C_CMAX}; -void error(const char *msg); -int guid_is0(const struct guid *guid); void wait_key(void); -void lba2chs(disk_chs *dst, const struct disk_info *di, uint64_t lba, uint32_t mode); +void lba2chs(disk_chs *dst, const struct disk_info *di, uint64_t lba, int mode); uint32_t get_file_lba(const char *filename); int drvoff_detect(int type, unsigned int *off); int bpb_detect(const uint8_t *bpb, const char *tag); +int guid_is0(const struct guid *guid); + +static inline +void error(const char *msg) +{ + fputs(msg, stderr); +} #endif -- 1.7.10.4
Michal Soltys
2013-Jan-29 14:05 UTC
[syslinux] [PATCH 03/28] com32/chain: use anonymous and unnamed aggregates
Signed-off-by: Michal Soltys <soltys at ziu.info> --- com32/chain/chain.c | 12 +++---- com32/chain/mangle.c | 12 +++---- com32/chain/partiter.c | 84 ++++++++++++++++++++++++------------------------ com32/chain/partiter.h | 8 ++--- 4 files changed, 58 insertions(+), 58 deletions(-) diff --git a/com32/chain/chain.c b/com32/chain/chain.c index 617e9e3..d76c669 100644 --- a/com32/chain/chain.c +++ b/com32/chain/chain.c @@ -79,7 +79,7 @@ static int find_by_sig(uint32_t mbr_sig, pi_del(&boot_part); continue; } - if (boot_part->sub.dos.disk_sig == mbr_sig) { + if (boot_part->dos.disk_sig == mbr_sig) { goto ok; } } @@ -111,12 +111,12 @@ static int find_by_guid(const struct guid *gpt_guid, continue; } /* Check for a matching GPT disk guid */ - if (!memcmp(&boot_part->sub.gpt.disk_guid, gpt_guid, sizeof(*gpt_guid))) { + if (!memcmp(&boot_part->gpt.disk_guid, gpt_guid, sizeof(*gpt_guid))) { goto ok; } /* disk guid doesn't match, maybe partition guid will */ while (!pi_next(&boot_part)) { - if (!memcmp(&boot_part->sub.gpt.part_guid, gpt_guid, sizeof(*gpt_guid))) + if (!memcmp(&boot_part->gpt.part_guid, gpt_guid, sizeof(*gpt_guid))) goto ok; } } @@ -148,7 +148,7 @@ static int find_by_label(const char *label, struct part_iter **_boot_part) } /* Check for a matching partition */ while (!pi_next(&boot_part)) { - if (!strcmp(label, boot_part->sub.gpt.part_label)) + if (!strcmp(label, boot_part->gpt.part_label)) goto ok; } } @@ -427,7 +427,7 @@ static int setup_handover(const struct part_iter *iter, } else if (iter->type == typegpt) { uint32_t *plen; /* GPT handover protocol */ - synth_size += sizeof *plen + iter->sub.gpt.pe_size; + synth_size += sizeof *plen + iter->gpt.pe_size; ha = malloc(synth_size); if (!ha) { error("Could not build GPT hand-over record!\n"); @@ -447,7 +447,7 @@ static int setup_handover(const struct part_iter *iter, ha->length = iter->length; /* Next comes the GPT partition record length */ plen = (uint32_t *)(ha + 1); - plen[0] = iter->sub.gpt.pe_size; + plen[0] = iter->gpt.pe_size; /* Next comes the GPT partition record copy */ memcpy(plen + 1, iter->record, plen[0]); #ifdef DEBUG diff --git a/com32/chain/mangle.c b/com32/chain/mangle.c index 69004b8..8185a17 100644 --- a/com32/chain/mangle.c +++ b/com32/chain/mangle.c @@ -481,7 +481,7 @@ int mangler_grldr(const struct part_iter *iter) */ static void push_embr(struct part_iter *diter, struct part_iter *siter) { - if (diter->sub.dos.cebr_lba == siter->sub.dos.cebr_lba && + if (diter->dos.cebr_lba == siter->dos.cebr_lba && diter->di.disk == siter->di.disk) { memcpy(diter->data, siter->data, sizeof(struct disk_dos_mbr)); } @@ -554,7 +554,7 @@ int manglepe_hide(struct part_iter *miter) if (ridx >= 4 && wb && !werr) { push_embr(miter, iter); - werr |= disk_write_sectors(&iter->di, iter->sub.dos.cebr_lba, iter->data, 1); + werr |= disk_write_sectors(&iter->di, iter->dos.cebr_lba, iter->data, 1); wb = 0; } } @@ -565,7 +565,7 @@ int manglepe_hide(struct part_iter *miter) /* last write */ if (wb && !werr) { push_embr(miter, iter); - werr |= disk_write_sectors(&iter->di, iter->sub.dos.cebr_lba, iter->data, 1); + werr |= disk_write_sectors(&iter->di, iter->dos.cebr_lba, iter->data, 1); } if (werr) error("WARNING: failed to write E/MBR during '*hide*'\n"); @@ -619,11 +619,11 @@ int manglepe_fixchs(struct part_iter *miter) wb |= mpe_setchs(&iter->di, dp, iter->start_lba); if (ridx > 4) - wb |= mpe_setchs(&iter->di, dp + 1, iter->sub.dos.nebr_lba); + wb |= mpe_setchs(&iter->di, dp + 1, iter->dos.nebr_lba); if (ridx >= 4 && wb && !werr) { push_embr(miter, iter); - werr |= disk_write_sectors(&iter->di, iter->sub.dos.cebr_lba, iter->data, 1); + werr |= disk_write_sectors(&iter->di, iter->dos.cebr_lba, iter->data, 1); wb = 0; } } @@ -634,7 +634,7 @@ int manglepe_fixchs(struct part_iter *miter) /* last write */ if (wb && !werr) { push_embr(miter, iter); - werr |= disk_write_sectors(&iter->di, iter->sub.dos.cebr_lba, iter->data, 1); + werr |= disk_write_sectors(&iter->di, iter->dos.cebr_lba, iter->data, 1); } if (werr) error("WARNING: failed to write E/MBR during 'fixchs'\n"); diff --git a/com32/chain/partiter.c b/com32/chain/partiter.c index 092cca2..9352fcc 100644 --- a/com32/chain/partiter.c +++ b/com32/chain/partiter.c @@ -155,8 +155,8 @@ static int iter_dos_ctor(struct part_iter *iter, va_list *args) memcpy(iter->data, mbr, sizeof(struct disk_dos_mbr)); - iter->sub.dos.bebr_index0 = -1; - iter->sub.dos.disk_sig = mbr->disk_sig; + iter->dos.bebr_index0 = -1; + iter->dos.disk_sig = mbr->disk_sig; return 0; bail: @@ -207,12 +207,12 @@ static int iter_gpt_ctor(struct part_iter *iter, va_list *args) memcpy(iter->data, gptl, (size_t)siz); - iter->sub.gpt.pe_count = (int)gpth->part_count; - iter->sub.gpt.pe_size = (int)gpth->part_size; - iter->sub.gpt.ufirst = gpth->lba_first_usable; - iter->sub.gpt.ulast = gpth->lba_last_usable; + iter->gpt.pe_count = (int)gpth->part_count; + iter->gpt.pe_size = (int)gpth->part_size; + iter->gpt.ufirst = gpth->lba_first_usable; + iter->gpt.ulast = gpth->lba_last_usable; - memcpy(&iter->sub.gpt.disk_guid, &gpth->disk_guid, sizeof(struct guid)); + memcpy(&iter->gpt.disk_guid, &gpth->disk_guid, sizeof(struct guid)); return 0; bail: @@ -247,7 +247,7 @@ static int notsane_logical(const struct part_iter *iter) if (!dp[0].start_lba || !dp[0].length || !sane(dp[0].start_lba, dp[0].length) || - end_log > iter->sub.dos.ebr_size) { + end_log > iter->dos.ebr_size) { error("Insane logical partition.\n"); return -1; @@ -283,7 +283,7 @@ static int notsane_extended(const struct part_iter *iter) if (!dp[1].start_lba || !dp[1].length || !sane(dp[1].start_lba, dp[1].length) || - end_ebr > iter->sub.dos.bebr_size) { + end_ebr > iter->dos.bebr_size) { error("Insane extended partition.\n"); return -1; @@ -320,13 +320,13 @@ static int notsane_gpt(const struct part_iter *iter) { const struct disk_gpt_part_entry *gp; gp = (const struct disk_gpt_part_entry *) - (iter->data + iter->index0 * iter->sub.gpt.pe_size); + (iter->data + iter->index0 * iter->gpt.pe_size); if (guid_is0(&gp->type)) return 0; - if (gp->lba_first < iter->sub.gpt.ufirst || - gp->lba_last > iter->sub.gpt.ulast) { + if (gp->lba_first < iter->gpt.ufirst || + gp->lba_last > iter->gpt.ulast) { error("Insane GPT partition.\n"); return -1; } @@ -348,13 +348,13 @@ static int pi_dos_next_mbr(struct part_iter *iter, uint32_t *lba, } if (ost_is_ext(dp->ostype)) { - if (iter->sub.dos.bebr_index0 >= 0) { + if (iter->dos.bebr_index0 >= 0) { error("You have more than 1 extended partition.\n"); iter->status = PI_INSANE; goto bail; } /* record base EBR index */ - iter->sub.dos.bebr_index0 = iter->index0; + iter->dos.bebr_index0 = iter->index0; } if (!ost_is_nondata(dp->ostype) || iter->stepall) { *lba = dp->start_lba; @@ -372,19 +372,19 @@ static int prep_base_ebr(struct part_iter *iter) { struct disk_dos_part_entry *dp; - if (iter->sub.dos.bebr_index0 < 0) /* if we don't have base extended partition at all */ + if (iter->dos.bebr_index0 < 0) /* if we don't have base extended partition at all */ return -1; - else if (!iter->sub.dos.bebr_start) { /* if not initialized yet */ - dp = ((struct disk_dos_mbr *)iter->data)->table + iter->sub.dos.bebr_index0; + else if (!iter->dos.bebr_start) { /* if not initialized yet */ + dp = ((struct disk_dos_mbr *)iter->data)->table + iter->dos.bebr_index0; - iter->sub.dos.bebr_start = dp->start_lba; - iter->sub.dos.bebr_size = dp->length; + iter->dos.bebr_start = dp->start_lba; + iter->dos.bebr_size = dp->length; - iter->sub.dos.ebr_start = 0; - iter->sub.dos.ebr_size = iter->sub.dos.bebr_size; + iter->dos.ebr_start = 0; + iter->dos.ebr_size = iter->dos.bebr_size; - iter->sub.dos.cebr_lba = 0; - iter->sub.dos.nebr_lba = iter->sub.dos.bebr_start; + iter->dos.cebr_lba = 0; + iter->dos.nebr_lba = iter->dos.bebr_start; iter->index0--; } @@ -401,10 +401,10 @@ static int pi_dos_next_ebr(struct part_iter *iter, uint32_t *lba, return -1; } - while (++iter->index0 < 1024 && iter->sub.dos.nebr_lba) { + while (++iter->index0 < 1024 && iter->dos.nebr_lba) { free(iter->data); if (!(iter->data - disk_read_sectors(&iter->di, iter->sub.dos.nebr_lba, 1))) { + disk_read_sectors(&iter->di, iter->dos.nebr_lba, 1))) { error("Couldn't load EBR.\n"); iter->status = PI_ERRLOAD; return -1; @@ -417,24 +417,24 @@ static int pi_dos_next_ebr(struct part_iter *iter, uint32_t *lba, dp = ((struct disk_dos_mbr *)iter->data)->table; - iter->sub.dos.cebr_lba = iter->sub.dos.nebr_lba; + iter->dos.cebr_lba = iter->dos.nebr_lba; /* setup next frame values */ if (dp[1].ostype) { - iter->sub.dos.ebr_start = dp[1].start_lba; - iter->sub.dos.ebr_size = dp[1].length; - iter->sub.dos.nebr_lba = iter->sub.dos.bebr_start + dp[1].start_lba; + iter->dos.ebr_start = dp[1].start_lba; + iter->dos.ebr_size = dp[1].length; + iter->dos.nebr_lba = iter->dos.bebr_start + dp[1].start_lba; } else { - iter->sub.dos.ebr_start = 0; - iter->sub.dos.ebr_size = 0; - iter->sub.dos.nebr_lba = 0; + iter->dos.ebr_start = 0; + iter->dos.ebr_size = 0; + iter->dos.nebr_lba = 0; } if (!dp[0].ostype) - iter->sub.dos.skipcnt++; + iter->dos.skipcnt++; if (dp[0].ostype || iter->stepall) { - *lba = iter->sub.dos.cebr_lba + dp[0].start_lba; + *lba = iter->dos.cebr_lba + dp[0].start_lba; *_dp = dp; return 0; } @@ -477,7 +477,7 @@ static struct part_iter *pi_dos_next(struct part_iter *iter) if (iter->index0 >= 4 && !dos_part->ostype) iter->index = -1; else - iter->index = iter->index0 - iter->sub.dos.skipcnt + 1; + iter->index = iter->index0 - iter->dos.skipcnt + 1; iter->rawindex = iter->index0 + 1; iter->start_lba = start_lba; iter->length = dos_part->length; @@ -498,14 +498,14 @@ static void gpt_conv_label(struct part_iter *iter) const int16_t *orig_lab; gp = (const struct disk_gpt_part_entry *) - (iter->data + iter->index0 * iter->sub.gpt.pe_size); + (iter->data + iter->index0 * iter->gpt.pe_size); orig_lab = (const int16_t *)gp->name; /* caveat: this is very crude conversion */ for (int i = 0; i < PI_GPTLABSIZE/2; i++) { - iter->sub.gpt.part_label[i] = (char)orig_lab[i]; + iter->gpt.part_label[i] = (char)orig_lab[i]; } - iter->sub.gpt.part_label[PI_GPTLABSIZE/2] = 0; + iter->gpt.part_label[PI_GPTLABSIZE/2] = 0; } static struct part_iter *pi_gpt_next(struct part_iter *iter) @@ -515,9 +515,9 @@ static struct part_iter *pi_gpt_next(struct part_iter *iter) if (iter->status) goto bail; - while (++iter->index0 < iter->sub.gpt.pe_count) { + while (++iter->index0 < iter->gpt.pe_count) { gpt_part = (const struct disk_gpt_part_entry *) - (iter->data + iter->index0 * iter->sub.gpt.pe_size); + (iter->data + iter->index0 * iter->gpt.pe_size); if (notsane_gpt(iter)) { iter->status = PI_INSANE; @@ -528,7 +528,7 @@ static struct part_iter *pi_gpt_next(struct part_iter *iter) break; } /* no more partitions ? */ - if (iter->index0 == iter->sub.gpt.pe_count) { + if (iter->index0 == iter->gpt.pe_count) { iter->status = PI_DONE; goto bail; } @@ -538,7 +538,7 @@ static struct part_iter *pi_gpt_next(struct part_iter *iter) iter->start_lba = gpt_part->lba_first; iter->length = gpt_part->lba_last - gpt_part->lba_first + 1; iter->record = (char *)gpt_part; - memcpy(&iter->sub.gpt.part_guid, &gpt_part->uid, sizeof(struct guid)); + memcpy(&iter->gpt.part_guid, &gpt_part->uid, sizeof(struct guid)); gpt_conv_label(iter); #ifdef DEBUG diff --git a/com32/chain/partiter.h b/com32/chain/partiter.h index 8b47822..4f5a23d 100644 --- a/com32/chain/partiter.h +++ b/com32/chain/partiter.h @@ -69,8 +69,8 @@ struct part_iter { int status; /* internal */ int index0; - union _sub { - struct _dos { + union { + struct { uint32_t disk_sig; uint32_t nebr_lba; uint32_t cebr_lba; @@ -82,7 +82,7 @@ struct part_iter { int bebr_index0; int skipcnt; } dos; - struct _gpt { + struct { struct guid disk_guid; struct guid part_guid; char part_label[PI_GPTLABSIZE/2+1]; @@ -91,7 +91,7 @@ struct part_iter { uint64_t ufirst; uint64_t ulast; } gpt; - } sub; + }; }; extern const struct itertype * const typedos; -- 1.7.10.4
Michal Soltys
2013-Jan-29 14:05 UTC
[syslinux] [PATCH 04/28] com32/chain: change stepall into flags
Signed-off-by: Michal Soltys <soltys at ziu.info> --- com32/chain/mangle.c | 4 ++-- com32/chain/partiter.c | 20 ++++++++++---------- com32/chain/partiter.h | 8 ++++++-- 3 files changed, 18 insertions(+), 14 deletions(-) diff --git a/com32/chain/mangle.c b/com32/chain/mangle.c index 8185a17..fbb5d57 100644 --- a/com32/chain/mangle.c +++ b/com32/chain/mangle.c @@ -540,7 +540,7 @@ int manglepe_hide(struct part_iter *miter) if (miter->index > 4 && !(opt.hide & 2)) error("WARNING: your partition is beyond mbr, so it can't be unhidden without '*hideall'.\n"); - if (!(iter = pi_begin(&miter->di, 1))) /* turn stepall on */ + if (!(iter = pi_begin(&miter->di, PIF_STEPALL))) return -1; while (!pi_next(&iter) && !werr) { @@ -610,7 +610,7 @@ int manglepe_fixchs(struct part_iter *miter) return -1; } - if (!(iter = pi_begin(&miter->di, 1))) /* turn stepall on */ + if (!(iter = pi_begin(&miter->di, PIF_STEPALL))) return -1; while (!pi_next(&iter) && !werr) { diff --git a/com32/chain/partiter.c b/com32/chain/partiter.c index 9352fcc..d8d6472 100644 --- a/com32/chain/partiter.c +++ b/com32/chain/partiter.c @@ -93,14 +93,14 @@ static int inv_type(const void *type) * iter_ctor() - common iterator initialization * @iter: iterator pointer * @args(0): disk_info structure used for disk functions - * @args(1): stepall modifier + * @args(1): flags modifier * * Second and further arguments are passed as a pointer to va_list **/ static int iter_ctor(struct part_iter *iter, va_list *args) { const struct disk_info *di = va_arg(*args, const struct disk_info *); - int stepall = va_arg(*args, int); + int flags = va_arg(*args, int); #ifdef DEBUG if (!di) @@ -108,7 +108,7 @@ static int iter_ctor(struct part_iter *iter, va_list *args) #endif memcpy(&iter->di, di, sizeof(struct disk_info)); - iter->stepall = stepall; + iter->flags = flags; iter->index0 = -1; iter->length = di->lbacnt; @@ -356,7 +356,7 @@ static int pi_dos_next_mbr(struct part_iter *iter, uint32_t *lba, /* record base EBR index */ iter->dos.bebr_index0 = iter->index0; } - if (!ost_is_nondata(dp->ostype) || iter->stepall) { + if (!ost_is_nondata(dp->ostype) || (iter->flags & PIF_STEPALL)) { *lba = dp->start_lba; *_dp = dp; break; @@ -433,7 +433,7 @@ static int pi_dos_next_ebr(struct part_iter *iter, uint32_t *lba, if (!dp[0].ostype) iter->dos.skipcnt++; - if (dp[0].ostype || iter->stepall) { + if (dp[0].ostype || (iter->flags & PIF_STEPALL)) { *lba = iter->dos.cebr_lba + dp[0].start_lba; *_dp = dp; return 0; @@ -524,7 +524,7 @@ static struct part_iter *pi_gpt_next(struct part_iter *iter) goto bail; } - if (!guid_is0(&gpt_part->type) || iter->stepall) + if (!guid_is0(&gpt_part->type) || (iter->flags & PIF_STEPALL)) break; } /* no more partitions ? */ @@ -701,7 +701,7 @@ void pi_del(struct part_iter **_iter) * This function checks the disk for GPT or legacy partition table and allocates * an appropriate iterator. **/ -struct part_iter *pi_begin(const struct disk_info *di, int stepall) +struct part_iter *pi_begin(const struct disk_info *di, int flags) { int setraw = 0; struct part_iter *iter = NULL; @@ -784,17 +784,17 @@ struct part_iter *pi_begin(const struct disk_info *di, int stepall) } } /* allocate iterator and exit */ - iter = pi_new(typegpt, di, stepall, gpth, gptl); + iter = pi_new(typegpt, di, flags, gpth, gptl); } else { /* looks like MBR */ - iter = pi_new(typedos, di, stepall, mbr); + iter = pi_new(typedos, di, flags, mbr); } setraw = 0; bail: if (setraw) { error("WARNING: treating disk as raw.\n"); - iter = pi_new(typeraw, di, stepall); + iter = pi_new(typeraw, di, flags); } free(mbr); free(gpth); diff --git a/com32/chain/partiter.h b/com32/chain/partiter.h index 4f5a23d..ac15de6 100644 --- a/com32/chain/partiter.h +++ b/com32/chain/partiter.h @@ -45,6 +45,10 @@ #define PI_DONE 1 #define PI_OK 0 +/* behaviour flags */ + +#define PIF_STEPALL 0x01 + struct itertype; struct part_iter; @@ -65,7 +69,7 @@ struct part_iter { int index; int rawindex; struct disk_info di; - int stepall; + int flags; int status; /* internal */ int index0; @@ -98,7 +102,7 @@ extern const struct itertype * const typedos; extern const struct itertype * const typegpt; extern const struct itertype * const typeraw; -struct part_iter *pi_begin(const struct disk_info *, int stepall); +struct part_iter *pi_begin(const struct disk_info *, int flags); struct part_iter *pi_new(const struct itertype *, ...); void pi_del(struct part_iter **); int pi_next(struct part_iter **); -- 1.7.10.4
Michal Soltys
2013-Jan-29 14:05 UTC
[syslinux] [PATCH 05/28] com32/chain: shuffle code before partiter simplifications
Signed-off-by: Michal Soltys <soltys at ziu.info> --- com32/chain/partiter.c | 124 ++++++++++++++++++++++++------------------------ 1 file changed, 62 insertions(+), 62 deletions(-) diff --git a/com32/chain/partiter.c b/com32/chain/partiter.c index d8d6472..8fdb359 100644 --- a/com32/chain/partiter.c +++ b/com32/chain/partiter.c @@ -450,6 +450,68 @@ static int pi_dos_next_ebr(struct part_iter *iter, uint32_t *lba, return -1; } +static void gpt_conv_label(struct part_iter *iter) +{ + const struct disk_gpt_part_entry *gp; + const int16_t *orig_lab; + + gp = (const struct disk_gpt_part_entry *) + (iter->data + iter->index0 * iter->gpt.pe_size); + orig_lab = (const int16_t *)gp->name; + + /* caveat: this is very crude conversion */ + for (int i = 0; i < PI_GPTLABSIZE/2; i++) { + iter->gpt.part_label[i] = (char)orig_lab[i]; + } + iter->gpt.part_label[PI_GPTLABSIZE/2] = 0; +} + +static int check_crc(uint32_t crc_match, const uint8_t *buf, unsigned int siz) +{ + uint32_t crc; + + crc = crc32(0, NULL, 0); + crc = crc32(crc, buf, siz); + + return crc_match != crc; +} + +static int gpt_check_hdr_crc(const struct disk_info * const diskinfo, struct disk_gpt_header **_gh) +{ + struct disk_gpt_header *gh = *_gh; + uint64_t lba_alt; + uint32_t hold_crc32; + + hold_crc32 = gh->chksum; + gh->chksum = 0; + if (check_crc(hold_crc32, (const uint8_t *)gh, gh->hdr_size)) { + error("WARNING: Primary GPT header checksum invalid.\n"); + /* retry with backup */ + lba_alt = gh->lba_alt; + free(gh); + if (!(gh = *_gh = disk_read_sectors(diskinfo, lba_alt, 1))) { + error("Couldn't read backup GPT header.\n"); + return -1; + } + hold_crc32 = gh->chksum; + gh->chksum = 0; + if (check_crc(hold_crc32, (const uint8_t *)gh, gh->hdr_size)) { + error("Secondary GPT header checksum invalid.\n"); + return -1; + } + } + /* restore old checksum */ + gh->chksum = hold_crc32; + + return 0; +} + +static struct part_iter *pi_raw_next(struct part_iter *iter) +{ + iter->status = PI_DONE; + return NULL; +} + static struct part_iter *pi_dos_next(struct part_iter *iter) { uint32_t start_lba = 0; @@ -492,22 +554,6 @@ bail: return NULL; } -static void gpt_conv_label(struct part_iter *iter) -{ - const struct disk_gpt_part_entry *gp; - const int16_t *orig_lab; - - gp = (const struct disk_gpt_part_entry *) - (iter->data + iter->index0 * iter->gpt.pe_size); - orig_lab = (const int16_t *)gp->name; - - /* caveat: this is very crude conversion */ - for (int i = 0; i < PI_GPTLABSIZE/2; i++) { - iter->gpt.part_label[i] = (char)orig_lab[i]; - } - iter->gpt.part_label[PI_GPTLABSIZE/2] = 0; -} - static struct part_iter *pi_gpt_next(struct part_iter *iter) { const struct disk_gpt_part_entry *gpt_part = NULL; @@ -550,52 +596,6 @@ bail: return NULL; } -static struct part_iter *pi_raw_next(struct part_iter *iter) -{ - iter->status = PI_DONE; - return NULL; -} - -static int check_crc(uint32_t crc_match, const uint8_t *buf, unsigned int siz) -{ - uint32_t crc; - - crc = crc32(0, NULL, 0); - crc = crc32(crc, buf, siz); - - return crc_match != crc; -} - -static int gpt_check_hdr_crc(const struct disk_info * const diskinfo, struct disk_gpt_header **_gh) -{ - struct disk_gpt_header *gh = *_gh; - uint64_t lba_alt; - uint32_t hold_crc32; - - hold_crc32 = gh->chksum; - gh->chksum = 0; - if (check_crc(hold_crc32, (const uint8_t *)gh, gh->hdr_size)) { - error("WARNING: Primary GPT header checksum invalid.\n"); - /* retry with backup */ - lba_alt = gh->lba_alt; - free(gh); - if (!(gh = *_gh = disk_read_sectors(diskinfo, lba_alt, 1))) { - error("Couldn't read backup GPT header.\n"); - return -1; - } - hold_crc32 = gh->chksum; - gh->chksum = 0; - if (check_crc(hold_crc32, (const uint8_t *)gh, gh->hdr_size)) { - error("Secondary GPT header checksum invalid.\n"); - return -1; - } - } - /* restore old checksum */ - gh->chksum = hold_crc32; - - return 0; -} - /* * ---------------------------------------------------------------------------- * Following functions are for users to call. -- 1.7.10.4
Michal Soltys
2013-Jan-29 14:05 UTC
[syslinux] [PATCH 06/28] com32/chain: partiter - simplifications and updates
The code uses more abstractions than it's really worth or necessary, so these patches simplify the code a bit. Partially suggested by Shao as well. Additionally, there're some added comments and more consistent naming used. Signed-off-by: Michal Soltys <soltys at ziu.info> --- com32/chain/chain.c | 8 +- com32/chain/mangle.c | 4 +- com32/chain/partiter.c | 350 +++++++++++++----------------------------------- com32/chain/partiter.h | 36 ++--- 4 files changed, 119 insertions(+), 279 deletions(-) diff --git a/com32/chain/chain.c b/com32/chain/chain.c index d76c669..bb24955 100644 --- a/com32/chain/chain.c +++ b/com32/chain/chain.c @@ -115,7 +115,7 @@ static int find_by_guid(const struct guid *gpt_guid, goto ok; } /* disk guid doesn't match, maybe partition guid will */ - while (!pi_next(&boot_part)) { + while (!pi_next(boot_part)) { if (!memcmp(&boot_part->gpt.part_guid, gpt_guid, sizeof(*gpt_guid))) goto ok; } @@ -147,7 +147,7 @@ static int find_by_label(const char *label, struct part_iter **_boot_part) continue; } /* Check for a matching partition */ - while (!pi_next(&boot_part)) { + while (!pi_next(boot_part)) { if (!strcmp(label, boot_part->gpt.part_label)) goto ok; } @@ -353,7 +353,7 @@ int find_dp(struct part_iter **_iter) /* 'fs' => we should lookup the syslinux partition number and use it */ if (!strcmp(opt.drivename, "fs")) { - while (!pi_next(&iter)) { + while (!pi_next(iter)) { if (iter->start_lba == fs_lba) break; } @@ -377,7 +377,7 @@ int find_dp(struct part_iter **_iter) do { if (iter->index == partition) break; - } while (!pi_next(&iter)); + } while (!pi_next(iter)); if (iter->status) { error("Requested disk / partition combination not found.\n"); goto bail; diff --git a/com32/chain/mangle.c b/com32/chain/mangle.c index fbb5d57..7fe77ee 100644 --- a/com32/chain/mangle.c +++ b/com32/chain/mangle.c @@ -543,7 +543,7 @@ int manglepe_hide(struct part_iter *miter) if (!(iter = pi_begin(&miter->di, PIF_STEPALL))) return -1; - while (!pi_next(&iter) && !werr) { + while (!pi_next(iter) && !werr) { ridx = iter->rawindex; if (!(opt.hide & 2) && ridx > 4) break; /* skip when we're constrained to pri only */ @@ -613,7 +613,7 @@ int manglepe_fixchs(struct part_iter *miter) if (!(iter = pi_begin(&miter->di, PIF_STEPALL))) return -1; - while (!pi_next(&iter) && !werr) { + while (!pi_next(iter) && !werr) { ridx = iter->rawindex; dp = (struct disk_dos_part_entry *)iter->record; diff --git a/com32/chain/partiter.c b/com32/chain/partiter.c index 8fdb359..23cbf90 100644 --- a/com32/chain/partiter.c +++ b/com32/chain/partiter.c @@ -48,108 +48,61 @@ #define ost_is_nondata(type) (ost_is_ext(type) || (type) == 0x00) #define sane(s,l) ((s)+(l) > (s)) -/* forwards */ +/* virtual forwards */ -static int iter_ctor(struct part_iter *, va_list *); -static int iter_dos_ctor(struct part_iter *, va_list *); -static int iter_gpt_ctor(struct part_iter *, va_list *); -static void iter_dtor(struct part_iter *); -static struct part_iter *pi_dos_next(struct part_iter *); -static struct part_iter *pi_gpt_next(struct part_iter *); -static struct part_iter *pi_raw_next(struct part_iter *); +static void pi_dtor_(struct part_iter *); +static int pi_next_(struct part_iter *); +static int pi_dos_next(struct part_iter *); +static int pi_gpt_next(struct part_iter *); + +/* vtab and types */ static struct itertype types[] = { [0] = { - .ctor = &iter_dos_ctor, - .dtor = &iter_dtor, + .dtor = &pi_dtor_, .next = &pi_dos_next, }, [1] = { - .ctor = &iter_gpt_ctor, - .dtor = &iter_dtor, + .dtor = &pi_dtor_, .next = &pi_gpt_next, }, [2] = { - .ctor = &iter_ctor, - .dtor = &iter_dtor, - .next = &pi_raw_next, + .dtor = &pi_dtor_, + .next = &pi_next_, }}; const struct itertype * const typedos = types; const struct itertype * const typegpt = types+1; const struct itertype * const typeraw = types+2; -#ifdef DEBUG -static int inv_type(const void *type) +/* pi_dtor_() - common/raw iterator cleanup */ +static void pi_dtor_(struct part_iter *iter) { - int i, cnt = sizeof(types)/sizeof(types[0]); - for (i = 0; i < cnt; i++) { - if (type == types + i) - return 0; - } - return -1; + /* syslinux's free is null resilient */ + free(iter->data); } -#endif -/** - * iter_ctor() - common iterator initialization - * @iter: iterator pointer - * @args(0): disk_info structure used for disk functions - * @args(1): flags modifier - * - * Second and further arguments are passed as a pointer to va_list - **/ -static int iter_ctor(struct part_iter *iter, va_list *args) +/* pi_ctor() - common/raw iterator initialization */ +static int pi_ctor(struct part_iter *iter, + const struct disk_info *di, int flags +) { - const struct disk_info *di = va_arg(*args, const struct disk_info *); - int flags = va_arg(*args, int); - -#ifdef DEBUG - if (!di) - return -1; -#endif - memcpy(&iter->di, di, sizeof(struct disk_info)); iter->flags = flags; iter->index0 = -1; iter->length = di->lbacnt; + iter->type = typeraw; return 0; } -/** - * iter_dtor() - common iterator cleanup - * @iter: iterator pointer - * - **/ -static void iter_dtor(struct part_iter *iter) +/* pi_dos_ctor() - MBR/EBR iterator specific initialization */ +static int pi_dos_ctor(struct part_iter *iter, + const struct disk_info *di, int flags, + const struct disk_dos_mbr *mbr +) { - free(iter->data); -} - -/** - * iter_dos_ctor() - MBR/EBR iterator specific initialization - * @iter: iterator pointer - * @args(0): disk_info structure used for disk functions - * @args(1): pointer to buffer with loaded valid MBR - * - * Second and further arguments are passed as a pointer to va_list. - * This function only makes rudimentary checks. If user uses - * pi_new(), he/she is responsible for doing proper sanity checks. - **/ -static int iter_dos_ctor(struct part_iter *iter, va_list *args) -{ - const struct disk_dos_mbr *mbr; - - /* uses args(0) */ - if (iter_ctor(iter, args)) + if (pi_ctor(iter, di, flags)) return -1; - mbr = va_arg(*args, const struct disk_dos_mbr *); - -#ifdef DEBUG - if (!mbr) - goto bail; -#endif - if (!(iter->data = malloc(sizeof(struct disk_dos_mbr)))) goto bail; @@ -158,50 +111,26 @@ static int iter_dos_ctor(struct part_iter *iter, va_list *args) iter->dos.bebr_index0 = -1; iter->dos.disk_sig = mbr->disk_sig; + iter->type = typedos; return 0; bail: - iter->type->dtor(iter); + pi_dtor_(iter); return -1; } -/** - * iter_gpt_ctor() - GPT iterator specific initialization - * @iter: iterator pointer - * @args(0): ptr to disk_info structure - * @args(1): ptr to buffer with GPT header - * @args(2): ptr to buffer with GPT partition list - * - * Second and further arguments are passed as a pointer to va_list. - * This function only makes rudimentary checks. If user uses - * pi_new(), he/she is responsible for doing proper sanity checks. - **/ -static int iter_gpt_ctor(struct part_iter *iter, va_list *args) +/* pi_gpt_ctor() - GPT iterator specific initialization */ +static int pi_gpt_ctor(struct part_iter *iter, + const struct disk_info *di, int flags, + const struct disk_gpt_header *gpth, const struct disk_gpt_part_entry *gptl +) { uint64_t siz; - const struct disk_gpt_header *gpth; - const struct disk_gpt_part_entry *gptl; - /* uses args(0) */ - if (iter_ctor(iter, args)) + if (pi_ctor(iter, di, flags)) return -1; - gpth = va_arg(*args, const struct disk_gpt_header *); - gptl = va_arg(*args, const struct disk_gpt_part_entry *); - -#ifdef DEBUG - if (!gpth || !gptl) - goto bail; -#endif - siz = (uint64_t)gpth->part_count * gpth->part_size; -#ifdef DEBUG - if (!siz || (siz + iter->di.bps - 1) / iter->di.bps > 255u || - gpth->part_size < sizeof(struct disk_gpt_part_entry)) { - goto bail; - } -#endif - if (!(iter->data = malloc((size_t)siz))) goto bail; @@ -214,9 +143,10 @@ static int iter_gpt_ctor(struct part_iter *iter, va_list *args) memcpy(&iter->gpt.disk_guid, &gpth->disk_guid, sizeof(struct guid)); + iter->type = typegpt; return 0; bail: - iter->type->dtor(iter); + pi_dtor_(iter); return -1; } @@ -309,7 +239,7 @@ static int notsane_primary(const struct part_iter *iter) !dp->length || !sane(dp->start_lba, dp->length) || dp->start_lba + dp->length > iter->di.lbacnt) { - error("Insane primary (MBR) partition.\n"); + error("Primary (MBR) with invalid offset and/or length.\n"); return -1; } @@ -327,14 +257,14 @@ static int notsane_gpt(const struct part_iter *iter) if (gp->lba_first < iter->gpt.ufirst || gp->lba_last > iter->gpt.ulast) { - error("Insane GPT partition.\n"); + error("LBA sectors of GPT partition are beyond the range allowed in GPT header.\n"); return -1; } return 0; } -static int pi_dos_next_mbr(struct part_iter *iter, uint32_t *lba, +static int dos_next_mbr(struct part_iter *iter, uint32_t *lba, struct disk_dos_part_entry **_dp) { struct disk_dos_part_entry *dp; @@ -344,14 +274,14 @@ static int pi_dos_next_mbr(struct part_iter *iter, uint32_t *lba, if (notsane_primary(iter)) { iter->status = PI_INSANE; - goto bail; + return -1; } if (ost_is_ext(dp->ostype)) { if (iter->dos.bebr_index0 >= 0) { error("You have more than 1 extended partition.\n"); iter->status = PI_INSANE; - goto bail; + return -1; } /* record base EBR index */ iter->dos.bebr_index0 = iter->index0; @@ -364,8 +294,6 @@ static int pi_dos_next_mbr(struct part_iter *iter, uint32_t *lba, } return 0; -bail: - return -1; } static int prep_base_ebr(struct part_iter *iter) @@ -391,12 +319,12 @@ static int prep_base_ebr(struct part_iter *iter) return 0; } -static int pi_dos_next_ebr(struct part_iter *iter, uint32_t *lba, +static int dos_next_ebr(struct part_iter *iter, uint32_t *lba, struct disk_dos_part_entry **_dp) { struct disk_dos_part_entry *dp; - if (prep_base_ebr(iter)) { + if (prep_base_ebr(iter) < 0) { iter->status = PI_DONE; return -1; } @@ -442,8 +370,8 @@ static int pi_dos_next_ebr(struct part_iter *iter, uint32_t *lba, * This way it's possible to continue, if some crazy soft left a "hole" * - EBR with a valid extended partition without a logical one. In * such case, linux will not reserve a number for such hole - so we - * don't increase index0. If stepall flag is set, we will never reach - * this place. + * don't increase index0. If PIF_STEPALL flag is set, we will never + * reach this place. */ } iter->status = PI_DONE; @@ -466,14 +394,9 @@ static void gpt_conv_label(struct part_iter *iter) iter->gpt.part_label[PI_GPTLABSIZE/2] = 0; } -static int check_crc(uint32_t crc_match, const uint8_t *buf, unsigned int siz) +static inline int valid_crc(uint32_t crc, const uint8_t *buf, unsigned int siz) { - uint32_t crc; - - crc = crc32(0, NULL, 0); - crc = crc32(crc, buf, siz); - - return crc_match != crc; + return crc == crc32(crc32(0, NULL, 0), buf, siz); } static int gpt_check_hdr_crc(const struct disk_info * const diskinfo, struct disk_gpt_header **_gh) @@ -484,7 +407,7 @@ static int gpt_check_hdr_crc(const struct disk_info * const diskinfo, struct dis hold_crc32 = gh->chksum; gh->chksum = 0; - if (check_crc(hold_crc32, (const uint8_t *)gh, gh->hdr_size)) { + if (!valid_crc(hold_crc32, (const uint8_t *)gh, gh->hdr_size)) { error("WARNING: Primary GPT header checksum invalid.\n"); /* retry with backup */ lba_alt = gh->lba_alt; @@ -495,7 +418,7 @@ static int gpt_check_hdr_crc(const struct disk_info * const diskinfo, struct dis } hold_crc32 = gh->chksum; gh->chksum = 0; - if (check_crc(hold_crc32, (const uint8_t *)gh, gh->hdr_size)) { + if (!valid_crc(hold_crc32, (const uint8_t *)gh, gh->hdr_size)) { error("Secondary GPT header checksum invalid.\n"); return -1; } @@ -506,34 +429,33 @@ static int gpt_check_hdr_crc(const struct disk_info * const diskinfo, struct dis return 0; } -static struct part_iter *pi_raw_next(struct part_iter *iter) +static int pi_next_(struct part_iter *iter) { iter->status = PI_DONE; - return NULL; + return iter->status; } -static struct part_iter *pi_dos_next(struct part_iter *iter) +static int pi_dos_next(struct part_iter *iter) { uint32_t start_lba = 0; struct disk_dos_part_entry *dos_part = NULL; if (iter->status) - goto bail; + return iter->status; /* look for primary partitions */ if (iter->index0 < 4 && - pi_dos_next_mbr(iter, &start_lba, &dos_part)) - goto bail; + dos_next_mbr(iter, &start_lba, &dos_part) < 0) + return iter->status; /* look for logical partitions */ if (iter->index0 >= 4 && - pi_dos_next_ebr(iter, &start_lba, &dos_part)) - goto bail; + dos_next_ebr(iter, &start_lba, &dos_part) < 0) + return iter->status; /* - * note special index handling, if we have stepall set - - * this is made to keep index consistent with non-stepall - * iterators + * note special index handling, if we have PIF_STEPALL set - this is made + * to keep index consistent with non-PIF_STEPALL iterators */ if (iter->index0 >= 4 && !dos_part->ostype) @@ -549,17 +471,15 @@ static struct part_iter *pi_dos_next(struct part_iter *iter) disk_dos_part_dump(dos_part); #endif - return iter; -bail: - return NULL; + return iter->status; } -static struct part_iter *pi_gpt_next(struct part_iter *iter) +static int pi_gpt_next(struct part_iter *iter) { const struct disk_gpt_part_entry *gpt_part = NULL; if (iter->status) - goto bail; + return iter->status; while (++iter->index0 < iter->gpt.pe_count) { gpt_part = (const struct disk_gpt_part_entry *) @@ -567,7 +487,7 @@ static struct part_iter *pi_gpt_next(struct part_iter *iter) if (notsane_gpt(iter)) { iter->status = PI_INSANE; - goto bail; + return iter->status; } if (!guid_is0(&gpt_part->type) || (iter->flags & PIF_STEPALL)) @@ -576,7 +496,7 @@ static struct part_iter *pi_gpt_next(struct part_iter *iter) /* no more partitions ? */ if (iter->index0 == iter->gpt.pe_count) { iter->status = PI_DONE; - goto bail; + return iter->status; } /* gpt_part is guaranteed to be valid here */ iter->index = iter->index0 + 1; @@ -591,135 +511,53 @@ static struct part_iter *pi_gpt_next(struct part_iter *iter) disk_gpt_part_dump(gpt_part); #endif - return iter; -bail: - return NULL; + return iter->status; } -/* - * ---------------------------------------------------------------------------- - * Following functions are for users to call. - * ---------------------------------------------------------------------------- - */ - - -int pi_next(struct part_iter **_iter) +static struct part_iter *pi_alloc(void) { struct part_iter *iter; - - if(!_iter || !*_iter) - return 0; - iter = *_iter; -#ifdef DEBUG - if (inv_type(iter->type)) { - error("This is not a valid iterator.\n"); - return 0; - } -#endif - if ((iter = iter->type->next(iter))) { - *_iter = iter; - } - return (*_iter)->status; -} - -/** - * pi_new() - get new iterator - * @itertype: iterator type - * @...: variable arguments passed to ctors - * - * Variable arguments depend on the type. Please see functions: - * iter_gpt_ctor() and iter_dos_ctor() for details. - **/ -struct part_iter *pi_new(const struct itertype *type, ...) -{ - int badctor = 0; - struct part_iter *iter = NULL; - va_list ap; - - va_start(ap, type); - -#ifdef DEBUG - if (inv_type(type)) { - error("Unknown iterator requested.\n"); - goto bail; - } -#endif - - if (!(iter = malloc(sizeof(struct part_iter)))) { + if (!(iter = malloc(sizeof(struct part_iter)))) error("Couldn't allocate memory for the iterator.\n"); - goto bail; - } - - memset(iter, 0, sizeof(struct part_iter)); - iter->type = type; - - if (type->ctor(iter, &ap)) { - badctor = -1; - error("Cannot initialize the iterator.\n"); - goto bail; - } - -bail: - va_end(ap); - if (badctor) { - free(iter); - iter = NULL; - } + else + memset(iter, 0, sizeof(struct part_iter)); return iter; } -/** - * pi_del() - delete iterator - * @iter: iterator double pointer - * - **/ - +/* pi_del() - delete iterator */ void pi_del(struct part_iter **_iter) { - struct part_iter *iter; - if(!_iter || !*_iter) return; - iter = *_iter; - -#ifdef DEBUG - if (inv_type(iter->type)) { - error("This is not a valid iterator.\n"); - return; - } -#endif - - iter->type->dtor(iter); - free(iter); + pi_dtor(*_iter); + free(*_iter); *_iter = NULL; } -/** - * pi_begin() - check disk, validate, and get proper iterator - * @di: diskinfo struct pointer - * - * This function checks the disk for GPT or legacy partition table and allocates - * an appropriate iterator. - **/ +/* pi_begin() - validate and and get proper iterator for a disk described by di */ struct part_iter *pi_begin(const struct disk_info *di, int flags) { - int setraw = 0; - struct part_iter *iter = NULL; + int ret = -1; + struct part_iter *iter; struct disk_dos_mbr *mbr = NULL; struct disk_gpt_header *gpth = NULL; struct disk_gpt_part_entry *gptl = NULL; + /* Preallocate iterator */ + if (!(iter = pi_alloc())) + goto bail; + /* Read MBR */ if (!(mbr = disk_read_sectors(di, 0, 1))) { error("Couldn't read first disk sector.\n"); goto bail; } - setraw = -1; - - /* Check for MBR magic*/ + /* Check for MBR magic */ if (mbr->sig != disk_mbr_sig_magic) { - error("No MBR magic.\n"); + error("WARNING: no MBR magic, treating disk as raw.\n"); + /* looks like RAW */ + ret = pi_ctor(iter, di, flags); goto bail; } @@ -770,32 +608,28 @@ struct part_iter *pi_begin(const struct disk_info *di, int flags) goto bail; } /* Check array checksum(s). */ - if (check_crc(gpth->table_chksum, (const uint8_t *)gptl, (unsigned int)gpt_lsiz)) { - error("WARNING: GPT partition list checksum invalid, trying backup.\n"); + if (!valid_crc(gpth->table_chksum, (const uint8_t *)gptl, (unsigned int)gpt_lsiz)) { + error("Main GPT partition list's checksum invalid, trying backup.\n"); free(gptl); /* secondary array directly precedes secondary header */ if (!(gptl = disk_read_sectors(di, gpth->lba_alt - gpt_lcnt, gpt_lcnt))) { error("Couldn't read backup GPT partition list.\n"); goto bail; } - if (check_crc(gpth->table_chksum, (const uint8_t *)gptl, gpt_lsiz)) { - error("Backup GPT partition list checksum invalid.\n"); + if (!valid_crc(gpth->table_chksum, (const uint8_t *)gptl, gpt_lsiz)) { + error("Backup GPT partition list's checksum invalid.\n"); goto bail; } } - /* allocate iterator and exit */ - iter = pi_new(typegpt, di, flags, gpth, gptl); + /* looks like GPT */ + ret = pi_gpt_ctor(iter, di, flags, gpth, gptl); } else { /* looks like MBR */ - iter = pi_new(typedos, di, flags, mbr); + ret = pi_dos_ctor(iter, di, flags, mbr); } - - setraw = 0; bail: - if (setraw) { - error("WARNING: treating disk as raw.\n"); - iter = pi_new(typeraw, di, flags); - } + if (ret < 0) + free(iter); free(mbr); free(gpth); free(gptl); diff --git a/com32/chain/partiter.h b/com32/chain/partiter.h index ac15de6..821d448 100644 --- a/com32/chain/partiter.h +++ b/com32/chain/partiter.h @@ -40,12 +40,11 @@ #include <stdint.h> #include <syslinux/disk.h> -#define PI_ERRLOAD 3 -#define PI_INSANE 2 -#define PI_DONE 1 -#define PI_OK 0 +/* status */ -/* behaviour flags */ +enum {PI_OK, PI_DONE, PI_INSANE, PI_ERRLOAD}; + +/* flags */ #define PIF_STEPALL 0x01 @@ -53,9 +52,8 @@ struct itertype; struct part_iter; struct itertype { - int (*ctor)(struct part_iter *, va_list *); void (*dtor)(struct part_iter *); - struct part_iter *(*next) (struct part_iter *); + int (*next)(struct part_iter *); }; #define PI_GPTLABSIZE ((int)sizeof(((struct disk_gpt_part_entry *)0)->name)) @@ -66,13 +64,12 @@ struct part_iter { char *record; uint64_t start_lba; uint64_t length; - int index; - int rawindex; + int index0; /* including holes, from -1 (disk, then parts from 0) */ + int rawindex; /* including holes, from 0 (disk, then parts from 1) */ + int index; /* excluding holes, from 0 (disk) (-1) means hole, if PIF_STEPALL is set */ + int flags; /* flags, see #defines above */ + int status; /* current status, see enums above */ struct disk_info di; - int flags; - int status; - /* internal */ - int index0; union { struct { uint32_t disk_sig; @@ -103,9 +100,18 @@ extern const struct itertype * const typegpt; extern const struct itertype * const typeraw; struct part_iter *pi_begin(const struct disk_info *, int flags); -struct part_iter *pi_new(const struct itertype *, ...); void pi_del(struct part_iter **); -int pi_next(struct part_iter **); + +/* inline virtuals */ +static inline int pi_next(struct part_iter *iter) +{ + return iter->type->next(iter); +} + +static inline void pi_dtor(struct part_iter *iter) +{ + iter->type->dtor(iter); +} #endif -- 1.7.10.4
Michal Soltys
2013-Jan-29 14:05 UTC
[syslinux] [PATCH 07/28] com32/chain: remove redundant rawindex
'index0' provides the same "raw" info, complementing standard 'index'. Signed-off-by: Michal Soltys <soltys at ziu.info> --- com32/chain/mangle.c | 4 ++-- com32/chain/partiter.c | 2 -- com32/chain/partiter.h | 5 ++--- 3 files changed, 4 insertions(+), 7 deletions(-) diff --git a/com32/chain/mangle.c b/com32/chain/mangle.c index 7fe77ee..136f3bc 100644 --- a/com32/chain/mangle.c +++ b/com32/chain/mangle.c @@ -544,7 +544,7 @@ int manglepe_hide(struct part_iter *miter) return -1; while (!pi_next(iter) && !werr) { - ridx = iter->rawindex; + ridx = iter->index0 + 1; if (!(opt.hide & 2) && ridx > 4) break; /* skip when we're constrained to pri only */ @@ -614,7 +614,7 @@ int manglepe_fixchs(struct part_iter *miter) return -1; while (!pi_next(iter) && !werr) { - ridx = iter->rawindex; + ridx = iter->index0 + 1; dp = (struct disk_dos_part_entry *)iter->record; wb |= mpe_setchs(&iter->di, dp, iter->start_lba); diff --git a/com32/chain/partiter.c b/com32/chain/partiter.c index 23cbf90..25810eb 100644 --- a/com32/chain/partiter.c +++ b/com32/chain/partiter.c @@ -462,7 +462,6 @@ static int pi_dos_next(struct part_iter *iter) iter->index = -1; else iter->index = iter->index0 - iter->dos.skipcnt + 1; - iter->rawindex = iter->index0 + 1; iter->start_lba = start_lba; iter->length = dos_part->length; iter->record = (char *)dos_part; @@ -500,7 +499,6 @@ static int pi_gpt_next(struct part_iter *iter) } /* gpt_part is guaranteed to be valid here */ iter->index = iter->index0 + 1; - iter->rawindex = iter->index0 + 1; iter->start_lba = gpt_part->lba_first; iter->length = gpt_part->lba_last - gpt_part->lba_first + 1; iter->record = (char *)gpt_part; diff --git a/com32/chain/partiter.h b/com32/chain/partiter.h index 821d448..10f1882 100644 --- a/com32/chain/partiter.h +++ b/com32/chain/partiter.h @@ -65,9 +65,8 @@ struct part_iter { uint64_t start_lba; uint64_t length; int index0; /* including holes, from -1 (disk, then parts from 0) */ - int rawindex; /* including holes, from 0 (disk, then parts from 1) */ - int index; /* excluding holes, from 0 (disk) (-1) means hole, if PIF_STEPALL is set */ - int flags; /* flags, see #defines above */ + int index; /* excluding holes, from 0 (disk, then parts from 1), -1 means hole, if PIF_STEPALL is set */ + int flags; /* flags, see #defines above */ int status; /* current status, see enums above */ struct disk_info di; union { -- 1.7.10.4
Michal Soltys
2013-Jan-29 14:05 UTC
[syslinux] [PATCH 08/28] com32/chain: partiter - more precise comments / output
Signed-off-by: Michal Soltys <soltys at ziu.info> --- com32/chain/partiter.c | 19 ++++++++++--------- com32/chain/partiter.h | 23 +++++++++++++---------- 2 files changed, 23 insertions(+), 19 deletions(-) diff --git a/com32/chain/partiter.c b/com32/chain/partiter.c index 25810eb..2f6197a 100644 --- a/com32/chain/partiter.c +++ b/com32/chain/partiter.c @@ -179,7 +179,7 @@ static int notsane_logical(const struct part_iter *iter) !sane(dp[0].start_lba, dp[0].length) || end_log > iter->dos.ebr_size) { - error("Insane logical partition.\n"); + error("Logical partition (in EBR) with invalid offset and/or length.\n"); return -1; } @@ -204,7 +204,7 @@ static int notsane_extended(const struct part_iter *iter) return 0; if (!ost_is_nondata(dp[1].ostype)) { - error("2nd EBR entry must be extended or empty.\n"); + error("The 2nd EBR entry must be extended or empty.\n"); return -1; } @@ -215,7 +215,7 @@ static int notsane_extended(const struct part_iter *iter) !sane(dp[1].start_lba, dp[1].length) || end_ebr > iter->dos.bebr_size) { - error("Insane extended partition.\n"); + error("Extended partition (EBR) with invalid offset and/or length.\n"); return -1; } @@ -239,7 +239,7 @@ static int notsane_primary(const struct part_iter *iter) !dp->length || !sane(dp->start_lba, dp->length) || dp->start_lba + dp->length > iter->di.lbacnt) { - error("Primary (MBR) with invalid offset and/or length.\n"); + error("Primary partition (in MBR) with invalid offset and/or length.\n"); return -1; } @@ -279,7 +279,7 @@ static int dos_next_mbr(struct part_iter *iter, uint32_t *lba, if (ost_is_ext(dp->ostype)) { if (iter->dos.bebr_index0 >= 0) { - error("You have more than 1 extended partition.\n"); + error("More than 1 extended partition.\n"); iter->status = PI_INSANE; return -1; } @@ -454,8 +454,9 @@ static int pi_dos_next(struct part_iter *iter) return iter->status; /* - * note special index handling, if we have PIF_STEPALL set - this is made - * to keep index consistent with non-PIF_STEPALL iterators + * note special index handling: + * in case PIF_STEPALL is set - this makes the index consistent with + * non-PIF_STEPALL iterators */ if (iter->index0 >= 4 && !dos_part->ostype) @@ -607,7 +608,7 @@ struct part_iter *pi_begin(const struct disk_info *di, int flags) } /* Check array checksum(s). */ if (!valid_crc(gpth->table_chksum, (const uint8_t *)gptl, (unsigned int)gpt_lsiz)) { - error("Main GPT partition list's checksum invalid, trying backup.\n"); + error("Checksum of the main GPT partition list is invalid, trying backup.\n"); free(gptl); /* secondary array directly precedes secondary header */ if (!(gptl = disk_read_sectors(di, gpth->lba_alt - gpt_lcnt, gpt_lcnt))) { @@ -615,7 +616,7 @@ struct part_iter *pi_begin(const struct disk_info *di, int flags) goto bail; } if (!valid_crc(gpth->table_chksum, (const uint8_t *)gptl, gpt_lsiz)) { - error("Backup GPT partition list's checksum invalid.\n"); + error("Checksum of the backup GPT partition list is invalid, giving up.\n"); goto bail; } } diff --git a/com32/chain/partiter.h b/com32/chain/partiter.h index 10f1882..18c3315 100644 --- a/com32/chain/partiter.h +++ b/com32/chain/partiter.h @@ -71,16 +71,19 @@ struct part_iter { struct disk_info di; union { struct { - uint32_t disk_sig; - uint32_t nebr_lba; - uint32_t cebr_lba; - /* internal */ - uint32_t ebr_start; - uint32_t ebr_size; - uint32_t bebr_start; - uint32_t bebr_size; - int bebr_index0; - int skipcnt; + uint32_t disk_sig; /* 32bit disk signature as stored in MBR */ + + uint32_t bebr_start; /* abs lba of base extended partition */ + uint32_t bebr_size; /* size of base extended partition */ + + uint32_t cebr_lba; /* absolute lba of curr ext. partition */ + uint32_t nebr_lba; /* absolute lba of next ext. partition */ + + uint32_t ebr_start; /* relative (to bebr) lba of next extended partition */ + uint32_t ebr_size; /* size of next extended partition */ + + int bebr_index0; /* index of (0-3) of base ext. part., -1 if not present in MBR */ + int skipcnt; /* how many logical holes were skipped */ } dos; struct { struct guid disk_guid; -- 1.7.10.4
Michal Soltys
2013-Jan-29 14:05 UTC
[syslinux] [PATCH 09/28] com32/chain: remove unused ebr_start
Signed-off-by: Michal Soltys <soltys at ziu.info> --- com32/chain/partiter.c | 3 --- com32/chain/partiter.h | 1 - 2 files changed, 4 deletions(-) diff --git a/com32/chain/partiter.c b/com32/chain/partiter.c index 2f6197a..2a14ef7 100644 --- a/com32/chain/partiter.c +++ b/com32/chain/partiter.c @@ -308,7 +308,6 @@ static int prep_base_ebr(struct part_iter *iter) iter->dos.bebr_start = dp->start_lba; iter->dos.bebr_size = dp->length; - iter->dos.ebr_start = 0; iter->dos.ebr_size = iter->dos.bebr_size; iter->dos.cebr_lba = 0; @@ -349,11 +348,9 @@ static int dos_next_ebr(struct part_iter *iter, uint32_t *lba, /* setup next frame values */ if (dp[1].ostype) { - iter->dos.ebr_start = dp[1].start_lba; iter->dos.ebr_size = dp[1].length; iter->dos.nebr_lba = iter->dos.bebr_start + dp[1].start_lba; } else { - iter->dos.ebr_start = 0; iter->dos.ebr_size = 0; iter->dos.nebr_lba = 0; } diff --git a/com32/chain/partiter.h b/com32/chain/partiter.h index 18c3315..cf52833 100644 --- a/com32/chain/partiter.h +++ b/com32/chain/partiter.h @@ -79,7 +79,6 @@ struct part_iter { uint32_t cebr_lba; /* absolute lba of curr ext. partition */ uint32_t nebr_lba; /* absolute lba of next ext. partition */ - uint32_t ebr_start; /* relative (to bebr) lba of next extended partition */ uint32_t ebr_size; /* size of next extended partition */ int bebr_index0; /* index of (0-3) of base ext. part., -1 if not present in MBR */ -- 1.7.10.4
Michal Soltys
2013-Jan-29 14:05 UTC
[syslinux] [PATCH 10/28] com32/chain: add pi_errored() in partiter
Signed-off-by: Michal Soltys <soltys at ziu.info> --- com32/chain/mangle.c | 4 ++-- com32/chain/partiter.h | 5 +++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/com32/chain/mangle.c b/com32/chain/mangle.c index 136f3bc..0523db5 100644 --- a/com32/chain/mangle.c +++ b/com32/chain/mangle.c @@ -559,7 +559,7 @@ int manglepe_hide(struct part_iter *miter) } } - if (iter->status > PI_DONE) + if (pi_errored(iter)) goto bail; /* last write */ @@ -628,7 +628,7 @@ int manglepe_fixchs(struct part_iter *miter) } } - if (iter->status > PI_DONE) + if (pi_errored(iter)) goto bail; /* last write */ diff --git a/com32/chain/partiter.h b/com32/chain/partiter.h index cf52833..813b9e6 100644 --- a/com32/chain/partiter.h +++ b/com32/chain/partiter.h @@ -103,6 +103,11 @@ extern const struct itertype * const typeraw; struct part_iter *pi_begin(const struct disk_info *, int flags); void pi_del(struct part_iter **); +static inline int pi_errored(struct part_iter *iter) +{ + return iter->status > PI_DONE; +} + /* inline virtuals */ static inline int pi_next(struct part_iter *iter) { -- 1.7.10.4
Michal Soltys
2013-Jan-29 14:05 UTC
[syslinux] [PATCH 11/28] com32/chain: mangle and related updates
Comments, output and minor adjustments. Signed-off-by: Michal Soltys <soltys at ziu.info> --- com32/chain/mangle.c | 69 ++++++++++++++++++++++++++----------------------- com32/chain/options.c | 10 +++---- com32/chain/options.h | 2 ++ com32/chain/utility.c | 9 +++---- com32/chain/utility.h | 2 +- 5 files changed, 49 insertions(+), 43 deletions(-) diff --git a/com32/chain/mangle.c b/com32/chain/mangle.c index 0523db5..a699f3c 100644 --- a/com32/chain/mangle.c +++ b/com32/chain/mangle.c @@ -276,8 +276,8 @@ bail: /* Adjust BPB common function */ static int mangle_bpb(const struct part_iter *iter, struct data_area *data, const char *tag) { - unsigned int off; int type = bpb_detect(data->data, tag); + int off = drvoff_detect(type); /* BPB: hidden sectors 32bit*/ if (type >= bpbV34) { @@ -307,7 +307,7 @@ static int mangle_bpb(const struct part_iter *iter, struct data_area *data, cons } } /* BPB: drive */ - if (drvoff_detect(type, &off)) { + if (off >= 0) { *(uint8_t *)((char *)data->data + off) = (opt.swap ? iter->di.disk & 0x80 : iter->di.disk); } @@ -343,7 +343,7 @@ int mangles_bpb(const struct part_iter *iter, struct data_area *data) int manglesf_bss(struct data_area *sec, struct data_area *fil) { int type1, type2; - unsigned int cnt = 0; + size_t cnt = 0; if (!(opt.sect && opt.file && opt.bss)) return 0; @@ -479,7 +479,7 @@ int mangler_grldr(const struct part_iter *iter) /* * try to copy values from temporary iterator, if positions match */ -static void push_embr(struct part_iter *diter, struct part_iter *siter) +static void mbrcpy(struct part_iter *diter, struct part_iter *siter) { if (diter->dos.cebr_lba == siter->dos.cebr_lba && diter->di.disk == siter->di.disk) { @@ -487,7 +487,7 @@ static void push_embr(struct part_iter *diter, struct part_iter *siter) } } -static int mpe_sethide(struct part_iter *iter, struct part_iter *miter) +static int fliphide(struct part_iter *iter, struct part_iter *miter) { struct disk_dos_part_entry *dp; static const uint16_t mask @@ -500,7 +500,7 @@ static int mpe_sethide(struct part_iter *iter, struct part_iter *miter) if ((t <= 0x1f) && ((mask >> (t & ~0x10u)) & 1)) { /* It's a hideable partition type */ - if (miter->index == iter->index || opt.hide & 4) + if (miter->index == iter->index || opt.hide & HIDE_REV) t &= ~0x10u; /* unhide */ else t |= 0x10u; /* hide */ @@ -526,34 +526,35 @@ int manglepe_hide(struct part_iter *miter) struct disk_dos_part_entry *dp; int ridx; - if (!opt.hide) + if (!(opt.hide & HIDE_ON)) return 0; if (miter->type != typedos) { - error("Options '*hide*' is meaningful only for legacy partition scheme.\n"); + error("Option '[un]hide[all]' is meaningful only for legacy (DOS) partition scheme.\n"); return -1; } - if (miter->index < 1) - error("WARNING: It's impossible to unhide a disk.\n"); - - if (miter->index > 4 && !(opt.hide & 2)) - error("WARNING: your partition is beyond mbr, so it can't be unhidden without '*hideall'.\n"); + if (miter->index > 4 && !(opt.hide & HIDE_EXT)) + error("WARNING: your partition is logical, so it can't be unhidden without 'unhideall'.\n"); if (!(iter = pi_begin(&miter->di, PIF_STEPALL))) return -1; while (!pi_next(iter) && !werr) { - ridx = iter->index0 + 1; - if (!(opt.hide & 2) && ridx > 4) + ridx = iter->index0; + if (!(opt.hide & HIDE_EXT) && ridx > 3) break; /* skip when we're constrained to pri only */ dp = (struct disk_dos_part_entry *)iter->record; if (dp->ostype) - wb |= mpe_sethide(iter, miter); - - if (ridx >= 4 && wb && !werr) { - push_embr(miter, iter); + wb |= fliphide(iter, miter); + + /* + * we have to update mbr and each extended partition, but only if + * changes (wb) were detected and there was no prior write error (werr) + */ + if (ridx >= 3 && wb && !werr) { + mbrcpy(miter, iter); werr |= disk_write_sectors(&iter->di, iter->dos.cebr_lba, iter->data, 1); wb = 0; } @@ -562,20 +563,20 @@ int manglepe_hide(struct part_iter *miter) if (pi_errored(iter)) goto bail; - /* last write */ + /* last update */ if (wb && !werr) { - push_embr(miter, iter); + mbrcpy(miter, iter); werr |= disk_write_sectors(&iter->di, iter->dos.cebr_lba, iter->data, 1); } if (werr) - error("WARNING: failed to write E/MBR during '*hide*'\n"); + error("WARNING: failed to write E/MBR during '[un]hide[all]'\n"); bail: pi_del(&iter); return 0; } -static int mpe_setchs(const struct disk_info *di, +static int updchs(const struct disk_info *di, struct disk_dos_part_entry *dp, uint32_t lba1) { @@ -606,7 +607,7 @@ int manglepe_fixchs(struct part_iter *miter) return 0; if (miter->type != typedos) { - error("Options 'fixchs' is meaningful only for legacy partition scheme.\n"); + error("Option 'fixchs' is meaningful only for legacy (DOS) partition scheme.\n"); return -1; } @@ -614,15 +615,19 @@ int manglepe_fixchs(struct part_iter *miter) return -1; while (!pi_next(iter) && !werr) { - ridx = iter->index0 + 1; + ridx = iter->index0; dp = (struct disk_dos_part_entry *)iter->record; - wb |= mpe_setchs(&iter->di, dp, iter->start_lba); - if (ridx > 4) - wb |= mpe_setchs(&iter->di, dp + 1, iter->dos.nebr_lba); + wb |= updchs(&iter->di, dp, iter->start_lba); + if (ridx > 3) + wb |= updchs(&iter->di, dp + 1, iter->dos.nebr_lba); - if (ridx >= 4 && wb && !werr) { - push_embr(miter, iter); + /* + * we have to update mbr and each extended partition, but only if + * changes (wb) were detected and there was no prior write error (werr) + */ + if (ridx >= 3 && wb && !werr) { + mbrcpy(miter, iter); werr |= disk_write_sectors(&iter->di, iter->dos.cebr_lba, iter->data, 1); wb = 0; } @@ -631,9 +636,9 @@ int manglepe_fixchs(struct part_iter *miter) if (pi_errored(iter)) goto bail; - /* last write */ + /* last update */ if (wb && !werr) { - push_embr(miter, iter); + mbrcpy(miter, iter); werr |= disk_write_sectors(&iter->di, iter->dos.cebr_lba, iter->data, 1); } if (werr) diff --git a/com32/chain/options.c b/com32/chain/options.c index b831afa..46a26df 100644 --- a/com32/chain/options.c +++ b/com32/chain/options.c @@ -284,15 +284,15 @@ int opt_parse_args(int argc, char *argv[]) } else if (!strcmp(argv[i], "noswap")) { opt.swap = false; } else if (!strcmp(argv[i], "nohide")) { - opt.hide = 0; + opt.hide = HIDE_OFF; } else if (!strcmp(argv[i], "hide")) { - opt.hide = 1; /* 001b */ + opt.hide = HIDE_ON; } else if (!strcmp(argv[i], "hideall")) { - opt.hide = 2; /* 010b */ + opt.hide = HIDE_ON | HIDE_EXT; } else if (!strcmp(argv[i], "unhide")) { - opt.hide = 5; /* 101b */ + opt.hide = HIDE_ON | HIDE_REV; } else if (!strcmp(argv[i], "unhideall")) { - opt.hide = 6; /* 110b */ + opt.hide = HIDE_ON | HIDE_EXT | HIDE_REV; } else if (!strcmp(argv[i], "setbpb")) { opt.setbpb = true; } else if (!strcmp(argv[i], "nosetbpb")) { diff --git a/com32/chain/options.h b/com32/chain/options.h index c3e1af6..ea6e470 100644 --- a/com32/chain/options.h +++ b/com32/chain/options.h @@ -34,6 +34,8 @@ #include <stdint.h> #include <syslinux/bootrm.h> +enum {HIDE_OFF = 0, HIDE_ON = 1, HIDE_EXT = 2, HIDE_REV = 4}; + struct options { unsigned int fseg; unsigned int foff; diff --git a/com32/chain/utility.c b/com32/chain/utility.c index 172707e..30eec6d 100644 --- a/com32/chain/utility.c +++ b/com32/chain/utility.c @@ -176,14 +176,13 @@ uint32_t get_file_lba(const char *filename) } /* drive offset detection */ -int drvoff_detect(int type, unsigned int *off) +int drvoff_detect(int type) { if (bpbV40 <= type && type <= bpbVNT) { - *off = 0x24; + return 0x24; } else if (type == bpbV70) { - *off = 0x40; - } else - return 0; + return 0x40; + } return -1; } diff --git a/com32/chain/utility.h b/com32/chain/utility.h index 769c4d1..cc2c93a 100644 --- a/com32/chain/utility.h +++ b/com32/chain/utility.h @@ -50,7 +50,7 @@ enum {L2C_CNUL, L2C_CADD, L2C_CMAX}; void wait_key(void); void lba2chs(disk_chs *dst, const struct disk_info *di, uint64_t lba, int mode); uint32_t get_file_lba(const char *filename); -int drvoff_detect(int type, unsigned int *off); +int drvoff_detect(int type); int bpb_detect(const uint8_t *bpb, const char *tag); int guid_is0(const struct guid *guid); -- 1.7.10.4
Michal Soltys
2013-Jan-29 14:05 UTC
[syslinux] [PATCH 12/28] com32/chain: cleaner variable names
Signed-off-by: Michal Soltys <soltys at ziu.info> --- com32/chain/partiter.c | 23 +++++++++++------------ com32/chain/partiter.h | 7 +++---- 2 files changed, 14 insertions(+), 16 deletions(-) diff --git a/com32/chain/partiter.c b/com32/chain/partiter.c index 2a14ef7..c928f35 100644 --- a/com32/chain/partiter.c +++ b/com32/chain/partiter.c @@ -177,7 +177,7 @@ static int notsane_logical(const struct part_iter *iter) if (!dp[0].start_lba || !dp[0].length || !sane(dp[0].start_lba, dp[0].length) || - end_log > iter->dos.ebr_size) { + end_log > iter->dos.nebr_siz) { error("Logical partition (in EBR) with invalid offset and/or length.\n"); return -1; @@ -213,7 +213,7 @@ static int notsane_extended(const struct part_iter *iter) if (!dp[1].start_lba || !dp[1].length || !sane(dp[1].start_lba, dp[1].length) || - end_ebr > iter->dos.bebr_size) { + end_ebr > iter->dos.bebr_siz) { error("Extended partition (EBR) with invalid offset and/or length.\n"); return -1; @@ -302,16 +302,14 @@ static int prep_base_ebr(struct part_iter *iter) if (iter->dos.bebr_index0 < 0) /* if we don't have base extended partition at all */ return -1; - else if (!iter->dos.bebr_start) { /* if not initialized yet */ + else if (!iter->dos.bebr_lba) { /* if not initialized yet */ dp = ((struct disk_dos_mbr *)iter->data)->table + iter->dos.bebr_index0; - iter->dos.bebr_start = dp->start_lba; - iter->dos.bebr_size = dp->length; + iter->dos.bebr_lba = dp->start_lba; + iter->dos.bebr_siz = dp->length; - iter->dos.ebr_size = iter->dos.bebr_size; - - iter->dos.cebr_lba = 0; - iter->dos.nebr_lba = iter->dos.bebr_start; + iter->dos.nebr_lba = dp->start_lba; + iter->dos.nebr_siz = dp->length; iter->index0--; } @@ -337,6 +335,7 @@ static int dos_next_ebr(struct part_iter *iter, uint32_t *lba, return -1; } + /* check sanity of loaded data */ if (notsane_logical(iter) || notsane_extended(iter)) { iter->status = PI_INSANE; return -1; @@ -348,11 +347,11 @@ static int dos_next_ebr(struct part_iter *iter, uint32_t *lba, /* setup next frame values */ if (dp[1].ostype) { - iter->dos.ebr_size = dp[1].length; - iter->dos.nebr_lba = iter->dos.bebr_start + dp[1].start_lba; + iter->dos.nebr_lba = iter->dos.bebr_lba + dp[1].start_lba; + iter->dos.nebr_siz = dp[1].length; } else { - iter->dos.ebr_size = 0; iter->dos.nebr_lba = 0; + iter->dos.nebr_siz = 0; } if (!dp[0].ostype) diff --git a/com32/chain/partiter.h b/com32/chain/partiter.h index 813b9e6..63dc6da 100644 --- a/com32/chain/partiter.h +++ b/com32/chain/partiter.h @@ -73,13 +73,12 @@ struct part_iter { struct { uint32_t disk_sig; /* 32bit disk signature as stored in MBR */ - uint32_t bebr_start; /* abs lba of base extended partition */ - uint32_t bebr_size; /* size of base extended partition */ + uint32_t bebr_lba; /* absolute lba of base extended partition */ + uint32_t bebr_siz; /* size of base extended partition */ uint32_t cebr_lba; /* absolute lba of curr ext. partition */ uint32_t nebr_lba; /* absolute lba of next ext. partition */ - - uint32_t ebr_size; /* size of next extended partition */ + uint32_t nebr_siz; /* size of next ext. partition */ int bebr_index0; /* index of (0-3) of base ext. part., -1 if not present in MBR */ int skipcnt; /* how many logical holes were skipped */ -- 1.7.10.4
Michal Soltys
2013-Jan-29 14:06 UTC
[syslinux] [PATCH 13/28] com32/chain: use disk_guid for part_guid for 0th partition
Initial position of each itarator is whole disk, so this actually matches. Signed-off-by: Michal Soltys <soltys at ziu.info> --- com32/chain/chain.c | 10 +++------- com32/chain/partiter.c | 1 + 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/com32/chain/chain.c b/com32/chain/chain.c index bb24955..85ec723 100644 --- a/com32/chain/chain.c +++ b/com32/chain/chain.c @@ -110,15 +110,11 @@ static int find_by_guid(const struct guid *gpt_guid, pi_del(&boot_part); continue; } - /* Check for a matching GPT disk guid */ - if (!memcmp(&boot_part->gpt.disk_guid, gpt_guid, sizeof(*gpt_guid))) { - goto ok; - } - /* disk guid doesn't match, maybe partition guid will */ - while (!pi_next(boot_part)) { + /* Check for a matching GPT disk/partition guid */ + do { if (!memcmp(&boot_part->gpt.part_guid, gpt_guid, sizeof(*gpt_guid))) goto ok; - } + } while (!pi_next(boot_part)); } drive = -1; ok: diff --git a/com32/chain/partiter.c b/com32/chain/partiter.c index c928f35..7f98ecb 100644 --- a/com32/chain/partiter.c +++ b/com32/chain/partiter.c @@ -142,6 +142,7 @@ static int pi_gpt_ctor(struct part_iter *iter, iter->gpt.ulast = gpth->lba_last_usable; memcpy(&iter->gpt.disk_guid, &gpth->disk_guid, sizeof(struct guid)); + memcpy(&iter->gpt.part_guid, &gpth->disk_guid, sizeof(struct guid)); iter->type = typegpt; return 0; -- 1.7.10.4
Michal Soltys
2013-Jan-29 14:06 UTC
[syslinux] [PATCH 14/28] com32/chain: warning/error/help/doc tidying
Trivial change that tidies a bit warning / error reporting through fatal()/error()/warn(). Also small doc/help updates. Signed-off-by: Michal Soltys <soltys at ziu.info> --- com32/chain/chain.c | 60 ++++++++++----------- com32/chain/mangle.c | 30 +++++------ com32/chain/options.c | 137 +++++++++++++++++++++++++----------------------- com32/chain/partiter.c | 50 ++++++++++-------- com32/chain/utility.h | 17 ++++-- doc/chain.txt | 21 ++++---- 6 files changed, 166 insertions(+), 149 deletions(-) diff --git a/com32/chain/chain.c b/com32/chain/chain.c index 85ec723..ccfeefa 100644 --- a/com32/chain/chain.c +++ b/com32/chain/chain.c @@ -168,7 +168,7 @@ static void do_boot(struct data_area *data, int ndata) mmap = syslinux_memory_map(); if (!mmap) { - error("Cannot read system memory map\n"); + error("Cannot read system memory map."); return; } @@ -269,17 +269,17 @@ static void do_boot(struct data_area *data, int ndata) /* Force text mode */ syslinux_force_text_mode(); - fputs("Booting...\n", stdout); + puts("Booting..."); syslinux_shuffle_boot_rm(mlist, mmap, opt.keeppxe, &opt.regs); - error("Chainboot failed!\n"); + error("Chainboot failed !"); return; too_big: - error("Loader file too large\n"); + error("Loader file too large."); return; enomem: - error("Out of memory\n"); + error("Out of memory."); return; } @@ -296,23 +296,23 @@ int find_dp(struct part_iter **_iter) if (!strncmp(opt.drivename, "mbr", 3)) { if (find_by_sig(strtoul(opt.drivename + 4, NULL, 0), &iter) < 0) { - error("Unable to find requested MBR signature.\n"); + error("Unable to find requested MBR signature."); goto bail; } } else if (!strncmp(opt.drivename, "guid", 4)) { if (str_to_guid(opt.drivename + 5, &gpt_guid)) goto bail; if (find_by_guid(&gpt_guid, &iter) < 0) { - error("Unable to find requested GPT disk or partition by guid.\n"); + error("Unable to find requested GPT disk or partition by guid."); goto bail; } } else if (!strncmp(opt.drivename, "label", 5)) { if (!opt.drivename[6]) { - error("No label specified.\n"); + error("No label specified."); goto bail; } if (find_by_label(opt.drivename + 6, &iter) < 0) { - error("Unable to find requested GPT partition by label.\n"); + error("Unable to find requested GPT partition by label."); goto bail; } } else if ((opt.drivename[0] == 'h' || opt.drivename[0] == 'f') && @@ -330,7 +330,7 @@ int find_dp(struct part_iter **_iter) } else if (!strcmp(opt.drivename, "boot") || !strcmp(opt.drivename, "fs")) { if (!is_phys(sdi->c.filesystem)) { error("When syslinux is not booted from physical disk (or its emulation),\n" - "'boot' and 'fs' are meaningless.\n"); + "'boot' and 'fs' are meaningless."); goto bail; } /* offsets match, but in case it changes in the future */ @@ -355,12 +355,12 @@ int find_dp(struct part_iter **_iter) } /* broken part structure or other problems */ if (iter->status) { - error("Can't find myself on the drive I booted from.\n"); + error("Can't find myself on the drive I booted from."); goto bail; } } } else { - error("Unparsable drive specification.\n"); + error("Unparsable drive specification."); goto bail; } /* main options done - only thing left is explicit partition specification, @@ -375,13 +375,13 @@ int find_dp(struct part_iter **_iter) break; } while (!pi_next(iter)); if (iter->status) { - error("Requested disk / partition combination not found.\n"); + error("Requested disk / partition combination not found."); goto bail; } } if (!(iter->di.disk & 0x80) && iter->index) { - error("WARNING: Partitions on floppy devices may not work.\n"); + warn("Partitions on floppy devices may not work."); } *_iter = iter; @@ -408,7 +408,7 @@ static int setup_handover(const struct part_iter *iter, /* RAW handover protocol */ ha = malloc(synth_size); if (!ha) { - error("Could not build RAW hand-over record!\n"); + critm(); goto bail; } len = ~0u; @@ -426,7 +426,7 @@ static int setup_handover(const struct part_iter *iter, synth_size += sizeof *plen + iter->gpt.pe_size; ha = malloc(synth_size); if (!ha) { - error("Could not build GPT hand-over record!\n"); + critm(); goto bail; } lba2chs(&ha->start, &iter->di, iter->start_lba, L2C_CADD); @@ -456,7 +456,7 @@ static int setup_handover(const struct part_iter *iter, /* MBR handover protocol */ ha = malloc(synth_size); if (!ha) { - error("Could not build MBR hand-over record!\n"); + critm(); goto bail; } memcpy(ha, iter->record, synth_size); @@ -528,11 +528,11 @@ int main(int argc, char *argv[]) fdat.base = (opt.fseg << 4) + opt.foff; if (loadfile(opt.file, &fdat.data, &fdat.size)) { - error("Couldn't read the boot file.\n"); + error("Couldn't read the boot file."); goto bail; } if (fdat.base + fdat.size - 1 > ADDRMAX) { - error("The boot file is too big to load at this address.\n"); + error("The boot file is too big to load at this address."); goto bail; } } @@ -543,22 +543,22 @@ int main(int argc, char *argv[]) sdat.size = iter->di.bps; if (sdat.base + sdat.size - 1 > ADDRMAX) { - error("The sector cannot be loaded at such high address.\n"); + error("The sector cannot be loaded at such high address."); goto bail; } if (!(sdat.data = disk_read_sectors(&iter->di, iter->start_lba, 1))) { - error("Couldn't read the sector.\n"); + error("Couldn't read the sector."); goto bail; } if (opt.save) { if (!(sbck = malloc(sdat.size))) { - error("Couldn't allocate cmp-buf for option 'save'.\n"); + critm(); goto bail; } memcpy(sbck, sdat.data, sdat.size); } if (opt.file && opt.maps && overlap(&fdat, &sdat)) { - error("WARNING: The sector won't be mmapped, as it would conflict with the boot file.\n"); + warn("The sector won't be mmapped, as it would conflict with the boot file."); opt.maps = false; } } @@ -570,8 +570,8 @@ int main(int argc, char *argv[]) /* Verify possible conflicts */ if ( ( opt.file && overlap(&fdat, &hdat)) || ( opt.maps && overlap(&sdat, &hdat)) ) { - error("WARNING: Handover area won't be prepared,\n" - "as it would conflict with the boot file and/or the sector.\n"); + warn("Handover area won't be prepared,\n" + "as it would conflict with the boot file and/or the sector."); opt.hand = false; } } @@ -622,15 +622,15 @@ int main(int argc, char *argv[]) memcpy(data + ndata++, &hdat, sizeof(hdat)); #ifdef DEBUG - printf("iter->di dsk, bps: %X, %u\niter->di lbacnt, C*H*S: %"PRIu64", %u\n" + dprintf("iter->di dsk, bps: %X, %u\niter->di lbacnt, C*H*S: %"PRIu64", %u\n" "iter->di C, H, S: %u, %u, %u\n", iter->di.disk, iter->di.bps, iter->di.lbacnt, iter->di.cyl * iter->di.head * iter->di.spt, iter->di.cyl, iter->di.head, iter->di.spt); - printf("iter idx: %d\n", iter->index); - printf("iter lba: %"PRIu64"\n", iter->start_lba); + dprintf("iter idx: %d\n", iter->index); + dprintf("iter lba: %"PRIu64"\n", iter->start_lba); if (opt.hand) - printf("hand lba: %u\n", + dprintf("hand lba: %u\n", ((struct disk_dos_part_entry *)hdat.data)->start_lba); #endif @@ -642,7 +642,7 @@ int main(int argc, char *argv[]) if (ndata && !opt.brkchain) /* boot only if we actually chainload */ do_boot(data, ndata); else - error("Service-only run completed, exiting.\n"); + puts("Service-only run completed, exiting."); bail: pi_del(&iter); /* Free allocated areas */ diff --git a/com32/chain/mangle.c b/com32/chain/mangle.c index a699f3c..b252a66 100644 --- a/com32/chain/mangle.c +++ b/com32/chain/mangle.c @@ -62,7 +62,7 @@ int manglef_isolinux(struct data_area *data) sdi = syslinux_derivative_info(); if (sdi->c.filesystem != SYSLINUX_FS_ISOLINUX) { - error ("The isolinux= option is only valid when run from ISOLINUX.\n"); + error("The isolinux= option is only valid when run from ISOLINUX."); goto bail; } @@ -88,7 +88,7 @@ int manglef_isolinux(struct data_area *data) file_lba = get_file_lba(opt.file); if (file_lba == 0) { - error("Failed to find LBA offset of the boot file\n"); + error("Failed to find LBA offset of the boot file."); goto bail; } /* Set it */ @@ -163,7 +163,7 @@ int manglef_grub(const struct part_iter *iter, struct data_area *data) return 0; if (data->size < sizeof(struct grub_stage2_patch_area)) { - error("The file specified by grub=<loader> is too small to be stage2 of GRUB Legacy.\n"); + error("The file specified by grub=<loader> is too small to be stage2 of GRUB Legacy."); goto bail; } stage2 = data->data; @@ -174,7 +174,7 @@ int manglef_grub(const struct part_iter *iter, struct data_area *data) */ if (stage2->compat_version_major != 3 || stage2->compat_version_minor != 2) { - error("The file specified by grub=<loader> is not a supported stage2 GRUB Legacy binary.\n"); + error("The file specified by grub=<loader> is not a supported stage2 GRUB Legacy binary."); goto bail; } @@ -213,7 +213,7 @@ int manglef_grub(const struct part_iter *iter, struct data_area *data) */ if (opt.grubcfg) { if (strlen(opt.grubcfg) > sizeof(stage2->config_file) - 1) { - error ("The config filename length can't exceed 88 characters.\n"); + error("The config filename length can't exceed 88 characters."); goto bail; } @@ -254,11 +254,11 @@ int manglef_drmk(struct data_area *data) dprintf(" fs_lba offset is %d\n", fs_lba); /* DRMK only uses a DWORD */ if (fs_lba > 0xffffffff) { - error("LBA very large; Only using lower 32 bits; DRMK will probably fail\n"); + error("LBA very large; Only using lower 32 bits; DRMK will probably fail."); } opt.regs.ss = opt.regs.fs = opt.regs.gs = 0; /* Used before initialized */ if (!realloc(data->data, tsize)) { - error("Failed to realloc for DRMK.\n"); + error("Failed to realloc for DRMK."); goto bail; } data->size = tsize; @@ -352,12 +352,12 @@ int manglesf_bss(struct data_area *sec, struct data_area *fil) type2 = bpb_detect(sec->data, "bss/sect"); if (!type1 || !type2) { - error("Couldn't determine the BPB type for option 'bss'.\n"); + error("Couldn't determine the BPB type for option 'bss'."); goto bail; } if (type1 != type2) { error("Option 'bss' can't be used,\n" - "when a sector and a file have incompatible BPBs.\n"); + "when a sector and a file have incompatible BPBs."); goto bail; } @@ -395,7 +395,7 @@ int mangles_save(const struct part_iter *iter, const struct data_area *data, voi if (memcmp(org, data->data, data->size)) { if (disk_write_sectors(&iter->di, iter->start_lba, data->data, 1)) { - error("Cannot write the updated sector.\n"); + error("Cannot write the updated sector."); goto bail; } /* function can be called again */ @@ -530,12 +530,12 @@ int manglepe_hide(struct part_iter *miter) return 0; if (miter->type != typedos) { - error("Option '[un]hide[all]' is meaningful only for legacy (DOS) partition scheme.\n"); + error("Option '[un]hide[all]' works only for legacy (DOS) partition scheme."); return -1; } if (miter->index > 4 && !(opt.hide & HIDE_EXT)) - error("WARNING: your partition is logical, so it can't be unhidden without 'unhideall'.\n"); + warn("Specified partition is logical, so it can't be unhidden without 'unhideall'."); if (!(iter = pi_begin(&miter->di, PIF_STEPALL))) return -1; @@ -569,7 +569,7 @@ int manglepe_hide(struct part_iter *miter) werr |= disk_write_sectors(&iter->di, iter->dos.cebr_lba, iter->data, 1); } if (werr) - error("WARNING: failed to write E/MBR during '[un]hide[all]'\n"); + warn("Failed to write E/MBR during '[un]hide[all]'."); bail: pi_del(&iter); @@ -607,7 +607,7 @@ int manglepe_fixchs(struct part_iter *miter) return 0; if (miter->type != typedos) { - error("Option 'fixchs' is meaningful only for legacy (DOS) partition scheme.\n"); + error("Option 'fixchs' works only for legacy (DOS) partition scheme."); return -1; } @@ -642,7 +642,7 @@ int manglepe_fixchs(struct part_iter *miter) werr |= disk_write_sectors(&iter->di, iter->dos.cebr_lba, iter->data, 1); } if (werr) - error("WARNING: failed to write E/MBR during 'fixchs'\n"); + warn("Failed to write E/MBR during 'fixchs'."); bail: pi_del(&iter); diff --git a/com32/chain/options.c b/com32/chain/options.c index 46a26df..93f14f7 100644 --- a/com32/chain/options.c +++ b/com32/chain/options.c @@ -58,14 +58,14 @@ static int soi_s2n(char *ptr, unsigned int *seg, val = (segval << 4) + offval; if (val < ADDRMIN || val > ADDRMAX) { - error("Invalid seg:off:* address specified..\n"); + error("Invalid seg:off:* address specified."); goto bail; } val = (segval << 4) + ipval; if (ipval > 0xFFFE || val < ADDRMIN || val > ADDRMAX) { - error("Invalid seg:*:ip address specified.\n"); + error("Invalid seg:*:ip address specified."); goto bail; } @@ -83,69 +83,74 @@ bail: static void usage(void) { - unsigned int i; - static const char key[] = "Press any key...\n"; + size_t i; static const char *const usage[] = { -"\ -Usage:\n\ - chain.c32 [options]\n\ - chain.c32 {fd|hd}<disk#>{,| }[<part#>] [options]\n\ - chain.c32 mbr{:|=}<id>{,| }[<part#>] [options]\n\ - chain.c32 guid{:|=}<guid>{,| }[<part#>] [options]\n\ - chain.c32 label{:|=}<label> [<part#>] [options]\n\ - chain.c32 boot{,| }[<part#>] [options]\n\ - chain.c32 fs [options]\n\ -", "\ -\nOptions ('no' prefix specifies default value):\n\ - sect[=<s[:o[:i]]>] Load sector at <s:o>, jump to <s:i>\n\ - - defaults to 0:0x7C00:0x7C00\n\ - - ommited o/i values default to 0\n\ - maps Map loaded sector into real memory\n\ - nosetbpb Fix BPB fields in loaded sector\n\ - nofilebpb Apply 'setbpb' to loaded file\n\ - nosave Write adjusted sector back to disk\n\ - hand Prepare handover area\n\ - nohptr Force ds:si and ds:bp to point to handover area\n\ - noswap Swap drive numbers, if bootdisk is not fd0/hd0\n\ - nohide Disable all hide variations (also the default)\n\ - hide Hide primary partitions, unhide selected partition\n\ - hideall Hide *all* partitions, unhide selected partition\n\ - unhide Unhide primary partitions\n\ - unhideall Unhide *all* partitions\n\ - nofixchs Walk *all* partitions and fix E/MBRs' chs values\n\ - nokeeppxe Keep the PXE and UNDI stacks in memory (PXELINUX)\n\ - nowarn Wait for a keypress to continue chainloading\n\ - - useful to see emited warnings\n\ - nobreak Actually perform the chainloading\n\ -", "\ -\nOptions continued ...\n\ - file=<file> Load and execute <file>\n\ - seg=<s[:o[:i]]> Load file at <s:o>, jump to <s:i>\n\ - - defaults to 0:0x7C00:0x7C00\n\ - - ommited o/i values default to 0\n\ - isolinux=<loader> Load another version of ISOLINUX\n\ - ntldr=<loader> Load Windows NTLDR, SETUPLDR.BIN or BOOTMGR\n\ - reactos=<loader> Load ReactOS's loader\n\ - cmldr=<loader> Load Recovery Console of Windows NT/2K/XP/2003\n\ - freedos=<loader> Load FreeDOS KERNEL.SYS\n\ - msdos=<loader> Load MS-DOS 2.xx - 6.xx IO.SYS\n\ - msdos7=<loader> Load MS-DOS 7+ IO.SYS\n\ - pcdos=<loader> Load PC-DOS IBMBIO.COM\n\ - drmk=<loader> Load DRMK DELLBIO.BIN\n\ - grub=<loader> Load GRUB Legacy stage2\n\ - grubcfg=<filename> Set alternative config filename for GRUB Legacy\n\ - grldr=<loader> Load GRUB4DOS grldr\n\ - bss=<filename> Emulate syslinux's BSS\n\ - bs=<filename> Emulate syslinux's BS\n\ -\nPlease see doc/chain.txt for the detailed documentation.\n\ -" - }; +"Usage:", +"", +" disk + partition selection:", +" chain.c32 [options]", +" chain.c32 hd#[,#] [options]", +" chain.c32 fd#[,#] [options]", +" chain.c32 mbr=<id>[,#] [options]", +" chain.c32 guid=<guid>[,#] [options]", +" chain.c32 boot[,#] [options]", +"", +" direct partition selection:", +" chain.c32 guid=<guid> [options]", +" chain.c32 label=<label> [options]", +" chain.c32 fs [options]", +"", +"You can use ':' instead of '=' and ' ' instead of ','.", +"The default is 'boot,0'.", +"", +"Options:", +" sect[=<s[:o[:i]]>] Load sector at <s:o>, jump to <s:i>", +" - defaults to 0:0x7C00:0x7C00", +" - omitted o/i values default to 0", +" maps Map loaded sector into real memory", +" setbpb Fix BPB fields in loaded sector", +" filebpb Apply 'setbpb' to loaded file", +" save Write adjusted sector back to disk", +" hand Prepare handover area", +" hptr Force ds:si and ds:bp to point to handover area", +" swap Swap drive numbers, if bootdisk is not fd0/hd0", +" nohide Disable all hide variations (default)", +" hide Hide primary partitions, unhide selected partition", +" hideall Hide *all* partitions, unhide selected partition", +" unhide Unhide primary partitions", +" unhideall Unhide *all* partitions", +" fixchs Walk *all* partitions and fix E/MBRs' CHS values", +" keeppxe Keep the PXE and UNDI stacks in memory (PXELINUX)", +" warn Wait for a keypress to continue chainloading", +" break Don't chainload", +"", +" file=<file> Load and execute <file>", +" seg=<s[:o[:i]]> Load file at <s:o>, jump to <s:i>", +" - defaults to 0:0x7C00:0x7C00", +" - omitted o/i values default to 0", +" isolinux=<loader> Load another version of ISOLINUX", +" ntldr=<loader> Load Windows NTLDR, SETUPLDR.BIN or BOOTMGR", +" reactos=<loader> Load ReactOS's loader", +" cmldr=<loader> Load Recovery Console of Windows NT/2K/XP/2003", +" freedos=<loader> Load FreeDOS KERNEL.SYS", +" msdos=<loader> Load MS-DOS 2.xx - 6.xx IO.SYS", +" msdos7=<loader> Load MS-DOS 7+ IO.SYS", +" pcdos=<loader> Load PC-DOS IBMBIO.COM", +" drmk=<loader> Load DRMK DELLBIO.BIN", +" grub=<loader> Load GRUB Legacy stage2", +" grubcfg=<config> Set alternative config filename for GRUB Legacy", +" grldr=<loader> Load GRUB4DOS grldr", +" bss=<sectimage> Emulate syslinux's BSS", +" bs=<sectimage> Emulate syslinux's BS", +"", +"Please see doc/chain.txt for the detailed documentation." +}; for (i = 0; i < sizeof(usage)/sizeof(usage[0]); i++) { - if (i) { - error(key); + if (i % 20 == 19) { + puts("Press any key..."); wait_key(); } - error(usage[i]); + puts(usage[i]); } } @@ -360,27 +365,27 @@ int opt_parse_args(int argc, char *argv[]) } if (opt.grubcfg && !opt.grub) { - error("grubcfg=<filename> must be used together with grub=<loader>.\n"); + error("grubcfg=<filename> must be used together with grub=<loader>."); goto bail; } if (opt.filebpb && !opt.file) { - error("Option 'filebpb' requires a file.\n"); + error("Option 'filebpb' requires a file."); goto bail; } if (opt.save && !opt.sect) { - error("Option 'save' requires a sector.\n"); + error("Option 'save' requires a sector."); goto bail; } if (opt.setbpb && !opt.sect) { - error("Option 'setbpb' requires a sector.\n"); + error("Option 'setbpb' requires a sector."); goto bail; } if (opt.maps && !opt.sect) { - error("Option 'maps' requires a sector.\n"); + error("Option 'maps' requires a sector."); goto bail; } diff --git a/com32/chain/partiter.c b/com32/chain/partiter.c index 7f98ecb..6535719 100644 --- a/com32/chain/partiter.c +++ b/com32/chain/partiter.c @@ -103,8 +103,10 @@ static int pi_dos_ctor(struct part_iter *iter, if (pi_ctor(iter, di, flags)) return -1; - if (!(iter->data = malloc(sizeof(struct disk_dos_mbr)))) + if (!(iter->data = malloc(sizeof(struct disk_dos_mbr)))) { + critm(); goto bail; + } memcpy(iter->data, mbr, sizeof(struct disk_dos_mbr)); @@ -131,8 +133,10 @@ static int pi_gpt_ctor(struct part_iter *iter, siz = (uint64_t)gpth->part_count * gpth->part_size; - if (!(iter->data = malloc((size_t)siz))) + if (!(iter->data = malloc((size_t)siz))) { + critm(); goto bail; + } memcpy(iter->data, gptl, (size_t)siz); @@ -169,7 +173,7 @@ static int notsane_logical(const struct part_iter *iter) return 0; if (ost_is_ext(dp[0].ostype)) { - error("1st EBR entry must be data or empty.\n"); + error("The 1st EBR entry must be data or empty."); return -1; } @@ -180,7 +184,7 @@ static int notsane_logical(const struct part_iter *iter) !sane(dp[0].start_lba, dp[0].length) || end_log > iter->dos.nebr_siz) { - error("Logical partition (in EBR) with invalid offset and/or length.\n"); + error("Logical partition (in EBR) with invalid offset and/or length."); return -1; } @@ -205,7 +209,7 @@ static int notsane_extended(const struct part_iter *iter) return 0; if (!ost_is_nondata(dp[1].ostype)) { - error("The 2nd EBR entry must be extended or empty.\n"); + error("The 2nd EBR entry must be extended or empty."); return -1; } @@ -216,7 +220,7 @@ static int notsane_extended(const struct part_iter *iter) !sane(dp[1].start_lba, dp[1].length) || end_ebr > iter->dos.bebr_siz) { - error("Extended partition (EBR) with invalid offset and/or length.\n"); + error("Extended partition (EBR) with invalid offset and/or length."); return -1; } @@ -240,7 +244,7 @@ static int notsane_primary(const struct part_iter *iter) !dp->length || !sane(dp->start_lba, dp->length) || dp->start_lba + dp->length > iter->di.lbacnt) { - error("Primary partition (in MBR) with invalid offset and/or length.\n"); + error("Primary partition (in MBR) with invalid offset and/or length."); return -1; } @@ -258,7 +262,7 @@ static int notsane_gpt(const struct part_iter *iter) if (gp->lba_first < iter->gpt.ufirst || gp->lba_last > iter->gpt.ulast) { - error("LBA sectors of GPT partition are beyond the range allowed in GPT header.\n"); + error("LBA sectors of GPT partition are beyond the range allowed in GPT header."); return -1; } @@ -280,7 +284,7 @@ static int dos_next_mbr(struct part_iter *iter, uint32_t *lba, if (ost_is_ext(dp->ostype)) { if (iter->dos.bebr_index0 >= 0) { - error("More than 1 extended partition.\n"); + error("More than 1 extended partition."); iter->status = PI_INSANE; return -1; } @@ -331,7 +335,7 @@ static int dos_next_ebr(struct part_iter *iter, uint32_t *lba, free(iter->data); if (!(iter->data disk_read_sectors(&iter->di, iter->dos.nebr_lba, 1))) { - error("Couldn't load EBR.\n"); + error("Couldn't load EBR."); iter->status = PI_ERRLOAD; return -1; } @@ -405,18 +409,18 @@ static int gpt_check_hdr_crc(const struct disk_info * const diskinfo, struct dis hold_crc32 = gh->chksum; gh->chksum = 0; if (!valid_crc(hold_crc32, (const uint8_t *)gh, gh->hdr_size)) { - error("WARNING: Primary GPT header checksum invalid.\n"); + warn("Primary GPT header checksum invalid."); /* retry with backup */ lba_alt = gh->lba_alt; free(gh); if (!(gh = *_gh = disk_read_sectors(diskinfo, lba_alt, 1))) { - error("Couldn't read backup GPT header.\n"); + error("Couldn't read backup GPT header."); return -1; } hold_crc32 = gh->chksum; gh->chksum = 0; if (!valid_crc(hold_crc32, (const uint8_t *)gh, gh->hdr_size)) { - error("Secondary GPT header checksum invalid.\n"); + error("Secondary GPT header checksum invalid."); return -1; } } @@ -514,7 +518,7 @@ static struct part_iter *pi_alloc(void) { struct part_iter *iter; if (!(iter = malloc(sizeof(struct part_iter)))) - error("Couldn't allocate memory for the iterator.\n"); + critm(); else memset(iter, 0, sizeof(struct part_iter)); return iter; @@ -545,13 +549,13 @@ struct part_iter *pi_begin(const struct disk_info *di, int flags) /* Read MBR */ if (!(mbr = disk_read_sectors(di, 0, 1))) { - error("Couldn't read first disk sector.\n"); + error("Couldn't read the first disk sector."); goto bail; } /* Check for MBR magic */ if (mbr->sig != disk_mbr_sig_magic) { - error("WARNING: no MBR magic, treating disk as raw.\n"); + warn("No MBR magic, treating disk as raw."); /* looks like RAW */ ret = pi_ctor(iter, di, flags); goto bail; @@ -560,7 +564,7 @@ struct part_iter *pi_begin(const struct disk_info *di, int flags) /* Check for GPT protective MBR */ if (mbr->table[0].ostype == 0xEE) { if (!(gpth = disk_read_sectors(di, 1, 1))) { - error("Couldn't read potential GPT header.\n"); + error("Couldn't read potential GPT header."); goto bail; } } @@ -572,7 +576,7 @@ struct part_iter *pi_begin(const struct disk_info *di, int flags) uint64_t gpt_lsiz; /* size of GPT partition list in bytes */ uint64_t gpt_lcnt; /* size of GPT partition in sectors */ #ifdef DEBUG - puts("Looks like a GPT v1.0 disk."); + dprintf("Looks like a GPT v1.0 disk.\n"); disk_gpt_header_dump(gpth); #endif /* Verify checksum, fallback to backup, then bail if invalid */ @@ -596,24 +600,24 @@ struct part_iter *pi_begin(const struct disk_info *di, int flags) gpth->lba_last_usable + gpt_lcnt >= gpth->lba_alt || gpth->lba_alt >= di->lbacnt || gpth->part_size < sizeof(struct disk_gpt_part_entry)) { - error("Invalid GPT header's values.\n"); + error("Invalid GPT header's values."); goto bail; } if (!(gptl = disk_read_sectors(di, gpt_loff, gpt_lcnt))) { - error("Couldn't read GPT partition list.\n"); + error("Couldn't read GPT partition list."); goto bail; } /* Check array checksum(s). */ if (!valid_crc(gpth->table_chksum, (const uint8_t *)gptl, (unsigned int)gpt_lsiz)) { - error("Checksum of the main GPT partition list is invalid, trying backup.\n"); + warn("Checksum of the main GPT partition list is invalid, trying backup."); free(gptl); /* secondary array directly precedes secondary header */ if (!(gptl = disk_read_sectors(di, gpth->lba_alt - gpt_lcnt, gpt_lcnt))) { - error("Couldn't read backup GPT partition list.\n"); + error("Couldn't read backup GPT partition list."); goto bail; } if (!valid_crc(gpth->table_chksum, (const uint8_t *)gptl, gpt_lsiz)) { - error("Checksum of the backup GPT partition list is invalid, giving up.\n"); + error("Checksum of the backup GPT partition list is invalid, giving up."); goto bail; } } diff --git a/com32/chain/utility.h b/com32/chain/utility.h index cc2c93a..ac056dc 100644 --- a/com32/chain/utility.h +++ b/com32/chain/utility.h @@ -54,12 +54,23 @@ int drvoff_detect(int type); int bpb_detect(const uint8_t *bpb, const char *tag); int guid_is0(const struct guid *guid); -static inline -void error(const char *msg) +static inline int warn(const char *x) { - fputs(msg, stderr); + return fprintf(stderr, "WARN: %s\n", x); } +static inline int error(const char *x) +{ + return fprintf(stderr, "ERR: %s\n", x); +} + +static inline int crit(const char *x) +{ + return fprintf(stderr, "CRIT: %s @%s:%d\n", x, __FILE__, __LINE__); +} + +#define critm() crit("Malloc failure.") + #endif /* vim: set ts=8 sts=4 sw=4 noet: */ diff --git a/doc/chain.txt b/doc/chain.txt index 6dd0632..e71b1c0 100644 --- a/doc/chain.txt +++ b/doc/chain.txt @@ -53,29 +53,27 @@ Module invocation: chain [drive/partition] [options] +In case of repeated arguments, rightmost ones take precedence. + + DRIVE / PARTITION SPECIFICATION Drive can be specified as 'hd#', 'fd#', 'boot', 'mbr', or 'guid'. -- 'mbr' will select a drive by a signature. -- 'guid' will select a drive by a guid +- 'mbr' will select a drive by its signature. +- 'guid' will select a drive by its guid (GPT only). - 'boot' is the drive syslinux was booted from. This is the default value, if nothing else is specified. - 'hd#' and 'fd#' are standard ways to specify drive number as seen by bios, starting from 0. -Option 'guid' is shared with partition selection (see below). If you happened +Option 'guid' is shared with partition selection (see below). If you happen to have non-unique guids, they are searched in disk0, partitions of disk0, disk1 ... order. -The priority of those options are the same as in the above list. - -If you specify the same value more than once, the last value will be used. - 'mbr' and 'guid' take extra parameter - you should use ':' or '=' as a delimiter. - Partition can be specified as '#', 'guid', 'label' or 'fs'. - 'guid' option will select a partition by a guid (not a type guid !) @@ -85,11 +83,10 @@ Partition can be specified as '#', 'guid', 'label' or 'fs'. - '#' is the standard method. Partitions 1-4 are primary, 5+ logical, 0 = boot MBR (default). -The priority of those options are the same as in the above list. - If you use a number to select a partition it should be specified after a drive using space or comma as delimiters (after 'hd#', 'fd#', 'mbr', 'guid' or 'boot'). + OPTIONS file=<file> *nofile @@ -110,7 +107,7 @@ This triplet lets you alter the addresses a file will use. It's loaded at other bootloader or kernel, it's almost always mandatory. The defaults, if option is not specified, are 0:0x7c00:0x7c00 -If any of the fields are ommited (e.g. 0x2000::), they default to 0. +If any of the fields are omitted (e.g. 0x2000::), they default to 0. sect=<segment>:<offset>:<ip> nosect @@ -126,7 +123,7 @@ expect relocated sector at some particular address (e.g. DRKM). is being chainloaded, sector is not necessary. The defaults if option is not specified, are 0:0x7c00:0x7c00. -If some of the fields are ommited (e.g. 0x2000::), they default to 0. +If some of the fields are omitted (e.g. 0x2000::), they default to 0. *maps nomaps -- 1.7.10.4
Michal Soltys
2013-Jan-29 14:06 UTC
[syslinux] [PATCH 15/28] com32/chain: implement relax flag
This flag tones down sanity checks during partition iteration. This is useful in situations such as: - inconsistent layouts, but with some partition still in sane bootable state - usb sticks/disks moved between different PCs might return different size, which might cause problems if the partitions span the whole disk Signed-off-by: Michal Soltys <soltys at ziu.info> --- com32/chain/chain.c | 10 +++++----- com32/chain/mangle.c | 4 ++-- com32/chain/options.c | 6 ++++++ com32/chain/options.h | 1 + com32/chain/partiter.c | 17 +++++++++++++++-- com32/chain/partiter.h | 1 + doc/chain.txt | 14 ++++++++++++-- 7 files changed, 42 insertions(+), 11 deletions(-) diff --git a/com32/chain/chain.c b/com32/chain/chain.c index ccfeefa..f1120d9 100644 --- a/com32/chain/chain.c +++ b/com32/chain/chain.c @@ -72,7 +72,7 @@ static int find_by_sig(uint32_t mbr_sig, for (drive = 0x80; drive < 0x80 + fixed_cnt; drive++) { if (disk_get_params(drive, &diskinfo)) continue; /* Drive doesn't exist */ - if (!(boot_part = pi_begin(&diskinfo, 0))) + if (!(boot_part = pi_begin(&diskinfo, opt.relax))) continue; /* Check for a MBR disk */ if (boot_part->type != typedos) { @@ -103,7 +103,7 @@ static int find_by_guid(const struct guid *gpt_guid, for (drive = 0x80; drive < 0x80 + fixed_cnt; drive++) { if (disk_get_params(drive, &diskinfo)) continue; /* Drive doesn't exist */ - if (!(boot_part = pi_begin(&diskinfo, 0))) + if (!(boot_part = pi_begin(&diskinfo, opt.relax))) continue; /* Check for a GPT disk */ if (boot_part->type != typegpt) { @@ -135,7 +135,7 @@ static int find_by_label(const char *label, struct part_iter **_boot_part) for (drive = 0x80; drive < 0x80 + fixed_cnt; drive++) { if (disk_get_params(drive, &diskinfo)) continue; /* Drive doesn't exist */ - if (!(boot_part = pi_begin(&diskinfo, 0))) + if (!(boot_part = pi_begin(&diskinfo, opt.relax))) continue; /* Check for a GPT disk */ if (!(boot_part->type == typegpt)) { @@ -324,7 +324,7 @@ int find_dp(struct part_iter **_iter) if (disk_get_params(drive, &diskinfo)) goto bail; /* this will start iteration over FDD, possibly raw */ - if (!(iter = pi_begin(&diskinfo, 0))) + if (!(iter = pi_begin(&diskinfo, opt.relax))) goto bail; } else if (!strcmp(opt.drivename, "boot") || !strcmp(opt.drivename, "fs")) { @@ -344,7 +344,7 @@ int find_dp(struct part_iter **_iter) if (disk_get_params(drive, &diskinfo)) goto bail; /* this will start iteration over disk emulation, possibly raw */ - if (!(iter = pi_begin(&diskinfo, 0))) + if (!(iter = pi_begin(&diskinfo, opt.relax))) goto bail; /* 'fs' => we should lookup the syslinux partition number and use it */ diff --git a/com32/chain/mangle.c b/com32/chain/mangle.c index b252a66..252128d 100644 --- a/com32/chain/mangle.c +++ b/com32/chain/mangle.c @@ -537,7 +537,7 @@ int manglepe_hide(struct part_iter *miter) if (miter->index > 4 && !(opt.hide & HIDE_EXT)) warn("Specified partition is logical, so it can't be unhidden without 'unhideall'."); - if (!(iter = pi_begin(&miter->di, PIF_STEPALL))) + if (!(iter = pi_begin(&miter->di, PIF_STEPALL | opt.relax))) return -1; while (!pi_next(iter) && !werr) { @@ -611,7 +611,7 @@ int manglepe_fixchs(struct part_iter *miter) return -1; } - if (!(iter = pi_begin(&miter->di, PIF_STEPALL))) + if (!(iter = pi_begin(&miter->di, PIF_STEPALL | opt.relax))) return -1; while (!pi_next(iter) && !werr) { diff --git a/com32/chain/options.c b/com32/chain/options.c index 93f14f7..209ad01 100644 --- a/com32/chain/options.c +++ b/com32/chain/options.c @@ -33,6 +33,7 @@ #include <string.h> #include "common.h" #include "chain.h" +#include "partiter.h" #include "utility.h" #include "options.h" @@ -123,6 +124,7 @@ static void usage(void) " keeppxe Keep the PXE and UNDI stacks in memory (PXELINUX)", " warn Wait for a keypress to continue chainloading", " break Don't chainload", +" relax Relax sanity checks", "", " file=<file> Load and execute <file>", " seg=<s[:o[:i]]> Load file at <s:o>, jump to <s:i>", @@ -324,6 +326,10 @@ int opt_parse_args(int argc, char *argv[]) opt.fixchs = true; } else if (!strcmp(argv[i], "nofixchs")) { opt.fixchs = false; + } else if (!strcmp(argv[i], "relax")) { + opt.relax = PIF_RELAX; + } else if (!strcmp(argv[i], "norelax")) { + opt.relax = 0; } else if (!strcmp(argv[i], "warn")) { opt.warn = true; } else if (!strcmp(argv[i], "nowarn")) { diff --git a/com32/chain/options.h b/com32/chain/options.h index ea6e470..ac8f356 100644 --- a/com32/chain/options.h +++ b/com32/chain/options.h @@ -64,6 +64,7 @@ struct options { bool filebpb; bool fixchs; bool warn; + int relax; bool brkchain; uint16_t keeppxe; struct syslinux_rm_regs regs; diff --git a/com32/chain/partiter.c b/com32/chain/partiter.c index 6535719..967769f 100644 --- a/com32/chain/partiter.c +++ b/com32/chain/partiter.c @@ -177,6 +177,9 @@ static int notsane_logical(const struct part_iter *iter) return -1; } + if (iter->flags & PIF_RELAX) + return 0; + end_log = dp[0].start_lba + dp[0].length; if (!dp[0].start_lba || @@ -213,6 +216,9 @@ static int notsane_extended(const struct part_iter *iter) return -1; } + if (iter->flags & PIF_RELAX) + return 0; + end_ebr = dp[1].start_lba + dp[1].length; if (!dp[1].start_lba || @@ -240,6 +246,9 @@ static int notsane_primary(const struct part_iter *iter) if (!dp->ostype) return 0; + if (iter->flags & PIF_RELAX) + return 0; + if (!dp->start_lba || !dp->length || !sane(dp->start_lba, dp->length) || @@ -260,6 +269,9 @@ static int notsane_gpt(const struct part_iter *iter) if (guid_is0(&gp->type)) return 0; + if (iter->flags & PIF_RELAX) + return 0; + if (gp->lba_first < iter->gpt.ufirst || gp->lba_last > iter->gpt.ulast) { error("LBA sectors of GPT partition are beyond the range allowed in GPT header."); @@ -592,14 +604,15 @@ struct part_iter *pi_begin(const struct disk_info *di, int flags) * it as a sanity check base. EFI doesn't specify max (AFAIK). * Apart from that, some extensive sanity checks. */ - if (!gpt_loff || !gpt_lsiz || gpt_lcnt > 255u || + if (!(flags & PIF_RELAX) && ( + !gpt_loff || !gpt_lsiz || gpt_lcnt > 255u || gpth->lba_first_usable > gpth->lba_last_usable || !sane(gpt_loff, gpt_lcnt) || gpt_loff + gpt_lcnt > gpth->lba_first_usable || !sane(gpth->lba_last_usable, gpt_lcnt) || gpth->lba_last_usable + gpt_lcnt >= gpth->lba_alt || gpth->lba_alt >= di->lbacnt || - gpth->part_size < sizeof(struct disk_gpt_part_entry)) { + gpth->part_size < sizeof(struct disk_gpt_part_entry))) { error("Invalid GPT header's values."); goto bail; } diff --git a/com32/chain/partiter.h b/com32/chain/partiter.h index 63dc6da..a737584 100644 --- a/com32/chain/partiter.h +++ b/com32/chain/partiter.h @@ -47,6 +47,7 @@ enum {PI_OK, PI_DONE, PI_INSANE, PI_ERRLOAD}; /* flags */ #define PIF_STEPALL 0x01 +#define PIF_RELAX 0x02 struct itertype; struct part_iter; diff --git a/doc/chain.txt b/doc/chain.txt index e71b1c0..d3c012c 100644 --- a/doc/chain.txt +++ b/doc/chain.txt @@ -110,8 +110,8 @@ The defaults, if option is not specified, are 0:0x7c00:0x7c00 If any of the fields are omitted (e.g. 0x2000::), they default to 0. sect=<segment>:<offset>:<ip> - nosect *sect=0:0x7c00:0x7c00 + nosect nosect sets: nomaps This triplet lets you alter the addresses a sector will use. It's loaded at @@ -226,8 +226,18 @@ stacks in memory (pxelinux only). This option will wait for a keypress right before continuing the chainloading. Useful to see warnings emited by the chain module. - *nobreak + relax + *norelax + +This option inhibits sanity checks during the traversal of the partition table. +This is potentially useful in corner cases, when for example an usb stick moved +to some different computer would report smaller size than previously with +partitions spanning the whole space. Normally partition iterator would report +an error and abort in such case. Another case scenario is disk corruption in +some later EMBR partition. + break + *nobreak break sets: nofile nomaps nohand It is possible to trigger a "service-only" run - The chain module will do -- 1.7.10.4
Michal Soltys
2013-Jan-29 14:06 UTC
[syslinux] [PATCH 21/28] com32/chain: manglepe_fixchs() correction
We have to be more careful, when in-entry start/length values are 0 (one or both). Firstly they are relative to the disk or the [B]EBR (while CHS are absolute). Secondly, length 0 would imply the end CHS being lower than the start CHS. Under normal circumstances, partiter would complain about corrupt layout (unless relax flag is set) and value 0 in any of those fields generally imply a hole, so the adjustments were harmless - nontheless they made everything look silly and not really correct. Adjusted approach is: - for start entry - if the os entry is 0 /and/ the beginning is 0 - reset to 0, otherwise calculate chs - for end entry - as above /or/ length is 0 - reset to 0, otherwise calculate chs Signed-off-by: Michal Soltys <soltys at ziu.info> --- com32/chain/mangle.c | 48 ++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 38 insertions(+), 10 deletions(-) diff --git a/com32/chain/mangle.c b/com32/chain/mangle.c index 215ca41..a506e79 100644 --- a/com32/chain/mangle.c +++ b/com32/chain/mangle.c @@ -578,17 +578,47 @@ bail: return 0; } -static int updchs(const struct disk_info *di, - struct disk_dos_part_entry *dp, - uint32_t lba1) +static int updchs(struct part_iter *iter, int ext) { - uint32_t ochs1, ochs2; + struct disk_dos_part_entry *dp; + uint32_t ochs1, ochs2, lba; + dp = (struct disk_dos_part_entry *)iter->record; + if (!ext) { + /* primary or logical */ + lba = (uint32_t)iter->start_lba; + } else { + /* extended */ + dp += 1; + lba = iter->dos.nebr_lba; + } ochs1 = *(uint32_t *)dp->start; ochs2 = *(uint32_t *)dp->end; - lba2chs(&dp->start, di, lba1, L2C_CADD); - lba2chs(&dp->end, di, lba1 + dp->length - 1, L2C_CADD); + /* + * We have to be a bit more careful here in case of 0 start and/or length; + * start = 0 would be converted to the beginning of the disk (C/H/S + * 0/0/1) or the [B]EBR, length = 0 would actually set the end CHS to be + * lower than the start CHS. + * + * Both are harmless in case of a hole (and in non-hole case will make + * partiter complain about corrupt layout unless PIF_RELAX is set), but it + * makes everything look silly and not really correct. + * + * Thus the approach as seen below. + */ + + if (dp->start_lba || iter->index != -1) { + lba2chs(&dp->start, &iter->di, lba, L2C_CADD); + } else { + memset(&dp->start, 0, sizeof dp->start); + } + + if ((dp->start_lba || iter->index != -1) && dp->length) { + lba2chs(&dp->end, &iter->di, lba + dp->length - 1, L2C_CADD); + } else { + memset(&dp->end, 0, sizeof dp->end); + } return *(uint32_t *)dp->start != ochs1 || @@ -602,7 +632,6 @@ int manglepe_fixchs(struct part_iter *miter) { int wb = 0, werr = 0; struct part_iter *iter = NULL; - struct disk_dos_part_entry *dp; int ridx; if (!opt.fixchs) @@ -618,11 +647,10 @@ int manglepe_fixchs(struct part_iter *miter) while (!pi_next(iter) && !werr) { ridx = iter->index0; - dp = (struct disk_dos_part_entry *)iter->record; - wb |= updchs(&iter->di, dp, iter->start_lba); + wb |= updchs(iter, 0); if (ridx > 3) - wb |= updchs(&iter->di, dp + 1, iter->dos.nebr_lba); + wb |= updchs(iter, 1); /* * we have to update mbr and each extended partition, but only if -- 1.7.10.4
Michal Soltys
2013-Jan-29 14:06 UTC
[syslinux] [PATCH 24/28] com32/chain: (partiter) dos_next_ebr() fixup
Make sure that *lba is set to 0, if start_lba in the record is 0. Not an issue in any of the code using partiter currently, as that implies either broken layout or a hole. Still useful for consistency with index == -1 or when relax flag is set. Signed-off-by: Michal Soltys <soltys at ziu.info> --- com32/chain/partiter.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/com32/chain/partiter.c b/com32/chain/partiter.c index a4dc13d..8d0c272 100644 --- a/com32/chain/partiter.c +++ b/com32/chain/partiter.c @@ -374,7 +374,7 @@ static int dos_next_ebr(struct part_iter *iter, uint32_t *lba, iter->dos.logskipcnt++; if (dp[0].ostype || (iter->flags & PIF_STEPALL)) { - *lba = iter->dos.cebr_lba + dp[0].start_lba; + *lba = dp[0].start_lba ? iter->dos.cebr_lba + dp[0].start_lba : 0; *_dp = dp; return 0; } -- 1.7.10.4
Michal Soltys
2013-Jan-29 14:06 UTC
[syslinux] [PATCH 25/28] com32/chain: (partiter) add cebr_siz for completness
Might be useful at some and/or when partiter becomes a non-chain specific code. Signed-off-by: Michal Soltys <soltys at ziu.info> --- com32/chain/partiter.c | 1 + com32/chain/partiter.h | 1 + 2 files changed, 2 insertions(+) diff --git a/com32/chain/partiter.c b/com32/chain/partiter.c index 8d0c272..ced3a45 100644 --- a/com32/chain/partiter.c +++ b/com32/chain/partiter.c @@ -360,6 +360,7 @@ static int dos_next_ebr(struct part_iter *iter, uint32_t *lba, dp = ((struct disk_dos_mbr *)iter->data)->table; iter->dos.cebr_lba = iter->dos.nebr_lba; + iter->dos.cebr_siz = iter->dos.nebr_siz; /* setup next frame values */ if (dp[1].ostype) { diff --git a/com32/chain/partiter.h b/com32/chain/partiter.h index ab4922c..13dec84 100644 --- a/com32/chain/partiter.h +++ b/com32/chain/partiter.h @@ -77,6 +77,7 @@ struct part_iter { uint32_t bebr_siz; /* size of base extended partition */ uint32_t cebr_lba; /* absolute lba of curr ext. partition */ + uint32_t cebr_siz; /* size of curr ext. partition */ uint32_t nebr_lba; /* absolute lba of next ext. partition */ uint32_t nebr_siz; /* size of next ext. partition */ -- 1.7.10.4
Michal Soltys
2013-Jan-29 14:06 UTC
[syslinux] [PATCH 26/28] com32/chain: (utility) use enum for BPB types
Signed-off-by: Michal Soltys <soltys at ziu.info> --- com32/chain/utility.h | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/com32/chain/utility.h b/com32/chain/utility.h index c9d4652..596017b 100644 --- a/com32/chain/utility.h +++ b/com32/chain/utility.h @@ -36,15 +36,8 @@ #include <syslinux/disk.h> #include <syslinux/movebits.h> -#define bpbUNK 0 -#define bpbV20 1 -#define bpbV30 2 -#define bpbV32 3 -#define bpbV34 4 -#define bpbV40 5 -#define bpbVNT 6 -#define bpbV70 7 -#define bpbEXF 8 +/* most (all ?) bpb "types" known to humankind as of 2012 */ +enum {bpbUNK, bpbV20, bpbV30, bpbV32, bpbV34, bpbV40, bpbVNT, bpbV70, bpbEXF}; /* see utility.c for details */ enum {L2C_CNUL, L2C_CADD, L2C_CMAX}; -- 1.7.10.4
Matt Fleming
2013-Feb-04 18:17 UTC
[syslinux] [PATCH 01/28] com32/chain: update licenses and #ifndef stanzas
On Tue, 2013-01-29 at 15:05 +0100, Michal Soltys wrote:> Licenses: > > chain.[ch] Makefile: GPLv2+ > the rest: MIT > > Defines: > > Avoid prefixing with _ > > Signed-off-by: Michal Soltys <soltys at ziu.info>Peter, Shao, could I get an Acked-by for this patch? -- Matt Fleming, Intel Open Source Technology Center
H. Peter Anvin
2013-Feb-04 21:39 UTC
[syslinux] [PATCH 01/28] com32/chain: update licenses and #ifndef stanzas
On 01/29/2013 06:05 AM, Michal Soltys wrote:> Licenses: > > chain.[ch] Makefile: GPLv2+ > the rest: MIT > > Defines: > > Avoid prefixing with _ > > Signed-off-by: Michal Soltys <soltys at ziu.info>Acked-by: H. Peter Anvin <hpa at linux.intel.com> -hpa
Possibly Parallel Threads
- [PATCH 0/6] chain.c32 patches
- PATCH/RFC chain.c: update iterator code, yank from chain.c, move both to separate directory
- [PULL 0/8] MultiFS suppport for BIOS and EFI
- [PATCH 00/12] Multidisk support
- [RFC/PATCH 1/3] Move partiter from com32/chain to com32/lib/syslinux