Changeset 699ac7c in rtems


Ignore:
Timestamp:
Feb 24, 2012, 4:08:06 PM (8 years ago)
Author:
Sebastian Huber <sebastian.huber@…>
Branches:
4.11, master
Children:
c5392ef9
Parents:
70927458
git-author:
Sebastian Huber <sebastian.huber@…> (02/24/12 16:08:06)
git-committer:
Sebastian Huber <sebastian.huber@…> (03/13/12 11:24:16)
Message:

IMFS: Add and use node control

Add and use structure IMFS_node_control with support functions. This
helps to make high level functions independent of the node type and
reduces the number of branches in the code.

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

Legend:

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

    r70927458 r699ac7c  
    5050};
    5151
     52static const IMFS_node_control *const
     53  IMFS_fifo_node_controls [IMFS_TYPE_COUNT] = {
     54  [IMFS_DIRECTORY] = &IMFS_node_control_directory,
     55  [IMFS_DEVICE] = &IMFS_node_control_device,
     56  [IMFS_HARD_LINK] = &IMFS_node_control_hard_link,
     57  [IMFS_SYM_LINK] = &IMFS_node_control_sym_link,
     58  [IMFS_MEMORY_FILE] = &IMFS_node_control_memfile,
     59  [IMFS_LINEAR_FILE] = &IMFS_node_control_linfile,
     60  [IMFS_FIFO] = &IMFS_node_control_fifo
     61};
     62
    5263int fifoIMFS_initialize(
    5364  rtems_filesystem_mount_table_entry_t *mt_entry,
     
    5869    mt_entry,
    5970    &fifoIMFS_ops,
    60     &IMFS_link_handlers,
    61     &IMFS_fifo_handlers
     71    IMFS_fifo_node_controls
    6272  );
    6373}
  • cpukit/libfs/src/imfs/imfs.h

    r70927458 r699ac7c  
    133133  IMFS_MEMORY_FILE = RTEMS_FILESYSTEM_MEMORY_FILE,
    134134  IMFS_LINEAR_FILE,
    135   IMFS_FIFO
     135  IMFS_FIFO,
     136  IMFS_INVALID_NODE
    136137} IMFS_jnode_types_t;
     138
     139#define IMFS_TYPE_COUNT (IMFS_FIFO + 1)
    137140
    138141typedef union {
     
    146149} IMFS_types_union;
    147150
     151typedef IMFS_jnode_t *(*IMFS_node_control_initialize)(
     152  IMFS_jnode_t *node,
     153  const IMFS_types_union *info
     154);
     155
     156IMFS_jnode_t *IMFS_node_initialize_default(
     157  IMFS_jnode_t *node,
     158  const IMFS_types_union *info
     159);
     160
     161typedef IMFS_jnode_t *(*IMFS_node_control_remove)(
     162  IMFS_jnode_t *node,
     163  const IMFS_jnode_t *root_node
     164);
     165
     166IMFS_jnode_t *IMFS_node_remove_default(
     167  IMFS_jnode_t *node,
     168  const IMFS_jnode_t *root_node
     169);
     170
     171typedef IMFS_jnode_t *(*IMFS_node_control_destroy)( IMFS_jnode_t *node );
     172
     173IMFS_jnode_t *IMFS_node_destroy_default( IMFS_jnode_t *node );
     174
     175typedef struct {
     176  IMFS_jnode_types_t imfs_type;
     177  const rtems_filesystem_file_handlers_r *handlers;
     178  IMFS_node_control_initialize node_initialize;
     179  IMFS_node_control_remove node_remove;
     180  IMFS_node_control_destroy node_destroy;
     181} IMFS_node_control;
     182
    148183/*
    149184 * Major device number for the IMFS. This is not a real device number because
     
    177212  time_t              stat_mtime;            /* Time of last modification */
    178213  time_t              stat_ctime;            /* Time of last status change */
    179   IMFS_jnode_types_t  type;                  /* Type of this entry */
     214  const IMFS_node_control *control;
    180215  IMFS_types_union    info;
    181216};
     
    211246
    212247typedef struct {
    213   int                                     instance;
    214   ino_t                                   ino_count;
    215   const rtems_filesystem_file_handlers_r *memfile_handlers;
    216   const rtems_filesystem_file_handlers_r *directory_handlers;
    217   const rtems_filesystem_file_handlers_r *link_handlers;
    218   const rtems_filesystem_file_handlers_r *fifo_handlers;
     248  int instance;
     249  ino_t ino_count;
     250  const IMFS_node_control *node_controls [IMFS_TYPE_COUNT];
    219251} IMFS_fs_info_t;
    220252
     
    223255 */
    224256
    225 extern const rtems_filesystem_file_handlers_r       IMFS_directory_handlers;
    226 extern const rtems_filesystem_file_handlers_r       IMFS_device_handlers;
    227 extern const rtems_filesystem_file_handlers_r       IMFS_link_handlers;
    228 extern const rtems_filesystem_file_handlers_r       IMFS_memfile_handlers;
    229 extern const rtems_filesystem_file_handlers_r       IMFS_fifo_handlers;
    230 extern const rtems_filesystem_operations_table      IMFS_ops;
    231 extern const rtems_filesystem_operations_table      fifoIMFS_ops;
     257extern const IMFS_node_control IMFS_node_control_directory;
     258extern const IMFS_node_control IMFS_node_control_device;
     259extern const IMFS_node_control IMFS_node_control_hard_link;
     260extern const IMFS_node_control IMFS_node_control_sym_link;
     261extern const IMFS_node_control IMFS_node_control_memfile;
     262extern const IMFS_node_control IMFS_node_control_linfile;
     263extern const IMFS_node_control IMFS_node_control_fifo;
     264extern const IMFS_node_control IMFS_node_control_default;
     265
     266extern const rtems_filesystem_operations_table miniIMFS_ops;
     267extern const rtems_filesystem_operations_table IMFS_ops;
     268extern const rtems_filesystem_operations_table fifoIMFS_ops;
     269
    232270extern const rtems_filesystem_limits_and_options_t  IMFS_LIMITS_AND_OPTIONS;
    233271
     
    252290
    253291extern int IMFS_initialize_support(
    254    rtems_filesystem_mount_table_entry_t       *mt_entry,
    255    const rtems_filesystem_operations_table    *op_table,
    256    const rtems_filesystem_file_handlers_r     *link_handlers,
    257    const rtems_filesystem_file_handlers_r     *fifo_handlers
     292  rtems_filesystem_mount_table_entry_t *mt_entry,
     293  const rtems_filesystem_operations_table *op_table,
     294  const IMFS_node_control *const node_controls [IMFS_TYPE_COUNT]
    258295);
    259296
     
    291328);
    292329
    293 extern void IMFS_Set_handlers( rtems_filesystem_location_info_t *loc );
    294 
    295330extern void IMFS_eval_path(
    296331  rtems_filesystem_eval_path_context_t *ctx
     
    319354
    320355extern IMFS_jnode_t *IMFS_allocate_node(
    321   IMFS_jnode_types_t                type,         /* IN  */
    322   const char                       *name,         /* IN  */
    323   size_t                            namelen,      /* IN  */
    324   mode_t                            mode          /* IN  */
    325 );
    326 
    327 extern IMFS_jnode_t *IMFS_create_root_node(void);
    328 
    329 extern IMFS_jnode_t *IMFS_create_node(
    330   const rtems_filesystem_location_info_t *pathloc, /* IN  */
    331   IMFS_jnode_types_t                      type,    /* IN  */
    332   const char                             *name,    /* IN  */
    333   size_t                                  namelen, /* IN  */
    334   mode_t                                  mode,    /* IN  */
    335   const IMFS_types_union                 *info     /* IN  */
     356  IMFS_fs_info_t *fs_info,
     357  const IMFS_node_control *node_control,
     358  const char *name,
     359  size_t namelen,
     360  mode_t mode,
     361  const IMFS_types_union *info
     362);
     363
     364extern IMFS_jnode_t *IMFS_create_node_with_control(
     365  const rtems_filesystem_location_info_t *parentloc,
     366  const IMFS_node_control *node_control,
     367  const char *name,
     368  size_t namelen,
     369  mode_t mode,
     370  const IMFS_types_union *info
    336371);
    337372
     
    344379);
    345380
    346 extern int IMFS_memfile_remove(
     381extern IMFS_jnode_t *IMFS_memfile_remove(
    347382 IMFS_jnode_t  *the_jnode         /* IN/OUT */
    348383);
     
    483518  #define IMFS_assert(_x)
    484519#endif
     520
     521static inline void IMFS_Set_handlers( rtems_filesystem_location_info_t *loc )
     522{
     523  IMFS_jnode_t *node = (IMFS_jnode_t *) loc->node_access;
     524
     525  loc->handlers = node->control->handlers;
     526}
    485527
    486528static inline void IMFS_add_to_directory(
     
    502544static inline IMFS_jnode_types_t IMFS_type( const IMFS_jnode_t *node )
    503545{
    504   return node->type;
     546  return node->control->imfs_type;
    505547}
    506548
    507549static inline bool IMFS_is_directory( const IMFS_jnode_t *node )
    508550{
    509   return node->type == IMFS_DIRECTORY;
     551  return node->control->imfs_type == IMFS_DIRECTORY;
     552}
     553
     554static inline IMFS_jnode_t *IMFS_create_node(
     555  const rtems_filesystem_location_info_t *parentloc,
     556  IMFS_jnode_types_t type,
     557  const char *name,
     558  size_t namelen,
     559  mode_t mode,
     560  const IMFS_types_union *info
     561)
     562{
     563  const IMFS_fs_info_t *fs_info =
     564    (const IMFS_fs_info_t *) parentloc->mt_entry->fs_info;
     565
     566  return IMFS_create_node_with_control(
     567    parentloc,
     568    fs_info->node_controls [type],
     569    name,
     570    namelen,
     571    mode,
     572    info
     573  );
    510574}
    511575
  • cpukit/libfs/src/imfs/imfs_creat.c

    r70927458 r699ac7c  
    2323#include <string.h>
    2424
    25 static void IMFS_initialize_directory( IMFS_jnode_t *dir )
    26 {
    27   rtems_chain_initialize_empty( &dir->info.directory.Entries );
    28 }
    29 
    30 /*
    31  *  Create an IMFS filesystem node of an arbitrary type that is NOT
    32  *  the root directory node.
    33  */
    34 IMFS_jnode_t *IMFS_create_node(
    35   const rtems_filesystem_location_info_t *parent_loc,
    36   IMFS_jnode_types_t                      type,
    37   const char                             *name,
    38   size_t                                  namelen,
    39   mode_t                                  mode,
    40   const IMFS_types_union                 *info
    41 )
    42 {
    43   IMFS_jnode_t        *node;
    44   IMFS_jnode_t        *parent;
    45   IMFS_fs_info_t      *fs_info;
    46 
    47   parent = parent_loc->node_access;
    48   fs_info = parent_loc->mt_entry->fs_info;
    49 
    50   /*
    51    *  Allocate filesystem node and fill in basic information
    52    */
    53   node  = IMFS_allocate_node( type, name, namelen, mode );
    54   if ( !node )
    55     return NULL;
    56 
    57   /*
    58    *  Set the type specific information
    59    */
    60   if ( type == IMFS_DIRECTORY ) {
    61     IMFS_initialize_directory( node );
    62   } else if ( type == IMFS_HARD_LINK ) {
    63     node->info.hard_link.link_node = info->hard_link.link_node;
    64   } else if ( type == IMFS_SYM_LINK ) {
    65     node->info.sym_link.name = info->sym_link.name;
    66   } else if ( type == IMFS_DEVICE ) {
    67     node->info.device.major = info->device.major;
    68     node->info.device.minor = info->device.minor;
    69   } else if ( type == IMFS_LINEAR_FILE ) {
    70     node->info.linearfile.size      = 0;
    71     node->info.linearfile.direct    = 0;
    72   } else if ( type == IMFS_MEMORY_FILE ) {
    73       node->info.file.size            = 0;
    74       node->info.file.indirect        = 0;
    75       node->info.file.doubly_indirect = 0;
    76       node->info.file.triply_indirect = 0;
    77   } else if ( type == IMFS_FIFO ) {
    78     node->info.fifo.pipe = NULL;
    79   } else {
    80     IMFS_assert(0);
    81   }
    82 
    83   /*
    84    *  This node MUST have a parent, so put it in that directory list.
    85    */
    86   IMFS_assert( parent != NULL );
    87   IMFS_add_to_directory( parent, node );
    88 
    89   node->st_ino = ++fs_info->ino_count;
    90 
    91   return node;
    92 }
    93 
    94 /*
    95  *  Allocate filesystem node and fill in basic information
    96  */
    9725IMFS_jnode_t *IMFS_allocate_node(
    98   IMFS_jnode_types_t                type,
    99   const char                       *name,
    100   size_t                            namelen,
    101   mode_t                            mode
     26  IMFS_fs_info_t *fs_info,
     27  const IMFS_node_control *node_control,
     28  const char *name,
     29  size_t namelen,
     30  mode_t mode,
     31  const IMFS_types_union *info
    10232)
    10333{
     
    11040    return NULL;
    11141  }
     42
     43  gettimeofday( &tv, 0 );
    11244
    11345  /*
     
    12658  node->reference_count = 1;
    12759  node->st_nlink = 1;
    128   node->type     = type;
    12960  memcpy( node->name, name, namelen );
    13061  node->name [namelen] = '\0';
     62  node->control = node_control;
    13163
    13264  /*
     
    14577   *  Now set all the times.
    14678   */
    147   gettimeofday( &tv, 0 );
    14879
    14980  node->stat_atime  = (time_t) tv.tv_sec;
    15081  node->stat_mtime  = (time_t) tv.tv_sec;
    15182  node->stat_ctime  = (time_t) tv.tv_sec;
     83  node->st_ino = ++fs_info->ino_count;
     84
     85  return (*node->control->node_initialize)( node, info );
     86}
     87
     88/*
     89 *  Create an IMFS filesystem node of an arbitrary type that is NOT
     90 *  the root directory node.
     91 */
     92IMFS_jnode_t *IMFS_create_node_with_control(
     93  const rtems_filesystem_location_info_t *parentloc,
     94  const IMFS_node_control *node_control,
     95  const char *name,
     96  size_t namelen,
     97  mode_t mode,
     98  const IMFS_types_union *info
     99)
     100{
     101  IMFS_fs_info_t *fs_info = parentloc->mt_entry->fs_info;
     102  IMFS_jnode_t *node = IMFS_allocate_node(
     103    fs_info,
     104    node_control,
     105    name,
     106    namelen,
     107    mode,
     108    info
     109  );
     110
     111  if ( node != NULL ) {
     112    IMFS_jnode_t *parent = parentloc->node_access;
     113
     114    /*
     115     *  This node MUST have a parent, so put it in that directory list.
     116     */
     117    IMFS_assert( parent != NULL );
     118    IMFS_add_to_directory( parent, node );
     119  }
    152120
    153121  return node;
    154122}
    155123
    156 IMFS_jnode_t *IMFS_create_root_node(void)
    157 {
    158   IMFS_jnode_t        *node;
    159 
    160   /*
    161    *  Allocate filesystem node and fill in basic information
    162    */
    163   node = IMFS_allocate_node( IMFS_DIRECTORY, "", 0, (S_IFDIR | 0755) );
    164   if ( !node )
    165     return NULL;
    166 
    167   /*
    168    *  Set the type specific information
    169    *
    170    *  NOTE: Root node is always a directory.
    171    */
    172   IMFS_initialize_directory( node );
    173 
    174   return node;
    175 }
  • cpukit/libfs/src/imfs/imfs_eval.c

    r70927458 r699ac7c  
    1818
    1919#include "imfs.h"
    20 
    21 void IMFS_Set_handlers( rtems_filesystem_location_info_t *loc )
    22 {
    23   IMFS_jnode_t *node = loc->node_access;
    24   IMFS_fs_info_t *fs_info = loc->mt_entry->fs_info;
    25   const rtems_filesystem_file_handlers_r *handlers;
    26 
    27   switch ( node->type ) {
    28     case IMFS_DIRECTORY:
    29       handlers = &IMFS_directory_handlers;
    30       break;
    31     case IMFS_DEVICE:
    32       handlers = &IMFS_device_handlers;
    33       break;
    34     case IMFS_HARD_LINK:
    35     case IMFS_SYM_LINK:
    36       handlers = fs_info->link_handlers;
    37       break;
    38     case IMFS_MEMORY_FILE:
    39     case IMFS_LINEAR_FILE:
    40       handlers = &IMFS_memfile_handlers;
    41       break;
    42     case IMFS_FIFO:
    43       handlers = fs_info->fifo_handlers;
    44       break;
    45     default:
    46       IMFS_assert( 0 );
    47       break;
    48   }
    49 
    50   loc->handlers = handlers;
    51 }
    5220
    5321static bool IMFS_eval_is_directory(
  • cpukit/libfs/src/imfs/imfs_fifo.c

    r70927458 r699ac7c  
    120120}
    121121
    122 /*
    123  *  Handler table for IMFS FIFO nodes
    124  */
    125 
    126 const rtems_filesystem_file_handlers_r IMFS_fifo_handlers = {
     122static const rtems_filesystem_file_handlers_r IMFS_fifo_handlers = {
    127123  IMFS_fifo_open,
    128124  IMFS_fifo_close,
     
    137133  rtems_filesystem_default_fcntl
    138134};
     135
     136const IMFS_node_control IMFS_node_control_fifo = {
     137  .imfs_type = IMFS_FIFO,
     138  .handlers = &IMFS_fifo_handlers,
     139  .node_initialize = IMFS_node_initialize_default,
     140  .node_remove = IMFS_node_remove_default,
     141  .node_destroy = IMFS_node_destroy_default
     142};
  • cpukit/libfs/src/imfs/imfs_handlers_device.c

    r70927458 r699ac7c  
    1818#include "imfs.h"
    1919
    20 /*
    21  *  Handler table for IMFS device nodes
    22  */
    23 
    24 const rtems_filesystem_file_handlers_r IMFS_device_handlers = {
     20static const rtems_filesystem_file_handlers_r IMFS_device_handlers = {
    2521  device_open,
    2622  device_close,
     
    3531  rtems_filesystem_default_fcntl
    3632};
     33
     34static IMFS_jnode_t *IMFS_node_initialize_device(
     35  IMFS_jnode_t *node,
     36  const IMFS_types_union *info
     37)
     38{
     39  node->info.device.major = info->device.major;
     40  node->info.device.minor = info->device.minor;
     41
     42  return node;
     43}
     44
     45const IMFS_node_control IMFS_node_control_device = {
     46  .imfs_type = IMFS_DEVICE,
     47  .handlers = &IMFS_device_handlers,
     48  .node_initialize = IMFS_node_initialize_device,
     49  .node_remove = IMFS_node_remove_default,
     50  .node_destroy = IMFS_node_destroy_default
     51};
  • cpukit/libfs/src/imfs/imfs_handlers_directory.c

    r70927458 r699ac7c  
    1818#include "imfs.h"
    1919
    20 /*
    21  *  Set of operations handlers for operations on directories.
    22  */
    23 
    24 const rtems_filesystem_file_handlers_r IMFS_directory_handlers = {
     20static const rtems_filesystem_file_handlers_r IMFS_directory_handlers = {
    2521  rtems_filesystem_default_open,
    2622  rtems_filesystem_default_close,
     
    3531  rtems_filesystem_default_fcntl
    3632};
     33
     34static IMFS_jnode_t *IMFS_node_initialize_directory(
     35  IMFS_jnode_t *node,
     36  const IMFS_types_union *info
     37)
     38{
     39  rtems_chain_initialize_empty( &node->info.directory.Entries );
     40
     41  return node;
     42}
     43
     44static bool IMFS_is_mount_point( const IMFS_jnode_t *node )
     45{
     46  return node->info.directory.mt_fs != NULL;
     47}
     48
     49static IMFS_jnode_t *IMFS_node_remove_directory(
     50  IMFS_jnode_t *node,
     51  const IMFS_jnode_t *root_node
     52)
     53{
     54  if ( !rtems_chain_is_empty( &node->info.directory.Entries ) ) {
     55    errno = ENOTEMPTY;
     56    node = NULL;
     57  } else if ( node == root_node || IMFS_is_mount_point( node ) ) {
     58    errno = EBUSY;
     59    node = NULL;
     60  }
     61
     62  return node;
     63}
     64
     65const IMFS_node_control IMFS_node_control_directory = {
     66  .imfs_type = IMFS_DIRECTORY,
     67  .handlers = &IMFS_directory_handlers,
     68  .node_initialize = IMFS_node_initialize_directory,
     69  .node_remove = IMFS_node_remove_directory,
     70  .node_destroy = IMFS_node_destroy_default
     71};
  • cpukit/libfs/src/imfs/imfs_handlers_link.c

    r70927458 r699ac7c  
    1818#include "imfs.h"
    1919
    20 /*
    21  *  Handler table for IMFS device nodes
    22  */
     20#include <stdlib.h>
    2321
    24 const rtems_filesystem_file_handlers_r IMFS_link_handlers = {
     22static const rtems_filesystem_file_handlers_r IMFS_link_handlers = {
    2523  rtems_filesystem_default_open,
    2624  rtems_filesystem_default_close,
     
    3533  rtems_filesystem_default_fcntl
    3634};
     35
     36static IMFS_jnode_t *IMFS_node_initialize_hard_link(
     37  IMFS_jnode_t *node,
     38  const IMFS_types_union *info
     39)
     40{
     41  node->info.hard_link.link_node = info->hard_link.link_node;
     42
     43  return node;
     44}
     45
     46static IMFS_jnode_t *IMFS_node_remove_hard_link(
     47  IMFS_jnode_t *node,
     48  const IMFS_jnode_t *root_node
     49)
     50{
     51  IMFS_jnode_t *target = node->info.hard_link.link_node;
     52
     53  if ( target->st_nlink == 1) {
     54    target = (*target->control->node_remove)( target, root_node );
     55    if ( target == NULL ) {
     56      node = NULL;
     57    }
     58  } else {
     59    --target->st_nlink;
     60    IMFS_update_ctime( target );
     61  }
     62
     63  return node;
     64}
     65
     66const IMFS_node_control IMFS_node_control_hard_link = {
     67  .imfs_type = IMFS_HARD_LINK,
     68  .handlers = &IMFS_link_handlers,
     69  .node_initialize = IMFS_node_initialize_hard_link,
     70  .node_remove = IMFS_node_remove_hard_link,
     71  .node_destroy = IMFS_node_destroy_default
     72};
     73
     74static IMFS_jnode_t *IMFS_node_initialize_sym_link(
     75  IMFS_jnode_t *node,
     76  const IMFS_types_union *info
     77)
     78{
     79  node->info.sym_link.name = info->sym_link.name;
     80
     81  return node;
     82}
     83
     84static IMFS_jnode_t *IMFS_node_destroy_sym_link( IMFS_jnode_t *node )
     85{
     86  free( node->info.sym_link.name );
     87
     88  return node;
     89}
     90
     91const IMFS_node_control IMFS_node_control_sym_link = {
     92  .imfs_type = IMFS_SYM_LINK,
     93  .handlers = &IMFS_link_handlers,
     94  .node_initialize = IMFS_node_initialize_sym_link,
     95  .node_remove = IMFS_node_remove_default,
     96  .node_destroy = IMFS_node_destroy_sym_link
     97};
  • cpukit/libfs/src/imfs/imfs_handlers_memfile.c

    r70927458 r699ac7c  
    1818#include "imfs.h"
    1919
    20 /*
    21  *  Set of operations handlers for operations on memfile entities.
    22  */
    23 
    24 const rtems_filesystem_file_handlers_r IMFS_memfile_handlers = {
     20static const rtems_filesystem_file_handlers_r IMFS_memfile_handlers = {
    2521  memfile_open,
    2622  rtems_filesystem_default_close,
     
    3531  rtems_filesystem_default_fcntl
    3632};
     33
     34const IMFS_node_control IMFS_node_control_memfile = {
     35  .imfs_type = IMFS_MEMORY_FILE,
     36  .handlers = &IMFS_memfile_handlers,
     37  .node_initialize = IMFS_node_initialize_default,
     38  .node_remove = IMFS_node_remove_default,
     39  .node_destroy = IMFS_memfile_remove
     40};
     41
     42const IMFS_node_control IMFS_node_control_linfile = {
     43  .imfs_type = IMFS_LINEAR_FILE,
     44  .handlers = &IMFS_memfile_handlers,
     45  .node_initialize = IMFS_node_initialize_default,
     46  .node_remove = IMFS_node_remove_default,
     47  .node_destroy = IMFS_node_destroy_default
     48};
  • cpukit/libfs/src/imfs/imfs_init.c

    r70927458 r699ac7c  
    4848};
    4949
     50static const IMFS_node_control *const
     51  IMFS_node_controls [IMFS_TYPE_COUNT] = {
     52  [IMFS_DIRECTORY] = &IMFS_node_control_directory,
     53  [IMFS_DEVICE] = &IMFS_node_control_device,
     54  [IMFS_HARD_LINK] = &IMFS_node_control_hard_link,
     55  [IMFS_SYM_LINK] = &IMFS_node_control_sym_link,
     56  [IMFS_MEMORY_FILE] = &IMFS_node_control_memfile,
     57  [IMFS_LINEAR_FILE] = &IMFS_node_control_linfile,
     58  [IMFS_FIFO] = &IMFS_node_control_default
     59};
     60
    5061int IMFS_initialize(
    5162  rtems_filesystem_mount_table_entry_t *mt_entry,
     
    5667    mt_entry,
    5768    &IMFS_ops,
    58     &IMFS_link_handlers,
    59     &rtems_filesystem_handlers_default /* for fifos */
     69    IMFS_node_controls
    6070  );
    6171}
  • cpukit/libfs/src/imfs/imfs_initsupp.c

    r70927458 r699ac7c  
    5151}
    5252
    53 
    54 /*
    55  *  IMFS_initialize
    56  */
    5753int IMFS_initialize_support(
    58   rtems_filesystem_mount_table_entry_t        *temp_mt_entry,
    59    const rtems_filesystem_operations_table    *op_table,
    60    const rtems_filesystem_file_handlers_r     *link_handlers,
    61    const rtems_filesystem_file_handlers_r     *fifo_handlers
     54  rtems_filesystem_mount_table_entry_t *mt_entry,
     55  const rtems_filesystem_operations_table *op_table,
     56  const IMFS_node_control *const node_controls [IMFS_TYPE_COUNT]
    6257)
    6358{
    64   static int                             imfs_instance;
    65   IMFS_fs_info_t                        *fs_info;
    66   IMFS_jnode_t                          *jnode;
     59  static int imfs_instance;
    6760
    68   /*
    69    * determine/check value for imfs_memfile_bytes_per_block
    70    */
    71   IMFS_determine_bytes_per_block(&imfs_memfile_bytes_per_block,
    72                                  imfs_rq_memfile_bytes_per_block,
    73                                  IMFS_MEMFILE_DEFAULT_BYTES_PER_BLOCK);
     61  int rv = 0;
     62  IMFS_fs_info_t *fs_info = calloc( 1, sizeof( *fs_info ) );
    7463
    75   /*
    76    *  Create the root node
    77    *
    78    *  NOTE: UNIX root is 755 and owned by root/root (0/0).
    79    */
    80   temp_mt_entry->mt_fs_root->location.node_access = IMFS_create_root_node();
    81   temp_mt_entry->mt_fs_root->location.handlers = &IMFS_directory_handlers;
    82   temp_mt_entry->mt_fs_root->location.ops = op_table;
    83   temp_mt_entry->pathconf_limits_and_options = IMFS_LIMITS_AND_OPTIONS;
     64  if ( fs_info != NULL ) {
     65    IMFS_jnode_t *root_node;
    8466
    85   /*
    86    * Create custom file system data.
    87    */
    88   fs_info = calloc( 1, sizeof( IMFS_fs_info_t ) );
    89   if ( !fs_info ) {
    90     free(temp_mt_entry->mt_fs_root->location.node_access);
    91     rtems_set_errno_and_return_minus_one(ENOMEM);
     67    fs_info->instance = imfs_instance++;
     68    memcpy(
     69      fs_info->node_controls,
     70      node_controls,
     71      sizeof( fs_info->node_controls )
     72    );
     73
     74    root_node = IMFS_allocate_node(
     75      fs_info,
     76      fs_info->node_controls [IMFS_DIRECTORY],
     77      "",
     78      0,
     79      (S_IFDIR | 0755),
     80      NULL
     81    );
     82    if ( root_node != NULL ) {
     83      mt_entry->fs_info = fs_info;
     84      mt_entry->pathconf_limits_and_options = IMFS_LIMITS_AND_OPTIONS;
     85      mt_entry->mt_fs_root->location.node_access = root_node;
     86      mt_entry->mt_fs_root->location.ops = op_table;
     87      IMFS_Set_handlers( &mt_entry->mt_fs_root->location );
     88    } else {
     89      errno = ENOMEM;
     90      rv = -1;
     91    }
     92  } else {
     93    errno = ENOMEM;
     94    rv = -1;
    9295  }
    93   temp_mt_entry->fs_info = fs_info;
    9496
    95   /*
    96    * Set st_ino for the root to 1.
    97    */
     97  if ( rv == 0 ) {
     98    IMFS_determine_bytes_per_block(
     99      &imfs_memfile_bytes_per_block,
     100      imfs_rq_memfile_bytes_per_block,
     101      IMFS_MEMFILE_DEFAULT_BYTES_PER_BLOCK
     102    );
     103  }
    98104
    99   fs_info->instance              = imfs_instance++;
    100   fs_info->ino_count             = 1;
    101   fs_info->link_handlers         = link_handlers;
    102   fs_info->fifo_handlers         = fifo_handlers;
    103 
    104   jnode = temp_mt_entry->mt_fs_root->location.node_access;
    105   jnode->st_ino = fs_info->ino_count;
    106 
    107   return 0;
     105  return rv;
    108106}
    109107
     
    121119  IMFS_assert( node->reference_count == 0 );
    122120
    123   switch ( node->type ) {
    124     case IMFS_MEMORY_FILE:
    125       IMFS_memfile_remove( node );
    126       break;
    127     case IMFS_SYM_LINK:
    128       free( node->info.sym_link.name );
    129       break;
    130     default:
    131       break;
    132   }
     121  node = (*node->control->node_destroy)( node );
    133122
    134123  free( node );
     
    145134  }
    146135}
     136
     137IMFS_jnode_t *IMFS_node_initialize_default(
     138  IMFS_jnode_t *node,
     139  const IMFS_types_union *info
     140)
     141{
     142  return node;
     143}
     144
     145IMFS_jnode_t *IMFS_node_remove_default(
     146  IMFS_jnode_t *node,
     147  const IMFS_jnode_t *root_node
     148)
     149{
     150  return node;
     151}
     152
     153IMFS_jnode_t *IMFS_node_destroy_default( IMFS_jnode_t *node )
     154{
     155  return node;
     156}
     157
     158const IMFS_node_control IMFS_node_control_default = {
     159  .imfs_type = IMFS_INVALID_NODE,
     160  .handlers = &rtems_filesystem_handlers_default,
     161  .node_initialize = IMFS_node_initialize_default,
     162  .node_remove = IMFS_node_remove_default,
     163  .node_destroy = IMFS_node_destroy_default
     164};
  • cpukit/libfs/src/imfs/imfs_rmnod.c

    r70927458 r699ac7c  
    2424#include "imfs.h"
    2525
    26 static int IMFS_rmnod_directory(
    27   const rtems_filesystem_location_info_t *parentloc,
    28   const rtems_filesystem_location_info_t *loc
    29 )
    30 {
    31   int rv = 0;
    32   IMFS_jnode_t *node = loc->node_access;
    33 
    34   if ( !rtems_chain_is_empty( &node->info.directory.Entries ) ) {
    35     errno = ENOTEMPTY;
    36     rv = -1;
    37   } else if (
    38     rtems_filesystem_location_is_root( loc )
    39       || node->info.directory.mt_fs != NULL
    40   ) {
    41     errno = EBUSY;
    42     rv = -1;
    43   }
    44 
    45   return rv;
    46 }
    47 
    48 static int IMFS_rmnod_hard_link(
    49   const rtems_filesystem_location_info_t *parentloc,
    50   const rtems_filesystem_location_info_t *loc
    51 )
    52 {
    53   int rv = 0;
    54   IMFS_jnode_t *node = loc->node_access;
    55   IMFS_jnode_t *target = node->info.hard_link.link_node;
    56 
    57   if ( target->st_nlink == 1) {
    58     rtems_filesystem_location_info_t target_loc = *loc;
    59 
    60     target_loc.node_access = target;
    61     IMFS_Set_handlers( &target_loc );
    62 
    63     rv = (*target_loc.ops->rmnod_h)( parentloc, &target_loc );
    64   } else {
    65     --target->st_nlink;
    66     IMFS_update_ctime( target );
    67   }
    68 
    69   return rv;
    70 }
    71 
    7226int IMFS_rmnod(
    7327  const rtems_filesystem_location_info_t *parentloc,
     
    7832  IMFS_jnode_t *node = loc->node_access;
    7933
    80   switch ( node->type ) {
    81     case IMFS_DIRECTORY:
    82       rv = IMFS_rmnod_directory( parentloc, loc );
    83       break;
    84     case IMFS_HARD_LINK:
    85       rv = IMFS_rmnod_hard_link( parentloc, loc );
    86       break;
    87     default:
    88       break;
    89   }
    90 
    91   if ( rv == 0 ) {
     34  node = (*node->control->node_remove)(
     35    node,
     36    loc->mt_entry->mt_fs_root->location.node_access
     37  );
     38  if ( node != NULL ) {
    9239    --node->reference_count;
    9340    --node->st_nlink;
     
    9542      IMFS_remove_from_directory( node );
    9643    }
     44  } else {
     45    rv = -1;
    9746  }
    9847
  • cpukit/libfs/src/imfs/memfile.c

    r70927458 r699ac7c  
    9898    const unsigned char *buffer = the_jnode->info.linearfile.direct;
    9999
    100     the_jnode->type = IMFS_MEMORY_FILE;
     100    the_jnode->control = &IMFS_node_control_memfile;
    101101    the_jnode->info.file.size            = 0;
    102102    the_jnode->info.file.indirect        = 0;
     
    421421 *         is better to stick to simple, easy to understand algorithms.
    422422 */
    423 int IMFS_memfile_remove(
     423IMFS_jnode_t *IMFS_memfile_remove(
    424424 IMFS_jnode_t  *the_jnode
    425425)
     
    483483  }
    484484
    485   return 0;
     485  return the_jnode;
    486486}
    487487
  • cpukit/libfs/src/imfs/miniimfs_init.c

    r70927458 r699ac7c  
    2424#include "imfs.h"
    2525
    26 static const rtems_filesystem_operations_table miniIMFS_ops = {
     26const rtems_filesystem_operations_table miniIMFS_ops = {
    2727  .lock_h = rtems_filesystem_default_lock,
    2828  .unlock_h = rtems_filesystem_default_unlock,
     
    4848};
    4949
     50static const IMFS_node_control *const
     51  IMFS_mini_node_controls [IMFS_TYPE_COUNT] = {
     52  [IMFS_DIRECTORY] = &IMFS_node_control_directory,
     53  [IMFS_DEVICE] = &IMFS_node_control_device,
     54  [IMFS_HARD_LINK] = &IMFS_node_control_default,
     55  [IMFS_SYM_LINK] = &IMFS_node_control_default,
     56  [IMFS_MEMORY_FILE] = &IMFS_node_control_memfile,
     57  [IMFS_LINEAR_FILE] = &IMFS_node_control_linfile,
     58  [IMFS_FIFO] = &IMFS_node_control_default
     59};
     60
    5061int miniIMFS_initialize(
    5162  rtems_filesystem_mount_table_entry_t *mt_entry,
     
    5667    mt_entry,
    5768    &miniIMFS_ops,
    58     &rtems_filesystem_handlers_default, /* for links */
    59     &rtems_filesystem_handlers_default  /* for fifos */
     69    IMFS_mini_node_controls
    6070  );
    6171}
Note: See TracChangeset for help on using the changeset viewer.