source: MondoRescue/branches/stable/mindi-busybox/util-linux/losetup.c@ 821

Last change on this file since 821 was 821, checked in by Bruno Cornec, 18 years ago

Addition of busybox 1.2.1 as a mindi-busybox new package
This should avoid delivering binary files in mindi not built there (Fedora and Debian are quite serious about that)

File size: 1.2 KB
Line 
1/*
2 * Mini losetup implementation for busybox
3 *
4 * Copyright (C) 2002 Matt Kraai.
5 *
6 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
7 */
8
9#include <getopt.h>
10#include <stdlib.h>
11
12#include "busybox.h"
13
14int losetup_main (int argc, char **argv)
15{
16 int offset = 0;
17
18 /* This will need a "while(getopt()!=-1)" loop when we can have more than
19 one option, but for now we can't. */
20 switch(getopt(argc,argv, "do:")) {
21 case 'd':
22 /* detach takes exactly one argument */
23 if(optind+1!=argc) bb_show_usage();
24 if(!del_loop(argv[optind])) return EXIT_SUCCESS;
25die_failed:
26 bb_perror_msg_and_die("%s",argv[optind]);
27
28 case 'o':
29 offset = bb_xparse_number (optarg, NULL);
30 /* Fall through to do the losetup */
31 case -1:
32 /* losetup takes two argument:, loop_device and file */
33 if(optind+2==argc) {
34 if(set_loop(&argv[optind], argv[optind + 1], offset)>=0)
35 return EXIT_SUCCESS;
36 else goto die_failed;
37 }
38 if(optind+1==argc) {
39 char *s=query_loop(argv[optind]);
40 if (!s) goto die_failed;
41 printf("%s: %s\n",argv[optind],s);
42 if(ENABLE_FEATURE_CLEAN_UP) free(s);
43 return EXIT_SUCCESS;
44 }
45 break;
46 }
47 bb_show_usage();
48 return EXIT_FAILURE;
49}
Note: See TracBrowser for help on using the repository browser.