Search code examples
c#.netimapi

Available space on blank dvd / blu-ray discs (IMAPI)


Since my original question was a bit too vague, let me clarify.

My goals are:

  1. to estimate blank disc size after selecting filesystem via IMAPI
  2. to estimate space which my file will consume on this disc if i burn it.

What i would like to know:

  1. Is it possible to get bytes per sector for selected file system programmatically
  2. If not, is there default value for bytes per sector which IMAPI uses for different file systems / media types, and is it documented somewhere.

Solution

  • Ok, so the short answer to my question is: one can safely assume, that sector size for DVD/BD discs = 2048 bytes.

    The reason, why i was getting different sizes during my debug sessions, was because of an error in code, which retrieved sectors count :)

    Mentioned code block was copypasted from http://www.codeproject.com/Articles/24544/Burning-and-Erasing-CD-DVD-Blu-ray-Media-with-C-an , so just in case im posting a quick fix.

    original code:

    discFormatData = new MsftDiscFormat2Data();
    discFormatData.Recorder = discRecorder;
    IMAPI_MEDIA_PHYSICAL_TYPE mediaType = discFormatData.CurrentPhysicalMediaType;
    fileSystemImage = new MsftFileSystemImage();
    fileSystemImage.ChooseImageDefaultsForMediaType(mediaType);
    if (!discFormatData.MediaHeuristicallyBlank)
    {
         fileSystemImage.MultisessionInterfaces = discFormatData.MultisessionInterfaces;
         fileSystemImage.ImportFileSystem();
    }
    Int64 freeMediaBlocks = fileSystemImage.FreeMediaBlocks;
    

    fixed code:

    discFormatData = new MsftDiscFormat2Data { Recorder = discRecorder };
    fileSystemImage = new MsftFileSystemImage();
    fileSystemImage.ChooseImageDefaults(discRecorder);
    if (!discFormatData.MediaHeuristicallyBlank)
    {
        fileSystemImage.MultisessionInterfaces = discFormatData.MultisessionInterfaces;
        fileSystemImage.ImportFileSystem();
    }
    Int64 freeMediaBlocks = fileSystemImage.FreeMediaBlocks;