diff -urN busybox-0.51-elfboot/Config.h busybox-0.51-losetup/Config.h --- busybox-0.51-elfboot/Config.h Tue Apr 10 00:48:11 2001 +++ busybox-0.51-losetup/Config.h Mon Apr 23 19:18:01 2001 @@ -62,6 +62,7 @@ //#define BB_LOADKMAP #define BB_LOGGER //#define BB_LOGNAME +//#define BB_LOSETUP #define BB_LS #define BB_LSMOD //#define BB_MAKEDEVS diff -urN busybox-0.51-elfboot/applets.h busybox-0.51-losetup/applets.h --- busybox-0.51-elfboot/applets.h Mon Apr 23 19:01:15 2001 +++ busybox-0.51-losetup/applets.h Mon Apr 23 19:06:30 2001 @@ -233,6 +233,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 diff -urN busybox-0.51-elfboot/losetup.c busybox-0.51-losetup/losetup.c --- busybox-0.51-elfboot/losetup.c Thu Jan 1 01:00:00 1970 +++ busybox-0.51-losetup/losetup.c Mon Apr 23 19:15:00 2001 @@ -0,0 +1,102 @@ +/* vi: set sw=4 ts=4: */ +/* + * losetup.c - setup and control loop devices + * + * 23-Apr-2001: Now for 0.51 + * 14-Mar-2001: Ported up to 0.50pre by Magnus Damm . + * + * The old CVS code says it's based on mount-2.6d and that + * Erik Andersen did the BusyBox adaption. + * + * Encryption is not supported for now. + * + * 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 + * + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "busybox.h" +#include "libbb/loop.h" + +static void show_loop(const char *device) +{ + struct loop_info loopinfo; + int fd; + + if ((fd = open(device, O_RDWR)) < 0) { + perror(device); + return; + } + if (ioctl(fd, LOOP_GET_STATUS, &loopinfo) < 0) { + perror("Cannot get loop info"); + close(fd); + return; + } + printf("%s: [%04x]:%ld (%s) offset %d\n", + device, (unsigned int) loopinfo.lo_device, loopinfo.lo_inode, + loopinfo.lo_name, loopinfo.lo_offset); + close(fd); +} + +int losetup_main(int argc, char **argv) +{ + char *offset; + int delete, off, c; + int ro = 0; + + delete = off = 0; + offset = NULL; + while ((c = getopt(argc, argv, "do:")) != EOF) { + switch (c) { + case 'd': + delete = 1; + break; + case 'o': + offset = optarg; + break; + default: + show_usage(); + } + } + if (argc == 1) { + show_usage(); + } + + if ((delete && (argc != optind + 1 || offset)) || + (!delete && (argc < optind + 1 || argc > optind + 2))) + show_usage(); + + if (argc == optind + 1) + if (delete) + return del_loop(argv[optind]); + else + show_loop(argv[optind]); + else { + if (offset && sscanf(offset, "%d", &off) != 1) + show_usage(); + + return set_loop(argv[optind], argv[optind + 1], off, &ro); + } + return 0; +} diff -urN busybox-0.51-elfboot/usage.h busybox-0.51-losetup/usage.h --- busybox-0.51-elfboot/usage.h Mon Apr 23 19:01:15 2001 +++ busybox-0.51-losetup/usage.h Mon Apr 23 19:16:04 2001 @@ -889,6 +889,14 @@ #define logread_full_usage \ "Shows the messages from syslogd (using circular buffer)." +#define losetup_trivial_usage \ + "[OPTION]... loop_device [file]" +#define losetup_full_usage \ + "Set up and control loop devices.\n\n" \ + "\tlosetup loop_device give info\n" \ + "\tlosetup -d loop_device delete\n" \ + "\tlosetup [ -o offset ] loop_device file setup" + #ifdef BB_FEATURE_LS_TIMESTAMPS #define USAGE_LS_TIMESTAMPS(a) a #else