Using tar to access files

Pavel Pisa pisa at cmp.felk.cvut.cz
Mon Jul 13 15:26:26 UTC 2015


Hello Sujay Raj,


On Tuesday 30 of June 2015 06:39:28 Sujay Raj wrote:
> I need to access configurations files the for web server I am porting to
> rtems.
>
> I create a tar archive , that contains the required folders and files ,
> convert it into c source using rtems-bin2c , ( a header file and a c source
> ) and link them with my project.
>
> In the init, I call
>
> sc = Untar_FromMemory((void *)TARFILE_START, (size_t)TARFILE_SIZE);
>
> where TARFILE_START is the macro with the name of the array , TARFILE_SIZE
> is the size of the array.
>
> But when I run the program, I get errors of the form
>
> "Untar: failed to create file <folder>/<filename>"
>

I have noticed and reported similar problem and workaround some
time ago. Problem is, that Untar_FromMemory() function fails
when it reaches a directory entry in a TAR file and given
directory already exists. It fails even for existing
top level directory which has to exists in RTEMS runing
system and are packed by TAR by default.

My fix is not ideal. Other (more generic option) is to use
stat(const char *path, struct stat *buf) with check
that target is already existing direcory. But using stat()
in really minimal application can lead to unneeded overhead.
Other option is to ignore directory create errors completelly
but I do not like something like that in RT system.

There is alternative way to untar file by other RTEMS functions
but we use Untar_FromMemory() in more projects. If there is no
objection or opinion for other solution, I prepare and check
patch with stat().


From 4ce027b21cfde5bc6143d51d244345e05dd85cd4 Mon Sep 17 00:00:00 2001
Message-Id: <4ce027b21cfde5bc6143d51d244345e05dd85cd4.1436800331.git.ppisa at pikron.com>
From: Pavel Pisa <ppisa at pikron.com>
Date: Mon, 31 Mar 2014 00:57:12 +0200
Subject: [PATCH] untar: workaround for fail on top level directory existence.
To: rtems-devel at rtems.org

Signed-off-by: Pavel Pisa <ppisa at pikron.com>
---
 cpukit/libmisc/untar/untar.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/cpukit/libmisc/untar/untar.c b/cpukit/libmisc/untar/untar.c
index aed8fed..498fa12 100644
--- a/cpukit/libmisc/untar/untar.c
+++ b/cpukit/libmisc/untar/untar.c
@@ -203,6 +203,8 @@ Untar_FromMemory(
       }
     } else if (linkflag == DIRTYPE) {
       if ( mkdir(fname, S_IRWXU | S_IRWXG | S_IRWXO) != 0 ) {
+        if ( !strcmp(fname, "/") || !strcmp(fname, "./"))
+          continue;
         printk("Untar: failed to create directory %s\n", fname);
         retval = UNTAR_FAIL;
         break;
-- 
1.9.1


More information about the devel mailing list