From e6945f7ee62c48a1a3f528c18a59f75f56da08c6 Mon Sep 17 00:00:00 2001 From: tsoome Date: Wed, 1 Feb 2017 20:10:56 +0000 Subject: [PATCH] loader: disk/part api needs to use uint64_t offsets The disk_* and part_* api is using 64bit values for media size and offsets. However, the current api is using off_t type, which is signed 64-bit int. In this context the signed media size does not make any sense, and the offsets are used to mark absolute, not relative locations. Also, the data from GPT partition table and some other sources is already using uint64_t data type, so using signed off_t can cause sign issues. Reviewed by: imp Approved by: imp (mentor) Differential Revision: https://reviews.freebsd.org/D8710 --- sys/boot/common/disk.c | 12 ++++++------ sys/boot/common/disk.h | 10 +++++----- sys/boot/common/part.c | 2 +- sys/boot/common/part.h | 4 ++-- sys/boot/i386/libi386/biosdisk.c | 2 +- sys/boot/uboot/lib/disk.c | 2 +- sys/boot/usb/storage/umass_loader.c | 8 ++++---- sys/boot/zfs/zfs.c | 2 +- 8 files changed, 21 insertions(+), 21 deletions(-) diff --git a/sys/boot/common/disk.c b/sys/boot/common/disk.c index feb0b9d7732a..e64afa973196 100644 --- a/sys/boot/common/disk.c +++ b/sys/boot/common/disk.c @@ -45,7 +45,7 @@ __FBSDID("$FreeBSD$"); struct open_disk { struct ptable *table; - off_t mediasize; + uint64_t mediasize; u_int sectorsize; u_int flags; int rcnt; @@ -64,7 +64,7 @@ struct dentry { int d_partition; struct open_disk *od; - off_t d_offset; + uint64_t d_offset; STAILQ_ENTRY(dentry) entry; #ifdef DISK_DEBUG uint32_t count; @@ -171,7 +171,7 @@ display_size(uint64_t size, u_int sectorsize) } int -ptblread(void *d, void *buf, size_t blocks, off_t offset) +ptblread(void *d, void *buf, size_t blocks, uint64_t offset) { struct disk_devdesc *dev; struct open_disk *od; @@ -238,7 +238,7 @@ disk_print(struct disk_devdesc *dev, char *prefix, int verbose) } int -disk_read(struct disk_devdesc *dev, void *buf, off_t offset, u_int blocks) +disk_read(struct disk_devdesc *dev, void *buf, uint64_t offset, u_int blocks) { struct open_disk *od; int ret; @@ -251,7 +251,7 @@ disk_read(struct disk_devdesc *dev, void *buf, off_t offset, u_int blocks) } int -disk_write(struct disk_devdesc *dev, void *buf, off_t offset, u_int blocks) +disk_write(struct disk_devdesc *dev, void *buf, uint64_t offset, u_int blocks) { struct open_disk *od; int ret; @@ -274,7 +274,7 @@ disk_ioctl(struct disk_devdesc *dev, u_long cmd, void *buf) } int -disk_open(struct disk_devdesc *dev, off_t mediasize, u_int sectorsize, +disk_open(struct disk_devdesc *dev, uint64_t mediasize, u_int sectorsize, u_int flags) { struct open_disk *od; diff --git a/sys/boot/common/disk.h b/sys/boot/common/disk.h index d17ace93f0b3..632cbdc460cb 100644 --- a/sys/boot/common/disk.h +++ b/sys/boot/common/disk.h @@ -86,7 +86,7 @@ struct disk_devdesc void *d_opendata; int d_slice; int d_partition; - off_t d_offset; + uint64_t d_offset; }; enum disk_ioctl { @@ -97,17 +97,17 @@ enum disk_ioctl { /* * Parse disk metadata and initialise dev->d_offset. */ -extern int disk_open(struct disk_devdesc *dev, off_t mediasize, +extern int disk_open(struct disk_devdesc *dev, uint64_t mediasize, u_int sectorsize, u_int flags); #define DISK_F_NOCACHE 0x0001 /* Do not use metadata caching */ extern int disk_close(struct disk_devdesc *dev); extern void disk_cleanup(const struct devsw *d_dev); extern int disk_ioctl(struct disk_devdesc *dev, u_long cmd, void *buf); -extern int disk_read(struct disk_devdesc *dev, void *buf, off_t offset, +extern int disk_read(struct disk_devdesc *dev, void *buf, uint64_t offset, u_int blocks); -extern int disk_write(struct disk_devdesc *dev, void *buf, off_t offset, +extern int disk_write(struct disk_devdesc *dev, void *buf, uint64_t offset, u_int blocks); -extern int ptblread(void *d, void *buf, size_t blocks, off_t offset); +extern int ptblread(void *d, void *buf, size_t blocks, uint64_t offset); /* * Print information about slices on a disk. diff --git a/sys/boot/common/part.c b/sys/boot/common/part.c index a5f76912d386..d26bccf1cc68 100644 --- a/sys/boot/common/part.c +++ b/sys/boot/common/part.c @@ -584,7 +584,7 @@ out: #endif /* LOADER_VTOC8_SUPPORT */ struct ptable* -ptable_open(void *dev, off_t sectors, uint16_t sectorsize, +ptable_open(void *dev, uint64_t sectors, uint16_t sectorsize, diskread_t *dread) { struct dos_partition *dp; diff --git a/sys/boot/common/part.h b/sys/boot/common/part.h index 217bf3b55121..11ca0632d10d 100644 --- a/sys/boot/common/part.h +++ b/sys/boot/common/part.h @@ -62,11 +62,11 @@ struct ptable_entry { }; /* The offset and size are in sectors */ -typedef int (diskread_t)(void *arg, void *buf, size_t blocks, off_t offset); +typedef int (diskread_t)(void *arg, void *buf, size_t blocks, uint64_t offset); typedef int (ptable_iterate_t)(void *arg, const char *partname, const struct ptable_entry *part); -struct ptable *ptable_open(void *dev, off_t sectors, uint16_t sectorsize, +struct ptable *ptable_open(void *dev, uint64_t sectors, uint16_t sectorsize, diskread_t *dread); void ptable_close(struct ptable *table); enum ptable_type ptable_gettype(const struct ptable *table); diff --git a/sys/boot/i386/libi386/biosdisk.c b/sys/boot/i386/libi386/biosdisk.c index 2081d06b0404..b9fc0dd5c06b 100644 --- a/sys/boot/i386/libi386/biosdisk.c +++ b/sys/boot/i386/libi386/biosdisk.c @@ -493,7 +493,7 @@ bd_ioctl(struct open_file *f, u_long cmd, void *data) *(u_int *)data = BD(dev).bd_sectorsize; break; case DIOCGMEDIASIZE: - *(off_t *)data = BD(dev).bd_sectors * BD(dev).bd_sectorsize; + *(uint64_t *)data = BD(dev).bd_sectors * BD(dev).bd_sectorsize; break; default: return (ENOTTY); diff --git a/sys/boot/uboot/lib/disk.c b/sys/boot/uboot/lib/disk.c index f5092f6c1d50..31ebdb40fc67 100644 --- a/sys/boot/uboot/lib/disk.c +++ b/sys/boot/uboot/lib/disk.c @@ -282,7 +282,7 @@ stor_ioctl(struct open_file *f, u_long cmd, void *data) *(u_int *)data = SI(dev).bsize; break; case DIOCGMEDIASIZE: - *(off_t *)data = SI(dev).bsize * SI(dev).blocks; + *(uint64_t *)data = SI(dev).bsize * SI(dev).blocks; break; default: return (ENOTTY); diff --git a/sys/boot/usb/storage/umass_loader.c b/sys/boot/usb/storage/umass_loader.c index efbd914a5792..d8c09dd36f32 100644 --- a/sys/boot/usb/storage/umass_loader.c +++ b/sys/boot/usb/storage/umass_loader.c @@ -143,14 +143,14 @@ umass_disk_ioctl(struct open_file *f __unused, u_long cmd, void *buf) uint32_t blocksize; switch (cmd) { - case IOCTL_GET_BLOCK_SIZE: - case IOCTL_GET_BLOCKS: + case DIOCGSECTORSIZE: + case DIOCGMEDIASIZE: if (usb_msc_read_capacity(umass_uaa.device, 0, &nblock, &blocksize) != 0) return (EINVAL); - if (cmd == IOCTL_GET_BLOCKS) - *(uint32_t*)buf = nblock; + if (cmd == DIOCGMEDIASIZE) + *(uint64_t*)buf = nblock; else *(uint32_t*)buf = blocksize; diff --git a/sys/boot/zfs/zfs.c b/sys/boot/zfs/zfs.c index 67f47bc2854e..78823a5f53f5 100644 --- a/sys/boot/zfs/zfs.c +++ b/sys/boot/zfs/zfs.c @@ -417,7 +417,7 @@ struct zfs_probe_args { }; static int -zfs_diskread(void *arg, void *buf, size_t blocks, off_t offset) +zfs_diskread(void *arg, void *buf, size_t blocks, uint64_t offset) { struct zfs_probe_args *ppa;