OSDN Git Service

Make "losetup /dev/loop0 filename" work.
authorRob Landley <rob@landley.net>
Thu, 29 May 2014 11:29:12 +0000 (06:29 -0500)
committerRob Landley <rob@landley.net>
Thu, 29 May 2014 11:29:12 +0000 (06:29 -0500)
Sigh. Implement the complex cases and you screw up the simple cases you already tested...

toys/other/losetup.c

index 618016e..aad722e 100644 (file)
@@ -179,10 +179,13 @@ void losetup_main(void)
   } else {
     char *file = (toys.optflags & (FLAG_d|FLAG_c)) ? NULL : toys.optargs[1];
 
-    if (!toys.optc || (file && toys.optc>1)) {
+    if (!toys.optc || (file && toys.optc != 2)) {
       toys.exithelp++;
-      perror_exit("needs 1 arg");
+      perror_exit("needs %d arg%s", 1+!!file, file ? "s" : "");
+    }
+    for (s = toys.optargs; *s; s++) {
+      loopback_setup(*s, file);
+      if (file) break;
     }
-    for (s = toys.optargs; *s; s++) loopback_setup(*s, file);
   }
 }