Click here to Skip to main content
15,390,695 members
Articles / Desktop Programming / MFC
Posted 19 Sep 2002


39 bookmarked

Write a UDF CDR

Rate me:
Please Sign up or sign in to vote.
4.82/5 (12 votes)
22 Jul 2003CPOL1 min read
How to write a CDR in UDF

Image 1


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
//For a blank CDR, you need to format it 
//Then you can write files onto it
//Append more files here...
//After you have writen ALL the files, close the session
//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


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


About the Author

United States United States
Wheels I reinvented on various embedded systems

*License Plate Reader
*TCP/IP stack
*Web Server
*Ethernet/SCSI/USB drivers
*FAT32/UDF file system
*JPEG/MJPEG encoder

Comments and Discussions

Questionload library WNASPI32.DLL not found Pin
jyotisawakare1-May-18 19:25
Memberjyotisawakare1-May-18 19:25 
GeneralNot working in Release mode Pin
Abinash Mohanty17-Aug-09 19:23
MemberAbinash Mohanty17-Aug-09 19:23 
GeneralRe:DVD-RAM FAT32 format in xp Pin
rrbhuvan10-Aug-07 4:33
Memberrrbhuvan10-Aug-07 4:33 
Generalno load Pin
Anima_in_Bofekor24-Nov-05 19:16
MemberAnima_in_Bofekor24-Nov-05 19:16 
QuestionHow many copies make by the CDR Pin
ThangaDharma5-Oct-05 7:22
MemberThangaDharma5-Oct-05 7:22 
GeneralClose Session Problem Pin
gzu5323-Aug-05 4:24
Membergzu5323-Aug-05 4:24 
GeneralCode corrections Pin
nico0418-Aug-04 22:18
Membernico0418-Aug-04 22:18 
QuestionHow to append files to a UDF CDR Pin
jacmod10-Aug-04 17:46
Memberjacmod10-Aug-04 17:46 
AnswerClose session Error: Pin
jacmod25-Aug-04 17:52
Memberjacmod25-Aug-04 17:52 
GeneralError in "Write Files" Process Pin
jacmod5-Jul-04 22:30
Memberjacmod5-Jul-04 22:30 
GeneralRe: Error in "Write Files" Process Pin
Anonymous15-Jul-04 20:34
MemberAnonymous15-Jul-04 20:34 
GeneralRe: Error in "Write Files" Process Pin
jacmod28-Jul-04 17:19
Memberjacmod28-Jul-04 17:19 
GeneralRe: Error in "Write Files" Process Pin
Anonymous29-Jul-04 1:28
MemberAnonymous29-Jul-04 1:28 
GeneralRe: Error in "Write Files" Process Pin
jacmod10-Aug-04 17:29
Memberjacmod10-Aug-04 17:29 
GeneralRe: Error in "Write Files" Process Pin
Tuan Hung 202129-Apr-21 8:15
MemberTuan Hung 202129-Apr-21 8:15 
GeneralError in SetWriteParameters() function Pin
sunil samineni24-Jun-04 0:37
Membersunil samineni24-Jun-04 0:37 
GeneralRe: Error in SetWriteParameters() function Pin
fullluck1-Jul-04 21:28
Memberfullluck1-Jul-04 21:28 
Generalexplain note 4 in ATAPI code fix Pin
fkking25-May-04 13:13
Memberfkking25-May-04 13:13 
GeneralRe: explain note 4 in ATAPI code fix Pin
fullluck27-May-04 1:20
Memberfullluck27-May-04 1:20 
GeneralRe: explain note 4 in ATAPI code fix Pin
fkking28-May-04 10:27
Memberfkking28-May-04 10:27 
QuestionWhat's mean this error code? Pin
holysky10019-May-04 19:20
Memberholysky10019-May-04 19:20 
AnswerRe: What's mean this error code? Pin
fkking25-May-04 13:15
Memberfkking25-May-04 13:15 
GeneralDVD RAM Format Pin
Anonymous12-May-04 5:48
MemberAnonymous12-May-04 5:48 
GeneralRe: DVD RAM Format Pin
nico0416-Aug-04 4:24
Membernico0416-Aug-04 4:24 
GeneralRe: DVD RAM Format Pin
KenThompson10-Mar-08 3:07
MemberKenThompson10-Mar-08 3:07 

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

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.