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:
Mark McLoughlin 2009-09-29 09:41:23 +01:00
parent a010fb58d6
commit 295fd6e833
3 changed files with 24 additions and 0 deletions

View File

@ -395,6 +395,7 @@ virStorageGenerateQcowPassphrase;
# storage_file.h
virStorageFileFormatTypeToString;
virStorageFileFormatTypeFromString;
virStorageFileGetMetadata;
virStorageFileGetMetadataFromFD;
# threads.h

View File

@ -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;
}

View File

@ -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,