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 | |
---|
36 | void 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 | } |
---|