Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 01 Mar 1999 17:40:20 -0800
From:      grady@xcf.berkeley.edu (Steven Grady)
To:        freebsd-multimedia@freebsd.org, freebsd-bugs@freebsd.org
Subject:   CD-ROM problem on 3.0: Invalid argument?
Message-ID:  <19990302013959.8005D1536F@hub.freebsd.org>

next in thread | raw e-mail | index | archive | help
(Sorry about not using send-pr, but installing GNATS on my machine
for non-FreeBSD purposes seems to have screwed up send-pr.)

I'm trying to rip my CDs.  The program I'm using to get the header info
(to query CDDB) works the first n times I run it (where n >= 1),
but at some point the open fails with "Invalid argument".  It works again the
next time I reboot.  Sounds like a bug to me.  Anyone have a clue?

The program (courtesy of Daniel O'Connor, doconnor@gsoft.com.au), is the
following:

====

#include <stdio.h>
#include <sysexits.h>
#include <fcntl.h>
#include <sys/errno.h>
#include <sys/ioctl.h>
#include <sys/cdio.h>

int cddb_sum(int n);
unsigned long cddb_discid(int tot_trks, struct cd_toc_entry *cdtoc);

int
main(int argc, char **argv)
{
    int 			cd_fd, tot_tracks, i;
    struct ioc_toc_header	toc_head;
    struct ioc_read_toc_entry	toc_entries_head;
    struct cd_toc_entry		*toc_entries;
    char			cd_path[256];

    if (argc != 2) {
	warnx("Usage: %s <cd-device>", argv[0]);
	exit(EX_USAGE);
    }

    strcpy(cd_path, argv[1]);

    if ((cd_fd = open(cd_path, O_RDWR)) == -1) {
	warnx("Failed to open %s, reason: %s", cd_path, strerror(errno));
	exit(EX_IOERR);
    }

    if (ioctl(cd_fd, CDIOREADTOCHEADER, &toc_head) == -1) {
	warnx("Failed to get TOC header, reason: %s", strerror(errno));
	exit(EX_UNAVAILABLE);
    }
    
    printf("Start track = %d, end track = %d, length = %d\n", toc_head.starting_track,
	   toc_head.ending_track, toc_head.len);

    tot_tracks = toc_head.ending_track - toc_head.starting_track + 1;
    
    toc_entries = (struct cd_toc_entry *)malloc(sizeof(struct cd_toc_entry) * (tot_tracks + 1));
    if (toc_entries == NULL) {
	warnx("Couldn't allocate memeory for TOC entries");
	exit(EX_UNAVAILABLE);
    }
    
    toc_entries_head.data = toc_entries;
    toc_entries_head.data_len = sizeof(struct cd_toc_entry) * (tot_tracks + 1);
    toc_entries_head.starting_track = 0;
    toc_entries_head.address_format = CD_MSF_FORMAT;

    if (ioctl(cd_fd, CDIOREADTOCENTRYS, &toc_entries_head) == -1) {
	warnx("Failed to get TOC entries, reason: %s\n", strerror(errno));
	exit(EX_UNAVAILABLE);
    }
    
    for (i = 0; i < (tot_tracks + 1); i++) {
	printf("Track %d, Minute = %d, Second = %d, Frame = %d, Type = %s, Offset = %d\n", 
	       toc_entries[i].track, toc_entries[i].addr.msf.minute,
	       toc_entries[i].addr.msf.second, toc_entries[i].addr.msf.frame,
	       (toc_entries[i].control & 4) ? "data" : "audio",
	       (toc_entries[i].addr.msf.minute * 60 * 75) + (toc_entries[i].addr.msf.second
							     * 75) +
	       toc_entries[i].addr.msf.frame);
    }

    printf("Disc ID is %08x\n", cddb_discid(tot_tracks, toc_entries));
    printf("Length is %d seconds\n", (toc_entries[tot_tracks].addr.msf.minute * 60) +
				     (toc_entries[tot_tracks].addr.msf.second));
}
    
int
cddb_sum(int n)
{
        int     ret;

	/* For backward compatibility this algorithm must not change */

	ret = 0;

	while (n > 0) {
		ret = ret + (n % 10);
		n = n / 10;
	}

	return (ret);
}

unsigned long
cddb_discid(int tot_trks, struct cd_toc_entry *cdtoc)
{
        int     i,
		t = 0,
		n = 0;

	/* For backward compatibility this algorithm must not change */

	i = 0;

	while (i < tot_trks) {
		n = n + cddb_sum((cdtoc[i].addr.msf.minute * 60)
		      + cdtoc[i].addr.msf.second);
		i++;
	}
	t = ((cdtoc[tot_trks].addr.msf.minute * 60) +
	      cdtoc[tot_trks].addr.msf.second) -
	    ((cdtoc[0].addr.msf.minute * 60) +
	      cdtoc[0].addr.msf.second);

	return ((n % 0xff) << 24 | t << 8 | tot_trks);
}

====

My system is 3.0-RELEASE.  Dmesg output follows.  Note that the CD-ROM is
a Toshiba XM-5401.


====

Copyright (c) 1992-1998 FreeBSD Inc.
Copyright (c) 1982, 1986, 1989, 1991, 1993
	The Regents of the University of California. All rights reserved.
FreeBSD 3.0-RELEASE #3: Mon Feb 15 11:47:19 PST 1999
    grady@semprini.ip.holonet.net:/usr/src/sys/compile/SEMPRINI
Timecounter "i8254"  frequency 1193182 Hz  cost 3011 ns
CPU: Pentium II (300.68-MHz 686-class CPU)
  Origin = "GenuineIntel"  Id = 0x634  Stepping=4
  Features=0x80f9ff<FPU,VME,DE,PSE,TSC,MSR,PAE,MCE,CX8,SEP,MTRR,PGE,MCA,CMOV,MMX>
real memory  = 67108864 (65536K bytes)
avail memory = 62554112 (61088K bytes)
Probing for devices on PCI bus 0:
chip0: <Host to PCI bridge (vendor=8086 device=7180)> rev 0x03 on pci0.0.0
chip1: <PCI to PCI bridge (vendor=8086 device=7181)> rev 0x03 on pci0.1.0
chip2: <Intel 82371AB PCI to ISA bridge> rev 0x01 on pci0.4.0
ide_pci0: <Intel PIIX4 Bus-master IDE controller> rev 0x01 on pci0.4.1
chip3: <Intel 82371AB USB host controller> rev 0x01 int d irq 9 on pci0.4.2
chip4: <Intel 82371AB Power management controller> rev 0x01 on pci0.4.3
vga0: <Matrox MGA 2164W graphics accelerator> rev 0x00 int a irq 9 on pci0.10.0
ahc0: <Adaptec 2940A Ultra SCSI adapter> rev 0x01 int a irq 11 on pci0.12.0
ahc0: aic7860 Single Channel A, SCSI Id=7, 3/255 SCBs
Probing for devices on PCI bus 1:
Probing for PnP devices:
CSN 1 Vendor ID: CTL0039 [0x39008c0e] Serial 0x0001d455 Comp ID: PNP0600 [0x0006d041]
pcm1 (SB16pnp <SB16 PnP> sn 0x0001d455) at 0x220-0x22f irq 5 drq 1 flags 0x15 on isa
Probing for devices on the ISA bus:
sc0 at 0x60-0x6f irq 1 on motherboard
sc0: VGA color <16 virtual consoles, flags=0x0>
ed0 at 0x300-0x31f irq 15 on isa
ed0: address 00:40:33:5a:29:e9, type NE2000 (16 bit) 
pcm0 not found
sio0 at 0x3f8-0x3ff irq 4 flags 0x10 on isa
sio0: type 16550A
sio1 at 0x2f8-0x2ff irq 3 on isa
sio1: type 16550A
lpt0 at 0x378-0x37f irq 7 on isa
lpt0: Interrupt-driven port
lp0: TCP/IP capable interface
psm0 at 0x60-0x64 irq 12 on motherboard
psm0: model Generic PS/2 mouse, device ID 0
fdc0 at 0x3f0-0x3f7 irq 6 drq 2 on isa
fdc0: FIFO enabled, 8 bytes threshold
fd0: 1.44MB 3.5in
wdc0 at 0x1f0-0x1f7 irq 14 on isa
wdc0: unit 0 (wd0): <QUANTUM Bigfoot TX12.0AT>
wd0: 11497MB (23547888 sectors), 23361 cyls, 16 heads, 63 S/T, 512 B/S
npx0 on motherboard
npx0: INT 16 interface
apm0 on isa
apm: found APM BIOS version 1.2
Waiting 2 seconds for SCSI devices to settle
changing root device to da1s2a
da0 at ahc0 bus 0 target 0 lun 0
da0: <QUANTUM LPS540S 5900> Fixed Direct Access SCSI2 device 
da0: 10.0MB/s transfers (10.0MHz, offset 8)
da0: 516MB (1057616 512 byte sectors: 64H 32S/T 516C)
da1 at ahc0 bus 0 target 1 lun 0
da1: <MICROP 3387NS x43h> Fixed Direct Access SCSI2 device 
da1: 10.0MB/s transfers (10.0MHz, offset 15), Tagged Queueing Enabled
da1: 8296MB (16992188 512 byte sectors: 255H 63S/T 1057C)
ffs_mountfs: superblock updated
ffs_mountfs: superblock updated
cd0 at ahc0 bus 0 target 2 lun 0
cd0: <TOSHIBA CD-ROM XM-5401TA 3605> Removable CD-ROM SCSI2 device 
cd0: 4.237MB/s transfers (4.237MHz, offset 15)
cd0: cd present [331145 x 2048 byte records]
(da2:ahc0:0:4:0): SCB 0x2 - timed out while idle, LASTPHASE == 0x1, SCSISIGI == 0x0
SEQADDR == 0x8
SSTAT1 == 0xa
(da2:ahc0:0:4:0): Queuing a BDR SCB
(da2:ahc0:0:4:0): Bus Device Reset Message Sent
(da2:ahc0:0:4:0): no longer in timeout, status = 34b
ahc0: Bus Device Reset on A:4. 1 SCBs aborted
da2 at ahc0 bus 0 target 4 lun 0
da2: <iomega jaz 1GB G.60> Removable Direct Access SCSI2 device 
da2: 10.0MB/s transfers (10.0MHz, offset 15)
da2: 1021MB (2091050 512 byte sectors: 64H 32S/T 1021C)
ed0: promiscuous mode enabled
(da1:ahc0:0:1:0): tagged openings now 48

====

The output of the program looks like:

	% cddb-id /dev/cd0a
	cddb-id: Failed to open /dev/cd0a, reason: Invalid argument

As stated before, the program works just fine at least once before it gets
into this state.

	Steven
	grady@xcf.berkeley.edu

It's true that every time you hear a bell, an angel gets its wings.  But
what they don't tell you is that every time you hear a mouse trap snap,
an angel gets set on fire.


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-bugs" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?19990302013959.8005D1536F>