1 /* vi: set sw=4 ts=4: */
5 * Copyright (C) 1999-2003 by Erik Andersen <andersen@codepoet.org>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
29 * Given a block device, find the mount table entry if that block device
32 * Given any other file (or directory), find the mount table entry for its
35 extern struct mntent *find_mount_point(const char *name, const char *table)
40 struct mntent *mountEntry;
42 if (stat(name, &s) != 0)
45 if ((s.st_mode & S_IFMT) == S_IFBLK)
46 mountDevice = s.st_rdev;
48 mountDevice = s.st_dev;
51 if ((mountTable = setmntent(table, "r")) == 0)
54 while ((mountEntry = getmntent(mountTable)) != 0) {
55 if (strcmp(name, mountEntry->mnt_dir) == 0
56 || strcmp(name, mountEntry->mnt_fsname) == 0) /* String match. */
58 if (stat(mountEntry->mnt_fsname, &s) == 0 && s.st_rdev == mountDevice) /* Match the device. */
60 if (stat(mountEntry->mnt_dir, &s) == 0 && s.st_dev == mountDevice) /* Match the directory's mount point. */
63 endmntent(mountTable);