[rtems commit] Teach rtems_tarfs_load() about symlinks
Sebastian Huber
sebh at rtems.org
Thu Dec 11 07:12:50 UTC 2014
Module: rtems
Branch: master
Commit: 9d9c42601ac54a316a5a8656ebc083c401da07e2
Changeset: http://git.rtems.org/rtems/commit/?id=9d9c42601ac54a316a5a8656ebc083c401da07e2
Author: Nick Withers <nick.withers at anu.edu.au>
Date: Fri Mar 7 14:23:30 2014 +1100
Teach rtems_tarfs_load() about symlinks
---
cpukit/libfs/src/imfs/imfs_load_tar.c | 17 +++++++++++++++++
testsuites/libtests/tar02/init.c | 2 --
testsuites/libtests/tar02/tar02.scn | 10 ++++++++--
3 files changed, 25 insertions(+), 4 deletions(-)
diff --git a/cpukit/libfs/src/imfs/imfs_load_tar.c b/cpukit/libfs/src/imfs/imfs_load_tar.c
index 5b6f545..1ef0e0b 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 cfeda1b..29bc529 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 ***
More information about the vc
mailing list