From: Michal Soltys Date: Sun, 22 Aug 2010 11:44:01 +0000 (+0200) Subject: chain.c: Split chain into smaller files X-Git-Tag: syslinux-4.06-pre3~3^2~55 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=b4ba30102958f77e6bef1354459a06416408c2d7;p=profile%2Fivi%2Fsyslinux.git chain.c: Split chain into smaller files new file: chain.h new file: common.h new file: mangle.c new file: mangle.h new file: options.c new file: options.h new file: utility.c new file: utility.h Signed-off-by: Michal Soltys --- diff --git a/com32/chain/Makefile b/com32/chain/Makefile index 337775c..054c768 100644 --- a/com32/chain/Makefile +++ b/com32/chain/Makefile @@ -15,7 +15,7 @@ topdir = ../.. include ../MCONFIG -OBJS = chain.o partiter.o +OBJS = chain.o partiter.o utility.o options.o mangle.o GCCEXTRA = -Wextra -Wconversion -pedantic -Wno-error -DDEBUG all: chain.c32 diff --git a/com32/chain/chain.c b/com32/chain/chain.c index 5af6c15..d1939ec 100644 --- a/com32/chain/chain.c +++ b/com32/chain/chain.c @@ -34,83 +34,22 @@ #include #include #include +#include "common.h" +#include "chain.h" +#include "utility.h" +#include "options.h" #include "partiter.h" +#include "mangle.h" -/* used in checks, whenever addresses supplied by user are sane */ +struct options opt; -#define ADDRMAX 0x9EFFFu -#define ADDRMIN 0x500u - -static const char cmldr_signature[8] = "cmdcons"; static int fixed_cnt; -static struct options { - unsigned int fseg; - unsigned int foff; - unsigned int fip; - unsigned int sseg; - unsigned int soff; - unsigned int sip; - unsigned int drvoff; - const char *drivename; - const char *partition; - const char *file; - const char *grubcfg; - bool isolinux; - bool cmldr; - bool drmk; - bool grub; - bool grldr; - bool maps; - bool hand; - bool hptr; - bool swap; - bool hide; - bool sethid; - bool setgeo; - bool setdrv; - bool sect; - bool save; - bool filebpb; - bool warn; - uint16_t keeppxe; - struct syslinux_rm_regs regs; -} opt; - -struct data_area { - void *data; - addr_t base; - addr_t size; -}; - -static void wait_key(void) -{ - int cnt; - char junk; - - /* drain */ - do { - errno = 0; - cnt = read(0, &junk, 1); - } while (cnt > 0 || (cnt < 0 && errno == EAGAIN)); - - /* wait */ - do { - errno = 0; - cnt = read(0, &junk, 1); - } while (!cnt || (cnt < 0 && errno == EAGAIN)); -} - -static void error(const char *msg) -{ - fputs(msg, stderr); -} - -static int no_ov(const struct data_area *a, const struct data_area *b) +static int overlap(const struct data_area *a, const struct data_area *b) { return - a->base + a->size <= b->base || - b->base + b->size <= a->base; + a->base + a->size > b->base && + b->base + b->size > a->base; } static int is_phys(uint8_t sdifs) @@ -400,377 +339,6 @@ out: free(mbr); } -static uint32_t get_file_lba(const char *filename) -{ - com32sys_t inregs; - uint32_t lba; - - /* Start with clean registers */ - memset(&inregs, 0, sizeof(com32sys_t)); - - /* Put the filename in the bounce buffer */ - strlcpy(__com32.cs_bounce, filename, __com32.cs_bounce_size); - - /* Call comapi_open() which returns a structure pointer in SI - * to a structure whose first member happens to be the LBA. - */ - inregs.eax.w[0] = 0x0006; - inregs.esi.w[0] = OFFS(__com32.cs_bounce); - inregs.es = SEG(__com32.cs_bounce); - __com32.cs_intcall(0x22, &inregs, &inregs); - - if ((inregs.eflags.l & EFLAGS_CF) || inregs.esi.w[0] == 0) { - return 0; /* Filename not found */ - } - - /* Since the first member is the LBA, we simply cast */ - lba = *((uint32_t *) MK_PTR(inregs.ds, inregs.esi.w[0])); - - /* Clean the registers for the next call */ - memset(&inregs, 0, sizeof(com32sys_t)); - - /* Put the filename in the bounce buffer */ - strlcpy(__com32.cs_bounce, filename, __com32.cs_bounce_size); - - /* Call comapi_close() to free the structure */ - inregs.eax.w[0] = 0x0008; - inregs.esi.w[0] = OFFS(__com32.cs_bounce); - inregs.es = SEG(__com32.cs_bounce); - __com32.cs_intcall(0x22, &inregs, &inregs); - - return lba; -} - -/* Convert string seg:off:ip values into numerical seg:off:ip ones */ - -static int soi_s2n(char *ptr, unsigned int *seg, - unsigned int *off, - unsigned int *ip) -{ - unsigned int segval = 0, offval = 0, ipval = 0, val; - char *p; - - segval = strtoul(ptr, &p, 0); - if (*p == ':') - offval = strtoul(p+1, &p, 0); - if (*p == ':') - ipval = strtoul(p+1, NULL, 0); - - val = (segval << 4) + offval; - - if (val < ADDRMIN || val > ADDRMAX) { - error("Invalid seg:off:* address specified..\n"); - goto bail; - } - - val = (segval << 4) + ipval; - - if (ipval > 0xFFFE || val < ADDRMIN || val > ADDRMAX) { - error("Invalid seg:*:ip address specified.\n"); - goto bail; - } - - if (seg) - *seg = segval; - if (off) - *off = offval; - if (ip) - *ip = ipval; - - return 0; - -bail: - return -1; -} - -static void usage(void) -{ - static const char *const usage[] = { "\ -Usage:\n\ - chain.c32 [options]\n\ - chain.c32 {fd|hd} [] [options]\n\ - chain.c32 mbr{:|=} [] [options]\n\ - chain.c32 guid{:|=} [] [options]\n\ - chain.c32 label{:|=}