From 295fd6e8330c7416e2d97634364f2890133c28fa Mon Sep 17 00:00:00 2001 From: Mark McLoughlin Date: Tue, 29 Sep 2009 09:41:23 +0100 Subject: [PATCH] Add virStorageFileGetMetadata() helper * src/util/storage_file.c: add virStorageFileGetMetadata() so that the caller does not need to open the file --- src/libvirt_private.syms | 1 + src/util/storage_file.c | 20 ++++++++++++++++++++ src/util/storage_file.h | 3 +++ 3 files changed, 24 insertions(+) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 9eb4b77974..b699fb2187 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 e674713d12..44057d2fce 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 e34d7495a6..b0abcafe89 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, -- GitLab