Changeset e998c985 in rtems


Ignore:
Timestamp:
Mar 5, 2012, 10:51:23 AM (7 years ago)
Author:
Sebastian Huber <sebastian.huber@…>
Branches:
4.11, master
Children:
beea580
Parents:
04ca77e
git-author:
Sebastian Huber <sebastian.huber@…> (03/05/12 10:51:23)
git-committer:
Sebastian Huber <sebastian.huber@…> (03/13/12 11:24:16)
Message:

IMFS: Node specific stat handlers

Location:
cpukit/libfs/src/imfs
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • cpukit/libfs/src/imfs/imfs_handlers_device.c

    r04ca77e re998c985  
    1818#include "imfs.h"
    1919
     20static int IMFS_stat_device(
     21  const rtems_filesystem_location_info_t *loc,
     22  struct stat *buf
     23)
     24{
     25  const IMFS_jnode_t *node = loc->node_access;
     26  const IMFS_device_t *io = &node->info.device;
     27
     28  buf->st_rdev = rtems_filesystem_make_dev_t( io->major, io->minor );
     29
     30  return IMFS_stat( loc, buf );
     31}
     32
    2033static const rtems_filesystem_file_handlers_r IMFS_device_handlers = {
    2134  device_open,
     
    2538  device_ioctl,
    2639  device_lseek,
    27   IMFS_stat,
     40  IMFS_stat_device,
    2841  device_ftruncate,
    2942  rtems_filesystem_default_fsync_or_fdatasync,
  • cpukit/libfs/src/imfs/imfs_handlers_directory.c

    r04ca77e re998c985  
    1818#include "imfs.h"
    1919
     20#include <dirent.h>
     21
     22static size_t IMFS_directory_size( const IMFS_jnode_t *node )
     23{
     24  size_t size = 0;
     25  const rtems_chain_control *chain = &node->info.directory.Entries;
     26  const rtems_chain_node *current = rtems_chain_immutable_first( chain );
     27  const rtems_chain_node *tail = rtems_chain_immutable_tail( chain );
     28
     29  while ( current != tail ) {
     30    size += sizeof( struct dirent );
     31    current = rtems_chain_immutable_next( current );
     32  }
     33
     34  return size;
     35}
     36
     37static int IMFS_stat_directory(
     38  const rtems_filesystem_location_info_t *loc,
     39  struct stat *buf
     40)
     41{
     42  const IMFS_jnode_t *node = loc->node_access;
     43
     44  buf->st_size = IMFS_directory_size( node );
     45
     46  return IMFS_stat( loc, buf );
     47}
     48
    2049static const rtems_filesystem_file_handlers_r IMFS_directory_handlers = {
    2150  rtems_filesystem_default_open,
     
    2554  rtems_filesystem_default_ioctl,
    2655  imfs_dir_lseek,
    27   IMFS_stat,
     56  IMFS_stat_directory,
    2857  rtems_filesystem_default_ftruncate_directory,
    2958  rtems_filesystem_default_fsync_or_fdatasync_success,
  • cpukit/libfs/src/imfs/imfs_handlers_link.c

    r04ca77e re998c985  
    1919
    2020#include <stdlib.h>
     21#include <string.h>
     22
     23static int IMFS_stat_link(
     24  const rtems_filesystem_location_info_t *loc,
     25  struct stat *buf
     26)
     27{
     28  const IMFS_jnode_t *node = loc->node_access;
     29
     30  if ( IMFS_type( node ) != IMFS_HARD_LINK ) {
     31    buf->st_size = strlen( node->info.sym_link.name );
     32
     33    return IMFS_stat( loc, buf );
     34  } else {
     35    rtems_filesystem_location_info_t targetloc = *loc;
     36
     37    targetloc.node_access = node->info.hard_link.link_node;
     38    IMFS_Set_handlers( &targetloc );
     39
     40    return (targetloc.handlers->fstat_h)( &targetloc, buf );
     41  }
     42}
    2143
    2244static const rtems_filesystem_file_handlers_r IMFS_link_handlers = {
     
    2749  rtems_filesystem_default_ioctl,
    2850  rtems_filesystem_default_lseek,
    29   IMFS_stat,  /* stat */
     51  IMFS_stat_link,
    3052  rtems_filesystem_default_ftruncate,
    3153  rtems_filesystem_default_fsync_or_fdatasync,
  • cpukit/libfs/src/imfs/imfs_handlers_memfile.c

    r04ca77e re998c985  
    1818#include "imfs.h"
    1919
     20static int IMFS_stat_file(
     21  const rtems_filesystem_location_info_t *loc,
     22  struct stat *buf
     23)
     24{
     25  const IMFS_jnode_t *node = loc->node_access;
     26
     27  buf->st_size = node->info.file.size;
     28  buf->st_blksize = imfs_rq_memfile_bytes_per_block;
     29
     30  return IMFS_stat( loc, buf );
     31}
     32
    2033static const rtems_filesystem_file_handlers_r IMFS_memfile_handlers = {
    2134  memfile_open,
     
    2538  memfile_ioctl,
    2639  memfile_lseek,
    27   IMFS_stat,
     40  IMFS_stat_file,
    2841  memfile_ftruncate,
    2942  rtems_filesystem_default_fsync_or_fdatasync_success,
  • cpukit/libfs/src/imfs/imfs_stat.c

    r04ca77e re998c985  
    2323#include "imfs.h"
    2424
    25 #include <dirent.h>
    26 #include <string.h>
    27 
    28 static size_t IMFS_directory_size( const IMFS_jnode_t *the_jnode )
    29 {
    30   size_t size = 0;
    31   const rtems_chain_control *chain = &the_jnode->info.directory.Entries;
    32   const rtems_chain_node *current = rtems_chain_immutable_first( chain );
    33   const rtems_chain_node *tail = rtems_chain_immutable_tail( chain );
    34 
    35   while ( current != tail ) {
    36     size += sizeof(struct dirent);
    37     current = rtems_chain_immutable_next( current );
    38   }
    39 
    40   return size;
    41 }
    42 
    4325int IMFS_stat(
    4426  const rtems_filesystem_location_info_t *loc,
     
    4830  IMFS_fs_info_t *fs_info = loc->mt_entry->fs_info;
    4931  IMFS_jnode_t *the_jnode = loc->node_access;
    50   IMFS_device_t *io = &the_jnode->info.device;
    51 
    52   if ( IMFS_type( the_jnode ) == IMFS_HARD_LINK ) {
    53     the_jnode = the_jnode->info.hard_link.link_node;
    54   }
    55 
    56   switch ( IMFS_type( the_jnode ) ) {
    57 
    58     case IMFS_DEVICE:
    59       buf->st_rdev = rtems_filesystem_make_dev_t( io->major, io->minor );
    60       break;
    61 
    62     case IMFS_LINEAR_FILE:
    63     case IMFS_MEMORY_FILE:
    64       buf->st_size = the_jnode->info.file.size;
    65       break;
    66 
    67     case IMFS_DIRECTORY:
    68       buf->st_size = IMFS_directory_size( the_jnode );
    69       break;
    70 
    71     case IMFS_SYM_LINK:
    72       buf->st_size = strlen( the_jnode->info.sym_link.name );
    73       break;
    74 
    75     case IMFS_FIFO:
    76       break;
    77 
    78     default:
    79       rtems_set_errno_and_return_minus_one( ENOTSUP );
    80       break;
    81   }
    8232
    8333  /*
     
    9848  buf->st_ctime = the_jnode->stat_ctime;
    9949
    100   if ( !IMFS_is_directory( the_jnode ) ) {
    101     buf->st_blksize = imfs_rq_memfile_bytes_per_block;
    102   }
    103 
    10450  return 0;
    10551}
Note: See TracChangeset for help on using the changeset viewer.