From e6411a9473a77cccd0e136866f48445d6d6eb671 Mon Sep 17 00:00:00 2001 From: Peter Jones Date: Dec 02 2010 20:35:43 +0000 Subject: Minor fixes in ext2 and */loader/linux.c It's important to get the math right. --- diff --git a/grub-0.97-support-4k-sector-size.patch b/grub-0.97-support-4k-sector-size.patch index 4b0ccc4..3653efa 100644 --- a/grub-0.97-support-4k-sector-size.patch +++ b/grub-0.97-support-4k-sector-size.patch @@ -1,4 +1,4 @@ -From a39611033b8f84d5935b7e5f74dcb3150e0be86d Mon Sep 17 00:00:00 2001 +From aa7ca7c9f7266c432b5dad65302ae7cfa7a1c050 Mon Sep 17 00:00:00 2001 From: Peter Jones Date: Fri, 19 Nov 2010 11:25:00 -0500 Subject: [PATCH] Make most SECTOR_SIZE checks use functions. @@ -7,21 +7,21 @@ Most uses of SECTOR_SIZE or SECTOR_BITS are changed to get_sector_size() or get_sector_bits(), respectively. --- efi/efidisk.c | 62 ++++++++++++++++++++++++++++++++++++++++---- - efi/ia32/loader/linux.c | 6 ++-- - efi/x86_64/loader/linux.c | 6 ++-- + efi/ia32/loader/linux.c | 9 ++++++- + efi/x86_64/loader/linux.c | 9 ++++++- grub/asmstub.c | 25 +++++++++++++----- lib/device.c | 3 ++ stage2/boot.c | 11 ++++--- stage2/builtins.c | 20 ++++++++++---- stage2/disk_io.c | 50 ++++++++++++++++++++++------------- - stage2/fsys_ext2fs.c | 8 +++-- + stage2/fsys_ext2fs.c | 5 ++- stage2/fsys_fat.c | 20 +++++++++----- stage2/fsys_jfs.c | 12 +++++--- stage2/fsys_reiserfs.c | 24 +++++++++-------- stage2/fsys_xfs.c | 2 +- stage2/gpt.h | 9 +++--- stage2/shared.h | 12 ++++++--- - 15 files changed, 186 insertions(+), 84 deletions(-) + 15 files changed, 194 insertions(+), 79 deletions(-) diff --git a/efi/efidisk.c b/efi/efidisk.c index 145ed16..edd830e 100644 @@ -145,28 +145,24 @@ index 145ed16..edd830e 100644 while (next_partition (drv, 0, &part, &part_type, &partition_start, &partition_len, diff --git a/efi/ia32/loader/linux.c b/efi/ia32/loader/linux.c -index eb6b5de..499b852 100644 +index eb6b5de..eaaeb38 100644 --- a/efi/ia32/loader/linux.c +++ b/efi/ia32/loader/linux.c -@@ -92,7 +92,7 @@ allocate_pages (grub_size_t real_size, grub_size_t prot_size) - grub_efi_physical_address_t addr; +@@ -37,6 +37,13 @@ - /* Make sure that each size is aligned to a page boundary. */ -- real_size = page_align (real_size + SECTOR_SIZE); -+ real_size = page_align (real_size + get_sector_size(current_drive)); - prot_size = page_align (prot_size); + #define PTR_HI(x) ((grub_uint32_t) ((unsigned long long)((unsigned long)(x)) >> 32)) - grub_dprintf ("linux", "real_size = %x, prot_size = %x, mmap_size = %x\n", -@@ -365,7 +365,7 @@ grub_load_linux (char *kernel, char *arg) - setup_sects = lh->setup_sects; - - real_size = 0x1000 + grub_strlen(arg); -- prot_size = grub_file_size () - (setup_sects << SECTOR_BITS) - SECTOR_SIZE; -+ prot_size = grub_file_size () - (setup_sects << get_sector_bits(current_drive)) - get_sector_size(current_drive); - - if (! allocate_pages (real_size, prot_size)) - goto fail; -@@ -499,7 +499,7 @@ grub_load_linux (char *kernel, char *arg) ++#ifndef SECTOR_SIZE ++#define SECTOR_SIZE 0x200 ++#endif /* defined(SECTOR_SIZE) */ ++#ifndef SECTOR_BITS ++#define SECTOR_BITS 9 ++#endif /* defined(SECTOR_BITS) */ ++ + static unsigned long linux_mem_size; + static int loaded; + static void *real_mode_mem; +@@ -499,7 +506,7 @@ grub_load_linux (char *kernel, char *arg) dest = grub_stpcpy ((char *) real_mode_mem + 0x1000, skip_to(0, arg)); @@ -176,28 +172,24 @@ index eb6b5de..499b852 100644 if (grub_read ((char *) GRUB_LINUX_BZIMAGE_ADDR, len) != len) grub_printf ("Couldn't read file"); diff --git a/efi/x86_64/loader/linux.c b/efi/x86_64/loader/linux.c -index 18746ea..e4358a3 100644 +index 18746ea..93a0377 100644 --- a/efi/x86_64/loader/linux.c +++ b/efi/x86_64/loader/linux.c -@@ -87,7 +87,7 @@ allocate_pages (grub_size_t real_size, grub_size_t prot_size) - grub_efi_physical_address_t addr; - - /* Make sure that each size is aligned to a page boundary. */ -- real_size = page_align (real_size + SECTOR_SIZE); -+ real_size = page_align (real_size + get_sector_size(current_drive)); - prot_size = page_align (prot_size); +@@ -37,6 +37,13 @@ - grub_dprintf ("linux", "real_size = %x, prot_size = %x, mmap_size = %x\n", -@@ -316,7 +316,7 @@ grub_load_linux (char *kernel, char *arg) - setup_sects = lh->setup_sects; + #define PTR_HI(x) ((grub_uint32_t) ((unsigned long long)((unsigned long)(x)) >> 32)) - real_size = 0x1000 + grub_strlen(arg); -- prot_size = grub_file_size () - (setup_sects << SECTOR_BITS) - SECTOR_SIZE; -+ prot_size = grub_file_size () - (setup_sects << get_sector_bits(current_drive)) - get_sector_size(current_drive); - prot_kernel_size = prot_size; - - if (! allocate_pages (real_size, prot_size)) -@@ -447,7 +447,7 @@ grub_load_linux (char *kernel, char *arg) ++#ifndef SECTOR_SIZE ++#define SECTOR_SIZE 0x200 ++#endif /* defined(SECTOR_SIZE) */ ++#ifndef SECTOR_BITS ++#define SECTOR_BITS 9 ++#endif /* defined(SECTOR_BITS) */ ++ + static unsigned long linux_mem_size; + static int loaded; + static void *real_mode_mem; +@@ -447,7 +454,7 @@ grub_load_linux (char *kernel, char *arg) dest = grub_stpcpy ((char *) real_mode_mem + 0x1000, skip_to(0, arg)); @@ -603,7 +595,7 @@ index d54864f..308b291 100644 size = len; diff --git a/stage2/fsys_ext2fs.c b/stage2/fsys_ext2fs.c -index 810ac5f..80a1938 100644 +index 810ac5f..01386d1 100644 --- a/stage2/fsys_ext2fs.c +++ b/stage2/fsys_ext2fs.c @@ -25,7 +25,7 @@ @@ -632,16 +624,6 @@ index 810ac5f..80a1938 100644 (char *) SUPERBLOCK) || SUPERBLOCK->s_magic != EXT2_SUPER_MAGIC) retval = 0; -@@ -428,7 +429,8 @@ ext2_rdfsb (int fsblock, int buffer) - #ifdef E2DEBUG - printf ("fsblock %d buffer %d\n", fsblock, buffer); - #endif /* E2DEBUG */ -- return devread (fsblock * (EXT2_BLOCK_SIZE (SUPERBLOCK) / DEV_BSIZE), 0, -+ return devread (fsblock * (EXT2_BLOCK_SIZE (SUPERBLOCK) / DEV_BSIZE), -+ fsblock * (EXT2_BLOCK_SIZE (SUPERBLOCK) % blocksize), - EXT2_BLOCK_SIZE (SUPERBLOCK), (char *) (unsigned long) buffer); - } - diff --git a/stage2/fsys_fat.c b/stage2/fsys_fat.c index 266ec03..7e82266 100644 --- a/stage2/fsys_fat.c