diff --git a/ChangeLog b/ChangeLog index 5f944efbe..763ccf2c4 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,50 @@ +2006-06-05 Yoshinori K. Okuji + + Count partitions from 1 instead of 0 in the string representation + of partitions. Still use 0-based internally. + + * partmap/sun.c (grub_sun_is_valid): A cosmetic change. + (sun_partition_map_iterate): Use grub_partition_t instead of + struct grub_partition *. Cast DESC->START_CYLINDER to + grub_uint64_t after converting the endian. + (sun_partition_map_probe): Subtract 1 for PARTNUM. + (sun_partition_map_get_name): Add 1 to P->INDEX. + + * partmap/pc.c (grub_partition_parse): Subtract 1 for + PCDATA->DOS_PART. + (pc_partition_map_get_name): Add 1 into PCDATA->DOS_PART. + + * partmap/gpt.c (gpt_partition_map_iterate): Initialize PARTNO to + zero instead of one. + (gpt_partition_map_probe): Subtract 1 for PARTNUM. + (gpt_partition_map_get_name): Add 1 into P->INDEX. + + * partmap/apple.c (apple_partition_map_iterate): Change the type + of POS to unsigned. + (apple_partition_map_probe): Subtract 1 for PARTNUM. + (apple_partition_map_get_name): Add 1 into P->INDEX. + + * partmap/amiga.c (amiga_partition_map_iterate): Change the type + of POS to unsigned. + (amiga_partition_map_iterate): Cast NEXT to grub_off_t to + calculate the offset of a partition. + (amiga_partition_map_probe): Subtract 1 for PARTNUM. + (amiga_partition_map_get_name): Add 1 into P->INDEX. + + * partmap/acorn.c (acorn_partition_map_find): Change the type of + SECTOR to grub_disk_addr_t. + (acorn_partition_map_iterate): Likewise. + (acorn_partition_map_probe): Subtract 1 for PARTNUM. + Change the type of SECTOR to grub_disk_addr_t. Declare P on the + top. + (acorn_partition_map_get_name): Add 1 into P->INDEX. + + * kern/i386/pc/init.c (make_install_device): Add 1 into + GRUB_INSTALL_DOS_PART. + + * fs/iso9660.c (grub_iso9660_mount): Fixed a reversed + conditional. + 2006-06-04 Yoshinori K. Okuji Clean up the code to support 64-bit addressing in disks and diff --git a/NEWS b/NEWS index 19071e35d..575177f27 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,8 @@ +New in 1.95: + +* Number partitions from 1 instead of 0. For instance, the first + partition of "hd0" is now "hd0,1" but not "hd0,0". + New in 1.94 - 2006-06-04: * Fix several serious bugs in HFS+. diff --git a/fs/iso9660.c b/fs/iso9660.c index 225ce0df2..453d47ace 100644 --- a/fs/iso9660.c +++ b/fs/iso9660.c @@ -236,7 +236,7 @@ grub_iso9660_mount (grub_disk_t disk) goto fail; } - if (grub_strncmp ((char *) data->voldesc.voldesc.magic, "CD001", 5) == 0) + if (grub_strncmp ((char *) data->voldesc.voldesc.magic, "CD001", 5) != 0) { grub_error (GRUB_ERR_BAD_FS, "not a iso9660 filesystem"); goto fail; @@ -268,7 +268,7 @@ grub_iso9660_mount (grub_disk_t disk) sua_size = rootdir.len - sua_pos; sua = grub_malloc (sua_size); - if (!sua) + if (! sua) goto fail; if (grub_disk_read (disk, (grub_le_to_cpu32 (data->voldesc.rootdir.first_sector) @@ -622,7 +622,7 @@ grub_iso9660_dir (grub_device_t device, const char *path, #endif data = grub_iso9660_mount (device->disk); - if (!data) + if (! data) goto fail; rootnode.data = data; diff --git a/kern/i386/pc/init.c b/kern/i386/pc/init.c index f553df74f..2baf6a107 100644 --- a/kern/i386/pc/init.c +++ b/kern/i386/pc/init.c @@ -1,6 +1,6 @@ /* * GRUB -- GRand Unified Bootloader - * Copyright (C) 2002, 2003, 2004, 2005 Free Software Foundation, Inc. + * Copyright (C) 2002,2003,2004,2005,2006 Free Software Foundation, Inc. * * 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 @@ -64,7 +64,7 @@ make_install_device (void) grub_boot_drive & 0x7f); if (grub_install_dos_part >= 0) - grub_sprintf (dev + grub_strlen (dev), ",%u", grub_install_dos_part); + grub_sprintf (dev + grub_strlen (dev), ",%u", grub_install_dos_part + 1); if (grub_install_bsd_part >= 0) grub_sprintf (dev + grub_strlen (dev), ",%c", grub_install_bsd_part + 'a'); diff --git a/partmap/acorn.c b/partmap/acorn.c index ff8a13448..bb8f5b4e4 100644 --- a/partmap/acorn.c +++ b/partmap/acorn.c @@ -51,7 +51,7 @@ static struct grub_partition_map grub_acorn_partition_map; static grub_err_t acorn_partition_map_find (grub_disk_t disk, struct linux_part *m, - unsigned int *sector) + grub_disk_addr_t *sector) { struct grub_acorn_boot_block boot; grub_err_t err; @@ -61,8 +61,8 @@ acorn_partition_map_find (grub_disk_t disk, struct linux_part *m, int i; err = grub_disk_read (disk, 0xC00 / GRUB_DISK_SECTOR_SIZE, 0, - sizeof (struct grub_acorn_boot_block), - (char *)&boot); + sizeof (struct grub_acorn_boot_block), + (char *) &boot); if (err) return err; @@ -82,7 +82,7 @@ acorn_partition_map_find (grub_disk_t disk, struct linux_part *m, return grub_disk_read (disk, *sector, 0, sizeof (struct linux_part) * LINUX_MAP_ENTRIES, - (char *)m); + (char *) m); fail: return grub_error (GRUB_ERR_BAD_PART_TABLE, @@ -100,7 +100,7 @@ acorn_partition_map_iterate (grub_disk_t disk, struct grub_disk raw; struct linux_part map[LINUX_MAP_ENTRIES]; int i; - unsigned int sector; + grub_disk_addr_t sector; grub_err_t err; /* Enforce raw disk access. */ @@ -119,7 +119,7 @@ acorn_partition_map_iterate (grub_disk_t disk, && map[i].magic != LINUX_SWAP_MAGIC) return GRUB_ERR_NONE; - part.start = (grub_disk_addr_t)sector + map[i].start; + part.start = sector + map[i].start; part.len = map[i].size; part.offset = 6; part.index = i; @@ -137,10 +137,11 @@ acorn_partition_map_probe (grub_disk_t disk, const char *str) { struct linux_part map[LINUX_MAP_ENTRIES]; struct grub_disk raw = *disk; - unsigned long partnum = grub_strtoul (str, 0, 10); - unsigned int sector; + unsigned long partnum = grub_strtoul (str, 0, 10) - 1; + grub_disk_addr_t sector; grub_err_t err; - + grub_partition_t p; + /* Enforce raw disk access. */ raw.partition = 0; @@ -156,11 +157,11 @@ acorn_partition_map_probe (grub_disk_t disk, const char *str) && map[partnum].magic != LINUX_SWAP_MAGIC) goto fail; - grub_partition_t p = grub_malloc (sizeof (struct grub_partition)); - if (!p) + p = grub_malloc (sizeof (struct grub_partition)); + if (! p) return 0; - p->start = (grub_disk_addr_t)sector + map[partnum].start; + p->start = sector + map[partnum].start; p->len = map[partnum].size; p->offset = 6; p->index = partnum; @@ -178,10 +179,10 @@ acorn_partition_map_get_name (const grub_partition_t p) char *name; name = grub_malloc (13); - if (!name) + if (! name) return 0; - grub_sprintf (name, "%d", p->index); + grub_sprintf (name, "%d", p->index + 1); return name; } diff --git a/partmap/amiga.c b/partmap/amiga.c index bb5417ff5..5306cd58a 100644 --- a/partmap/amiga.c +++ b/partmap/amiga.c @@ -84,7 +84,7 @@ amiga_partition_map_iterate (grub_disk_t disk, struct grub_disk raw; int partno = 0; int next = -1; - int pos; + unsigned pos; /* Enforce raw disk access. */ raw = *disk; @@ -94,8 +94,7 @@ amiga_partition_map_iterate (grub_disk_t disk, for (pos = 0; pos < 15; pos++) { /* Read the RDSK block which is a descriptor for the entire disk. */ - if (grub_disk_read (&raw, pos, 0, - sizeof (rdsk), (char *) &rdsk)) + if (grub_disk_read (&raw, pos, 0, sizeof (rdsk), (char *) &rdsk)) return grub_errno; if (grub_strcmp ((char *) rdsk.magic, "RDSK") == 0) @@ -116,8 +115,7 @@ amiga_partition_map_iterate (grub_disk_t disk, struct grub_amiga_partition apart; /* Read the RDSK block which is a descriptor for the entire disk. */ - if (grub_disk_read (&raw, next, 0, - sizeof (apart), (char *) &apart)) + if (grub_disk_read (&raw, next, 0, sizeof (apart), (char *) &apart)) return grub_errno; /* Calculate the first block and the size of the partition. */ @@ -129,7 +127,7 @@ amiga_partition_map_iterate (grub_disk_t disk, * grub_be_to_cpu32 (apart.heads) * grub_be_to_cpu32 (apart.block_per_track)); - part.offset = next * 512; + part.offset = (grub_off_t) next * 512; part.index = partno; part.partmap = &grub_amiga_partition_map; @@ -155,7 +153,7 @@ amiga_partition_map_probe (grub_disk_t disk, const char *str) int find_func (grub_disk_t d __attribute__ ((unused)), const grub_partition_t partition) - { + { if (partnum == partition->index) { p = (grub_partition_t) grub_malloc (sizeof (*p)); @@ -170,7 +168,7 @@ amiga_partition_map_probe (grub_disk_t disk, const char *str) } /* Get the partition number. */ - partnum = grub_strtoul (s, 0, 10); + partnum = grub_strtoul (s, 0, 10) - 1; if (grub_errno) { grub_error (GRUB_ERR_BAD_FILENAME, "invalid partition"); @@ -197,7 +195,7 @@ amiga_partition_map_get_name (const grub_partition_t p) if (! name) return 0; - grub_sprintf (name, "%d", p->index); + grub_sprintf (name, "%d", p->index + 1); return name; } diff --git a/partmap/apple.c b/partmap/apple.c index 96d7c192a..2c6457fd6 100644 --- a/partmap/apple.c +++ b/partmap/apple.c @@ -1,7 +1,7 @@ /* apple.c - Read macintosh partition tables. */ /* * GRUB -- GRand Unified Bootloader - * Copyright (C) 2002, 2004, 2005 Free Software Foundation, Inc. + * Copyright (C) 2002,2004,2005,2006 Free Software Foundation, Inc. * * 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 @@ -102,7 +102,7 @@ apple_partition_map_iterate (grub_disk_t disk, struct grub_apple_part apart; struct grub_disk raw; int partno = 0; - int pos = GRUB_DISK_SECTOR_SIZE; + unsigned pos = GRUB_DISK_SECTOR_SIZE; /* Enforce raw disk access. */ raw = *disk; @@ -113,7 +113,7 @@ apple_partition_map_iterate (grub_disk_t disk, for (;;) { if (grub_disk_read (&raw, pos / GRUB_DISK_SECTOR_SIZE, - pos % GRUB_DISK_SECTOR_SIZE, + pos % GRUB_DISK_SECTOR_SIZE, sizeof (struct grub_apple_part), (char *) &apart)) return grub_errno; @@ -140,7 +140,8 @@ apple_partition_map_iterate (grub_disk_t disk, if (hook (disk, &part)) return grub_errno; - if (grub_be_to_cpu32 (apart.first_phys_block) == GRUB_DISK_SECTOR_SIZE * 2) + if (grub_be_to_cpu32 (apart.first_phys_block) + == GRUB_DISK_SECTOR_SIZE * 2) return 0; pos += sizeof (struct grub_apple_part); @@ -181,7 +182,7 @@ apple_partition_map_probe (grub_disk_t disk, const char *str) } /* Get the partition number. */ - partnum = grub_strtoul (s, 0, 10); + partnum = grub_strtoul (s, 0, 10) - 1; if (grub_errno) { grub_error (GRUB_ERR_BAD_FILENAME, "invalid partition"); @@ -208,7 +209,7 @@ apple_partition_map_get_name (const grub_partition_t p) if (! name) return 0; - grub_sprintf (name, "%d", p->index); + grub_sprintf (name, "%d", p->index + 1); return name; } diff --git a/partmap/gpt.c b/partmap/gpt.c index cfcb974c9..0cb959ae2 100644 --- a/partmap/gpt.c +++ b/partmap/gpt.c @@ -79,7 +79,7 @@ gpt_partition_map_iterate (grub_disk_t disk, struct grub_disk raw; struct grub_pc_partition_mbr mbr; grub_uint64_t entries; - int partno = 1; + int partno = 0; unsigned int i; int last_offset = 0; @@ -157,7 +157,7 @@ gpt_partition_map_probe (grub_disk_t disk, const char *str) int find_func (grub_disk_t d __attribute__ ((unused)), const grub_partition_t partition) - { + { if (partnum == partition->index) { p = (grub_partition_t) grub_malloc (sizeof (*p)); @@ -172,7 +172,7 @@ gpt_partition_map_probe (grub_disk_t disk, const char *str) } /* Get the partition number. */ - partnum = grub_strtoul (s, 0, 10); + partnum = grub_strtoul (s, 0, 10) - 1; if (grub_errno) { grub_error (GRUB_ERR_BAD_FILENAME, "invalid partition"); @@ -199,7 +199,7 @@ gpt_partition_map_get_name (const grub_partition_t p) if (! name) return 0; - grub_sprintf (name, "%d", p->index); + grub_sprintf (name, "%d", p->index + 1); return name; } diff --git a/partmap/pc.c b/partmap/pc.c index 7aee7ec93..45e4eb139 100644 --- a/partmap/pc.c +++ b/partmap/pc.c @@ -55,8 +55,9 @@ grub_partition_parse (const char *str) /* Initialize some of the fields with invalid values. */ pcdata->bsd_part = pcdata->dos_type = pcdata->bsd_type = p->index = -1; - /* Get the DOS partition number. */ - pcdata->dos_part = grub_strtoul (s, &s, 0); + /* Get the DOS partition number. The number is counted from one for + the user interface, and from zero internally. */ + pcdata->dos_part = grub_strtoul (s, &s, 0) - 1; if (grub_errno) { @@ -237,6 +238,7 @@ pc_partition_map_probe (grub_disk_t disk, const char *str) const grub_partition_t partition) { struct grub_pc_partition *partdata = partition->data; + if ((pcdata->dos_part == partdata->dos_part || pcdata->dos_part == -1) && pcdata->bsd_part == partdata->bsd_part) { @@ -283,9 +285,11 @@ pc_partition_map_get_name (const grub_partition_t p) return 0; if (pcdata->bsd_part < 0) - grub_sprintf (name, "%d", pcdata->dos_part); + grub_sprintf (name, "%d", pcdata->dos_part + 1); + else if (pcdata->dos_part < 0) + grub_sprintf (name, "%c", pcdata->bsd_part + 'a'); else - grub_sprintf (name, "%d,%c", pcdata->dos_part, pcdata->bsd_part + 'a'); + grub_sprintf (name, "%d,%c", pcdata->dos_part + 1, pcdata->bsd_part + 'a'); return name; } diff --git a/partmap/sun.c b/partmap/sun.c index e2cde0a2e..9d51160cf 100644 --- a/partmap/sun.c +++ b/partmap/sun.c @@ -1,7 +1,7 @@ /* sun.c - Read SUN style partition tables. */ /* * GRUB -- GRand Unified Bootloader - * Copyright (C) 2002, 2005 Free Software Foundation, Inc. + * Copyright (C) 2002,2005,2006 Free Software Foundation, Inc. * * GRUB is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -78,9 +78,13 @@ grub_sun_is_valid (struct grub_sun_block *label) { grub_uint16_t *pos; grub_uint16_t sum = 0; - for (pos = (grub_uint16_t *) label; pos < (grub_uint16_t *) (label + 1); pos++) + + for (pos = (grub_uint16_t *) label; + pos < (grub_uint16_t *) (label + 1); + pos++) sum ^= *pos; - return !sum; + + return ! sum; } static grub_err_t @@ -88,14 +92,16 @@ sun_partition_map_iterate (grub_disk_t disk, int (*hook) (grub_disk_t disk, const grub_partition_t partition)) { - struct grub_partition *p; + grub_partition_t p; struct grub_disk raw; struct grub_sun_block block; int partnum; + raw = *disk; raw.partition = 0; - p = (struct grub_partition *) grub_malloc (sizeof (struct grub_partition)); - if (!p) + + p = (grub_partition_t) grub_malloc (sizeof (struct grub_partition)); + if (! p) return grub_errno; p->offset = 0; @@ -106,20 +112,25 @@ sun_partition_map_iterate (grub_disk_t disk, { if (GRUB_PARTMAP_SUN_MAGIC != grub_be_to_cpu16 (block.magic)) grub_error (GRUB_ERR_BAD_PART_TABLE, "not a sun partiton table"); - if (!grub_sun_is_valid (&block)) + + if (! grub_sun_is_valid (&block)) grub_error (GRUB_ERR_BAD_PART_TABLE, "invalid checksum"); + /* Maybe another error value would be better, because partition table _is_ recognised but invalid. */ for (partnum = 0; partnum < GRUB_PARTMAP_SUN_MAX_PARTS; partnum++) { - if (block.infos[partnum].id == 0 || - block.infos[partnum].id == GRUB_PARTMAP_SUN_WHOLE_DISK_ID) + struct grub_sun_partition_descriptor *desc; + + if (block.infos[partnum].id == 0 + || block.infos[partnum].id == GRUB_PARTMAP_SUN_WHOLE_DISK_ID) continue; - p->start = grub_be_to_cpu32 - (block.partitions[partnum].start_cylinder) - * grub_be_to_cpu16 (block.ntrks) - * grub_be_to_cpu16 (block.nsect); - p->len = grub_be_to_cpu32 (block.partitions[partnum].num_sectors); + + desc = &block.partitions[partnum]; + p->start = ((grub_uint64_t) grub_be_to_cpu32 (desc->start_cylinder) + * grub_be_to_cpu16 (block.ntrks) + * grub_be_to_cpu16 (block.nsect)); + p->len = grub_be_to_cpu32 (desc->num_sectors); p->index = partnum; if (p->len) { @@ -128,6 +139,7 @@ sun_partition_map_iterate (grub_disk_t disk, } } } + grub_free (p); return grub_errno; @@ -150,13 +162,15 @@ sun_partition_map_probe (grub_disk_t disk, const char *str) p = (grub_partition_t) grub_malloc (sizeof (*p)); if (p) grub_memcpy (p, partition, sizeof (*p)); + return 1; } + return 0; } grub_errno = GRUB_ERR_NONE; - partnum = grub_strtoul (s, 0, 10); + partnum = grub_strtoul (s, 0, 10) - 1; if (grub_errno == GRUB_ERR_NONE) { if (sun_partition_map_iterate (disk, find_func)) @@ -170,6 +184,7 @@ sun_partition_map_probe (grub_disk_t disk, const char *str) grub_error (GRUB_ERR_BAD_FILENAME, "invalid partition"); p = 0; } + return p; } @@ -177,9 +192,11 @@ static char * sun_partition_map_get_name (const grub_partition_t p) { char *name; + name = grub_malloc (13); if (name) - grub_sprintf (name, "%d", p->index); + grub_sprintf (name, "%d", p->index + 1); + return name; }