Subject: how many bytes on a CD?
To: None <>
From: Steve Bellovin <>
List: netbsd-users
Date: 01/03/2002 12:29:48
Is there any way to tell how many bytes are actually on a CD?
I've written a small C program to copy a CD to a .iso file.  It works,
but I'd rather not get ugly console messages about check conditions.

In theory, I would think I could look at the disk label.  But I haven't
found any rational relationships between the number of bytes I can
read and the values that disklabel reports.  For example, on one test
CD there are 10518528 bytes, both according to my program and according
to 'dd' on the cooked device with a blocksize of 512.  Disklabel says

	disklabel: can't read master boot record: Invalid argument
	# /dev/rcd0d:
	type: ATAPI
	disk: \004\000\000
	label: fictitious
	flags: removable
	bytes/sector: 2048
	sectors/track: 100
	tracks/cylinder: 1
	sectors/cylinder: 100
	cylinders: 120
	total sectors: 11906
	rpm: 300
	interleave: 1
	trackskew: 0
	cylinderskew: 0
	headswitch: 0           # microseconds
	track-to-track seek: 0  # microseconds
	drivedata: 0 

	4 partitions:
	#        size    offset     fstype  [fsize bsize cpg/sgs]
	 a:     47624         0    ISO9660                      # (Cyl.    0 - 476*)
	 d:     47624         0    ISO9660                      # (Cyl.    0 - 476*)
	disklabel: boot block size 0
	disklabel: super block size 0
	disklabel: partition a: partition extends past end of unit
	disklabel: partition d: partition extends past end of unit

(Some of the values are larger for a bigger CD I checked.)