summaryrefslogtreecommitdiffstats
path: root/fdisk/utils.c
diff options
context:
space:
mode:
authorDavidlohr Bueso2012-06-03 20:15:20 +0200
committerKarel Zak2012-06-06 10:40:40 +0200
commit618882d6095a2c11876e800fef1ff442d60605f5 (patch)
tree1c4e98f4f9ffac576f88b838591ee9ab024c9409 /fdisk/utils.c
parentfdisk: add device topology to the API (diff)
downloadkernel-qcow2-util-linux-618882d6095a2c11876e800fef1ff442d60605f5.tar.gz
kernel-qcow2-util-linux-618882d6095a2c11876e800fef1ff442d60605f5.tar.xz
kernel-qcow2-util-linux-618882d6095a2c11876e800fef1ff442d60605f5.zip
fdisk: add total sectors
Add the total_sectors variable to the context structure. This is the initial geometry information. Signed-off-by: Davidlohr Bueso <dave@gnu.org>
Diffstat (limited to 'fdisk/utils.c')
-rw-r--r--fdisk/utils.c12
1 files changed, 12 insertions, 0 deletions
diff --git a/fdisk/utils.c b/fdisk/utils.c
index 5de4cab02..3162c7054 100644
--- a/fdisk/utils.c
+++ b/fdisk/utils.c
@@ -40,6 +40,16 @@ static unsigned long __get_sector_size(int fd)
return DEFAULT_SECTOR_SIZE;
}
+static int __discover_geometry(struct fdisk_context *cxt)
+{
+ sector_t nsects;
+
+ /* get number of 512-byte sectors, and convert it the real sectors */
+ if (!blkdev_get_sectors(cxt->dev_fd, &nsects))
+ cxt->total_sectors = (nsects / (cxt->sector_size >> 9));
+ return 0;
+}
+
static int __discover_topology(struct fdisk_context *cxt)
{
#ifdef HAVE_LIBBLKID
@@ -151,7 +161,9 @@ struct fdisk_context *fdisk_new_context_from_filename(const char *fname, int rea
cxt->dev_path = strdup(fname);
if (!cxt->dev_path)
goto fail;
+
__discover_topology(cxt);
+ __discover_geometry(cxt);
DBG(CONTEXT, dbgprint("context initialized for %s [%s]",
fname, readonly ? "READ-ONLY" : "READ-WRITE"));