Message ID | 1562763153-13674-2-git-send-email-philippe.reynes@softathome.com |
---|---|
State | Accepted |
Headers | show |
Series | handlers: ubivol: add support to auto-resize an ubi volume | expand |
On 10/07/19 14:52, Philippe Reynes wrote: > This commit add a function resize_volume that can > be used by the handler adjust_volume but it could > also be used by another handler. It prepare the > new property auto-resize for ubi image handler. > > Signed-off-by: Philippe Reynes <philippe.reynes@softathome.com> > --- > handlers/ubivol_handler.c | 61 +++++++++++++++++++++++++---------------------- > 1 file changed, 33 insertions(+), 28 deletions(-) > > diff --git a/handlers/ubivol_handler.c b/handlers/ubivol_handler.c > index f683bfe..4de4914 100644 > --- a/handlers/ubivol_handler.c > +++ b/handlers/ubivol_handler.c > @@ -229,31 +229,7 @@ static int update_volume(libubi_t libubi, struct img_type *img, > return err; > } > > -static int install_ubivol_image(struct img_type *img, > - void __attribute__ ((__unused__)) *data) > -{ > - struct flash_description *flash = get_flash_info(); > - struct ubi_part *ubivol; > - int ret; > - > - /* find the volume to be updated */ > - ubivol = search_volume_global(img->volname); > - > - if (!ubivol) { > - ERROR("Image %s should be stored in volume " > - "%s, but no volume found", > - img->fname, > - img->volname); > - return -1; > - } > - ret = update_volume(flash->libubi, img, > - &ubivol->vol_info); > - return ret; > - > -} > - > -static int adjust_volume(struct img_type *cfg, > - void __attribute__ ((__unused__)) *data) > +static int resize_volume(struct img_type *cfg, long long size) > { > struct flash_description *nandubi = get_flash_info(); > struct ubi_part *ubivol; > @@ -308,8 +284,8 @@ static int adjust_volume(struct img_type *cfg, > } > > /* Check if size is changed */ > - requested_lebs = cfg->partsize / mtd_info->dev_info.leb_size + > - ((cfg->partsize % mtd_info->dev_info.leb_size) ? 1 : 0); > + requested_lebs = size / mtd_info->dev_info.leb_size + > + ((size % mtd_info->dev_info.leb_size) ? 1 : 0); > allocated_lebs = ubivol->vol_info.rsvd_bytes / mtd_info->dev_info.leb_size; > > if (requested_lebs == allocated_lebs && > @@ -342,7 +318,7 @@ static int adjust_volume(struct img_type *cfg, > req.vol_type = req_vol_type; > req.vol_id = UBI_VOL_NUM_AUTO; > req.alignment = 1; > - req.bytes = cfg->partsize; > + req.bytes = size; > req.name = cfg->volname; > err = ubi_mkvol(nandubi->libubi, node, &req); > if (err < 0) { > @@ -373,6 +349,35 @@ static int adjust_volume(struct img_type *cfg, > return 0; > } > > +static int install_ubivol_image(struct img_type *img, > + void __attribute__ ((__unused__)) *data) > +{ > + struct flash_description *flash = get_flash_info(); > + struct ubi_part *ubivol; > + int ret; > + > + /* find the volume to be updated */ > + ubivol = search_volume_global(img->volname); > + > + if (!ubivol) { > + ERROR("Image %s should be stored in volume " > + "%s, but no volume found", > + img->fname, > + img->volname); > + return -1; > + } > + ret = update_volume(flash->libubi, img, > + &ubivol->vol_info); > + return ret; > + > +} > + > +static int adjust_volume(struct img_type *cfg, > + void __attribute__ ((__unused__)) *data) > +{ > + return resize_volume(cfg, cfg->partsize); > +} > + > static int ubi_volume_get_info(char *name, int *dev_num, int *vol_id) > { > struct ubi_part *ubi_part; > Applied to -master, thanks ! Best regards, Stefano Babic
diff --git a/handlers/ubivol_handler.c b/handlers/ubivol_handler.c index f683bfe..4de4914 100644 --- a/handlers/ubivol_handler.c +++ b/handlers/ubivol_handler.c @@ -229,31 +229,7 @@ static int update_volume(libubi_t libubi, struct img_type *img, return err; } -static int install_ubivol_image(struct img_type *img, - void __attribute__ ((__unused__)) *data) -{ - struct flash_description *flash = get_flash_info(); - struct ubi_part *ubivol; - int ret; - - /* find the volume to be updated */ - ubivol = search_volume_global(img->volname); - - if (!ubivol) { - ERROR("Image %s should be stored in volume " - "%s, but no volume found", - img->fname, - img->volname); - return -1; - } - ret = update_volume(flash->libubi, img, - &ubivol->vol_info); - return ret; - -} - -static int adjust_volume(struct img_type *cfg, - void __attribute__ ((__unused__)) *data) +static int resize_volume(struct img_type *cfg, long long size) { struct flash_description *nandubi = get_flash_info(); struct ubi_part *ubivol; @@ -308,8 +284,8 @@ static int adjust_volume(struct img_type *cfg, } /* Check if size is changed */ - requested_lebs = cfg->partsize / mtd_info->dev_info.leb_size + - ((cfg->partsize % mtd_info->dev_info.leb_size) ? 1 : 0); + requested_lebs = size / mtd_info->dev_info.leb_size + + ((size % mtd_info->dev_info.leb_size) ? 1 : 0); allocated_lebs = ubivol->vol_info.rsvd_bytes / mtd_info->dev_info.leb_size; if (requested_lebs == allocated_lebs && @@ -342,7 +318,7 @@ static int adjust_volume(struct img_type *cfg, req.vol_type = req_vol_type; req.vol_id = UBI_VOL_NUM_AUTO; req.alignment = 1; - req.bytes = cfg->partsize; + req.bytes = size; req.name = cfg->volname; err = ubi_mkvol(nandubi->libubi, node, &req); if (err < 0) { @@ -373,6 +349,35 @@ static int adjust_volume(struct img_type *cfg, return 0; } +static int install_ubivol_image(struct img_type *img, + void __attribute__ ((__unused__)) *data) +{ + struct flash_description *flash = get_flash_info(); + struct ubi_part *ubivol; + int ret; + + /* find the volume to be updated */ + ubivol = search_volume_global(img->volname); + + if (!ubivol) { + ERROR("Image %s should be stored in volume " + "%s, but no volume found", + img->fname, + img->volname); + return -1; + } + ret = update_volume(flash->libubi, img, + &ubivol->vol_info); + return ret; + +} + +static int adjust_volume(struct img_type *cfg, + void __attribute__ ((__unused__)) *data) +{ + return resize_volume(cfg, cfg->partsize); +} + static int ubi_volume_get_info(char *name, int *dev_num, int *vol_id) { struct ubi_part *ubi_part;
This commit add a function resize_volume that can be used by the handler adjust_volume but it could also be used by another handler. It prepare the new property auto-resize for ubi image handler. Signed-off-by: Philippe Reynes <philippe.reynes@softathome.com> --- handlers/ubivol_handler.c | 61 +++++++++++++++++++++++++---------------------- 1 file changed, 33 insertions(+), 28 deletions(-)