source: rtems/c/src/libfs/src/imfs/imfs_rmnod.c @ 49629bd8

4.104.114.84.95
Last change on this file since 49629bd8 was 07a3253d, checked in by Joel Sherrill <joel.sherrill@…>, on 11/23/98 at 19:07:58

Added base version of file system infrastructure. This includes a major
overhaul of the RTEMS system call interface. This base file system is
the "In-Memory File System" aka IMFS.

The design and implementation was done by the following people:

+ Joel Sherrill (joel@…)
+ Jennifer Averett (jennifer@…)
+ Steve "Mr Mount" Salitasc (salitasc@…)
+ Kerwin Wade (wade@…)

PROBLEMS
========

+ It is VERY likely that merging this will break the UNIX port. This

can/will be fixed.

+ There is likely some reentrancy/mutual exclusion needed.

+ Eventually, there should be a "mini-IMFS" description table to

eliminate links, symlinks, etc to save memory. All you need to
have "classic RTEMS" functionality is technically directories
and device IO. All the rest could be left out to save memory.

  • 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  if ( the_jnode->Parent != NULL ) {
59    Chain_Extract( (Chain_Node *) the_jnode );
60    the_jnode->Parent = NULL;
61  }
62
63  /*
64   * Decrement the link counter and see if we can free the space.
65   */
66
67  the_jnode->st_nlink--;
68  IMFS_update_ctime( the_jnode );
69
70  /*
71   * The file cannot be open and the link must be less than 1 to free.
72   */
73
74  if ( !rtems_libio_is_file_open( the_jnode ) && (the_jnode->st_nlink < 1) ) {
75
76    /*
77     * Is the rtems_filesystem_current is this node?
78     */
79
80    if ( rtems_filesystem_current.node_access == pathloc->node_access )
81       rtems_filesystem_current.node_access = NULL;
82
83    /*
84     * Free memory associated with a memory file.
85     */
86
87    if ( the_jnode->type == IMFS_MEMORY_FILE )
88      IMFS_memfile_remove( the_jnode );
89
90    free( the_jnode );
91  }
92
93  return 0;
94
95}
96
97
Note: See TracBrowser for help on using the repository browser.