determining size of cdrom

From: Jeff Meininger (jeffm@boxybutgood.com)
Date: Wed May 30 2001 - 11:11:00 EST


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.

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/



This archive was generated by hypermail 2b29 : Thu May 31 2001 - 21:00:48 EST