Whamcloud - gitweb
debugfs: fix building rdebugfs (with READ_ONLY define)
authorTheodore Ts'o <tytso@mit.edu>
Thu, 18 Jun 2020 01:43:37 +0000 (21:43 -0400)
committerTheodore Ts'o <tytso@mit.edu>
Thu, 18 Jun 2020 01:43:37 +0000 (21:43 -0400)
Fix bitrot for building a restricted version of debugfs, which does
not require read/write access to the file system, and which only
allows access to the file system metadata.

Signed-off-by: Theodore Ts'o <tytso@mit.edu>
debugfs/debugfs.c
debugfs/debugfs.h
debugfs/util.c
debugfs/zap.c

index 4bbadf1..2be5c13 100644 (file)
@@ -276,7 +276,11 @@ void do_open_filesys(int argc, char **argv, int sci_idx EXT2FS_ATTR((unused)),
                                return;
                        break;
                case 'z':
                                return;
                        break;
                case 'z':
+#ifdef READ_ONLY
+                       goto print_usage;
+#else
                        undo_file = optarg;
                        undo_file = optarg;
+#endif
                        break;
                default:
                        goto print_usage;
                        break;
                default:
                        goto print_usage;
@@ -294,9 +298,10 @@ void do_open_filesys(int argc, char **argv, int sci_idx EXT2FS_ATTR((unused)),
 
 print_usage:
        fprintf(stderr, "%s: Usage: open [-s superblock] [-b blocksize] "
 
 print_usage:
        fprintf(stderr, "%s: Usage: open [-s superblock] [-b blocksize] "
+#ifdef READ_ONLY
                "[-d image_filename] [-z undo_file] [-c] [-i] [-f] [-e] [-D] "
                "[-d image_filename] [-z undo_file] [-c] [-i] [-f] [-e] [-D] "
-#ifndef READ_ONLY
-               "[-w] "
+#else
+               "[-d image_filename] [-c] [-i] [-f] [-e] [-D] [-w] "
 #endif
                "<device>\n", argv[0]);
 }
 #endif
                "<device>\n", argv[0]);
 }
@@ -2379,7 +2384,6 @@ void do_fallocate(int argc, char *argv[], int sci_idx EXT2FS_ATTR((unused)),
                return;
        }
 }
                return;
        }
 }
-#endif /* READ_ONLY */
 
 void do_symlink(int argc, char *argv[], int sci_idx EXT2FS_ATTR((unused)),
                void *infop EXT2FS_ATTR((unused)))
 
 void do_symlink(int argc, char *argv[], int sci_idx EXT2FS_ATTR((unused)),
                void *infop EXT2FS_ATTR((unused)))
@@ -2395,6 +2399,7 @@ void do_symlink(int argc, char *argv[], int sci_idx EXT2FS_ATTR((unused)),
                com_err(argv[0], retval, 0);
 
 }
                com_err(argv[0], retval, 0);
 
 }
+#endif /* READ_ONLY */
 
 #if CONFIG_MMP
 void do_dump_mmp(int argc EXT2FS_ATTR((unused)), char *argv[],
 
 #if CONFIG_MMP
 void do_dump_mmp(int argc EXT2FS_ATTR((unused)), char *argv[],
@@ -2539,8 +2544,8 @@ int main(int argc, char **argv)
        const char      *opt_string = "nicR:f:b:s:Vd:D";
 #else
        const char      *opt_string = "niwcR:f:b:s:Vd:Dz:";
        const char      *opt_string = "nicR:f:b:s:Vd:D";
 #else
        const char      *opt_string = "niwcR:f:b:s:Vd:Dz:";
-       char            *undo_file = NULL;
 #endif
 #endif
+       char            *undo_file = NULL;
 #ifdef CONFIG_JBD_DEBUG
        char            *jbd_debug;
 #endif
 #ifdef CONFIG_JBD_DEBUG
        char            *jbd_debug;
 #endif
@@ -2612,9 +2617,11 @@ int main(int argc, char **argv)
                        fprintf(stderr, "\tUsing %s\n",
                                error_message(EXT2_ET_BASE));
                        exit(0);
                        fprintf(stderr, "\tUsing %s\n",
                                error_message(EXT2_ET_BASE));
                        exit(0);
+#ifndef READ_ONLY
                case 'z':
                        undo_file = optarg;
                        break;
                case 'z':
                        undo_file = optarg;
                        break;
+#endif
                default:
                        com_err(argv[0], 0, usage, debug_prog_name);
                        return 1;
                default:
                        com_err(argv[0], 0, usage, debug_prog_name);
                        return 1;
index 956517b..39bc024 100644 (file)
@@ -193,7 +193,8 @@ extern void do_get_quota(int argc, char *argv[], int sci_idx, void *infop);
 
 /* util.c */
 extern __s64 string_to_time(const char *arg);
 
 /* util.c */
 extern __s64 string_to_time(const char *arg);
-errcode_t read_list(char *str, blk64_t **list, size_t *len);
+extern errcode_t read_list(char *str, blk64_t **list, size_t *len);
+extern void do_byte_hexdump(FILE *fp, unsigned char *buf, size_t bufsize);
 
 /* xattrs.c */
 void dump_inode_attributes(FILE *out, ext2_ino_t ino);
 
 /* xattrs.c */
 void dump_inode_attributes(FILE *out, ext2_ino_t ino);
@@ -207,4 +208,3 @@ void block_xattr_dump(FILE *f, unsigned char *buf, unsigned int len);
 /* zap.c */
 extern void do_zap_block(int argc, char **argv, int sci_idx, void *infop);
 extern void do_block_dump(int argc, char **argv, int sci_idx, void *infop);
 /* zap.c */
 extern void do_zap_block(int argc, char **argv, int sci_idx, void *infop);
 extern void do_block_dump(int argc, char **argv, int sci_idx, void *infop);
-extern void do_byte_hexdump(FILE *fp, unsigned char *buf, size_t bufsize);
index 759bb39..da3a7ef 100644 (file)
@@ -562,3 +562,38 @@ err:
        free(lst);
        return retval;
 }
        free(lst);
        return retval;
 }
+
+void do_byte_hexdump(FILE *fp, unsigned char *buf, size_t bufsize)
+{
+       size_t          i, j, max;
+       int             suppress = -1;
+
+       for (i = 0; i < bufsize; i += 16) {
+               max = (bufsize - i > 16) ? 16 : bufsize - i;
+               if (suppress < 0) {
+                       if (i && memcmp(buf + i, buf + i - max, max) == 0) {
+                               suppress = i;
+                               fprintf(fp, "*\n");
+                               continue;
+                       }
+               } else {
+                       if (memcmp(buf + i, buf + suppress, max) == 0)
+                               continue;
+                       suppress = -1;
+               }
+               fprintf(fp, "%04o  ", (unsigned int)i);
+               for (j = 0; j < 16; j++) {
+                       if (j < max)
+                               fprintf(fp, "%02x", buf[i+j]);
+                       else
+                               fprintf(fp, "  ");
+                       if ((j % 2) == 1)
+                               fprintf(fp, " ");
+               }
+               fprintf(fp, " ");
+               for (j = 0; j < max; j++)
+                       fprintf(fp, "%c", isprint(buf[i+j]) ? buf[i+j] : '.');
+               fprintf(fp, "\n");
+       }
+       fprintf(fp, "\n");
+}
index c7996b2..f120377 100644 (file)
@@ -239,38 +239,3 @@ void do_block_dump(int argc, char *argv[], int sci_idx EXT2FS_ATTR((unused)),
 errout:
        free(buf);
 }
 errout:
        free(buf);
 }
-
-void do_byte_hexdump(FILE *fp, unsigned char *buf, size_t bufsize)
-{
-       size_t          i, j, max;
-       int             suppress = -1;
-
-       for (i = 0; i < bufsize; i += 16) {
-               max = (bufsize - i > 16) ? 16 : bufsize - i;
-               if (suppress < 0) {
-                       if (i && memcmp(buf + i, buf + i - max, max) == 0) {
-                               suppress = i;
-                               fprintf(fp, "*\n");
-                               continue;
-                       }
-               } else {
-                       if (memcmp(buf + i, buf + suppress, max) == 0)
-                               continue;
-                       suppress = -1;
-               }
-               fprintf(fp, "%04o  ", (unsigned int)i);
-               for (j = 0; j < 16; j++) {
-                       if (j < max)
-                               fprintf(fp, "%02x", buf[i+j]);
-                       else
-                               fprintf(fp, "  ");
-                       if ((j % 2) == 1)
-                               fprintf(fp, " ");
-               }
-               fprintf(fp, " ");
-               for (j = 0; j < max; j++)
-                       fprintf(fp, "%c", isprint(buf[i+j]) ? buf[i+j] : '.');
-               fprintf(fp, "\n");
-       }
-       fprintf(fp, "\n");
-}