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
This commit is contained in:
parent
5354226f97
commit
e6945f7ee6
@ -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;
|
||||
|
@ -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.
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user