]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
xfs_db: Allow writes of corrupted data
authorEric Sandeen <sandeen@sandeen.net>
Mon, 6 Apr 2015 23:19:04 +0000 (09:19 +1000)
committerDave Chinner <david@fromorbit.com>
Mon, 6 Apr 2015 23:19:04 +0000 (09:19 +1000)
Being able to write corrupt data is handy if we wish to test
repair against specific types of corruptions.

Add a "-c" option to the write command which allows this by removing
the write verifier.

Note that this also skips CRC updates; it's not currently possible
to write invalid data with a valid CRC; CRC recalculation is
intertwined with validation.

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
Reviewed-by: Brian Foster <bfoster@redhat.com>
Signed-off-by: Dave Chinner <david@fromorbit.com>
db/io.c
db/io.h
db/write.c
man/man8/xfs_db.8

diff --git a/db/io.c b/db/io.c
index 7f1b76a2594635a5824ebf401d1ca29f89b74e42..c5898f1e5d05548240dbff3464c337a6fe56ff4c 100644 (file)
--- a/db/io.c
+++ b/db/io.c
@@ -456,6 +456,13 @@ write_cur_bbs(void)
                dbprintf(_("read error: %s\n"), strerror(ret));
 }
 
+void
+xfs_dummy_verify(
+       struct xfs_buf *bp)
+{
+       return;
+}
+
 void
 write_cur(void)
 {
diff --git a/db/io.h b/db/io.h
index 71082e6ba1aab9e64fad81e6c00362b4453957c1..31d96b497c77d5637ec2712335dc9236e50a0cc2 100644 (file)
--- a/db/io.h
+++ b/db/io.h
@@ -63,6 +63,7 @@ extern void   set_cur(const struct typ *t, __int64_t d, int c, int ring_add,
                        bbmap_t *bbmap);
 extern void     ring_add(void);
 extern void    set_iocur_type(const struct typ *t);
+extern void    xfs_dummy_verify(struct xfs_buf *bp);
 
 /*
  * returns -1 for unchecked, 0 for bad and 1 for good
index a0f14f46e15e0c35a4fe5aac5353f782c77053a0..655b6188d8db353964eea0ef786334aeab1ebe7d 100644 (file)
@@ -38,7 +38,7 @@ static int    write_f(int argc, char **argv);
 static void     write_help(void);
 
 static const cmdinfo_t write_cmd =
-       { "write", NULL, write_f, 0, -1, 0, N_("[field or value]..."),
+       { "write", NULL, write_f, 0, -1, 0, N_("[-c] [field or value]..."),
          N_("write value to disk"), write_help };
 
 void
@@ -79,6 +79,7 @@ write_help(void)
 "  String mode: 'write \"This_is_a_filename\" - write null terminated string.\n"
 "\n"
 " In data mode type 'write' by itself for a list of specific commands.\n\n"
+" Specifying the -c option will allow writes of invalid (corrupt) data.\n\n"
 ));
 
 }
@@ -90,6 +91,10 @@ write_f(
 {
        pfunc_t pf;
        extern char *progname;
+       int c;
+       int corrupt = 0;                /* Allow write of corrupt data; skip verification */
+       struct xfs_buf_ops nowrite_ops;
+       const struct xfs_buf_ops *stashed_ops = NULL;
 
        if (x.isreadonly & LIBXFS_ISREADONLY) {
                dbprintf(_("%s started in read only mode, writing disabled\n"),
@@ -109,12 +114,34 @@ write_f(
                return 0;
        }
 
-       /* move past the "write" command */
-       argc--;
-       argv++;
+       while ((c = getopt(argc, argv, "c")) != EOF) {
+               switch (c) {
+               case 'c':
+                       corrupt = 1;
+                       break;
+               default:
+                       dbprintf(_("bad option for write command\n"));
+                       return 0;
+               }
+       }
+
+       argc -= optind;
+       argv += optind;
+
+       if (iocur_top->bp->b_ops && corrupt) {
+               /* Temporarily remove write verifier to write bad data */
+               stashed_ops = iocur_top->bp->b_ops;
+               nowrite_ops.verify_read = stashed_ops->verify_read;
+               nowrite_ops.verify_write = xfs_dummy_verify;
+               iocur_top->bp->b_ops = &nowrite_ops;
+               dbprintf(_("Allowing write of corrupted data\n"));
+       }
 
        (*pf)(DB_WRITE, cur_typ->fields, argc, argv);
 
+       if (stashed_ops)
+               iocur_top->bp->b_ops = stashed_ops;
+
        return 0;
 }
 
index 4d8d4ffce1edf30c87b767aec6253a9eeb986b12..d52723060028de01572561e85a90605002a9f08c 100644 (file)
@@ -711,7 +711,7 @@ and
 bits respectively, and their string equivalent reported
 (but no modifications are made).
 .TP
-.BI "write [" "field value" "] ..."
+.BI "write [\-c] [" "field value" "] ..."
 Write a value to disk.
 Specific fields can be set in structures (struct mode),
 or a block can be set to data values (data mode),
@@ -729,6 +729,12 @@ contents of the block can be shifted or rotated left or right, or filled
 with a sequence, a constant value, or a random value. In this mode
 .B write
 with no arguments gives more information on the allowed commands.
+.RS 1.0i
+.TP 0.4i
+.B \-c
+Skip write verifiers and CRC recalculation; allows invalid data to be written
+to disk.
+.RE
 .SH TYPES
 This section gives the fields in each structure type and their meanings.
 Note that some types of block cover multiple actual structures,