How to read multi-session DVD disc size in Windows?

Attempting to read the sizes of disks created in multiple sessions using GetDiskFreeSpaceEx () yields the size of only the last session. How to read the number and sizes of all sessions in C / C ++?

Thanks.

+6
c ++ winapi diskspace
source share
3 answers

You might want to look at the DeviceIoControl API function . See here for control codes. Here is an example of code that retrieves the size of a CD. Replace

CreateFile(TEXT("\\\\.\\PhysicalDrive0") 

eg,

 CreateFile(TEXT("\\\\.\\F:") /* Drive is F: */ 

if you want to.

Note. The page indicates that DeviceIoControl can be used to "get information about a floppy disk, hard drive, tape drive or CD-ROM", but I also tested it on a DVD, and it seemed to work fine. I did not have access to multisession DVDs for testing, so you have to check if this works on its own. If it does not work, I would try some other control codes, at least IOCTL_DISK_GET_DRIVE_GEOMETRY_EX , IOCTL_DISK_GET_DRIVE_LAYOUT_EX , IOCTL_DISK_GET_LENGTH_INFO and IOCTL_DISK_GET_PARTITION_INFO_EX .


If all else fails with DeviceIoControl, you can use the Windows Image Management API (IMAPI). You will need the v2 API (included in Vista and later, you can add it in XP and 2003, see here: What's New in IMAPIv2 ) to support DVD. This API is primarily intended for burning CDs, but it may contain some functions for extracting the size of the disc, I would find it strange if this did not happen. In particular, this example seems interesting. I do not know if this file works for multisession discs, but since it can create them, I assume that this is possible.

Here are some resources for IMAPI:
MSDN - IMAPI
Interfaces MSDN - IMAPI
MSDN - creating multisession drives with IMAPI (note: example with VB, not C or C ++)

+3
source share

Hi, I have at least 2 solutions for you:

1) Download dvd+rw-mediainfo.exe from http://fy.chalmers.se/~appro/linux/DVD+RW/tools/win32/ , this is a tool that reads information about your disk. Then just make a system call from your application and analyze the results. Here is an example output:

 D:\Downloads>"dvd+rw-mediainfo.exe" f: INQUIRY: [HL-DT-ST][DVDRAM GT30N ][1.01] GET [CURRENT] CONFIGURATION: Mounted Media: 10h, DVD-ROM Current Write Speed: 1.0x1385=1385KB/s Write Speed #0: 8.0x1385=11080KB/s Write Speed #1: 4.0x1385=5540KB/s Write Speed #2: 2.0x1385=2770KB/s Write Speed #3: 1.0x1385=1385KB/s Speed Descriptor#0: 00/2292991 R@8.0x1385 =11080KB/s W@8.0x1385 =11080KB/s READ DVD STRUCTURE[#0h]: Media Book Type: 01h, DVD-ROM book [revision 1] Legacy lead-out at: 2292992*2KB=4696047616 READ DISC INFORMATION: Disc status: complete Number of Sessions: 1 State of Last Session: complete Number of Tracks: 1 READ TRACK INFORMATION[#1]: Track State: complete Track Start Address: 0*2KB Free Blocks: 0*2KB Track Size: 2292992*2KB Last Recorded Address: 2292991*2KB FABRICATED TOC: Track#1 : 17@0 Track#AA : 17@2292992 Multi-session Info: # 1@0 READ CAPACITY: 2292992*2048=4696047616 

2) Examine mciSendString from [DllImport("winmm.dll", EntryPoint = "mciSendStringA", CharSet = CharSet.Ansi)] , I suspect you may send some command and get the desired results.

PS: you can download dvd+rw-mediainfo.exe sources from here and continue your research, I just give you ideas to think about.

UPDATE

Source code link updated, thanks @oystein

+1
source share

There are many ways to do this, since DVDs have several interfaces for this, due to issues with past and backward compatibility.

You can send the IOCTL_SCSI_PASSTHROUGH_DIRECT command to the DVD drive (for it, this will be a handle to the physical device). With it, you issue SCSI commands to which the disk will respond. You can read session information, disk drive information, and more. I believe dvd + rw-mediainfo.exe is causing these problems.

Unfortunately, the interface is a bit complicated and unclear, as this is a team within a team. Th Passthrough has a byte buffer, you will need to fill in the command structure.

Or you can call IOCTL_CDROM_READ_TOC_EX: http://www.osronline.com/ddkx/storage/k306_2cs2.htm

I also believe that the exact set of IOCTL / commands that will work depends on the disk and its strength.

Old disks will not support new interfaces, and some of the new disks will not support obsolete interfaces.

Thus, some libraries and tools can use one or more of these interfaces.

The coincidence of the old sessons is all pretty dirty, indeed, since most OSs don't care about them, only the very latest.

0
source share

All Articles