+// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (c) 2005-2006 Silicon Graphics, Inc.
* All Rights Reserved.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it would be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <paths.h>
return NULL;
}
-/*
- * Find the FS table entry describing an actual mount for the given path.
- * Unlike fs_table_lookup(), fs_table_lookup_mount() compares the "dir"
- * argument to actual mount point entries in the table. Accordingly, it
- * will find matches only if the "dir" argument is indeed mounted.
- */
-struct fs_path *
-fs_table_lookup_mount(
- const char *dir)
+static struct fs_path *
+__fs_table_lookup_mount(
+ const char *dir,
+ const char *blkdev)
{
uint i;
- dev_t dev = 0;
char rpath[PATH_MAX];
+ char dpath[PATH_MAX];
- if (fs_device_number(dir, &dev))
+ if (!dir && !blkdev)
+ return NULL;
+
+ if (dir && !realpath(dir, dpath))
+ return NULL;
+ if (blkdev && !realpath(blkdev, dpath))
return NULL;
for (i = 0; i < fs_count; i++) {
if (fs_table[i].fs_flags != FS_MOUNT_POINT)
continue;
- if (!realpath(fs_table[i].fs_dir, rpath))
+ if (dir && !realpath(fs_table[i].fs_dir, rpath))
continue;
- if (strcmp(rpath, dir) == 0)
+ if (blkdev && !realpath(fs_table[i].fs_name, rpath))
+ continue;
+ if (strcmp(rpath, dpath) == 0)
return &fs_table[i];
}
return NULL;
}
+/*
+ * Find the FS table entry describing an actual mount for the given path.
+ * Unlike fs_table_lookup(), fs_table_lookup_mount() compares the "dir"
+ * argument to actual mount point entries in the table. Accordingly, it
+ * will find matches only if the "dir" argument is indeed mounted.
+ */
+struct fs_path *
+fs_table_lookup_mount(
+ const char *dir)
+{
+ return __fs_table_lookup_mount(dir, NULL);
+}
+
+/*
+ * Find the FS table entry describing an actual mount for the block device.
+ * Unlike fs_table_lookup(), fs_table_lookup_blkdev() compares the "bdev"
+ * argument to actual mount point names in the table. Accordingly, it
+ * will find matches only if the "bdev" argument is indeed mounted.
+ */
+struct fs_path *
+fs_table_lookup_blkdev(
+ const char *bdev)
+{
+ return __fs_table_lookup_mount(NULL, bdev);
+}
+
static int
fs_table_insert(
char *dir,
return error;
}
+/* Remove all the cached entries in the fs table. */
+void
+fs_table_destroy(void)
+{
+ int i;
+ struct fs_path *fsp;
+
+ for (i = 0, fsp = fs_table; i < fs_count; i++, fsp++) {
+ free(fsp->fs_name);
+ free(fsp->fs_dir);
+ free(fsp->fs_log);
+ free(fsp->fs_rt);
+ }
+
+ fs_count = 0;
+ xfs_fs_count = 0;
+ free(fs_table);
+ fs_table = NULL;
+}
+
/*
* Table iteration (cursor-based) interfaces
*/
return error;
}
-#elif defined(HAVE_GETMNTINFO)
-#include <sys/mount.h>
-
-/*
- * If *path is NULL, initialize the fs table with all xfs mount points in mtab
- * If *path is specified, search for that path in mtab
- *
- * Everything - path, devices, and mountpoints - are boiled down to realpath()
- * for comparison, but fs_table is populated with what comes from getmntinfo.
- */
-static int
-fs_table_initialise_mounts(
- char *path)
-{
- struct statfs *stats;
- int i, count, error, found;
- char rpath[PATH_MAX], rmntfromname[PATH_MAX], rmntonname[PATH_MAX];
-
- error = found = 0;
- if ((count = getmntinfo(&stats, 0)) < 0) {
- fprintf(stderr, _("%s: getmntinfo() failed: %s\n"),
- progname, strerror(errno));
- return 0;
- }
-
- /* Use realpath to resolve symlinks, relative paths, etc */
- if (path)
- if (!realpath(path, rpath))
- return errno;
-
- for (i = 0; i < count; i++) {
- if (!realpath(stats[i].f_mntfromname, rmntfromname))
- continue;
- if (!realpath(stats[i].f_mntonname, rmntonname))
- continue;
-
- if (path &&
- ((strcmp(rpath, rmntonname) != 0) &&
- (strcmp(rpath, rmntfromname) != 0)))
- continue;
- /* TODO: external log and realtime device? */
- (void) fs_table_insert(stats[i].f_mntonname, 0,
- FS_MOUNT_POINT, stats[i].f_mntfromname,
- NULL, NULL);
- if (path) {
- found = 1;
- break;
- }
- }
- if (path && !found)
- error = ENXIO;
-
- return error;
-}
-
#else
# error "How do I extract info about mounted filesystems on this platform?"
#endif