1 | /* |
---|
2 | * IMFS_unlink |
---|
3 | * |
---|
4 | * Routine to remove a link node from the tree. |
---|
5 | * |
---|
6 | * COPYRIGHT (c) 1989-1999. |
---|
7 | * On-Line Applications Research Corporation (OAR). |
---|
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 | #if HAVE_CONFIG_H |
---|
17 | #include "config.h" |
---|
18 | #endif |
---|
19 | |
---|
20 | #include <errno.h> |
---|
21 | #include <stdlib.h> |
---|
22 | |
---|
23 | #include "imfs.h" |
---|
24 | #include <rtems/libio_.h> |
---|
25 | #include <rtems/seterr.h> |
---|
26 | |
---|
27 | int IMFS_unlink( |
---|
28 | rtems_filesystem_location_info_t *loc /* IN */ |
---|
29 | ) |
---|
30 | { |
---|
31 | IMFS_jnode_t *node; |
---|
32 | rtems_filesystem_location_info_t the_link; |
---|
33 | int result = 0; |
---|
34 | |
---|
35 | node = loc->node_access; |
---|
36 | |
---|
37 | /* |
---|
38 | * Decrement the link counter of node pointed to and free the |
---|
39 | * space. |
---|
40 | */ |
---|
41 | |
---|
42 | /* |
---|
43 | * If this is the last last pointer to the node |
---|
44 | * free the node. |
---|
45 | */ |
---|
46 | |
---|
47 | if ( node->type == IMFS_HARD_LINK ) { |
---|
48 | |
---|
49 | if ( !node->info.hard_link.link_node ) |
---|
50 | rtems_set_errno_and_return_minus_one( EINVAL ); |
---|
51 | |
---|
52 | the_link = *loc; |
---|
53 | the_link.node_access = node->info.hard_link.link_node; |
---|
54 | IMFS_Set_handlers( &the_link ); |
---|
55 | |
---|
56 | /* |
---|
57 | * If removing the last hard link to a node, then we need |
---|
58 | * to remove the node that is a link and the node itself. |
---|
59 | */ |
---|
60 | |
---|
61 | if ( node->info.hard_link.link_node->st_nlink == 1) |
---|
62 | { |
---|
63 | result = (*the_link.handlers->rmnod_h)( &the_link ); |
---|
64 | if ( result != 0 ) |
---|
65 | return -1; |
---|
66 | } |
---|
67 | else |
---|
68 | { |
---|
69 | node->info.hard_link.link_node->st_nlink --; |
---|
70 | IMFS_update_ctime( node->info.hard_link.link_node ); |
---|
71 | } |
---|
72 | } |
---|
73 | |
---|
74 | /* |
---|
75 | * Now actually free the node we were asked to free. |
---|
76 | */ |
---|
77 | |
---|
78 | result = (*loc->handlers->rmnod_h)( loc ); |
---|
79 | |
---|
80 | return result; |
---|
81 | } |
---|
82 | |
---|