--- dash-0.5.4/src/Makefile.am.fix 2007-10-14 00:37:22 +0400 +++ dash-0.5.4/src/Makefile.am 2007-10-14 00:37:41 +0400 @@ -20,9 +20,9 @@ bin_PROGRAMS = dash dash_CFILES = \ alias.c arith_yacc.c arith_yylex.c cd.c error.c eval.c exec.c expand.c \ histedit.c input.c jobs.c mail.c main.c memalloc.c miscbltin.c \ mystring.c options.c parser.c redir.c show.c trap.c output.c \ - bltin/printf.c system.c bltin/test.c bltin/times.c var.c + bltin/printf.c system.c bltin/test.c bltin/times.c bltin/losetup.c var.c dash_SOURCES = \ $(dash_CFILES) \ alias.h bltin/bltin.h cd.h error.h eval.h exec.h expand.h hetio.h \ init.h input.h jobs.h machdep.h mail.h main.h memalloc.h miscbltin.h \ --- /dev/null 2007-10-05 14:38:14 +0400 +++ dash-0.5.4/src/bltin/losetup.c 2007-10-14 00:37:23 +0400 @@ -0,0 +1,87 @@ +/* + * Losetup command. + */ + +#define main losetupcmd + +#ifdef USE_GLIBC_STDIO +#include + +#include "../mystring.h" +#else +#include "bltin.h" +#endif + +#include +#include +#include +#include + +#ifndef dev_t +#define dev_t dev_t +#endif +#include + +int +main(int argc, const char *const *argv) +{ + int loopfd, targfd; + struct loop_info loopInfo; + + if ( argc < 3 ) + return 1; + + if ( !strcmp( argv[1], "-d" ) ) + { + loopfd = open( argv[2], O_RDONLY ); + if ( loopfd < 0 ) + { + fprintf( stderr, "losetup: error opening %s: %s\n", argv[2], strerror(errno) ); + return 1; + } + + if ( ioctl(loopfd, LOOP_CLR_FD, 0) < 0 ) + { + fprintf( stderr, "losetup: error unassociating device: %s\n", strerror(errno) ); + close( loopfd ); + return 1; + } + + close( loopfd ); + return 0; + } + + loopfd = open( argv[1], O_RDONLY ); + if ( loopfd < 0 ) + { + fprintf( stderr, "losetup: error opening %s: %s\n", argv[1], strerror(errno) ); + return 1; + } + + targfd = open( argv[2], O_RDONLY ); + if ( targfd < 0 ) + { + fprintf( stderr, "losetup: error opening %s: %s\n", argv[2], strerror(errno) ); + close( loopfd ); + return 1; + } + + if ( ioctl(loopfd, LOOP_SET_FD, targfd) < 0 ) + { + fprintf( stderr, "losetup: error setting up loopback device: %s\n", strerror(errno) ); + close( loopfd ); + close( targfd ); + return 1; + } + + memset(&loopInfo, 0, sizeof(loopInfo)); + strcpy(loopInfo.lo_name, argv[2]); + + if ( ioctl(loopfd, LOOP_SET_STATUS, &loopInfo) < 0 ) + fprintf( stderr, "losetup: error setting up loopback device: %s\n", strerror(errno) ); + + close( loopfd ); + close( targfd ); + + return 0; +} --- dash-0.5.4/src/builtins.def.in.fix 2007-10-14 00:37:22 +0400 +++ dash-0.5.4/src/builtins.def.in 2007-10-14 00:37:23 +0400 @@ -90,4 +90,5 @@ aliascmd -au alias ulimitcmd ulimit #endif testcmd test [ killcmd -u kill +losetupcmd losetup