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 tarball for details.
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)
25 struct mntent *mountEntry;
27 if (stat(name, &s) != 0)
30 if (S_ISBLK(s.st_mode))
31 mountDevice = s.st_rdev;
33 mountDevice = s.st_dev;
36 mountTable = setmntent(bb_path_mtab_file, "r");
40 while ((mountEntry = getmntent(mountTable)) != NULL) {
41 /* rootfs mount in Linux 2.6 exists always,
42 * and it makes sense to always ignore it.
43 * Otherwise people can't reference their "real" root! */
44 if (strcmp(mountEntry->mnt_fsname, "rootfs") == 0)
47 if (strcmp(name, mountEntry->mnt_dir) == 0
48 || strcmp(name, mountEntry->mnt_fsname) == 0
49 ) { /* String match. */
52 /* Match the device. */
53 if (stat(mountEntry->mnt_fsname, &s) == 0 && s.st_rdev == mountDevice)
55 /* Match the directory's mount point. */
56 if (stat(mountEntry->mnt_dir, &s) == 0 && s.st_dev == mountDevice)
59 endmntent(mountTable);