Date: Wed, 28 Jan 2009 02:09:50 -0700 (MST) From: "M. Warner Losh" <imp@bsdimp.com> To: hackers@freebsd.org Subject: Code review request: cdcontrol status label additon Message-ID: <20090128.020950.-1962670362.imp@bsdimp.com>
next in thread | raw e-mail | index | archive | help
----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)----
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20090128.020950.-1962670362.imp>