mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-24 14:45:24 +00:00
Remove 'type' field from FileTypeInfo struct
Instead of including a field in FileTypeInfo struct for the disk format, rely on the array index matching the format. Use verify() to assert the correct number of elements in the array. * src/util/storage_file.c: remove type field from FileTypeInfo
This commit is contained in:
parent
a93402d48b
commit
779b6ea7c4
@ -58,7 +58,6 @@ enum {
|
|||||||
|
|
||||||
/* Either 'magic' or 'extension' *must* be provided */
|
/* Either 'magic' or 'extension' *must* be provided */
|
||||||
struct FileTypeInfo {
|
struct FileTypeInfo {
|
||||||
int type; /* One of the constants above */
|
|
||||||
const char *magic; /* Optional string of file magic
|
const char *magic; /* Optional string of file magic
|
||||||
* to check at head of file */
|
* to check at head of file */
|
||||||
const char *extension; /* Optional file extension to check */
|
const char *extension; /* Optional file extension to check */
|
||||||
@ -108,58 +107,59 @@ static int vmdk4GetBackingStore(char **, int *,
|
|||||||
|
|
||||||
|
|
||||||
static struct FileTypeInfo const fileTypeInfo[] = {
|
static struct FileTypeInfo const fileTypeInfo[] = {
|
||||||
/* Bochs */
|
[VIR_STORAGE_FILE_RAW] = { NULL, NULL, LV_LITTLE_ENDIAN, -1, 0, 0, 0, 0, 0, NULL },
|
||||||
/* XXX Untested
|
[VIR_STORAGE_FILE_DIR] = { NULL, NULL, LV_LITTLE_ENDIAN, -1, 0, 0, 0, 0, 0, NULL },
|
||||||
{ VIR_STORAGE_FILE_BOCHS, "Bochs Virtual HD Image", NULL,
|
[VIR_STORAGE_FILE_BOCHS] = {
|
||||||
LV_LITTLE_ENDIAN, 64, 0x20000,
|
/*"Bochs Virtual HD Image", */ /* Untested */ NULL,
|
||||||
32+16+16+4+4+4+4+4, 8, 1, -1, NULL },*/
|
NULL,
|
||||||
/* CLoop */
|
LV_LITTLE_ENDIAN, 64, 0x20000,
|
||||||
/* XXX Untested
|
32+16+16+4+4+4+4+4, 8, 1, -1, NULL
|
||||||
{ VIR_STORAGE_VOL_CLOOP, "#!/bin/sh\n#V2.0 Format\nmodprobe cloop file=$0 && mount -r -t iso9660 /dev/cloop $1\n", NULL,
|
},
|
||||||
LV_LITTLE_ENDIAN, -1, 0,
|
[VIR_STORAGE_FILE_CLOOP] = {
|
||||||
-1, 0, 0, -1, NULL }, */
|
/*"#!/bin/sh\n#V2.0 Format\nmodprobe cloop file=$0 && mount -r -t iso9660 /dev/cloop $1\n", */ /* Untested */ NULL,
|
||||||
/* Cow */
|
NULL,
|
||||||
{ VIR_STORAGE_FILE_COW, "OOOM", NULL,
|
LV_LITTLE_ENDIAN, -1, 0,
|
||||||
LV_BIG_ENDIAN, 4, 2,
|
-1, 0, 0, -1, NULL
|
||||||
4+4+1024+4, 8, 1, -1, cowGetBackingStore },
|
},
|
||||||
/* DMG */
|
[VIR_STORAGE_FILE_COW] = {
|
||||||
/* XXX QEMU says there's no magic for dmg, but we should check... */
|
"OOOM", NULL,
|
||||||
{ VIR_STORAGE_FILE_DMG, NULL, ".dmg",
|
LV_BIG_ENDIAN, 4, 2,
|
||||||
0, -1, 0,
|
4+4+1024+4, 8, 1, -1, cowGetBackingStore
|
||||||
-1, 0, 0, -1, NULL },
|
},
|
||||||
/* XXX there's probably some magic for iso we can validate too... */
|
[VIR_STORAGE_FILE_DMG] = {
|
||||||
{ VIR_STORAGE_FILE_ISO, NULL, ".iso",
|
NULL, /* XXX QEMU says there's no magic for dmg, but we should check... */
|
||||||
0, -1, 0,
|
".dmg",
|
||||||
-1, 0, 0, -1, NULL },
|
0, -1, 0,
|
||||||
/* Parallels */
|
-1, 0, 0, -1, NULL
|
||||||
/* XXX Untested
|
},
|
||||||
{ VIR_STORAGE_FILE_PARALLELS, "WithoutFreeSpace", NULL,
|
[VIR_STORAGE_FILE_ISO] = {
|
||||||
LV_LITTLE_ENDIAN, 16, 2,
|
NULL, /* XXX there's probably some magic for iso we can validate too... */
|
||||||
16+4+4+4+4, 4, 512, -1, NULL },
|
".iso",
|
||||||
*/
|
0, -1, 0,
|
||||||
/* QCow */
|
-1, 0, 0, -1, NULL
|
||||||
{ VIR_STORAGE_FILE_QCOW, "QFI", NULL,
|
},
|
||||||
LV_BIG_ENDIAN, 4, 1,
|
[VIR_STORAGE_FILE_QCOW] = {
|
||||||
QCOWX_HDR_IMAGE_SIZE, 8, 1, QCOW1_HDR_CRYPT, qcow1GetBackingStore },
|
"QFI", NULL,
|
||||||
/* QCow 2 */
|
LV_BIG_ENDIAN, 4, 1,
|
||||||
{ VIR_STORAGE_FILE_QCOW2, "QFI", NULL,
|
QCOWX_HDR_IMAGE_SIZE, 8, 1, QCOW1_HDR_CRYPT, qcow1GetBackingStore,
|
||||||
LV_BIG_ENDIAN, 4, 2,
|
},
|
||||||
QCOWX_HDR_IMAGE_SIZE, 8, 1, QCOW2_HDR_CRYPT, qcow2GetBackingStore },
|
[VIR_STORAGE_FILE_QCOW2] = {
|
||||||
/* VMDK 3 */
|
"QFI", NULL,
|
||||||
/* XXX Untested
|
LV_BIG_ENDIAN, 4, 2,
|
||||||
{ VIR_STORAGE_FILE_VMDK, "COWD", NULL,
|
QCOWX_HDR_IMAGE_SIZE, 8, 1, QCOW2_HDR_CRYPT, qcow2GetBackingStore,
|
||||||
LV_LITTLE_ENDIAN, 4, 1,
|
},
|
||||||
4+4+4, 4, 512, -1, NULL },
|
[VIR_STORAGE_FILE_VMDK] = {
|
||||||
*/
|
"KDMV", NULL,
|
||||||
/* VMDK 4 */
|
LV_LITTLE_ENDIAN, 4, 1,
|
||||||
{ VIR_STORAGE_FILE_VMDK, "KDMV", NULL,
|
4+4+4, 8, 512, -1, vmdk4GetBackingStore
|
||||||
LV_LITTLE_ENDIAN, 4, 1,
|
},
|
||||||
4+4+4, 8, 512, -1, vmdk4GetBackingStore },
|
[VIR_STORAGE_FILE_VPC] = {
|
||||||
/* Connectix / VirtualPC */
|
"conectix", NULL,
|
||||||
{ VIR_STORAGE_FILE_VPC, "conectix", NULL,
|
LV_BIG_ENDIAN, 12, 0x10000,
|
||||||
LV_BIG_ENDIAN, 12, 0x10000,
|
8 + 4 + 4 + 8 + 4 + 4 + 2 + 2 + 4, 8, 1, -1, NULL
|
||||||
8 + 4 + 4 + 8 + 4 + 4 + 2 + 2 + 4, 8, 1, -1, NULL},
|
},
|
||||||
};
|
};
|
||||||
|
verify(ARRAY_CARDINALITY(fileTypeInfo) == VIR_STORAGE_FILE_LAST);
|
||||||
|
|
||||||
static int
|
static int
|
||||||
cowGetBackingStore(char **res,
|
cowGetBackingStore(char **res,
|
||||||
@ -506,7 +506,7 @@ virStorageFileGetMetadataFromFD(const char *path,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Validation passed, we know the file format now */
|
/* Validation passed, we know the file format now */
|
||||||
meta->format = fileTypeInfo[i].type;
|
meta->format = i;
|
||||||
if (fileTypeInfo[i].getBackingStore != NULL) {
|
if (fileTypeInfo[i].getBackingStore != NULL) {
|
||||||
char *backing;
|
char *backing;
|
||||||
int backingFormat;
|
int backingFormat;
|
||||||
@ -546,7 +546,7 @@ virStorageFileGetMetadataFromFD(const char *path,
|
|||||||
if (!virFileHasSuffix(path, fileTypeInfo[i].extension))
|
if (!virFileHasSuffix(path, fileTypeInfo[i].extension))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
meta->format = fileTypeInfo[i].type;
|
meta->format = i;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user