[PATCH] applet volname

Matthew Stoltenberg d3matt at gmail.com
Wed Aug 12 18:33:32 UTC 2009


Hello BusyBox devs,

I'd like to make my first contribution.  It's a small applet that
reads the 32 byte volume name from a cdrom.  The included patch is
based on busybox-1.14.3.

Matt

--------------------------------------------

diff -ruN -x CVS -x '.config*' -x busybox.spec
busybox-1.14.3/include/applets.h busybox/include/applets.h
--- busybox-1.14.3/include/applets.h	2009-08-02 13:17:33.000000000 -0500
+++ busybox/include/applets.h	2009-08-12 12:49:38.000000000 -0500
@@ -408,6 +408,7 @@
 USE_VCONFIG(APPLET(vconfig, _BB_DIR_SBIN, _BB_SUID_NEVER))
 USE_VI(APPLET(vi, _BB_DIR_BIN, _BB_SUID_NEVER))
 USE_VLOCK(APPLET(vlock, _BB_DIR_USR_BIN, _BB_SUID_ALWAYS))
+USE_VOLNAME(APPLET(volname, _BB_DIR_USR_BIN, _BB_SUID_NEVER))
 USE_WATCH(APPLET(watch, _BB_DIR_BIN, _BB_SUID_NEVER))
 USE_WATCHDOG(APPLET(watchdog, _BB_DIR_SBIN, _BB_SUID_NEVER))
 USE_WC(APPLET(wc, _BB_DIR_USR_BIN, _BB_SUID_NEVER))
diff -ruN -x CVS -x '.config*' -x busybox.spec
busybox-1.14.3/include/usage.h busybox/include/usage.h
--- busybox-1.14.3/include/usage.h	2009-08-02 13:16:36.000000000 -0500
+++ busybox/include/usage.h	2009-08-12 12:51:16.000000000 -0500
@@ -4804,6 +4804,11 @@
      "\nOptions:" \
      "\n	-a	Lock all VTs" \

+#define volname_trivial_usage \
+       "[DEVICE]"
+#define volname_full_usage "\n\n" \
+       "Show volume name for specified DEVICE (or default /dev/cdrom)\n"
+
 #define watch_trivial_usage \
        "[-n seconds] [-t] COMMAND..."
 #define watch_full_usage "\n\n" \
diff -ruN -x CVS -x '.config*' -x busybox.spec
busybox-1.14.3/miscutils/Config.in busybox/miscutils/Config.in
--- busybox-1.14.3/miscutils/Config.in	2009-08-02 13:16:36.000000000 -0500
+++ busybox/miscutils/Config.in	2009-08-12 12:48:40.000000000 -0500
@@ -570,6 +570,12 @@
 	  error, but returns default 80x24.
 	  Usage in shell scripts: width=`ttysize w`.

+config VOLNAME
+	bool "volname"
+	default n
+	help
+	  Used to find volume name of cdroms. (defaults to /dev/cdrom)
+
 config WATCHDOG
 	bool "watchdog"
 	default n
diff -ruN -x CVS -x '.config*' -x busybox.spec
busybox-1.14.3/miscutils/Kbuild busybox/miscutils/Kbuild
--- busybox-1.14.3/miscutils/Kbuild	2009-08-02 13:16:36.000000000 -0500
+++ busybox/miscutils/Kbuild	2009-08-12 12:48:37.000000000 -0500
@@ -38,4 +38,5 @@
 lib-$(CONFIG_TIME)        += time.o
 lib-$(CONFIG_TIMEOUT)     += timeout.o
 lib-$(CONFIG_TTYSIZE)     += ttysize.o
+lib-$(CONFIG_VOLNAME)     += volname.o
 lib-$(CONFIG_WATCHDOG)    += watchdog.o
diff -ruN -x CVS -x '.config*' -x busybox.spec
busybox-1.14.3/miscutils/volname.c busybox/miscutils/volname.c
--- busybox-1.14.3/miscutils/volname.c	1969-12-31 18:00:00.000000000 -0600
+++ busybox/miscutils/volname.c	2009-08-12 13:21:28.000000000 -0500
@@ -0,0 +1,75 @@
+/*
+ * Reads and displays CD-ROM volume name
+ *
+ * Several people have asked how to read CD volume names so I wrote this
+ * small program to do it.
+ *
+ * usage: volname [<device-file>]
+ *
+ ********************************************************************
+ *
+ * Copyright (C) 2000-2001 Jeff Tranter (tranter at pobox.com)
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ ********************************************************************
+ *
+ */
+
+/*
+ * mods from  distrubuted source (eject-2.0.13) are by
+ * Matthew Stoltenberg <d3matt at gmail.com>
+ */
+
+#include "libbb.h"
+
+int volname_main(int argc, char *argv[])
+{
+	int fd;
+	int status;
+	char *device;
+	char buffer[33];
+
+	if (argc == 2) {
+		device = argv[1];
+	} else if (argc == 1) {
+		device = "/dev/cdrom";
+	} else {
+		fprintf(stderr, "usage: volname [<device-file>]\n");
+		exit(1);
+	}
+
+	fd = open(device, O_RDONLY);
+	if (fd == -1) {
+		perror("volname");
+		exit(1);
+	}
+
+	status = lseek(fd, 32808, SEEK_SET);
+	if (status == -1) {
+		perror("volname");
+		exit(1);
+	}
+
+	status = read(fd, buffer, 32);
+	if (status == -1) {
+		perror("volname");
+		exit(1);
+	}
+
+	printf("%32.32s\n", buffer);
+
+	return 0;
+}


More information about the busybox mailing list