Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F173767681
D59253.id187134.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
1 KB
Referenced Files
None
Subscribers
None
D59253.id187134.diff
View Options
diff --git a/usr.sbin/bhyveload/bhyveload.c b/usr.sbin/bhyveload/bhyveload.c
--- a/usr.sbin/bhyveload/bhyveload.c
+++ b/usr.sbin/bhyveload/bhyveload.c
@@ -101,6 +101,7 @@
static struct termios term, oldterm;
static int disk_fd[NDISKS];
+static int disk_sectsz[NDISKS];
static int ndisks;
static int consin_fd, consout_fd;
static int hostbase_fd = -1;
@@ -360,7 +361,7 @@
switch (cmd) {
case DIOCGSECTORSIZE:
- *(u_int *)data = 512;
+ *(u_int *)data = disk_sectsz[unit];
break;
case DIOCGMEDIASIZE:
if (fstat(disk_fd[unit], &sb) != 0)
@@ -714,7 +715,9 @@
static int
disk_open(char *path)
{
- int fd;
+ struct stat sbuf;
+ off_t size;
+ int fd, ret, sectsz;
if (ndisks >= NDISKS)
return (ERANGE);
@@ -724,11 +727,31 @@
fd = open(path, O_RDONLY);
if (fd < 0)
return (errno);
+ if (fstat(fd, &sbuf) < 0) {
+ ret = errno;
+ goto err;
+ }
+
+ size = sbuf.st_size;
+ sectsz = DEV_BSIZE;
+ if (S_ISCHR(sbuf.st_mode)) {
+ if (ioctl(fd, DIOCGMEDIASIZE, &size) < 0 ||
+ ioctl(fd, DIOCGSECTORSIZE, §sz) < 0) {
+ ret = errno;
+ goto err;
+ }
+ assert(size != 0);
+ assert(sectsz != 0);
+ }
disk_fd[ndisks] = fd;
+ disk_sectsz[ndisks] = sectsz;
ndisks++;
return (0);
+err:
+ close(fd);
+ return (ret);
}
static void
@@ -812,7 +835,7 @@
case 'd':
error = disk_open(optarg);
if (error != 0)
- errx(EX_USAGE, "Could not open '%s'", optarg);
+ errc(EX_USAGE, error, "Could not open '%s'", optarg);
break;
case 'e':
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Tue, Sep 29, 6:25 AM (12 h, 24 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
39240924
Default Alt Text
D59253.id187134.diff (1 KB)
Attached To
Mode
D59253: bhyveload: validate character disk devices
Attached
Detach File
Event Timeline
Log In to Comment