Hi Reuben,

Thanks for working on this.

Some comments below.

On Wed, Feb 02, 2011 at 05:23:57PM +1300, Reuben Dowle wrote:
> Cut down version of ubimkvol, ubirmvol and ubirsvol. Does not support 
> deleting or resizing named volumes (must use volume id), and does not support 
> specifying size as anything other than a byte count.
> 
> Signed-off-by: Reuben Dowle <reuben.dowle at navico.com>
> ---
> miscutils/ubi_attach_detach.c |  130 +++++++++++++++++++++++++++++++++++++----
>  1 files changed, 119 insertions(+), 11 deletions(-)
> 
> diff --git a/miscutils/ubi_attach_detach.c b/miscutils/ubi_attach_detach.c

[snip]

> +#define OPTION_n  (1 << 0)
> +#define OPTION_N  (1 << 1)
> +#define OPTION_s  (1 << 2)
> +#define OPTION_a  (1 << 3)
> +#define OPTION_m  (1 << 4)

This is not used, and not (yet) implemented. I guess it's better removed.

> +#define OPTION_t  (1 << 5)

[snip]

> +     if (do_attach || do_detach) {
> +             opt_complementary = "=1:m+:d+";
> +             opts = getopt32(argv, "m:d:n:N:s:a:m:t:", &mtd_num, &dev_num, 
> &vol_id, &vol_name, &size_bytes, &alignment, &type);

Do we actually need all these parameters for attach/detach?

Can't we combine these two getopt32 calls into one? This should make the 
generated code smaller.

> +     } else {
> +             opt_complementary = "n+:s+:a+:";
> +             opts = getopt32(argv, "n:N:s:a:t:", &vol_id, &vol_name, 
> &size_bytes, &alignment, &type);
> +     }
>       ubi_ctrl = argv[optind];
>  
>       fd = xopen(ubi_ctrl, O_RDWR);
> @@ -68,6 +138,7 @@ int ubi_attach_detach_main(int argc UNUSED_PARAM, char 
> **argv)
>       //      bb_error_msg_and_die("%s: not a char device", ubi_ctrl);
>  
>       if (do_attach) {
> +             struct ubi_attach_req req;
>               if (!(opts & OPTION_M))
>                       bb_error_msg_and_die("%s device not specified", "MTD");
>  
> @@ -76,11 +147,48 @@ int ubi_attach_detach_main(int argc UNUSED_PARAM, char 
> **argv)
>               req.ubi_num = dev_num;
>  
>               xioctl(fd, UBI_IOCATT, &req);
> -     } else { /* detach */
> +     } else if (do_detach) {
>               if (!(opts & OPTION_D))
>                       bb_error_msg_and_die("%s device not specified", "UBI");
>  
>               xioctl(fd, UBI_IOCDET, &dev_num);
> +     } else if (do_mkvol) {
> +             struct ubi_mkvol_req req;
> +             if (!(opts & OPTION_s))
> +                     bb_error_msg_and_die("%s size not specified", "UBI");
> +             if (!(opts & OPTION_N))
> +                     bb_error_msg_and_die("%s name not specified", "UBI");
> +
> +             req.vol_id = vol_id;
> +             if (opts & OPTION_t) {
> +                     if (type[0] == 's')
> +                             req.vol_type = UBI_STATIC_VOLUME;
> +                     else
> +                             req.vol_type = UBI_DYNAMIC_VOLUME;
> +             } else
> +                     req.vol_type = UBI_DYNAMIC_VOLUME;
> +             req.alignment = alignment;
> +             req.bytes = size_bytes;
> +             strcpy(req.name, vol_name);
> +
> +             printf("%d %d %lld %d %s\n", req.vol_id, req.alignment, 
> req.bytes, req.vol_type, req.name);

Is this necessary? If so, than a more verbose message would be better, 
preferably, after the successful completion of the ioctl() below.

> +
> +             xioctl(fd, UBI_IOCMKVOL, &req);
> +     } else if (do_rmvol) {
> +             if (!(opts & OPTION_n))
> +                     bb_error_msg_and_die("%s volume id not specified", 
> "UBI");
> +
> +             xioctl(fd, UBI_IOCRMVOL, &vol_id);
> +     } else if (do_rsvol) {
> +             struct ubi_rsvol_req req;
> +             if (!(opts & OPTION_s))
> +                     bb_error_msg_and_die("%s size not specified", "UBI");
> +             if (!(opts & OPTION_n))
> +                     bb_error_msg_and_die("%s volume id not specified", 
> "UBI");
> +             req.bytes = size_bytes;
> +             req.vol_id = vol_id;
> +
> +             xioctl(fd, UBI_IOCRMVOL, &req);
>       }
>  
>       if (ENABLE_FEATURE_CLEAN_UP)

baruch

-- 
                                                     ~. .~   Tk Open Systems
=}------------------------------------------------ooO--U--Ooo------------{=
   - [email protected] - tel: +972.2.679.5364, http://www.tkos.co.il -
_______________________________________________
busybox mailing list
[email protected]
http://lists.busybox.net/mailman/listinfo/busybox

Reply via email to