1 /* vi: set sw=4 ts=4: */
5 * Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
7 * Licensed under GPLv2 or later, see file LICENSE in this source tree.
14 * Given a block device, find the mount table entry if that block device
17 * Given any other file (or directory), find the mount table entry for its
20 struct mntent
* FAST_FUNC
find_mount_point(const char *name
, int subdir_too
)
24 struct mntent
*mountEntry
;
28 if (stat(name
, &s
) != 0)
31 devno_of_name
= s
.st_dev
;
33 /* Why S_ISCHR? - UBI volumes use char devices, not block */
34 if (S_ISBLK(s
.st_mode
) || S_ISCHR(s
.st_mode
)) {
35 devno_of_name
= s
.st_rdev
;
39 mtab_fp
= setmntent(bb_path_mtab_file
, "r");
43 while ((mountEntry
= getmntent(mtab_fp
)) != NULL
) {
44 /* rootfs mount in Linux 2.6 exists always,
45 * and it makes sense to always ignore it.
46 * Otherwise people can't reference their "real" root! */
47 if (ENABLE_FEATURE_SKIP_ROOTFS
&& strcmp(mountEntry
->mnt_fsname
, "rootfs") == 0)
50 if (strcmp(name
, mountEntry
->mnt_dir
) == 0
51 || strcmp(name
, mountEntry
->mnt_fsname
) == 0
52 ) { /* String match. */
56 if (!(subdir_too
|| block_dev
))
59 /* Is device's dev_t == name's dev_t? */
60 if (stat(mountEntry
->mnt_fsname
, &s
) == 0 && s
.st_rdev
== devno_of_name
)
62 /* Match the directory's mount point. */
63 if (stat(mountEntry
->mnt_dir
, &s
) == 0 && s
.st_dev
== devno_of_name
)