Changeset 316507ab in rtems


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

IMFS: Lock the file system during directory reads

Other threads may add or remove directory entries during a read of the
directory. Use the file system instance lock for protection.

File:
1 edited

Legend:

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

    re00cca9b r316507ab  
    8282   struct dirent        tmp_dirent;
    8383
     84   rtems_filesystem_instance_lock( &iop->pathinfo );
     85
    8486   the_jnode = (IMFS_jnode_t *)iop->pathinfo.node_access;
    8587   the_chain = &the_jnode->info.directory.Entries;
    8688
    87    if ( rtems_chain_is_empty( the_chain ) )
    88       return 0;
    89 
    9089   /* Move to the first of the desired directory entries */
    91    the_node = rtems_chain_first( the_chain );
    9290
    9391   bytes_transferred = 0;
     
    9593   /* protect against using sizes that are not exact multiples of the */
    9694   /* -dirent- size. These could result in unexpected results          */
    97    last_entry = first_entry + (count/sizeof(struct dirent)) * sizeof(struct dirent);
     95   last_entry = first_entry
     96     + (count / sizeof( struct dirent )) * sizeof( struct dirent );
    9897
    9998   /* The directory was not empty so try to move to the desired entry in chain*/
    10099   for (
    101       current_entry = 0;
    102       current_entry < last_entry;
    103       current_entry = current_entry + sizeof(struct dirent) ){
    104 
    105       if ( rtems_chain_is_tail( the_chain, the_node ) ){
    106          /* We hit the tail of the chain while trying to move to the first */
    107          /* entry in the read */
    108          return bytes_transferred;  /* Indicate that there are no more */
    109                                     /* entries to return */
    110       }
    111 
     100      current_entry = 0,
     101        the_node = rtems_chain_first( the_chain );
     102      current_entry < last_entry
     103        && !rtems_chain_is_tail( the_chain, the_node );
     104      current_entry +=  sizeof( struct dirent ),
     105        the_node = rtems_chain_next( the_node )
     106   ) {
    112107      if( current_entry >= first_entry ) {
    113108         /* Move the entry to the return buffer */
     
    123118            sizeof( struct dirent )
    124119         );
    125          iop->offset = iop->offset + sizeof(struct dirent);
    126          bytes_transferred = bytes_transferred + sizeof( struct dirent );
     120         iop->offset += sizeof( struct dirent );
     121         bytes_transferred += sizeof( struct dirent );
    127122      }
    128 
    129       the_node = the_node->next;
    130123   }
    131124
    132    /* Success */
     125   rtems_filesystem_instance_unlock( &iop->pathinfo );
     126
    133127   return bytes_transferred;
    134128}
Note: See TracChangeset for help on using the changeset viewer.