From owner-svn-src-user@FreeBSD.ORG Tue Jun 26 11:00:34 2012 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id C5BC8106564A; Tue, 26 Jun 2012 11:00:34 +0000 (UTC) (envelope-from ae@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id B07F78FC0C; Tue, 26 Jun 2012 11:00:34 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.4/8.14.4) with ESMTP id q5QB0YGL036185; Tue, 26 Jun 2012 11:00:34 GMT (envelope-from ae@svn.freebsd.org) Received: (from ae@localhost) by svn.freebsd.org (8.14.4/8.14.4/Submit) id q5QB0YVL036182; Tue, 26 Jun 2012 11:00:34 GMT (envelope-from ae@svn.freebsd.org) Message-Id: <201206261100.q5QB0YVL036182@svn.freebsd.org> From: "Andrey V. Elsukov" Date: Tue, 26 Jun 2012 11:00:34 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r237598 - in user/ae/bootcode/sys/boot/userboot: . userboot X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 26 Jun 2012 11:00:34 -0000 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 #include - #include -#include - #include #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)); +}