]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blobdiff - fsr/xfs_fsr.c
xfs_repair: clear extent size hints when clearing inode core
[thirdparty/xfsprogs-dev.git] / fsr / xfs_fsr.c
index 517b75f0dffd68e769f3da76aa287d6939287439..b74a70b59df6dec5e97576fa53b8d77ee3207d44 100644 (file)
@@ -22,6 +22,7 @@
 #include "jdm.h"
 #include "xfs_bmap_btree.h"
 #include "xfs_attr_sf.h"
+#include "path.h"
 
 #include <fcntl.h>
 #include <errno.h>
@@ -54,7 +55,7 @@ struct getbmap  *outmap = NULL;
 int             outmap_size = 0;
 int            RealUid;
 int            tmp_agi;
-static __int64_t       minimumfree = 2048;
+static int64_t         minimumfree = 2048;
 
 #define MNTTYPE_XFS             "xfs"
 
@@ -167,73 +168,13 @@ aborter(int unused)
        exit(1);
 }
 
-/*
- * Check if the argument is either the device name or mountpoint of an XFS
- * filesystem.  Note that we do not care about bind mounted regular files
- * here - the code that handles defragmentation of invidual files takes care
- * of that.
- */
-static char *
-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 NULL;
-               if (sb->st_ino != ms.st_ino)
-                       return NULL;
-               if (sb->st_dev != ms.st_dev)
-                       return NULL;
-               if (strcmp(t->mnt_type, MNTTYPE_XFS) != 0)
-                       return NULL;
-       } else {                                /* device */
-               if (stat(t->mnt_fsname, &ms) < 0)
-                       return NULL;
-               if (sb->st_rdev != ms.st_rdev)
-                       return NULL;
-               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 NULL;
-       }
-
-       return t->mnt_dir;
-}
-
-static char *
-find_mountpoint(char *mtab, char *argname, struct stat *sb)
-{
-       struct mntent_cursor cursor;
-       struct mntent *t = NULL;
-       char *mntp = NULL;
-
-       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) {
-               mntp = find_mountpoint_check(sb, t);
-               if (mntp == NULL)
-                       continue;
-               break;
-       }
-       platform_mntent_close(&cursor);
-       return mntp;
-}
-
 int
 main(int argc, char **argv)
 {
        struct stat sb;
        char *argname;
        int c;
-       char *mntp;
+       struct fs_path  *fsp;
        char *mtab = NULL;
 
        setlinebuf(stdout);
@@ -322,7 +263,7 @@ main(int argc, char **argv)
        RealUid = getuid();
 
        pagesize = getpagesize();
-
+       fs_table_initialise(0, NULL, 0, NULL);
        if (optind < argc) {
                for (; optind < argc; optind++) {
                        argname = argv[optind];
@@ -343,9 +284,11 @@ main(int argc, char **argv)
                                sb = sb2;
                        }
 
-                       mntp = find_mountpoint(mtab, argname, &sb);
-                       if (mntp != NULL) {
-                               fsrfs(mntp, 0, 100);
+                       fsp = fs_table_lookup_mount(argname);
+                       if (!fsp)
+                               fsp = fs_table_lookup_blkdev(argname);
+                       if (fsp != NULL) {
+                               fsrfs(fsp->fs_dir, 0, 100);
                        } else if (S_ISCHR(sb.st_mode)) {
                                fprintf(stderr, _(
                                        "%s: char special not supported: %s\n"),
@@ -600,12 +543,7 @@ fsrallfs(char *mtab, int howlong, char *leftofffile)
        /* reorg for 'howlong' -- checked in 'fsrfs' */
        while (endtime > time(0)) {
                pid_t pid;
-               if (fs == fsend)
-                       fs = fsbase;
-               if (fs->npass == npasses) {
-                       fsrprintf(_("Completed all %d passes\n"), npasses);
-                       break;
-               }
+
                if (npasses > 1 && !fs->npass)
                        Mflag = 1;
                else
@@ -631,6 +569,12 @@ fsrallfs(char *mtab, int howlong, char *leftofffile)
                startino = 0;  /* reset after the first time through */
                fs->npass++;
                fs++;
+               if (fs == fsend)
+                       fs = fsbase;
+               if (fs->npass == npasses) {
+                       fsrprintf(_("Completed all %d passes\n"), npasses);
+                       break;
+               }
        }
        fsrall_cleanup(endtime <= time(0));
 }