[svlug] Predicting size of CD image

Tim tim at tetro.net
Thu Jan 30 16:28:37 PST 2003

On Thu, Jan 30, 2003 at 03:55:38PM -0800, Sean McAfee wrote:
> I'm working on some software which generates CD images by running the
> following command:
> dd if=/dev/scd0 of=image.iso
> I'd like to be able to find out in advance how large the image is going to
> be so that I can present a status thermometer for the reading process.
> I've tried stat(2) and fstat(2), but both return a size of zero when
> applied to /dev/scd0.  That's pretty much all I presently know to try.
> Can anyone suggest a way to get the info I'm after?  Thanks in advance.

You can get the number of 1024-byte blocks from /proc/partitions.  First
you have to access the device in some way so that the kernel will update
the size.  So just read the first block or so, and then check

I tried it on a few CD-ROMs, CD-RWs, and CD-Rs, and it always matched
the size of the image exactly.  Though they're all single session
ISO-9660 file systems burned in disk-at-once mode, so I don't know how
well it will work with multisession, track-at-once, UDF file system, and
packet-written CDs.

There is also a program named 'isoinfo' that comes with cdrecord (on
Debian it comes in the mkisofs package), and it'll show you the block
size and the volume size (in blocks of that size) with a command like:
isoinfo -d -i /dev/cdrom

   - Tim

More information about the svlug mailing list