source: rtems/cpukit/libfs/src/imfs/imfs_handlers_directory.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: 2.4 KB
Line 
1/*
2 *  Operations Table for Directories for the IMFS
3 *
4 *  COPYRIGHT (c) 1989-1999.
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 <dirent.h>
19
20static size_t IMFS_directory_size( const IMFS_jnode_t *node )
21{
22  size_t size = 0;
23  const rtems_chain_control *chain = &node->info.directory.Entries;
24  const rtems_chain_node *current = rtems_chain_immutable_first( chain );
25  const rtems_chain_node *tail = rtems_chain_immutable_tail( chain );
26
27  while ( current != tail ) {
28    size += sizeof( struct dirent );
29    current = rtems_chain_immutable_next( current );
30  }
31
32  return size;
33}
34
35static int IMFS_stat_directory(
36  const rtems_filesystem_location_info_t *loc,
37  struct stat *buf
38)
39{
40  const IMFS_jnode_t *node = loc->node_access;
41
42  buf->st_size = IMFS_directory_size( node );
43
44  return IMFS_stat( loc, buf );
45}
46
47static const rtems_filesystem_file_handlers_r IMFS_directory_handlers = {
48  rtems_filesystem_default_open,
49  rtems_filesystem_default_close,
50  imfs_dir_read,
51  rtems_filesystem_default_write,
52  rtems_filesystem_default_ioctl,
53  rtems_filesystem_default_lseek_directory,
54  IMFS_stat_directory,
55  rtems_filesystem_default_ftruncate_directory,
56  rtems_filesystem_default_fsync_or_fdatasync_success,
57  rtems_filesystem_default_fsync_or_fdatasync_success,
58  rtems_filesystem_default_fcntl
59};
60
61static IMFS_jnode_t *IMFS_node_initialize_directory(
62  IMFS_jnode_t *node,
63  const IMFS_types_union *info
64)
65{
66  rtems_chain_initialize_empty( &node->info.directory.Entries );
67
68  return node;
69}
70
71static bool IMFS_is_mount_point( const IMFS_jnode_t *node )
72{
73  return node->info.directory.mt_fs != NULL;
74}
75
76static IMFS_jnode_t *IMFS_node_remove_directory(
77  IMFS_jnode_t *node
78)
79{
80  if ( !rtems_chain_is_empty( &node->info.directory.Entries ) ) {
81    errno = ENOTEMPTY;
82    node = NULL;
83  } else if ( IMFS_is_mount_point( node ) ) {
84    errno = EBUSY;
85    node = NULL;
86  }
87
88  return node;
89}
90
91const IMFS_node_control IMFS_node_control_directory = {
92  .imfs_type = IMFS_DIRECTORY,
93  .handlers = &IMFS_directory_handlers,
94  .node_initialize = IMFS_node_initialize_directory,
95  .node_remove = IMFS_node_remove_directory,
96  .node_destroy = IMFS_node_destroy_default
97};
Note: See TracBrowser for help on using the repository browser.