[PATCH 5/7] debugfs: Add new debugfs command punch (aka truncate)

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This uses the newly added ext2fs_punch() function.

Signed-off-by: "Theodore Ts'o" <tytso@xxxxxxx>
---
 debugfs/debug_cmds.ct |    3 +++
 debugfs/debugfs.8.in  |   12 ++++++++++++
 debugfs/debugfs.c     |   31 +++++++++++++++++++++++++++++++
 debugfs/debugfs.h     |    1 +
 4 files changed, 47 insertions(+), 0 deletions(-)

diff --git a/debugfs/debug_cmds.ct b/debugfs/debug_cmds.ct
index 95dea0d..9b6c985 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 9012a56..faa23eb 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 8e0dc55..260c38d 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 deaa56f..4cc8a1f 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);
 
-- 
1.7.0.4

--
To unsubscribe from this list: send the line "unsubscribe linux-ext4" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Reiser Filesystem Development]     [Ceph FS]     [Kernel Newbies]     [Security]     [Netfilter]     [Bugtraq]     [Linux FS]     [Yosemite National Park]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Samba]     [Device Mapper]     [Linux Media]

  Powered by Linux