From patchwork Thu Jun 18 14:08:41 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wolfgang Bumiller X-Patchwork-Id: 486490 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id C3E1E140327 for ; Fri, 19 Jun 2015 06:51:22 +1000 (AEST) Received: from localhost ([::1]:54877 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z5gmO-0001b1-TW for incoming@patchwork.ozlabs.org; Thu, 18 Jun 2015 16:51:20 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37618) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z5af5-0006Ue-QQ for qemu-devel@nongnu.org; Thu, 18 Jun 2015 10:19:30 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Z5aez-0005af-Pl for qemu-devel@nongnu.org; Thu, 18 Jun 2015 10:19:23 -0400 Received: from proxmox.maurer-it.com ([94.136.31.133]:47269) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z5aez-0005aD-Dz for qemu-devel@nongnu.org; Thu, 18 Jun 2015 10:19:17 -0400 Received: from proxmox.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox.maurer-it.com (Proxmox) with ESMTP id B68CCAD09D8; Thu, 18 Jun 2015 16:08:46 +0200 (CEST) From: Wolfgang Bumiller To: qemu-devel@nongnu.org Date: Thu, 18 Jun 2015 16:08:41 +0200 Message-Id: <1434636521-24426-1-git-send-email-w.bumiller@proxmox.com> X-Mailer: git-send-email 2.1.4 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 94.136.31.133 X-Mailman-Approved-At: Thu, 18 Jun 2015 16:50:40 -0400 Cc: Kevin Wolf , Stefan Hajnoczi Subject: [Qemu-devel] [PATCH] vvfat: add a label option X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Till now the vvfat filesystem's label was hardcoded to be "QEMU VVFAT", now you can pass a file.label=labelname option to the -drive to change it. Signed-off-by: Wolfgang Bumiller --- block/vvfat.c | 25 ++++++++++++++++++++++--- qapi/block-core.json | 3 ++- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/block/vvfat.c b/block/vvfat.c index e803589..d407e37 100644 --- a/block/vvfat.c +++ b/block/vvfat.c @@ -322,6 +322,7 @@ typedef struct BDRVVVFATState { int fat_type; /* 16 or 32 */ array_t fat,directory,mapping; + char volume_label[11]; unsigned int cluster_size; unsigned int sectors_per_cluster; @@ -859,7 +860,7 @@ static int init_directories(BDRVVVFATState* s, { direntry_t* entry=array_get_next(&(s->directory)); entry->attributes=0x28; /* archive | volume label */ - memcpy(entry->name, "QEMU VVFAT ", sizeof(entry->name)); + memcpy(entry->name, s->volume_label, sizeof(entry->name)); } /* Now build FAT, and write back information into directory */ @@ -968,7 +969,8 @@ static int init_directories(BDRVVVFATState* s, bootsector->u.fat16.signature=0x29; bootsector->u.fat16.id=cpu_to_le32(0xfabe1afd); - memcpy(bootsector->u.fat16.volume_label,"QEMU VVFAT ",11); + memcpy(bootsector->u.fat16.volume_label, s->volume_label, + sizeof(bootsector->u.fat16.volume_label)); memcpy(bootsector->fat_type,(s->fat_type==12?"FAT12 ":s->fat_type==16?"FAT16 ":"FAT32 "),8); bootsector->magic[0]=0x55; bootsector->magic[1]=0xaa; @@ -1008,6 +1010,11 @@ static QemuOptsList runtime_opts = { .help = "Create a floppy rather than a hard disk image", }, { + .name = "label", + .type = QEMU_OPT_STRING, + .help = "Use a partition label other than QEMU VVFAT", + }, + { .name = "rw", .type = QEMU_OPT_BOOL, .help = "Make the image writable", @@ -1069,7 +1076,7 @@ static int vvfat_open(BlockDriverState *bs, QDict *options, int flags, BDRVVVFATState *s = bs->opaque; int cyls, heads, secs; bool floppy; - const char *dirname; + const char *dirname, *label; QemuOpts *opts; Error *local_err = NULL; int ret; @@ -1096,6 +1103,18 @@ static int vvfat_open(BlockDriverState *bs, QDict *options, int flags, s->fat_type = qemu_opt_get_number(opts, "fat-type", 0); floppy = qemu_opt_get_bool(opts, "floppy", false); + memset(s->volume_label, ' ', sizeof(s->volume_label)); + label = qemu_opt_get(opts, "label"); + if (label) { + size_t label_length = strlen(label); + if (label_length > 11) { + error_setg(errp, "vvfat label cannot be longer than 11 bytes"); + ret = -EINVAL; + goto fail; + } + memcpy(s->volume_label, label, label_length); + } + if (floppy) { /* 1.44MB or 2.88MB floppy. 2.88MB can be FAT12 (default) or FAT16. */ if (!s->fat_type) { diff --git a/qapi/block-core.json b/qapi/block-core.json index afa9d3d..2a529b1 100644 --- a/qapi/block-core.json +++ b/qapi/block-core.json @@ -1453,13 +1453,14 @@ # @fat-type: #optional FAT type: 12, 16 or 32 # @floppy: #optional whether to export a floppy image (true) or # partitioned hard disk (false; default) +# @label: #optional override default label # @rw: #optional whether to allow write operations (default: false) # # Since: 1.7 ## { 'struct': 'BlockdevOptionsVVFAT', 'data': { 'dir': 'str', '*fat-type': 'int', '*floppy': 'bool', - '*rw': 'bool' } } + '*label': 'str', '*rw': 'bool' } } ## # @BlockdevOptionsGenericFormat