Changeset 60cf8a5 in rtems


Ignore:
Timestamp:
Feb 6, 2015, 3:32:39 PM (5 years ago)
Author:
Sebastian Huber <sebastian.huber@…>
Branches:
4.11, master
Children:
11026956
Parents:
9247d3f
git-author:
Sebastian Huber <sebastian.huber@…> (02/06/15 15:32:39)
git-committer:
Sebastian Huber <sebastian.huber@…> (02/12/15 19:53:35)
Message:

IMFS: Add root directory to FS info

Fix memory leak in IMFS_fsunmount().

Files:
5 edited

Legend:

Unmodified
Added
Removed
  • cpukit/libfs/src/imfs/imfs.h

    r9247d3f r60cf8a5  
    376376
    377377typedef struct {
     378  IMFS_directory_t Root_directory;
    378379  const IMFS_mknod_control *mknod_controls[ IMFS_TYPE_COUNT ];
    379380} IMFS_fs_info_t;
     
    563564);
    564565
    565 /**
    566  * @brief Create a new IMFS node.
    567  *
    568  * Routine to create a new in memory file system node.
    569  */
    570 extern IMFS_jnode_t *IMFS_allocate_node(
     566extern IMFS_jnode_t *IMFS_initialize_node(
     567  IMFS_jnode_t *node,
    571568  const IMFS_node_control *node_control,
    572   size_t node_size,
    573569  const char *name,
    574570  size_t namelen,
  • cpukit/libfs/src/imfs/imfs_creat.c

    r9247d3f r60cf8a5  
    2323#include <string.h>
    2424
    25 IMFS_jnode_t *IMFS_allocate_node(
    26   const IMFS_node_control *node_control,
    27   size_t node_size,
    28   const char *name,
    29   size_t namelen,
    30   mode_t mode,
    31   void *arg
    32 )
    33 {
    34   IMFS_jnode_t        *node;
    35   IMFS_jnode_t        *initialized_node;
    36   struct timeval       tv;
    37 
    38   if ( namelen > IMFS_NAME_MAX ) {
    39     errno = ENAMETOOLONG;
    40 
    41     return NULL;
    42   }
    43 
    44   gettimeofday( &tv, 0 );
    45 
    46   /*
    47    *  Allocate an IMFS jnode
    48    */
    49   node = calloc( 1, node_size );
    50   if ( !node ) {
    51     errno = ENOMEM;
    52 
    53     return NULL;
    54   }
    55 
    56   /*
    57    *  Fill in the basic information
    58    */
    59   node->reference_count = 1;
    60   node->st_nlink = 1;
    61   memcpy( node->name, name, namelen );
    62   node->name [namelen] = '\0';
    63   node->control = node_control;
    64 
    65   /*
    66    *  Fill in the mode and permission information for the jnode structure.
    67    */
    68   node->st_mode = mode;
    69   node->st_uid = geteuid();
    70   node->st_gid = getegid();
    71 
    72   /*
    73    *  Now set all the times.
    74    */
    75 
    76   node->stat_atime  = (time_t) tv.tv_sec;
    77   node->stat_mtime  = (time_t) tv.tv_sec;
    78   node->stat_ctime  = (time_t) tv.tv_sec;
    79 
    80   initialized_node = (*node->control->node_initialize)( node, arg );
    81   if ( initialized_node == NULL ) {
    82     free( node );
    83   }
    84 
    85   return initialized_node;
    86 }
    87 
    8825IMFS_jnode_t *IMFS_create_node(
    8926  const rtems_filesystem_location_info_t *parentloc,
     
    9633)
    9734{
    98   IMFS_jnode_t *node = IMFS_allocate_node(
     35  IMFS_jnode_t *allocated_node;
     36  IMFS_jnode_t *node;
     37
     38  allocated_node = calloc( 1, node_size );
     39  if ( allocated_node == NULL ) {
     40    errno = ENOMEM;
     41
     42    return NULL;
     43  }
     44
     45  node = IMFS_initialize_node(
     46    allocated_node,
    9947    node_control,
    100     node_size,
    10148    name,
    10249    namelen,
     
    10451    arg
    10552  );
    106 
    10753  if ( node != NULL ) {
    10854    IMFS_jnode_t *parent = parentloc->node_access;
     
    11359    IMFS_assert( parent != NULL );
    11460    IMFS_add_to_directory( parent, node );
     61  } else {
     62    free( allocated_node );
    11563  }
    11664
  • cpukit/libfs/src/imfs/imfs_fsunmount.c

    r9247d3f r60cf8a5  
    5050   jnode = (IMFS_jnode_t *)loc.node_access;
    5151
    52    /*
    53     *  Set this to null to indicate that it is being unmounted.
    54     */
    55 
    56    temp_mt_entry->mt_fs_root->location.node_access = NULL;
    57 
    5852   do {
    5953     next = jnode->Parent;
  • cpukit/libfs/src/imfs/imfs_initsupp.c

    r9247d3f r60cf8a5  
    2424#include <stdlib.h>
    2525#include <string.h>
     26#include <unistd.h>
    2627
    2728/*
     
    5657}
    5758
     59IMFS_jnode_t *IMFS_initialize_node(
     60  IMFS_jnode_t *node,
     61  const IMFS_node_control *node_control,
     62  const char *name,
     63  size_t namelen,
     64  mode_t mode,
     65  void *arg
     66)
     67{
     68  struct timeval tv;
     69
     70  if ( namelen > IMFS_NAME_MAX ) {
     71    errno = ENAMETOOLONG;
     72
     73    return NULL;
     74  }
     75
     76  gettimeofday( &tv, 0 );
     77
     78  /*
     79   *  Fill in the basic information
     80   */
     81  node->reference_count = 1;
     82  node->st_nlink = 1;
     83  memcpy( node->name, name, namelen );
     84  node->name [namelen] = '\0';
     85  node->control = node_control;
     86
     87  /*
     88   *  Fill in the mode and permission information for the jnode structure.
     89   */
     90  node->st_mode = mode;
     91  node->st_uid = geteuid();
     92  node->st_gid = getegid();
     93
     94  /*
     95   *  Now set all the times.
     96   */
     97
     98  node->stat_atime  = (time_t) tv.tv_sec;
     99  node->stat_mtime  = (time_t) tv.tv_sec;
     100  node->stat_ctime  = (time_t) tv.tv_sec;
     101
     102  return (*node_control->node_initialize)( node, arg );
     103}
     104
    58105int IMFS_initialize_support(
    59106  rtems_filesystem_mount_table_entry_t *mt_entry,
     
    74121    );
    75122
    76     root_node = IMFS_allocate_node(
     123    root_node = IMFS_initialize_node(
     124      &fs_info->Root_directory.Node,
    77125      &fs_info->mknod_controls[ IMFS_DIRECTORY ]->node_control,
    78       fs_info->mknod_controls[ IMFS_DIRECTORY ]->node_size,
    79126      "",
    80127      0,
     
    82129      NULL
    83130    );
    84     if ( root_node != NULL ) {
    85       mt_entry->fs_info = fs_info;
    86       mt_entry->ops = op_table;
    87       mt_entry->pathconf_limits_and_options = &IMFS_LIMITS_AND_OPTIONS;
    88       mt_entry->mt_fs_root->location.node_access = root_node;
    89       IMFS_Set_handlers( &mt_entry->mt_fs_root->location );
    90     } else {
    91       free(fs_info);
    92       errno = ENOMEM;
    93       rv = -1;
    94     }
     131    IMFS_assert( root_node != NULL );
     132
     133    mt_entry->fs_info = fs_info;
     134    mt_entry->ops = op_table;
     135    mt_entry->pathconf_limits_and_options = &IMFS_LIMITS_AND_OPTIONS;
     136    mt_entry->mt_fs_root->location.node_access = root_node;
     137    IMFS_Set_handlers( &mt_entry->mt_fs_root->location );
    95138  } else {
    96139    errno = ENOMEM;
  • testsuites/fstests/mimfs_support/fs_support.c

    r9247d3f r60cf8a5  
    1515#include <sys/stat.h>
    1616#include <rtems/libio.h>
     17#include <rtems/libcsupport.h>
    1718
    1819#include "fstest.h"
    1920#include "fstest_support.h"
     21
     22static rtems_resource_snapshot before_mount;
    2023
    2124void
     
    2528  rc = mkdir (BASE_FOR_TEST,S_IRWXU|S_IRWXG|S_IRWXO);
    2629  rtems_test_assert (rc == 0);
     30
     31  rtems_resource_snapshot_take(&before_mount);
    2732
    2833  rc = mount (NULL, BASE_FOR_TEST, "imfs", RTEMS_FILESYSTEM_READ_WRITE, NULL);
     
    3742  rc = unmount (BASE_FOR_TEST);
    3843  rtems_test_assert (rc == 0);
     44
     45  rtems_test_assert(rtems_resource_snapshot_check(&before_mount));
    3946}
    4047
Note: See TracChangeset for help on using the changeset viewer.