
On Tue, Sep 29, 2009 at 09:56:48AM +0100, Mark McLoughlin wrote:
* 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(+), 0 deletions(-)
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 4890032..635c6b6 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -393,6 +393,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 e674713..44057d2 100644 --- a/src/util/storage_file.c +++ b/src/util/storage_file.c @@ -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; +} diff --git a/src/util/storage_file.h b/src/util/storage_file.h index e34d749..b0abcaf 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,
ACK Daniel -- |: Red Hat, Engineering, London -o- http://people.redhat.com/berrange/ :| |: http://libvirt.org -o- http://virt-manager.org -o- http://ovirt.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: GnuPG: 7D3B9505 -o- F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|