Date: Tue, 26 Jun 2012 11:00:34 +0000 (UTC) From: "Andrey V. Elsukov" <ae@FreeBSD.org> To: src-committers@freebsd.org, svn-src-user@freebsd.org Subject: svn commit: r237598 - in user/ae/bootcode/sys/boot/userboot: . userboot Message-ID: <201206261100.q5QB0YVL036182@svn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: ae Date: Tue Jun 26 11:00:34 2012 New Revision: 237598 URL: http://svn.freebsd.org/changeset/base/237598 Log: Add diskioctl method to the loader_callbacks_v1 structure. It is used to know the disk image and sector size. Also implement this functional in the userboot_disk.c and modify disk_open() call. Modified: user/ae/bootcode/sys/boot/userboot/userboot.h user/ae/bootcode/sys/boot/userboot/userboot/userboot_disk.c Modified: user/ae/bootcode/sys/boot/userboot/userboot.h ============================================================================== --- user/ae/bootcode/sys/boot/userboot/userboot.h Tue Jun 26 10:55:01 2012 (r237597) +++ user/ae/bootcode/sys/boot/userboot/userboot.h Tue Jun 26 11:00:34 2012 (r237598) @@ -175,4 +175,9 @@ struct loader_callbacks_v1 { */ void (*getmem)(void *arg, uint64_t *lowmem, uint64_t *highmem); + /* + * ioctl interface to the disk device + */ + int (*diskioctl)(void *arg, int unit, u_long cmd, + void *data); }; Modified: user/ae/bootcode/sys/boot/userboot/userboot/userboot_disk.c ============================================================================== --- user/ae/bootcode/sys/boot/userboot/userboot/userboot_disk.c Tue Jun 26 10:55:01 2012 (r237597) +++ user/ae/bootcode/sys/boot/userboot/userboot/userboot_disk.c Tue Jun 26 11:00:34 2012 (r237598) @@ -31,11 +31,9 @@ __FBSDID("$FreeBSD$"); * Userboot disk image handling. */ +#include <sys/disk.h> #include <stand.h> - #include <stdarg.h> -#include <uuid.h> - #include <bootstrap.h> #include "disk.h" @@ -48,6 +46,7 @@ static int userdisk_strategy(void *devda size_t size, char *buf, size_t *rsize); static int userdisk_open(struct open_file *f, ...); static int userdisk_close(struct open_file *f); +static int userdisk_ioctl(struct open_file *f, u_long cmd, void *data); static void userdisk_print(int verbose); struct devsw userboot_disk = { @@ -57,7 +56,7 @@ struct devsw userboot_disk = { userdisk_strategy, userdisk_open, userdisk_close, - noioctl, + userdisk_ioctl, userdisk_print, NULL }; @@ -78,20 +77,27 @@ userdisk_init(void) static void userdisk_print(int verbose) { - int i; - char line[80]; - struct disk_devdesc dev; + struct disk_devdesc dev; + char line[80]; + off_t mediasize; + u_int sectorsize; + int i; for (i = 0; i < userboot_disk_maxunit; i++) { sprintf(line, " disk%d: Guest drive image\n", i); pager_output(line); + if (CALLBACK(diskioctl, i, DIOCGSECTORSIZE, §orsize) != 0 || + CALLBACK(diskioctl, i, DIOCGMEDIASIZE, &mediasize) != 0) + continue; dev.d_dev = &userboot_disk; dev.d_unit = i; dev.d_slice = -1; dev.d_partition = -1; - dev.d_offset = 0; - sprintf(line, " disk%d", i); - disk_print(&dev, line, verbose); + if (disk_open(&dev, mediasize, sectorsize) == 0) { + sprintf(line, " disk%d", i); + disk_print(&dev, line, verbose); + disk_close(&dev); + } } } @@ -103,6 +109,9 @@ userdisk_open(struct open_file *f, ...) { va_list ap; struct disk_devdesc *dev; + u_int sectorsize; + off_t mediasize; + int rc; va_start(ap, f); dev = va_arg(ap, struct disk_devdesc *); @@ -111,7 +120,13 @@ userdisk_open(struct open_file *f, ...) if (dev->d_unit < 0 || dev->d_unit >= userboot_disk_maxunit) return (EIO); - return (disk_open(dev)); + rc = CALLBACK(diskioctl, dev->d_unit, DIOCGSECTORSIZE, §orsize); + if (rc != 0) + return (rc); + rc = CALLBACK(diskioctl, dev->d_unit, DIOCGMEDIASIZE, &mediasize); + if (rc != 0) + return (rc); + return (disk_open(dev, mediasize, sectorsize)); } static int @@ -144,3 +159,12 @@ userdisk_strategy(void *devdata, int rw, *rsize = size - resid; return (0); } + +static int +userdisk_ioctl(struct open_file *f, u_long cmd, void *data) +{ + struct disk_devdesc *dev; + + dev = (struct disk_devdesc *)f->f_devdata; + return (CALLBACK(diskioctl, dev->d_unit, cmd, data)); +}
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201206261100.q5QB0YVL036182>