diff options
author | landley <landley@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 2005-11-29 23:47:10 +0000 |
---|---|---|
committer | landley <landley@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 2005-11-29 23:47:10 +0000 |
commit | af977c6e219aa2e3f45e3f6e73c9cedcf7bcc350 (patch) | |
tree | 4a6c23fb08ab9c8fa2e3ad68c9425f65a3fe6a21 /util-linux | |
parent | 929e65144578d72d3e5f72a1c0bc20edb42f1c3a (diff) | |
download | busybox-w32-af977c6e219aa2e3f45e3f6e73c9cedcf7bcc350.tar.gz busybox-w32-af977c6e219aa2e3f45e3f6e73c9cedcf7bcc350.tar.bz2 busybox-w32-af977c6e219aa2e3f45e3f6e73c9cedcf7bcc350.zip |
Fix losetup so that it A) actually works again, B) has much better error
messages, C) can show the current association (if any) when called
with only one argument. Update the documentation a lot too.
Remind me to add a test suite for this thing. I think I've figured out
how to handle root-only testsuites...
git-svn-id: svn://busybox.net/trunk/busybox@12582 69ca8d6d-28ef-0310-b511-8ec308f3f277
Diffstat (limited to 'util-linux')
-rw-r--r-- | util-linux/losetup.c | 24 |
1 files changed, 16 insertions, 8 deletions
diff --git a/util-linux/losetup.c b/util-linux/losetup.c index 11bd66ebf..b2af63dc0 100644 --- a/util-linux/losetup.c +++ b/util-linux/losetup.c | |||
@@ -24,8 +24,7 @@ | |||
24 | 24 | ||
25 | #include "busybox.h" | 25 | #include "busybox.h" |
26 | 26 | ||
27 | int | 27 | int losetup_main (int argc, char **argv) |
28 | losetup_main (int argc, char **argv) | ||
29 | { | 28 | { |
30 | int offset = 0; | 29 | int offset = 0; |
31 | 30 | ||
@@ -34,18 +33,27 @@ losetup_main (int argc, char **argv) | |||
34 | switch(getopt(argc,argv, "do:")) { | 33 | switch(getopt(argc,argv, "do:")) { |
35 | case 'd': | 34 | case 'd': |
36 | /* detach takes exactly one argument */ | 35 | /* detach takes exactly one argument */ |
37 | if(optind+1==argc) | 36 | if(optind+1==argc && !del_loop(argv[optind])) return EXIT_SUCCESS; |
38 | return del_loop(argv[optind]) ? EXIT_SUCCESS : EXIT_FAILURE; | 37 | die_failed: |
39 | break; | 38 | bb_perror_msg_and_die("%s",argv[optind]); |
40 | 39 | ||
41 | case 'o': | 40 | case 'o': |
42 | offset = bb_xparse_number (optarg, NULL); | 41 | offset = bb_xparse_number (optarg, NULL); |
43 | /* Fall through to do the losetup */ | 42 | /* Fall through to do the losetup */ |
44 | case -1: | 43 | case -1: |
45 | /* losetup takes two argument:, loop_device and file */ | 44 | /* losetup takes two argument:, loop_device and file */ |
46 | if(optind+2==argc) | 45 | if(optind+2==argc) { |
47 | return set_loop(&argv[optind], argv[optind + 1], offset)<0 | 46 | if(set_loop(&argv[optind], argv[optind + 1], offset)>=0) |
48 | ? EXIT_FAILURE : EXIT_SUCCESS; | 47 | return EXIT_SUCCESS; |
48 | else goto die_failed; | ||
49 | } | ||
50 | if(optind+1==argc) { | ||
51 | char *s=query_loop(argv[optind]); | ||
52 | if (!s) goto die_failed; | ||
53 | printf("%s: %s\n",argv[optind],s); | ||
54 | if(ENABLE_FEATURE_CLEAN_UP) free(s); | ||
55 | return EXIT_SUCCESS; | ||
56 | } | ||
49 | break; | 57 | break; |
50 | } | 58 | } |
51 | bb_show_usage(); | 59 | bb_show_usage(); |