source: rtems/cpukit/libfs/src/imfs/imfs_fsunmount.c @ 1bdff036

4.115
Last change on this file since 1bdff036 was 1bdff036, checked in by Sebastian Huber <sebastian.huber@…>, on 02/23/12 at 16:57:27

IMFS: Reference counting for nodes

The introduction of reference counting of nodes avoids the removal of
open nodes and potential usage of freed memory.

  • Property mode set to 100644
File size: 1.9 KB
Line 
1/*
2 *  IMFS Initialization
3 *
4 *  COPYRIGHT (c) 1989-1999.
5 *  On-Line Applications Research Corporation (OAR).
6 *
7 *  The license and distribution terms for this file may be
8 *  found in the file LICENSE in this distribution or at
9 *  http://www.rtems.com/license/LICENSE.
10 *
11 *  $Id$
12 */
13
14#if HAVE_CONFIG_H
15  #include "config.h"
16#endif
17
18#include "imfs.h"
19
20/*
21 *  IMFS_fsunmount
22 */
23
24#define jnode_get_control( jnode ) \
25  (&jnode->info.directory.Entries)
26
27#define jnode_has_no_children( jnode )  \
28  rtems_chain_is_empty( jnode_get_control( jnode ) )
29
30#define jnode_has_children( jnode ) \
31  ( ! jnode_has_no_children( jnode ) )
32
33#define jnode_get_first_child( jnode ) \
34    ((IMFS_jnode_t *)( rtems_chain_head( jnode_get_control( jnode ) )->next))
35
36void IMFS_fsunmount(
37  rtems_filesystem_mount_table_entry_t *temp_mt_entry
38)
39{
40   IMFS_jnode_t                     *jnode;
41   IMFS_jnode_t                     *next;
42   rtems_filesystem_location_info_t loc;
43   int                              result = 0;
44
45   /*
46    * Traverse tree that starts at the mt_fs_root and deallocate memory
47    * associated memory space
48    */
49
50   loc = temp_mt_entry->mt_fs_root->location;
51   jnode = (IMFS_jnode_t *)loc.node_access;
52
53   /*
54    *  Set this to null to indicate that it is being unmounted.
55    */
56
57   temp_mt_entry->mt_fs_root->location.node_access = NULL;
58
59   do {
60     next = jnode->Parent;
61     loc.node_access = (void *)jnode;
62     IMFS_Set_handlers( &loc );
63
64     if ( jnode->type != IMFS_DIRECTORY || jnode_has_no_children( jnode ) ) {
65        result = IMFS_rmnod( NULL, &loc );
66        if ( result != 0 )
67          rtems_fatal_error_occurred( 0xdeadbeef );
68        IMFS_node_destroy( jnode );
69        jnode = next;
70     }
71     if ( jnode != NULL ) {
72       if ( jnode->type == IMFS_DIRECTORY ) {
73         if ( jnode_has_children( jnode ) )
74           jnode = jnode_get_first_child( jnode );
75       }
76     }
77   } while (jnode != NULL);
78}
Note: See TracBrowser for help on using the repository browser.