From d19415873fb6b6197d77916758593c9897a0cb69 Mon Sep 17 00:00:00 2001 From: Joel Sherrill Date: Fri, 12 Jan 2001 13:44:12 +0000 Subject: 2001-01-12 Jake Janovetz * src/imfs/imfs.h, src/imfs/imfs_creat.c, src/imfs/imfs_debug.c, src/imfs/imfs_eval.c, src/imfs/imfs_fchmod.c, src/imfs/imfs_handlers_memfile.c, src/imfs/imfs_init.c, src/imfs/imfs_initsupp.c, src/imfs/imfs_stat.c, src/imfs/memfile.c, src/imfs/miniimfs_init.c: Final developmental update to "tarfs". When rtems_tarfs_load() is called, it checks the permissions on each file. If there is write permission, it just creates a standard file using "creat()" and therefore, uses the IMFS MEMORY_FILE. If there is no write permission, it creates a LINEAR_FILE node with the appropriate properties. If the permission is ever changed to writeable, IMFS_fchmod converts it to a regular memory file. --- c/src/libfs/src/imfs/imfs_load_tar.c | 62 ++++++++++++++++++++++++++++-------- 1 file changed, 49 insertions(+), 13 deletions(-) (limited to 'c/src/libfs/src/imfs/imfs_load_tar.c') diff --git a/c/src/libfs/src/imfs/imfs_load_tar.c b/c/src/libfs/src/imfs/imfs_load_tar.c index 7dc7df8a61..ede0c6ad89 100644 --- a/c/src/libfs/src/imfs/imfs_load_tar.c +++ b/c/src/libfs/src/imfs/imfs_load_tar.c @@ -4,13 +4,10 @@ * Directories from the TAR file are created as usual in the IMFS. * File entries are created as IMFS_LINEAR_FILE nodes with their nods * pointing to addresses in the TAR image. - * - * $Id$ - * *************************************************************************/ #include -#include +#include #include #include #include @@ -110,9 +107,9 @@ compute_tar_header_checksum(char *bufr) /************************************************************************** - * rtems_tarfs_mount + * rtems_tarfs_load * - * Here we create the mountpoint directory and mount the tarfs at + * Here we create the mountpoint directory and load the tarfs at * that node. Once the IMFS has been mounted, we work through the * tar image and perform as follows: * - For directories, simply call mkdir(). The IMFS creates nodes as @@ -121,9 +118,9 @@ compute_tar_header_checksum(char *bufr) * create_node. *************************************************************************/ int -rtems_tarfs_mount(char *mountpoint, - unsigned char *tar_image, - unsigned long tar_size) +rtems_tarfs_load(char *mountpoint, + unsigned char *tar_image, + unsigned long tar_size) { rtems_filesystem_location_info_t root_loc; rtems_filesystem_location_info_t loc; @@ -133,6 +130,7 @@ rtems_tarfs_mount(char *mountpoint, int hdr_chksum; unsigned char linkflag; unsigned long file_size; + unsigned long file_mode; int offset; unsigned long nblocks; IMFS_jnode_t *node; @@ -143,6 +141,9 @@ rtems_tarfs_mount(char *mountpoint, if (status != 0) return(-1); + if (root_loc.ops != &IMFS_ops) + return(-1); + /*********************************************************************** * Create an IMFS node structure pointing to tar image memory. **********************************************************************/ @@ -164,9 +165,10 @@ rtems_tarfs_mount(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); + if (compute_tar_header_checksum(hdr_ptr) != hdr_chksum) break; @@ -179,15 +181,19 @@ rtems_tarfs_mount(char *mountpoint, if (linkflag == LF_DIR) { strcpy(full_filename, mountpoint); - strcat(full_filename, "/"); + if (full_filename[strlen(full_filename)-1] != '/') + strcat(full_filename, "/"); strcat(full_filename, filename); mkdir(full_filename, S_IRWXU | S_IRWXG | S_IRWXO); } - else if (linkflag == LF_NORMAL) + /****************************************************************** + * Create a LINEAR_FILE node if no user write permission. + *****************************************************************/ + else if ((linkflag == LF_NORMAL) && + ((file_mode & 0200) == 0000)) { const char *name; - loc = root_loc; if (IMFS_evaluate_for_make(filename, &loc, &name) == 0) { @@ -199,6 +205,36 @@ rtems_tarfs_mount(char *mountpoint, node->info.linearfile.direct = &tar_image[offset]; } + nblocks = (((file_size) + 511) & ~511) / 512; + offset += 512 * nblocks; + } + /****************************************************************** + * Create a regular MEMORY_FILE if write permission exists. + *****************************************************************/ + else if ((linkflag == LF_NORMAL) && + ((file_mode & 0200) == 0200)) + { + int fd; + int n, left, ptr; + + strcpy(full_filename, mountpoint); + if (full_filename[strlen(full_filename)-1] != '/') + strcat(full_filename, "/"); + strcat(full_filename, filename); + + fd = creat(full_filename, S_IRUSR|S_IWUSR | S_IRGRP|S_IWGRP); + if (fd != -1) + { + left = file_size; + ptr = offset; + while ((n = write(fd, &tar_image[ptr], left)) > 0) + { + left -= n; + ptr += n; + } + close(fd); + } + nblocks = (((file_size) + 511) & ~511) / 512; offset += 512 * nblocks; } -- cgit v1.2.3