source: rtems/cpukit/libfs/src/imfs/imfs_rmnod.c @ 2e0ce55

4.115
Last change on this file since 2e0ce55 was 2e0ce55, checked in by Sebastian Huber <sebastian.huber@…>, on 02/21/12 at 16:24:10

IMFS: Use unprotected chain operations

Directory entry add or removal operations are protected by the file
system instance lock. There is no need for protected chain operations.

  • Property mode set to 100644
File size: 2.6 KB
Line 
1/*
2 *  IMFS Node Removal Handler
3 *
4 *  This file contains the handler used to remove a node when a file type
5 *  does not require special actions.
6 *
7 *  COPYRIGHT (c) 1989-1999.
8 *  On-Line Applications Research Corporation (OAR).
9 *
10 *  Modifications to support reference counting in the file system are
11 *  Copyright (c) 2012 embedded brains GmbH.
12 *
13 *  The license and distribution terms for this file may be
14 *  found in the file LICENSE in this distribution or at
15 *  http://www.rtems.com/license/LICENSE.
16 *
17 *  $Id$
18 */
19
20#if HAVE_CONFIG_H
21  #include "config.h"
22#endif
23
24#include "imfs.h"
25
26#include <stdlib.h>
27
28void IMFS_create_orphan( IMFS_jnode_t *jnode )
29{
30  if ( jnode->Parent != NULL ) {
31    IMFS_remove_from_directory( jnode );
32  }
33
34  --jnode->st_nlink;
35
36  IMFS_update_ctime( jnode );
37}
38
39void IMFS_check_node_remove( IMFS_jnode_t *jnode )
40{
41  if ( jnode->st_nlink < 1 ) {
42    switch ( jnode->type ) {
43      case IMFS_MEMORY_FILE:
44        IMFS_memfile_remove( jnode );
45        break;
46      case IMFS_SYM_LINK:
47        free( jnode->info.sym_link.name );
48        break;
49      default:
50        break;
51    }
52
53    free( jnode );
54  }
55}
56
57static int IMFS_rmnod_directory(
58  const rtems_filesystem_location_info_t *parentloc,
59  const rtems_filesystem_location_info_t *loc
60)
61{
62  IMFS_jnode_t *node = loc->node_access;
63  int rv = 0;
64
65  if ( !rtems_chain_is_empty( &node->info.directory.Entries ) ) {
66    errno = ENOTEMPTY;
67    rv = -1;
68  } else if (
69    rtems_filesystem_location_is_root( loc )
70      || node->info.directory.mt_fs != NULL
71  ) {
72    errno = EBUSY;
73    rv = -1;
74  }
75
76  return rv;
77}
78
79static int IMFS_rmnod_hard_link(
80  const rtems_filesystem_location_info_t *parentloc,
81  const rtems_filesystem_location_info_t *loc
82)
83{
84  int rv = 0;
85  IMFS_jnode_t *node = loc->node_access;
86  IMFS_jnode_t *target = node->info.hard_link.link_node;
87
88  if ( target->st_nlink == 1) {
89    rtems_filesystem_location_info_t target_loc = *loc;
90
91    target_loc.node_access = target;
92    IMFS_Set_handlers( &target_loc );
93
94    rv = (*target_loc.ops->rmnod_h)( parentloc, &target_loc );
95  } else {
96    --target->st_nlink;
97    IMFS_update_ctime( target );
98  }
99
100  return rv;
101}
102
103int IMFS_rmnod(
104  const rtems_filesystem_location_info_t *parentloc,
105  const rtems_filesystem_location_info_t *loc
106)
107{
108  int rv = 0;
109  IMFS_jnode_t *node = loc->node_access;
110
111  switch ( node->type ) {
112    case IMFS_DIRECTORY:
113      rv = IMFS_rmnod_directory( parentloc, loc );
114      break;
115    case IMFS_HARD_LINK:
116      rv = IMFS_rmnod_hard_link( parentloc, loc );
117      break;
118    default:
119      break;
120  }
121
122  if ( rv == 0 ) {
123    IMFS_create_orphan( node );
124    IMFS_check_node_remove( node );
125  }
126
127  return rv;
128}
Note: See TracBrowser for help on using the repository browser.