bug-parted
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: question about exception throwing and ped_device_write.


From: Andrew Clausen
Subject: Re: question about exception throwing and ped_device_write.
Date: Tue, 4 Nov 2003 22:46:28 +1100
User-agent: Mutt/1.5.4i

On Tue, Nov 04, 2003 at 11:47:32AM +0100, Sven Luther wrote:
> Hello, ...
> 
> In the process of adding amiga support to parted i came to write the
> following construct :
> 
>         if (_amiga_checksum (blk) != 0) {
>                 switch (ped_exception_throw(PED_EXCEPTION_ERROR,
>                         PED_EXCEPTION_FIX | PED_EXCEPTION_IGNORE |
>                       PED_EXCEPTION_CANCEL,
>                         _("%s : Bad checksum on block %d of type %s\n"),
>                         __func__, block,
>                       _amiga_block_id(blk->amiga_ID)))
>                 {
>                         case PED_EXCEPTION_CANCEL :
>                                 return NULL;
>                         case PED_EXCEPTION_FIX :
>                                 _amiga_calculate_checksum(AMIGA(blk));
>                                 ped_device_write (dev, blk, block, 1);
>                         case PED_EXCEPTION_IGNORE :
>                         case PED_EXCEPTION_UNHANDLED :
>                         default :
>                                 return blk;
>                 }
>         }
> 
> So, i check the checksum of the block, and ask if the checksum should be
> fixed if it is wrong.

I don't think you should offer the option of "Ignore"... either "Fix"
or "Cancel".  There is no reason not to fix, and you'll probably
end up asking the user a dozen times.

> What am i supposed to do if the ped_device_write (dev, blk, block, 1);
> fails ? In this case something is seriously wrong, and i should raise a
> PED_EXCEPTION_FATAL ?

Fatal is when Parted destroyed something, or similar, IMHO.

It's just an error... I'd do:

        if (!ped_device_write (dev, blk, block, 1))
                return 0;

In summary, I think you should structure this as:

        if (checksum(blk)) {
                if (ped_exception_throw(..., "Doesn't match")) {
                        add_checksum(blk);
                        if (!ped_device_write(..., blk))
                                return 0;
                }
        }

Cheers,
Andrew




reply via email to

[Prev in Thread] Current Thread [Next in Thread]