]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libfdisk: (gpt) fix last LBA code for S_ISREG
authorKarel Zak <kzak@redhat.com>
Fri, 30 May 2014 08:51:53 +0000 (10:51 +0200)
committerKarel Zak <kzak@redhat.com>
Fri, 30 May 2014 08:51:53 +0000 (10:51 +0200)
Reported-by: Ruediger Meier <sweet_f_a@gmx.de>
Signed-off-by: Karel Zak <kzak@redhat.com>
libfdisk/src/gpt.c

index 2026c538fd80e984a894ec60bac0e7dcfccaac86..1ee1b49a2338374d18e8e06d236c8b5cc8b1e72e 100644 (file)
@@ -604,6 +604,7 @@ done:
 static uint64_t last_lba(struct fdisk_context *cxt)
 {
        struct stat s;
+       uint64_t sectors = 0;
 
        memset(&s, 0, sizeof(s));
        if (fstat(cxt->dev_fd, &s) == -1) {
@@ -612,13 +613,15 @@ static uint64_t last_lba(struct fdisk_context *cxt)
        }
 
        if (S_ISBLK(s.st_mode))
-               return cxt->total_sectors - 1;
-       else if (S_ISREG(s.st_mode)) {
-               uint64_t sectors = s.st_size >> cxt->sector_size;
-               return (sectors / cxt->sector_size) - 1ULL;
-       else
+               sectors = cxt->total_sectors - 1;
+       else if (S_ISREG(s.st_mode))
+               sectors = ((uint64_t) s.st_size /
+                          (uint64_t) cxt->sector_size) - 1ULL;
+       else
                fdisk_warnx(cxt, _("gpt: cannot handle files with mode %o"), s.st_mode);
-       return 0;
+
+       DBG(LABEL, ul_debug("GPT last LBA: %ju", sectors));
+       return sectors;
 }
 
 static ssize_t read_lba(struct fdisk_context *cxt, uint64_t lba,