]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
xfsprogs: libxcmd: kill "search" arg in fs_device_number()
authorAlex Elder <aelder@sgi.com>
Wed, 28 Sep 2011 10:57:10 +0000 (10:57 +0000)
committerAlex Elder <aelder@sgi.com>
Thu, 29 Sep 2011 14:30:47 +0000 (09:30 -0500)
The function fs_device_number() in libxcmd allows the caller to
optionally "search" in /dev for a given device path in order to look
up the dev_t that represents that device path.

If set, all that function does is prepend "/dev/" to the path to see
if that produces a device path that works.  So it appears this might
have been to support providing just the basename of a device as a
shorthand for its full path.

In practice, the paths passed to this function with "search" set are
those used in the mount options for a mounted XFS filesystem for the
optional log and real-time device paths.  When such paths are used
in the XFS mount path, they will have been subject to a AT_FDCWD
path lookup, so unless the process mounting the filesystem was
sitting in /dev no relative path would ever be specified as just the
basename.

Even though the "mounting with CWD=/dev" is a conceivable scenario,
I think it is not likely enough to warrant the special handling to
cover that case in fs_device_number().

So delete the code that retries with a "/dev" prepended, eliminate
the "search" argument that enables it, and fix the callers
accordingly.

Signed-off-by: Alex Elder <aelder@sgi.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
libxcmd/paths.c

index 5aa343be4f4bc7dda21c92fe4f38759be60570c7..f1cd6c7e0250c4c895637cd8cbbfe7c48d575be9 100644 (file)
@@ -76,33 +76,14 @@ fs_table_lookup(
 static char *
 fs_device_number(
        char            *name,
-       dev_t           *devnum,
-       int             search)
+       dev_t           *devnum)
 {
        struct stat64   sbuf;
-       int             len;
-
-       if (stat64(name, &sbuf) < 0) {
-               if (!search)
-                       return NULL;
-               len = strlen(name) + 1;
-               name = realloc(name, len + 5);  /* "/dev/ */
-               if (!name) {
-                       fprintf(stderr, _("%s: warning - out of memory\n"),
-                               progname);
-                       return NULL;
-               }
-               memmove(name + 5, name, len);
-               strncpy(name, "/dev/", 5);
-               if (stat64(name, &sbuf) < 0) {
-                       fprintf(stderr,
-                               _("%s: warning - cannot find %s: %s\n"),
-                               progname, name, strerror(errno));
-                       free(name);
-                       return NULL;
-               }
-       }
+
+       if (stat64(name, &sbuf) < 0)
+               return NULL;
        *devnum = sbuf.st_dev;
+
        return name;
 }
 
@@ -122,11 +103,11 @@ fs_table_insert(
                return EINVAL;
 
        datadev = logdev = rtdev = 0;
-       if (!fs_device_number(dir, &datadev, 0))
+       if (!fs_device_number(dir, &datadev))
                return errno;
-       if (fslog && (fslog = fs_device_number(fslog, &logdev, 1)) == NULL)
+       if (fslog && !fs_device_number(fslog, &logdev))
                return errno;
-       if (fsrt && (fsrt = fs_device_number(fsrt, &rtdev, 1)) == NULL)
+       if (fsrt && !fs_device_number(fsrt, &rtdev))
                return errno;
 
        tmp_fs_table = realloc(fs_table, sizeof(fs_path_t) * (fs_count + 1));