diff mbox series

raw file handler: add free space check

Message ID 20210412012750.117483-1-dominique.martinet@atmark-techno.com
State Accepted
Headers show
Series raw file handler: add free space check | expand

Commit Message

Dominique MARTINET April 12, 2021, 1:27 a.m. UTC
Check for free space before writing file in raw file handler, to avoid
needlessly filling partition.
This reuses img_check_free_space which checks decompressed or decrypted
size attributes if available, but will fallback to cpio size if not set

Signed-off-by: Dominique Martinet <dominique.martinet@atmark-techno.com>
---

Follow up on https://groups.google.com/g/swupdate/c/hLK4jAIsC-g/m/pimR8Pl9AwAJ
We probably also want install raw file to check in final destination,
and not just protect /tmp

Tested with installed directly and without.

 handlers/raw_handler.c | 4 ++++
 1 file changed, 4 insertions(+)

Comments

Stefano Babic April 17, 2021, 9:43 a.m. UTC | #1
On 12.04.21 03:27, Dominique Martinet wrote:
> Check for free space before writing file in raw file handler, to avoid
> needlessly filling partition.
> This reuses img_check_free_space which checks decompressed or decrypted
> size attributes if available, but will fallback to cpio size if not set
> 
> Signed-off-by: Dominique Martinet <dominique.martinet@atmark-techno.com>
> ---
> 
> Follow up on https://groups.google.com/g/swupdate/c/hLK4jAIsC-g/m/pimR8Pl9AwAJ
> We probably also want install raw file to check in final destination,
> and not just protect /tmp
> 
> Tested with installed directly and without.
> 
>   handlers/raw_handler.c | 4 ++++
>   1 file changed, 4 insertions(+)
> 
> diff --git a/handlers/raw_handler.c b/handlers/raw_handler.c
> index 14005717d950..17e1c2c3a4aa 100644
> --- a/handlers/raw_handler.c
> +++ b/handlers/raw_handler.c
> @@ -253,6 +253,10 @@ static int install_raw_file(struct img_type *img,
>   	}
>   
>   	fdout = openfileoutput(path);
> +	if (!img_check_free_space(img, fdout)) {
> +		return -ENOSPC;
> +	}
> +
>   	ret = copyimage(&fdout, img, NULL);
>   	if (ret< 0) {
>   		ERROR("Error copying extracted file");
> 
Applied to -master, thanks !

Best regards,
Stefano Babic
diff mbox series

Patch

diff --git a/handlers/raw_handler.c b/handlers/raw_handler.c
index 14005717d950..17e1c2c3a4aa 100644
--- a/handlers/raw_handler.c
+++ b/handlers/raw_handler.c
@@ -253,6 +253,10 @@  static int install_raw_file(struct img_type *img,
 	}
 
 	fdout = openfileoutput(path);
+	if (!img_check_free_space(img, fdout)) {
+		return -ENOSPC;
+	}
+
 	ret = copyimage(&fdout, img, NULL);
 	if (ret< 0) {
 		ERROR("Error copying extracted file");