summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeremy Kerr <jk@ozlabs.org>2015-09-30 10:26:35 +0800
committerJeremy Kerr <jk@ozlabs.org>2015-09-30 13:23:49 +0800
commit9e0b6b31c9bb5ce3ad72756c918f02e6e909c737 (patch)
treed21f1ee1b153a6903bb2cd05e414cf87c5170f36
parent519d84fe21d48fe277ef5cc65d29839f86b4e1a0 (diff)
downloadpetitboot-9e0b6b31c9bb5ce3ad72756c918f02e6e909c737.zip
petitboot-9e0b6b31c9bb5ce3ad72756c918f02e6e909c737.tar.gz
discover/devmapper: Use explicit 64-bit types for sector counts
We currently have a bug where the return value from get_block_sectors may overflow an unsigned int, so we create a snapshot that is too small. This change uses uint64_t types for the sector counts. Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
-rw-r--r--discover/device-handler.h2
-rw-r--r--discover/devmapper.c24
2 files changed, 14 insertions, 12 deletions
diff --git a/discover/device-handler.h b/discover/device-handler.h
index 5877733..d18910a 100644
--- a/discover/device-handler.h
+++ b/discover/device-handler.h
@@ -65,7 +65,7 @@ struct ramdisk_device {
char *snapshot;
char *origin;
char *base;
- unsigned int sectors;
+ uint64_t sectors;
};
struct device_handler *device_handler_init(struct discover_server *server,
diff --git a/discover/devmapper.c b/discover/devmapper.c
index e2ef0b5..d3179f1 100644
--- a/discover/devmapper.c
+++ b/discover/devmapper.c
@@ -11,17 +11,17 @@
#define MERGE_INTERVAL_US 200000
struct target {
- long unsigned int start_sector;
- long unsigned int end_sector;
- char *ttype;
- char *params;
+ uint64_t start_sector;
+ uint64_t end_sector;
+ char *ttype;
+ char *params;
};
/* Return the number of sectors on a block device. Zero represents an error */
-static unsigned int get_block_sectors(struct discover_device *device)
+static uint64_t get_block_sectors(struct discover_device *device)
{
+ unsigned long long sectors;
const char *tmp;
- long unsigned int sectors;
tmp = discover_device_get_param(device, "ID_PART_ENTRY_SIZE");
if (!tmp) {
@@ -31,14 +31,14 @@ static unsigned int get_block_sectors(struct discover_device *device)
}
errno = 0;
- sectors = strtoul(tmp, NULL, 0);
+ sectors = strtoull(tmp, NULL, 0);
if (errno) {
pb_debug("Error reading sector count for %s: %s\n",
device->device_path, strerror(errno));
sectors = 0;
}
- return sectors;
+ return (uint64_t)sectors;
}
/*
@@ -60,7 +60,7 @@ static inline int set_cookie(struct dm_task *task, uint32_t *cookie)
static bool snapshot_merge_complete(const char *dm_name)
{
- long long unsigned int sectors, meta_sectors;
+ uint64_t sectors, meta_sectors;
char *params = NULL, *target_type = NULL;
uint64_t start, length;
struct dm_task *task;
@@ -97,14 +97,16 @@ static bool snapshot_merge_complete(const char *dm_name)
/* Merge is complete when metadata sectors are the only sectors
* allocated - see Documentation/device-mapper/snapshot.txt */
- n = sscanf(params, "%llu/%*u %llu", &sectors, &meta_sectors);
+ n = sscanf(params, "%" SCNu64 "/%*u %" SCNu64,
+ &sectors, &meta_sectors);
if (n != 2) {
pb_log("%s unexpected status: '%s'\n", dm_name, params);
goto out;
}
result = sectors == meta_sectors;
- pb_debug("%s merging; %llu sectors, %llu metadata sectors\n",
+ pb_debug("%s merging; %" PRIu64 " sectors, %" PRIu64
+ " metadata sectors\n",
dm_name, sectors, meta_sectors);
out:
OpenPOWER on IntegriCloud