[CRIU] [PATCH RFC 1/2] criu: image: add img_raw_size helper

Mike Rapoport rppt at linux.vnet.ibm.com
Thu Jun 2 06:10:05 PDT 2016


Signed-off-by: Mike Rapoport <rppt at linux.vnet.ibm.com>
---
 criu/image.c         | 12 ++++++++++++
 criu/include/image.h |  2 ++
 2 files changed, 14 insertions(+)

diff --git a/criu/image.c b/criu/image.c
index e680e87..cff9edd 100644
--- a/criu/image.c
+++ b/criu/image.c
@@ -1,6 +1,7 @@
 #include <unistd.h>
 #include <stdarg.h>
 #include <fcntl.h>
+#include <sys/stat.h>
 #include "crtools.h"
 #include "cr_options.h"
 #include "imgset.h"
@@ -563,3 +564,14 @@ int read_img_str(struct cr_img *img, char **pstr, int size)
 	return 0;
 }
 
+off_t img_raw_size(struct cr_img *img)
+{
+	struct stat stat;
+
+	if (fstat(img->_x.fd, &stat)) {
+		pr_perror("Failed to get image stats\n");
+		return -1;
+	}
+
+	return stat.st_size;
+}
diff --git a/criu/include/image.h b/criu/include/image.h
index 9981f08..476a096 100644
--- a/criu/include/image.h
+++ b/criu/include/image.h
@@ -142,6 +142,8 @@ static inline int img_raw_fd(struct cr_img *img)
 	return img->_x.fd;
 }
 
+extern off_t img_raw_size(struct cr_img *img);
+
 extern int open_image_dir(char *dir);
 extern void close_image_dir(void);
 
-- 
1.9.1



More information about the CRIU mailing list