diff options
author | Michael Olbrich <m.olbrich@pengutronix.de> | 2018-12-17 15:37:23 +0100 |
---|---|---|
committer | Michael Olbrich <m.olbrich@pengutronix.de> | 2019-03-01 16:38:16 +0100 |
commit | 3552a4d30da208516f5b97a5ec7a89509ddfcbca (patch) | |
tree | 0f0f6fe737d7152caa47554a0b7b967b8ade0068 | |
parent | 3ea3e3078f7f8d3b2dcb2371e48aecc204d71491 (diff) | |
download | genimage-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.h | 1 | ||||
-rw-r--r-- | image-hd.c | 1 | ||||
-rw-r--r-- | util.c | 24 |
3 files changed, 26 insertions, 0 deletions
@@ -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); @@ -387,6 +387,7 @@ static int hdimage_generate(struct image *image) if (ret) return ret; } + return reload_partitions(image); } return 0; @@ -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; +} |