Archive

Archive for October, 2009

Improving Backup Reliability on Optical Storage

October 24th, 2009 No comments

Many end-users are using CD-R or DVD-R media as a convenient storage for backup data. However the quality of writable media degrades over time; which inevitably leads to a loss of all or part of the stored data. In some cases, data loss can already occur within the first year after a media has been written. As a consequence, the data needs to be copied in regular intervals, before data loss happens.
Now the important point is how to determine the right time when a disc has to be copied. If copied too early, time and media are wasted. If copied too late, data loss has already occurred which might not be recoverable. Unlike a piece of printed paper, where the text on it is fading over time, the degradation of data on optical media is usually not linear and there are no clear signs that would signal if the media is about to fail or not.

There is an open source project called dvddisaster which has tackled this problem using an interesting approach: Before an ISO image is written on a media, it can be stuffed with extra error correction data that will be transparrently embedded along with the actual data. This gives gives extra redundancy to an extent that can be controlled by the user and depending on the free space remaining on the media.

While the idea of adding redundant error correction codes to important data is not new, the novelty lies in the concept of adding this information invisibly on a level below the visible file system. If any disk with error correction information is starting to deteriorate and some sectors become unreadable, we can still recover the real data that was stored in these sectors – provided that the redundant data is enough for recovery.
This brings the advantage that slight data loss is not critical, but can now be used as an indicator of aging media. With this approach one can actually wait with copying until some of the media’s sectors become illegible – wthout having to fear any loss of data.

dvddisaster is open source software, which makes it less likely that you will find a discontinued software if you need to recover a CD 10 years from now. As an added benefit, it is cross platform, so you should be able to use it from Windows and Linux.

C++ Callbacks

October 11th, 2009 No comments

C – style callbacks are straight forward to declare and implement. C++ callbacks are less trivial due to the nature of the thiscall convention. Calls adhering to this convention transparently pass a pointer of the current instance to the function/method.
How the instance pointer is passed is compiler specific. GCC pushes it on the stack as a last parameter, MSVC will pass it in ECX except when calling vararg functions.
It is still possible to execute callbacks if they are stored in the same class, but when stored in an external location it is not possible to invoke a thiscall callback directly. Here is a small workaround:

typedef struct SomeStorage
{
    // ...
    VOID (MyClass::*MyMethodPtr)(); 
};
class Myclass
{
public:
    void SomeMethod()
    {
        SomeStorage ss;
        ss.MyMethodPtr = &MyClass::MyMethod;
        this->MyMethodPtr= ss.MyMethodPtr;
        (this->*MyMethodPtr)( void );
    }
private:
    void (MyClass::*MyMethodPtr)( void ); // dummy
    void MyMethod()
    {
        // ...
    }
};

The trick is to temporarily store the retrieved pointer in a member variable and dereference it from there using the ->* operator.

See: