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

3

10

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.
Raeraeann answered 14/9, 2012 at 11:11 Comment(9)
Why isn't WMI an option?Terebinthine
@S.L. Barth, I dont think so.Raeraeann
@PhonicUK, past experience :) I will use it, if there is no other way. I was hoping to get those values via IMAPI, tbh.Raeraeann
@HenkHolterman You're forgetting R and RW media (CD-R/CD-RW/DVD-R/DVD+R/DVD-RW)Meraz
yes, i am obv talking about R and RW media, i'm sorry if it wasnt clear enoughRaeraeann
"since ISO 9660 works by segmenting the CD-ROM into logical blocks, the size of these blocks is found in the primary volume descriptor as well."Terebinthine
@PhonicUK, from what i can tell, there is no guarantee that media is using ISO 9660, not when it comes to dvd/blu-ray. But i think it is possible to detect which fs it uses exactly and then somehow extract this info depending on fs. Still looks like a bit too much work for what seems to be such a simple/common task, huh =\Raeraeann
Of course if you know free/used blocks and the total size of the storage volume (ignoring used/free space) then you can calculate the size per block and then work the rest out. Size per block = total size / (blocks used + blocks free), free space = size per block * blocks free. I'd be surprised if you found the block size was anything other than 1K though.Terebinthine
@Nik You are right - I misread the question.Shriek
R
4

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;
Raeraeann answered 17/9, 2012 at 8:12 Comment(1)
I am using the same code. But in my case, freeMediaBlocks for an empty DVD (4.7GB) returns 681574400 which means the capacity is 650 MB. However, the correct number of freeMediaBlocks should be 2,295,104. Is there anything I miss?Condyle
T
1

via IMAPI - IWriteEngine2::get_BytesPerSector

http://msdn.microsoft.com/en-us/library/windows/desktop/aa832661(v=vs.85).aspx

This project uses a managed IMAPI2 wrapper to make life easier - http://www.codeproject.com/Articles/24544/Burning-and-Erasing-CD-DVD-Blu-ray-Media-with-C-an

Terebinthine answered 14/9, 2012 at 15:49 Comment(2)
oh, i ve missed this interface totally :S As soon as i have chance i will try to figure out how to work with it and report the results. :) CHeers. Still though, if some1 can share a code sample - that would be real nice.Raeraeann
as stated on msdn: "Retrieves the number of bytes to use for each sector during writing. The returned value indicates what the value previously set with IWriteEngine2::put_BytesPerSector, and does not return a current bytes per sector value for media." So, this property serves different purpose.Raeraeann
T
0

If you know free/used blocks and the total size of the storage volume (ignoring used/free space) then you can calculate the size per block and then work the rest out.

block size = total size / (blocks used + blocks free)
free space = size per block * blocks free

I'd be surprised if you found the block size was anything other than 1K though

Terebinthine answered 14/9, 2012 at 13:3 Comment(4)
But the thing is - i dont know the total size. That is why i need the sector size. So i can multiply it by sectors count and get free/used/total space in bytes. At least thats what i came up with >_>Raeraeann
And no, its not 1k. I debugged my app with various media types and block size varied from 2048 to 4096 (i calculated those manually by looking at total sizes, displayed in windows explorer)Raeraeann
Just use a DriveInfo instance to get the same total size displayed in explorer to do the calculation. - msdn.microsoft.com/en-us/library/system.io.driveinfo.aspxTerebinthine
As i mentioned above DriveInfo is not working for compact discs. Well sometimes it does, but most of the time the IsReady property returns false. And, obviously it does not support blank discs. Let me edit an origianl question, to make my question clearer.Raeraeann

© 2022 - 2024 — McMap. All rights reserved.