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.
17 * Given a block device, find the mount table entry if that block device
20 * Given any other file (or directory), find the mount table entry for its
23 struct mntent *find_mount_point(const char *name, const char *table)
28 struct mntent *mountEntry;
30 if (stat(name, &s) != 0)
33 if ((s.st_mode & S_IFMT) == S_IFBLK)
34 mountDevice = s.st_rdev;
36 mountDevice = s.st_dev;
39 if ((mountTable = setmntent(table ? table : bb_path_mtab_file, "r")) == 0)
42 while ((mountEntry = getmntent(mountTable)) != 0) {
44 if(strcmp(name, mountEntry->mnt_dir) == 0
45 || strcmp(name, mountEntry->mnt_fsname) == 0) /* String match. */
47 if (stat(mountEntry->mnt_fsname, &s) == 0 && s.st_rdev == mountDevice) /* Match the device. */
49 if (stat(mountEntry->mnt_dir, &s) == 0 && s.st_dev == mountDevice) /* Match the directory's mount point. */
52 endmntent(mountTable);