Message ID | 20210319085531.1070347-1-dominique.martinet@atmark-techno.com |
---|---|
State | Changes Requested |
Headers | show |
Series | [1/3] utils: move get_output_size from ubivol handler | expand |
On 19.03.21 09:55, Dominique Martinet wrote: > Signed-off-by: Dominique Martinet <dominique.martinet@atmark-techno.com> > --- > > Note this patch applies on top of my utils: add read_lines_notify helper > patch. > It's simple enough to rebase if required though but that would explain > if it doesn't apply cleanly for you, I'm not sure which is preferable -- > unless you have more remarks the run_system_cmd fixes are probably going > to get in first so I left it like this. Good to know, I will apply after read_lines_notify . > > core/util.c | 40 +++++++++++++++++++++++++++++++++++++++ > handlers/ubivol_handler.c | 40 --------------------------------------- > include/util.h | 1 + > 3 files changed, 41 insertions(+), 40 deletions(-) > > diff --git a/core/util.c b/core/util.c > index a9353ca8cb27..30c7e0b7aece 100644 > --- a/core/util.c > +++ b/core/util.c > @@ -894,3 +894,43 @@ int read_lines_notify(int fd, char *buf, int buf_size, int *buf_offset, > > return n; > } > + > +long long get_output_size(struct img_type *img) > +{ > + char *output_size_str = NULL; > + long long bytes = img->size; > + > + if (img->compressed) { > + output_size_str = dict_get_value(&img->properties, "decompressed-size"); > + > + bytes = ustrtoull(output_size_str, 0); > + if (errno) { > + ERROR("decompressed-size argument: ustrtoull failed"); > + return -1; > + } > + > + if (bytes == 0) { > + ERROR("UBIFS to be decompressed, but decompressed-size not valid"); > + return -1; > + } > + TRACE("Image is compressed, decompressed size %lld bytes", bytes); > + > + } else if (img->is_encrypted) { > + > + output_size_str = dict_get_value(&img->properties, "decrypted-size"); > + > + bytes = ustrtoull(output_size_str, 0); > + if (errno){ > + ERROR("decrypted-size argument: ustrtoull failed"); > + return -1; > + } > + > + if (bytes < AES_BLK_SIZE) { > + ERROR("Encrypted image size (%lld) too small", bytes); > + return -1; > + } > + TRACE("Image is crypted, decrypted size %lld bytes", bytes); > + } > + > + return bytes; > +} > diff --git a/handlers/ubivol_handler.c b/handlers/ubivol_handler.c > index 80db4994c8d9..bf8c035e1b81 100644 > --- a/handlers/ubivol_handler.c > +++ b/handlers/ubivol_handler.c > @@ -147,46 +147,6 @@ static int check_ubi_alwaysremove(struct img_type *img) > return ret; > } > > -static long long get_output_size(struct img_type *img) > -{ > - char *output_size_str = NULL; > - long long bytes = img->size; > - > - if (img->compressed) { > - output_size_str = dict_get_value(&img->properties, "decompressed-size"); > - > - bytes = ustrtoull(output_size_str, 0); > - if (errno) { > - ERROR("decompressed-size argument: ustrtoull failed"); > - return -1; > - } > - > - if (bytes == 0) { > - ERROR("UBIFS to be decompressed, but decompressed-size not valid"); > - return -1; > - } > - TRACE("Image is compressed, decompressed size %lld bytes", bytes); > - > - } else if (img->is_encrypted) { > - > - output_size_str = dict_get_value(&img->properties, "decrypted-size"); > - > - bytes = ustrtoull(output_size_str, 0); > - if (errno){ > - ERROR("decrypted-size argument: ustrtoull failed"); > - return -1; > - } > - > - if (bytes < AES_BLK_SIZE) { > - ERROR("Encrypted image size (%lld) too small", bytes); > - return -1; > - } > - TRACE("Image is crypted, decrypted size %lld bytes", bytes); > - } > - > - return bytes; > -} > - > static int update_volume(libubi_t libubi, struct img_type *img, > struct ubi_vol_info *vol) > { > diff --git a/include/util.h b/include/util.h > index 76448504f303..1fed441192bd 100644 > --- a/include/util.h > +++ b/include/util.h > @@ -218,6 +218,7 @@ unsigned int count_string_array(const char **nodes); > void free_string_array(char **nodes); > int read_lines_notify(int fd, char *buf, int buf_size, int *buf_offset, > LOGLEVEL level); > +long long get_output_size(struct img_type *img); > > /* Decryption key functions */ > int load_decryption_key(char *fname); > Acked-by: Stefano Babic <sbabic@denx.de> Best regards, Stefano Babic
diff --git a/core/util.c b/core/util.c index a9353ca8cb27..30c7e0b7aece 100644 --- a/core/util.c +++ b/core/util.c @@ -894,3 +894,43 @@ int read_lines_notify(int fd, char *buf, int buf_size, int *buf_offset, return n; } + +long long get_output_size(struct img_type *img) +{ + char *output_size_str = NULL; + long long bytes = img->size; + + if (img->compressed) { + output_size_str = dict_get_value(&img->properties, "decompressed-size"); + + bytes = ustrtoull(output_size_str, 0); + if (errno) { + ERROR("decompressed-size argument: ustrtoull failed"); + return -1; + } + + if (bytes == 0) { + ERROR("UBIFS to be decompressed, but decompressed-size not valid"); + return -1; + } + TRACE("Image is compressed, decompressed size %lld bytes", bytes); + + } else if (img->is_encrypted) { + + output_size_str = dict_get_value(&img->properties, "decrypted-size"); + + bytes = ustrtoull(output_size_str, 0); + if (errno){ + ERROR("decrypted-size argument: ustrtoull failed"); + return -1; + } + + if (bytes < AES_BLK_SIZE) { + ERROR("Encrypted image size (%lld) too small", bytes); + return -1; + } + TRACE("Image is crypted, decrypted size %lld bytes", bytes); + } + + return bytes; +} diff --git a/handlers/ubivol_handler.c b/handlers/ubivol_handler.c index 80db4994c8d9..bf8c035e1b81 100644 --- a/handlers/ubivol_handler.c +++ b/handlers/ubivol_handler.c @@ -147,46 +147,6 @@ static int check_ubi_alwaysremove(struct img_type *img) return ret; } -static long long get_output_size(struct img_type *img) -{ - char *output_size_str = NULL; - long long bytes = img->size; - - if (img->compressed) { - output_size_str = dict_get_value(&img->properties, "decompressed-size"); - - bytes = ustrtoull(output_size_str, 0); - if (errno) { - ERROR("decompressed-size argument: ustrtoull failed"); - return -1; - } - - if (bytes == 0) { - ERROR("UBIFS to be decompressed, but decompressed-size not valid"); - return -1; - } - TRACE("Image is compressed, decompressed size %lld bytes", bytes); - - } else if (img->is_encrypted) { - - output_size_str = dict_get_value(&img->properties, "decrypted-size"); - - bytes = ustrtoull(output_size_str, 0); - if (errno){ - ERROR("decrypted-size argument: ustrtoull failed"); - return -1; - } - - if (bytes < AES_BLK_SIZE) { - ERROR("Encrypted image size (%lld) too small", bytes); - return -1; - } - TRACE("Image is crypted, decrypted size %lld bytes", bytes); - } - - return bytes; -} - static int update_volume(libubi_t libubi, struct img_type *img, struct ubi_vol_info *vol) { diff --git a/include/util.h b/include/util.h index 76448504f303..1fed441192bd 100644 --- a/include/util.h +++ b/include/util.h @@ -218,6 +218,7 @@ unsigned int count_string_array(const char **nodes); void free_string_array(char **nodes); int read_lines_notify(int fd, char *buf, int buf_size, int *buf_offset, LOGLEVEL level); +long long get_output_size(struct img_type *img); /* Decryption key functions */ int load_decryption_key(char *fname);
Signed-off-by: Dominique Martinet <dominique.martinet@atmark-techno.com> --- Note this patch applies on top of my utils: add read_lines_notify helper patch. It's simple enough to rebase if required though but that would explain if it doesn't apply cleanly for you, I'm not sure which is preferable -- unless you have more remarks the run_system_cmd fixes are probably going to get in first so I left it like this. core/util.c | 40 +++++++++++++++++++++++++++++++++++++++ handlers/ubivol_handler.c | 40 --------------------------------------- include/util.h | 1 + 3 files changed, 41 insertions(+), 40 deletions(-)