[BusyBox] losetup applet

Bernhard Wiedemann wiedeman at informatik.hu-berlin.de
Tue Feb 26 02:18:03 UTC 2002


Hello dear busy boxers

I apreciate your work a lot and now want to contribute to it a bit:
I have added (for my linux bootCD initrd) a *very* minimalistic losetup
but have not yet figured out how to let it appear in make menuconfig 
(add this please for me)
patch files attached.

a many thanks
Bernhard M. Wiedemann
_________
hopefully helpful


----- this is for 0.60.2 (ignore if you have fixed it)

broken shell: export VARI=value
help does not work

umount -r /var/mnt
umount: Cannot open /proc/mounts
umount: Cannot remount (null) read-only
umount: /var/mnt: Device or resource busy

pidof init
always returns 1 (wrong for initrd)
and pidof name returns only pid of the last process with that name

----------
------ this goes for unstable-20020224 version:
make distclean leaves docs/busybox.pod and a lot ".*.flags" files.
the new-applet-HOWTO.txt could need a rewrite (e.g. subdir/config.in)
------------

and also some corrections to documentation:
? what does tr do with missing [STRING2] ?
and two minor corrections included in busybox-20020224-bmw.diff
-------------- next part --------------
diff -urN ./debian/Config.h-deb /vol/d/root/busybox/debian/Config.h-deb
--- ./debian/Config.h-deb	Wed Oct 24 06:59:18 2001
+++ /vol/d/root/busybox/debian/Config.h-deb	Tue Feb 26 09:09:43 2002
@@ -68,6 +68,7 @@
 #define CONFIG_LOADKMAP
 #define CONFIG_LOGGER
 //#define CONFIG_LOGNAME
+//#define CONFIG_LOSETUP
 #define CONFIG_LS
 #define CONFIG_LSMOD
 //#define CONFIG_MAKEDEVS
diff -urN ./debian/Config.h-static /vol/d/root/busybox/debian/Config.h-static
--- ./debian/Config.h-static	Wed Oct 24 06:59:18 2001
+++ /vol/d/root/busybox/debian/Config.h-static	Tue Feb 26 09:10:07 2002
@@ -68,6 +68,7 @@
 #define CONFIG_LOADKMAP
 #define CONFIG_LOGGER
 #define CONFIG_LOGNAME
+//#define CONFIG_LOSETUP
 #define CONFIG_LS
 #define CONFIG_LSMOD
 #define CONFIG_MAKEDEVS
diff -urN ./debian/Config.h-udeb /vol/d/root/busybox/debian/Config.h-udeb
--- ./debian/Config.h-udeb	Wed Oct 24 06:59:18 2001
+++ /vol/d/root/busybox/debian/Config.h-udeb	Tue Feb 26 09:09:57 2002
@@ -68,6 +68,7 @@
 #define CONFIG_LOADKMAP
 #define CONFIG_LOGGER
 //#define CONFIG_LOGNAME
+//#define CONFIG_LOSETUP
 #define CONFIG_LS
 #define CONFIG_LSMOD
 //#define CONFIG_MAKEDEVS
diff -urN ./docs/busybox.pod /vol/d/root/busybox/docs/busybox.pod
--- ./docs/busybox.pod	Tue Feb 26 09:27:24 2002
+++ /vol/d/root/busybox/docs/busybox.pod	Tue Feb 26 09:14:51 2002
@@ -1386,6 +1386,14 @@
 
 -------------------------------
 
+=item B<losetup>
+
+losetup loop_device file
+
+Connects files to loop block devices
+
+-------------------------------
+
 =item B<ls>
 
 ls [B<-1AacCdeFilnpLRrSsTtuvwxXhk>] [filenames...]
diff -urN ./docs/busybox.sgml /vol/d/root/busybox/docs/busybox.sgml
--- ./docs/busybox.sgml	Tue Dec 18 15:06:01 2001
+++ /vol/d/root/busybox/docs/busybox.sgml	Tue Feb 26 09:42:06 2002
@@ -2275,7 +2275,7 @@
 			-c	Check for read-ability.
 			-v0	Make version 0 swap [max 128 Megs].
 			-v1	Make version 1 swap [big!] (default for kernels &gt; 2.1.117).
-			BLOCKS	Number of block to use (default is entire partition).
+			BLOCKS	Number of blocks to use (default is entire partition).
 		</screen>
 		</para>
 	</sect1>
@@ -3753,7 +3753,7 @@
 	    <title>which</title>
 
 		<para>
-		Usage: which [COMMAND]...
+		Usage: which COMMAND [COMMAND ...]
 		</para>
 
 		<para>
diff -urN ./include/applets.h /vol/d/root/busybox/include/applets.h
--- ./include/applets.h	Wed Jan  2 14:52:23 2002
+++ /vol/d/root/busybox/include/applets.h	Tue Feb 26 08:45:10 2002
@@ -269,6 +269,9 @@
 #ifdef CONFIG_LOGREAD
 	APPLET(logread, logread_main, _BB_DIR_SBIN)
 #endif
+#ifdef CONFIG_LOSETUP
+	APPLET(losetup, losetup_main, _BB_DIR_SBIN)
+#endif
 #ifdef CONFIG_LS
 	APPLET(ls, ls_main, _BB_DIR_BIN)
 #endif
diff -urN ./include/usage.h /vol/d/root/busybox/include/usage.h
--- ./include/usage.h	Tue Feb  5 23:31:47 2002
+++ /vol/d/root/busybox/include/usage.h	Tue Feb 26 08:38:09 2002
@@ -988,6 +988,10 @@
 
 #define logread_full_usage \
         "Shows the messages from syslogd (using circular buffer)."
+#define losetup_trivial_usage \
+	"loop_device file"
+#define losetup_full_usage \
+	"Connects files to loop block devices"
 
 #ifdef CONFIG_FEATURE_LS_TIMESTAMPS
   #define USAGE_LS_TIMESTAMPS(a) a
Binary files ./scripts/mkdep and /vol/d/root/busybox/scripts/mkdep differ
diff -urN ./sysdeps/linux/defconfig /vol/d/root/busybox/sysdeps/linux/defconfig
--- ./sysdeps/linux/defconfig	Sat Nov 10 14:08:01 2001
+++ /vol/d/root/busybox/sysdeps/linux/defconfig	Tue Feb 26 09:12:37 2002
@@ -285,6 +285,7 @@
 # CONFIG_PIVOT_ROOT is not set
 # CONFIG_RDATE is not set
 # CONFIG_SWAPONOFF is not set
+# CONFIG_LOSETUP is not set
 CONFIG_MOUNT=y
 # CONFIG_NFSMOUNT is not set
 # CONFIG_FEATURE_USE_DEVPS_PATCH is not set
diff -urN ./util-linux/Makefile /vol/d/root/busybox/util-linux/Makefile
--- ./util-linux/Makefile	Fri Nov  2 12:39:46 2001
+++ /vol/d/root/busybox/util-linux/Makefile	Tue Feb 26 09:02:24 2002
@@ -31,6 +31,7 @@
 obj-$(CONFIG_FSCK_MINIX)	+= fsck_minix.o
 obj-$(CONFIG_GETOPT)		+= getopt.o
 obj-$(CONFIG_HEXDUMP)		+= hexdump.o
+obj-$(CONFIG_LOSETUP)		+= losetup.o
 obj-$(CONFIG_MKFS_MINIX)	+= mkfs_minix.o
 obj-$(CONFIG_MKSWAP)		+= mkswap.o
 obj-$(CONFIG_MORE)		+= more.o
diff -urN ./util-linux/config.in /vol/d/root/busybox/util-linux/config.in
--- ./util-linux/config.in	Sat Nov 10 13:07:24 2001
+++ /vol/d/root/busybox/util-linux/config.in	Tue Feb 26 09:43:53 2002
@@ -32,6 +32,7 @@
     comment '  Common options for ls and more'
     bool    '   Calculate terminal & column widths'	CONFIG_FEATURE_AUTOWIDTH
 fi
+boot 'losetup'		    CONFIG_LOSETUP
 bool 'pivot_root'	    CONFIG_PIVOT_ROOT
 bool 'rdate'		    CONFIG_RDATE
 bool 'swaponoff'	    CONFIG_SWAPONOFF
diff -urN ./util-linux/losetup.c /vol/d/root/busybox/util-linux/losetup.c
--- ./util-linux/losetup.c	Thu Jan  1 01:00:00 1970
+++ /vol/d/root/busybox/util-linux/losetup.c	Tue Feb 26 08:34:52 2002
@@ -0,0 +1,32 @@
+/* vi: set sw=4 ts=4: */
+/*
+ * based on pivot_root.c and mount.c which based on util-linux 2.10s
+ * connects files to loop block devices
+ *
+ * busyboxed 2002 by Bernhard M. Wiedemann
+ */
+#include <stdlib.h>
+#include <stdio.h>
+#include <errno.h>
+#include "busybox.h"
+
+int losetup_main(int argc, char **argv)
+{
+	int loro=0;
+    if (argc != 3)
+        show_usage();
+
+	if (set_loop(argv[1],argv[2],0,&loro) < 0)
+		perror_msg_and_die("Could not setup loop device");
+
+    return EXIT_SUCCESS;
+}
+
+
+/*
+Local Variables:
+c-file-style: "linux"
+c-basic-offset: 4
+tab-width: 4
+End:
+*/
-------------- next part --------------
diff -u -P busybox-0.60.2/Config.h busybox-0.60.2-bmw/Config.h
--- busybox-0.60.2/Config.h	Sun Oct 28 06:14:46 2001
+++ busybox-0.60.2-bmw/Config.h	Fri Feb 22 08:53:28 2002
@@ -68,6 +68,7 @@
 //#define BB_LOADKMAP
 #define BB_LOGGER
 //#define BB_LOGNAME
+#define BB_LOSETUP
 #define BB_LS
 #define BB_LSMOD
 //#define BB_MAKEDEVS
diff -u -P busybox-0.60.2/applets.h busybox-0.60.2-bmw/applets.h
--- busybox-0.60.2/applets.h	Sat Oct 27 01:08:04 2001
+++ busybox-0.60.2-bmw/applets.h	Fri Feb 22 08:53:28 2002
@@ -242,6 +242,9 @@
 #ifdef BB_LOGREAD
 	APPLET(logread, logread_main, _BB_DIR_SBIN)
 #endif
+#ifdef BB_LOSETUP
+	APPLET(losetup, losetup_main, _BB_DIR_SBIN)
+#endif
 #ifdef BB_LS
 	APPLET(ls, ls_main, _BB_DIR_BIN)
 #endif
Common subdirectories: busybox-0.60.2/bootfloppy and busybox-0.60.2-bmw/bootfloppy
Common subdirectories: busybox-0.60.2/debian and busybox-0.60.2-bmw/debian
Common subdirectories: busybox-0.60.2/docs and busybox-0.60.2-bmw/docs
Common subdirectories: busybox-0.60.2/kernel-patches and busybox-0.60.2-bmw/kernel-patches
Common subdirectories: busybox-0.60.2/libbb and busybox-0.60.2-bmw/libbb
diff -u -P busybox-0.60.2/losetup.c busybox-0.60.2-bmw/losetup.c
--- busybox-0.60.2/losetup.c	Thu Jan  1 01:00:00 1970
+++ busybox-0.60.2-bmw/losetup.c	Fri Feb 22 08:55:11 2002
@@ -0,0 +1,33 @@
+/* vi: set sw=4 ts=4: */
+/*
+ * based on pivot_root.c and mount.c which based on util-linux 2.10s 
+ * connects files to loop block devices
+ *
+ * busyboxed 2002 by Bernhard M. Wiedemann
+ */
+#include <stdlib.h>
+#include <stdio.h>
+#include <errno.h>
+#include "busybox.h"
+
+int losetup_main(int argc, char **argv)
+{
+	char *specialfile, *lofile;
+	int loro=0;
+	if (argc != 3)
+		show_usage();
+	specialfile=argv[1];
+	lofile=argv[2];
+	if (set_loop(specialfile, lofile, 0, &loro)) {
+		error_msg_and_die("Could not setup loop device");
+	}
+	return EXIT_SUCCESS;
+}
+
+/*
+Local Variables:
+c-file-style: "linux"
+c-basic-offset: 4
+tab-width: 4
+End:
+*/
Common subdirectories: busybox-0.60.2/pwd_grp and busybox-0.60.2-bmw/pwd_grp
Common subdirectories: busybox-0.60.2/scripts and busybox-0.60.2-bmw/scripts
Common subdirectories: busybox-0.60.2/tests and busybox-0.60.2-bmw/tests
diff -u -P busybox-0.60.2/usage.h busybox-0.60.2-bmw/usage.h
--- busybox-0.60.2/usage.h	Sat Oct 27 01:08:05 2001
+++ busybox-0.60.2-bmw/usage.h	Fri Feb 22 08:53:28 2002
@@ -902,6 +902,8 @@
 
 #define logread_full_usage \
         "Shows the messages from syslogd (using circular buffer)."
+#define losetup_trivial_usage \
+        "loop_device file"
 
 #ifdef BB_FEATURE_LS_TIMESTAMPS
   #define USAGE_LS_TIMESTAMPS(a) a


More information about the busybox mailing list