source: rtems/cpukit/libfs/src/imfs/imfs_handlers_directory.c @ 24ec25d

4.115
Last change on this file since 24ec25d was 24ec25d, checked in by Sebastian Huber <sebastian.huber@…>, on Feb 5, 2015 at 3:14:59 PM

IMFS: Introduce IMFS_mknod_control

Drop IMFS_node_control::node_size field and add node_size parameter to
IMFS_allocate_node() and IMFS_create_node(). This reduces the size of
generic nodes.

  • Property mode set to 100644
File size: 2.8 KB
Line 
1/**
2 * @file
3 *
4 * @brief Operations Table for Directories
5 * @ingroup IMFS
6 */
7
8/*
9 *  COPYRIGHT (c) 1989-1999.
10 *  On-Line Applications Research Corporation (OAR).
11 *
12 *  The license and distribution terms for this file may be
13 *  found in the file LICENSE in this distribution or at
14 *  http://www.rtems.org/license/LICENSE.
15 */
16
17#if HAVE_CONFIG_H
18  #include "config.h"
19#endif
20
21#include "imfs.h"
22
23#include <dirent.h>
24
25static size_t IMFS_directory_size( const IMFS_jnode_t *node )
26{
27  size_t size = 0;
28  const IMFS_directory_t *dir = (const IMFS_directory_t *) node;
29  const rtems_chain_control *chain = &dir->Entries;
30  const rtems_chain_node *current = rtems_chain_immutable_first( chain );
31  const rtems_chain_node *tail = rtems_chain_immutable_tail( chain );
32
33  while ( current != tail ) {
34    size += sizeof( struct dirent );
35    current = rtems_chain_immutable_next( current );
36  }
37
38  return size;
39}
40
41static int IMFS_stat_directory(
42  const rtems_filesystem_location_info_t *loc,
43  struct stat *buf
44)
45{
46  const IMFS_jnode_t *node = loc->node_access;
47
48  buf->st_size = IMFS_directory_size( node );
49
50  return IMFS_stat( loc, buf );
51}
52
53static const rtems_filesystem_file_handlers_r IMFS_directory_handlers = {
54  .open_h = rtems_filesystem_default_open,
55  .close_h = rtems_filesystem_default_close,
56  .read_h = imfs_dir_read,
57  .write_h = rtems_filesystem_default_write,
58  .ioctl_h = rtems_filesystem_default_ioctl,
59  .lseek_h = rtems_filesystem_default_lseek_directory,
60  .fstat_h = IMFS_stat_directory,
61  .ftruncate_h = rtems_filesystem_default_ftruncate_directory,
62  .fsync_h = rtems_filesystem_default_fsync_or_fdatasync_success,
63  .fdatasync_h = rtems_filesystem_default_fsync_or_fdatasync_success,
64  .fcntl_h = rtems_filesystem_default_fcntl,
65  .kqfilter_h = rtems_filesystem_default_kqfilter,
66  .poll_h = rtems_filesystem_default_poll,
67  .readv_h = rtems_filesystem_default_readv,
68  .writev_h = rtems_filesystem_default_writev
69};
70
71static IMFS_jnode_t *IMFS_node_initialize_directory(
72  IMFS_jnode_t *node,
73  void *arg
74)
75{
76  IMFS_directory_t *dir = (IMFS_directory_t *) node;
77
78  rtems_chain_initialize_empty( &dir->Entries );
79
80  return node;
81}
82
83static bool IMFS_is_mount_point( const IMFS_directory_t *dir )
84{
85  return dir->mt_fs != NULL;
86}
87
88static IMFS_jnode_t *IMFS_node_remove_directory(
89  IMFS_jnode_t *node
90)
91{
92  IMFS_directory_t *dir = (IMFS_directory_t *) node;
93
94  if ( !rtems_chain_is_empty( &dir->Entries ) ) {
95    errno = ENOTEMPTY;
96    dir = NULL;
97  } else if ( IMFS_is_mount_point( dir ) ) {
98    errno = EBUSY;
99    dir = NULL;
100  }
101
102  return &dir->Node;
103}
104
105const IMFS_mknod_control IMFS_mknod_control_directory = {
106  {
107    .handlers = &IMFS_directory_handlers,
108    .node_initialize = IMFS_node_initialize_directory,
109    .node_remove = IMFS_node_remove_directory,
110    .node_destroy = IMFS_node_destroy_default
111  },
112  .node_size = sizeof( IMFS_directory_t )
113};
Note: See TracBrowser for help on using the repository browser.