]> git.proxmox.com Git - pve-qemu-kvm.git/blob - debian/patches/0001-vvfat-add-a-label-option.patch
qemu : add drive-mirror sleep patches
[pve-qemu-kvm.git] / debian / patches / 0001-vvfat-add-a-label-option.patch
1 From 9c13522262d0acadeb3014f4cbc0a508c93fc629 Mon Sep 17 00:00:00 2001
2 From: Wolfgang Bumiller <w.bumiller@proxmox.com>
3 Date: Thu, 18 Jun 2015 11:36:49 +0200
4 Subject: [PATCH] vvfat: add a label option
5
6 Till now the vvfat filesystem's label was hardcoded to be
7 "QEMU VVFAT", now you can pass a file.label=labelname option
8 to the -drive to change it.
9
10 Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
11 ---
12 block/vvfat.c | 28 ++++++++++++++++++++++++++--
13 qapi/block-core.json | 3 ++-
14 2 files changed, 28 insertions(+), 3 deletions(-)
15
16 diff --git a/block/vvfat.c b/block/vvfat.c
17 index 9be632f..0ffd1b4 100644
18 --- a/block/vvfat.c
19 +++ b/block/vvfat.c
20 @@ -322,6 +322,7 @@ typedef struct BDRVVVFATState {
21
22 int fat_type; /* 16 or 32 */
23 array_t fat,directory,mapping;
24 + char *volume_label;
25
26 unsigned int cluster_size;
27 unsigned int sectors_per_cluster;
28 @@ -836,6 +837,7 @@ static int init_directories(BDRVVVFATState* s,
29 mapping_t* mapping;
30 unsigned int i;
31 unsigned int cluster;
32 + size_t label_length;
33
34 memset(&(s->first_sectors[0]),0,0x40*0x200);
35
36 @@ -859,7 +861,17 @@ static int init_directories(BDRVVVFATState* s,
37 {
38 direntry_t* entry=array_get_next(&(s->directory));
39 entry->attributes=0x28; /* archive | volume label */
40 - memcpy(entry->name, "QEMU VVFAT ", sizeof(entry->name));
41 + if (!s->volume_label) {
42 + memcpy(entry->name, "QEMU VVFAT ", sizeof(entry->name));
43 + } else {
44 + label_length = strlen(s->volume_label);
45 + if (label_length > sizeof(entry->name)) {
46 + error_setg(errp, "vvfat label cannot be longer than 11 bytes");
47 + return -EINVAL;
48 + }
49 + memcpy(entry->name, s->volume_label, label_length);
50 + memset(entry->name + label_length, ' ', sizeof(entry->name)-label_length);
51 + }
52 }
53
54 /* Now build FAT, and write back information into directory */
55 @@ -968,7 +980,12 @@ static int init_directories(BDRVVVFATState* s,
56 bootsector->u.fat16.signature=0x29;
57 bootsector->u.fat16.id=cpu_to_le32(0xfabe1afd);
58
59 - memcpy(bootsector->u.fat16.volume_label,"QEMU VVFAT ",11);
60 + if (!s->volume_label) {
61 + memcpy(bootsector->u.fat16.volume_label,"QEMU VVFAT ",11);
62 + } else {
63 + memcpy(bootsector->u.fat16.volume_label, s->volume_label, label_length);
64 + memset(bootsector->u.fat16.volume_label + label_length, ' ', 11-label_length);
65 + }
66 memcpy(bootsector->fat_type,(s->fat_type==12?"FAT12 ":s->fat_type==16?"FAT16 ":"FAT32 "),8);
67 bootsector->magic[0]=0x55; bootsector->magic[1]=0xaa;
68
69 @@ -1008,6 +1025,11 @@ static QemuOptsList runtime_opts = {
70 .help = "Create a floppy rather than a hard disk image",
71 },
72 {
73 + .name = "label",
74 + .type = QEMU_OPT_STRING,
75 + .help = "Use a partition label other than QEMU VVFAT",
76 + },
77 + {
78 .name = "rw",
79 .type = QEMU_OPT_BOOL,
80 .help = "Make the image writable",
81 @@ -1095,6 +1117,7 @@ static int vvfat_open(BlockDriverState *bs, QDict *options, int flags,
82
83 s->fat_type = qemu_opt_get_number(opts, "fat-type", 0);
84 floppy = qemu_opt_get_bool(opts, "floppy", false);
85 + s->volume_label = g_strdup(qemu_opt_get(opts, "label"));
86
87 if (floppy) {
88 /* 1.44MB or 2.88MB floppy. 2.88MB can be FAT12 (default) or FAT16. */
89 @@ -2968,6 +2991,7 @@ static void vvfat_close(BlockDriverState *bs)
90 array_free(&(s->directory));
91 array_free(&(s->mapping));
92 g_free(s->cluster_buffer);
93 + g_free(s->volume_label);
94
95 if (s->qcow) {
96 migrate_del_blocker(s->migration_blocker);
97 diff --git a/qapi/block-core.json b/qapi/block-core.json
98 index 7873084..8dd3f3f 100644
99 --- a/qapi/block-core.json
100 +++ b/qapi/block-core.json
101 @@ -1325,13 +1325,14 @@
102 # @fat-type: #optional FAT type: 12, 16 or 32
103 # @floppy: #optional whether to export a floppy image (true) or
104 # partitioned hard disk (false; default)
105 +# @label: #optional override default label
106 # @rw: #optional whether to allow write operations (default: false)
107 #
108 # Since: 1.7
109 ##
110 { 'type': 'BlockdevOptionsVVFAT',
111 'data': { 'dir': 'str', '*fat-type': 'int', '*floppy': 'bool',
112 - '*rw': 'bool' } }
113 + '*label': 'str', '*rw': 'bool' } }
114
115 ##
116 # @BlockdevOptionsGenericFormat
117 --
118 2.1.4
119