]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blobdiff - scrub/common.c
xfsprogs: convert to SPDX license tags
[thirdparty/xfsprogs-dev.git] / scrub / common.c
index 5a37a984b2ad71d5f6d86a4d0a55fd045d53f83b..96b86a26e75282966cb6c7db73e4d607deffa294 100644 (file)
@@ -1,21 +1,7 @@
+// SPDX-License-Identifier: GPL-2.0+
 /*
  * Copyright (C) 2018 Oracle.  All Rights Reserved.
- *
  * Author: Darrick J. Wong <darrick.wong@oracle.com>
- *
- * 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; either version 2
- * of the License, or (at your option) any later version.
- *
- * 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 "xfs.h"
 #include <pthread.h>
@@ -56,18 +42,15 @@ xfs_scrub_excessive_errors(
        return ret;
 }
 
-static const char *err_str[] = {
-       [S_ERROR]       = "Error",
-       [S_WARN]        = "Warning",
-       [S_REPAIR]      = "Repaired",
-       [S_INFO]        = "Info",
-       [S_PREEN]       = "Optimized",
-};
-
-static int log_level[] = {
-       [S_ERROR]       = LOG_ERR,
-       [S_WARN]        = LOG_WARNING,
-       [S_INFO]        = LOG_INFO,
+static struct {
+       const char *string;
+       int loglevel;
+} err_levels[] = {
+       [S_ERROR]  = { .string = "Error",       .loglevel = LOG_ERR },
+       [S_WARN]   = { .string = "Warning",     .loglevel = LOG_WARNING },
+       [S_REPAIR] = { .string = "Repaired",    .loglevel = LOG_WARNING },
+       [S_INFO]   = { .string = "Info",        .loglevel = LOG_INFO },
+       [S_PREEN]  = { .string = "Optimized",   .loglevel = LOG_INFO }
 };
 
 /* If stream is a tty, clear to end of line to clean up progress bar. */
@@ -106,8 +89,8 @@ __str_out(
        if (level == S_PREEN && !debug && !verbose)
                goto out_record;
 
-       fprintf(stream, "%s%s: %s: ", stream_start(stream), _(err_str[level]),
-                       descr);
+       fprintf(stream, "%s%s: %s: ", stream_start(stream),
+                       _(err_levels[level].string), descr);
        if (error) {
                fprintf(stream, _("%s."), strerror_r(error, buf, DESCR_BUFSZ));
        } else {
@@ -168,11 +151,11 @@ __str_log(
        snprintf(logname, LOGNAME_BUFSZ, "%s@%s", progname, ctx->mntpoint);
        openlog(logname, LOG_PID, LOG_DAEMON);
 
-       sz = snprintf(buf, LOG_BUFSZ, "%s: ", _(err_str[level]));
+       sz = snprintf(buf, LOG_BUFSZ, "%s: ", _(err_levels[level].string));
        va_start(args, format);
        vsnprintf(buf + sz, LOG_BUFSZ - sz, format, args);
        va_end(args);
-       syslog(log_level[level], "%s", buf);
+       syslog(err_levels[level].loglevel, "%s", buf);
 
        closelog();
 }
@@ -266,75 +249,6 @@ scrub_nproc_workqueue(
        return x;
 }
 
-/*
- * Check if the argument is either the device name or mountpoint of a mounted
- * filesystem.
- */
-#define MNTTYPE_XFS    "xfs"
-static bool
-find_mountpoint_check(
-       struct stat             *sb,
-       struct mntent           *t)
-{
-       struct stat             ms;
-
-       if (S_ISDIR(sb->st_mode)) {             /* mount point */
-               if (stat(t->mnt_dir, &ms) < 0)
-                       return false;
-               if (sb->st_ino != ms.st_ino)
-                       return false;
-               if (sb->st_dev != ms.st_dev)
-                       return false;
-               if (strcmp(t->mnt_type, MNTTYPE_XFS) != 0)
-                       return NULL;
-       } else {                                /* device */
-               if (stat(t->mnt_fsname, &ms) < 0)
-                       return false;
-               if (sb->st_rdev != ms.st_rdev)
-                       return false;
-               if (strcmp(t->mnt_type, MNTTYPE_XFS) != 0)
-                       return NULL;
-               /*
-                * Make sure the mountpoint given by mtab is accessible
-                * before using it.
-                */
-               if (stat(t->mnt_dir, &ms) < 0)
-                       return false;
-       }
-
-       return true;
-}
-
-/* Check that our alleged mountpoint is in mtab */
-bool
-find_mountpoint(
-       char                    *mtab,
-       struct scrub_ctx        *ctx)
-{
-       struct mntent_cursor    cursor;
-       struct mntent           *t = NULL;
-       bool                    found = false;
-
-       if (platform_mntent_open(&cursor, mtab) != 0) {
-               fprintf(stderr, "Error: can't get mntent entries.\n");
-               exit(1);
-       }
-
-       while ((t = platform_mntent_next(&cursor)) != NULL) {
-               /*
-                * Keep jotting down matching mount details; newer mounts are
-                * towards the end of the file (hopefully).
-                */
-               if (find_mountpoint_check(&ctx->mnt_sb, t)) {
-                       ctx->mntpoint = strdup(t->mnt_dir);
-                       ctx->blkdev = strdup(t->mnt_fsname);
-                       found = true;
-               }
-       }
-       platform_mntent_close(&cursor);
-       return found;
-}
-
 /*
  * Sleep for 100ms * however many -b we got past the initial one.
  * This is an (albeit clumsy) way to throttle scrub activity.