1 | /** |
---|
2 | * @file |
---|
3 | * |
---|
4 | * @brief Unmount this Instance of IMFS |
---|
5 | * @ingroup IMFS |
---|
6 | */ |
---|
7 | |
---|
8 | /* |
---|
9 | * COPYRIGHT (c) 1989-1999. |
---|
10 | * On-Line Applications Research Corporation (OAR). |
---|
11 | * |
---|
12 | * The license and distribution terms for this file may be |
---|
13 | * found in the file LICENSE in this distribution or at |
---|
14 | * http://www.rtems.org/license/LICENSE. |
---|
15 | */ |
---|
16 | |
---|
17 | #if HAVE_CONFIG_H |
---|
18 | #include "config.h" |
---|
19 | #endif |
---|
20 | |
---|
21 | #include "imfs.h" |
---|
22 | |
---|
23 | #define jnode_get_control( jnode ) \ |
---|
24 | (&jnode->info.directory.Entries) |
---|
25 | |
---|
26 | #define jnode_has_no_children( jnode ) \ |
---|
27 | rtems_chain_is_empty( jnode_get_control( jnode ) ) |
---|
28 | |
---|
29 | #define jnode_has_children( jnode ) \ |
---|
30 | ( ! jnode_has_no_children( jnode ) ) |
---|
31 | |
---|
32 | #define jnode_get_first_child( jnode ) \ |
---|
33 | ((IMFS_jnode_t *)( rtems_chain_head( jnode_get_control( jnode ) )->next)) |
---|
34 | |
---|
35 | void IMFS_fsunmount( |
---|
36 | rtems_filesystem_mount_table_entry_t *temp_mt_entry |
---|
37 | ) |
---|
38 | { |
---|
39 | IMFS_jnode_t *jnode; |
---|
40 | IMFS_jnode_t *next; |
---|
41 | rtems_filesystem_location_info_t loc; |
---|
42 | int result = 0; |
---|
43 | |
---|
44 | /* |
---|
45 | * Traverse tree that starts at the mt_fs_root and deallocate memory |
---|
46 | * associated memory space |
---|
47 | */ |
---|
48 | |
---|
49 | loc = temp_mt_entry->mt_fs_root->location; |
---|
50 | jnode = (IMFS_jnode_t *)loc.node_access; |
---|
51 | |
---|
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 | |
---|
58 | do { |
---|
59 | next = jnode->Parent; |
---|
60 | loc.node_access = (void *)jnode; |
---|
61 | IMFS_Set_handlers( &loc ); |
---|
62 | |
---|
63 | if ( !IMFS_is_directory( jnode ) || jnode_has_no_children( jnode ) ) { |
---|
64 | result = IMFS_rmnod( NULL, &loc ); |
---|
65 | if ( result != 0 ) |
---|
66 | rtems_fatal_error_occurred( 0xdeadbeef ); |
---|
67 | IMFS_node_destroy( jnode ); |
---|
68 | jnode = next; |
---|
69 | } |
---|
70 | if ( jnode != NULL ) { |
---|
71 | if ( IMFS_is_directory( jnode ) ) { |
---|
72 | if ( jnode_has_children( jnode ) ) |
---|
73 | jnode = jnode_get_first_child( jnode ); |
---|
74 | } |
---|
75 | } |
---|
76 | } while (jnode != NULL); |
---|
77 | } |
---|