summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Olbrich <m.olbrich@pengutronix.de>2019-05-06 08:58:42 +0200
committerMichael Olbrich <m.olbrich@pengutronix.de>2019-05-07 13:05:20 +0200
commit8d9c1a2bd3d995434f3f66c3c0a08edc035b1f3a (patch)
treeee2a84f02e222ce781f64a622dd10c9420289105
parent393897209665117e32360d5346bc1d3960f40a41 (diff)
downloadgenimage-8d9c1a2bd3d995434f3f66c3c0a08edc035b1f3a.tar.gz
genimage-8d9c1a2bd3d995434f3f66c3c0a08edc035b1f3a.tar.xz
genimage: allow percentages for image sizes
Signed-off-by: Michael Olbrich <m.olbrich@pengutronix.de>
-rw-r--r--Makefile.am2
-rw-r--r--README.rst6
-rw-r--r--genimage.c16
-rw-r--r--genimage.h1
-rwxr-xr-xtest/basic-images.test5
-rw-r--r--test/ext2percent.config7
-rw-r--r--test/ext2test-percent.dump40
7 files changed, 71 insertions, 6 deletions
diff --git a/Makefile.am b/Makefile.am
index 3c96229..d283212 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -51,6 +51,8 @@ EXTRA_DIST += \
test/cramfs.config \
test/ext2.config \
test/ext2test.dump \
+ test/ext2percent.config \
+ test/ext2test-percent.dump \
test/ext3.config \
test/ext3test.dump \
test/ext4.config \
diff --git a/README.rst b/README.rst
index 67a648a..6cc5846 100644
--- a/README.rst
+++ b/README.rst
@@ -68,7 +68,11 @@ Here are all options for images:
:name: The name of this image. This is used for some image types
to set the name of the image.
-:size: Size of this image in bytes
+:size: Size of this image in bytes. 'k', 'M' or 'G' can be used as suffix to
+ specify the size in multiple of 1024 etc. If the image if filled from
+ a mountpoint then '%' as suffix indicates a percentage. '200%' means
+ the resulting filesystem should be about 50% filled. Note that is is
+ only a rough estimate based on the original size of the content.
:mountpoint: mountpoint if image refers to a filesystem image. The
default is "/". The content of "${rootpath}${mountpoint}"
will be used used fill the filesystem.
diff --git a/genimage.c b/genimage.c
index 64a7b2e..ca2c6d6 100644
--- a/genimage.c
+++ b/genimage.c
@@ -157,6 +157,11 @@ static int image_setup(struct image *image)
image->seen = -1;
+ if (image->size_is_percent) {
+ image->size = image_dir_size(image) * image->size / 100;
+ image->size_is_percent = cfg_false;
+ }
+
list_for_each_entry(part, &image->partitions, list) {
struct image *child;
if (!part->image)
@@ -664,7 +669,8 @@ int main(int argc, char *argv[])
list_add_tail(&image->list, &images);
image->file = cfg_title(imagesec);
image->name = cfg_getstr(imagesec, "name");
- image->size = cfg_getint_suffix(imagesec, "size");
+ image->size = cfg_getint_suffix_percent(imagesec, "size",
+ &image->size_is_percent);
image->mountpoint = cfg_getstr(imagesec, "mountpoint");
image->exec_pre = cfg_getstr(imagesec, "exec-pre");
image->exec_post = cfg_getstr(imagesec, "exec-post");
@@ -717,6 +723,10 @@ int main(int argc, char *argv[])
if (ret)
goto cleanup;
+ ret = collect_mountpoints();
+ if (ret)
+ goto cleanup;
+
list_for_each_entry(image, &images, list) {
ret = image_setup(image);
if (ret)
@@ -731,10 +741,6 @@ int main(int argc, char *argv[])
if (ret)
goto cleanup;
- ret = collect_mountpoints();
- if (ret)
- goto cleanup;
-
list_for_each_entry(image, &images, list) {
ret = setenv_image(image);
if (ret)
diff --git a/genimage.h b/genimage.h
index 2559511..1ebe1cd 100644
--- a/genimage.h
+++ b/genimage.h
@@ -51,6 +51,7 @@ struct image {
const char *name;
const char *file;
unsigned long long size;
+ cfg_bool_t size_is_percent;
const char *mountpoint;
const char *exec_pre;
const char *exec_post;
diff --git a/test/basic-images.test b/test/basic-images.test
index 9b53b45..cf6d68b 100755
--- a/test/basic-images.test
+++ b/test/basic-images.test
@@ -157,6 +157,11 @@ test_expect_success genext2fs,e2fsck "ext2" "
check_ext images/test.ext2 ext2test 4194304
"
+test_expect_success genext2fs,e2fsck "ext2percent" "
+ run_genimage ext2percent.config test.ext2 &&
+ check_ext images/test.ext2 ext2test-percent 69632
+"
+
test_expect_success genext2fs,e2fsck "ext3" "
run_genimage ext3.config test.ext3 &&
check_ext images/test.ext3 ext3test 4194304
diff --git a/test/ext2percent.config b/test/ext2percent.config
new file mode 100644
index 0000000..f9cd848
--- /dev/null
+++ b/test/ext2percent.config
@@ -0,0 +1,7 @@
+image test.ext2 {
+ ext2 {
+ label = "ext2test"
+ fs-timestamp = "20000101000000"
+ }
+ size = 100%
+}
diff --git a/test/ext2test-percent.dump b/test/ext2test-percent.dump
new file mode 100644
index 0000000..f771eb4
--- /dev/null
+++ b/test/ext2test-percent.dump
@@ -0,0 +1,40 @@
+Filesystem volume name: ext2test
+Last mounted on: <not available>
+Filesystem magic number: 0xEF53
+Filesystem revision #: 0 (original)
+Filesystem features: (none)
+Default mount options: (none)
+Filesystem state: clean
+Errors behavior: Unknown (continue)
+Filesystem OS type: Linux
+Inode count: 56
+Block count: 68
+Reserved block count: 3
+Free blocks: 36
+Free inodes: 5
+First block: 1
+Block size: 1024
+Fragment size: 1024
+Blocks per group: 72
+Fragments per group: 72
+Inodes per group: 56
+Inode blocks per group: 7
+Filesystem created: Sat Jan 1 00:00:00 2000
+Last mount time: n/a
+Last write time: Sat Jan 1 00:00:00 2000
+Mount count: 0
+Maximum mount count: 20
+Last checked: Sat Jan 1 00:00:00 2000
+Check interval: 0 (<none>)
+Reserved blocks uid: 0 (user root)
+Reserved blocks gid: 0 (group root)
+
+
+Group 0: (Blocks 1-67)
+ Primary superblock at 1, Group descriptors at 2-2
+ Block bitmap at 3 (+2)
+ Inode bitmap at 4 (+3)
+ Inode table at 5-11 (+4)
+ 36 free blocks, 5 free inodes, 18 directories
+ Free blocks: 32-67
+ Free inodes: 52-56