From d160380affab95c1375f3981663b97b5d037708e Mon Sep 17 00:00:00 2001 From: "H. Peter Anvin" Date: Fri, 25 Jun 2010 19:49:20 -0700 Subject: [PATCH] extlinux: modify the layout for btrfs Put the btrfs boot code right after the boot sector (they are really one image anyway). Align the ADV with the end of the boot region, so we can locate it for modification as necessary, and the offset don't end up shifting with different boot image sizes. Signed-off-by: H. Peter Anvin --- extlinux/main.c | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/extlinux/main.c b/extlinux/main.c index ad17351..884a025 100644 --- a/extlinux/main.c +++ b/extlinux/main.c @@ -67,13 +67,14 @@ typedef uint64_t u64; #endif /* the btrfs partition first 64K blank area is used to store boot sector and - boot image, the boot sector is from 0~512, the boot image starts at 2K */ -#define BTRFS_EXTLINUX_OFFSET (2*1024) + boot image, the boot sector is from 0~512, the boot image starts after */ +#define BTRFS_BOOTSECT_AREA 65536 +#define BTRFS_EXTLINUX_OFFSET SECTOR_SIZE #define BTRFS_SUBVOL_OPT "subvol=" #define BTRFS_SUBVOL_MAX 256 /* By btrfs specification */ static char subvol[BTRFS_SUBVOL_MAX]; -#define BTRFS_ADV_OFFSET (BTRFS_EXTLINUX_OFFSET + boot_image_len) +#define BTRFS_ADV_OFFSET (BTRFS_BOOTSECT_AREA - 2 * ADV_SIZE) /* * Get the size of a block device @@ -265,9 +266,12 @@ int patch_file_and_bootblock(int fd, const char *dir, int devfd) } } else if (fs_type == BTRFS) { int i; + sector_t *sp = sectp; - for (i = 0; i < nsect; i++) - sectp[i] = BTRFS_EXTLINUX_OFFSET/SECTOR_SIZE + i; + for (i = 0; i < nsect - 2; i++) + *sp++ = BTRFS_EXTLINUX_OFFSET/SECTOR_SIZE + i; + for (i = 0; i < 2; i++) + *sp++ = BTRFS_ADV_OFFSET/SECTOR_SIZE + i; } /* Create the modified image in memory */ @@ -441,13 +445,13 @@ int btrfs_install_file(const char *path, int devfd, struct stat *rst) perror("writing bootblock"); return 1; } - printf("write boot_image to 0x%x\n", BTRFS_EXTLINUX_OFFSET); - if (xpwrite(devfd, syslinux_adv, 2 * ADV_SIZE, - BTRFS_EXTLINUX_OFFSET + boot_image_len) != 2 * ADV_SIZE) { + dprintf("write boot_image to 0x%x\n", BTRFS_EXTLINUX_OFFSET); + if (xpwrite(devfd, syslinux_adv, 2 * ADV_SIZE, BTRFS_ADV_OFFSET) + != 2 * ADV_SIZE) { perror("writing adv"); return 1; } - printf("write adv to 0x%x\n", BTRFS_EXTLINUX_OFFSET + boot_image_len); + dprintf("write adv to 0x%x\n", BTRFS_ADV_OFFSET); if (stat(path, rst)) { perror(path); return 1; -- 2.7.4