ext2fsprogs: Symlink support
v2 cover ext2fsprogs: Symlink support
The following series adds symlink support the libext2fs and adds the command to debugfs. Basic testing demonstrates functional duplication of a small test directory including fastlinks and slowlinks in both the root and a single subdirectory.
There is one FIXME/question remaining in the symlink implementation regarding the use of ext2fs_bmap2 where I would particularly welcome some review. I found the various block creation, allocation, and bitmap functions to be rather difficult to grok in terms of which to use when.
Otherwise, I believe I have addressed Ted's and Darrick's comments from the previous RFC.
Thanks,
Darren Hart
Intel Open Source Technology Center
PATCH v2 1/3 lib/ext2fs: Add ext2fs_symlink
Creating symlinks is a complex affair when accounting for slowlinks.
Create a new function, ext2fs_symlink(), modeled after ext2fs_mkdir(). Like ext2fs_mkdir(), ext2fs_symlink() takes on the task of allocating a new inode and block (for slowlinks), setting up sane default values in the inode, copying the target path to either the inode (for fastlinks) or to the first block (for slowlinks), and accounting for the inode and block stats. Disallow link targets longer than blocksize as the Linux kernel prevents this.
It does not attempt to expand the parent directory, instead returning EXT2_ET_DIR_NO_SPACE and leaving it to the caller to expand just as ext2fs_mkdir() does. Ideally, I think both of these functions should make a single attempt to expand the directory.
Note the one remaining FIXME. Do I need to use ext2fs_bmap2() for the slowlink without extents? If not, how is the 0 block associated with the inode?
libext2fs.a impact (stripped):
Orig | Patched | Delta 274752 | 276580 | 1828
V2 incorporates feedback from Ted and Darrick:
o Add error codes to the end of the table
o Remove redundant EXT2_FT_SYMLINK definition
o Time fields set by write_new_inode
o Use size=target_len for slow links as well
o Test for len < blocksize
o Replace file ops with manual block handling
o Keep line width under 80 characters
--- lib/ext2fs/Makefile.in | 8 +++ lib/ext2fs/ext2_err.et.in | 3 + lib/ext2fs/symlink.c | 161 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 172 insertions(+) create mode 100644 lib/ext2fs/symlink.c
lib/ext2fs/Makefile.in +8 -0
@@ -80,6 +80,7 @@ OBJS= $(DEBUGFS_LIB_OBJS) $(RESIZE_LIB_OBJS) $(E2IMAGE_LIB_OBJS) \ res_gdt.o \ rw_bitmaps.o \ swapfs.o \ + symlink.o \ tdb.o \ undo_io.o \ unix_io.o \
@@ -155,6 +156,7 @@ SRCS= ext2_err.c \ $(srcdir)/res_gdt.c \ $(srcdir)/rw_bitmaps.c \ $(srcdir)/swapfs.c \ + $(srcdir)/symlink.c \ $(srcdir)/tdb.c \ $(srcdir)/test_io.c \ $(srcdir)/tst_badblocks.c \
@@ -893,6 +895,12 @@ swapfs.o: $(srcdir)/swapfs.c $(top_builddir)/lib/config.h \ $(srcdir)/ext2_fs.h $(srcdir)/ext3_extents.h $(top_srcdir)/lib/et/com_err.h \ $(srcdir)/ext2_io.h $(top_builddir)/lib/ext2fs/ext2_err.h \ $(srcdir)/ext2_ext_attr.h $(srcdir)/bitops.h +symlink.o: $(srcdir)/symlink.c $(top_builddir)/lib/config.h \ + $(top_builddir)/lib/dirpaths.h $(srcdir)/ext2_fs.h \ + $(top_builddir)/lib/ext2fs/ext2_types.h $(srcdir)/ext2fs.h \ + $(srcdir)/ext2_fs.h $(srcdir)/ext3_extents.h $(top_srcdir)/lib/et/com_err.h \ + $(srcdir)/ext2_io.h $(top_builddir)/lib/ext2fs/ext2_err.h \ + $(srcdir)/ext2_ext_attr.h $(srcdir)/bitops.h tdb.o: $(srcdir)/tdb.c $(top_builddir)/lib/config.h \ $(top_builddir)/lib/dirpaths.h $(srcdir)/tdb.h test_io.o: $(srcdir)/test_io.c $(top_builddir)/lib/config.h \
lib/ext2fs/ext2_err.et.in +3 -0
@@ -473,4 +473,7 @@ ec EXT2_ET_UNKNOWN_CSUM, ec EXT2_ET_MMP_CSUM_INVALID, "MMP block checksum does not match MMP block" +ec EXT2_ET_FILE_EXISTS, + "Ext2 file already exists" + end
lib/ext2fs/symlink.c new file +161 -0
161 lines not on this page · raw message
Signature · 1 line
1.7.11.7
Re: [PATCH 1/3] lib/ext2fs: Add ext2fs_symlink
Quoted 182 lines · Darren Hart
Creating symlinks is a complex affair when accounting for slowlinks.
Create a new function,
ext2fs_symlink(), modeled afterext2fs_mkdir(). Likeext2fs_mkdir(),ext2fs_symlink()takes on the task of allocating a new inode and block (for slowlinks), setting up sane default values in the inode, copying the target path to either the inode (for fastlinks) or to the first block (for slowlinks), and accounting for the inode and block stats. Disallow link targets longer than blocksize as the Linux kernel prevents this.It does not attempt to expand the parent directory, instead returning
EXT2_ET_DIR_NO_SPACEand leaving it to the caller to expand just asext2fs_mkdir()does. Ideally, I think both of these functions should make a single attempt to expand the directory.Note the one remaining FIXME. Do I need to use
ext2fs_bmap2()for the slowlink without extents? If not, how is the 0 block associated with the inode?libext2fs.a impact (stripped):
Orig | Patched | Delta 274752 | 276580 | 1828V2 incorporates feedback from Ted and Darrick:
o Add error codes to the end of the table
o Remove redundantEXT2_FT_SYMLINKdefinition
o Time fields set bywrite_new_inode
o Use size=target_len for slow links as well
o Test for len < blocksize
o Replace file ops with manual block handling
o Keep line width under 80 charactersSigned-off-by Darren Hart <[email protected]>Cc "Theodore Ts'o" <[email protected]>Cc "Darrick J. Wong" <[email protected]>Cc "Andreas Dilger" <[email protected]>--- lib/ext2fs/Makefile.in | 8 +++ lib/ext2fs/ext2_err.et.in | 3 + lib/ext2fs/symlink.c | 161 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 172 insertions(+) create mode 100644 lib/ext2fs/symlink.clib/ext2fs/Makefile.in +8
-0@@ -80,6 +80,7 @@ OBJS= $(DEBUGFS_LIB_OBJS) $(RESIZE_LIB_OBJS) $(E2IMAGE_LIB_OBJS) \ res_gdt.o \ rw_bitmaps.o \ swapfs.o \ + symlink.o \ tdb.o \ undo_io.o \ unix_io.o \@@ -155,6 +156,7 @@ SRCS= ext2_err.c \ $(srcdir)/res_gdt.c \ $(srcdir)/rw_bitmaps.c \ $(srcdir)/swapfs.c \ + $(srcdir)/symlink.c \ $(srcdir)/tdb.c \ $(srcdir)/test_io.c \ $(srcdir)/tst_badblocks.c \@@ -893,6 +895,12 @@ swapfs.o: $(srcdir)/swapfs.c $(top_builddir)/lib/config.h \ $(srcdir)/ext2_fs.h $(srcdir)/ext3_extents.h $(top_srcdir)/lib/et/com_err.h \ $(srcdir)/ext2_io.h $(top_builddir)/lib/ext2fs/ext2_err.h \ $(srcdir)/ext2_ext_attr.h $(srcdir)/bitops.h +symlink.o: $(srcdir)/symlink.c $(top_builddir)/lib/config.h \ + $(top_builddir)/lib/dirpaths.h $(srcdir)/ext2_fs.h \ + $(top_builddir)/lib/ext2fs/ext2_types.h $(srcdir)/ext2fs.h \ + $(srcdir)/ext2_fs.h $(srcdir)/ext3_extents.h $(top_srcdir)/lib/et/com_err.h \ + $(srcdir)/ext2_io.h $(top_builddir)/lib/ext2fs/ext2_err.h \ + $(srcdir)/ext2_ext_attr.h $(srcdir)/bitops.h tdb.o: $(srcdir)/tdb.c $(top_builddir)/lib/config.h \ $(top_builddir)/lib/dirpaths.h $(srcdir)/tdb.h test_io.o: $(srcdir)/test_io.c $(top_builddir)/lib/config.h \lib/ext2fs/ext2_err.et.in +3
-0@@ -473,4 +473,7 @@ ec EXT2_ET_UNKNOWN_CSUM, ec EXT2_ET_MMP_CSUM_INVALID, "MMP block checksum does not match MMP block" +ec EXT2_ET_FILE_EXISTS, + "Ext2 file already exists" + endlib/ext2fs/symlink.c new file +88
-0@@ -0,0 +1,161 @@ +/* +* symlink.c --- make a symlink in the filesystem, based on mkdir.c +* +* Copyright (c) 2012, Intel Corporation. +* All Rights Reserved. +* +* %Begin-Header% +* This file may be redistributed under the terms of the GNU Library +* General Public License, version 2. +* %End-Header% +*/ + +#include "config.h" +#include <stdio.h> +#include <string.h> +#if HAVE_UNISTD_H +#include <unistd.h> +#endif +#include <fcntl.h> +#include <time.h> +#if HAVE_SYS_STAT_H +#include <sys/stat.h> +#endif +#if HAVE_SYS_TYPES_H +#include <sys/types.h> +#endif + +#include "ext2_fs.h" +#include "ext2fs.h" + +errcode_t ext2fs_symlink (ext2_filsys fs,ext2_ino_t parent,ext2_ino_t ino, +const char *name,char *target) +{ +ext2_extent_handle_t handle; +errcode_t retval; +struct ext2_inode inode; +ext2_ino_t scratch_ino; +blk64_t blk; +int fastlink; +int target_len; +char *block_buf =0 ; + +EXT2_CHECK_MAGIC (fs,EXT2_ET_MAGIC_EXT2FS_FILSYS ); + +/* The Linux kernel doesn't allow for links longer than a block */ + target_len =strlen (target); +if (target_len > fs->blocksize) { + retval =EXT2_ET_INVALID_ARGUMENT ; + goto cleanup; + } + +/* +* Allocate a data block for slow links +*/ + fastlink = (target_len <sizeof (inode.i_block)); +if (!fastlink) { + retval =ext2fs_new_block2 (fs,0 ,0 , &blk); +if (retval) + goto cleanup; + retval =ext2fs_get_mem (fs->blocksize, &block_buf); +if (retval) + goto cleanup; + } + +/* +* Allocate an inode, if necessary +*/ +if (!ino) { + retval =ext2fs_new_inode (fs, parent,LINUX_S_IFLNK |0755 , +0 , &ino); +if (retval) + goto cleanup; + } + +/* +* Create the inode structure.... +*/ +memset (&inode,0 ,sizeof (struct ext2_inode )); + inode.i_mode =LINUX_S_IFLNK |0777 ; + inode.i_uid = inode.i_gid =0 ; +ext2fs_iblk_set (fs, &inode,1 ); + inode.i_links_count =1 ; + inode.i_size = target_len; +/* The time fields are set by ext2fs_write_new_inode() */ + +if (fastlink) { +/* Fast symlinks, target stored in inode */ +strcpy ((char *)&inode.i_block, target);
lib/ext2fs/symlink.c line 98
Quoted 10 lines
lib/ext2fs/symlink.c new file +10
-0+ }else { +/* Slow symlinks, target stored in the first block */ +strcpy (block_buf, target); +if (fs->super->s_feature_incompat & +EXT3_FEATURE_INCOMPAT_EXTENTS ) { +/* +* The extent bmap is setup after the inode and block +* have been written out below. +*/ + inode.i_flags |=EXT4_EXTENTS_FL ;
Given that you can have at most one data block anyway, does it matter to set EXTENTS_FL?
Actually, now that I think of it -- any reason not to use the ext2fs_file_* functions? They'll take care of block allocation, updating the extent tree, etc, so you don't have to remember how to do that here.
I think you have to ext2fs_write_new_inode() before you can ext2fs_file_open().
Also, what happens to the inode + data block if the ext2fs_link fails? I don't see any code that explicitly rolls back those allocations, but maybe I missed something?
--D
Quoted 66 lines
lib/ext2fs/symlink.c new file +63
-0+ }else { + inode.i_block[0 ] = blk; + } + } + +/* +* Write out the inode and inode data block. The inode generation +* number is assigned by write_new_inode, which means that the +* operations using ino must come after it. +*/ + retval =ext2fs_write_new_inode (fs, ino, &inode); +if (retval) + goto cleanup; + +if (!fastlink) { + retval =io_channel_write_blk (fs->io, blk,1 , block_buf); +if (retval) + goto cleanup; + +/* FIXME/VERIFY: Do we need ext2fs_bmap2() here? file ops use +* it, mkdir did not */ + +if (fs->super->s_feature_incompat & +EXT3_FEATURE_INCOMPAT_EXTENTS ) { + retval =ext2fs_extent_open2 (fs, ino, &inode, &handle); +if (retval) + goto cleanup; + retval =ext2fs_extent_set_bmap (handle,0 , blk,0 ); +ext2fs_extent_free (handle); +if (retval) + goto cleanup; + } + } + +/* +* Link the symlink into the filesystem hierarchy +*/ +if (name) { + retval =ext2fs_lookup (fs, parent, name,strlen (name),0 , + &scratch_ino); +if (!retval) { + retval =EXT2_ET_FILE_EXISTS ; + goto cleanup; + } +if (retval !=EXT2_ET_FILE_NOT_FOUND ) + goto cleanup; + retval =ext2fs_link (fs, parent, name, ino,EXT2_FT_SYMLINK ); +if (retval) + goto cleanup; + } + +/* +* Update accounting.... +*/ +if (!fastlink) +ext2fs_block_alloc_stats2 (fs, blk,+1 ); +ext2fs_inode_alloc_stats2 (fs, ino,+1 ,1 ); + +cleanup: +if (block_buf) +ext2fs_free_mem (&block_buf); +return retval; +}Signature · 1 line
1.7.11.7
Re: [PATCH 1/3] lib/ext2fs: Add ext2fs_symlink
Quoted 2 lines · Darrick J. Wong
Given that you can have at most one data block anyway, does it matter to set
EXTENTS_FL?
It doesn't matter either way.
Quoted 3 lines
Also, what happens to the inode + data block if the
ext2fs_linkfails? I don't see any code that explicitly rolls back those allocations, but maybe I missed something?
It's fine. We don't actually update the block bitmap, nor update the block group statistics, until the very end, when the proposed code does this:
*/ if (!fastlink) ext2fs_block_alloc_stats2(fs, blk, +1); ext2fs_inode_alloc_stats2(fs, ino, +1, 1);
This is one of the reasons why ext2fs_new_block and ext2fs_new_inode don't actually mark the block and inode as in use. You could argue they are misnamed; something like ext2fs_find_unused_{block,inode}() would have been better names, but what I can say? I didn't think of that back in 1996....
- Ted
Theodore Ts'o
AppliedRe: [PATCH 1/3] lib/ext2fs: Add ext2fs_symlink
In reply to Darren HartOn Fri, Jan 04, 2013 at 12:00:58PM -0800, Darren Hart wrote:
Applied, thanks.
Quoted 3 lines
Note the one remaining FIXME. Do I need to use
ext2fs_bmap2()for the slowlink without extents? If not, how is the 0 block associated with the inode?
No, you don't need to use ext2fs_bmap2(). The 0 block was set here in the else clause:
+ if (fs->super->s_feature_incompat &
+ EXT3_FEATURE_INCOMPAT_EXTENTS) {
+ /*
+ * The extent bmap is setup after the inode and block
+ * have been written out below.
+ */
+ inode.i_flags |= EXT4_EXTENTS_FL;
+ } else {
+ inode.i_block[0] = blk;
+ }
- Ted
Re: [PATCH 1/3] lib/ext2fs: Add ext2fs_symlink
In reply to Darren HartI'll fix up the this patch before I commit it, but this is a perfect exhibit about why I request that code submissions come with test cases. It turns out that there were a couple of problems with ext2fs_symlink(), that showed up very quickly as soon as I started writing a test case (where it's important to run e2fsck on the resulting file system after creating the symlinks --- e2fsck is a wonderful rep invariant checkers for ext[234] file systems. :-)
*) i_blocks must be set to 0 for fast symlinks
*) The last argument of ext2fs_inode_alloc_stats() indicates whether
the new inode is a directory or not. So when you cut and pasted the code from ext2fs_mkdir(), it needed to be changed.
*) Zeroing the entire block before setting the symlink in the case
where it needs to use an external data block makes it a lot easier to write the regression test.
So here's the patch I needed to apply on top of your submission....
- Ted
lib/ext2fs/symlink.c +3 -2
@@ -78,7 +78,7 @@ errcode_t ext2fs_symlink(ext2_filsys fs, ext2_ino_t parent, ext2_ino_t ino,memset (&inode,0 ,sizeof (struct ext2_inode )); inode.i_mode =LINUX_S_IFLNK |0777 ; inode.i_uid = inode.i_gid =0 ; -ext2fs_iblk_set (fs, &inode,1 ); +ext2fs_iblk_set (fs, &inode, fastlink ?0 :1 ); inode.i_links_count =1 ; inode.i_size = target_len;/* The time fields are set by ext2fs_write_new_inode() */
@@ -88,6 +88,7 @@ errcode_t ext2fs_symlink(ext2_filsys fs, ext2_ino_t parent, ext2_ino_t ino,strcpy ((char *)&inode.i_block, target); }else {/* Slow symlinks, target stored in the first block */ +memset (block_buf,0 , fs->blocksize);strcpy (block_buf, target);if (fs->super->s_feature_incompat &EXT3_FEATURE_INCOMPAT_EXTENTS ) {
@@ -149,7 +150,7 @@ errcode_t ext2fs_symlink(ext2_filsys fs, ext2_ino_t parent, ext2_ino_t ino,*/ if (!fastlink)ext2fs_block_alloc_stats2 (fs, blk,+1 ); -ext2fs_inode_alloc_stats2 (fs, ino,+1 ,1 ); +ext2fs_inode_alloc_stats2 (fs, ino,+1 ,0 ); cleanup:if (block_buf)
PATCH 1/2 debugfs: fix mknod command so that it updates the block group statistics
--- debugfs/debugfs.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
debugfs/debugfs.c +1 -2
@@ -1747,8 +1747,7 @@ void do_mknod(int argc, char *argv[]) }if (ext2fs_test_inode_bitmap2 (current_fs->inode_map,newfile))com_err (argv[0 ],0 ,"Warning: inode already set" ); -ext2fs_mark_inode_bitmap2 (current_fs->inode_map, newfile); -ext2fs_mark_ib_dirty (current_fs); +ext2fs_inode_alloc_stats2 (current_fs, newfile,+1 ,0 );memset (&inode,0 ,sizeof (inode)); inode.i_mode = mode; inode.i_atime = inode.i_ctime = inode.i_mtime =
Signature · 1 line
1.7.12.rc0.22.gcdd159b
PATCH 2/2 tests: create test for debugfs creating special files
--- tests/d_special_files/expect | 85 +++++++++++++++++++++++++++++++++++++++ tests/d_special_files/name | 1 + tests/d_special_files/script | 94 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 180 insertions(+) create mode 100644 tests/d_special_files/expect create mode 100644 tests/d_special_files/name create mode 100644 tests/d_special_files/script
tests/d_special_files/expect new file +85 -0
@@ -0,0 +1,85 @@ +debugfs create special files +mke2fs -Fq -b 1024 test.img 512 +Exit status is 0 +debugfs -R ''stat foo'' -w test.img +Inode: 12 Type: symlink Mode: 0777 Flags: 0x0 +Generation: 0 Version: 0x00000000 +User: 0 Group: 0 Size: 3 +File ACL: 0 Directory ACL: 0 +Links: 1 Blockcount: 0 +Fragment: Address: 0 Number: 0 Size: 0 +ctime: 0x50f560e0 -- Tue Jan 15 14:00:00 2013 +atime: 0x50f560e0 -- Tue Jan 15 14:00:00 2013 +mtime: 0x50f560e0 -- Tue Jan 15 14:00:00 2013 +Fast_link_dest: bar +Exit status is 0 +debugfs -R ''stat foo2'' -w test.img +Inode: 13 Type: symlink Mode: 0777 Flags: 0x0 +Generation: 0 Version: 0x00000000 +User: 0 Group: 0 Size: 80 +File ACL: 0 Directory ACL: 0 +Links: 1 Blockcount: 2 +Fragment: Address: 0 Number: 0 Size: 0 +ctime: 0x50f560e0 -- Tue Jan 15 14:00:00 2013 +atime: 0x50f560e0 -- Tue Jan 15 14:00:00 2013 +mtime: 0x50f560e0 -- Tue Jan 15 14:00:00 2013 +BLOCKS: +(0):28 +TOTAL: 1 + +Exit status is 0 +debugfs -R ''block_dump 28'' -w test.img +0000 3132 3334 3536 3738 3930 3132 3334 3536 1234567890123456 +0020 3738 3930 3132 3334 3536 3738 3930 3132 7890123456789012 +0040 3334 3536 3738 3930 3132 3334 3536 3738 3456789012345678 +0060 3930 3132 3334 3536 3738 3930 3132 3334 9012345678901234 +0100 3536 3738 3930 3132 3334 3536 3738 3930 5678901234567890 +0120 0000 0000 0000 0000 0000 0000 0000 0000 ................ +* + +Exit status is 0 +debugfs -R ''stat pipe'' -w test.img +Inode: 14 Type: FIFO Mode: 0000 Flags: 0x0 +Generation: 0 Version: 0x00000000 +User: 0 Group: 0 Size: 0 +File ACL: 0 Directory ACL: 0 +Links: 1 Blockcount: 0 +Fragment: Address: 0 Number: 0 Size: 0 +ctime: 0x50f560e0 -- Tue Jan 15 14:00:00 2013 +atime: 0x50f560e0 -- Tue Jan 15 14:00:00 2013 +mtime: 0x50f560e0 -- Tue Jan 15 14:00:00 2013 +BLOCKS: + +Exit status is 0 +debugfs -R ''stat sda'' -w test.img +Inode: 15 Type: block special Mode: 0000 Flags: 0x0 +Generation: 0 Version: 0x00000000 +User: 0 Group: 0 Size: 0 +File ACL: 0 Directory ACL: 0 +Links: 1 Blockcount: 0 +Fragment: Address: 0 Number: 0 Size: 0 +ctime: 0x50f560e0 -- Tue Jan 15 14:00:00 2013 +atime: 0x50f560e0 -- Tue Jan 15 14:00:00 2013 +mtime: 0x50f560e0 -- Tue Jan 15 14:00:00 2013 +Device major/minor number: 08:00 (hex 08:00) +Exit status is 0 +debugfs -R ''stat null'' -w test.img +Inode: 16 Type: character special Mode: 0000 Flags: 0x0 +Generation: 0 Version: 0x00000000 +User: 0 Group: 0 Size: 0 +File ACL: 0 Directory ACL: 0 +Links: 1 Blockcount: 0 +Fragment: Address: 0 Number: 0 Size: 0 +ctime: 0x50f560e0 -- Tue Jan 15 14:00:00 2013 +atime: 0x50f560e0 -- Tue Jan 15 14:00:00 2013 +mtime: 0x50f560e0 -- Tue Jan 15 14:00:00 2013 +Device major/minor number: 01:03 (hex 01:03) +Exit status is 0 +e2fsck -yf -N test_filesys +Pass 1: Checking inodes, blocks, and sizes +Pass 2: Checking directory structure +Pass 3: Checking directory connectivity +Pass 4: Checking reference counts +Pass 5: Checking group summary information +test_filesys: 16/64 files (0.0% non-contiguous), 29/512 blocks +Exit status is 0
tests/d_special_files/name new file +1 -0
@@ -0,0 +1 @@ +create special files in debugfs
tests/d_special_files/script new file +94 -0
94 lines not on this page · raw message
Signature · 1 line
1.7.12.rc0.22.gcdd159b
Re: [PATCH 1/3] lib/ext2fs: Add ext2fs_symlink
In reply to Theodore Ts'oQuoted 16 lines · Theodore Ts'o
I'll fix up the this patch before I commit it, but this is a perfect exhibit about why I request that code submissions come with test cases. It turns out that there were a couple of problems with
ext2fs_symlink(), that showed up very quickly as soon as I started writing a test case (where it's important to run e2fsck on the resulting file system after creating the symlinks --- e2fsck is a wonderful rep invariant checkers for ext[234] file systems. :-)*)
i_blocksmust be set to 0 for fast symlinks
*) The last argument ofext2fs_inode_alloc_stats()indicates whether
the new inode is a directory or not. So when you cut and pasted the code fromext2fs_mkdir(), it needed to be changed.
*) Zeroing the entire block before setting the symlink in the case
where it needs to use an external data block makes it a lot easier to write the regression test.
Quoted 2 lines
So here's the patch I needed to apply on top of your submission....
Ted,
I apologize for not getting to the test case, I meant to, and was still meaning to. I was pulled away on a number of other tasks, took a family vacation etc. I figured I was the only one that cared and it would be me who had to pay the price if things changed while I delayed.
THANK YOU, THANK YOU! I really appreciate you writing the test cases and fixing up the remaining issues with the patch.
This should now allow us to work with a debugfs script to validate this tooling to populate filesystem images. Once we have done that, we'll want to look at pushing some things (like file copy wrappers) from debugfs into libext2fs and implement the -i (initial dir) option we discused for mke2fs.
We'll do our validation and then resurface here.
Thanks again!
--
Darren
PATCH v2 2/3 debugfs: Add symlink command
In reply to Darren HartAdd 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.
--- debugfs/debug_cmds.ct | 3 +++ debugfs/debugfs.8.in | 3 +++ debugfs/debugfs.c | 43 +++++++++++++++++++++++++++++++++++++++++++ debugfs/debugfs.h | 1 + debugfs/dump.c | 2 +- 5 files changed, 51 insertions(+), 1 deletion(-)
debugfs/debug_cmds.ct +3 -0
@@ -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;
debugfs/debugfs.8.in +3 -0
@@ -469,6 +469,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
debugfs/debugfs.c +43 -0
49 lines not on this page · raw message
debugfs/debugfs.h +1 -0
@@ -136,6 +136,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);
debugfs/dump.c +1 -1
@@ -285,7 +285,7 @@ static void rdump_inode(ext2_ino_t ino, struct ext2_inode *inode,fix_perms ("rdump" , inode,-1 , fullname); } -/* else do nothing (don't dump device files, sockets, fifos, etc.) */ +/* else do nothing (don't dump device files, sockets, fifos, symlinks, etc.) */ errout:free (fullname);
Signature · 1 line
1.7.11.7
PATCH v2 3/3 libext2fs: Remove obsolete redefinition of EXT2_FT_DIR
In reply to Darren HartThis was needed a decade or more ago, back when we included ext2_fs.h from the kernel headers in /usr/include/linux.
--- lib/ext2fs/mkdir.c | 4 ---- 1 file changed, 4 deletions(-)
lib/ext2fs/mkdir.c +0 -3
@@ -27,10 +27,6 @@#include "ext2_fs.h" #include "ext2fs.h" -#ifndef EXT2_FT_DIR -#define EXT2_FT_DIR 2 -#endif
Quoted 4 lines · Darren Hart
The following series adds symlink support the libext2fs and adds the command to debugfs. Basic testing demonstrates functional duplication of a small test directory including fastlinks and slowlinks in both the root and a single subdirectory.
One thing I'd really appreciate is if you could write a regression test for this new code. You can use tests/d_loaddump and tests/f_dup4/script as a model; I'd suggest calling it d_symlink, and it would be good if it created a short symlink and a long symlink, and that the script verified that you get the expected output when you stat the small and long symlinks using debugfs. Then run e2fsck on the file system and make sure the file system is consistent.
Note the use of the debugfs commands:
set_current_time 200704102100
set_super_value lastcheck 0
set_super_value hash_seed null
set_super_value mkfs_time 0
and the environment variable:
E2FSCK_TIME=200704102100
in f_dup4's script. These are used to control various variable (random or time-specific) values such that so that you can use a simple comparison of the output of programs such as debugfs, mke2fs, and dumpe2fs using "diff".
Thanks again!!
- Ted
P.S. Actually, while you're at it, if you could also have the script create some block and character device files using the debugfs mknod command, and perhaps call the test d_create_spec_files instead ofd_symlink, that would be great! (Since I don't think those functions
currently any good test coverage.)
Quoted 32 lines · Theodore Ts'o
Quoted 4 lines · Darren Hart
The following series adds symlink support the libext2fs and adds the command to debugfs. Basic testing demonstrates functional duplication of a small test directory including fastlinks and slowlinks in both the root and a single subdirectory.
One thing I'd really appreciate is if you could write a regression test for this new code. You can use tests/d_loaddump and tests/f_dup4/script as a model; I'd suggest calling it
d_symlink, and it would be good if it created a short symlink and a long symlink, and that the script verified that you get the expected output when you stat the small and long symlinks using debugfs. Then run e2fsck on the file system and make sure the file system is consistent.Note the use of the debugfs commands:
set_current_time200704102100
set_super_valuelastcheck 0
set_super_valuehash_seednull
set_super_valuemkfs_time0and the environment variable:
E2FSCK_TIME=200704102100in f_dup4's script. These are used to control various variable (random or time-specific) values such that so that you can use a simple comparison of the output of programs such as debugfs, mke2fs, and dumpe2fs using "diff".
Thanks again!!
Quoted 7 lines
- Ted
P.S. Actually, while you're at it, if you could also have the script create some block and character device files using the debugfs mknod command, and perhaps call the testd_create_spec_filesinstead ofd_symlink, that would be great! (Since I don't think those functions
currently any good test coverage.)
Ah, great. I'm all for built-in tests. I'll get on it next week.
Thanks Ted.
--
Darren Hart
Intel Open Source Technology Center