aboutsummaryrefslogtreecommitdiff
path: root/util-linux
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2011-09-12 02:13:47 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2011-09-12 08:30:16 +0200
commit13e709c53f700a18a660feebdf72c613a233bf48 (patch)
tree248b913b7bb6629b751bbd5a79a7e3c6b55dd1af /util-linux
parentdd1061b6a79b0161597799e825bfefc27993ace5 (diff)
downloadbusybox-w32-13e709c53f700a18a660feebdf72c613a233bf48.tar.gz
busybox-w32-13e709c53f700a18a660feebdf72c613a233bf48.tar.bz2
busybox-w32-13e709c53f700a18a660feebdf72c613a233bf48.zip
losetup: implement -r option. Closes 4033.
function old new delta packed_usage 28595 28633 +38 losetup_main 285 290 +5 singlemount 906 908 +2 set_loop 674 672 -2 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'util-linux')
-rw-r--r--util-linux/losetup.c16
-rw-r--r--util-linux/mount.c2
2 files changed, 10 insertions, 8 deletions
diff --git a/util-linux/losetup.c b/util-linux/losetup.c
index 9b7c49f50..21108d0bf 100644
--- a/util-linux/losetup.c
+++ b/util-linux/losetup.c
@@ -8,11 +8,12 @@
8 */ 8 */
9 9
10//usage:#define losetup_trivial_usage 10//usage:#define losetup_trivial_usage
11//usage: "[-o OFS] LOOPDEV FILE - associate loop devices\n" 11//usage: "[-r] [-o OFS] LOOPDEV FILE - associate loop devices\n"
12//usage: " losetup -d LOOPDEV - disassociate\n" 12//usage: " losetup -d LOOPDEV - disassociate\n"
13//usage: " losetup [-f] - show" 13//usage: " losetup [-f] - show"
14//usage:#define losetup_full_usage "\n\n" 14//usage:#define losetup_full_usage "\n\n"
15//usage: " -o OFS Start OFS bytes into FILE" 15//usage: " -o OFS Start OFS bytes into FILE"
16//usage: "\n -r Read-only"
16//usage: "\n -f Show first free loop device" 17//usage: "\n -f Show first free loop device"
17//usage: 18//usage:
18//usage:#define losetup_notes_usage 19//usage:#define losetup_notes_usage
@@ -37,11 +38,12 @@ int losetup_main(int argc UNUSED_PARAM, char **argv)
37 OPT_d = (1 << 0), 38 OPT_d = (1 << 0),
38 OPT_o = (1 << 1), 39 OPT_o = (1 << 1),
39 OPT_f = (1 << 2), 40 OPT_f = (1 << 2),
41 OPT_r = (1 << 3), /* must be last */
40 }; 42 };
41 43
42 /* max 2 args, all opts are mutually exclusive */ 44 /* max 2 args, -d,-o,-f opts are mutually exclusive */
43 opt_complementary = "?2:d--of:o--df:f--do"; 45 opt_complementary = "?2:d--of:o--df:f--do";
44 opt = getopt32(argv, "do:f", &opt_o); 46 opt = getopt32(argv, "do:fr", &opt_o);
45 argv += optind; 47 argv += optind;
46 48
47 if (opt == OPT_o) 49 if (opt == OPT_o)
@@ -63,12 +65,12 @@ int losetup_main(int argc UNUSED_PARAM, char **argv)
63 bb_show_usage(); 65 bb_show_usage();
64 66
65 if (argv[1]) { 67 if (argv[1]) {
66 /* [-o OFS] BLOCKDEV FILE */ 68 /* [-r] [-o OFS] BLOCKDEV FILE */
67 if (set_loop(&argv[0], argv[1], offset) < 0) 69 if (set_loop(&argv[0], argv[1], offset, (opt / OPT_r)) < 0)
68 bb_simple_perror_msg_and_die(argv[0]); 70 bb_simple_perror_msg_and_die(argv[0]);
69 return EXIT_SUCCESS; 71 return EXIT_SUCCESS;
70 } 72 }
71 /* [-o OFS] BLOCKDEV */ 73 /* [-r] [-o OFS] BLOCKDEV */
72 s = query_loop(argv[0]); 74 s = query_loop(argv[0]);
73 if (!s) 75 if (!s)
74 bb_simple_perror_msg_and_die(argv[0]); 76 bb_simple_perror_msg_and_die(argv[0]);
@@ -78,7 +80,7 @@ int losetup_main(int argc UNUSED_PARAM, char **argv)
78 return EXIT_SUCCESS; 80 return EXIT_SUCCESS;
79 } 81 }
80 82
81 /* [-o OFS|-f] with no params */ 83 /* [-r] [-o OFS|-f] with no params */
82 n = 0; 84 n = 0;
83 while (1) { 85 while (1) {
84 char *s; 86 char *s;
diff --git a/util-linux/mount.c b/util-linux/mount.c
index 05e532cda..b51ab1782 100644
--- a/util-linux/mount.c
+++ b/util-linux/mount.c
@@ -1809,7 +1809,7 @@ static int singlemount(struct mntent *mp, int ignore_busy)
1809 if (ENABLE_FEATURE_MOUNT_LOOP && S_ISREG(st.st_mode)) { 1809 if (ENABLE_FEATURE_MOUNT_LOOP && S_ISREG(st.st_mode)) {
1810 loopFile = bb_simplify_path(mp->mnt_fsname); 1810 loopFile = bb_simplify_path(mp->mnt_fsname);
1811 mp->mnt_fsname = NULL; // will receive malloced loop dev name 1811 mp->mnt_fsname = NULL; // will receive malloced loop dev name
1812 if (set_loop(&mp->mnt_fsname, loopFile, 0) < 0) { 1812 if (set_loop(&mp->mnt_fsname, loopFile, 0, /*ro:*/ 0) < 0) {
1813 if (errno == EPERM || errno == EACCES) 1813 if (errno == EPERM || errno == EACCES)
1814 bb_error_msg(bb_msg_perm_denied_are_you_root); 1814 bb_error_msg(bb_msg_perm_denied_are_you_root);
1815 else 1815 else