source: rtems/cpukit/libfs/src/imfs/imfs_initsupp.c @ c17d0b3

4.11
Last change on this file since c17d0b3 was c17d0b3, checked in by Sebastian Huber <sebastian.huber@…>, on Oct 2, 2012 at 1:44:59 PM

Filesystem: Reject removal of root nodes

Reject the removal of file system instance root nodes in rmdir() and
unlink() and return the EBUSY error status. File system instances can
be removed with unmount(). Remove root node special cases in IMFS,
DOSFS, and RFS.

  • Property mode set to 100644
File size: 3.3 KB
Line 
1/*
2 *  IMFS Initialization
3 *
4 *  COPYRIGHT (c) 1989-2010.
5 *  On-Line Applications Research Corporation (OAR).
6 *
7 *  The license and distribution terms for this file may be
8 *  found in the file LICENSE in this distribution or at
9 *  http://www.rtems.com/license/LICENSE.
10 */
11
12#if HAVE_CONFIG_H
13  #include "config.h"
14#endif
15
16#include "imfs.h"
17
18#include <stdlib.h>
19
20/*
21 *  IMFS_determine_bytes_per_block
22 */
23int imfs_memfile_bytes_per_block = 0;
24
25static int IMFS_determine_bytes_per_block(
26  int *dest_bytes_per_block,
27  int requested_bytes_per_block,
28  int default_bytes_per_block
29)
30{
31  bool is_valid = false;
32  int bit_mask;
33
34  /*
35   * check, whether requested bytes per block is valid
36   */
37  for (bit_mask = 16; !is_valid && (bit_mask <= 512); bit_mask <<= 1) {
38    if (bit_mask == requested_bytes_per_block) {
39      is_valid = true;
40      break;
41    }
42    if(bit_mask > requested_bytes_per_block)
43      break;
44  }
45  *dest_bytes_per_block = ((is_valid)
46                           ? requested_bytes_per_block
47                           : default_bytes_per_block);
48  return 0;
49}
50
51int IMFS_initialize_support(
52  rtems_filesystem_mount_table_entry_t *mt_entry,
53  const rtems_filesystem_operations_table *op_table,
54  const IMFS_node_control *const node_controls [IMFS_TYPE_COUNT]
55)
56{
57  static int imfs_instance;
58
59  int rv = 0;
60  IMFS_fs_info_t *fs_info = calloc( 1, sizeof( *fs_info ) );
61
62  if ( fs_info != NULL ) {
63    IMFS_jnode_t *root_node;
64
65    fs_info->instance = imfs_instance++;
66    memcpy(
67      fs_info->node_controls,
68      node_controls,
69      sizeof( fs_info->node_controls )
70    );
71
72    root_node = IMFS_allocate_node(
73      fs_info,
74      fs_info->node_controls [IMFS_DIRECTORY],
75      "",
76      0,
77      (S_IFDIR | 0755),
78      NULL
79    );
80    if ( root_node != NULL ) {
81      mt_entry->fs_info = fs_info;
82      mt_entry->ops = op_table;
83      mt_entry->pathconf_limits_and_options = &IMFS_LIMITS_AND_OPTIONS;
84      mt_entry->mt_fs_root->location.node_access = root_node;
85      IMFS_Set_handlers( &mt_entry->mt_fs_root->location );
86    } else {
87      errno = ENOMEM;
88      rv = -1;
89    }
90  } else {
91    errno = ENOMEM;
92    rv = -1;
93  }
94
95  if ( rv == 0 ) {
96    IMFS_determine_bytes_per_block(
97      &imfs_memfile_bytes_per_block,
98      imfs_rq_memfile_bytes_per_block,
99      IMFS_MEMFILE_DEFAULT_BYTES_PER_BLOCK
100    );
101  }
102
103  return rv;
104}
105
106int IMFS_node_clone( rtems_filesystem_location_info_t *loc )
107{
108  IMFS_jnode_t *node = loc->node_access;
109
110  ++node->reference_count;
111
112  return 0;
113}
114
115void IMFS_node_destroy( IMFS_jnode_t *node )
116{
117  IMFS_assert( node->reference_count == 0 );
118
119  node = (*node->control->node_destroy)( node );
120
121  free( node );
122}
123
124void IMFS_node_free( const rtems_filesystem_location_info_t *loc )
125{
126  IMFS_jnode_t *node = loc->node_access;
127
128  if ( node->reference_count == 1 ) {
129    IMFS_node_destroy( node );
130  } else {
131    --node->reference_count;
132  }
133}
134
135IMFS_jnode_t *IMFS_node_initialize_default(
136  IMFS_jnode_t *node,
137  const IMFS_types_union *info
138)
139{
140  return node;
141}
142
143IMFS_jnode_t *IMFS_node_remove_default(
144  IMFS_jnode_t *node
145)
146{
147  return node;
148}
149
150IMFS_jnode_t *IMFS_node_destroy_default( IMFS_jnode_t *node )
151{
152  return node;
153}
154
155const IMFS_node_control IMFS_node_control_default = {
156  .imfs_type = IMFS_INVALID_NODE,
157  .handlers = &rtems_filesystem_handlers_default,
158  .node_initialize = IMFS_node_initialize_default,
159  .node_remove = IMFS_node_remove_default,
160  .node_destroy = IMFS_node_destroy_default
161};
Note: See TracBrowser for help on using the repository browser.