[ef5e452] | 1 | /** |
---|
| 2 | * @file |
---|
[7999174] | 3 | * |
---|
[ef5e452] | 4 | * @brief Operations Table for Directories |
---|
| 5 | * @ingroup IMFS |
---|
| 6 | */ |
---|
| 7 | |
---|
| 8 | /* |
---|
[08311cc3] | 9 | * COPYRIGHT (c) 1989-1999. |
---|
[7999174] | 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 |
---|
[c499856] | 14 | * http://www.rtems.org/license/LICENSE. |
---|
[7999174] | 15 | */ |
---|
| 16 | |
---|
[d6b1d73] | 17 | #if HAVE_CONFIG_H |
---|
[3b7c123] | 18 | #include "config.h" |
---|
[d6b1d73] | 19 | #endif |
---|
| 20 | |
---|
[7999174] | 21 | #include "imfs.h" |
---|
| 22 | |
---|
[e998c985] | 23 | #include <dirent.h> |
---|
| 24 | |
---|
| 25 | static size_t IMFS_directory_size( const IMFS_jnode_t *node ) |
---|
| 26 | { |
---|
| 27 | size_t size = 0; |
---|
[cf36b70] | 28 | const IMFS_directory_t *dir = (const IMFS_directory_t *) node; |
---|
| 29 | const rtems_chain_control *chain = &dir->Entries; |
---|
[e998c985] | 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 | |
---|
| 41 | static 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 | |
---|
[699ac7c] | 53 | static const rtems_filesystem_file_handlers_r IMFS_directory_handlers = { |
---|
[2f68778] | 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, |
---|
[56bea43] | 65 | .kqfilter_h = rtems_filesystem_default_kqfilter, |
---|
| 66 | .poll_h = rtems_filesystem_default_poll, |
---|
[2f68778] | 67 | .readv_h = rtems_filesystem_default_readv, |
---|
| 68 | .writev_h = rtems_filesystem_default_writev |
---|
[7999174] | 69 | }; |
---|
[699ac7c] | 70 | |
---|
| 71 | static IMFS_jnode_t *IMFS_node_initialize_directory( |
---|
| 72 | IMFS_jnode_t *node, |
---|
[cf36b70] | 73 | void *arg |
---|
[699ac7c] | 74 | ) |
---|
| 75 | { |
---|
[cf36b70] | 76 | IMFS_directory_t *dir = (IMFS_directory_t *) node; |
---|
| 77 | |
---|
| 78 | rtems_chain_initialize_empty( &dir->Entries ); |
---|
[699ac7c] | 79 | |
---|
| 80 | return node; |
---|
| 81 | } |
---|
| 82 | |
---|
[cf36b70] | 83 | static bool IMFS_is_mount_point( const IMFS_directory_t *dir ) |
---|
[699ac7c] | 84 | { |
---|
[cf36b70] | 85 | return dir->mt_fs != NULL; |
---|
[699ac7c] | 86 | } |
---|
| 87 | |
---|
| 88 | static IMFS_jnode_t *IMFS_node_remove_directory( |
---|
[c17d0b3] | 89 | IMFS_jnode_t *node |
---|
[699ac7c] | 90 | ) |
---|
| 91 | { |
---|
[cf36b70] | 92 | IMFS_directory_t *dir = (IMFS_directory_t *) node; |
---|
| 93 | |
---|
| 94 | if ( !rtems_chain_is_empty( &dir->Entries ) ) { |
---|
[699ac7c] | 95 | errno = ENOTEMPTY; |
---|
[cf36b70] | 96 | dir = NULL; |
---|
| 97 | } else if ( IMFS_is_mount_point( dir ) ) { |
---|
[699ac7c] | 98 | errno = EBUSY; |
---|
[cf36b70] | 99 | dir = NULL; |
---|
[699ac7c] | 100 | } |
---|
| 101 | |
---|
[cf36b70] | 102 | return &dir->Node; |
---|
[699ac7c] | 103 | } |
---|
| 104 | |
---|
[24ec25d] | 105 | const 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 ) |
---|
[699ac7c] | 113 | }; |
---|