Index: cpukit/ChangeLog
===================================================================
--- cpukit/ChangeLog	(revision 9d0e65ed92ad0fd928b7b7dc900f88cd5f203208)
+++ cpukit/ChangeLog	(revision 1996aee7f0c6922c6c12f1185e66d3bb3c6ea359)
@@ -1,2 +1,8 @@
+2005-02-07	Ralf Corsepius <ralf.corsepius@rtems.org>
+
+	* libfs/src/imfs/imfs.h, libfs/src/imfs/imfs_load_tar.c,
+	libmisc/untar/untar.c, libmisc/untar/untar.h:
+	Various generalizations and fixes.
+
 2005-02-07	Ralf Corsepius <ralf.corsepius@rtems.org>
 
Index: cpukit/libfs/src/imfs/imfs.h
===================================================================
--- cpukit/libfs/src/imfs/imfs.h	(revision 9d0e65ed92ad0fd928b7b7dc900f88cd5f203208)
+++ cpukit/libfs/src/imfs/imfs.h	(revision 1996aee7f0c6922c6c12f1185e66d3bb3c6ea359)
@@ -85,5 +85,5 @@
   (IMFS_MEMFILE_BYTES_PER_BLOCK / sizeof(void *))
 
-typedef unsigned char * block_p;
+typedef char * block_p;
 typedef block_p *block_ptr;
 
@@ -269,7 +269,7 @@
 
 int rtems_tarfs_load(
-   char          *mountpoint,
-   unsigned char *addr,
-   unsigned long length
+   char         *mountpoint,
+   char         *tar_image,
+   size_t        tar_size
 );
 
Index: cpukit/libfs/src/imfs/imfs_load_tar.c
===================================================================
--- cpukit/libfs/src/imfs/imfs_load_tar.c	(revision 9d0e65ed92ad0fd928b7b7dc900f88cd5f203208)
+++ cpukit/libfs/src/imfs/imfs_load_tar.c	(revision 1996aee7f0c6922c6c12f1185e66d3bb3c6ea359)
@@ -25,5 +25,5 @@
 #include <rtems/chain.h>
 #include <rtems/imfs.h>
-
+#include <rtems/untar.h>
 
 /**************************************************************************
@@ -57,20 +57,7 @@
  *************************************************************************/
 
-#define LF_OLDNORMAL  '\0'     /* Normal disk file, Unix compatible */
-#define LF_NORMAL     '0'      /* Normal disk file                  */
-#define LF_LINK       '1'      /* Link to previously dumped file    */
-#define LF_SYMLINK    '2'      /* Symbolic link                     */
-#define LF_CHR        '3'      /* Character special file            */
-#define LF_BLK        '4'      /* Block special file                */
-#define LF_DIR        '5'      /* Directory                         */
-#define LF_FIFO       '6'      /* FIFO special file                 */
-#define LF_CONFIG     '7'      /* Contiguous file                   */
-
 #define MAX_NAME_FIELD_SIZE      99
 
 #define MIN(a,b)   ((a)>(b)?(b):(a))
-
-static unsigned long octal2ulong(char *octascii, int len);
-static int compute_tar_header_checksum(char *bufr);
 
 /**************************************************************************
@@ -87,10 +74,10 @@
 int
 rtems_tarfs_load(char *mountpoint,
-                 unsigned char *tar_image,
-                 unsigned long tar_size)
+                 char *tar_image,
+                 size_t tar_size)
 {
    rtems_filesystem_location_info_t root_loc;
    rtems_filesystem_location_info_t loc;
-   char            *hdr_ptr;
+   const char     *hdr_ptr;
    char            filename[100];
    char            full_filename[256];
@@ -133,9 +120,9 @@
 
       linkflag   = hdr_ptr[156];
-      file_mode  = octal2ulong(&hdr_ptr[100], 8);
-      file_size  = octal2ulong(&hdr_ptr[124], 12);
-      hdr_chksum = (int)octal2ulong(&hdr_ptr[148], 8);
+      file_mode  = _rtems_octal2ulong(&hdr_ptr[100], 8);
+      file_size  = _rtems_octal2ulong(&hdr_ptr[124], 12);
+      hdr_chksum = _rtems_octal2ulong(&hdr_ptr[148], 8);
 
-      if (compute_tar_header_checksum(hdr_ptr) != hdr_chksum)
+      if (_rtems_tar_header_checksum(hdr_ptr) != hdr_chksum)
          break;
 
@@ -146,5 +133,5 @@
        * - For files, create a file node with special tarfs properties.
        *****************************************************************/
-      if (linkflag == LF_DIR)
+      if (linkflag == DIRTYPE)
       {
          strcpy(full_filename, mountpoint);
@@ -157,5 +144,5 @@
        * Create a LINEAR_FILE node if no user write permission.
        *****************************************************************/
-      else if ((linkflag == LF_NORMAL) &&
+      else if ((linkflag == REGTYPE) &&
                ((file_mode & 0200) == 0000))
       {
@@ -179,5 +166,5 @@
        * Create a regular MEMORY_FILE if write permission exists.
        *****************************************************************/
-      else if ((linkflag == LF_NORMAL) &&
+      else if ((linkflag == REGTYPE) &&
                ((file_mode & 0200) == 0200))
       {
@@ -211,50 +198,2 @@
 }
 
-/**************************************************************************
- * This converts octal ASCII number representations into an
- * unsigned long.  Only support 32-bit numbers for now.
- *************************************************************************/
-static unsigned long
-octal2ulong(char *octascii, int len)
-{
-   int           i;
-   unsigned long num;
-   unsigned long mult;
-
-   num = 0;
-   mult = 1;
-   for (i=len-1; i>=0; i--)
-   {
-      if (octascii[i] < '0')
-         continue;
-      if (octascii[i] > '9')
-         continue;
-
-      num  += mult*((unsigned long)(octascii[i] - '0'));
-      mult *= 8;
-   }
-   return(num);
-}
-
-
-/************************************************************************
- * Compute the TAR checksum and check with the value in
- * the archive.  The checksum is computed over the entire
- * header, but the checksum field is substituted with blanks.
- ************************************************************************/
-static int
-compute_tar_header_checksum(char *bufr)
-{
-   int  i, sum;
-
-
-   sum = 0;
-   for (i=0; i<512; i++)
-   {
-      if ((i >= 148) && (i < 156))
-         sum += 0xff & ' ';
-      else
-         sum += 0xff & bufr[i];
-   }
-   return(sum);
-}
Index: cpukit/libmisc/untar/untar.c
===================================================================
--- cpukit/libmisc/untar/untar.c	(revision 9d0e65ed92ad0fd928b7b7dc900f88cd5f203208)
+++ cpukit/libmisc/untar/untar.c	(revision 1996aee7f0c6922c6c12f1185e66d3bb3c6ea359)
@@ -24,5 +24,5 @@
 #include <sys/stat.h>
 #include <fcntl.h>
-#include "untar.h"
+#include <rtems/untar.h>
 
 
@@ -57,14 +57,4 @@
  *************************************************************************/
 
-#define LF_OLDNORMAL  '\0'     /* Normal disk file, Unix compatible */
-#define LF_NORMAL     '0'      /* Normal disk file                  */
-#define LF_LINK       '1'      /* Link to previously dumped file    */
-#define LF_SYMLINK    '2'      /* Symbolic link                     */
-#define LF_CHR        '3'      /* Character special file            */
-#define LF_BLK        '4'      /* Block special file                */
-#define LF_DIR        '5'      /* Directory                         */
-#define LF_FIFO       '6'      /* FIFO special file                 */
-#define LF_CONFIG     '7'      /* Contiguous file                   */
-
 #define MAX_NAME_FIELD_SIZE      99
 
@@ -76,8 +66,8 @@
  * unsigned long.  Only support 32-bit numbers for now.
  *************************************************************************/
-static unsigned long
-octal2ulong(char *octascii, int len)
+unsigned long
+_rtems_octal2ulong(const char *octascii, size_t len)
 {
-   int           i;
+   size_t        i;
    unsigned long num;
    unsigned long mult;
@@ -163,5 +153,5 @@
 
       linkflag   = bufr[156];
-      file_size  = octal2ulong(&bufr[124], 12);
+      file_size  = _rtems_octal2ulong(&bufr[124], 12);
 
       /******************************************************************
@@ -170,17 +160,7 @@
        * header, but the checksum field is substituted with blanks.
        ******************************************************************/
-      hdr_chksum = octal2ulong(&bufr[148], 8);
-      sum = 0;
-      for (i=0; i<512; i++)
-      {
-         if ((i >= 148) && (i < 156))
-         {
-            sum += 0xff & ' ';
-         }
-         else
-         {
-            sum += 0xff & bufr[i];
-         }
-      }
+      hdr_chksum = _rtems_octal2ulong(&bufr[148], 8);
+      sum = _rtems_tar_header_checksum(bufr);
+
       if (sum != hdr_chksum)
       {
@@ -194,5 +174,5 @@
        * do something with it.
        *****************************************************************/
-      if (linkflag == LF_SYMLINK)
+      if (linkflag == SYMTYPE)
       {
          strncpy(linkname, &bufr[157], MAX_NAME_FIELD_SIZE);
@@ -200,5 +180,5 @@
          symlink(linkname, fname);
       }
-      else if (linkflag == LF_NORMAL)
+      else if (linkflag == REGTYPE)
       {
          nblocks = (((file_size) + 511) & ~511) / 512;
@@ -232,5 +212,5 @@
          }
       }
-      else if (linkflag == LF_DIR)
+      else if (linkflag == DIRTYPE)
       {
          mkdir(fname, S_IRWXU | S_IRWXG | S_IRWXO);
@@ -310,5 +290,5 @@
 
       linkflag   = bufr[156];
-      size       = octal2ulong(&bufr[124], 12);
+      size       = _rtems_octal2ulong(&bufr[124], 12);
 
       /******************************************************************
@@ -317,17 +297,7 @@
        * header, but the checksum field is substituted with blanks.
        ******************************************************************/
-      hdr_chksum = (int)octal2ulong(&bufr[148], 8);
-      sum = 0;
-      for (i=0; i<512; i++)
-      {
-         if ((i >= 148) && (i < 156))
-         {
-            sum += 0xff & ' ';
-         }
-         else
-         {
-            sum += 0xff & bufr[i];
-         }
-      }
+      hdr_chksum = _rtems_octal2ulong(&bufr[148], 8);
+      sum = _rtems_tar_header_checksum(bufr);
+
       if (sum != hdr_chksum)
       {
@@ -340,5 +310,5 @@
        * do something with it.
        *****************************************************************/
-      if (linkflag == LF_SYMLINK)
+      if (linkflag == SYMTYPE)
       {
          strncpy(linkname, &bufr[157], MAX_NAME_FIELD_SIZE);
@@ -346,5 +316,5 @@
          symlink(linkname,fname);
       }
-      else if (linkflag == LF_NORMAL)
+      else if (linkflag == REGTYPE)
       {
          int out_fd;
@@ -374,5 +344,5 @@
          }
       }
-      else if (linkflag == LF_DIR)
+      else if (linkflag == DIRTYPE)
       {
          mkdir(fname, S_IRWXU | S_IRWXG | S_IRWXO);
@@ -384,2 +354,23 @@
    return(retval);
 }
+
+/************************************************************************
+ * Compute the TAR checksum and check with the value in
+ * the archive.  The checksum is computed over the entire
+ * header, but the checksum field is substituted with blanks.
+ ************************************************************************/
+int
+_rtems_tar_header_checksum(const char *bufr)
+{
+   int  i, sum;
+
+   sum = 0;
+   for (i=0; i<512; i++)
+   {
+      if ((i >= 148) && (i < 156))
+         sum += 0xff & ' ';
+      else
+         sum += 0xff & bufr[i];
+   }
+   return(sum);
+}
Index: cpukit/libmisc/untar/untar.h
===================================================================
--- cpukit/libmisc/untar/untar.h	(revision 9d0e65ed92ad0fd928b7b7dc900f88cd5f203208)
+++ cpukit/libmisc/untar/untar.h	(revision 1996aee7f0c6922c6c12f1185e66d3bb3c6ea359)
@@ -13,4 +13,5 @@
 
 #include <stddef.h>
+#include <rtems/tar.h>
 
 #ifdef __cplusplus
@@ -27,4 +28,19 @@
 int Untar_FromFile(char *tar_name);
 
+/**************************************************************************
+ * This converts octal ASCII number representations into an
+ * unsigned long.  Only support 32-bit numbers for now.
+ *************************************************************************/
+extern unsigned long
+_rtems_octal2ulong(const char *octascii, size_t len);
+
+/************************************************************************
+ * Compute the TAR checksum and check with the value in
+ * the archive.  The checksum is computed over the entire
+ * header, but the checksum field is substituted with blanks.
+ ************************************************************************/
+extern int
+_rtems_tar_header_checksum(const char *bufr);
+
 #ifdef __cplusplus
 }
