From owner-freebsd-hackers Wed Oct 6 3: 7:48 1999 Delivered-To: freebsd-hackers@freebsd.org Received: from relay1.bcs.zp.ua (bcs-zyx-eth.marka.net.ua [195.248.171.202]) by hub.freebsd.org (Postfix) with ESMTP id 349C514C4B for ; Wed, 6 Oct 1999 03:04:00 -0700 (PDT) (envelope-from serg@bcs3.bcs.zp.ua) Received: from bcs3.bcs.zp.ua (bcs3.bcs.zp.ua [212.8.35.73]) by relay1.bcs.zp.ua (8.9.3/8.9.3) with ESMTP id NAA13450 for ; Wed, 6 Oct 1999 13:02:14 +0300 (EEST) Received: (from serg@localhost) by bcs3.bcs.zp.ua (8.8.8/8.8.8) id NAA28930 for hackers@freebsd.org; Wed, 6 Oct 1999 13:02:14 +0300 (EEST) (envelope-from serg) From: Sergey Shkonda Message-Id: <199910061002.NAA28930@bcs3.bcs.zp.ua> Subject: New command for cdcontrol(1) To: hackers@freebsd.org Date: Wed, 6 Oct 1999 13:02:14 +0300 (EEST) X-Mailer: ELM [version 2.4ME+ PL61 (25)] MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG I'm using this patch for cdcontrol(1): cdid Print the xmcd's CD id. --- cdcontrol.c.orig Sun Aug 29 18:40:16 1999 +++ cdcontrol.c Wed Oct 6 12:01:35 1999 @@ -33,6 +33,7 @@ #include #include #include +#include #define VERSION "2.0" @@ -65,6 +66,7 @@ #define CMD_RESET 12 #define CMD_SET 13 #define CMD_STATUS 14 +#define CMD_CDID 15 #define STATUS_AUDIO 0x1 #define STATUS_MEDIA 0x2 #define STATUS_VOLUME 0x4 @@ -93,6 +95,7 @@ { CMD_STATUS, "status", 1, "[audio | media | volume]" }, { CMD_STOP, "stop", 3, "" }, { CMD_VOLUME, "volume", 1, " | left | right | mute | mono | stereo" }, +{ CMD_CDID, "cdid", 2, "" }, { 0, } }; @@ -112,6 +115,7 @@ int open_cd __P((void)); int play __P((char *arg)); int info __P((char *arg)); +int cdid __P((void)); int pstatus __P((char *arg)); char *input __P((int *)); void prtrack __P((struct cd_toc_entry *e, int lastflag)); @@ -252,6 +256,12 @@ return info (arg); + case CMD_CDID: + if (fd < 0 && ! open_cd ()) + return (0); + + return cdid (); + case CMD_STATUS: if (fd < 0 && ! open_cd ()) return (0); @@ -739,6 +749,92 @@ printf ("No volume level info available\n"); } return(0); +} + +/* + * dbprog_sum + * Convert an integer to its text string representation, and + * compute its checksum. Used by dbprog_discid to derive the + * disc ID. + * + * Args: + * n - The integer value. + * + * Return: + * The integer checksum. + */ +static int +dbprog_sum(int n) +{ + char buf[12], + *p; + int ret = 0; + + /* For backward compatibility this algorithm must not change */ + sprintf(buf, "%u", n); + for (p = buf; *p != '\0'; p++) + ret += (*p - '0'); + + return(ret); +} + + +/* + * dbprog_discid + * Compute a magic disc ID based on the number of tracks, + * the length of each track, and a checksum of the string + * that represents the offset of each track. + * + * Args: + * s - Pointer to the curstat_t structure. + * + * Return: + * The integer disc ID. + */ +static u_int +dbprog_discid() +{ + struct ioc_toc_header h; + int rc; + int i, ntr, + t = 0, + n = 0; + + rc = ioctl (fd, CDIOREADTOCHEADER, &h); + if (rc < 0) + return 0; + ntr = h.ending_track - h.starting_track + 1; + i = msf; + msf = 1; + rc = read_toc_entrys ((ntr + 1) * sizeof (struct cd_toc_entry)); + msf = i; + if (rc < 0) + return 0; + /* For backward compatibility this algorithm must not change */ + for (i = 0; i < ntr; i++) { +#define TC_MM(a) toc_buffer[a].addr.msf.minute +#define TC_SS(a) toc_buffer[a].addr.msf.second + n += dbprog_sum((TC_MM(i) * 60) + TC_SS(i)); + + t += ((TC_MM(i+1) * 60) + TC_SS(i+1)) - + ((TC_MM(i) * 60) + TC_SS(i)); + } + + return((n % 0xff) << 24 | t << 8 | ntr); +} + +int cdid () +{ + u_int id; + + id = dbprog_discid(); + if (id) + { + if (verbose) + printf ("CDID="); + printf ("%08x\n",id); + } + return id ? 0 : 1; } int info (char *arg) --- cdcontrol.1.orig Sun Aug 29 18:40:15 1999 +++ cdcontrol.1 Wed Oct 6 12:04:42 1999 @@ -129,6 +129,9 @@ .It Cm info Print the table of contents. +.It Cm cdid +Print the xmcd's CD id. + .It Cm status .Op Ar audio | media | volume -- Sergey Shkonda To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message