Frediano Ziglio
2012-Aug-02 09:44 UTC
[syslinux] [PATCH 2/3] ALPHA: first try to fix adv problem
This is part of some patches to support sectors > 512. Currently I'm able to boot a Ubuntu kernel but seems that mboot is not working for some reason. This patch try to fix ADV size problem. Signed-off-by: Frediano Ziglio <frediano.ziglio at citrix.com> --- extlinux/main.c | 40 +++++++++++++++++++++++++++++++++++----- 1 files changed, 35 insertions(+), 5 deletions(-) diff --git a/extlinux/main.c b/extlinux/main.c index e40b4d7..61eaad1 100644 --- a/extlinux/main.c +++ b/extlinux/main.c @@ -275,7 +275,8 @@ static int patch_file_and_bootblock(int fd, const char *dir, int devfd) dprintf("subpath = %s\n", subpath); totalbytes = get_size(devfd); - sector_size = get_sector_size(devfd); + /* FIXME support greater sector sizes for BTRFS */ + sector_size = fs_type == BTRFS ? SECTOR_SIZE : get_sector_size(devfd); get_geometry(devfd, totalbytes, sector_size, &geo); if (opt.heads) @@ -318,6 +319,7 @@ static int patch_file_and_bootblock(int fd, const char *dir, int devfd) int i; sector_t *sp = sectp; +// FIXME ?? for (i = 0; i < nsect - 2; i++) *sp++ = BTRFS_EXTLINUX_OFFSET/SECTOR_SIZE + i; for (i = 0; i < 2; i++) @@ -410,12 +412,33 @@ int install_bootblock(int fd, const char *device) return 0; } -int ext2_fat_install_file(const char *path, int devfd, struct stat *rst) +static int inc_and_align(int fd, unsigned *pos, unsigned bytes, unsigned align) +{ + char buf[512]; + unsigned left; + + *pos += bytes; + left = *pos % align; + left = (align - left) % align; + while (left > 0) { + unsigned l = left > sizeof(buf) ? sizeof(buf) : left; + memset(buf, 0, sizeof(buf)); + if (xpwrite(fd, buf, l, *pos) != l) + return 0; + left -= l; + *pos += l; + } + return 1; +} + +static int ext2_fat_install_file(const char *path, int devfd, struct stat *rst) { char *file, *oldfile; int fd = -1, dirfd = -1; int modbytes; int r1, r2; + unsigned sector_size; + unsigned pos; r1 = asprintf(&file, "%s%sldlinux.sys", path, path[0] && path[strlen(path) - 1] == '/' ? "" : "/"); @@ -450,10 +473,17 @@ int ext2_fat_install_file(const char *path, int devfd, struct stat *rst) goto bail; } + /* FIXME copied above */ + sector_size = fs_type == BTRFS ? SECTOR_SIZE : get_sector_size(devfd); + /* Write it the first time */ - if (xpwrite(fd, boot_image, boot_image_len, 0) != boot_image_len || - xpwrite(fd, syslinux_adv, 2 * ADV_SIZE, - boot_image_len) != 2 * ADV_SIZE) { + pos = 0; + if (xpwrite(fd, boot_image, boot_image_len, pos) != boot_image_len || + !inc_and_align(fd, &pos, boot_image_len, sector_size) || + xpwrite(fd, syslinux_adv, ADV_SIZE, pos) != ADV_SIZE || + !inc_and_align(fd, &pos, ADV_SIZE, sector_size) || + xpwrite(fd, syslinux_adv + ADV_SIZE, ADV_SIZE, pos) != ADV_SIZE || + !inc_and_align(fd, &pos, ADV_SIZE, sector_size)) { fprintf(stderr, "%s: write failure on %s\n", program, file); goto bail; } -- 1.7.5.4