Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 6 Oct 1999 13:02:14 +0300 (EEST)
From:      Sergey Shkonda <serg@bcs.zp.ua>
To:        hackers@freebsd.org
Subject:   New command for cdcontrol(1)
Message-ID:  <199910061002.NAA28930@bcs3.bcs.zp.ua>

next in thread | raw e-mail | index | archive | help
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 <sys/file.h>
 #include <sys/cdio.h>
 #include <sys/ioctl.h>
+#include <sys/types.h>
 
 #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, "<l> <r> | 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           <serg@bcs.zp.ua>


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




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