Click here to Skip to main content
15,889,867 members
Articles / Desktop Programming / MFC

Write a UDF CDR

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

Image 1

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)


Written By
Engineer
United States United States
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

Comments and Discussions

 
GeneralRe: Problem Pin
Anonymous9-Oct-02 3:58
Anonymous9-Oct-02 3:58 
GeneralRe: Problem Pin
chen9-Oct-02 5:13
chen9-Oct-02 5:13 
GeneralRe: Problem Pin
spotofleopard9-Oct-02 5:46
spotofleopard9-Oct-02 5:46 
GeneralRe: Problem Pin
tututoto29-Jan-03 23:22
tututoto29-Jan-03 23:22 
GeneralNice to know how it works, but... Pin
Kochise23-Sep-02 0:35
Kochise23-Sep-02 0:35 
GeneralRe: Nice to know how it works, but... Pin
spotofleopard23-Sep-02 4:03
spotofleopard23-Sep-02 4:03 
GeneralRe: Nice to know how it works, but... Pin
Christian Graus23-Sep-02 12:03
protectorChristian Graus23-Sep-02 12:03 
GeneralRe: Nice to know how it works, but... Pin
Kochise23-Sep-02 21:41
Kochise23-Sep-02 21:41 
You're a bit harsh with 'tapes' Wink | ;) As i said, thanks, for a tempo storage, it's really a nice system you provided us. And *YES*, CD are far more wide spread than magneto-optical drives (due to their low cost). But sometimes cost mean also quality, and MO drives cost far more than CD drives. I already burnt hundreds of HiQual CD brand that cannot be read after 3 months (I also *ALWAYS* avoid to burn them faster than 4x). I still have *NO* problems with my MO after years, and can trustfully reuse my old cartidge without any doubts to be able to read back what i wrote on so many times before. I don't trust anymore on CDs (nor tapes, be sure of that)...

I said nothing against you nor your project, just that a reliable way to save data should not use CDs, but some other technologies that people hardly heard about, most of the time because these are more expensive, but far more reliable too. MO drives can be connected to the SCSI bus. And the more important I learnt in your project is the way to access the SCSI bus. It was something missing in my knowledge, thanks alot dear ! But as there is no specific format for MO, I was already saving data immediatly on it with standard file functions (fopen/fwrite/fread/fclose, or CreateFile/WriteFile/ReadFile/CloseHandle)...

Kochise

PS : Your project is still very necessary for data sharing, as CD are more common than MO (you're right about it). Don't feel bothered by my post, please...
GeneralRe: Nice to know how it works, but... Pin
spotofleopard24-Sep-02 5:37
spotofleopard24-Sep-02 5:37 
GeneralRe: Nice to know how it works, but... Pin
Kochise24-Sep-02 5:53
Kochise24-Sep-02 5:53 
GeneralRe: Nice to know how it works, but... Pin
spotofleopard24-Sep-02 6:08
spotofleopard24-Sep-02 6:08 
GeneralLegality... Pin
Christian Graus22-Sep-02 17:46
protectorChristian Graus22-Sep-02 17:46 
GeneralRe: Legality... Pin
Joao Vaz23-Sep-02 1:53
Joao Vaz23-Sep-02 1:53 
GeneralRe: Legality... Pin
spotofleopard23-Sep-02 3:56
spotofleopard23-Sep-02 3:56 
GeneralRe: Legality... Pin
Joao Vaz23-Sep-02 4:19
Joao Vaz23-Sep-02 4:19 
QuestionA Little Dangerous....? Pin
Fred21-Sep-02 4:42
Fred21-Sep-02 4:42 
AnswerRe: A Little Dangerous....? Pin
spotofleopard21-Sep-02 14:15
spotofleopard21-Sep-02 14:15 
GeneralRe: A Little Dangerous....? Pin
Fred22-Sep-02 2:09
Fred22-Sep-02 2:09 
GeneralGood~~ Pin
Leaves21-Sep-02 4:17
Leaves21-Sep-02 4:17 

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.