Writing to a CD using C

I want to write an existing ISO file to a CD using C. I am using an array of 256 bytes to read characters from the ISO file and trying to write it to the block file /dev/sr0. But I am getting the error message “No disk space present”, even though I have checked that the CD is a blank one. Can anybody suggest why this is not working?

I would be grateful if somebody could offer some advice on this matter.

Thanks for reading this!

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Since you don’t specify, is there a reason you must do this directly from
C? I do not believe, in any language, that you can treat optical devices
as regular writable devices. You could fairly easily write your 256-bite
blocks of data to a file and then burn that directly using something like
cdrecorder, though, without needing to reinvent the CD-burning wheel. You
could probably find the code to do the writing from the cdrecorder code as
well as long as you complied with its license.

Good luck.

On 03/04/2010 08:36 AM, arani wrote:
>
> I want to write an existing ISO file to a CD using C. I am using an
> array of 256 bytes to read characters from the ISO file and trying to
> write it to the block file /dev/sr0. But I am getting the error message
> “No disk space present”, even though I have checked that the CD is a
> blank one. Can anybody suggest why this is not working?
>
> I would be grateful if somebody could offer some advice on this
> matter.
>
> Thanks for reading this!
>
>
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.12 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iQIcBAEBAgAGBQJLj9YyAAoJEF+XTK08PnB57MkP/iR+NjUJT4n6Vl/kyFdcYapw
WHU+MbKn2yI8K3rmnBAFuGBrX9N1y0CUBYuTP4NYy/NQP5yOwQZvIbcv1WgRZKz0
IRDhGKRgdv2nAusFhkJLdxWcnFUbLPgiuLyQxMrs+NkCKVbrFQgXf2exdOP6JHwi
zLSarKQfHOiBHNSg/s/rVICv0IO1iNvcPQcusyZQBdyMWpoQEFqSJTVGZmfAT7nl
10E3msRTt74dfbLWAGao/oGAB9xvuHC6En18YLInBrjoeuilqhtSfYwxWVr8enSK
h58ni1wGRItEzEAskHJWxdaVe7uP7inlt0lpdez1dEN03MWwQotaHPiVkE/l/yMx
xOZCvXFmgWAubBEEqNL1eSueHsfJ5cGUav6N5ihv+xwcPqy4nQhGHsQrfZNeb0eR
HKKtv4XFQzPKUcUIr5Ei2i+W4FqN8kyR8iytp5V5sfbCRK7t85G9XLDBtc1CpHHV
TdoVheQGin81XT2SLUZq9vLds5FEkdxAdSOIiWlDK9xu0LXCZlBwXWs6k7M4Wxyj
49diM84FC3CAdfyNW1pjgx9EH3XinmXrwP/AfBra43KWNcWtpb6BGBPiqk0NPDbn
o+UYr5NezyA4dxj97OqQxq7hqqhqtTI3351QVZjp3oULECC/YBwsr5eZcgJg1O+B
HvaOwXmR26Ucbw8FKZ7y
=yqtk
-----END PGP SIGNATURE-----

‘growisofs’ can write to a CD/DVD, so I would suggest looking at it’s source code how they do it. I suspect there are some tricks involved how to keep buffers almost full and assure a constant flow of data.

Why not just call the wodim (cdrecord) utility to do it for you?

status = system(“wodim -dev=/dev/sr0 file.iso”);

Well, to be honest, the only reason why I am doing it is because I want to know how programs interact with optical devices. I have heard that every device (including optical devices) are treated as a file (though with some restrictions), and now I am looking forward to test it.

Yes, but treated as a file when reading. You can do cat /dev/sr0 > output.iso. When writing, different rules apply due to the nature of the media.

dd if=path-to-iso of=/dev/cdrom

i am not sure, but point me if anything is wrong…

It is as far as I know not possible to directly treat the cd/dvd in the same
way as block device as you would do it with a harddisk.

What comes nearest is the use of UDF as file system on the optical media
(yes it can also be used for cd not only for dvd where it is used more
often).

I recommend: Make yourself familier with the specs of UDF and to get an
impression from the programmers point of view:
Look into the source code of udftools and libudf on your system.