by Yavor N.
15. June 2010 08:35
If you want to erase the contents of a DVD+RW media, the PrimoBurner Device.Erase/Device.Format methods will not do. To achieve this you should actually write 0s in the sectors that contain the data you want to erase. This could be done using code that looks like:
...
PrimoSoftware.Burner.Device device;
...
// Initialize the device variable using PrimoSoftware.Burner.DeviceEnumerator object
...
// Set this variable with the desired number of blocks to fill with 0s.
// 2000 blocks are enough to erase the ISO and UDF file system descriptors
// from the target medium.
long blocksToWrite = 2000;
device.StartDVDSession(false, WriteMethod.DvdIncremental, false);
// Start writing 0s from the first block on the target medium
device.NewSessionStartAddress = 0;
device.StartDVDTrack((int)blocksToWrite));
const int writeChunk = 32;
// Create a data buffer filled with 0s that will be written repeatedly on the target medium
byte[] dummyBuffer = new byte[writeChunk * (int)BlockSize.Dvd];
long lAddrBuf1 = 0;
long lAddrBuf2 = 0;
int buf1Size = 0;
int buf2Size = 0;
int blocks = blocksToWrite;
int blocksChunk = 0;
// Perform the actual writing
while ((blocksChunk = Math.Min(blocks, writeChunk)) > 0)
{
buf1Size = 0;
buf2Size = 0;
device.LockOutputBuffer(blocksChunk, out lAddrBuf1, out buf1Size, out lAddrBuf2, out buf2Size);
...
// Copy content from dummyBuffer into the memory pointed to
// by lAddrBuf1 and lAddrBuf2
...
device.UnlockOutputBuffer(blocksChunk);
blocks -= blocksChunk;
}
device.EndDVDTrack(true);
device.EndDVDSession(true);
...
The attached archive contains a sample C# project that demonstrates this algorithm. The actual implementation is in the Eraser.cs file. Note that it is possible to erase the content of the first 2000 blocks or of the entire DVD+RW medium thus performing quick or full 'erase', quick being considerably faster than full.
CleanDVDPlusRW.zip (6,26 kb)