source: rtems/c/src/lib/libc/imfs_rmnod.c @ a6883c4

4.104.114.84.95
Last change on this file since a6883c4 was a6883c4, checked in by Joel Sherrill <joel.sherrill@…>, on Oct 12, 1999 at 8:22:27 PM

Spacing.

  • Property mode set to 100644
File size: 2.1 KB
Line 
1/*
2 *  IMFS_rmnod
3 *
4 *  This routine is available from the optable to remove a node
5 *  from the IMFS file system.
6 *
7 *  COPYRIGHT (c) 1989-1998.
8 *  On-Line Applications Research Corporation (OAR).
9 *  Copyright assigned to U.S. Government, 1994.
10 *
11 *  The license and distribution terms for this file may be
12 *  found in the file LICENSE in this distribution or at
13 *  http://www.OARcorp.com/rtems/license.html.
14 *
15 *  $Id$
16 */
17
18#include <errno.h>
19#include "libio_.h"
20#include "imfs.h"
21
22
23int IMFS_rmnod(
24  rtems_filesystem_location_info_t      *pathloc       /* IN */
25)
26{
27  IMFS_jnode_t *the_jnode; 
28
29  the_jnode = (IMFS_jnode_t *) pathloc->node_access;
30
31  if ( the_jnode->type == IMFS_DIRECTORY ) {
32
33    /*
34     * You cannot remove a node that still has children
35     */
36
37    if ( ! Chain_Is_empty( &the_jnode->info.directory.Entries ) )
38       set_errno_and_return_minus_one( ENOTEMPTY );
39
40    /*
41     * You cannot remove the file system root node.
42     */
43
44    if ( pathloc->mt_entry->mt_fs_root.node_access == pathloc->node_access )
45       set_errno_and_return_minus_one( EBUSY );
46
47    /*
48     * You cannot remove a mountpoint.
49     */
50
51     if ( the_jnode->info.directory.mt_fs != NULL )
52       set_errno_and_return_minus_one( EBUSY );         
53  } 
54   
55  /*
56   * Take the node out of the parent's chain that contains this node
57   */
58
59  if ( the_jnode->Parent != NULL ) {
60    Chain_Extract( (Chain_Node *) the_jnode );
61    the_jnode->Parent = NULL;
62  }
63
64  /*
65   * Decrement the link counter and see if we can free the space.
66   */
67
68  the_jnode->st_nlink--;
69  IMFS_update_ctime( the_jnode );
70
71  /*
72   * The file cannot be open and the link must be less than 1 to free.
73   */
74
75  if ( !rtems_libio_is_file_open( the_jnode ) && (the_jnode->st_nlink < 1) ) {
76
77    /*
78     * Is the rtems_filesystem_current is this node?
79     */
80
81    if ( rtems_filesystem_current.node_access == pathloc->node_access )
82       rtems_filesystem_current.node_access = NULL;
83
84    /*
85     * Free memory associated with a memory file.
86     */
87
88    if ( the_jnode->type == IMFS_MEMORY_FILE ) 
89      IMFS_memfile_remove( the_jnode );
90
91    free( the_jnode );
92  }
93
94  return 0;
95
96}
97
98
Note: See TracBrowser for help on using the repository browser.