]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libfdisk: don't use off_t in public API
authorKarel Zak <kzak@redhat.com>
Mon, 26 Jan 2015 11:12:30 +0000 (12:12 +0100)
committerKarel Zak <kzak@redhat.com>
Mon, 26 Jan 2015 11:26:00 +0000 (12:26 +0100)
It's better to use exact and explicitly defined types (e.g. uint64_t)
rather than something like off_t to make code more portable.

[reported with gcc (Ubuntu 4.4.3-4ubuntu5.1) 4.4.3)]

The patch also fixes one debug message.

Reported-by: Benno Schulenberg <bensberg@justemail.net>
Signed-off-by: Karel Zak <kzak@redhat.com>
disk-utils/fdisk.c
disk-utils/sfdisk.c
libfdisk/src/dos.c
libfdisk/src/fdiskP.h
libfdisk/src/gpt.c
libfdisk/src/label.c
libfdisk/src/libfdisk.h.in

index 6f20a310f51ec87ded3cbb99e364c0cdc15f0c7d..8807940eca1b7527e678700399373b05e0b0f239 100644 (file)
@@ -568,7 +568,7 @@ static void dump_buffer(off_t base, unsigned char *buf, size_t sz, int all)
 }
 
 static void dump_blkdev(struct fdisk_context *cxt, const char *name,
-                       off_t offset, size_t size, int all)
+                       uint64_t offset, size_t size, int all)
 {
        int fd = fdisk_get_devfd(cxt);
 
@@ -577,7 +577,7 @@ static void dump_blkdev(struct fdisk_context *cxt, const char *name,
 
        assert(fd >= 0);
 
-       if (lseek(fd, offset, SEEK_SET) == (off_t) -1)
+       if (lseek(fd, (off_t) offset, SEEK_SET) == (off_t) -1)
                fdisk_warn(cxt, _("cannot seek"));
        else {
                unsigned char *buf = xmalloc(size);
@@ -604,7 +604,7 @@ void dump_disklabel(struct fdisk_context *cxt)
        int all = !isatty(STDOUT_FILENO);
        int i = 0;
        const char *name = NULL;
-       off_t offset = 0;
+       uint64_t offset = 0;
        size_t size = 0;
 
        assert(cxt);
index eed9180abf8f3baca64f2fe63fbb8b4073880f59..f9f733b48ffa8623a4bd0a90ebd8bd8f0aeea03e 100644 (file)
@@ -225,7 +225,7 @@ static void backup_sectors(struct sfdisk *sf,
                           const char *tpl,
                           const char *name,
                           const char *devname,
-                          off_t offset, size_t size)
+                          uint64_t offset, size_t size)
 {
        char *fname;
        int fd, devfd;
@@ -239,7 +239,7 @@ static void backup_sectors(struct sfdisk *sf,
        if (fd < 0)
                goto fail;
 
-       if (lseek(devfd, offset, SEEK_SET) == (off_t) -1) {
+       if (lseek(devfd, (off_t) offset, SEEK_SET) == (off_t) -1) {
                fdisk_warn(sf->cxt, _("cannot seek %s"), devname);
                goto fail;
        } else {
@@ -269,7 +269,7 @@ static void backup_partition_table(struct sfdisk *sf, const char *devname)
 {
        const char *name;
        char *tpl;
-       off_t offset = 0;
+       uint64_t offset = 0;
        size_t size = 0;
        int i = 0;
 
index 2a067076e394788565fd6b1e83625224f8918baa..2cb11cb4a300e32dcf4189de74645b87081f5611 100644 (file)
@@ -1738,7 +1738,7 @@ done:
 }
 
 static int dos_locate_disklabel(struct fdisk_context *cxt, int n,
-               const char **name, off_t *offset, size_t *size)
+               const char **name, uint64_t *offset, size_t *size)
 {
        assert(cxt);
 
@@ -1760,7 +1760,7 @@ static int dos_locate_disklabel(struct fdisk_context *cxt, int n,
                        assert(pe->private_sectorbuffer);
 
                        *name = "EBR";
-                       *offset = pe->offset * cxt->sector_size;
+                       *offset = (uint64_t) pe->offset * cxt->sector_size;
                        *size = 512;
                } else
                        return 1;
index 59ab0c3393a7ca70f699ee4ce24d840934c08a4c..dc561f389c3388d5835f16a5bdd1016ffdd068a3 100644 (file)
@@ -185,7 +185,8 @@ struct fdisk_label_operations {
        /* list disklabel details */
        int (*list)(struct fdisk_context *cxt);
        /* returns offset and size of the 'n' part of the PT */
-       int (*locate)(struct fdisk_context *cxt, int n, const char **name, off_t *offset, size_t *size);
+       int (*locate)(struct fdisk_context *cxt, int n, const char **name,
+                     uint64_t *offset, size_t *size);
        /* reorder partitions */
        int (*reorder)(struct fdisk_context *cxt);
 
index 2f1fe2eaa84a25b822f370b5a73b28d3888783b4..e7b58f398307fbefa77a9359b48e856fc27c0f34 100644 (file)
@@ -927,7 +927,7 @@ invalid:
 
 
 static int gpt_locate_disklabel(struct fdisk_context *cxt, int n,
-               const char **name, off_t *offset, size_t *size)
+               const char **name, uint64_t *offset, size_t *size)
 {
        struct fdisk_gpt_label *gpt;
 
@@ -945,7 +945,7 @@ static int gpt_locate_disklabel(struct fdisk_context *cxt, int n,
                break;
        case 1:
                *name = _("GPT Header");
-               *offset = GPT_PRIMARY_PARTITION_TABLE_LBA * cxt->sector_size;
+               *offset = (uint64_t) GPT_PRIMARY_PARTITION_TABLE_LBA * cxt->sector_size;
                *size = sizeof(struct gpt_header);
                break;
        case 2:
index beff2e82736be21b18d084dc8200aa941933088d..717a8cd802a2b73ea74d0d01b4df3ea653d27a0b 100644 (file)
@@ -375,7 +375,7 @@ int fdisk_create_disklabel(struct fdisk_context *cxt, const char *name)
  * Returns: 0 on succes, <0 on error, 1 no more items.
  */
 int fdisk_locate_disklabel(struct fdisk_context *cxt, int n, const char **name,
-                          off_t *offset, size_t *size)
+                          uint64_t *offset, size_t *size)
 {
        if (!cxt || !cxt->label)
                return -EINVAL;
index d15d64f1c35196c465a52ef8eddf15c7628c89be..f13c3db5dc5f3ccdd4a823ed6d971f58a4e2491f 100644 (file)
@@ -282,7 +282,10 @@ extern int fdisk_write_disklabel(struct fdisk_context *cxt);
 extern int fdisk_verify_disklabel(struct fdisk_context *cxt);
 extern int fdisk_create_disklabel(struct fdisk_context *cxt, const char *name);
 extern int fdisk_list_disklabel(struct fdisk_context *cxt);
-extern int fdisk_locate_disklabel(struct fdisk_context *cxt, int n, const char **name, off_t *offset, size_t *size);
+extern int fdisk_locate_disklabel(struct fdisk_context *cxt, int n,
+                                 const char **name,
+                                 uint64_t *offset,
+                                 size_t *size);
 
 extern int fdisk_get_disklabel_id(struct fdisk_context *cxt, char **id);
 extern int fdisk_set_disklabel_id(struct fdisk_context *cxt);