diff options
Diffstat (limited to 'cpukit/libfs/src/imfs/imfs_stat.c')
-rw-r--r-- | cpukit/libfs/src/imfs/imfs_stat.c | 53 |
1 files changed, 37 insertions, 16 deletions
diff --git a/cpukit/libfs/src/imfs/imfs_stat.c b/cpukit/libfs/src/imfs/imfs_stat.c index 5bc1eae579..66d1ca2ba9 100644 --- a/cpukit/libfs/src/imfs/imfs_stat.c +++ b/cpukit/libfs/src/imfs/imfs_stat.c @@ -6,6 +6,9 @@ * COPYRIGHT (c) 1989-1999. * On-Line Applications Research Corporation (OAR). * + * Modifications to support reference counting in the file system are + * Copyright (c) 2012 embedded brains GmbH. + * * 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. @@ -14,31 +17,45 @@ */ #if HAVE_CONFIG_H -#include "config.h" + #include "config.h" #endif -#include <errno.h> -#include <string.h> #include "imfs.h" -#include <rtems/libio_.h> -#include <rtems/seterr.h> + +#include <dirent.h> +#include <string.h> + +static size_t IMFS_directory_size( const IMFS_jnode_t *the_jnode ) +{ + size_t size = 0; + const rtems_chain_control *chain = &the_jnode->info.directory.Entries; + const rtems_chain_node *current = rtems_chain_immutable_first( chain ); + const rtems_chain_node *tail = rtems_chain_immutable_tail( chain ); + + while ( current != tail ) { + size += sizeof(struct dirent); + current = rtems_chain_immutable_next( current ); + } + + return size; +} int IMFS_stat( - rtems_filesystem_location_info_t *loc, - struct stat *buf + const rtems_filesystem_location_info_t *loc, + struct stat *buf ) { - IMFS_fs_info_t *fs_info; - IMFS_jnode_t *the_jnode; - IMFS_device_t *io; - - the_jnode = loc->node_access; + IMFS_fs_info_t *fs_info = loc->mt_entry->fs_info; + IMFS_jnode_t *the_jnode = loc->node_access; + IMFS_device_t *io = &the_jnode->info.device; + if ( the_jnode->type == IMFS_HARD_LINK ) { + the_jnode = the_jnode->info.hard_link.link_node; + } switch ( the_jnode->type ) { case IMFS_DEVICE: - io = &the_jnode->info.device; buf->st_rdev = rtems_filesystem_make_dev_t( io->major, io->minor ); break; @@ -47,12 +64,15 @@ int IMFS_stat( buf->st_size = the_jnode->info.file.size; break; + case IMFS_DIRECTORY: + buf->st_size = IMFS_directory_size( the_jnode ); + break; + case IMFS_SYM_LINK: buf->st_size = strlen( the_jnode->info.sym_link.name ); break; case IMFS_FIFO: - buf->st_size = 0; break; default: @@ -64,7 +84,6 @@ int IMFS_stat( * The device number of the IMFS is the major number and the minor is the * instance. */ - fs_info = loc->mt_entry->fs_info; buf->st_dev = rtems_filesystem_make_dev_t( IMFS_DEVICE_MAJOR_NUMBER, fs_info->instance ); @@ -78,7 +97,9 @@ int IMFS_stat( buf->st_mtime = the_jnode->stat_mtime; buf->st_ctime = the_jnode->stat_ctime; - buf->st_blksize = imfs_rq_memfile_bytes_per_block; + if ( the_jnode->type != IMFS_DIRECTORY ) { + buf->st_blksize = imfs_rq_memfile_bytes_per_block; + } return 0; } |