aboutsummaryrefslogtreecommitdiff
path: root/libbb/find_mount_point.c
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2009-07-18 16:22:26 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2009-07-18 16:22:26 +0200
commit6ae6426a7485b5835c23aea198b3065f491d918b (patch)
tree79ebcee570986e27d7137720ca3139af277a162b /libbb/find_mount_point.c
parentb71ce023e9527b6afaa497ce62ca53a74cf94cef (diff)
downloadbusybox-w32-6ae6426a7485b5835c23aea198b3065f491d918b.tar.gz
busybox-w32-6ae6426a7485b5835c23aea198b3065f491d918b.tar.bz2
busybox-w32-6ae6426a7485b5835c23aea198b3065f491d918b.zip
fix mountpoint test to not prevemt mkfs_xxx from making image in any file
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'libbb/find_mount_point.c')
-rw-r--r--libbb/find_mount_point.c39
1 files changed, 23 insertions, 16 deletions
diff --git a/libbb/find_mount_point.c b/libbb/find_mount_point.c
index 12b2cfce4..bcb18effe 100644
--- a/libbb/find_mount_point.c
+++ b/libbb/find_mount_point.c
@@ -17,27 +17,29 @@
17 * Given any other file (or directory), find the mount table entry for its 17 * Given any other file (or directory), find the mount table entry for its
18 * filesystem. 18 * filesystem.
19 */ 19 */
20struct mntent* FAST_FUNC find_mount_point(const char *name) 20struct mntent* FAST_FUNC find_mount_point(const char *name, int subdir_too)
21{ 21{
22 struct stat s; 22 struct stat s;
23 dev_t mountDevice; 23 FILE *mtab_fp;
24 FILE *mountTable;
25 struct mntent *mountEntry; 24 struct mntent *mountEntry;
25 dev_t devno_of_name;
26 bool block_dev;
26 27
27 if (stat(name, &s) != 0) 28 if (stat(name, &s) != 0)
28 return NULL; 29 return NULL;
29 30
30 if (S_ISBLK(s.st_mode)) 31 devno_of_name = s.st_dev;
31 mountDevice = s.st_rdev; 32 block_dev = 0;
32 else 33 if (S_ISBLK(s.st_mode)) {
33 mountDevice = s.st_dev; 34 devno_of_name = s.st_rdev;
34 35 block_dev = 1;
36 }
35 37
36 mountTable = setmntent(bb_path_mtab_file, "r"); 38 mtab_fp = setmntent(bb_path_mtab_file, "r");
37 if (!mountTable) 39 if (!mtab_fp)
38 return 0; 40 return NULL;
39 41
40 while ((mountEntry = getmntent(mountTable)) != NULL) { 42 while ((mountEntry = getmntent(mtab_fp)) != NULL) {
41 /* rootfs mount in Linux 2.6 exists always, 43 /* rootfs mount in Linux 2.6 exists always,
42 * and it makes sense to always ignore it. 44 * and it makes sense to always ignore it.
43 * Otherwise people can't reference their "real" root! */ 45 * Otherwise people can't reference their "real" root! */
@@ -49,13 +51,18 @@ struct mntent* FAST_FUNC find_mount_point(const char *name)
49 ) { /* String match. */ 51 ) { /* String match. */
50 break; 52 break;
51 } 53 }
52 /* Match the device. */ 54
53 if (stat(mountEntry->mnt_fsname, &s) == 0 && s.st_rdev == mountDevice) 55 if (!(subdir_too || block_dev))
56 continue;
57
58 /* Is device's dev_t == name's dev_t? */
59 if (stat(mountEntry->mnt_fsname, &s) == 0 && s.st_rdev == devno_of_name)
54 break; 60 break;
55 /* Match the directory's mount point. */ 61 /* Match the directory's mount point. */
56 if (stat(mountEntry->mnt_dir, &s) == 0 && s.st_dev == mountDevice) 62 if (stat(mountEntry->mnt_dir, &s) == 0 && s.st_dev == devno_of_name)
57 break; 63 break;
58 } 64 }
59 endmntent(mountTable); 65 endmntent(mtab_fp);
66
60 return mountEntry; 67 return mountEntry;
61} 68}