aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDarren Hart <dvhart@infradead.org>2013-01-04 12:00:59 -0800
committerTheodore Ts'o <tytso@mit.edu>2013-01-16 14:09:20 -0500
commit4df6a37bd39c84ea67394ab5049bc82f14b929b5 (patch)
treee156bcfc1fb457411db4419bfd672da22a291667
parentf01c1a6bce5e6674cbfa5260db1691bca01a4410 (diff)
downloade2fsprogs-4df6a37bd39c84ea67394ab5049bc82f14b929b5.tar.gz
e2fsprogs-4df6a37bd39c84ea67394ab5049bc82f14b929b5.tar.xz
e2fsprogs-4df6a37bd39c84ea67394ab5049bc82f14b929b5.zip
debugfs: add symlink command
Add support for symbolic links using a new symlink command. Modeled after the do_mkdir() command. Testing demonstrates both fastlinks and slowlinks work correctly. Very long target paths fail as the command parsing appears to truncate the input to somewhere around 256 bytes. Signed-off-by: Darren Hart <dvhart@infradead.org> Signed-off-by: "Theodore Ts'o" <tytso@mit.edu> Cc: "Darrick J. Wong" <darrick.wong@oracle.com> Cc: Andreas Dilger <adilger@dilger.ca>
-rw-r--r--debugfs/debug_cmds.ct3
-rw-r--r--debugfs/debugfs.8.in3
-rw-r--r--debugfs/debugfs.c43
-rw-r--r--debugfs/debugfs.h1
4 files changed, 50 insertions, 0 deletions
diff --git a/debugfs/debug_cmds.ct b/debugfs/debug_cmds.ct
index 4e50ab52..96ff00f0 100644
--- a/debugfs/debug_cmds.ct
+++ b/debugfs/debug_cmds.ct
@@ -160,6 +160,9 @@ request do_bmap, "Calculate the logical->physical block mapping for an inode",
request do_punch, "Punch (or truncate) blocks from an inode by deallocating them",
punch, truncate;
+request do_symlink, "Create a symbolic link",
+ symlink;
+
request do_imap, "Calculate the location of an inode",
imap;
diff --git a/debugfs/debugfs.8.in b/debugfs/debugfs.8.in
index bf93622e..e563b0db 100644
--- a/debugfs/debugfs.8.in
+++ b/debugfs/debugfs.8.in
@@ -465,6 +465,9 @@ is, all of the blocks starting at
.I start_blk
through to the end of the file will be deallocated.
.TP
+.I symlink filespec target
+Make a symbolic link.
+.TP
.I pwd
Print the current working directory.
.TP
diff --git a/debugfs/debugfs.c b/debugfs/debugfs.c
index b4eb805b..59860e79 100644
--- a/debugfs/debugfs.c
+++ b/debugfs/debugfs.c
@@ -2190,6 +2190,49 @@ void do_punch(int argc, char *argv[])
}
#endif /* READ_ONLY */
+void do_symlink(int argc, char *argv[])
+{
+ char *cp;
+ ext2_ino_t parent;
+ char *name, *target;
+ errcode_t retval;
+
+ if (common_args_process(argc, argv, 3, 3, "symlink",
+ "<filename> <target>", CHECK_FS_RW))
+ return;
+
+ cp = strrchr(argv[1], '/');
+ if (cp) {
+ *cp = 0;
+ parent = string_to_inode(argv[1]);
+ if (!parent) {
+ com_err(argv[1], ENOENT, 0);
+ return;
+ }
+ name = cp+1;
+ } else {
+ parent = cwd;
+ name = argv[1];
+ }
+ target = argv[2];
+
+try_again:
+ retval = ext2fs_symlink(current_fs, parent, 0, name, target);
+ if (retval == EXT2_ET_DIR_NO_SPACE) {
+ retval = ext2fs_expand_dir(current_fs, parent);
+ if (retval) {
+ com_err(argv[0], retval, "while expanding directory");
+ return;
+ }
+ goto try_again;
+ }
+ if (retval) {
+ com_err("ext2fs_symlink", retval, 0);
+ return;
+ }
+
+}
+
void do_dump_mmp(int argc EXT2FS_ATTR((unused)), char *argv[])
{
struct ext2_super_block *sb;
diff --git a/debugfs/debugfs.h b/debugfs/debugfs.h
index ea09e539..45175cf9 100644
--- a/debugfs/debugfs.h
+++ b/debugfs/debugfs.h
@@ -162,6 +162,7 @@ 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);
+extern void do_symlink(int argc, char **argv);
extern void do_dump_mmp(int argc, char **argv);
extern void do_set_mmp_value(int argc, char **argv);