On Sat, Jan 05, 2008 at 10:28:34AM +0000, Stuart Brady wrote: > On Fri, Jan 04, 2008 at 09:53:09PM -0600, Rob Landley wrote: > > Except that according to http://en.wikipedia.org/wiki/CD-ROM it's actually > > 703 > > and 1/8 binary megabytes (360,000 sectors *2048 bytes), which would be > > 1440000. > > Apparently that value comes from 75 sectors per second * 80 minutes... > 75*80*60 = 360000, and of course, 360000*2048/512 = 1440000, although > it actually seems that it should be one sector less than 80 minutes, > which is 359999 2048-byte sectors or 1439996 512-byte chunks. > > BTW, there are/were also 90 and 99 minute 'CD-Rs' -- Wikipedia's page on > CD-Rs describes them, but they were never very popular, and a lot of > drives can't read the discs.
the exact number of sectors is really not that relevant, as the whole point here is to try to detect if it is a CD (700MB) or a DVD (4.7GB) and the logic is just assuming that if it has more sectors than you should normally expect in a CD, then it is a DVD. attached the program I used in the guests (only works on Linux) to poke the emulated drive (or a physical drive if you feel like) and compare the responses (you will need to take a look at the SPEC tables to interpret the data though) for my own tests (using a linux guest with -cdrom /dev/cdrom in my linux host that has a DVD-+RW drive) : 700MB CD-R = 1374880 (with FreeSBIE 2.0.1) 4.7GB DVD-R = 6939520 (with SXDE 9/07) feel free to report back with the value to use then if you happen to have a CD that is completely full but I had already enough problems trying to get this merged without trying to change the code that much to try to guess a better magic number than the one was originally used (I like 1440000 though) Carlo
/* ide-atapi Copyright (c) 2007 Carlo Marcelo Arenas Belon ide-atapi is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License version 2 as published by the Free Software Foundation. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include <sys/ioctl.h> #include <linux/cdrom.h> #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> #include <string.h> #include <stdio.h> #include <unistd.h> int main (int argc, char *argv[]) { struct cdrom_generic_command cgc; struct request_sense sense; unsigned char buf[250]; int i; if (argc < 2) { printf("Usage: %s <device>\n", argv[0]); printf("\n"); printf(" device: where the commands are send\n"); printf("\n"); return 1; } memset (&cgc, 0, sizeof(struct cdrom_generic_command)); memset (&sense, 0, sizeof(struct request_sense)); memset (&buf, 0, sizeof(buf)); int fd = open (argv[1], O_RDONLY | O_NONBLOCK); if (fd < 0) { printf("couldn't open device %s\n", argv[1]); return 1; } cgc.cmd[0] = GPCMD_GET_CONFIGURATION; cgc.cmd[1] = 0x00; cgc.cmd[8] = sizeof(buf); cgc.timeout = 100; cgc.buffer = buf; cgc.buflen = sizeof(buf); cgc.data_direction = CGC_DATA_READ; cgc.sense = &sense; cgc.quiet = 0; i = ioctl (fd, CDROM_SEND_PACKET, &cgc); if (i < 0) { printf("command failed\n"); close (fd); return 1; } printf("Response raw dump:\n"); for (i = 0; i<sizeof(buf); i++) { if (i % 16 == 0) printf("\n"); printf("%02x ", buf[i]); } printf("\n"); close (fd); return 0; }