mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-24 22:55:23 +00:00
Add virStorageFileGetMetadata() helper
* src/util/storage_file.c: add virStorageFileGetMetadata() so that the caller does not need to open the file
This commit is contained in:
parent
a010fb58d6
commit
295fd6e833
@ -395,6 +395,7 @@ virStorageGenerateQcowPassphrase;
|
|||||||
# storage_file.h
|
# storage_file.h
|
||||||
virStorageFileFormatTypeToString;
|
virStorageFileFormatTypeToString;
|
||||||
virStorageFileFormatTypeFromString;
|
virStorageFileFormatTypeFromString;
|
||||||
|
virStorageFileGetMetadata;
|
||||||
virStorageFileGetMetadataFromFD;
|
virStorageFileGetMetadataFromFD;
|
||||||
|
|
||||||
# threads.h
|
# threads.h
|
||||||
|
@ -25,6 +25,7 @@
|
|||||||
#include "storage_file.h"
|
#include "storage_file.h"
|
||||||
|
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
#include <fcntl.h>
|
||||||
#include "memory.h"
|
#include "memory.h"
|
||||||
#include "virterror_internal.h"
|
#include "virterror_internal.h"
|
||||||
|
|
||||||
@ -402,3 +403,22 @@ virStorageFileGetMetadataFromFD(virConnectPtr conn,
|
|||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
virStorageFileGetMetadata(virConnectPtr conn,
|
||||||
|
const char *path,
|
||||||
|
virStorageFileMetadata *meta)
|
||||||
|
{
|
||||||
|
int fd, ret;
|
||||||
|
|
||||||
|
if ((fd = open(path, O_RDONLY)) < 0) {
|
||||||
|
virReportSystemError(conn, errno, _("cannot open file '%s'"), path);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = virStorageFileGetMetadataFromFD(conn, path, fd, meta);
|
||||||
|
|
||||||
|
close(fd);
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
@ -51,6 +51,9 @@ typedef struct _virStorageFileMetadata {
|
|||||||
bool encrypted;
|
bool encrypted;
|
||||||
} virStorageFileMetadata;
|
} virStorageFileMetadata;
|
||||||
|
|
||||||
|
int virStorageFileGetMetadata(virConnectPtr conn,
|
||||||
|
const char *path,
|
||||||
|
virStorageFileMetadata *meta);
|
||||||
int virStorageFileGetMetadataFromFD(virConnectPtr conn,
|
int virStorageFileGetMetadataFromFD(virConnectPtr conn,
|
||||||
const char *path,
|
const char *path,
|
||||||
int fd,
|
int fd,
|
||||||
|
Loading…
Reference in New Issue
Block a user