On Wed, 2014-12-10 at 16:34 +1100, Nick Withers wrote:
> On Wed, 2014-12-03 at 08:23 +0100, Sebastian Huber wrote:
> > 
> > On 03/12/14 07:07, Nick Withers wrote:
> > 
> > > Anyone be interested in committing this?
> > > 
> > > On Fri, 2014-03-07 at 14:37 +1100, Nick Withers wrote:
> > > > > Hi all,
> > > > > 
> > > > > The attached patch teaches rtems_tarfs_load() about symlinks, as well 
> > > > > as
> > > > > making it fail if it encounters an unsupported tar file entry type
> > > > > (e.g., hard links) rather than silently ignoring the 512 B block.
> > > > > 
> > > > > It tries to be consistent with the existing code which doesn't e.g.
> > > > > check tar string field NUL termination or printf() on error.
> > > -- Nick Withers Embedded Systems Programmer Department of Nuclear
> > > Physics, Research School of Physics and Engineering The Australian
> > > National University (CRICOS: 00120C) 
> > > 
> > > rtems_tarfs_load_symlinks.patch 
> > > >From 165b5fd7e0c2d5042a69d209a360522f80697d71 Mon Sep 17 00:00:00 2001
> > > From: Nick Withers <nick.with...@anu.edu.au>
> > > Date: Fri, 7 Mar 2014 14:23:30 +1100
> > > Subject: [PATCH] Teach rtems_tarfs_load() about symlinks
> > > 
> > > rtems_tarfs_load() will now also fail if it encounters unsupported tar 
> > > file entry types (e.g., hard links)
> > 
> > I am not sure if this should now fail if it encounters an unsupported
> > tar file entry.  This may crash applications that worked for a long
> > time.
> 
> Here's a version that doesn't fail like this.

Sorry - I'd left an out-of-date commit message.

> <Discussion>
> Personally, I'd much rather it did (for example, as I recall, there's
> nothing to say that an unsupported entry only occupies one block, so you
> could be stuffed anyway) and would think it would be an obvious failure
> if you're checking the return code. If you're not, I have no sympathy
> for you :-P
> 
> I also think that people porting an existing app to RTEMS 4.11 should be
> a) not releasing until RTEMS 4.11 itself is finalised OR accepting the
> potential for breakage working off off the moving HEAD target and b)
> testing thoroughly.
> 
> But hey - I don't have to deal with upset users!
> </Discussion>

-- 
Nick Withers

Embedded Systems Programmer
Department of Nuclear Physics, Research School of Physics and Engineering
The Australian National University (CRICOS: 00120C)
>From 165b5fd7e0c2d5042a69d209a360522f80697d71 Mon Sep 17 00:00:00 2001
From: Nick Withers <nick.with...@anu.edu.au>
Date: Fri, 7 Mar 2014 14:23:30 +1100
Subject: [PATCH] Teach rtems_tarfs_load() about symlinks
---
 cpukit/libfs/src/imfs/imfs_load_tar.c | 19 +++++++++++++++++++
 testsuites/libtests/tar02/init.c      |  3 ---
 testsuites/libtests/tar02/tar02.scn   | 10 ++++++++--
 3 files changed, 27 insertions(+), 5 deletions(-)

diff --git a/cpukit/libfs/src/imfs/imfs_load_tar.c b/cpukit/libfs/src/imfs/imfs_load_tar.c
index fd47ec2..22bc5bf 100644
--- a/cpukit/libfs/src/imfs/imfs_load_tar.c
+++ b/cpukit/libfs/src/imfs/imfs_load_tar.c
@@ -24,6 +24,7 @@
 #include <sys/stat.h>
 #include <string.h>
 #include <tar.h>
+#include <unistd.h>
 
 #include <rtems/untar.h>
 
@@ -96,6 +97,7 @@ int rtems_tarfs_load(
      * Generate an IMFS node depending on the file type.
      * - For directories, just create directories as usual.  IMFS
      *   will take care of the rest.
+     * - For symbolic links, create as usual
      * - For files, create a file node with special tarfs properties.
      */
     if (linkflag == DIRTYPE) {
@@ -136,6 +138,21 @@ int rtems_tarfs_load(
       nblocks = (((file_size) + 511) & ~511) / 512;
       offset += 512 * nblocks;
     }
+    /*
+     * Create a symbolic link
+     */
+    else if (linkflag == SYMTYPE) {
+      const char *linkto = hdr_ptr + 157;
+      int len;
+
+      strncpy(full_filename, mountpoint, 255);
+      if (full_filename[(len=strlen(full_filename))-1] != '/')
+        strcat(full_filename, "/");
+      ++len;
+      strncat(full_filename, filename, 256-len-1);
+
+      rv = symlink(linkto, full_filename);
+    }
   }
 
   rtems_filesystem_location_free( &rootloc );
diff --git a/testsuites/libtests/tar02/init.c b/testsuites/libtests/tar02/init.c
index 4f8a583..a10c129 100644
--- a/testsuites/libtests/tar02/init.c
+++ b/testsuites/libtests/tar02/init.c
@@ -57,10 +57,8 @@ void test_tarfs_load(void)
   test_cat( "/home/test_file", 0, 0 );
   
   /******************/
-#if 0
   printf( "========= /symlink =========\n" );
   test_cat( "/symlink", 0, 0 );
-#endif
 }
 
 rtems_task Init(
diff --git a/testsuites/libtests/tar02/tar02.scn b/testsuites/libtests/tar02/tar02.scn
index 3b4d1bc..f4ba9ce 100644
--- a/testsuites/libtests/tar02/tar02.scn
+++ b/testsuites/libtests/tar02/tar02.scn
@@ -4,12 +4,18 @@ Loading tarfs image ... successful
 (0)This is a test of loading an RTEMS filesystem from an
 initial tar image.
 
-*** Skipping symlink -- NOT CURRENTLY SUPPORTED ***
+========= /symlink =========
+(0)This is a test of loading an RTEMS filesystem from an
+initial tar image.
+
 *************** Dump of Entire IMFS ***************
 /
 ....dev/
+........ttyS0 (device 0, 0)
 ........console (device 0, 0)
+........ttyS1 (device 0, 1)
 ....home/
-........test_file (file 73 0x12022c)
+........test_file (file 73 0x390f8)
+....symlink links not printed
 ***************      End of Dump       ***************
 *** END OF TAR02 TEST ***
-- 
1.8.5.4

_______________________________________________
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel

Reply via email to