]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blobdiff - libfrog/paths.c
xfsprogs: remove write-only variables
[thirdparty/xfsprogs-dev.git] / libfrog / paths.c
index 62b4eda6a0cc41e18d9618f8606e9f6e35d62b49..6e266654bdc3a3c6979a729b0388d88ba6fbaadb 100644 (file)
@@ -1,19 +1,7 @@
+// 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>
@@ -89,34 +77,62 @@ fs_table_lookup(
        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,
@@ -399,61 +415,6 @@ fs_table_initialise_mounts(
        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