diff options
author | Joel Sherrill <joel.sherrill@OARcorp.com> | 2000-12-13 17:53:55 +0000 |
---|---|---|
committer | Joel Sherrill <joel.sherrill@OARcorp.com> | 2000-12-13 17:53:55 +0000 |
commit | 0ef748fb45137bac811ded19dfad2034f924505a (patch) | |
tree | 781c137a2c5303c3ad851c5982c2641fedc45bbf /cpukit/libfs/src/imfs/linearfile.c | |
parent | 2000-12-13 Joel Sherrill <joel@OARcorp.com> (diff) | |
download | rtems-0ef748fb45137bac811ded19dfad2034f924505a.tar.bz2 |
2000-12-12 Jake Janovetz <janovetz@uiuc.edu>
* src/imfs/linearfile.c, src/imfs/imfs_load_tar.c: New files.
* src/imfs/Makefile.am, src/imfs/imfs.h,
src/imfs/imfs_creat.c, src/imfs/imfs_debug.c,
src/imfs/imfs_eval.c, src/imfs/imfs_handlers_memfile.c,
src/imfs/imfs_init.c, src/imfs/imfs_initsupp.c,
src/imfs/imfs_stat.c, src/imfs/miniimfs_init.c: Added "tarfs".
This is not really a tar filesystem. It is a way to load a tar
image into the IMFS but actually leave bulky file contents in the
original tar image. It essentially adds the linear file type and
associated support and a loader routine.
Diffstat (limited to 'cpukit/libfs/src/imfs/linearfile.c')
-rw-r--r-- | cpukit/libfs/src/imfs/linearfile.c | 110 |
1 files changed, 110 insertions, 0 deletions
diff --git a/cpukit/libfs/src/imfs/linearfile.c b/cpukit/libfs/src/imfs/linearfile.c new file mode 100644 index 0000000000..e8d28fe31d --- /dev/null +++ b/cpukit/libfs/src/imfs/linearfile.c @@ -0,0 +1,110 @@ +/* + * IMFS Linear File Handlers + * + * This file contains the set of handlers used to process operations on + * IMFS linear memory file nodes. Linear memory files are contiguous + * blocks of memory created from a TAR or other filesystem image. + * The blocks are nonwriteable and nonresizeable. + * + * COPYRIGHT (c) 1989-1999. + * On-Line Applications Research Corporation (OAR). + * + * The license and distribution terms for this file may be + * found in the file LICENSE in this distribution or at + * http://www.OARcorp.com/rtems/license.html. + * + * $Id$ + */ + +#include <stdlib.h> +#include <assert.h> +#include <errno.h> + +#include <rtems.h> +#include <rtems/libio.h> +#include "imfs.h" +#include <rtems/libio_.h> + +/* + * linearfile_read + * + * This routine processes the read() system call. + */ + +int linearfile_read( + rtems_libio_t *iop, + void *buffer, + unsigned32 count +) +{ + IMFS_jnode_t *the_jnode; + unsigned char *dest; + unsigned char *file_ptr; + int file_offset; + + + the_jnode = iop->file_info; + + /* + * Perform internal consistency checks + */ + + assert( the_jnode ); + if ( !the_jnode ) + set_errno_and_return_minus_one( EIO ); + + assert( the_jnode->type == IMFS_LINEAR_FILE ); + if ( the_jnode->type != IMFS_LINEAR_FILE ) + set_errno_and_return_minus_one( EIO ); + + /* + * Error checks on arguments + */ + + dest = (unsigned char *)buffer; + assert( dest ); + if ( !dest ) + set_errno_and_return_minus_one( EINVAL ); + + /* + * Perform a simple memory copy. + */ + + if (count == 0) + return(0); + + the_jnode = iop->file_info; + file_ptr = (unsigned char *)the_jnode->info.linearfile.direct; + file_offset = (unsigned long)iop->offset; + + if (count > (the_jnode->info.linearfile.size - file_offset)) + count = the_jnode->info.linearfile.size - file_offset; + + memcpy(dest, &file_ptr[file_offset], count); + + return(count); +} + + +/* + * linearfile_lseek + * + * This routine processes the lseek() system call. + */ + +int linearfile_lseek( + rtems_libio_t *iop, + off_t offset, + int whence +) +{ + IMFS_jnode_t *the_jnode; + + the_jnode = iop->file_info; + + if (iop->offset > the_jnode->info.linearfile.size) + iop->offset = the_jnode->info.linearfile.size; + + return iop->offset; +} + |