Question

I'm trying to finalize a Live File System (or "Live UDF") optical disc in C#. From what I understand from reading MSDN and TechNet articles along with various forum postings, the Image Mastering API (or IMAPI) does not support this type of filesystem, and in my coding efforts I have been unsuccessful at finalizing a LiveUDF disc using IMAPI. As a result, I'm using the DeviceIoControl function using the FSCTL_MAKE_MEDIA_COMPATIBLE control code.

First, I was calling DeviceIoControl synchronously but the function would return 1117 and the disc would eventually become finalized minutes later. This outcome is unacceptable as I need the process to return only upon ultimate failure or actual success.

Next, I moved on to calling DeviceIoControl asynchronously by opening the device handle with CreateFile with the FILE_FLAG_OVERLAPPED (0x40000000) dwFlagsAndAttributes flag and passing a NativeOverlapped object to the DeviceIoControl call. Before that, obviously, I set up a IOCompletionCallback to handle any Overlapped events.

With calling DeviceIoControl asynchronously as described, it still returns 1117 almost immediately (as it does when called synchronously), the IOCompletionCallback method is never invoked and the disc becomes finalized minutes later.

My question is: How do I finalized a Live File System (or "Live UDF") optical disc in C# on the Windows 7 platform using C# and DeviceIoControl (either synchronously or asynchronously, with the ability to "wait" for its process to complete to capture the ultimate success or failure result)?

Much thanks in advance.

Was it helpful?

Solution

Calling DeviceIoControl passing the IOCTL_SCSI_PASS_THROUGH_DIRECT control code and a SCSI_PASS_THROUGH_DIRECT structure defined with the Close Track/Session SCSI MultiMedia Command (MMC) has provided a way to finalize a Live UDF disc and have the DeviceIoControl function return upon final success or failure.

I pieced this together reading the INCITS T10 Technical Committee's proposals for SCSI MultiMedia Commands and a project at http://sourceforge.net/projects/bwgburn/.

Basically, it came down to just sending SCSI commands to the device (which are defined in the Committee's proposals).

OTHER TIPS

I ran across the same problem recently, and found that the .ForceMediaToBeClosed of the IMAPI2.MsftDiscFormat2Data can be used to finalize the CD after the burn finishes. This is my code (in powershell):

$TargetFolder="c:\path\to\files\to\be\burned"
$DiskMaster = New-Object -com IMAPI2.MsftDiscMaster2
$DiscRecorder = New-Object -com IMAPI2.MsftDiscRecorder2
$id = $DiskMaster.Item(0) #specify drive index here
$DiscRecorder.InitializeDiscRecorder($id)               
$FileSystemImage = New-Object -com IMAPI2FS.MsftFileSystemImage
$dir = $FileSystemImage.Root
$DiscFormatData  = New-Object -com IMAPI2.MsftDiscFormat2Data
$DiscFormatData.Recorder = $DiscRecorder
$DiscFormatData.ClientName = 'cd label' #specify cd label here
$DiscFormatData.ForceMediaToBeClosed = $true   #to finalize cd after burn
$FileSystemImage.ChooseImageDefaults($DiscRecorder)                
$dir.AddTree($TargetFolder, $false)
$result = $FileSystemImage.CreateResultImage()
$stream = $result.ImageStream
$DiscFormatData.Write($stream)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top