From c718b074db224f50c03adbf872b98b83393092d7 Mon Sep 17 00:00:00 2001 From: Bryce Denney Date: Tue, 26 Jun 2001 08:12:21 +0000 Subject: [PATCH] - Another patch from splite@purdue.edu. The original code for determining the capacity of a disk only worked for ATAPI drives, leaving us poor SCSI users in the cold. The code uses the standard Linux CD-ROM driver routines, so it should work on any supported drive. It's basically just a copy of Keith Jones FreeBSD code. --- bochs/iodev/cdrom.cc | 69 ++++++++++++----- bochs/patches/patch.cdrom-blkgetsize | 106 --------------------------- 2 files changed, 51 insertions(+), 124 deletions(-) delete mode 100644 bochs/patches/patch.cdrom-blkgetsize diff --git a/bochs/iodev/cdrom.cc b/bochs/iodev/cdrom.cc index 4dbfe708a..71e4e7c48 100644 --- a/bochs/iodev/cdrom.cc +++ b/bochs/iodev/cdrom.cc @@ -553,24 +553,6 @@ cdrom_interface::capacity() return(buf.st_size); } -#elif __linux__ - { - // I just looked through the Linux kernel source to see - // what it does with the ATAPI capacity command, and reversed - // that process here. - uint32 nr_sects; - - if (fd < 0) { - BX_PANIC(("cdrom: capacity: file not open.")); - } - if (ioctl(fd, BLKGETSIZE, &nr_sects) != 0) { - BX_PANIC(("cdrom: ioctl(BLKGETSIZE) failed")); - } - nr_sects /= (CD_FRAMESIZE / 512); - - BX_DEBUG(( "capacity: %u", nr_sects)); - return(nr_sects); - } #elif defined(__OpenBSD__) { // We just read the disklabel, imagine that... @@ -584,6 +566,57 @@ cdrom_interface::capacity() BX_DEBUG(( "capacity: %u", lp.d_secperunit )); return(lp.d_secperunit); + } +#elif defined(__linux__) + { + // Read the TOC to get the data size, since BLKGETSIZE doesn't work on + // non-ATAPI drives. This is based on Keith Jones code below. + // 21 June 2001 + + int i, dtrk, dtrk_lba, num_sectors; + struct cdrom_tochdr td; + struct cdrom_tocentry te; + + if (fd < 0) + BX_PANIC(("cdrom: capacity: file not open.")); + + if (ioctl(fd, CDROMREADTOCHDR, &td) < 0) + BX_PANIC(("cdrom: ioctl(CDROMREADTOCHDR) failed")); + + num_sectors = -1; + dtrk_lba = -1; + + for (i = td.cdth_trk0; i <= td.cdth_trk1; i++) { + te.cdte_track = i; + te.cdte_format = CDROM_LBA; + if (ioctl(fd, CDROMREADTOCENTRY, &te) < 0) + BX_PANIC(("cdrom: ioctl(CDROMREADTOCENTRY) failed")); + + if (dtrk_lba != -1) { + num_sectors = te.cdte_addr.lba - dtrk_lba; + break; + } + if (te.cdte_ctrl & CDROM_DATA_TRACK) { + dtrk = i; + dtrk_lba = te.cdte_addr.lba; + } + } + + if (num_sectors < 0) { + if (dtrk_lba != -1) { + te.cdte_track = CDROM_LEADOUT; + te.cdte_format = CDROM_LBA; + if (ioctl(fd, CDROMREADTOCENTRY, &te) < 0) + BX_PANIC(("cdrom: ioctl(CDROMREADTOCENTRY) failed")); + num_sectors = te.cdte_addr.lba - dtrk_lba; + } else + BX_PANIC(("cdrom: no data track found")); + } + + BX_INFO(("cdrom: Data track %d, length %d", dtrk, num_sectors)); + + return(num_sectors); + } #elif defined(__FreeBSD__) { diff --git a/bochs/patches/patch.cdrom-blkgetsize b/bochs/patches/patch.cdrom-blkgetsize deleted file mode 100644 index 612fb7dd5..000000000 --- a/bochs/patches/patch.cdrom-blkgetsize +++ /dev/null @@ -1,106 +0,0 @@ ----------------------------------------------------------------------- -Patch name: patch.cdrom-blkgetsize -Author: bochs@sigint.cs.purdue.edu -Date: Fri, 22 Jun 2001 10:46:07 -0500 - -Detailed description: - The original code for determining the capacity of a disc only worked for - ATAPI drives, leaving us poor SCSI users in the cold. The code uses the - standard Linux CD-ROM driver routines, so it should work on any supported - drive. It's basically just a copy of Keith Jones FreeBSD code. - -Patch was created with: - ? -Apply patch to what version: - ? -Instructions: - ? ----------------------------------------------------------------------- - - ---- iodev/cdrom.cc.orig Tue Jun 19 16:36:09 2001 -+++ iodev/cdrom.cc Fri Jun 22 10:40:07 2001 -@@ -390,24 +390,6 @@ - - return(buf.st_size); - } --#elif __linux__ -- { -- // I just looked through the Linux kernel source to see -- // what it does with the ATAPI capacity command, and reversed -- // that process here. -- uint32 nr_sects; -- -- if (fd < 0) { -- BX_PANIC(("cdrom: capacity: file not open.")); -- } -- if (ioctl(fd, BLKGETSIZE, &nr_sects) != 0) { -- BX_PANIC(("cdrom: ioctl(BLKGETSIZE) failed")); -- } -- nr_sects /= (CD_FRAMESIZE / 512); -- -- BX_DEBUG(( "capacity: %u", nr_sects)); -- return(nr_sects); -- } - #elif defined(__OpenBSD__) - { - // We just read the disklabel, imagine that... -@@ -421,6 +403,57 @@ - - BX_DEBUG(( "capacity: %u", lp.d_secperunit )); - return(lp.d_secperunit); -+ } -+#elif defined(__linux__) -+ { -+ // Read the TOC to get the data size, since BLKGETSIZE doesn't work on -+ // non-ATAPI drives. This is based on Keith Jones code below. -+ // 21 June 2001 -+ -+ int i, dtrk, dtrk_lba, num_sectors; -+ struct cdrom_tochdr td; -+ struct cdrom_tocentry te; -+ -+ if (fd < 0) -+ BX_PANIC(("cdrom: capacity: file not open.")); -+ -+ if (ioctl(fd, CDROMREADTOCHDR, &td) < 0) -+ BX_PANIC(("cdrom: ioctl(CDROMREADTOCHDR) failed")); -+ -+ num_sectors = -1; -+ dtrk_lba = -1; -+ -+ for (i = td.cdth_trk0; i <= td.cdth_trk1; i++) { -+ te.cdte_track = i; -+ te.cdte_format = CDROM_LBA; -+ if (ioctl(fd, CDROMREADTOCENTRY, &te) < 0) -+ BX_PANIC(("cdrom: ioctl(CDROMREADTOCENTRY) failed")); -+ -+ if (dtrk_lba != -1) { -+ num_sectors = te.cdte_addr.lba - dtrk_lba; -+ break; -+ } -+ if (te.cdte_ctrl & CDROM_DATA_TRACK) { -+ dtrk = i; -+ dtrk_lba = te.cdte_addr.lba; -+ } -+ } -+ -+ if (num_sectors < 0) { -+ if (dtrk_lba != -1) { -+ te.cdte_track = CDROM_LEADOUT; -+ te.cdte_format = CDROM_LBA; -+ if (ioctl(fd, CDROMREADTOCENTRY, &te) < 0) -+ BX_PANIC(("cdrom: ioctl(CDROMREADTOCENTRY) failed")); -+ num_sectors = te.cdte_addr.lba - dtrk_lba; -+ } else -+ BX_PANIC(("cdrom: no data track found")); -+ } -+ -+ BX_INFO(("cdrom: Data track %d, length %d", dtrk, num_sectors)); -+ -+ return(num_sectors); -+ - } - #elif defined(__FreeBSD__) - { -