From owner-freebsd-hackers@FreeBSD.ORG Wed Jan 28 09:11:56 2009 Return-Path: Delivered-To: hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id A0A171065677 for ; Wed, 28 Jan 2009 09:11:56 +0000 (UTC) (envelope-from imp@bsdimp.com) Received: from harmony.bsdimp.com (bsdimp.com [199.45.160.85]) by mx1.freebsd.org (Postfix) with ESMTP id 40F998FC0A for ; Wed, 28 Jan 2009 09:11:56 +0000 (UTC) (envelope-from imp@bsdimp.com) Received: from localhost (localhost [127.0.0.1]) by harmony.bsdimp.com (8.14.2/8.14.1) with ESMTP id n0S99TP5091820 for ; Wed, 28 Jan 2009 02:09:29 -0700 (MST) (envelope-from imp@bsdimp.com) Date: Wed, 28 Jan 2009 02:09:50 -0700 (MST) Message-Id: <20090128.020950.-1962670362.imp@bsdimp.com> To: hackers@freebsd.org From: "M. Warner Losh" X-Mailer: Mew version 5.2 on Emacs 21.3 / Mule 5.0 (SAKAKI) Mime-Version: 1.0 Content-Type: Multipart/Mixed; boundary="--Next_Part(Wed_Jan_28_02_09_50_2009_836)--" Content-Transfer-Encoding: 7bit Cc: Subject: Code review request: cdcontrol status label additon X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 28 Jan 2009 09:11:57 -0000 ----Next_Part(Wed_Jan_28_02_09_50_2009_836)-- Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit Please find enclosed patches to enable printing of the ISO-9660 Volume label, if present, for a CD. I've connected this to the 'status label' command. Please comment. Warner ----Next_Part(Wed_Jan_28_02_09_50_2009_836)-- Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="cdcontrol.diff" Index: cdcontrol.1 =================================================================== --- cdcontrol.1 (revision 187760) +++ cdcontrol.1 (working copy) @@ -156,12 +156,14 @@ Play the right subtrack on both left and right channels. .It Ic info Print the table of contents. -.It Ic status Op Cm audio | media | volume +.It Ic status Op Cm audio | label | media | volume Print the information about the disc: .Pp .Bl -tag -width ".Cm volume" -compact .It Cm audio the current playing status and position +.It Cm label +the current ISO 9660 volume label, if present .It Cm media the current media catalog status .It Cm volume Index: cdcontrol.c =================================================================== --- cdcontrol.c (revision 187760) +++ cdcontrol.c (working copy) @@ -86,6 +86,7 @@ #define STATUS_AUDIO 0x1 #define STATUS_MEDIA 0x2 #define STATUS_VOLUME 0x4 +#define STATUS_LABEL 0x8 struct cmdtab { int command; @@ -801,6 +802,8 @@ what |= STATUS_MEDIA; else if (!strncasecmp(p, "volume", strlen(p))) what |= STATUS_VOLUME; + else if (!strncasecmp(p, "label", strlen(p))) + what |= STATUS_LABEL; else { warnx("invalid command arguments"); return 0; @@ -851,6 +854,32 @@ else printf ("No volume level info available\n"); } + if (what & STATUS_LABEL) { +#define ISO9660_MAGIC "\x01" "CD001" "\x01\x00" +#define ISO9660_OFFSET 0x8000 +#define VOLUME_LEN 32 +#define CD_SECTOR_LEN 2048 +#define LABEL_NAME_OFF 0x28 +#define LABEL_NAME_LEN 32 + char *sp, *ep, buffer[CD_SECTOR_LEN]; + + lseek(fd, ISO9660_OFFSET, SEEK_SET); + rc = read (fd, buffer, CD_SECTOR_LEN); + if (rc == CD_SECTOR_LEN && + memcmp(buffer, ISO9660_MAGIC, sizeof(ISO9660_MAGIC) - 1) == 0) { + sp = buffer + LABEL_NAME_OFF; + ep = sp + LABEL_NAME_LEN - 1; + while (*ep == ' ' && ep >= sp) + *ep-- = '\0'; + if (verbose) + printf("ISO 9660 Label is: %s\n", sp); + else + printf("%s\n", sp); + } + else + printf("No ISO 9660 label found\n"); + } + return(0); } ----Next_Part(Wed_Jan_28_02_09_50_2009_836)----