7 * Given a block device, find the mount table entry if that block device
10 * Given any other file (or directory), find the mount table entry for its
13 extern struct mntent *
14 findMountPoint(const char * name, const char * table)
19 struct mntent * mountEntry;
21 if ( stat(name, &s) != 0 )
24 if ( (s.st_mode & S_IFMT) == S_IFBLK )
25 mountDevice = s.st_rdev;
27 mountDevice = s.st_dev;
30 if ( (mountTable = setmntent(table, "r")) == 0 )
33 while ( (mountEntry = getmntent(mountTable)) != 0 ) {
34 if ( strcmp(name, mountEntry->mnt_dir) == 0
35 || strcmp(name, mountEntry->mnt_fsname) == 0 ) /* String match. */
37 if ( stat(mountEntry->mnt_fsname, &s) == 0
38 && s.st_rdev == mountDevice ) /* Match the device. */
40 if ( stat(mountEntry->mnt_dir, &s) == 0
41 && s.st_dev == mountDevice ) /* Match the directory's mount point. */
44 endmntent(mountTable);