2006-12-06 17:25:32 -06:00
|
|
|
|
/* Taken from Ted's losetup.c - Mitch <m.dsouza@mrc-apu.cam.ac.uk> */
|
2006-12-06 17:25:34 -06:00
|
|
|
|
/* Added vfs mount options - aeb - 960223 */
|
|
|
|
|
/* Removed lomount - aeb - 960224 */
|
|
|
|
|
|
2006-12-06 17:26:13 -06:00
|
|
|
|
/* 1999-02-22 Arkadiusz Mi<4D>kiewicz <misiek@pld.ORG.PL>
|
2006-12-06 17:25:39 -06:00
|
|
|
|
* - added Native Language Support
|
2006-12-06 17:26:13 -06:00
|
|
|
|
* Sun Mar 21 1999 - Arnaldo Carvalho de Melo <acme@conectiva.com.br>
|
2006-12-06 17:25:39 -06:00
|
|
|
|
* - fixed strerr(errno) in gettext calls
|
|
|
|
|
*/
|
|
|
|
|
|
2006-12-06 17:26:13 -06:00
|
|
|
|
#define PROC_DEVICES "/proc/devices"
|
2006-12-06 17:25:32 -06:00
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* losetup.c - setup and control loop devices
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
#include <ctype.h>
|
|
|
|
|
#include <fcntl.h>
|
2006-12-06 17:25:34 -06:00
|
|
|
|
#include <errno.h>
|
2006-12-06 17:25:32 -06:00
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <unistd.h>
|
|
|
|
|
#include <sys/ioctl.h>
|
2006-12-06 17:25:34 -06:00
|
|
|
|
#include <sys/stat.h>
|
2006-12-06 17:25:43 -06:00
|
|
|
|
#include <sys/mman.h>
|
2006-12-06 17:26:05 -06:00
|
|
|
|
#include <sys/sysmacros.h>
|
2006-12-06 17:25:32 -06:00
|
|
|
|
|
2006-12-06 17:25:34 -06:00
|
|
|
|
#include "loop.h"
|
|
|
|
|
#include "lomount.h"
|
2006-12-06 17:25:46 -06:00
|
|
|
|
#include "xstrncpy.h"
|
2006-12-06 17:25:39 -06:00
|
|
|
|
#include "nls.h"
|
2006-12-06 17:25:32 -06:00
|
|
|
|
|
2006-12-06 17:25:43 -06:00
|
|
|
|
extern int verbose;
|
|
|
|
|
extern char *xstrdup (const char *s); /* not: #include "sundries.h" */
|
|
|
|
|
extern void error (const char *fmt, ...); /* idem */
|
2006-12-06 17:25:35 -06:00
|
|
|
|
|
2006-12-06 17:25:34 -06:00
|
|
|
|
#ifdef LOOP_SET_FD
|
2006-12-06 17:26:13 -06:00
|
|
|
|
struct crypt_type_struct {
|
|
|
|
|
int id;
|
|
|
|
|
char *name;
|
|
|
|
|
} crypt_type_tbl[] = {
|
|
|
|
|
{ LO_CRYPT_NONE, "no" },
|
|
|
|
|
{ LO_CRYPT_NONE, "none" },
|
|
|
|
|
{ LO_CRYPT_XOR, "xor" },
|
|
|
|
|
{ LO_CRYPT_DES, "DES" },
|
|
|
|
|
{ -1, NULL }
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
|
crypt_type (const char *name) {
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
if (name) {
|
|
|
|
|
for (i = 0; crypt_type_tbl[i].id != -1; i++)
|
|
|
|
|
if (!strcasecmp (name, crypt_type_tbl[i].name))
|
|
|
|
|
return crypt_type_tbl[i].id;
|
|
|
|
|
}
|
|
|
|
|
return -1;
|
2006-12-06 17:25:32 -06:00
|
|
|
|
}
|
|
|
|
|
|
2006-12-06 17:25:43 -06:00
|
|
|
|
#ifdef MAIN
|
2006-12-06 17:26:13 -06:00
|
|
|
|
static char *
|
|
|
|
|
crypt_name (int id) {
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
for (i = 0; crypt_type_tbl[i].id != -1; i++)
|
|
|
|
|
if (id == crypt_type_tbl[i].id)
|
|
|
|
|
return crypt_type_tbl[i].name;
|
|
|
|
|
return "undefined";
|
|
|
|
|
}
|
2006-12-06 17:25:32 -06:00
|
|
|
|
|
2006-12-06 17:25:44 -06:00
|
|
|
|
static int
|
2006-12-06 17:26:13 -06:00
|
|
|
|
show_loop (char *device) {
|
2006-12-06 17:25:43 -06:00
|
|
|
|
struct loop_info loopinfo;
|
2006-12-06 17:26:13 -06:00
|
|
|
|
int fd;
|
2006-12-06 17:25:43 -06:00
|
|
|
|
|
2006-12-06 17:26:13 -06:00
|
|
|
|
if ((fd = open (device, O_RDONLY)) < 0) {
|
2006-12-06 17:25:43 -06:00
|
|
|
|
int errsv = errno;
|
|
|
|
|
fprintf(stderr, _("loop: can't open device %s: %s\n"),
|
|
|
|
|
device, strerror (errsv));
|
2006-12-06 17:25:44 -06:00
|
|
|
|
return 2;
|
2006-12-06 17:25:43 -06:00
|
|
|
|
}
|
2006-12-06 17:26:13 -06:00
|
|
|
|
if (ioctl (fd, LOOP_GET_STATUS, &loopinfo) < 0) {
|
|
|
|
|
int errsv = errno;
|
|
|
|
|
fprintf(stderr, _("loop: can't get info on device %s: %s\n"),
|
|
|
|
|
device, strerror (errsv));
|
2006-12-06 17:26:12 -06:00
|
|
|
|
close (fd);
|
2006-12-06 17:26:13 -06:00
|
|
|
|
return 1;
|
2006-12-06 17:26:12 -06:00
|
|
|
|
}
|
2006-12-06 17:26:13 -06:00
|
|
|
|
printf (_("%s: [%04x]:%ld (%s) offset %d, %s encryption\n"),
|
|
|
|
|
device, loopinfo.lo_device, loopinfo.lo_inode,
|
|
|
|
|
loopinfo.lo_name, loopinfo.lo_offset,
|
|
|
|
|
crypt_name (loopinfo.lo_encrypt_type));
|
2006-12-06 17:26:12 -06:00
|
|
|
|
close (fd);
|
2006-12-06 17:26:13 -06:00
|
|
|
|
|
|
|
|
|
return 0;
|
2006-12-06 17:25:32 -06:00
|
|
|
|
}
|
2006-12-06 17:25:34 -06:00
|
|
|
|
#endif
|
|
|
|
|
|
2006-12-06 17:25:44 -06:00
|
|
|
|
int
|
|
|
|
|
is_loop_device (const char *device) {
|
|
|
|
|
struct stat statbuf;
|
2006-12-06 17:26:13 -06:00
|
|
|
|
int loopmajor;
|
|
|
|
|
#if 1
|
|
|
|
|
loopmajor = 7;
|
|
|
|
|
#else
|
|
|
|
|
FILE *procdev;
|
|
|
|
|
char line[100], *cp;
|
|
|
|
|
|
|
|
|
|
loopmajor = 0;
|
|
|
|
|
if ((procdev = fopen(PROC_DEVICES, "r")) != NULL) {
|
|
|
|
|
while (fgets (line, sizeof(line), procdev)) {
|
|
|
|
|
if ((cp = strstr (line, " loop\n")) != NULL) {
|
|
|
|
|
*cp='\0';
|
|
|
|
|
loopmajor=atoi(line);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
fclose(procdev);
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
return (loopmajor && stat(device, &statbuf) == 0 &&
|
2006-12-06 17:25:44 -06:00
|
|
|
|
S_ISBLK(statbuf.st_mode) &&
|
2006-12-06 17:26:13 -06:00
|
|
|
|
major(statbuf.st_rdev) == loopmajor);
|
2006-12-06 17:25:44 -06:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#define SIZE(a) (sizeof(a)/sizeof(a[0]))
|
|
|
|
|
|
2006-12-06 17:25:34 -06:00
|
|
|
|
char *
|
2006-12-06 17:25:43 -06:00
|
|
|
|
find_unused_loop_device (void) {
|
|
|
|
|
/* Just creating a device, say in /tmp, is probably a bad idea -
|
|
|
|
|
people might have problems with backup or so.
|
|
|
|
|
So, we just try /dev/loop[0-7]. */
|
|
|
|
|
char dev[20];
|
2006-12-06 17:25:44 -06:00
|
|
|
|
char *loop_formats[] = { "/dev/loop%d", "/dev/loop/%d" };
|
2006-12-06 17:26:13 -06:00
|
|
|
|
int i, j, fd, somedev = 0, someloop = 0, loop_known = 0;
|
2006-12-06 17:25:43 -06:00
|
|
|
|
struct stat statbuf;
|
|
|
|
|
struct loop_info loopinfo;
|
2006-12-06 17:26:13 -06:00
|
|
|
|
FILE *procdev;
|
2006-12-06 17:25:43 -06:00
|
|
|
|
|
2006-12-06 17:25:44 -06:00
|
|
|
|
for (j = 0; j < SIZE(loop_formats); j++) {
|
|
|
|
|
for(i = 0; i < 256; i++) {
|
|
|
|
|
sprintf(dev, loop_formats[j], i);
|
2006-12-06 17:25:43 -06:00
|
|
|
|
if (stat (dev, &statbuf) == 0 && S_ISBLK(statbuf.st_mode)) {
|
|
|
|
|
somedev++;
|
|
|
|
|
fd = open (dev, O_RDONLY);
|
|
|
|
|
if (fd >= 0) {
|
|
|
|
|
if(ioctl (fd, LOOP_GET_STATUS, &loopinfo) == 0)
|
|
|
|
|
someloop++; /* in use */
|
|
|
|
|
else if (errno == ENXIO) {
|
|
|
|
|
close (fd);
|
|
|
|
|
return xstrdup(dev);/* probably free */
|
|
|
|
|
}
|
|
|
|
|
close (fd);
|
|
|
|
|
}
|
|
|
|
|
continue;/* continue trying as long as devices exist */
|
|
|
|
|
}
|
2006-12-06 17:25:44 -06:00
|
|
|
|
break;
|
|
|
|
|
}
|
2006-12-06 17:25:34 -06:00
|
|
|
|
}
|
2006-12-06 17:25:43 -06:00
|
|
|
|
|
2006-12-06 17:26:13 -06:00
|
|
|
|
/* Nothing found. Why not? */
|
|
|
|
|
if ((procdev = fopen(PROC_DEVICES, "r")) != NULL) {
|
|
|
|
|
char line[100];
|
|
|
|
|
while (fgets (line, sizeof(line), procdev))
|
|
|
|
|
if (strstr (line, " loop\n")) {
|
|
|
|
|
loop_known = 1;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
fclose(procdev);
|
|
|
|
|
if (!loop_known)
|
|
|
|
|
loop_known = -1;
|
|
|
|
|
}
|
|
|
|
|
|
2006-12-06 17:25:43 -06:00
|
|
|
|
if (!somedev)
|
|
|
|
|
error(_("mount: could not find any device /dev/loop#"));
|
2006-12-06 17:26:05 -06:00
|
|
|
|
else if (!someloop) {
|
2006-12-06 17:26:13 -06:00
|
|
|
|
if (loop_known == 1)
|
|
|
|
|
error(_(
|
|
|
|
|
"mount: Could not find any loop device.\n"
|
|
|
|
|
" Maybe /dev/loop# has a wrong major number?"));
|
|
|
|
|
else if (loop_known == -1)
|
|
|
|
|
error(_(
|
|
|
|
|
"mount: Could not find any loop device, and, according to %s,\n"
|
|
|
|
|
" this kernel does not know about the loop device.\n"
|
|
|
|
|
" (If so, then recompile or `insmod loop.o'.)"),
|
|
|
|
|
PROC_DEVICES);
|
|
|
|
|
else
|
2006-12-06 17:25:43 -06:00
|
|
|
|
error(_(
|
2006-12-06 17:26:13 -06:00
|
|
|
|
"mount: Could not find any loop device. Maybe this kernel does not know\n"
|
|
|
|
|
" about the loop device (then recompile or `insmod loop.o'), or\n"
|
|
|
|
|
" maybe /dev/loop# has the wrong major number?"));
|
2006-12-06 17:25:43 -06:00
|
|
|
|
} else
|
|
|
|
|
error(_("mount: could not find any free loop device"));
|
|
|
|
|
return 0;
|
2006-12-06 17:25:34 -06:00
|
|
|
|
}
|
2006-12-06 17:25:32 -06:00
|
|
|
|
|
|
|
|
|
int
|
2006-12-06 17:26:13 -06:00
|
|
|
|
set_loop (const char *device, const char *file, int offset,
|
|
|
|
|
const char *encryption, int *loopro) {
|
|
|
|
|
struct loop_info loopinfo;
|
|
|
|
|
int fd, ffd, mode, i;
|
2006-12-06 17:25:43 -06:00
|
|
|
|
char *pass;
|
|
|
|
|
|
|
|
|
|
mode = (*loopro ? O_RDONLY : O_RDWR);
|
2006-12-06 17:26:13 -06:00
|
|
|
|
if ((ffd = open (file, mode)) < 0) {
|
2006-12-06 17:25:43 -06:00
|
|
|
|
if (!*loopro && errno == EROFS)
|
2006-12-06 17:26:13 -06:00
|
|
|
|
ffd = open (file, mode = O_RDONLY);
|
2006-12-06 17:25:43 -06:00
|
|
|
|
if (ffd < 0) {
|
2006-12-06 17:26:13 -06:00
|
|
|
|
perror (file);
|
2006-12-06 17:25:43 -06:00
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
2006-12-06 17:26:13 -06:00
|
|
|
|
if ((fd = open (device, mode)) < 0) {
|
2006-12-06 17:25:43 -06:00
|
|
|
|
perror (device);
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
*loopro = (mode == O_RDONLY);
|
|
|
|
|
|
2006-12-06 17:26:13 -06:00
|
|
|
|
memset (&loopinfo, 0, sizeof (loopinfo));
|
|
|
|
|
xstrncpy (loopinfo.lo_name, file, LO_NAME_SIZE);
|
|
|
|
|
if (encryption && (loopinfo.lo_encrypt_type = crypt_type (encryption))
|
|
|
|
|
< 0) {
|
|
|
|
|
fprintf (stderr, _("Unsupported encryption type %s\n"),
|
|
|
|
|
encryption);
|
|
|
|
|
return 1;
|
2006-12-06 17:25:43 -06:00
|
|
|
|
}
|
2006-12-06 17:26:13 -06:00
|
|
|
|
loopinfo.lo_offset = offset;
|
2006-12-06 17:25:43 -06:00
|
|
|
|
|
|
|
|
|
#ifdef MCL_FUTURE
|
|
|
|
|
/*
|
|
|
|
|
* Oh-oh, sensitive data coming up. Better lock into memory to prevent
|
|
|
|
|
* passwd etc being swapped out and left somewhere on disk.
|
|
|
|
|
*/
|
|
|
|
|
|
2006-12-06 17:25:46 -06:00
|
|
|
|
if(mlockall(MCL_CURRENT | MCL_FUTURE)) {
|
2006-12-06 17:25:43 -06:00
|
|
|
|
perror("memlock");
|
|
|
|
|
fprintf(stderr, _("Couldn't lock into memory, exiting.\n"));
|
|
|
|
|
exit(1);
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
2006-12-06 17:26:13 -06:00
|
|
|
|
switch (loopinfo.lo_encrypt_type) {
|
2006-12-06 17:25:43 -06:00
|
|
|
|
case LO_CRYPT_NONE:
|
2006-12-06 17:26:13 -06:00
|
|
|
|
loopinfo.lo_encrypt_key_size = 0;
|
2006-12-06 17:25:43 -06:00
|
|
|
|
break;
|
|
|
|
|
case LO_CRYPT_XOR:
|
2006-12-06 17:26:13 -06:00
|
|
|
|
pass = getpass (_("Password: "));
|
|
|
|
|
xstrncpy (loopinfo.lo_encrypt_key, pass, LO_KEY_SIZE);
|
|
|
|
|
loopinfo.lo_encrypt_key_size = strlen(loopinfo.lo_encrypt_key);
|
|
|
|
|
break;
|
|
|
|
|
case LO_CRYPT_DES:
|
|
|
|
|
pass = getpass (_("Password: "));
|
|
|
|
|
strncpy (loopinfo.lo_encrypt_key, pass, 8);
|
|
|
|
|
loopinfo.lo_encrypt_key[8] = 0;
|
|
|
|
|
loopinfo.lo_encrypt_key_size = 8;
|
|
|
|
|
pass = getpass (_("Init (up to 16 hex digits): "));
|
|
|
|
|
for (i = 0; i < 16 && pass[i]; i++)
|
|
|
|
|
if (isxdigit (pass[i])) {
|
|
|
|
|
loopinfo.lo_init[i >> 3] |= (pass[i] > '9' ?
|
|
|
|
|
(islower (pass[i]) ? toupper (pass[i]) :
|
|
|
|
|
pass[i])-'A'+10 : pass[i]-'0') << (i&7) * 4;
|
|
|
|
|
} else {
|
|
|
|
|
fprintf (stderr, _("Non-hex digit '%c'.\n"),
|
|
|
|
|
pass[i]);
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
2006-12-06 17:25:43 -06:00
|
|
|
|
break;
|
|
|
|
|
default:
|
2006-12-06 17:26:13 -06:00
|
|
|
|
fprintf (stderr,
|
|
|
|
|
_("Don't know how to get key for encryption system %d\n"),
|
|
|
|
|
loopinfo.lo_encrypt_type);
|
|
|
|
|
return 1;
|
2006-12-06 17:25:43 -06:00
|
|
|
|
}
|
2006-12-06 17:26:13 -06:00
|
|
|
|
if (ioctl (fd, LOOP_SET_FD, ffd) < 0) {
|
|
|
|
|
perror ("ioctl: LOOP_SET_FD");
|
2006-12-06 17:25:43 -06:00
|
|
|
|
return 1;
|
|
|
|
|
}
|
2006-12-06 17:26:13 -06:00
|
|
|
|
if (ioctl (fd, LOOP_SET_STATUS, &loopinfo) < 0) {
|
|
|
|
|
(void) ioctl (fd, LOOP_CLR_FD, 0);
|
|
|
|
|
perror ("ioctl: LOOP_SET_STATUS");
|
|
|
|
|
return 1;
|
2006-12-06 17:25:43 -06:00
|
|
|
|
}
|
|
|
|
|
close (fd);
|
2006-12-06 17:26:13 -06:00
|
|
|
|
close (ffd);
|
2006-12-06 17:25:43 -06:00
|
|
|
|
if (verbose > 1)
|
|
|
|
|
printf(_("set_loop(%s,%s,%d): success\n"),
|
|
|
|
|
device, file, offset);
|
|
|
|
|
return 0;
|
2006-12-06 17:25:32 -06:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int
|
2006-12-06 17:25:43 -06:00
|
|
|
|
del_loop (const char *device) {
|
|
|
|
|
int fd;
|
|
|
|
|
|
|
|
|
|
if ((fd = open (device, O_RDONLY)) < 0) {
|
|
|
|
|
int errsv = errno;
|
|
|
|
|
fprintf(stderr, _("loop: can't delete device %s: %s\n"),
|
|
|
|
|
device, strerror (errsv));
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
if (ioctl (fd, LOOP_CLR_FD, 0) < 0) {
|
|
|
|
|
perror ("ioctl: LOOP_CLR_FD");
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
close (fd);
|
|
|
|
|
if (verbose > 1)
|
|
|
|
|
printf(_("del_loop(%s): success\n"), device);
|
|
|
|
|
return 0;
|
2006-12-06 17:25:32 -06:00
|
|
|
|
}
|
|
|
|
|
|
2006-12-06 17:25:34 -06:00
|
|
|
|
#else /* no LOOP_SET_FD defined */
|
|
|
|
|
static void
|
|
|
|
|
mutter(void) {
|
2006-12-06 17:25:43 -06:00
|
|
|
|
fprintf(stderr,
|
|
|
|
|
_("This mount was compiled without loop support. "
|
|
|
|
|
"Please recompile.\n"));
|
2006-12-06 17:25:34 -06:00
|
|
|
|
}
|
2006-12-06 17:25:32 -06:00
|
|
|
|
|
2006-12-06 17:25:34 -06:00
|
|
|
|
int
|
|
|
|
|
set_loop (const char *device, const char *file, int offset,
|
|
|
|
|
const char *encryption, int *loopro) {
|
2006-12-06 17:25:43 -06:00
|
|
|
|
mutter();
|
|
|
|
|
return 1;
|
2006-12-06 17:25:34 -06:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
|
del_loop (const char *device) {
|
2006-12-06 17:25:43 -06:00
|
|
|
|
mutter();
|
|
|
|
|
return 1;
|
2006-12-06 17:25:32 -06:00
|
|
|
|
}
|
2006-12-06 17:25:34 -06:00
|
|
|
|
|
|
|
|
|
char *
|
|
|
|
|
find_unused_loop_device (void) {
|
2006-12-06 17:25:43 -06:00
|
|
|
|
mutter();
|
|
|
|
|
return 0;
|
2006-12-06 17:25:34 -06:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endif
|
2006-12-06 17:25:43 -06:00
|
|
|
|
|
|
|
|
|
#ifdef MAIN
|
|
|
|
|
|
|
|
|
|
#ifdef LOOP_SET_FD
|
|
|
|
|
|
|
|
|
|
#include <getopt.h>
|
|
|
|
|
#include <stdarg.h>
|
|
|
|
|
|
|
|
|
|
int verbose = 0;
|
|
|
|
|
static char *progname;
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
usage(void) {
|
|
|
|
|
fprintf(stderr, _("usage:\n\
|
|
|
|
|
%s loop_device # give info\n\
|
|
|
|
|
%s -d loop_device # delete\n\
|
|
|
|
|
%s [ -e encryption ] [ -o offset ] loop_device file # setup\n"),
|
|
|
|
|
progname, progname, progname);
|
|
|
|
|
exit(1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
char *
|
|
|
|
|
xstrdup (const char *s) {
|
|
|
|
|
char *t;
|
|
|
|
|
|
|
|
|
|
if (s == NULL)
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
t = strdup (s);
|
|
|
|
|
|
|
|
|
|
if (t == NULL) {
|
|
|
|
|
fprintf(stderr, _("not enough memory"));
|
|
|
|
|
exit(1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return t;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
error (const char *fmt, ...) {
|
|
|
|
|
va_list args;
|
|
|
|
|
|
|
|
|
|
va_start (args, fmt);
|
|
|
|
|
vfprintf (stderr, fmt, args);
|
|
|
|
|
va_end (args);
|
|
|
|
|
fprintf (stderr, "\n");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
|
main(int argc, char **argv) {
|
2006-12-06 17:26:13 -06:00
|
|
|
|
char *offset, *encryption;
|
|
|
|
|
int delete,off,c;
|
2006-12-06 17:25:43 -06:00
|
|
|
|
int res = 0;
|
|
|
|
|
int ro = 0;
|
|
|
|
|
|
|
|
|
|
setlocale(LC_ALL, "");
|
|
|
|
|
bindtextdomain(PACKAGE, LOCALEDIR);
|
|
|
|
|
textdomain(PACKAGE);
|
|
|
|
|
|
|
|
|
|
delete = off = 0;
|
2006-12-06 17:26:13 -06:00
|
|
|
|
offset = encryption = NULL;
|
2006-12-06 17:25:43 -06:00
|
|
|
|
progname = argv[0];
|
2006-12-06 17:26:13 -06:00
|
|
|
|
while ((c = getopt(argc,argv,"de:o:v")) != -1) {
|
2006-12-06 17:25:43 -06:00
|
|
|
|
switch (c) {
|
|
|
|
|
case 'd':
|
|
|
|
|
delete = 1;
|
|
|
|
|
break;
|
|
|
|
|
case 'e':
|
|
|
|
|
encryption = optarg;
|
|
|
|
|
break;
|
|
|
|
|
case 'o':
|
|
|
|
|
offset = optarg;
|
|
|
|
|
break;
|
|
|
|
|
case 'v':
|
|
|
|
|
verbose = 1;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
usage();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (argc == 1) usage();
|
|
|
|
|
if ((delete && (argc != optind+1 || encryption || offset)) ||
|
|
|
|
|
(!delete && (argc < optind+1 || argc > optind+2)))
|
|
|
|
|
usage();
|
|
|
|
|
if (argc == optind+1) {
|
|
|
|
|
if (delete)
|
|
|
|
|
res = del_loop(argv[optind]);
|
|
|
|
|
else
|
2006-12-06 17:25:44 -06:00
|
|
|
|
res = show_loop(argv[optind]);
|
2006-12-06 17:25:43 -06:00
|
|
|
|
} else {
|
|
|
|
|
if (offset && sscanf(offset,"%d",&off) != 1)
|
|
|
|
|
usage();
|
2006-12-06 17:26:13 -06:00
|
|
|
|
res = set_loop(argv[optind],argv[optind+1],off,encryption,&ro);
|
2006-12-06 17:25:43 -06:00
|
|
|
|
}
|
|
|
|
|
return res;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#else /* LOOP_SET_FD not defined */
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
|
main(int argc, char **argv) {
|
|
|
|
|
fprintf(stderr,
|
|
|
|
|
_("No loop support was available at compile time. "
|
|
|
|
|
"Please recompile.\n"));
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
#endif
|