Click here to Skip to main content
Click here to Skip to main content

Write a UDF CDR

By , 22 Jul 2003
 

Introduction

Some electronic devices need to use CDR as storage media, and you have to append several files each time before the space is used out. In this case, UDF is a good solution, since for each writing, only 7 logic blocks of overhead are used. (Multisession CDs use several minutes for each session's leadout)

How to use the demo

(You need WNASPI32.dll to run the demo, which could be downloaded from Ahead.)
  • Select the CDR drive you want to write to.
  • Insert a blank disc, "Format" it.
  • Browse to select files, and write to the disc. (Now you can view the files using DirectCD).
  • You can list the content of the CDR, and restore files to hard disk
  • Close Session, now any CD drive can read it..

How to use the source code

//Create a variable for your drive
SCSI2 m_drive;
//m_HA:HostAdpaterNumber,m_ID:SCSI ID,m_LUN:LogicUnitNumber
m_drive.SCSISelectDevice(m_HA,m_ID,m_LUN);
//For a blank CDR, you need to format it 
m_drive.FormatDisc("VOL1");
//Then you can write files onto it
m_drive.WriteFiles("Test1.bmp");
//Append more files here...
//
//After you have writen ALL the files, close the session
m_drive.CloseSession();
//Now it's readable by regular CDROM drive.

Some useful functions

SCSIRead()      //Read data from CDR
WritePacket()      //Write packets to CDR
ReadTrackInfo()      //Read track info, like next writable address
ReadDiskInfo()      //Read disc info, like capacity
TestUnitReady()      //See if the drive is ready
LoadUnload()      //Eject/Close the tray
SetWriteParameters()    //Set write mode
SCSISetSpeed()      //Set read/write speed
ListFiles()      //List files on the CDR
SaveFileAs()      //Save file on CDR to hard disk

If you want to know more inside stuff

Things you need to have:
  • SCSI command block structure (ANSI X3.131-1994)
  • SCSI multimedia commands-2 (ANSI NCITS 333-2000)
  • OSTA specs: ECMA-167, Universal Disk Format Specification, ECMA-119
Things you need to know:
  • SCSI2 block command structure
  • Use of ASPI
  • Concepts about CDR: track, session, logical blocks, PMA, ATIP, TOC, write modes...
  • UDF(Volume structure, file system)

More info at my website.

Revision History

  • Ver 1.01
    • More comments, some code clean up
    • New function: ListFiles()
    • New function: SaveFileAs()
  • Ver 1.02
    • Some changes on the demo application

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

spotofleopard
Engineer
United States United States
Member
Wheels I reinvented on various embedded systems
 
*License Plate Reader
*TCP/IP stack
*Web Server
*HTTP/FTP/SMTP client
*Ethernet/SCSI/USB drivers
*FAT32/UDF file system
*JPEG/MJPEG encoder

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
GeneralNot working in Release modememberAbinash Mohanty17 Aug '09 - 19:23 
Dear All,
Can anyone please help me out why this program is not working in release mode.
GeneralRe:DVD-RAM FAT32 format in xpmemberrrbhuvan10 Aug '07 - 4:33 
How do i format maxwell dvd-ram disc in fat32 format in Windows XP..is any library or API available to do this?


Generalno loadmemberbose_sard24 Nov '05 - 19:16 
ftp://ftp6.nero.com/wnaspi32.dll
QuestionHow many copies make by the CDRmemberThangaDharma5 Oct '05 - 7:22 
How to fine the how many copies makes by the CDR
GeneralClose Session Problemmembergzu5323 Aug '05 - 4:24 
Hi,
 
When trying to write in mode 4 at the start of the CloseSession function my CD-Writer green light goes flashing endlessly. However the error codes returned will be SS_COMP until somewhere trying to read again and then it tells 0x2, 0x4, 0x8 which I think means :
 
Logical unit not ready, long write in progress
 
The write is only 0x168 bytes long. How could it be long? I waited nearly 30 mins...
 
Seems it makes it crash i did tried with Nero Burning ROM which is installed on that PC and CD-Burning works fine.
 
I would like to know what I could do to fix this.
 
Thanks a lot for your time.
 
Daniel

GeneralCode correctionsmembernico0418 Aug '04 - 22:18 
Hi all,
 
I'm in the process of understanding UDF CDR code. I have seen many isues which make the code not usable.
- Cache MUST be flushed after a writepacket
- In writefiles function, all files data are loaded in RAM memory : If you write 10 files of 20MB, 200MB will be loaded in RAM. Not a realistic programming method.
- function writepacket sends data to the burner without check/retry algorythm. It may work with small amount of data but will NEVER work with big amount of data. It may work untill the burner cache is full. Then it will crash.
- Code needs more than few modifications. There are many issues that need to be corrected to make code usable to generate a true UDF compliant disc. Using "udf_test" tool from Philips helps a lot in this task.
 

Nicolas
QuestionHow to append files to a UDF CDRmemberjacmod10 Aug '04 - 17:46 
Before i append files to the CDR,what should i do?
Could anyone detail the process?;)
 
Thanks for your responses.
 
photograph
AnswerClose session Error:memberjacmod25 Aug '04 - 17:52 
After i finished appending files to the disc, i got an
Error which means "Session Fixation Error-Imcomplete track in session ".
 
can anyone help me out of this question?;)
 
Thanks for your responses.
 
photograph
GeneralError in "Write Files" Processmemberjacmod5 Jul '04 - 22:30 
Hello,
It is able to format the CD-R. But when i tried to write a file onto it,I got an error code "Out of memory".
In function SCSI2::WriteFiles , the flags of the icbTag i got by the function "SCSIRead" is equal to 0.
 
Can anyone suggest a way out to this problem?
I very much appreciate your responses.
 
photograph
GeneralRe: Error in "Write Files" ProcesssussAnonymous15 Jul '04 - 20:34 
I think your ReadTrackInfo() don't return a correct value.
Check the value of next_writtable_addr is right.
If you use ATAPI CD-writer, see below to correct SetWriteParameters() function.

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Permalink | Advertise | Privacy | Mobile
Web02 | 2.6.130523.1 | Last Updated 23 Jul 2003
Article Copyright 2002 by spotofleopard
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid