1 | /* |
---|
2 | * Free IMFS Node Support Routines |
---|
3 | * |
---|
4 | * |
---|
5 | * COPYRIGHT (c) 1989-1998. |
---|
6 | * On-Line Applications Research Corporation (OAR). |
---|
7 | * Copyright assigned to U.S. Government, 1994. |
---|
8 | * |
---|
9 | * The license and distribution terms for this file may be |
---|
10 | * found in the file LICENSE in this distribution or at |
---|
11 | * http://www.OARcorp.com/rtems/license.html. |
---|
12 | * |
---|
13 | * $Id$ |
---|
14 | */ |
---|
15 | |
---|
16 | #include <errno.h> |
---|
17 | |
---|
18 | #include "libio_.h" |
---|
19 | #include "imfs.h" |
---|
20 | |
---|
21 | /* |
---|
22 | * IMFS_freenodinfo |
---|
23 | * |
---|
24 | * This routine is the IMFS free node handler for the file system |
---|
25 | * operations table. |
---|
26 | * |
---|
27 | * The In Memory File System keeps its nodes in memory. This routine |
---|
28 | * is for file sytems that do not. |
---|
29 | */ |
---|
30 | |
---|
31 | int IMFS_freenodinfo( |
---|
32 | rtems_filesystem_location_info_t *pathloc /* IN */ |
---|
33 | ) |
---|
34 | { |
---|
35 | return 0; |
---|
36 | } |
---|
37 | |
---|
38 | |
---|
39 | /* |
---|
40 | * IMFS_freenod |
---|
41 | * |
---|
42 | * The following routine frees a node if possible. |
---|
43 | * |
---|
44 | * The routine returns 0 if the node was not freed and 1 if it was. |
---|
45 | * |
---|
46 | * NOTE: This routine is for INTERNAL IMFS use only. |
---|
47 | */ |
---|
48 | |
---|
49 | int IMFS_freenod( |
---|
50 | rtems_filesystem_location_info_t *pathloc |
---|
51 | ) |
---|
52 | { |
---|
53 | IMFS_jnode_t *the_jnode; |
---|
54 | |
---|
55 | the_jnode = pathloc->node_access; |
---|
56 | |
---|
57 | if ( the_jnode->type == IMFS_DIRECTORY ) { |
---|
58 | |
---|
59 | /* |
---|
60 | * You cannot remove a node that still has children |
---|
61 | */ |
---|
62 | |
---|
63 | if ( ! Chain_Is_empty( &the_jnode->info.directory.Entries ) ) |
---|
64 | return ENOTEMPTY; |
---|
65 | |
---|
66 | /* |
---|
67 | * You cannot remove the file system root node. |
---|
68 | */ |
---|
69 | if ( pathloc->mt_entry->mt_fs_root.node_access == pathloc->node_access ) |
---|
70 | return EBUSY; |
---|
71 | |
---|
72 | /* |
---|
73 | * You cannot remove a mountpoint. |
---|
74 | */ |
---|
75 | if ( the_jnode->info.directory.mt_fs != NULL ) |
---|
76 | return EBUSY; |
---|
77 | } |
---|
78 | |
---|
79 | if ( !rtems_libio_is_file_open( the_jnode ) && |
---|
80 | (the_jnode->st_nlink < 1) ) { |
---|
81 | |
---|
82 | /* |
---|
83 | * Is the rtems_filesystem_current is this node? |
---|
84 | */ |
---|
85 | if ( rtems_filesystem_current.node_access == pathloc->node_access ) { |
---|
86 | rtems_filesystem_current.node_access = NULL; |
---|
87 | } |
---|
88 | |
---|
89 | /* |
---|
90 | * Free memory associated with a memory file. |
---|
91 | */ |
---|
92 | if ( the_jnode->type == IMFS_MEMORY_FILE ) |
---|
93 | IMFS_memfile_remove( the_jnode ); |
---|
94 | |
---|
95 | free( the_jnode ); |
---|
96 | } |
---|
97 | |
---|
98 | return 0; |
---|
99 | } |
---|