diff mbox series

[1/2] handles: ubivol: add property decompressed-size

Message ID 20200919183010.100367-1-bage@linutronix.de
State Changes Requested
Headers show
Series [1/2] handles: ubivol: add property decompressed-size | expand

Commit Message

Bastian Germann Sept. 19, 2020, 6:30 p.m. UTC
From: Bastian Germann <bage@linutronix.de>

Add the property decompressed-size that works similar to the decrypted-size
property.

This was posted to the mailing list by Matt over two years ago
("Update fails when ubifs is compressed - fixed and patch attached"),
so I assume it is meant to be released under the SWUpdate license.
The first version did not use properties and was rejected.

Co-developed-by: Matt <mattbeaumontgts@gmail.com>
[Add commit msg. Change decompressed_size to decompressed-size]
Signed-off-by: Bastian Germann <bage@linutronix.de>
---
 handlers/ubivol_handler.c | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/handlers/ubivol_handler.c b/handlers/ubivol_handler.c
index 5cfc0dd..ed3c08b 100644
--- a/handlers/ubivol_handler.c
+++ b/handlers/ubivol_handler.c
@@ -150,7 +150,7 @@  static int check_ubi_alwaysremove(struct img_type *img)
 static int update_volume(libubi_t libubi, struct img_type *img,
 	struct ubi_vol_info *vol)
 {
-	long long bytes;
+	long long bytes, decompressed_bytes;
 	int fdout;
 	char node[64];
 	int err;
@@ -219,7 +219,19 @@  static int update_volume(libubi_t libubi, struct img_type *img,
 		ERROR("cannot open UBI volume \"%s\"", node);
 		return -1;
 	}
-	err = ubi_update_start(libubi, fdout, bytes);
+
+	if (img->compressed) {
+		decompressed_bytes = strtoll(dict_get_value(&img->properties, "decompressed-size"), NULL, 10);
+		if (!decompressed_bytes) {
+			ERROR("UBIFS to be decompressed, but decompressed-size not found");
+			return -EINVAL;
+		}
+	}
+	else {
+		decompressed_bytes = bytes;
+	}
+
+	err = ubi_update_start(libubi, fdout, decompressed_bytes);
 	if (err) {
 		ERROR("cannot start volume \"%s\" update", node);
 		return -1;