mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-23 22:25:25 +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
|
||||
virStorageFileFormatTypeToString;
|
||||
virStorageFileFormatTypeFromString;
|
||||
virStorageFileGetMetadata;
|
||||
virStorageFileGetMetadataFromFD;
|
||||
|
||||
# threads.h
|
||||
|
@ -25,6 +25,7 @@
|
||||
#include "storage_file.h"
|
||||
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include "memory.h"
|
||||
#include "virterror_internal.h"
|
||||
|
||||
@ -402,3 +403,22 @@ virStorageFileGetMetadataFromFD(virConnectPtr conn,
|
||||
|
||||
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;
|
||||
} virStorageFileMetadata;
|
||||
|
||||
int virStorageFileGetMetadata(virConnectPtr conn,
|
||||
const char *path,
|
||||
virStorageFileMetadata *meta);
|
||||
int virStorageFileGetMetadataFromFD(virConnectPtr conn,
|
||||
const char *path,
|
||||
int fd,
|
||||
|
Loading…
Reference in New Issue
Block a user