]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
xfs_quota: support relative path as `path' arguments
authorSatoru Takeuchi <takeuchi_satoru@jp.fujitsu.com>
Tue, 27 Nov 2012 10:05:40 +0000 (10:05 +0000)
committerMark Tinguely <tinguely@eagdhcp-232-125.americas.sgi.com>
Fri, 21 Dec 2012 14:48:31 +0000 (08:48 -0600)
Current xfs_quota only accepts absolute path as its `path' arguments.
This patch adds the support of relative path for user's convenience.

Signed-off-by: Satoru Takeuchi <takeuchi_satoru@jp.fujitsu.com>
Reviewed-by: Carlos Maiolino <cmaiolino@redhat.com>
Tested-by: Carlos Maiolino <cmaiolino@redhat.com>
libxcmd/paths.c

index 2a922990a949a84d655d5d59861992ac8b9a3d30..bd84cde97f0a19e22abbb5a5c700fd61f225c855 100644 (file)
@@ -27,6 +27,7 @@
 #include <xfs/path.h>
 #include <xfs/input.h>
 #include <xfs/project.h>
+#include <limits.h>
 
 extern char *progname;
 
@@ -273,6 +274,7 @@ fs_table_initialise_mounts(
        FILE            *mtp;
        char            *fslog, *fsrt;
        int             error, found;
+       char            *rpath = NULL;
 
        error = found = 0;
        fslog = fsrt = NULL;
@@ -286,26 +288,32 @@ fs_table_initialise_mounts(
        if ((mtp = setmntent(mtab_file, "r")) == NULL)
                return ENOENT;
 
+       if (path)
+               if ((rpath = realpath(path, NULL)) == NULL)
+                       return ENOENT;
+
        while ((mnt = getmntent(mtp)) != NULL) {
                if (strcmp(mnt->mnt_type, "xfs") != 0)
                        continue;
-               if (path &&
-                   ((strcmp(path, mnt->mnt_dir) != 0) &&
-                    (strcmp(path, mnt->mnt_fsname) != 0)))
+               if (rpath &&
+                   ((strcmp(rpath, mnt->mnt_dir) != 0) &&
+                    (strcmp(rpath, mnt->mnt_fsname) != 0)))
                        continue;
                if (fs_extract_mount_options(mnt, &fslog, &fsrt))
                        continue;
                (void) fs_table_insert(mnt->mnt_dir, 0, FS_MOUNT_POINT,
                                        mnt->mnt_fsname, fslog, fsrt);
-               if (path) {
+               if (rpath) {
                        found = 1;
                        break;
                }
        }
        endmntent(mtp);
-       if (path && !found)
-               error = ENXIO;
-
+       if (rpath) {
+               free(rpath);
+               if (!found)
+                       error = ENXIO;
+       }
        return error;
 }
 
@@ -318,6 +326,7 @@ fs_table_initialise_mounts(
 {
        struct statfs   *stats;
        int             i, count, error, found;
+       char            *rpath = NULL;
 
        error = found = 0;
        if ((count = getmntinfo(&stats, 0)) < 0) {
@@ -326,24 +335,31 @@ fs_table_initialise_mounts(
                return 0;
        }
 
+       if (path)
+               if ((rpath = realpath(path, NULL)) == NULL)
+                       return ENOENT;
+
        for (i = 0; i < count; i++) {
                if (strcmp(stats[i].f_fstypename, "xfs") != 0)
                        continue;
-               if (path &&
-                   ((strcmp(path, stats[i].f_mntonname) != 0) &&
-                    (strcmp(path, stats[i].f_mntfromname) != 0)))
+               if (rpath &&
+                   ((strcmp(rpath, stats[i].f_mntonname) != 0) &&
+                    (strcmp(rpath, stats[i].f_mntfromname) != 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) {
+               if (rpath) {
                        found = 1;
                        break;
                }
        }
-       if (path && !found)
-               error = ENXIO;
+       if (rpath) {
+               free(rpath);
+               if (!found)
+                       error = ENXIO;
+       }
 
        return error;
 }