summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRalf Corsepius <ralf.corsepius@rtems.org>2005-02-07 13:25:14 +0000
committerRalf Corsepius <ralf.corsepius@rtems.org>2005-02-07 13:25:14 +0000
commit1996aee7f0c6922c6c12f1185e66d3bb3c6ea359 (patch)
treea3223ce8cbac5a04e065f568ed0a4268b5edee26
parent2005-02-07 Ralf Corsepius <ralf.corsepius@rtems.org> (diff)
downloadrtems-1996aee7f0c6922c6c12f1185e66d3bb3c6ea359.tar.bz2
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.
Diffstat (limited to '')
-rw-r--r--cpukit/ChangeLog6
-rw-r--r--cpukit/libfs/src/imfs/imfs.h8
-rw-r--r--cpukit/libfs/src/imfs/imfs_load_tar.c83
-rw-r--r--cpukit/libmisc/untar/untar.c87
-rw-r--r--cpukit/libmisc/untar/untar.h16
5 files changed, 76 insertions, 124 deletions
diff --git a/cpukit/ChangeLog b/cpukit/ChangeLog
index ed615e4766..0e546c3f6f 100644
--- a/cpukit/ChangeLog
+++ b/cpukit/ChangeLog
@@ -1,5 +1,11 @@
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>
+
* Makefile.am: Add include/rtems/tar.h.
Merge-in header rules from libmisc/Makefile.am
* libmisc/Makefile.am: Remove header rules.
diff --git a/cpukit/libfs/src/imfs/imfs.h b/cpukit/libfs/src/imfs/imfs.h
index 6e02734d81..984a4b3736 100644
--- a/cpukit/libfs/src/imfs/imfs.h
+++ b/cpukit/libfs/src/imfs/imfs.h
@@ -84,7 +84,7 @@ typedef struct {
#define IMFS_MEMFILE_BLOCK_SLOTS \
(IMFS_MEMFILE_BYTES_PER_BLOCK / sizeof(void *))
-typedef unsigned char * block_p;
+typedef char * block_p;
typedef block_p *block_ptr;
typedef struct {
@@ -268,9 +268,9 @@ int IMFS_fsunmount(
);
int rtems_tarfs_load(
- char *mountpoint,
- unsigned char *addr,
- unsigned long length
+ char *mountpoint,
+ char *tar_image,
+ size_t tar_size
);
/*
diff --git a/cpukit/libfs/src/imfs/imfs_load_tar.c b/cpukit/libfs/src/imfs/imfs_load_tar.c
index fd9d226003..8e47881930 100644
--- a/cpukit/libfs/src/imfs/imfs_load_tar.c
+++ b/cpukit/libfs/src/imfs/imfs_load_tar.c
@@ -24,7 +24,7 @@
#include <rtems/libio_.h>
#include <rtems/chain.h>
#include <rtems/imfs.h>
-
+#include <rtems/untar.h>
/**************************************************************************
* TAR file format:
@@ -56,23 +56,10 @@
* sum += 0xFF & header[i];
*************************************************************************/
-#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);
-
/**************************************************************************
* rtems_tarfs_load
*
@@ -86,12 +73,12 @@ static int compute_tar_header_checksum(char *bufr);
*************************************************************************/
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];
int hdr_chksum;
@@ -132,11 +119,11 @@ rtems_tarfs_load(char *mountpoint,
filename[MAX_NAME_FIELD_SIZE] = '\0';
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;
/******************************************************************
@@ -145,7 +132,7 @@ rtems_tarfs_load(char *mountpoint,
* will take care of the rest.
* - For files, create a file node with special tarfs properties.
*****************************************************************/
- if (linkflag == LF_DIR)
+ if (linkflag == DIRTYPE)
{
strcpy(full_filename, mountpoint);
if (full_filename[strlen(full_filename)-1] != '/')
@@ -156,7 +143,7 @@ rtems_tarfs_load(char *mountpoint,
/******************************************************************
* Create a LINEAR_FILE node if no user write permission.
*****************************************************************/
- else if ((linkflag == LF_NORMAL) &&
+ else if ((linkflag == REGTYPE) &&
((file_mode & 0200) == 0000))
{
const char *name;
@@ -178,7 +165,7 @@ rtems_tarfs_load(char *mountpoint,
/******************************************************************
* Create a regular MEMORY_FILE if write permission exists.
*****************************************************************/
- else if ((linkflag == LF_NORMAL) &&
+ else if ((linkflag == REGTYPE) &&
((file_mode & 0200) == 0200))
{
int fd;
@@ -210,51 +197,3 @@ rtems_tarfs_load(char *mountpoint,
return(status);
}
-/**************************************************************************
- * 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);
-}
diff --git a/cpukit/libmisc/untar/untar.c b/cpukit/libmisc/untar/untar.c
index 441f250d46..1ab2d798b4 100644
--- a/cpukit/libmisc/untar/untar.c
+++ b/cpukit/libmisc/untar/untar.c
@@ -23,7 +23,7 @@
#include <unistd.h>
#include <sys/stat.h>
#include <fcntl.h>
-#include "untar.h"
+#include <rtems/untar.h>
/**************************************************************************
@@ -56,16 +56,6 @@
* sum += 0xFF & header[i];
*************************************************************************/
-#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))
@@ -75,10 +65,10 @@
* 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)
+unsigned long
+_rtems_octal2ulong(const char *octascii, size_t len)
{
- int i;
+ size_t i;
unsigned long num;
unsigned long mult;
@@ -162,26 +152,16 @@ Untar_FromMemory(char *tar_buf, size_t size)
fname[MAX_NAME_FIELD_SIZE] = '\0';
linkflag = bufr[156];
- file_size = octal2ulong(&bufr[124], 12);
+ file_size = _rtems_octal2ulong(&bufr[124], 12);
/******************************************************************
* 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.
******************************************************************/
- 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)
{
retval = UNTAR_INVALID_CHECKSUM;
@@ -193,13 +173,13 @@ Untar_FromMemory(char *tar_buf, size_t size)
* We've decoded the header, now figure out what it contains and
* do something with it.
*****************************************************************/
- if (linkflag == LF_SYMLINK)
+ if (linkflag == SYMTYPE)
{
strncpy(linkname, &bufr[157], MAX_NAME_FIELD_SIZE);
linkname[MAX_NAME_FIELD_SIZE] = '\0';
symlink(linkname, fname);
}
- else if (linkflag == LF_NORMAL)
+ else if (linkflag == REGTYPE)
{
nblocks = (((file_size) + 511) & ~511) / 512;
if ((fp = fopen(fname, "w")) == NULL)
@@ -231,7 +211,7 @@ Untar_FromMemory(char *tar_buf, size_t size)
fclose(fp);
}
}
- else if (linkflag == LF_DIR)
+ else if (linkflag == DIRTYPE)
{
mkdir(fname, S_IRWXU | S_IRWXG | S_IRWXO);
}
@@ -309,26 +289,16 @@ Untar_FromFile(char *tar_name)
fname[MAX_NAME_FIELD_SIZE] = '\0';
linkflag = bufr[156];
- size = octal2ulong(&bufr[124], 12);
+ size = _rtems_octal2ulong(&bufr[124], 12);
/******************************************************************
* 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.
******************************************************************/
- 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)
{
retval = UNTAR_INVALID_CHECKSUM;
@@ -339,13 +309,13 @@ Untar_FromFile(char *tar_name)
* We've decoded the header, now figure out what it contains and
* do something with it.
*****************************************************************/
- if (linkflag == LF_SYMLINK)
+ if (linkflag == SYMTYPE)
{
strncpy(linkname, &bufr[157], MAX_NAME_FIELD_SIZE);
linkname[MAX_NAME_FIELD_SIZE] = '\0';
symlink(linkname,fname);
}
- else if (linkflag == LF_NORMAL)
+ else if (linkflag == REGTYPE)
{
int out_fd;
@@ -373,7 +343,7 @@ Untar_FromFile(char *tar_name)
close(out_fd);
}
}
- else if (linkflag == LF_DIR)
+ else if (linkflag == DIRTYPE)
{
mkdir(fname, S_IRWXU | S_IRWXG | S_IRWXO);
}
@@ -383,3 +353,24 @@ Untar_FromFile(char *tar_name)
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);
+}
diff --git a/cpukit/libmisc/untar/untar.h b/cpukit/libmisc/untar/untar.h
index e3f4a59555..64aae14163 100644
--- a/cpukit/libmisc/untar/untar.h
+++ b/cpukit/libmisc/untar/untar.h
@@ -12,6 +12,7 @@
#define __UNTAR_H__
#include <stddef.h>
+#include <rtems/tar.h>
#ifdef __cplusplus
extern "C" {
@@ -26,6 +27,21 @@ extern "C" {
int Untar_FromMemory(char *tar_buf, size_t size);
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
}
#endif