diff options
| author | Ken Sumrall <ksumrall@android.com> | 2011-07-12 19:47:06 -0700 |
|---|---|---|
| committer | Ken Sumrall <ksumrall@android.com> | 2011-07-13 14:37:41 -0700 |
| commit | 940c81078e7291096b22f05f6b953658f1e1d730 (patch) | |
| tree | 6982ffefd0d599cce5b9f9fbcf5fd4d4f5367836 /toolbox/umount.c | |
| parent | ed6b39cc7746fabdd0d01c96afcf60b9544913d3 (diff) | |
| download | system_core-940c81078e7291096b22f05f6b953658f1e1d730.tar.gz system_core-940c81078e7291096b22f05f6b953658f1e1d730.tar.bz2 system_core-940c81078e7291096b22f05f6b953658f1e1d730.zip | |
Add -o loop= option to mount, and fix error detection in mount and umount
This fixes bug http://b.android.com/18419, which complains about a bogus
error check in the mount command (it also was wrong in the umount command)
and also asks for the mount command to support more than one loopback
device, as mentioned in the FIXME comments in mount.c. This required some
corresponding changes to umount.c
Change-Id: Ib796c70926395e61557e487bad64984d3295d5f3
Diffstat (limited to 'toolbox/umount.c')
| -rw-r--r-- | toolbox/umount.c | 32 |
1 files changed, 24 insertions, 8 deletions
diff --git a/toolbox/umount.c b/toolbox/umount.c index 92c60760..6eb8b925 100644 --- a/toolbox/umount.c +++ b/toolbox/umount.c @@ -7,10 +7,24 @@ #include <unistd.h> #include <linux/loop.h> -// FIXME - only one loop mount is supported at a time -#define LOOP_DEVICE "/dev/block/loop0" +#define LOOPDEV_MAXLEN 64 +#define LOOP_MAJOR 7 -static int is_loop_mount(const char* path) +static int is_loop(char *dev) +{ + struct stat st; + int ret = 0; + + if (stat(dev, &st) == 0) { + if (S_ISBLK(st.st_mode) && (major(st.st_rdev) == LOOP_MAJOR)) { + ret = 1; + } + } + + return ret; +} + +static int is_loop_mount(const char* path, char *loopdev) { FILE* f; int count; @@ -29,7 +43,8 @@ static int is_loop_mount(const char* path) do { count = fscanf(f, "%255s %255s %255s\n", device, mount_path, rest); if (count == 3) { - if (strcmp(LOOP_DEVICE, device) == 0 && strcmp(path, mount_path) == 0) { + if (is_loop(device) && strcmp(path, mount_path) == 0) { + strlcpy(loopdev, device, LOOPDEV_MAXLEN); result = 1; break; } @@ -43,13 +58,14 @@ static int is_loop_mount(const char* path) int umount_main(int argc, char *argv[]) { int loop, loop_fd; - + char loopdev[LOOPDEV_MAXLEN]; + if(argc != 2) { fprintf(stderr,"umount <path>\n"); return 1; } - loop = is_loop_mount(argv[1]); + loop = is_loop_mount(argv[1], loopdev); if(umount(argv[1])){ fprintf(stderr,"failed.\n"); return 1; @@ -57,8 +73,8 @@ int umount_main(int argc, char *argv[]) if (loop) { // free the loop device - loop_fd = open(LOOP_DEVICE, O_RDONLY); - if (loop_fd < -1) { + loop_fd = open(loopdev, O_RDONLY); + if (loop_fd < 0) { perror("open loop device failed"); return 1; } |
