Reading and writing cd sector by sector

been to these links

They helped but basically I’m to ignoant and need some pointing to where to read.

I would like in the end be able to read and write one byte at a time with my cd burner to any region of a cd, but I haven’t got an understanding of I guess cd-drive geometry.

example hardrives have so many heads / tracks / and sectors per track.

so I guess a cdrom has one head but how many tracks? and how many secotors per track?

The above links basically use assembly and pascal to write and read harddrives and floppy drives. I wan’t to know if they can be adapted to write to cdroms. I realize that some of these assemlby routines use dos and bios calls which would completely bypass all cdrom drivers but I’m unsure as to wether I need a driver to do what I want since most new bios’s detect cdroms.

the harddrive is at address 80h so where’s the crdom’s address?

Not much help here…but I don’t think you can read anything less than a complete sector when you read from a CD disc. The number of bytes you will get depends on the mode of the track you are reading. The smallest size for data that I know of is 2048 bytes per sector. Audio has 2352 bytes per sector.

A CD has up to 99 tracks but that information is only available when you do a read TOC command to the drive. The number of sectors per track is found by track length in bytes divided by bytes per sector. Perhaps your idea of a ‘track’ is different than that of the CD specification.

Again, not sure if this is what you were asking for but I hope it helps a lil.

from what I’ve been reading that’s what every program has to do is read the toc of the cd before going on to read the rest of the cd. But that’s like haveing to read the fat sector of the harddrive or floppy before actually reading the drive… I’m asking for imformation more along the lines of driver level. Example cdrwin and other buring programs use aspi drivers or dos atapi drivers loaded in config sys to operate the cdrom drive. I need information on how the drivers operate the cdrom not how to make calls to the drivers. In the end I want to be able to move the cdrom lense in the smallest increment possible and scan the entire cd reguardless of toc or number of toc’s for that matter.

so when you say data track 2048 and music track 2352 that’s just a convetion like microsoft juliet

however it does lead me to believe cd tracks are not a fixed length but can vary. A single track could be 700mb. Hmm

It is not necessary to read the TOC before you read sectors from the CD. When you insert a CD into the drive, the drive’s firmware will automatically read the TOC to determine the type, location, and size of the user data tracks, nothing you can do about this. You can write a program to read any sector you want from the CD as long as it is a valid sector. The type of read command and settings you send to the drive determines the amount of bytes you get back. When you read from a CD, you can not get back anything less than a complete sector (I’ve never been able to anyway). You can not get one byte only.

All sectors on a CD are always 2352 bytes. For audio all of the bytes are user data (music). For Mode1 ROM, the 2352 bytes are made of 16 bytes ROM sync and header, 2048 bytes of user data and 288 bytes of EDC/ECC (error correction and detection codes).

The sector size of 2352 and 2048 are not just MS/Juliet conventions. These sector sizes are defined in the CD specifications RED book and Yellow book.

CDs can have up to 99 tracks. Tracks in this example mean user data tracks. For example, an audio CD might have 10 tracks and each track is a new song. When you press the ‘next track’ button you go to the next song. The drive knows where the next song is because it read the TOC as soon as you inserted the CD. And like you said, tracks are not fixed in length. They can be from 4 seconds long to the length of the entire CD. So, a CD has various sectors per track that all depends on how many minutes-seconds-frames the track is long.

Another form of a ‘track’ at a much lower level is the actual spiral of the data on the CD. In this case the tracks are typically around 1.5 microns apart from eachother. There is nothing you really need to know or can do about this type of track.

thank you for taking the time to instruct me richman I’ll do a search for the CD specifications RED book and Yellow book.

the second definition you have for tracks (spirals) 1.5 microns apart is what I’ve been refrencing because that’s physical. The dynamic tracks set up by the toc follow a set of rules manufacturers like to make and then break and call it copy protection; example put a rogue sector not defined by the toc so when you burn the cd the copy doesn’t have the magic sector and the consol laughs at you. But if as you say you can read any part of the cd despite the toc then this trick wouldn’t work. With stamped cd’s and layerd dvd’s even the physical characteristics are being tweaked though.

All sectors on a CD are always 2352 bytes I wonder if this is because your using DMA mode. since most of my experience is with harddrives and such I know if you read the harddrive through bios calls you can give the bios any sector size you want and it will get the harddrive to do it.

at this point I’ve decided I need direct control of hardware so I’ve been reading the atapi standard and how to communicate through the IDE controller.

I’ve never directly taken control of the ide controller the closest thing I’ve ever done to progrmming at the hardware level was with uarts and modems.

You’re welcome but I’m not trying to instruct, I am just trying to share what I have learned in the past 6 years. There are many things that I can not publicly discuss about the CD, DVD, HD, Blue-ray, Xbox, etc specifications. But I can share what is already considered ‘common public knowledge’ so to speak.

I think the biggest thing you should understand is that there are very major differences between optical discs and hard drives. I understand what you mean about talking to a hard drive through the BIOS and having a lot of control. However, this same thing is not as true for CD/DVD.

As I mentioned before, the sector size is defined in the specification and you can not simply read or write a byte from here or there at random (you must read/write entire sectors). Try to consider a sector as the absolute smallest thing on a CD. Even though CDs are random access, you still have to read and write complete sectors at a time. Also, when writing to CDs it must be sequential and you must write an entire sector during the write. In other words, you can not write a sector near the inside of the CD and then write the next sector near the outside. It just doesn’t work like hard drives do. But, you can read any valid sector from any place on the disc in any order that you wish. A valid sector is a sector that the firmware of the drive has determined to be somewhere between the end of leadin (TOC) and the beginning of leadout. And, of course, the firmware only knows this by first scanning the TOC when you insert the CD. So, the theory of placing a ‘rogue’ sector on the CD that is not referrenced in the TOC is not possible.

I can not guarantee that all of the above is 100% accurate but I bet it’s pretty close. I have tried to word it so that it makes the most sense. I hope it helps and feel free to ask more questions.


Hi, all. I am new to this forum. I have been searching for a CD-ROM drive that can read data at sector location -150. My TDK drive can read up to -145 and cannot go further to -150. Any idea ? I am using CDtools.exe from