Ignore:
Timestamp:
Jul 1, 2010, 2:10:54 PM (10 years ago)
Author:
Sebastian Huber <sebastian.huber@…>
Branches:
4.10
Children:
615d8cc
Parents:
f33be44
Message:

2010-06-07 Sebastian Huber <sebastian.huber@…>

  • libcsupport/include/rtems/libio_.h: Declare rtems_filesystem_mount_table_control.
  • libcsupport/include/rtems/libio.h: Removed rtems_filesystem_table_first(), rtems_filesystem_table_next() and rtems_filesystem_table_node_t declarations. Declare rtems_per_filesystem_routine, rtems_filesystem_iterate() and rtems_filesystem_get_mount_handler().
  • libcsupport/src/mount.c: Added rtems_filesystem_mounts_first() and rtems_filesystem_mounts_next(). Simplify mount(). Removed rtems_filesystem_mount_table_control_init. Use rtems_filesystem_get_mount_handler().
  • libcsupport/src/mount-mgr.c: Removed rtems_filesystem_mounts_first() and rtems_filesystem_mounts_next(). Added rtems_filesystem_iterate() and rtems_filesystem_get_mount_handler(). Use rtems_libio_lock() and rtems_libio_unlock();
  • sapi/include/confdefs.h, libmisc/shell/main_mount.c: Update for mount API changes.

2010-06-07 Bharath Suri <bharath.s.jois@…>

  • libcsupport/include/rtems/libio_.h: Removed macros rtems_filesystem_is_separator rtems_filesystem_get_start_loc rtems_filesystem_get_sym_start_loc and added them as files under libcsupport/src/
  • libcsupport/src/: Added new files libcsupport/src/sup_fs_get_start_loc.c libcsupport/src/sup_fs_get_sym_start_loc.c libcsupport/src/sup_fs_is_separator.c
  • libcsupport/Makefile.am: Changes to accommodate new files under libcsupport/src/
File:
1 edited

Legend:

Unmodified
Added
Removed
  • cpukit/libcsupport/src/mount-mgr.c

    rf33be44 r00bf6744  
    66 *
    77 *  COPYRIGHT (c) Chris Johns <chrisj@rtems.org> 2010.
     8 *
     9 *  Copyright (c) 2010 embedded brains GmbH.
    810 *
    911 *  The license and distribution terms for this file may be
     
    3133#include <rtems/libio_.h>
    3234
    33 /*
    34  * External defined by confdefs.h or the user.
    35  */
    36 extern const rtems_filesystem_table_t configuration_filesystem_table[];
     35typedef struct {
     36  rtems_chain_node node;
     37  rtems_filesystem_table_t entry;
     38} filesystem_node;
    3739
    38 /*
    39  * Points to a list of filesystems added at runtime.
    40  */
    41 extern rtems_chain_control *rtems_filesystem_table;
     40RTEMS_CHAIN_DEFINE_EMPTY(filesystem_chain);
    4241
    43 /*
    44  * Mount table list.
    45  */
    46 extern rtems_chain_control rtems_filesystem_mount_table_control;
    47 extern bool                rtems_filesystem_mount_table_control_init;
    48 
    49 /*
    50  * Get the first entry in the filesystem table.
    51  */
    52 const rtems_filesystem_table_t*
    53 rtems_filesystem_table_first(
    54   void
     42void
     43rtems_filesystem_iterate(
     44  rtems_per_filesystem_routine routine,
     45  void *routine_arg
    5546)
    5647{
    57   /*
    58    * We can assume this because it is the root file system.
    59    */
    60   return &configuration_filesystem_table[0];
     48  const rtems_filesystem_table_t *table_entry = &rtems_filesystem_table [0];
     49  rtems_chain_node *node = NULL;
     50
     51  while ( table_entry->type ) {
     52    if ( !(*routine)( table_entry, routine_arg ) ) {
     53      break;
     54    }
     55
     56    ++table_entry;
     57  }
     58
     59  rtems_libio_lock();
     60  for (
     61    node = rtems_chain_first( &filesystem_chain );
     62    !rtems_chain_is_tail( &filesystem_chain, node );
     63    node = rtems_chain_next( node )
     64  ) {
     65    const filesystem_node *fsn = (filesystem_node *) node;
     66
     67    if ( !(*routine)( &fsn->entry, routine_arg ) ) {
     68      break;
     69    }
     70  }
     71  rtems_libio_unlock();
    6172}
    6273
    63 /*
    64  * Get the next entry in the file system table.
    65  */
    66 const rtems_filesystem_table_t*
    67 rtems_filesystem_table_next(
    68   const rtems_filesystem_table_t *entry
     74typedef struct {
     75  const char *type;
     76  rtems_filesystem_fsmount_me_t mount_h;
     77} find_arg;
     78
     79static bool find_handler(const rtems_filesystem_table_t *entry, void *arg)
     80{
     81  find_arg *fa = arg;
     82
     83  if ( strcmp( entry->type, fa->type ) != 0 ) {
     84    return true;
     85  } else {
     86    fa->mount_h = entry->mount_h;
     87
     88    return true;
     89  }
     90}
     91
     92rtems_filesystem_fsmount_me_t
     93rtems_filesystem_get_mount_handler(
     94  const char *type
    6995)
    7096{
    71   const rtems_filesystem_table_t* fs;
     97  find_arg fa = {
     98    .type = type,
     99    .mount_h = NULL
     100  };
    72101
    73   fs = rtems_filesystem_table_first( );
    74  
    75   while ( fs->type && ( fs != entry ) )
    76     ++fs;
    77  
    78   if ( fs->type ) {
    79     ++fs;
    80     if ( fs->type )
    81       return fs;
     102  if ( type != NULL ) {
     103    rtems_filesystem_iterate( find_handler, &fa );
    82104  }
    83105
    84   if ( rtems_filesystem_table ) {
    85     rtems_chain_node* node;
    86     for (node = rtems_chain_first( rtems_filesystem_table );
    87          !rtems_chain_is_tail( rtems_filesystem_table, node);
    88          node = rtems_chain_next( node )) {
    89       rtems_filesystem_table_node_t* tnode;
    90       tnode = (rtems_filesystem_table_node_t*) node;
    91       if ( entry == &tnode->entry ) {
    92         node = rtems_chain_next( node );
    93         if ( !rtems_chain_is_tail( rtems_filesystem_table, node ) ) {
    94           tnode = (rtems_filesystem_table_node_t*) node;
    95           return &tnode->entry;
    96         }
    97       }
    98     }
    99   }
    100  
    101   return NULL;
     106  return fa.mount_h;
    102107}
    103108
    104 /*
    105  * Get the first entry in the mount table.
    106  */
    107 rtems_filesystem_mount_table_entry_t*
    108 rtems_filesystem_mounts_first(
    109   void
    110 )
    111 {
    112   rtems_filesystem_mount_table_entry_t* entry = NULL;
    113   if ( rtems_filesystem_mount_table_control_init ) {
    114     if ( !rtems_chain_is_empty( &rtems_filesystem_mount_table_control ) )
    115       entry = (rtems_filesystem_mount_table_entry_t*)
    116         rtems_chain_first( &rtems_filesystem_mount_table_control );
    117   }
    118   return entry;
    119 }
    120 
    121 /*
    122  * Get the next entry in the mount table.
    123  */
    124 rtems_filesystem_mount_table_entry_t*
    125 rtems_filesystem_mounts_next(
    126   rtems_filesystem_mount_table_entry_t *entry
    127 )
    128 {
    129   if ( !rtems_filesystem_mount_table_control_init || !entry )
    130     return NULL;
    131   return (rtems_filesystem_mount_table_entry_t*) rtems_chain_next( &entry->Node );
    132 }
    133 
    134 /*
    135  * Register a file system.
    136  */
    137109int
    138110rtems_filesystem_register(
     
    141113)
    142114{
    143   rtems_filesystem_table_node_t *fs;
    144   if ( !rtems_filesystem_table ) {
    145     rtems_filesystem_table = malloc( sizeof( rtems_chain_control ) );
    146     if ( !rtems_filesystem_table )
    147       rtems_set_errno_and_return_minus_one( ENOMEM );
    148     rtems_chain_initialize_empty ( rtems_filesystem_table );
     115  size_t fsn_size = sizeof( filesystem_node ) + strlen(type) + 1;
     116  filesystem_node *fsn = malloc( fsn_size );
     117  char *type_storage = (char *) fsn + sizeof( filesystem_node );
     118
     119  if ( fsn == NULL )
     120    rtems_set_errno_and_return_minus_one( ENOMEM );
     121
     122  strcpy(type_storage, type);
     123  fsn->entry.type = type_storage;
     124  fsn->entry.mount_h = mount_h;
     125
     126  rtems_libio_lock();
     127  if ( rtems_filesystem_get_mount_handler( type ) == NULL ) {
     128    rtems_chain_append( &filesystem_chain, &fsn->node );
     129  } else {
     130    rtems_libio_unlock();
     131    free( fsn );
     132
     133    rtems_set_errno_and_return_minus_one( EINVAL );
    149134  }
    150   fs = malloc( sizeof( rtems_filesystem_table_node_t ) );
    151   if ( !fs )
    152     rtems_set_errno_and_return_minus_one( ENOMEM );
    153   fs->entry.type = strdup( type );
    154   if ( !fs->entry.type ) {
    155     free( fs );
    156     rtems_set_errno_and_return_minus_one( ENOMEM );
    157   }   
    158   fs->entry.mount_h = mount_h;
    159   rtems_chain_append( rtems_filesystem_table, &fs->node );
     135  rtems_libio_unlock();
     136
    160137  return 0;
    161138}
    162139
    163 /*
    164  * Unregister a file system.
    165  */
    166140int
    167141rtems_filesystem_unregister(
     
    169143)
    170144{
    171   if ( rtems_filesystem_table ) {
    172     rtems_chain_node *node;
    173     for (node = rtems_chain_first( rtems_filesystem_table );
    174          !rtems_chain_is_tail( rtems_filesystem_table, node );
    175          node = rtems_chain_next( node ) ) {
    176       rtems_filesystem_table_node_t *fs;
    177       fs = (rtems_filesystem_table_node_t*) node;
    178       if ( strcmp( fs->entry.type, type ) == 0 ) {
    179         rtems_chain_extract( node );
    180         free( (void*) fs->entry.type );
    181         free( fs );
    182         return 0;
    183       }
     145  rtems_chain_node *node = NULL;
     146
     147  if ( type == NULL ) {
     148    rtems_set_errno_and_return_minus_one( EINVAL );
     149  }
     150
     151  rtems_libio_lock();
     152  for (
     153    node = rtems_chain_first( &filesystem_chain );
     154    !rtems_chain_is_tail( &filesystem_chain, node );
     155    node = rtems_chain_next( node )
     156  ) {
     157    filesystem_node *fsn = (filesystem_node *) node;
     158
     159    if ( strcmp( fsn->entry.type, type ) == 0 ) {
     160      rtems_chain_extract( node );
     161      free( fsn );
     162      rtems_libio_unlock();
     163
     164      return 0;
    184165    }
    185166  }
     167  rtems_libio_unlock();
     168
    186169  rtems_set_errno_and_return_minus_one( ENOENT );
    187170}
Note: See TracChangeset for help on using the changeset viewer.