public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* determining size of cdrom
@ 2001-05-30 16:11 Jeff Meininger
  2001-05-30 21:15 ` Jens Axboe
  0 siblings, 1 reply; 3+ messages in thread
From: Jeff Meininger @ 2001-05-30 16:11 UTC (permalink / raw)
  To: linux-kernel


I'm not subscribed to the mailing list, so please Cc a copy of your
replies straight to my email address: jeffm@boxybutgood.com.


I'm trying to determine the raw size of a cdrom disc, as in the size of
the file you'd get by doing 'dd if=/dev/cdrom of=size_of_this.img'.

I've tried the following things (with a disc in the drive) without
success, and I'm hoping that someone will be able to point me in the right
direction.


struct stat s;
stat("/dev/cdrom", &s);
/* s.st_size is 0, s.st_blocks is 0.  */

int fd = open("/dev/cdrom", O_RDONLY);

off_t bytes = lseek(fd, 0, SEEK_END);
/* bytes is 0 */

long sectors = 0;
ioctl(fd, BLKGETSIZE, &sectors);
/* sectors varies (never seems accurate) and is usually LONG_MAX */
	
long ssz = 0;
ioctl(fd, BLKSSZGET, &ssz);
/* ssz varies, and is usually 1024. (shouldn't it be 2048?)  */

/* ioctl HDIO_GETGEO fails. */

/* ioctl HDIO_GET_IDENTITY returns 0's for the c/h/s values I'm looking
for.  */

I didn't find anything that looked obvious to me in linux/cdrom.h, except
in the #ifdef __KERNEL__ section which I don't believe I can use from
user space.

I hope I didn't miss something really obvious, but I've been at this
problem for a few days now (mostly spent reading docs and headers) and I'm
at the point where I'll risk asking something stupid.

Thanks!!

BTW, once again, I'm not subscribed to the mailing list, so please Cc a
copy of your replies straight to my email address: jeffm@boxybutgood.com.



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: determining size of cdrom
  2001-05-30 16:11 determining size of cdrom Jeff Meininger
@ 2001-05-30 21:15 ` Jens Axboe
  2001-05-31  6:51   ` Jeff Meininger
  0 siblings, 1 reply; 3+ messages in thread
From: Jens Axboe @ 2001-05-30 21:15 UTC (permalink / raw)
  To: Jeff Meininger; +Cc: linux-kernel

On Wed, May 30 2001, Jeff Meininger wrote:
> 
> I'm not subscribed to the mailing list, so please Cc a copy of your
> replies straight to my email address: jeffm@boxybutgood.com.
> 
> 
> I'm trying to determine the raw size of a cdrom disc, as in the size of
> the file you'd get by doing 'dd if=/dev/cdrom of=size_of_this.img'.
> 
> I've tried the following things (with a disc in the drive) without
> success, and I'm hoping that someone will be able to point me in the right
> direction.
> 
> 
> struct stat s;
> stat("/dev/cdrom", &s);
> /* s.st_size is 0, s.st_blocks is 0.  */
> 
> int fd = open("/dev/cdrom", O_RDONLY);
> 
> off_t bytes = lseek(fd, 0, SEEK_END);
> /* bytes is 0 */
> 
> long sectors = 0;
> ioctl(fd, BLKGETSIZE, &sectors);
> /* sectors varies (never seems accurate) and is usually LONG_MAX */

At least this is the capacity as reported by the drive when we read the
table of contents.

> long ssz = 0;
> ioctl(fd, BLKSSZGET, &ssz);
> /* ssz varies, and is usually 1024. (shouldn't it be 2048?)  */

Someone added a block size setting of 1024 to ide revalidate, and this
has screwed us for a awhile (ie atapi dvd-ram breaks). Recent ac has the
correct stuff to reset it.

> /* ioctl HDIO_GETGEO fails. */
> 
> /* ioctl HDIO_GET_IDENTITY returns 0's for the c/h/s values I'm looking
> for.  */
> 
> I didn't find anything that looked obvious to me in linux/cdrom.h, except
> in the #ifdef __KERNEL__ section which I don't believe I can use from
> user space.

You can do it from user space with CDROMREADTOCHDR/CDROMREATOCENTRY if
you want, did you see those?

-- 
Jens Axboe


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: determining size of cdrom
  2001-05-30 21:15 ` Jens Axboe
@ 2001-05-31  6:51   ` Jeff Meininger
  0 siblings, 0 replies; 3+ messages in thread
From: Jeff Meininger @ 2001-05-31  6:51 UTC (permalink / raw)
  To: Jens Axboe; +Cc: linux-kernel



> > long sectors = 0;
> > ioctl(fd, BLKGETSIZE, &sectors);
> > /* sectors varies (never seems accurate) and is usually LONG_MAX */
> 
> At least this is the capacity as reported by the drive when we read the
> table of contents.

Am I interpreting the return value incorrectly?  I nearly always get
2147483647 (LONG_MAX?).



> > ioctl(fd, BLKSSZGET, &ssz);
> > /* ssz varies, and is usually 1024. (shouldn't it be 2048?)  */
> 
> Someone added a block size setting of 1024 to ide revalidate, and this
> has screwed us for a awhile (ie atapi dvd-ram breaks). Recent ac has the
> correct stuff to reset it.

I'd like my app to work with a wide variety of kernels, including 2.2
kernels, so I guess I'll have to avoid getting the sector size that
way.  Thanks for the tip.  :)



> > I didn't find anything that looked obvious to me in linux/cdrom.h, except
> > in the #ifdef __KERNEL__ section which I don't believe I can use from
> > user space.
> 
> You can do it from user space with CDROMREADTOCHDR/CDROMREATOCENTRY if
> you want, did you see those?

I've looked at those, but I don't see how I could calculate the disc size
from the information given in struct cdrom_tochdr and struct
cdrom_tocentry.  If I'm interpreting cdrom.h's interface correctly, the
best I'd be able to do is determine how many tracks, what type of data,
and where each track started (either in LBA or MSF).  



Any more ideas?  Perhaps I need to actually open /dev/cdrom and read it's
data to determine the size?  Maybe somewhere in the first 16 sectors (not
defined by iso9660) I can get the information I need?  It just seems that
I should be able to get the information from linux much more easily.

Thanks...
-Jeff M


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2001-05-31 11:52 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2001-05-30 16:11 determining size of cdrom Jeff Meininger
2001-05-30 21:15 ` Jens Axboe
2001-05-31  6:51   ` Jeff Meininger

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox