]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
Allow repair to run on a read only filesystem.
authorRussell Cattelan <cattelan@sgi.com>
Thu, 1 May 2003 21:31:58 +0000 (21:31 +0000)
committerRussell Cattelan <cattelan@sgi.com>
Thu, 1 May 2003 21:31:58 +0000 (21:31 +0000)
Added LIBXFS_DANGEROUSLY flag

include/libxfs.h
libxfs/init.c
man/man8/xfs_repair.8
repair/globals.h
repair/init.c
repair/xfs_repair.c

index e6c45f427028a2eb86b3cefb70f60620def13c60..579cf1d9ab97926d6b7d71a212b15d3344d6517d 100644 (file)
@@ -110,6 +110,7 @@ typedef struct {
 #define LIBXFS_EXIT_ON_FAILURE 0x0001  /* exit the program if a call fails */
 #define LIBXFS_ISREADONLY      0x0002  /* disallow all mounted filesystems */
 #define LIBXFS_ISINACTIVE      0x0004  /* allow mounted only if mounted ro */
+#define LIBXFS_DANGEROUSLY     0x0008  /* repair is mounted ro */
 
 extern char    *progname;
 extern int     libxfs_init (libxfs_init_t *);
index 6176948f5ac0a5da30f256886c4074cd0f728024..e5ffd11a053711fc51aa5e4237d956818f951a50 100644 (file)
@@ -170,6 +170,40 @@ libxfs_device_close(dev_t dev)
        exit(1);
 }
 
+int
+check_open(char *path, int flags,char **rawfile,char **blockfile){
+
+       int readonly = (flags & LIBXFS_ISREADONLY);
+       int inactive = (flags & LIBXFS_ISINACTIVE);
+       int dangerously = (flags & LIBXFS_DANGEROUSLY);
+       struct stat64   stbuf;
+
+       if (stat64(path, &stbuf) < 0) {
+               perror(path);
+               return 0;
+       }
+       if (!(*rawfile = findrawpath(path))) {
+               fprintf(stderr, _("%s: "
+                                 "can't find a character device matching %s\n"),
+                       progname, path);
+               return 0;
+       }
+       if (!(*blockfile = findblockpath(path))) {
+               fprintf(stderr, _("%s: "
+                                 "can't find a block device matching %s\n"),
+                       progname, path);
+               return 0;
+       }
+       if (!readonly && !inactive && platform_check_ismounted(path, *blockfile, NULL, 1))
+               return 0;
+       
+       if (inactive && check_isactive(path, *blockfile, ((readonly|dangerously)?1:0)))
+               return 0;
+
+       return 1;
+}
+
+
 
 /*
  * libxfs initialization.
@@ -192,7 +226,7 @@ libxfs_init(libxfs_init_t *a)
        int             rval = 0;
        int             readonly;
        int             inactive;
-       struct stat64   stbuf;
+       int             flags;
 
        dpath[0] = logpath[0] = rtpath[0] = '\0';
        dname = a->dname;
@@ -207,28 +241,11 @@ libxfs_init(libxfs_init_t *a)
        fd = -1;
        readonly = (a->isreadonly & LIBXFS_ISREADONLY);
        inactive = (a->isreadonly & LIBXFS_ISINACTIVE);
+       flags = a->isreadonly;
+
        if (a->volname) {
-               if (stat64(a->volname, &stbuf) < 0) {
-                       perror(a->volname);
-                       goto done;
-               }
-               if (!(rawfile = findrawpath(a->volname))) {
-                       fprintf(stderr, _("%s: "
-                               "can't find a character device matching %s\n"),
-                               progname, a->volname);
-                       goto done;
-               }
-               if (!(blockfile = findblockpath(a->volname))) {
-                       fprintf(stderr, _("%s: "
-                               "can't find a block device matching %s\n"),
-                               progname, a->volname);
-                       goto done;
-               }
-               if (!readonly && !inactive &&
-                   platform_check_ismounted(a->volname, blockfile, NULL, 1))
-                       goto done;
-               if (inactive && check_isactive(
-                                       a->volname, blockfile, readonly))
+               
+               if(!check_open(a->volname,flags,&rawfile,&blockfile))
                        goto done;
                needcd = 1;
                fd = open(rawfile, O_RDONLY);
@@ -314,29 +331,7 @@ voldone:
                                                    a->setblksize);
                        a->dfd = libxfs_device_to_fd(a->ddev);
                } else {
-                       if (stat64(dname, &stbuf) < 0) {
-                               fprintf(stderr,
-                                       _("%s: stat64 failed on %s: %s\n"),
-                                       progname, dname, strerror(errno));
-                               goto done;
-                       }
-                       if (!(rawfile = findrawpath(dname))) {
-                               fprintf(stderr,
-                                       _("%s: can't find a char device "
-                                       "matching %s\n"), progname, dname);
-                               goto done;
-                       }
-                       if (!(blockfile = findblockpath(dname))) {
-                               fprintf(stderr,
-                                       _("%s: can't find a block device "
-                                       "matching %s\n"), progname, dname);
-                               goto done;
-                       }
-                       if (!readonly && !inactive &&
-                           platform_check_ismounted(dname, blockfile, NULL, 1))
-                               goto done;
-                       if (inactive && check_isactive(
-                                               dname, blockfile, readonly))
+                       if(!check_open(dname,flags,&rawfile,&blockfile))
                                goto done;
                        a->ddev = libxfs_device_open(rawfile,
                                        a->dcreat, readonly, a->setblksize);
@@ -354,29 +349,7 @@ voldone:
                                        a->lcreat, readonly, a->setblksize);
                        a->logfd = libxfs_device_to_fd(a->logdev);
                } else {
-                       if (stat64(logname, &stbuf) < 0) {
-                               fprintf(stderr,
-                                       _("%s: stat64 failed on %s: %s\n"),
-                                       progname, logname, strerror(errno));
-                               goto done;
-                       }
-                       if (!(rawfile = findrawpath(logname))) {
-                               fprintf(stderr,
-                                       _("%s: can't find a char device "
-                                       "matching %s\n"), progname, logname);
-                               goto done;
-                       }
-                       if (!(blockfile = findblockpath(logname))) {
-                               fprintf(stderr,
-                                       _("%s: can't find a block device "
-                                       "matching %s\n"), progname, logname);
-                               goto done;
-                       }
-                       if (!readonly && !inactive &&
-                           platform_check_ismounted(logname, blockfile, NULL, 1))
-                               goto done;
-                       else if (inactive && check_isactive(
-                                               logname, blockfile, readonly))
+                       if(!check_open(logname,flags,&rawfile,&blockfile))
                                goto done;
                        a->logdev = libxfs_device_open(rawfile,
                                        a->lcreat, readonly, a->setblksize);
@@ -394,29 +367,7 @@ voldone:
                                        a->rcreat, readonly, a->setblksize);
                        a->rtfd = libxfs_device_to_fd(a->rtdev);
                } else {
-                       if (stat64(rtname, &stbuf) < 0) {
-                               fprintf(stderr,
-                                       _("%s: stat64 failed on %s: %s\n"),
-                                       progname, rtname, strerror(errno));
-                               goto done;
-                       }
-                       if (!(rawfile = findrawpath(rtname))) {
-                               fprintf(stderr,
-                                       _("%s: can't find a char device "
-                                       "matching %s\n"), progname, rtname);
-                               goto done;
-                       }
-                       if (!(blockfile = findblockpath(rtname))) {
-                               fprintf(stderr,
-                                       _("%s: can't find a block device "
-                                       "matching %s\n"), progname, rtname);
-                               goto done;
-                       }
-                       if (!readonly && !inactive &&
-                           platform_check_ismounted(rtname, blockfile, NULL, 1))
-                               goto done;
-                       if (inactive && check_isactive(
-                                               rtname, blockfile, readonly))
+                       if(!check_open(rtname,flags,&rawfile,&blockfile))
                                goto done;
                        a->rtdev = libxfs_device_open(rawfile,
                                        a->rcreat, readonly, a->setblksize);
index 025ea71a0ca336bece07cace884bc450ca90a67e..0bca163bd815134dccd264d69bba0c9b1d10f920 100644 (file)
@@ -3,10 +3,10 @@
 xfs_repair \- repair an XFS filesystem
 .SH SYNOPSIS
 .nf
-\f3xfs_repair\f1 [ \f3\-nLvV\f1 ] [ \f3\-o\f1 subopt[=value] ]
+\f3xfs_repair\f1 [ \f3\-nLvVd\f1 ] [ \f3\-o\f1 subopt[=value] ]
        [\f3-l\f1 logdev] [\f3-r\f1 rtdev] xfs_special
 .sp .8v
-\f3xfs_repair\f1 \f3\-f\f1 [ \f3\-nLvV\f1 ] [ \f3\-o\f1 subopt[=value] ]
+\f3xfs_repair\f1 \f3\-f\f1 [ \f3\-nLvVd\f1 ] [ \f3\-o\f1 subopt[=value] ]
        [\f3-l\f1 logfile] [\f3-r\f1 rtfile] file
 .fi
 .SH DESCRIPTION
@@ -94,6 +94,11 @@ will ignore an EFS superblock if one is found.
 .TP
 .B \-v
 Verbose output.
+.TP
+.B \-d
+Repair dangerously. Allow xfs_repair to repair an XFS filesystem 
+mounted read only. This is typically done on a root fileystem from 
+single user mode, immediately followed by a reboot.
 .SS Checks Performed
 Inconsistencies corrected include the following:
 .TP
index 35fe62d6de64751c43662bffb628cd1441e7597b..da0e621426bcfa5cc54bee6df486e0362ff6e77b 100644 (file)
@@ -120,6 +120,7 @@ EXTERN int  fs_fd;                  /* filesystem fd */
 
 EXTERN int     verbose;
 EXTERN int     no_modify;
+EXTERN int     dangerously;            /* live danderously ... repair a ro mounted fs */
 EXTERN int     isa_file;
 EXTERN int     zap_log;
 EXTERN int     dumpcore;               /* abort, not exit on fatal errs */
index 7570a07e2d34ce32fd71b030c6a4909493e5a7d6..b7dc6e0f044068ff39252bc3167cb75f75f33e8b 100644 (file)
@@ -70,6 +70,10 @@ xfs_init(libxfs_init_t *args)
 
        if (no_modify)
                args->isreadonly = (LIBXFS_ISREADONLY | LIBXFS_ISINACTIVE);
+       
+       if(dangerously)
+               args->isreadonly = (LIBXFS_ISINACTIVE | LIBXFS_DANGEROUSLY);
+       
 
        if (!libxfs_init(args))
                do_error(_("couldn't initialize XFS library\n"));
index a227c38714ef22c868b12ae78cfffa4ce7ba403e..1effeaadab00c357325d046a0fe0ecb1b2666a8d 100644 (file)
@@ -164,6 +164,7 @@ process_args(int argc, char **argv)
        fs_is_dirty = 0;
        verbose = 0;
        no_modify = 0;
+       dangerously = 0;
        isa_file = 0;
        zap_log = 0;
        dumpcore = 0;
@@ -188,7 +189,7 @@ process_args(int argc, char **argv)
         * XXX have to add suboption processing here
         * attributes, quotas, nlinks, aligned_inos, sb_fbits
         */
-       while ((c = getopt(argc, argv, "o:fl:r:LnDvV")) != EOF)  {
+       while ((c = getopt(argc, argv, "o:fl:r:LnDvVd")) != EOF)  {
                switch (c) {
                case 'D':
                        dumpcore = 1;
@@ -243,6 +244,9 @@ process_args(int argc, char **argv)
                case 'V':
                        printf(_("%s version %s\n"), progname, VERSION);
                        exit(0);
+               case 'd': /* dangerously */
+                       dangerously = 1;
+                       break;
                case '?':
                        usage();
                }