Whamcloud - gitweb
debugfs: Add new debugfs command punch (aka truncate)
authorTheodore Ts'o <tytso@mit.edu>
Thu, 22 Jul 2010 13:39:04 +0000 (09:39 -0400)
committerTheodore Ts'o <tytso@mit.edu>
Thu, 22 Jul 2010 13:39:04 +0000 (09:39 -0400)
This uses the newly added ext2fs_punch() function.

Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
debugfs/debug_cmds.ct
debugfs/debugfs.8.in
debugfs/debugfs.c
debugfs/debugfs.h

index 95dea0d..9b6c985 100644 (file)
@@ -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;
 
index 9012a56..faa23eb 100644 (file)
@@ -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
index 8e0dc55..260c38d 100644 (file)
@@ -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;
index deaa56f..4cc8a1f 100644 (file)
@@ -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);