From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([140.186.70.92]:46112) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Qvib9-0004j5-M3 for qemu-devel@nongnu.org; Tue, 23 Aug 2011 00:28:25 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Qvib8-0007WC-2L for qemu-devel@nongnu.org; Tue, 23 Aug 2011 00:28:23 -0400 Received: from mail-yx0-f173.google.com ([209.85.213.173]:42417) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Qvib7-0007Se-EU for qemu-devel@nongnu.org; Tue, 23 Aug 2011 00:28:21 -0400 Received: by mail-yx0-f173.google.com with SMTP id 3so4715948yxt.4 for ; Mon, 22 Aug 2011 21:28:21 -0700 (PDT) From: Devin Nakamura Date: Tue, 23 Aug 2011 00:27:43 -0400 Message-Id: <1314073663-32691-8-git-send-email-devin122@gmail.com> In-Reply-To: <1314073663-32691-1-git-send-email-devin122@gmail.com> References: <1314073663-32691-1-git-send-email-devin122@gmail.com> Subject: [Qemu-devel] [PATCH V4 7/7] block: add bdrv_copy_header() List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: kwolf@redhat.com, Devin Nakamura Signed-off-by: Devin Nakamura --- block.c | 41 +++++++++++++++++++++++++++++++++++++++++ block.h | 2 ++ 2 files changed, 43 insertions(+), 0 deletions(-) diff --git a/block.c b/block.c index aff1d34..76bd2e9 100644 --- a/block.c +++ b/block.c @@ -3349,3 +3349,44 @@ int bdrv_map(BlockDriverState *bs, uint64_t guest_offset, return drv->bdrv_map(bs, guest_offset, host_offset, contiguous_bytes); } + +/** + * Copies out the header of a conversion target + * + * Saves the current header for the image in a temporary file and overwrites + * it with the header for the new format (at the moment the header is + * assumed to be 1 sector) + * + * A filename can be specified by using filename. On entry if + * filename = NULL , or filename points to an empty string, a random file + * name will be generated. + * + * If a random filename was generated it will be returned to the user by + * copying it to the location pointed at by filename. Filename must already + * be allocated to a size of at least PATH_MAX + * + * @param bs Usualy opened with bdrv_open_conversion_target() + * @param filename[in,out] On entry is the optional filename to be used. On + * exit it will be the filename used (assuming + * filename != NULL at entry) + * @return Returns non-zero on failure + */ +int bdrv_copy_header(BlockDriverState *bs, char *filename) +{ + BlockDriver *drv = bs->drv; + char tmp_filename[PATH_MAX] = ""; + + if (!drv) { + return -ENOMEDIUM; + } + if (!drv->bdrv_copy_header) { + return -ENOTSUP; + } + if (!filename) { + filename = tmp_filename; + } + if (!filename[0]) { + get_tmp_filename(filename, PATH_MAX); + } + return drv->bdrv_copy_header(bs, filename); +} diff --git a/block.h b/block.h index 558b9b8..2fc546a 100644 --- a/block.h +++ b/block.h @@ -268,6 +268,8 @@ int bdrv_get_mapping(BlockDriverState *bs, uint64_t guest_offset, uint64_t *host_offset, uint64_t *contiguous_bytes); int bdrv_map(BlockDriverState *bs, uint64_t guest_offset, uint64_t host_offset, uint64_t contiguous_bytes); +int bdrv_copy_header(BlockDriverState *bs, char *filename); + typedef enum { BLKDBG_L1_UPDATE, -- 1.7.6.rc1