summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSebastian Huber <sebastian.huber@embedded-brains.de>2015-02-05 16:43:58 +0100
committerSebastian Huber <sebastian.huber@embedded-brains.de>2015-02-12 20:53:34 +0100
commite4d35d82fc6d25ae8e1d98f14938a7208fb8a592 (patch)
tree2c902219a94ddaf08bab9341ea68d5f64e6014e9
parentIMFS: Introduce IMFS_mknod_control (diff)
downloadrtems-e4d35d82fc6d25ae8e1d98f14938a7208fb8a592.tar.bz2
IMFS: Split linfile and memfile modules
Make several functions static.
-rw-r--r--cpukit/libfs/Makefile.am7
-rw-r--r--cpukit/libfs/src/imfs/imfs.h62
-rw-r--r--cpukit/libfs/src/imfs/imfs_linfile.c (renamed from cpukit/libfs/src/imfs/imfs_handlers_memfile.c)80
-rw-r--r--cpukit/libfs/src/imfs/imfs_memfile.c (renamed from cpukit/libfs/src/imfs/memfile.c)123
-rw-r--r--cpukit/libfs/src/imfs/imfs_stat_file.c33
5 files changed, 137 insertions, 168 deletions
diff --git a/cpukit/libfs/Makefile.am b/cpukit/libfs/Makefile.am
index 4bff8cfaf2..3c454e7154 100644
--- a/cpukit/libfs/Makefile.am
+++ b/cpukit/libfs/Makefile.am
@@ -49,13 +49,14 @@ libimfs_a_SOURCES += src/imfs/deviceio.c \
src/imfs/imfs_fsunmount.c \
src/imfs/imfs_handlers_device.c \
src/imfs/imfs_handlers_directory.c \
- src/imfs/imfs_handlers_memfile.c src/imfs/imfs_init.c \
+ src/imfs/imfs_init.c \
src/imfs/imfs_initsupp.c src/imfs/imfs_link.c src/imfs/imfs_load_tar.c \
+ src/imfs/imfs_linfile.c \
src/imfs/imfs_mknod.c src/imfs/imfs_mount.c \
src/imfs/imfs_rename.c src/imfs/imfs_rmnod.c \
- src/imfs/imfs_stat.c src/imfs/imfs_symlink.c \
+ src/imfs/imfs_stat.c src/imfs/imfs_stat_file.c src/imfs/imfs_symlink.c \
src/imfs/imfs_unmount.c src/imfs/imfs_utime.c src/imfs/ioman.c \
- src/imfs/memfile.c src/imfs/miniimfs_init.c src/imfs/imfs.h
+ src/imfs/imfs_memfile.c src/imfs/miniimfs_init.c src/imfs/imfs.h
# POSIX FIFO/pipe
libimfs_a_SOURCES += src/pipe/fifo.c src/pipe/pipe.c src/pipe/pipe.h
diff --git a/cpukit/libfs/src/imfs/imfs.h b/cpukit/libfs/src/imfs/imfs.h
index f69408a443..12881c4073 100644
--- a/cpukit/libfs/src/imfs/imfs.h
+++ b/cpukit/libfs/src/imfs/imfs.h
@@ -511,6 +511,11 @@ extern int IMFS_stat(
struct stat *buf
);
+extern int IMFS_stat_file(
+ const rtems_filesystem_location_info_t *loc,
+ struct stat *buf
+);
+
/**
* @brief IMFS evaluation node support.
*/
@@ -711,20 +716,6 @@ extern int IMFS_unmount(
rtems_filesystem_mount_table_entry_t *mt_entry /* IN */
);
-extern void IMFS_memfile_remove(
- IMFS_jnode_t *the_jnode /* IN/OUT */
-);
-
-/**
- * @brief Truncate a memory file.
- *
- * This routine processes the ftruncate() system call.
- */
-extern int memfile_ftruncate(
- rtems_libio_t *iop, /* IN */
- off_t length /* IN */
-);
-
/**
* @brief Read the next directory of the IMFS.
*
@@ -756,44 +747,11 @@ extern ssize_t imfs_dir_read(
*/
/**@{*/
-/**
- * @brief Open a linear file.
- *
- * Transforms the file into a memfile if opened for writing.
- */
-extern int IMFS_linfile_open(
- rtems_libio_t *iop, /* IN */
- const char *pathname, /* IN */
- int oflag, /* IN */
- mode_t mode /* IN */
-);
-
-extern ssize_t IMFS_linfile_read(
- rtems_libio_t *iop,
- void *buffer,
- size_t count
-);
-
-/**
- * @brief Read a memory file.
- *
- * This routine processes the read() system call.
- */
-extern ssize_t memfile_read(
- rtems_libio_t *iop, /* IN */
- void *buffer, /* IN */
- size_t count /* IN */
-);
-
-/**
- * @brief Write a memory file.
- *
- * This routine processes the write() system call.
- */
-extern ssize_t memfile_write(
- rtems_libio_t *iop, /* IN */
- const void *buffer, /* IN */
- size_t count /* IN */
+extern ssize_t IMFS_memfile_write(
+ IMFS_memfile_t *memfile,
+ off_t start,
+ const unsigned char *source,
+ unsigned int length
);
/** @} */
diff --git a/cpukit/libfs/src/imfs/imfs_handlers_memfile.c b/cpukit/libfs/src/imfs/imfs_linfile.c
index 1e5dba2a63..8a1486600b 100644
--- a/cpukit/libfs/src/imfs/imfs_handlers_memfile.c
+++ b/cpukit/libfs/src/imfs/imfs_linfile.c
@@ -1,7 +1,6 @@
/**
* @file
*
- * @brief Memfile Operations Tables
* @ingroup IMFS
*/
@@ -20,36 +19,57 @@
#include "imfs.h"
-static int IMFS_stat_file(
- const rtems_filesystem_location_info_t *loc,
- struct stat *buf
+static ssize_t IMFS_linfile_read(
+ rtems_libio_t *iop,
+ void *buffer,
+ size_t count
)
{
- const IMFS_file_t *file = loc->node_access;
+ IMFS_file_t *file = IMFS_iop_to_file( iop );
+ off_t start = iop->offset;
+ size_t size = file->File.size;
+ const unsigned char *data = file->Linearfile.direct;
- buf->st_size = file->File.size;
- buf->st_blksize = imfs_rq_memfile_bytes_per_block;
+ if (count > size - start)
+ count = size - start;
- return IMFS_stat( loc, buf );
+ IMFS_update_atime( &file->Node );
+ iop->offset = start + count;
+ memcpy(buffer, &data[start], count);
+
+ return (ssize_t) count;
}
-static const rtems_filesystem_file_handlers_r IMFS_memfile_handlers = {
- .open_h = rtems_filesystem_default_open,
- .close_h = rtems_filesystem_default_close,
- .read_h = memfile_read,
- .write_h = memfile_write,
- .ioctl_h = rtems_filesystem_default_ioctl,
- .lseek_h = rtems_filesystem_default_lseek_file,
- .fstat_h = IMFS_stat_file,
- .ftruncate_h = memfile_ftruncate,
- .fsync_h = rtems_filesystem_default_fsync_or_fdatasync_success,
- .fdatasync_h = rtems_filesystem_default_fsync_or_fdatasync_success,
- .fcntl_h = rtems_filesystem_default_fcntl,
- .kqfilter_h = rtems_filesystem_default_kqfilter,
- .poll_h = rtems_filesystem_default_poll,
- .readv_h = rtems_filesystem_default_readv,
- .writev_h = rtems_filesystem_default_writev
-};
+static int IMFS_linfile_open(
+ rtems_libio_t *iop,
+ const char *pathname,
+ int oflag,
+ mode_t mode
+)
+{
+ IMFS_file_t *file;
+
+ file = iop->pathinfo.node_access;
+
+ /*
+ * Perform 'copy on write' for linear files
+ */
+ if ((iop->flags & LIBIO_FLAGS_WRITE) != 0) {
+ uint32_t count = file->File.size;
+ const unsigned char *buffer = file->Linearfile.direct;
+
+ file->Node.control = &IMFS_mknod_control_memfile.node_control;
+ file->File.size = 0;
+ file->Memfile.indirect = 0;
+ file->Memfile.doubly_indirect = 0;
+ file->Memfile.triply_indirect = 0;
+ if ((count != 0)
+ && (IMFS_memfile_write(&file->Memfile, 0, buffer, count) == -1))
+ return -1;
+ }
+
+ return 0;
+}
static const rtems_filesystem_file_handlers_r IMFS_linfile_handlers = {
.open_h = IMFS_linfile_open,
@@ -69,16 +89,6 @@ static const rtems_filesystem_file_handlers_r IMFS_linfile_handlers = {
.writev_h = rtems_filesystem_default_writev
};
-const IMFS_mknod_control IMFS_mknod_control_memfile = {
- {
- .handlers = &IMFS_memfile_handlers,
- .node_initialize = IMFS_node_initialize_default,
- .node_remove = IMFS_node_remove_default,
- .node_destroy = IMFS_memfile_remove
- },
- .node_size = sizeof( IMFS_file_t )
-};
-
const IMFS_node_control IMFS_node_control_linfile = {
.handlers = &IMFS_linfile_handlers,
.node_initialize = IMFS_node_initialize_default,
diff --git a/cpukit/libfs/src/imfs/memfile.c b/cpukit/libfs/src/imfs/imfs_memfile.c
index 59da9a6c1b..2b6a49698a 100644
--- a/cpukit/libfs/src/imfs/memfile.c
+++ b/cpukit/libfs/src/imfs/imfs_memfile.c
@@ -23,106 +23,45 @@
#include <stdlib.h>
#include <string.h>
-#define MEMFILE_STATIC
-
/*
* Prototypes of private routines
*/
-MEMFILE_STATIC int IMFS_memfile_extend(
+static int IMFS_memfile_extend(
IMFS_memfile_t *memfile,
bool zero_fill,
off_t new_length
);
-MEMFILE_STATIC int IMFS_memfile_addblock(
+static int IMFS_memfile_addblock(
IMFS_memfile_t *memfile,
unsigned int block
);
-MEMFILE_STATIC void IMFS_memfile_remove_block(
+static void IMFS_memfile_remove_block(
IMFS_memfile_t *memfile,
unsigned int block
);
-MEMFILE_STATIC block_p *IMFS_memfile_get_block_pointer(
+static block_p *IMFS_memfile_get_block_pointer(
IMFS_memfile_t *memfile,
unsigned int block,
int malloc_it
);
-MEMFILE_STATIC ssize_t IMFS_memfile_read(
+static ssize_t IMFS_memfile_read(
IMFS_file_t *file,
off_t start,
unsigned char *destination,
unsigned int length
);
-ssize_t IMFS_memfile_write( /* cannot be static as used in imfs_fchmod.c */
- IMFS_memfile_t *memfile,
- off_t start,
- const unsigned char *source,
- unsigned int length
-);
-
-void *memfile_alloc_block(void);
+static void *memfile_alloc_block(void);
-void memfile_free_block(
+static void memfile_free_block(
void *memory
);
-int IMFS_linfile_open(
- rtems_libio_t *iop,
- const char *pathname,
- int oflag,
- mode_t mode
-)
-{
- IMFS_file_t *file;
-
- file = iop->pathinfo.node_access;
-
- /*
- * Perform 'copy on write' for linear files
- */
- if ((iop->flags & LIBIO_FLAGS_WRITE) != 0) {
- uint32_t count = file->File.size;
- const unsigned char *buffer = file->Linearfile.direct;
-
- file->Node.control = &IMFS_mknod_control_memfile.node_control;
- file->File.size = 0;
- file->Memfile.indirect = 0;
- file->Memfile.doubly_indirect = 0;
- file->Memfile.triply_indirect = 0;
- if ((count != 0)
- && (IMFS_memfile_write(&file->Memfile, 0, buffer, count) == -1))
- return -1;
- }
-
- return 0;
-}
-
-ssize_t IMFS_linfile_read(
- rtems_libio_t *iop,
- void *buffer,
- size_t count
-)
-{
- IMFS_file_t *file = IMFS_iop_to_file( iop );
- off_t start = iop->offset;
- size_t size = file->File.size;
- const unsigned char *data = file->Linearfile.direct;
-
- if (count > size - start)
- count = size - start;
-
- IMFS_update_atime( &file->Node );
- iop->offset = start + count;
- memcpy(buffer, &data[start], count);
-
- return (ssize_t) count;
-}
-
-ssize_t memfile_read(
+static ssize_t memfile_read(
rtems_libio_t *iop,
void *buffer,
size_t count
@@ -139,7 +78,7 @@ ssize_t memfile_read(
return status;
}
-ssize_t memfile_write(
+static ssize_t memfile_write(
rtems_libio_t *iop,
const void *buffer,
size_t count
@@ -165,7 +104,7 @@ ssize_t memfile_write(
* This IMFS_stat() can be used.
*/
-int memfile_ftruncate(
+static int memfile_ftruncate(
rtems_libio_t *iop,
off_t length
)
@@ -200,7 +139,7 @@ int memfile_ftruncate(
* specified. If necessary, it will allocate memory blocks to
* extend the file.
*/
-MEMFILE_STATIC int IMFS_memfile_extend(
+static int IMFS_memfile_extend(
IMFS_memfile_t *memfile,
bool zero_fill,
off_t new_length
@@ -271,7 +210,7 @@ MEMFILE_STATIC int IMFS_memfile_extend(
*
* This routine adds a single block to the specified in-memory file.
*/
-MEMFILE_STATIC int IMFS_memfile_addblock(
+static int IMFS_memfile_addblock(
IMFS_memfile_t *memfile,
unsigned int block
)
@@ -312,7 +251,7 @@ MEMFILE_STATIC int IMFS_memfile_addblock(
* block from the middle of a file would be exceptionally
* dangerous and the results unpredictable.
*/
-MEMFILE_STATIC void IMFS_memfile_remove_block(
+static void IMFS_memfile_remove_block(
IMFS_memfile_t *memfile,
unsigned int block
)
@@ -368,7 +307,7 @@ static void memfile_free_blocks_in_table(
}
/*
- * IMFS_memfile_remove
+ * IMFS_memfile_destroy
*
* This routine frees all memory associated with an in memory file.
*
@@ -385,7 +324,7 @@ static void memfile_free_blocks_in_table(
* Regardless until the IMFS implementation is proven, it
* is better to stick to simple, easy to understand algorithms.
*/
-void IMFS_memfile_remove(
+static void IMFS_memfile_destroy(
IMFS_jnode_t *the_jnode
)
{
@@ -461,7 +400,7 @@ void IMFS_memfile_remove(
* reading the data between offset and the end of the file (truncated
* read).
*/
-MEMFILE_STATIC ssize_t IMFS_memfile_read(
+static ssize_t IMFS_memfile_read(
IMFS_file_t *file,
off_t start,
unsigned char *destination,
@@ -566,7 +505,7 @@ MEMFILE_STATIC ssize_t IMFS_memfile_read(
* This routine writes the specified data buffer into the in memory
* file pointed to by memfile. The file is extended as needed.
*/
-MEMFILE_STATIC ssize_t IMFS_memfile_write(
+ssize_t IMFS_memfile_write(
IMFS_memfile_t *memfile,
off_t start,
const unsigned char *source,
@@ -891,3 +830,31 @@ void memfile_free_block(
free(memory);
memfile_blocks_allocated--;
}
+
+static const rtems_filesystem_file_handlers_r IMFS_memfile_handlers = {
+ .open_h = rtems_filesystem_default_open,
+ .close_h = rtems_filesystem_default_close,
+ .read_h = memfile_read,
+ .write_h = memfile_write,
+ .ioctl_h = rtems_filesystem_default_ioctl,
+ .lseek_h = rtems_filesystem_default_lseek_file,
+ .fstat_h = IMFS_stat_file,
+ .ftruncate_h = memfile_ftruncate,
+ .fsync_h = rtems_filesystem_default_fsync_or_fdatasync_success,
+ .fdatasync_h = rtems_filesystem_default_fsync_or_fdatasync_success,
+ .fcntl_h = rtems_filesystem_default_fcntl,
+ .kqfilter_h = rtems_filesystem_default_kqfilter,
+ .poll_h = rtems_filesystem_default_poll,
+ .readv_h = rtems_filesystem_default_readv,
+ .writev_h = rtems_filesystem_default_writev
+};
+
+const IMFS_mknod_control IMFS_mknod_control_memfile = {
+ {
+ .handlers = &IMFS_memfile_handlers,
+ .node_initialize = IMFS_node_initialize_default,
+ .node_remove = IMFS_node_remove_default,
+ .node_destroy = IMFS_memfile_destroy
+ },
+ .node_size = sizeof( IMFS_file_t )
+};
diff --git a/cpukit/libfs/src/imfs/imfs_stat_file.c b/cpukit/libfs/src/imfs/imfs_stat_file.c
new file mode 100644
index 0000000000..2302705b2c
--- /dev/null
+++ b/cpukit/libfs/src/imfs/imfs_stat_file.c
@@ -0,0 +1,33 @@
+/**
+ * @file
+ *
+ * @ingroup IMFS
+ */
+
+/*
+ * 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.org/license/LICENSE.
+ */
+
+#if HAVE_CONFIG_H
+ #include "config.h"
+#endif
+
+#include "imfs.h"
+
+int IMFS_stat_file(
+ const rtems_filesystem_location_info_t *loc,
+ struct stat *buf
+)
+{
+ const IMFS_file_t *file = loc->node_access;
+
+ buf->st_size = file->File.size;
+ buf->st_blksize = imfs_rq_memfile_bytes_per_block;
+
+ return IMFS_stat( loc, buf );
+}