提交 295fd6e8 编写于 作者: M Mark McLoughlin

Add virStorageFileGetMetadata() helper

* src/util/storage_file.c: add virStorageFileGetMetadata() so that
  the caller does not need to open the file
上级 a010fb58
...@@ -395,6 +395,7 @@ virStorageGenerateQcowPassphrase; ...@@ -395,6 +395,7 @@ virStorageGenerateQcowPassphrase;
# storage_file.h # storage_file.h
virStorageFileFormatTypeToString; virStorageFileFormatTypeToString;
virStorageFileFormatTypeFromString; virStorageFileFormatTypeFromString;
virStorageFileGetMetadata;
virStorageFileGetMetadataFromFD; virStorageFileGetMetadataFromFD;
# threads.h # threads.h
......
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
#include "storage_file.h" #include "storage_file.h"
#include <unistd.h> #include <unistd.h>
#include <fcntl.h>
#include "memory.h" #include "memory.h"
#include "virterror_internal.h" #include "virterror_internal.h"
...@@ -402,3 +403,22 @@ virStorageFileGetMetadataFromFD(virConnectPtr conn, ...@@ -402,3 +403,22 @@ virStorageFileGetMetadataFromFD(virConnectPtr conn,
return 0; 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 { ...@@ -51,6 +51,9 @@ typedef struct _virStorageFileMetadata {
bool encrypted; bool encrypted;
} virStorageFileMetadata; } virStorageFileMetadata;
int virStorageFileGetMetadata(virConnectPtr conn,
const char *path,
virStorageFileMetadata *meta);
int virStorageFileGetMetadataFromFD(virConnectPtr conn, int virStorageFileGetMetadataFromFD(virConnectPtr conn,
const char *path, const char *path,
int fd, int fd,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册