diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 9eb4b77974c6f06bd8da9ae08ace4c52154de5f5..b699fb2187aa1a962afa16ed876583f80a0c9938 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -395,6 +395,7 @@ virStorageGenerateQcowPassphrase; # storage_file.h virStorageFileFormatTypeToString; virStorageFileFormatTypeFromString; +virStorageFileGetMetadata; virStorageFileGetMetadataFromFD; # threads.h diff --git a/src/util/storage_file.c b/src/util/storage_file.c index e674713d12d8dfaba085d11454e6cb6fce117a97..44057d2fceb481ee22a664ea8a048e5d00bb967c 100644 --- a/src/util/storage_file.c +++ b/src/util/storage_file.c @@ -25,6 +25,7 @@ #include "storage_file.h" #include +#include #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; +} diff --git a/src/util/storage_file.h b/src/util/storage_file.h index e34d7495a6ac83a4564c4b3f2b8c4e28ec923b18..b0abcafe89f4412d35f83eeb9ec2951cc3aee058 100644 --- a/src/util/storage_file.h +++ b/src/util/storage_file.h @@ -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,