disk: Rename grub_disk_get_size() to grub_disk_native_sectors()

The function grub_disk_get_size() is confusingly named because it actually
returns a sector count where the sectors are sized in the GRUB native sector
size. Rename to something more appropriate.

Suggested-by: Daniel Kiper <daniel.kiper@oracle.com>
Signed-off-by: Glenn Washburn <development@efficientek.com>
Reviewed-by: Patrick Steinhardt <ps@pks.im>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
This commit is contained in:
Glenn Washburn 2020-12-08 16:45:32 -06:00 committed by Daniel Kiper
parent 85307c34e8
commit 880dfd8f40
19 changed files with 38 additions and 38 deletions

View File

@ -148,7 +148,7 @@ scan_disk_partition_iter (grub_disk_t disk, grub_partition_t p, void *data)
if (m->disk && m->disk->id == disk->id if (m->disk && m->disk->id == disk->id
&& m->disk->dev->id == disk->dev->id && m->disk->dev->id == disk->dev->id
&& m->part_start == grub_partition_get_start (disk->partition) && m->part_start == grub_partition_get_start (disk->partition)
&& m->part_size == grub_disk_get_size (disk)) && m->part_size == grub_disk_native_sectors (disk))
return 0; return 0;
} }
@ -1190,13 +1190,13 @@ insert_array (grub_disk_t disk, const struct grub_diskfilter_pv_id *id,
grub_dprintf ("diskfilter", "Inserting %s (+%lld,%lld) into %s (%s)\n", disk->name, grub_dprintf ("diskfilter", "Inserting %s (+%lld,%lld) into %s (%s)\n", disk->name,
(unsigned long long) grub_partition_get_start (disk->partition), (unsigned long long) grub_partition_get_start (disk->partition),
(unsigned long long) grub_disk_get_size (disk), (unsigned long long) grub_disk_native_sectors (disk),
array->name, diskfilter->name); array->name, diskfilter->name);
#ifdef GRUB_UTIL #ifdef GRUB_UTIL
grub_util_info ("Inserting %s (+%" GRUB_HOST_PRIuLONG_LONG ",%" grub_util_info ("Inserting %s (+%" GRUB_HOST_PRIuLONG_LONG ",%"
GRUB_HOST_PRIuLONG_LONG ") into %s (%s)\n", disk->name, GRUB_HOST_PRIuLONG_LONG ") into %s (%s)\n", disk->name,
(unsigned long long) grub_partition_get_start (disk->partition), (unsigned long long) grub_partition_get_start (disk->partition),
(unsigned long long) grub_disk_get_size (disk), (unsigned long long) grub_disk_native_sectors (disk),
array->name, diskfilter->name); array->name, diskfilter->name);
array->driver = diskfilter; array->driver = diskfilter;
#endif #endif
@ -1210,7 +1210,7 @@ insert_array (grub_disk_t disk, const struct grub_diskfilter_pv_id *id,
struct grub_diskfilter_lv *lv; struct grub_diskfilter_lv *lv;
/* FIXME: Check whether the update time of the superblocks are /* FIXME: Check whether the update time of the superblocks are
the same. */ the same. */
if (pv->disk && grub_disk_get_size (disk) >= pv->part_size) if (pv->disk && grub_disk_native_sectors (disk) >= pv->part_size)
return GRUB_ERR_NONE; return GRUB_ERR_NONE;
pv->disk = grub_disk_open (disk->name); pv->disk = grub_disk_open (disk->name);
if (!pv->disk) if (!pv->disk)
@ -1219,7 +1219,7 @@ insert_array (grub_disk_t disk, const struct grub_diskfilter_pv_id *id,
raid device, we shouldn't change it. */ raid device, we shouldn't change it. */
pv->start_sector -= pv->part_start; pv->start_sector -= pv->part_start;
pv->part_start = grub_partition_get_start (disk->partition); pv->part_start = grub_partition_get_start (disk->partition);
pv->part_size = grub_disk_get_size (disk); pv->part_size = grub_disk_native_sectors (disk);
#ifdef GRUB_UTIL #ifdef GRUB_UTIL
{ {
@ -1311,7 +1311,7 @@ grub_diskfilter_get_pv_from_disk (grub_disk_t disk,
if (pv->disk && pv->disk->id == disk->id if (pv->disk && pv->disk->id == disk->id
&& pv->disk->dev->id == disk->dev->id && pv->disk->dev->id == disk->dev->id
&& pv->part_start == grub_partition_get_start (disk->partition) && pv->part_start == grub_partition_get_start (disk->partition)
&& pv->part_size == grub_disk_get_size (disk)) && pv->part_size == grub_disk_native_sectors (disk))
{ {
if (vg_out) if (vg_out)
*vg_out = vg; *vg_out = vg;

View File

@ -107,7 +107,7 @@ grub_dmraid_nv_detect (grub_disk_t disk,
/* Skip partition. */ /* Skip partition. */
return NULL; return NULL;
sector = grub_disk_get_size (disk); sector = grub_disk_native_sectors (disk);
if (sector == GRUB_DISK_SIZE_UNKNOWN) if (sector == GRUB_DISK_SIZE_UNKNOWN)
/* Not raid. */ /* Not raid. */
return NULL; return NULL;

View File

@ -867,7 +867,7 @@ grub_efidisk_get_device_name (grub_efi_handle_t *handle)
if (ctx.hd->partition_start == 0 if (ctx.hd->partition_start == 0
&& (ctx.hd->partition_size << (parent->log_sector_size && (ctx.hd->partition_size << (parent->log_sector_size
- GRUB_DISK_SECTOR_BITS)) - GRUB_DISK_SECTOR_BITS))
== grub_disk_get_size (parent)) == grub_disk_native_sectors (parent))
{ {
dev_name = grub_strdup (parent->name); dev_name = grub_strdup (parent->name);
} }

View File

@ -258,7 +258,7 @@ configure_ciphers (grub_disk_t disk, const char *check_uuid,
if (2 * GRUB_MD_SHA256->mdlen + 1 > GRUB_CRYPTODISK_MAX_UUID_LENGTH) if (2 * GRUB_MD_SHA256->mdlen + 1 > GRUB_CRYPTODISK_MAX_UUID_LENGTH)
return NULL; return NULL;
sector = grub_disk_get_size (disk); sector = grub_disk_native_sectors (disk);
if (sector == GRUB_DISK_SIZE_UNKNOWN || sector == 0) if (sector == GRUB_DISK_SIZE_UNKNOWN || sector == 0)
return NULL; return NULL;
@ -391,7 +391,7 @@ configure_ciphers (grub_disk_t disk, const char *check_uuid,
newdev->modname = "geli"; newdev->modname = "geli";
newdev->total_sectors = grub_disk_get_size (disk) - 1; newdev->total_sectors = grub_disk_native_sectors (disk) - 1;
grub_memcpy (newdev->uuid, uuid, sizeof (newdev->uuid)); grub_memcpy (newdev->uuid, uuid, sizeof (newdev->uuid));
COMPILE_TIME_ASSERT (sizeof (newdev->uuid) >= 32 * 2 + 1); COMPILE_TIME_ASSERT (sizeof (newdev->uuid) >= 32 * 2 + 1);
return newdev; return newdev;
@ -420,7 +420,7 @@ recover_key (grub_disk_t source, grub_cryptodisk_t dev)
if (dev->hash->mdlen > GRUB_CRYPTO_MAX_MDLEN) if (dev->hash->mdlen > GRUB_CRYPTO_MAX_MDLEN)
return grub_error (GRUB_ERR_BUG, "mdlen is too long"); return grub_error (GRUB_ERR_BUG, "mdlen is too long");
sector = grub_disk_get_size (source); sector = grub_disk_native_sectors (source);
if (sector == GRUB_DISK_SIZE_UNKNOWN || sector == 0) if (sector == GRUB_DISK_SIZE_UNKNOWN || sector == 0)
return grub_error (GRUB_ERR_BUG, "not a geli"); return grub_error (GRUB_ERR_BUG, "not a geli");

View File

@ -821,7 +821,7 @@ grub_ldm_detect (grub_disk_t disk,
/* LDM is never inside a partition. */ /* LDM is never inside a partition. */
if (!has_ldm || disk->partition) if (!has_ldm || disk->partition)
continue; continue;
sector = grub_disk_get_size (disk); sector = grub_disk_native_sectors (disk);
if (sector == GRUB_DISK_SIZE_UNKNOWN) if (sector == GRUB_DISK_SIZE_UNKNOWN)
continue; continue;
sector--; sector--;
@ -938,7 +938,7 @@ grub_util_is_ldm (grub_disk_t disk)
/* LDM is never inside a partition. */ /* LDM is never inside a partition. */
if (!has_ldm || disk->partition) if (!has_ldm || disk->partition)
continue; continue;
sector = grub_disk_get_size (disk); sector = grub_disk_native_sectors (disk);
if (sector == GRUB_DISK_SIZE_UNKNOWN) if (sector == GRUB_DISK_SIZE_UNKNOWN)
continue; continue;
sector--; sector--;

View File

@ -125,7 +125,7 @@ configure_ciphers (grub_disk_t disk, const char *check_uuid,
newdev->offset_sectors = grub_be_to_cpu32 (header.payloadOffset); newdev->offset_sectors = grub_be_to_cpu32 (header.payloadOffset);
newdev->source_disk = NULL; newdev->source_disk = NULL;
newdev->log_sector_size = 9; newdev->log_sector_size = 9;
newdev->total_sectors = grub_disk_get_size (disk) - newdev->offset_sectors; newdev->total_sectors = grub_disk_native_sectors (disk) - newdev->offset_sectors;
grub_memcpy (newdev->uuid, uuid, sizeof (uuid)); grub_memcpy (newdev->uuid, uuid, sizeof (uuid));
newdev->modname = "luks"; newdev->modname = "luks";

View File

@ -609,7 +609,7 @@ luks2_recover_key (grub_disk_t source,
crypt->log_sector_size = sizeof (unsigned int) * 8 crypt->log_sector_size = sizeof (unsigned int) * 8
- __builtin_clz ((unsigned int) segment.sector_size) - 1; - __builtin_clz ((unsigned int) segment.sector_size) - 1;
if (grub_strcmp (segment.size, "dynamic") == 0) if (grub_strcmp (segment.size, "dynamic") == 0)
crypt->total_sectors = grub_disk_get_size (source) - crypt->offset_sectors; crypt->total_sectors = grub_disk_native_sectors (source) - crypt->offset_sectors;
else else
crypt->total_sectors = grub_strtoull (segment.size, NULL, 10); crypt->total_sectors = grub_strtoull (segment.size, NULL, 10);

View File

@ -111,7 +111,7 @@ grub_mdraid_detect (grub_disk_t disk,
grub_uint64_t size; grub_uint64_t size;
grub_uint8_t minor_version; grub_uint8_t minor_version;
size = grub_disk_get_size (disk); size = grub_disk_native_sectors (disk);
/* Check for an 1.x superblock. /* Check for an 1.x superblock.
* It's always aligned to a 4K boundary * It's always aligned to a 4K boundary

View File

@ -190,7 +190,7 @@ grub_mdraid_detect (grub_disk_t disk,
struct grub_diskfilter_vg *ret; struct grub_diskfilter_vg *ret;
/* The sector where the mdraid 0.90 superblock is stored, if available. */ /* The sector where the mdraid 0.90 superblock is stored, if available. */
size = grub_disk_get_size (disk); size = grub_disk_native_sectors (disk);
if (size == GRUB_DISK_SIZE_UNKNOWN) if (size == GRUB_DISK_SIZE_UNKNOWN)
/* not 0.9x raid. */ /* not 0.9x raid. */
return NULL; return NULL;

View File

@ -148,16 +148,16 @@ grub_cbfs_mount (grub_disk_t disk)
grub_off_t header_off; grub_off_t header_off;
struct cbfs_header head; struct cbfs_header head;
if (grub_disk_get_size (disk) == GRUB_DISK_SIZE_UNKNOWN) if (grub_disk_native_sectors (disk) == GRUB_DISK_SIZE_UNKNOWN)
goto fail; goto fail;
if (grub_disk_read (disk, grub_disk_get_size (disk) - 1, if (grub_disk_read (disk, grub_disk_native_sectors (disk) - 1,
GRUB_DISK_SECTOR_SIZE - sizeof (ptr), GRUB_DISK_SECTOR_SIZE - sizeof (ptr),
sizeof (ptr), &ptr)) sizeof (ptr), &ptr))
goto fail; goto fail;
ptr = grub_cpu_to_le32 (ptr); ptr = grub_cpu_to_le32 (ptr);
header_off = (grub_disk_get_size (disk) << GRUB_DISK_SECTOR_BITS) header_off = (grub_disk_native_sectors (disk) << GRUB_DISK_SECTOR_BITS)
+ (grub_int32_t) ptr; + (grub_int32_t) ptr;
if (grub_disk_read (disk, 0, header_off, if (grub_disk_read (disk, 0, header_off,
@ -171,16 +171,16 @@ grub_cbfs_mount (grub_disk_t disk)
if (!data) if (!data)
goto fail; goto fail;
data->cbfs_start = (grub_disk_get_size (disk) << GRUB_DISK_SECTOR_BITS) data->cbfs_start = (grub_disk_native_sectors (disk) << GRUB_DISK_SECTOR_BITS)
- (grub_be_to_cpu32 (head.romsize) - grub_be_to_cpu32 (head.offset)); - (grub_be_to_cpu32 (head.romsize) - grub_be_to_cpu32 (head.offset));
data->cbfs_end = (grub_disk_get_size (disk) << GRUB_DISK_SECTOR_BITS) data->cbfs_end = (grub_disk_native_sectors (disk) << GRUB_DISK_SECTOR_BITS)
- grub_be_to_cpu32 (head.bootblocksize); - grub_be_to_cpu32 (head.bootblocksize);
data->cbfs_align = grub_be_to_cpu32 (head.align); data->cbfs_align = grub_be_to_cpu32 (head.align);
if (data->cbfs_start >= (grub_disk_get_size (disk) << GRUB_DISK_SECTOR_BITS)) if (data->cbfs_start >= (grub_disk_native_sectors (disk) << GRUB_DISK_SECTOR_BITS))
goto fail; goto fail;
if (data->cbfs_end > (grub_disk_get_size (disk) << GRUB_DISK_SECTOR_BITS)) if (data->cbfs_end > (grub_disk_native_sectors (disk) << GRUB_DISK_SECTOR_BITS))
data->cbfs_end = (grub_disk_get_size (disk) << GRUB_DISK_SECTOR_BITS); data->cbfs_end = (grub_disk_native_sectors (disk) << GRUB_DISK_SECTOR_BITS);
data->next_hofs = data->cbfs_start; data->next_hofs = data->cbfs_start;

View File

@ -753,7 +753,7 @@ grub_nilfs2_load_sb (struct grub_nilfs2_data *data)
partition_size = (grub_le_to_cpu64 (data->sblock.s_dev_size) partition_size = (grub_le_to_cpu64 (data->sblock.s_dev_size)
>> GRUB_DISK_SECTOR_BITS); >> GRUB_DISK_SECTOR_BITS);
else else
partition_size = grub_disk_get_size (disk); partition_size = grub_disk_native_sectors (disk);
if (partition_size != GRUB_DISK_SIZE_UNKNOWN) if (partition_size != GRUB_DISK_SIZE_UNKNOWN)
{ {
/* Read second super block. */ /* Read second super block. */

View File

@ -1175,7 +1175,7 @@ scan_disk (grub_device_t dev, struct grub_zfs_data *data,
desc.original = original; desc.original = original;
/* Don't check back labels on CDROM. */ /* Don't check back labels on CDROM. */
if (grub_disk_get_size (dev->disk) == GRUB_DISK_SIZE_UNKNOWN) if (grub_disk_native_sectors (dev->disk) == GRUB_DISK_SIZE_UNKNOWN)
vdevnum = VDEV_LABELS / 2; vdevnum = VDEV_LABELS / 2;
for (label = 0; ubbest == NULL && label < vdevnum; label++) for (label = 0; ubbest == NULL && label < vdevnum; label++)
@ -1184,7 +1184,7 @@ scan_disk (grub_device_t dev, struct grub_zfs_data *data,
= label * (sizeof (vdev_label_t) >> SPA_MINBLOCKSHIFT) = label * (sizeof (vdev_label_t) >> SPA_MINBLOCKSHIFT)
+ ((VDEV_SKIP_SIZE + VDEV_BOOT_HEADER_SIZE) >> SPA_MINBLOCKSHIFT) + ((VDEV_SKIP_SIZE + VDEV_BOOT_HEADER_SIZE) >> SPA_MINBLOCKSHIFT)
+ (label < VDEV_LABELS / 2 ? 0 : + (label < VDEV_LABELS / 2 ? 0 :
ALIGN_DOWN (grub_disk_get_size (dev->disk), sizeof (vdev_label_t)) ALIGN_DOWN (grub_disk_native_sectors (dev->disk), sizeof (vdev_label_t))
- VDEV_LABELS * (sizeof (vdev_label_t) >> SPA_MINBLOCKSHIFT)); - VDEV_LABELS * (sizeof (vdev_label_t) >> SPA_MINBLOCKSHIFT));
/* Read in the uberblock ring (128K). */ /* Read in the uberblock ring (128K). */

View File

@ -533,7 +533,7 @@ grub_disk_read (grub_disk_t disk, grub_disk_addr_t sector,
} }
grub_uint64_t grub_uint64_t
grub_disk_get_size (grub_disk_t disk) grub_disk_native_sectors (grub_disk_t disk)
{ {
if (disk->partition) if (disk->partition)
return grub_partition_get_len (disk->partition); return grub_partition_get_len (disk->partition);

View File

@ -430,7 +430,7 @@ grub_machine_get_bootlocation (char **device, char **path)
} }
if (poff == 0 if (poff == 0
&& pend == grub_disk_get_size (parent)) && pend == grub_disk_native_sectors (parent))
{ {
grub_disk_close (parent); grub_disk_close (parent);
*device = dname; *device = dname;

View File

@ -176,14 +176,14 @@ grub_normal_print_device_info (const char *name)
(grub_partition_get_start (dev->disk->partition) & 1) ? ".5" : "" ); (grub_partition_get_start (dev->disk->partition) & 1) ? ".5" : "" );
else else
grub_printf_ (N_(" - Sector size %uB"), 1 << dev->disk->log_sector_size); grub_printf_ (N_(" - Sector size %uB"), 1 << dev->disk->log_sector_size);
if (grub_disk_get_size (dev->disk) == GRUB_DISK_SIZE_UNKNOWN) if (grub_disk_native_sectors (dev->disk) == GRUB_DISK_SIZE_UNKNOWN)
grub_puts_ (N_(" - Total size unknown")); grub_puts_ (N_(" - Total size unknown"));
else else
grub_printf (_(" - Total size %llu%sKiB"), grub_printf (_(" - Total size %llu%sKiB"),
(unsigned long long) (grub_disk_get_size (dev->disk) >> 1), (unsigned long long) (grub_disk_native_sectors (dev->disk) >> 1),
/* TRANSLATORS: Replace dot with appropriate decimal separator for /* TRANSLATORS: Replace dot with appropriate decimal separator for
your language. */ your language. */
(grub_disk_get_size (dev->disk) & 1) ? _(".5") : ""); (grub_disk_native_sectors (dev->disk) & 1) ? _(".5") : "");
} }
if (dev) if (dev)

View File

@ -371,7 +371,7 @@ grub_install_register_efi (grub_device_t efidir_grub_dev,
hddp->partition_start = grub_partition_get_start (efidir_grub_dev->disk->partition) hddp->partition_start = grub_partition_get_start (efidir_grub_dev->disk->partition)
>> (efidir_grub_dev->disk->log_sector_size - GRUB_DISK_SECTOR_BITS); >> (efidir_grub_dev->disk->log_sector_size - GRUB_DISK_SECTOR_BITS);
hddp->partition_size = grub_disk_get_size (efidir_grub_dev->disk) hddp->partition_size = grub_disk_native_sectors (efidir_grub_dev->disk)
>> (efidir_grub_dev->disk->log_sector_size - GRUB_DISK_SECTOR_BITS); >> (efidir_grub_dev->disk->log_sector_size - GRUB_DISK_SECTOR_BITS);
pathptr = hddp + 1; pathptr = hddp + 1;

View File

@ -177,7 +177,7 @@ typedef struct grub_disk_memberlist *grub_disk_memberlist_t;
#define GRUB_DISK_MAX_MAX_AGGLOMERATE ((1 << (30 - GRUB_DISK_CACHE_BITS - GRUB_DISK_SECTOR_BITS)) - 1) #define GRUB_DISK_MAX_MAX_AGGLOMERATE ((1 << (30 - GRUB_DISK_CACHE_BITS - GRUB_DISK_SECTOR_BITS)) - 1)
/* Return value of grub_disk_get_size() in case disk size is unknown. */ /* Return value of grub_disk_native_sectors() in case disk size is unknown. */
#define GRUB_DISK_SIZE_UNKNOWN 0xffffffffffffffffULL #define GRUB_DISK_SIZE_UNKNOWN 0xffffffffffffffffULL
/* Convert to GRUB native disk sized sector from disk sized sector. */ /* Convert to GRUB native disk sized sector from disk sized sector. */
@ -225,7 +225,7 @@ extern grub_err_t (*EXPORT_VAR(grub_disk_write_weak)) (grub_disk_t disk,
const void *buf); const void *buf);
grub_uint64_t EXPORT_FUNC(grub_disk_get_size) (grub_disk_t disk); grub_uint64_t EXPORT_FUNC(grub_disk_native_sectors) (grub_disk_t disk);
#if DISK_CACHE_STATS #if DISK_CACHE_STATS
void void

View File

@ -748,7 +748,7 @@ is_prep_empty (grub_device_t dev)
grub_disk_addr_t dsize, addr; grub_disk_addr_t dsize, addr;
grub_uint32_t buffer[32768]; grub_uint32_t buffer[32768];
dsize = grub_disk_get_size (dev->disk); dsize = grub_disk_native_sectors (dev->disk);
for (addr = 0; addr < dsize; for (addr = 0; addr < dsize;
addr += sizeof (buffer) / GRUB_DISK_SECTOR_SIZE) addr += sizeof (buffer) / GRUB_DISK_SECTOR_SIZE)
{ {

View File

@ -398,7 +398,7 @@ probe (const char *path, char **device_names, char delim)
if (! dev || !dev->disk) if (! dev || !dev->disk)
grub_util_error ("%s", grub_errmsg); grub_util_error ("%s", grub_errmsg);
dsize = grub_disk_get_size (dev->disk); dsize = grub_disk_native_sectors (dev->disk);
for (addr = 0; addr < dsize; for (addr = 0; addr < dsize;
addr += sizeof (buffer) / GRUB_DISK_SECTOR_SIZE) addr += sizeof (buffer) / GRUB_DISK_SECTOR_SIZE)
{ {