Received: from eggs.gnu.org ([208.118.235.92]:54454) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UVnFH-0007qS-On for qemu-devel@nongnu.org; Fri, 26 Apr 2013 14:19:51 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UVnFA-0004E0-Ph for qemu-devel@nongnu.org; Fri, 26 Apr 2013 14:19:43 -0400 From: Alexander Graf Date: Fri, 26 Apr 2013 20:19:30 +0200 Message-Id: <1367000373-7972-22-git-send-email-agraf@suse.de> In-Reply-To: <1367000373-7972-1-git-send-email-agraf@suse.de> References: <1367000373-7972-1-git-send-email-agraf@suse.de> Subject: [Qemu-devel] [PATCH 21/24] Common: Add quick access to first boot device List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-ppc@nongnu.org Cc: Blue Swirl , Dominik Dingel , qemu-devel@nongnu.org, Aurelien Jarno From: Dominik Dingel Instead of manually parsing the boot_list as character stream, we can access the nth boot device, specified by the position in the boot order. Signed-off-by: Dominik Dingel Reviewed-by: Anthony Liguori Signed-off-by: Alexander Graf --- include/sysemu/sysemu.h | 2 ++ vl.c | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+), 0 deletions(-) diff --git a/include/sysemu/sysemu.h b/include/sysemu/sysemu.h index 6578782..43b961c 100644 --- a/include/sysemu/sysemu.h +++ b/include/sysemu/sysemu.h @@ -181,6 +181,8 @@ void add_boot_device_path(int32_t bootindex, DeviceState *dev, const char *suffix); char *get_boot_devices_list(size_t *size); +DeviceState *get_boot_device(uint32_t position); + bool usb_enabled(bool default_usb); extern QemuOptsList qemu_drive_opts; diff --git a/vl.c b/vl.c index 2e0d1a7..322ea80 100644 --- a/vl.c +++ b/vl.c @@ -1222,6 +1222,24 @@ void add_boot_device_path(int32_t bootindex, DeviceState *dev, QTAILQ_INSERT_TAIL(&fw_boot_order, node, link); } +DeviceState *get_boot_device(uint32_t position) +{ + uint32_t counter = 0; + FWBootEntry *i = NULL; + DeviceState *res = NULL; + + if (!QTAILQ_EMPTY(&fw_boot_order)) { + QTAILQ_FOREACH(i, &fw_boot_order, link) { + if (counter == position) { + res = i->dev; + break; + } + counter++; + } + } + return res; +} + /* * This function returns null terminated string that consist of new line * separated device paths. -- 1.6.0.2