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/exec/libfs/src/imfs/memfile.c | 43 +++++++++++++++++++++++++++++-------- 1 file changed, 34 insertions(+), 9 deletions(-) (limited to 'c/src/exec/libfs/src/imfs/memfile.c') diff --git a/c/src/exec/libfs/src/imfs/memfile.c b/c/src/exec/libfs/src/imfs/memfile.c index 890f2aebc1..cfbf5dd110 100644 --- a/c/src/exec/libfs/src/imfs/memfile.c +++ b/c/src/exec/libfs/src/imfs/memfile.c @@ -197,10 +197,16 @@ int memfile_lseek( the_jnode = iop->file_info; - if (IMFS_memfile_extend( the_jnode, iop->offset )) - set_errno_and_return_minus_one( ENOSPC ); + if (the_jnode->type == IMFS_LINEAR_FILE) { + if (iop->offset > the_jnode->info.linearfile.size) + iop->offset = the_jnode->info.linearfile.size; + } + else { /* Must be a block file (IMFS_MEMORY_FILE). */ + if (IMFS_memfile_extend( the_jnode, iop->offset )) + set_errno_and_return_minus_one( ENOSPC ); - iop->size = the_jnode->info.file.size; + iop->size = the_jnode->info.file.size; + } return iop->offset; } @@ -499,8 +505,6 @@ int IMFS_memfile_remove( if ( info->triply_indirect ) { for ( i=0 ; itriply_indirect[i]; - if (!p) /* ensure we have a valid pointer */ - break; for ( j=0 ; jtype == IMFS_MEMORY_FILE ); - if ( the_jnode->type != IMFS_MEMORY_FILE ) + assert( the_jnode->type == IMFS_MEMORY_FILE || + the_jnode->type == IMFS_LINEAR_FILE ); + if ( the_jnode->type != IMFS_MEMORY_FILE && + the_jnode->type != IMFS_LINEAR_FILE ) set_errno_and_return_minus_one( EIO ); /* @@ -574,6 +580,25 @@ MEMFILE_STATIC int IMFS_memfile_read( if ( !my_length ) set_errno_and_return_minus_one( EINVAL ); + /* + * Linear files (as created from a tar file are easier to handle + * than block files). + */ + if (the_jnode->type == IMFS_LINEAR_FILE) { + unsigned char *file_ptr; + + file_ptr = (unsigned char *)the_jnode->info.linearfile.direct; + + if (my_length > (the_jnode->info.linearfile.size - start)) + my_length = the_jnode->info.linearfile.size - start; + + memcpy(dest, &file_ptr[start], my_length); + + IMFS_update_atime( the_jnode ); + + return my_length; + } + /* * If the last byte we are supposed to read is past the end of this * in memory file, then shorten the length to read. @@ -1090,8 +1115,8 @@ int memfile_rmnod( /* * Free memory associated with a memory file. */ - - IMFS_memfile_remove( the_jnode ); + if (the_jnode->type != IMFS_LINEAR_FILE) + IMFS_memfile_remove( the_jnode ); free( the_jnode ); } -- cgit v1.2.3