Changeset 0b0cd93 in rtems


Ignore:
Timestamp:
Feb 29, 2020, 10:15:43 AM (4 months ago)
Author:
Sebastian Huber <sebastian.huber@…>
Branches:
5, master
Children:
13b71f8
Parents:
8b73ee5
git-author:
Sebastian Huber <sebastian.huber@…> (02/29/20 10:15:43)
git-committer:
Sebastian Huber <sebastian.huber@…> (03/04/20 08:30:02)
Message:

imfs: Remove IMFS_NODE_FLAG_NAME_ALLOCATED

Remove IMFS_NODE_FLAG_NAME_ALLOCATED and instead replace the node
control in rename operations. This avoids a special case in the general
node destruction which pulled in free().

Update #3894.

Location:
cpukit
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • cpukit/include/rtems/imfs.h

    r8b73ee5 r0b0cd93  
    245245  const char         *name;                  /* "basename" (not \0 terminated) */
    246246  uint16_t            namelen;               /* Length of "basename" */
    247   uint16_t            flags;                 /* Node flags */
    248247  mode_t              st_mode;               /* File mode */
    249248  unsigned short      reference_count;
     
    258257  const IMFS_node_control *control;
    259258};
    260 
    261 #define IMFS_NODE_FLAG_NAME_ALLOCATED 0x1
    262259
    263260typedef struct {
  • cpukit/libfs/src/imfs/imfs_node.c

    r8b73ee5 r0b0cd93  
    108108void IMFS_node_destroy_default( IMFS_jnode_t *node )
    109109{
    110   if ( ( node->flags & IMFS_NODE_FLAG_NAME_ALLOCATED ) != 0 ) {
    111     free( RTEMS_DECONST( char *, node->name ) );
    112   }
    113 
    114110  free( node );
    115111}
  • cpukit/libfs/src/imfs/imfs_rename.c

    r8b73ee5 r0b0cd93  
    2424#include <stdlib.h>
    2525
     26typedef struct {
     27  IMFS_node_control Base;
     28  const IMFS_node_control *replaced;
     29  char name[ RTEMS_ZERO_LENGTH_ARRAY ];
     30} IMFS_renamed_control;
     31
     32static void IMFS_restore_replaced_control( IMFS_jnode_t *node )
     33{
     34  const IMFS_node_control *base;
     35  IMFS_renamed_control    *control;
     36
     37  base = RTEMS_DECONST( IMFS_node_control *, node->control );
     38  control = (IMFS_renamed_control *) base;
     39  node->control = control->replaced;
     40  free( control );
     41}
     42
     43static void IMFS_renamed_destroy( IMFS_jnode_t *node )
     44{
     45  IMFS_restore_replaced_control( node );
     46  ( *node->control->node_destroy )( node );
     47}
     48
    2649int IMFS_rename(
    2750  const rtems_filesystem_location_info_t *oldparentloc,
     
    3255)
    3356{
    34   IMFS_jnode_t *node = oldloc->node_access;
    35   IMFS_jnode_t *new_parent = newparentloc->node_access;
    36   char *allocated_name;
     57  IMFS_jnode_t         *node;
     58  IMFS_jnode_t         *new_parent;
     59  IMFS_renamed_control *control;
    3760
    3861  /*
     
    4063   * this operation.
    4164   */
     65
     66  node = oldloc->node_access;
     67  new_parent = newparentloc->node_access;
    4268
    4369  if ( node->Parent == NULL ) {
     
    4975  }
    5076
    51   allocated_name = malloc( namelen );
    52   if ( allocated_name == NULL ) {
     77  control = malloc( sizeof( *control ) + namelen );
     78  if ( control == NULL ) {
    5379    rtems_set_errno_and_return_minus_one( ENOMEM );
    5480  }
    5581
    56   memcpy( allocated_name, name, namelen );
     82  memcpy( control->name, name, namelen );
    5783
    58   if ( ( node->flags & IMFS_NODE_FLAG_NAME_ALLOCATED ) != 0 ) {
    59     free( RTEMS_DECONST( char *, node->name ) );
     84  if ( node->control->node_destroy == IMFS_renamed_destroy ) {
     85    IMFS_restore_replaced_control( node );
    6086  }
    6187
    62   node->name = allocated_name;
     88  control->Base = *node->control;
     89  control->Base.node_destroy = IMFS_renamed_destroy;
     90  control->replaced = node->control;
     91  node->control = &control->Base;
     92  node->name = control->name;
    6393  node->namelen = namelen;
    64   node->flags |= IMFS_NODE_FLAG_NAME_ALLOCATED;
    6594
    6695  IMFS_remove_from_directory( node );
Note: See TracChangeset for help on using the changeset viewer.