summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Olbrich <m.olbrich@pengutronix.de>2018-12-17 15:37:23 +0100
committerMichael Olbrich <m.olbrich@pengutronix.de>2019-03-01 16:38:16 +0100
commit3552a4d30da208516f5b97a5ec7a89509ddfcbca (patch)
tree0f0f6fe737d7152caa47554a0b7b967b8ade0068
parent3ea3e3078f7f8d3b2dcb2371e48aecc204d71491 (diff)
downloadgenimage-3552a4d30da208516f5b97a5ec7a89509ddfcbca.tar.gz
genimage-3552a4d30da208516f5b97a5ec7a89509ddfcbca.tar.xz
image-hd: re-read partition table for block devices
Signed-off-by: Michael Olbrich <m.olbrich@pengutronix.de>
-rw-r--r--genimage.h1
-rw-r--r--image-hd.c1
-rw-r--r--util.c24
3 files changed, 26 insertions, 0 deletions
diff --git a/genimage.h b/genimage.h
index 8eb2c91..e339d1d 100644
--- a/genimage.h
+++ b/genimage.h
@@ -141,6 +141,7 @@ int pad_file(struct image *image, const char *infile,
size_t size, unsigned char fillpattern, enum pad_mode mode);
int insert_data(struct image *image, const char *data, const char *outfile,
size_t size, long offset);
+int reload_partitions(struct image *image);
unsigned long long cfg_getint_suffix(cfg_t *sec, const char *name);
diff --git a/image-hd.c b/image-hd.c
index 8ad0814..2c2860c 100644
--- a/image-hd.c
+++ b/image-hd.c
@@ -387,6 +387,7 @@ static int hdimage_generate(struct image *image)
if (ret)
return ret;
}
+ return reload_partitions(image);
}
return 0;
diff --git a/util.c b/util.c
index 0e668d3..2b91a94 100644
--- a/util.c
+++ b/util.c
@@ -20,9 +20,11 @@
#include <string.h>
#include <stdlib.h>
#include <errno.h>
+#include <sys/ioctl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/wait.h>
+#include <linux/fs.h>
#include <unistd.h>
#include <fcntl.h>
#include <ctype.h>
@@ -532,3 +534,25 @@ char *uuid_random(void)
return uuid;
}
+
+int reload_partitions(struct image *image)
+{
+ const char *outfile = imageoutfile(image);
+ int fd;
+
+ if (!is_block_device(outfile))
+ return 0;
+
+ fd = open(outfile, O_WRONLY|O_EXCL);
+ if (fd < 0) {
+ int ret = -errno;
+ image_error(image, "open: %s\n", strerror(errno));
+ return ret;
+ }
+ /* no error because not all block devices support this */
+ if (ioctl(fd, BLKRRPART) < 0)
+ image_info(image, "failed to re-read partition table: %s\n",
+ strerror(errno));
+ close(fd);
+ return 0;
+}