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 | |
---|
20 | static 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 | |
---|
35 | static 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 | |
---|
47 | static 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 | |
---|
61 | static 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 | |
---|
71 | static bool IMFS_is_mount_point( const IMFS_jnode_t *node ) |
---|
72 | { |
---|
73 | return node->info.directory.mt_fs != NULL; |
---|
74 | } |
---|
75 | |
---|
76 | static IMFS_jnode_t *IMFS_node_remove_directory( |
---|
77 | IMFS_jnode_t *node, |
---|
78 | const IMFS_jnode_t *root_node |
---|
79 | ) |
---|
80 | { |
---|
81 | if ( !rtems_chain_is_empty( &node->info.directory.Entries ) ) { |
---|
82 | errno = ENOTEMPTY; |
---|
83 | node = NULL; |
---|
84 | } else if ( node == root_node || IMFS_is_mount_point( node ) ) { |
---|
85 | errno = EBUSY; |
---|
86 | node = NULL; |
---|
87 | } |
---|
88 | |
---|
89 | return node; |
---|
90 | } |
---|
91 | |
---|
92 | const IMFS_node_control IMFS_node_control_directory = { |
---|
93 | .imfs_type = IMFS_DIRECTORY, |
---|
94 | .handlers = &IMFS_directory_handlers, |
---|
95 | .node_initialize = IMFS_node_initialize_directory, |
---|
96 | .node_remove = IMFS_node_remove_directory, |
---|
97 | .node_destroy = IMFS_node_destroy_default |
---|
98 | }; |
---|