Changeset 00bf6744 in rtems for cpukit/libcsupport/src/mount.c


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.c

    rf33be44 r00bf6744  
    1111 *  On-Line Applications Research Corporation (OAR).
    1212 *
     13 *  Copyright (c) 2010 embedded brains GmbH.
     14 *
    1315 *  The license and distribution terms for this file may be
    1416 *  found in the file LICENSE in this distribution or at
     
    2527#include <sys/stat.h>
    2628#include <rtems/chain.h>
     29#include <rtems/seterr.h>
    2730#include <fcntl.h>
    2831#include <unistd.h>
     
    3538
    3639/*
    37  * External defined by confdefs.h or the user.
    38  */
    39 extern const rtems_filesystem_table_t configuration_filesystem_table[];
    40 
    41 /*
    42  * Points to a list of filesystems added at runtime.
    43  */
    44 rtems_chain_control *rtems_filesystem_table;
    45 
    46 /*
    4740 * Mount table list.
    4841 */
    49 rtems_chain_control rtems_filesystem_mount_table_control;
    50 bool                rtems_filesystem_mount_table_control_init;
     42RTEMS_CHAIN_DEFINE_EMPTY(rtems_filesystem_mount_table_control);
    5143
    5244/*
     
    8072
    8173static bool Is_node_fs_root(
    82   rtems_filesystem_location_info_t  *loc
    83 )
    84 {
    85   rtems_chain_node                     *the_node;
    86   rtems_filesystem_mount_table_entry_t *the_mount_entry;
     74  rtems_filesystem_location_info_t *loc
     75)
     76{
     77  rtems_chain_node *node = NULL;
    8778
    8879  /*
    8980   * For each mount table entry
    9081   */
    91   if ( rtems_filesystem_mount_table_control_init ) {
    92     for ( the_node = rtems_chain_first( &rtems_filesystem_mount_table_control );
    93           !rtems_chain_is_tail( &rtems_filesystem_mount_table_control, the_node );
    94           the_node = rtems_chain_next( the_node ) ) {
    95       the_mount_entry = (rtems_filesystem_mount_table_entry_t *) the_node;
    96       if ( the_mount_entry->mt_fs_root.node_access  == loc->node_access )
    97         return true;
    98     }
     82  for ( node = rtems_chain_first( &rtems_filesystem_mount_table_control );
     83        !rtems_chain_is_tail( &rtems_filesystem_mount_table_control, node );
     84        node = rtems_chain_next( node ) ) {
     85    rtems_filesystem_mount_table_entry_t *mount_table_entry =
     86      (rtems_filesystem_mount_table_entry_t *) node;
     87
     88    if ( mount_table_entry->mt_fs_root.node_access == loc->node_access )
     89      return true;
    9990  }
     91
    10092  return false;
     93}
     94
     95static rtems_filesystem_mount_table_entry_t *alloc_mount_table_entry(
     96  const char *source,
     97  const char *target,
     98  const char *filesystemtype,
     99  size_t *target_length_ptr
     100)
     101{
     102  const char *target_str = target ? target : "/";
     103  size_t filesystemtype_size = strlen( filesystemtype ) + 1;
     104  size_t source_size = source ? strlen( source ) + 1 : 0;
     105  size_t target_length = strlen( target_str );
     106  size_t size = sizeof( rtems_filesystem_mount_table_entry_t )
     107    + filesystemtype_size + source_size + target_length + 1;
     108  rtems_filesystem_mount_table_entry_t *mt_entry = calloc( 1, size );
     109
     110  if ( mt_entry ) {
     111    char *str = (char *) mt_entry + sizeof( *mt_entry );
     112
     113    mt_entry->type = str;
     114    strcpy( str, filesystemtype );
     115
     116    if ( source ) {
     117      str += filesystemtype_size;
     118      mt_entry->dev = str;
     119      strcpy( str, source );
     120    }
     121
     122    str += source_size;
     123    mt_entry->target = str;
     124    strcpy( str, target );
     125  }
     126
     127  *target_length_ptr = target_length;
     128
     129  return mt_entry;
    101130}
    102131
     
    122151  rtems_filesystem_options_t options,
    123152  const void                 *data
    124           )
    125 {
    126   const rtems_filesystem_table_t       *entry;
     153)
     154{
     155  rtems_filesystem_fsmount_me_t mount_h = NULL;
    127156  rtems_filesystem_location_info_t      loc;
    128157  rtems_filesystem_mount_table_entry_t *mt_entry = NULL;
    129158  rtems_filesystem_location_info_t     *loc_to_free = NULL;
    130   size_t size;
    131 
    132   /*
    133    * If mount is ever called we allocate the mount table control structure.
    134    */
    135   if ( !rtems_filesystem_mount_table_control_init ) {
    136     rtems_filesystem_mount_table_control_init = true;
    137     rtems_chain_initialize_empty ( &rtems_filesystem_mount_table_control );
    138   }
     159  bool has_target = target != NULL;
     160  size_t target_length = 0;
    139161
    140162  /*
     
    143165
    144166  if ( options != RTEMS_FILESYSTEM_READ_ONLY &&
    145        options != RTEMS_FILESYSTEM_READ_WRITE ) {
    146     errno = EINVAL;
    147     return -1;
    148   }
    149 
    150   /*
    151    * Check the type.
    152    */
    153   if (!filesystemtype) {
    154     errno = EINVAL;
    155     return -1;
    156   }
    157 
    158   if (strlen(filesystemtype) >= 128) {
    159     errno = EINVAL;
    160     return -1;
    161   }
    162    
    163   /*
    164    * Check the configuration table filesystems then check any runtime added
    165    * file systems.
    166    */
    167   entry = &configuration_filesystem_table[0];
    168   while (entry->type) {
    169     if (strcmp (filesystemtype, entry->type) == 0)
    170       break;
    171     ++entry;
    172   }
    173  
    174   if (!entry->type) {
    175     entry = NULL;
    176     if (rtems_filesystem_table) {
    177       rtems_chain_node *the_node;
    178       for (the_node = rtems_chain_first(rtems_filesystem_table);
    179            !rtems_chain_is_tail(rtems_filesystem_table, the_node);
    180            the_node = rtems_chain_next(the_node)) {
    181         entry = &(((rtems_filesystem_table_node_t*) the_node)->entry);
    182         if (strcmp (filesystemtype, entry->type) == 0)
    183           break;
    184         entry = NULL;
    185       }
    186     }
    187   }
    188 
    189   if (!entry)
    190   {
    191     errno = EINVAL;
    192     return -1;
    193   }
    194  
     167       options != RTEMS_FILESYSTEM_READ_WRITE )
     168    rtems_set_errno_and_return_minus_one( EINVAL );
     169
     170  /*
     171   *  Get mount handler
     172   */
     173  mount_h = rtems_filesystem_get_mount_handler( filesystemtype );
     174  if ( !mount_h )
     175    rtems_set_errno_and_return_minus_one( EINVAL );
     176
    195177  /*
    196178   * Allocate a mount table entry
    197179   */
    198 
    199   size = sizeof(rtems_filesystem_mount_table_entry_t);
    200   if ( source )
    201     size += strlen( source ) + 1;
    202    
    203   mt_entry = malloc( size );
    204   if ( !mt_entry ) {
    205     errno = ENOMEM;
    206     return -1;
    207   }
    208 
    209   memset( mt_entry, 0, size );
    210    
     180  mt_entry = alloc_mount_table_entry(
     181    source,
     182    target,
     183    filesystemtype,
     184    &target_length
     185  );
     186  if ( !mt_entry )
     187    rtems_set_errno_and_return_minus_one( ENOMEM );
     188
    211189  mt_entry->mt_fs_root.mt_entry = mt_entry;
    212   mt_entry->type = entry->type;
    213190  mt_entry->options = options;
    214191  mt_entry->pathconf_limits_and_options = rtems_filesystem_default_pathconf;
    215    
    216   if ( source ) {
    217     mt_entry->dev =
    218       (char *)mt_entry + sizeof( rtems_filesystem_mount_table_entry_t );
    219     strcpy( mt_entry->dev, source );
    220   } else
    221     mt_entry->dev = 0;
    222192
    223193  /*
     
    226196   */
    227197
    228   if ( target ) {
    229 
     198  if ( has_target ) {
    230199    if ( rtems_filesystem_evaluate_path(
    231            target, strlen( target ), RTEMS_LIBIO_PERMS_RWX, &loc, true ) == -1 )
     200           target, target_length, RTEMS_LIBIO_PERMS_RWX, &loc, true ) == -1 )
    232201      goto cleanup_and_bail;
    233202
     
    273242    mt_entry->mt_point_node.ops = loc.ops;
    274243    mt_entry->mt_point_node.mt_entry = loc.mt_entry;
    275      
     244
    276245    /*
    277246     *  This link to the parent is only done when we are dealing with system
     
    287256      goto cleanup_and_bail;
    288257    }
    289 
    290     mt_entry->target = strdup( target );
    291258  } else {
    292 
    293259    /*
    294260     * Do we already have a base file system ?
     
    298264      goto cleanup_and_bail;
    299265    }
    300    
     266
    301267    /*
    302268     *  This is a mount of the base file system --> The
    303      *  mt_point_node.node_access will be set to null to indicate that this
     269     *  mt_point_node.node_access will be left to null to indicate that this
    304270     *  is the root of the entire file system.
    305271     */
    306 
    307     mt_entry->mt_fs_root.node_access = NULL;
    308     mt_entry->mt_fs_root.handlers = NULL;
    309     mt_entry->mt_fs_root.ops = NULL;
    310 
    311     mt_entry->mt_point_node.node_access = NULL;
    312     mt_entry->mt_point_node.handlers = NULL;
    313     mt_entry->mt_point_node.ops = NULL;
    314     mt_entry->mt_point_node.mt_entry = NULL;
    315 
    316     mt_entry->target = "/";
    317272  }
    318273
    319   if ( entry->mount_h( mt_entry, data ) ) {
     274  if ( (*mount_h)( mt_entry, data ) ) {
    320275    /*
    321276     * Try to undo the mount operation
     
    333288                      &mt_entry->Node );
    334289
    335   if ( !target )
     290  if ( !has_target )
    336291    rtems_filesystem_root = mt_entry->mt_fs_root;
    337292
     
    340295cleanup_and_bail:
    341296
    342   free( (void*) mt_entry->target );
    343297  free( mt_entry );
    344298
     
    349303}
    350304
     305/*
     306 * Get the first entry in the mount table.
     307 */
     308rtems_filesystem_mount_table_entry_t *
     309rtems_filesystem_mounts_first(
     310  void
     311)
     312{
     313  rtems_filesystem_mount_table_entry_t *entry = NULL;
     314
     315  if ( !rtems_chain_is_empty( &rtems_filesystem_mount_table_control ) )
     316    entry = (rtems_filesystem_mount_table_entry_t *)
     317      rtems_chain_first( &rtems_filesystem_mount_table_control );
     318
     319  return entry;
     320}
     321
     322/*
     323 * Get the next entry in the mount table.
     324 */
     325rtems_filesystem_mount_table_entry_t *
     326rtems_filesystem_mounts_next(
     327  rtems_filesystem_mount_table_entry_t *entry
     328)
     329{
     330  if ( !entry )
     331    return NULL;
     332  return (rtems_filesystem_mount_table_entry_t *)
     333    rtems_chain_next( &entry->Node );
     334}
Note: See TracChangeset for help on using the changeset viewer.