summaryrefslogtreecommitdiff
path: root/debugfs
diff options
context:
space:
mode:
authorTheodore Ts'o <tytso@mit.edu>2010-07-22 09:39:04 -0400
committerTheodore Ts'o <tytso@mit.edu>2010-07-22 09:39:04 -0400
commit86685923625eed3632eaf17cdda8e86f13b13384 (patch)
treec647e63c51ccef57fa585651004e9c8d18134836 /debugfs
parent3adb9374fb92736e393ad64f751073b19927ec0e (diff)
downloade2fsprogs-86685923625eed3632eaf17cdda8e86f13b13384.tar.gz
debugfs: Add new debugfs command punch (aka truncate)
This uses the newly added ext2fs_punch() function. Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
Diffstat (limited to 'debugfs')
-rw-r--r--debugfs/debug_cmds.ct3
-rw-r--r--debugfs/debugfs.8.in12
-rw-r--r--debugfs/debugfs.c31
-rw-r--r--debugfs/debugfs.h1
4 files changed, 47 insertions, 0 deletions
diff --git a/debugfs/debug_cmds.ct b/debugfs/debug_cmds.ct
index 95dea0df..9b6c985a 100644
--- a/debugfs/debug_cmds.ct
+++ b/debugfs/debug_cmds.ct
@@ -148,6 +148,9 @@ request do_dirsearch, "Search a directory for a particular filename",
request do_bmap, "Calculate the logical->physical block mapping for an inode",
bmap;
+request do_punch, "Punch (or truncate) blocks from an inode by deallocating them",
+ punch, truncate;
+
request do_imap, "Calculate the location of an inode",
imap;
diff --git a/debugfs/debugfs.8.in b/debugfs/debugfs.8.in
index 9012a56a..faa23eb2 100644
--- a/debugfs/debugfs.8.in
+++ b/debugfs/debugfs.8.in
@@ -376,6 +376,18 @@ flag causes the filesystem to be opened in exclusive mode. The
options behave the same as the command-line options to
.BR debugfs .
.TP
+.I punch filespec start_blk [end_blk]
+Delete the blocks in the inode ranging from
+.I start_blk
+to
+.IR end_blk .
+If
+.I end_blk
+is omitted then this command will function as a truncate command; that
+is, all of the blocks starting at
+.I start_blk
+through to the end of the file will be deallocated.
+.TP
.I pwd
Print the current working directory.
.TP
diff --git a/debugfs/debugfs.c b/debugfs/debugfs.c
index 8e0dc55d..260c38d9 100644
--- a/debugfs/debugfs.c
+++ b/debugfs/debugfs.c
@@ -2102,6 +2102,37 @@ void do_supported_features(int argc, char *argv[])
}
}
+void do_punch(int argc, char *argv[])
+{
+ ext2_ino_t ino;
+ blk64_t start, end;
+ int err;
+ errcode_t errcode;
+
+ if (common_args_process(argc, argv, 3, 4, argv[0],
+ "<file> start_blk [end_blk]",
+ CHECK_FS_RW | CHECK_FS_BITMAPS))
+ return;
+
+ ino = string_to_inode(argv[1]);
+ if (!ino)
+ return;
+ start = parse_ulong(argv[2], argv[0], "logical_block", &err);
+ if (argc == 4)
+ end = parse_ulong(argv[3], argv[0], "logical_block", &err);
+ else
+ end = ~0;
+
+ errcode = ext2fs_punch(current_fs, ino, 0, 0, start, end);
+
+ if (errcode) {
+ com_err(argv[0], errcode,
+ "while truncating inode %u from %llu to %llu\n", ino,
+ (unsigned long long) start, (unsigned long long) end);
+ return;
+ }
+}
+
static int source_file(const char *cmd_file, int sci_idx)
{
FILE *f;
diff --git a/debugfs/debugfs.h b/debugfs/debugfs.h
index deaa56fd..4cc8a1ff 100644
--- a/debugfs/debugfs.h
+++ b/debugfs/debugfs.h
@@ -127,4 +127,5 @@ extern void do_bmap(int argc, char **argv);
extern void do_imap(int argc, char **argv);
extern void do_set_current_time(int argc, char **argv);
extern void do_supported_features(int argc, char **argv);
+extern void do_punch(int argc, char **argv);