Add copy-on-write semantics to rtems_tarfs_load().

This commit is contained in:
Eric Norum
2005-02-08 17:12:54 +00:00
parent babf5758c4
commit 624867bc09
12 changed files with 34 additions and 208 deletions

View File

@@ -1,3 +1,12 @@
2005-02-09 Eric Norum <norum@aps.anl.gov>
* libfs/Makefile.am, libfs/src/imfs/imfs.h, libfs/src/imfs/imfs_eval.c,
libfs/src/imfs/imfs_fchmod.c, libfs/src/imfs/imfs_handlers_memfile.c,
libfs/src/imfs/imfs_init.c, libfs/src/imfs/imfs_initsupp.c,
libfs/src/imfs/imfs_load_tar.c, libfs/src/imfs/linearfile.c,
libfs/src/imfs/memfile.c, libfs/src/imfs/miniimfs_init.c: Add
'copy-on-write' semantics to rtems_tarfs_load().
2005-02-08 Ralf Corsepius <ralf.corsepius@rtems.org>
* httpd/Makefile.am: Split preinstallation rules in to separate

View File

@@ -21,7 +21,7 @@ libimfs_a_SOURCES += src/imfs/imfs_chown.c src/imfs/imfs_config.c \
src/imfs/imfs_mknod.c src/imfs/imfs_mount.c src/imfs/imfs_fchmod.c \
src/imfs/imfs_unlink.c src/imfs/imfs_unmount.c src/imfs/imfs_utime.c \
src/imfs/imfs_ntype.c src/imfs/imfs_stat.c src/imfs/imfs_getchild.c \
src/imfs/memfile.c src/imfs/linearfile.c src/imfs/deviceio.c \
src/imfs/memfile.c src/imfs/deviceio.c \
src/imfs/imfs_handlers_device.c src/imfs/imfs_handlers_directory.c \
src/imfs/imfs_handlers_link.c src/imfs/imfs_handlers_memfile.c \
src/imfs/imfs_debug.c src/imfs/imfs_rmnod.c src/imfs/imfs_symlink.c \

View File

@@ -202,7 +202,6 @@ struct IMFS_jnode_tt {
typedef struct {
ino_t ino_count;
rtems_filesystem_file_handlers_r *linearfile_handlers;
rtems_filesystem_file_handlers_r *memfile_handlers;
rtems_filesystem_file_handlers_r *directory_handlers;
} IMFS_fs_info_t;
@@ -237,7 +236,6 @@ typedef enum {
extern rtems_filesystem_file_handlers_r IMFS_directory_handlers;
extern rtems_filesystem_file_handlers_r IMFS_device_handlers;
extern rtems_filesystem_file_handlers_r IMFS_link_handlers;
extern rtems_filesystem_file_handlers_r IMFS_linearfile_handlers;
extern rtems_filesystem_file_handlers_r IMFS_memfile_handlers;
extern rtems_filesystem_operations_table IMFS_ops;
extern rtems_filesystem_operations_table miniIMFS_ops;
@@ -258,7 +256,6 @@ int miniIMFS_initialize(
int IMFS_initialize_support(
rtems_filesystem_mount_table_entry_t *mt_entry,
rtems_filesystem_operations_table *op_table,
rtems_filesystem_file_handlers_r *linearfile_handlers,
rtems_filesystem_file_handlers_r *memfile_handlers,
rtems_filesystem_file_handlers_r *directory_handlers
);
@@ -416,18 +413,6 @@ int imfs_dir_rmnod(
rtems_filesystem_location_info_t *pathloc /* IN */
);
int linearfile_read(
rtems_libio_t *iop, /* IN */
void *buffer, /* IN */
uint32_t count /* IN */
);
int linearfile_lseek(
rtems_libio_t *iop, /* IN */
off_t offset, /* IN */
int whence /* IN */
);
int memfile_open(
rtems_libio_t *iop, /* IN */
const char *pathname, /* IN */

View File

@@ -52,7 +52,7 @@ int IMFS_Set_handlers(
loc->handlers = &IMFS_link_handlers;
break;
case IMFS_LINEAR_FILE:
loc->handlers = fs_info->linearfile_handlers;
loc->handlers = fs_info->memfile_handlers;
break;
case IMFS_MEMORY_FILE:
loc->handlers = fs_info->memfile_handlers;

View File

@@ -56,25 +56,6 @@ int IMFS_fchmod(
if ( mode & (~ (S_IRWXU | S_IRWXG | S_IRWXO ) ) )
rtems_set_errno_and_return_minus_one( EPERM );
/*
* If we make a linear-file writeable, construct a block file
* from it first.
*/
if ( (jnode->type == IMFS_LINEAR_FILE) &&
(mode & (S_IWUSR | S_IWGRP | S_IWOTH)) )
{
uint32_t count = jnode->info.linearfile.size;
const unsigned char *buffer = jnode->info.linearfile.direct;
jnode->type = IMFS_MEMORY_FILE;
jnode->info.file.size = 0;
jnode->info.file.indirect = 0;
jnode->info.file.doubly_indirect = 0;
jnode->info.file.triply_indirect = 0;
if (IMFS_memfile_write(jnode, 0, buffer, count) == -1)
return(-1);
}
jnode->st_mode &= ~(S_IRWXU | S_IRWXG | S_IRWXO);
jnode->st_mode |= mode;

View File

@@ -23,23 +23,6 @@
* Set of operations handlers for operations on memfile entities.
*/
rtems_filesystem_file_handlers_r IMFS_linearfile_handlers = {
memfile_open,
memfile_close,
memfile_read,
NULL, /* write */
memfile_ioctl,
memfile_lseek,
IMFS_stat,
IMFS_fchmod,
NULL, /* ftruncate */
NULL, /* fpathconf */
IMFS_fdatasync, /* fsync */
IMFS_fdatasync,
IMFS_fcntl,
memfile_rmnod
};
rtems_filesystem_file_handlers_r IMFS_memfile_handlers = {
memfile_open,
memfile_close,

View File

@@ -63,7 +63,6 @@ int IMFS_initialize(
return IMFS_initialize_support(
temp_mt_entry,
&IMFS_ops,
&IMFS_linearfile_handlers,
&IMFS_memfile_handlers,
&IMFS_directory_handlers
);

View File

@@ -37,7 +37,6 @@
int IMFS_initialize_support(
rtems_filesystem_mount_table_entry_t *temp_mt_entry,
rtems_filesystem_operations_table *op_table,
rtems_filesystem_file_handlers_r *linearfile_handlers,
rtems_filesystem_file_handlers_r *memfile_handlers,
rtems_filesystem_file_handlers_r *directory_handlers
)
@@ -78,7 +77,6 @@ int IMFS_initialize_support(
*/
fs_info->ino_count = 1;
fs_info->linearfile_handlers = linearfile_handlers;
fs_info->memfile_handlers = memfile_handlers;
fs_info->directory_handlers = directory_handlers;

View File

@@ -25,6 +25,7 @@
#include <rtems/chain.h>
#include <rtems/imfs.h>
#include <rtems/untar.h>
#include <rtems/tar.h>
/**************************************************************************
* TAR file format:
@@ -141,10 +142,9 @@ rtems_tarfs_load(char *mountpoint,
mkdir(full_filename, S_IRWXU | S_IRWXG | S_IRWXO);
}
/******************************************************************
* Create a LINEAR_FILE node if no user write permission.
* Create a LINEAR_FILE node
*****************************************************************/
else if ((linkflag == REGTYPE) &&
((file_mode & 0200) == 0000))
else if (linkflag == REGTYPE)
{
const char *name;
@@ -153,42 +153,12 @@ rtems_tarfs_load(char *mountpoint,
{
node = IMFS_create_node(&loc,
IMFS_LINEAR_FILE, (char *)name,
(S_IRUSR | S_IRGRP | S_IROTH) | S_IFREG,
(file_mode & (S_IRWXU | S_IRWXG | S_IRWXO)) | S_IFREG,
NULL);
node->info.linearfile.size = file_size;
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 == REGTYPE) &&
((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;
}

View File

@@ -1,115 +0,0 @@
/*
* 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.rtems.com/license/LICENSE.
*
* $Id$
*/
#if HAVE_CONFIG_H
#include "config.h"
#endif
#include <stdlib.h>
#include <assert.h>
#include <string.h>
#include <errno.h>
#include <rtems.h>
#include <rtems/libio.h>
#include "imfs.h"
#include <rtems/libio_.h>
#include <rtems/seterr.h>
/*
* linearfile_read
*
* This routine processes the read() system call.
*/
int linearfile_read(
rtems_libio_t *iop,
void *buffer,
uint32_t 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 )
rtems_set_errno_and_return_minus_one( EIO );
assert( the_jnode->type == IMFS_LINEAR_FILE );
if ( the_jnode->type != IMFS_LINEAR_FILE )
rtems_set_errno_and_return_minus_one( EIO );
/*
* Error checks on arguments
*/
dest = (unsigned char *)buffer;
assert( dest );
if ( !dest )
rtems_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;
}

View File

@@ -99,6 +99,23 @@ int memfile_open(
the_jnode = iop->file_info;
/*
* Perform 'copy on write' for linear files
*/
if ((iop->flags & (LIBIO_FLAGS_WRITE | LIBIO_FLAGS_APPEND))
&& (the_jnode->type == IMFS_LINEAR_FILE)) {
uint32_t count = the_jnode->info.linearfile.size;
const unsigned char *buffer = the_jnode->info.linearfile.direct;
the_jnode->type = IMFS_MEMORY_FILE;
the_jnode->info.file.size = 0;
the_jnode->info.file.indirect = 0;
the_jnode->info.file.doubly_indirect = 0;
the_jnode->info.file.triply_indirect = 0;
if ((count != 0)
&& (IMFS_memfile_write(the_jnode, 0, buffer, count) == -1))
return -1;
}
if (iop->flags & LIBIO_FLAGS_APPEND)
iop->offset = the_jnode->info.file.size;

View File

@@ -63,7 +63,6 @@ int miniIMFS_initialize(
return IMFS_initialize_support(
temp_mt_entry,
&miniIMFS_ops,
&rtems_filesystem_null_handlers, /* for linearfiles */
&rtems_filesystem_null_handlers, /* for memfiles */
&rtems_filesystem_null_handlers /* for directories */
);