--- sash-3.7/cmds.c.losetup 2002-07-22 00:28:19.000000000 +0200 +++ sash-3.7/cmds.c 2009-04-11 15:09:07.000000000 +0200 @@ -21,6 +21,7 @@ #include <linux/fs.h> #endif +#include <linux/loop.h> void do_echo(int argc, const char ** argv) @@ -1253,4 +1254,58 @@ printf("Program \"%s\" not found in PATH\n", program); } +void +do_losetup(int argc, const char ** argv) +{ + int loopfd; + int targfd; + struct loop_info loopInfo; + + if (!strcmp(argv[1], "-d")) { + loopfd = open(argv[2], O_RDONLY); + if (loopfd < 0) { + fprintf(stderr, "Error opening %s: %s\n", argv[2], + strerror(errno)); + return; + } + + if (ioctl(loopfd, LOOP_CLR_FD, 0)) { + fprintf(stderr, "Error unassociating device: %s\n", + strerror(errno)); + return; + } + } + + loopfd = open(argv[1], O_RDONLY); + if (loopfd < 0) { + fprintf(stderr, "Error opening %s: %s\n", argv[1], + strerror(errno)); + return; + } + + targfd = open(argv[2], O_RDONLY); + if (targfd < 0) { + fprintf(stderr, "Error opening %s: %s\n", argv[2], + strerror(errno)); + return; + } + + if (ioctl(loopfd, LOOP_SET_FD, targfd)) { + fprintf(stderr, "Error setting up loopback device: %s\n", + strerror(errno)); + return; + } + + memset(&loopInfo, 0, sizeof(loopInfo)); + strcpy(loopInfo.lo_name, argv[2]); + + if (ioctl(loopfd, LOOP_SET_STATUS, &loopInfo)) { + fprintf(stderr, "Error setting up loopback device: %s\n", + strerror(errno)); + return; + } + + return; +} + /* END CODE */ --- sash-3.7/sash.1.losetup 2004-01-14 06:04:50.000000000 +0100 +++ sash-3.7/sash.1 2009-04-11 15:09:07.000000000 +0200 @@ -24,9 +24,9 @@ .nf -ar, -chattr, -chgrp, -chmod, -chown, -cmp, -cp, -dd, -echo, -ed, -grep, -file, -find, -gunzip, - -gzip, -kill, -ln, -ls, -lsattr, -mkdir, -mknod, - -more, -mount, -mv, -printenv, -pwd, -rm, -rmdir, - -sum, -sync, -tar, -touch, -umount, -where + -gzip, -kill, -losetup, -ln, -ls, -lsattr, -mkdir, + -mknod, -more, -mount, -mv, -printenv, -pwd, -rm, + -rmdir, -sum, -sync, -tar, -touch, -umount, -where .fi .PP These commands are generally similar to the standard programs with similar @@ -312,6 +312,12 @@ QUIT, KILL, TERM, STOP, CONT, USR1 or USR2. If no signal is specified then SIGTERM is used. .TP +.B -losetup [-d] loopDev [file] +Associates loopback devices with files on the system. If -d is not given, +the loopback device \fBloopDev\fR is associated with \fBfile\fR. If -d is +given, \fBloopDev\fR is unassociated with the file it's currently configured +for. +.TP .B -ln [-s] srcName ... destName Links one or more files from the .I srcName --- sash-3.7/sash.c.losetup 2004-01-14 06:08:03.000000000 +0100 +++ sash-3.7/sash.c 2009-04-11 15:09:07.000000000 +0200 @@ -182,6 +182,12 @@ }, { + "-losetup", do_losetup, 3, 3, + "Associate a loopback device with a file", + "[-d] device\n -losetup device filename" + }, + + { "-ln", do_ln, 3, INFINITE_ARGS, "Link one fileName to another", "[-s] srcName ... destName" --- sash-3.7/sash.h.losetup 2002-07-22 00:05:17.000000000 +0200 +++ sash-3.7/sash.h 2009-04-11 15:09:07.000000000 +0200 @@ -99,6 +99,7 @@ extern void do_find(int argc, const char ** argv); extern void do_ed(int argc, const char ** argv); extern void do_where(int argc, const char ** argv); +extern void do_losetup(int argc, const char ** argv); #if HAVE_GZIP extern void do_gzip(int argc, const char ** argv);