aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTheodore Ts'o <tytso@mit.edu>2020-06-17 21:43:37 -0400
committerTheodore Ts'o <tytso@mit.edu>2020-06-17 21:43:37 -0400
commit6cdd4b9309fb7aad1746e7abab2afc756274dcbc (patch)
tree35a07c996ee903c1684735af966e6e3e14549357
parent6338a8467564c3a0a12e9fcb08bdd748d736ac2f (diff)
downloade2fsprogs-6cdd4b9309fb7aad1746e7abab2afc756274dcbc.tar.gz
debugfs: fix building rdebugfs (with READ_ONLY define)
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>
-rw-r--r--debugfs/debugfs.c15
-rw-r--r--debugfs/debugfs.h4
-rw-r--r--debugfs/util.c35
-rw-r--r--debugfs/zap.c35
4 files changed, 48 insertions, 41 deletions
diff --git a/debugfs/debugfs.c b/debugfs/debugfs.c
index 4bbadf1cb..2be5c13cc 100644
--- a/debugfs/debugfs.c
+++ b/debugfs/debugfs.c
@@ -276,7 +276,11 @@ void do_open_filesys(int argc, char **argv, int sci_idx EXT2FS_ATTR((unused)),
return;
break;
case 'z':
+#ifdef READ_ONLY
+ goto print_usage;
+#else
undo_file = optarg;
+#endif
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] "
+#ifdef READ_ONLY
"[-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]);
}
@@ -2379,7 +2384,6 @@ void do_fallocate(int argc, char *argv[], int sci_idx EXT2FS_ATTR((unused)),
return;
}
}
-#endif /* READ_ONLY */
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);
}
+#endif /* READ_ONLY */
#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:";
- char *undo_file = NULL;
#endif
+ char *undo_file = NULL;
#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);
+#ifndef READ_ONLY
case 'z':
undo_file = optarg;
break;
+#endif
default:
com_err(argv[0], 0, usage, debug_prog_name);
return 1;
diff --git a/debugfs/debugfs.h b/debugfs/debugfs.h
index 956517bcf..39bc0247f 100644
--- a/debugfs/debugfs.h
+++ b/debugfs/debugfs.h
@@ -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);
-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);
@@ -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);
-extern void do_byte_hexdump(FILE *fp, unsigned char *buf, size_t bufsize);
diff --git a/debugfs/util.c b/debugfs/util.c
index 759bb3924..da3a7ef76 100644
--- a/debugfs/util.c
+++ b/debugfs/util.c
@@ -562,3 +562,38 @@ err:
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");
+}
diff --git a/debugfs/zap.c b/debugfs/zap.c
index c7996b229..f12037741 100644
--- a/debugfs/zap.c
+++ b/debugfs/zap.c
@@ -239,38 +239,3 @@ void do_block_dump(int argc, char *argv[], int sci_idx EXT2FS_ATTR((unused)),
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");
-}