[378fe02] | 1 | /* |
---|
| 2 | * Link Operations Table for the IMFS |
---|
| 3 | * |
---|
[08311cc3] | 4 | * COPYRIGHT (c) 1989-1999. |
---|
[378fe02] | 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 |
---|
[cf0539b1] | 9 | * http://www.rtems.com/license/LICENSE. |
---|
[378fe02] | 10 | */ |
---|
| 11 | |
---|
[d6b1d73] | 12 | #if HAVE_CONFIG_H |
---|
[3b7c123] | 13 | #include "config.h" |
---|
[d6b1d73] | 14 | #endif |
---|
| 15 | |
---|
[378fe02] | 16 | #include "imfs.h" |
---|
| 17 | |
---|
[699ac7c] | 18 | #include <stdlib.h> |
---|
[e998c985] | 19 | #include <string.h> |
---|
| 20 | |
---|
| 21 | static int IMFS_stat_link( |
---|
| 22 | const rtems_filesystem_location_info_t *loc, |
---|
| 23 | struct stat *buf |
---|
| 24 | ) |
---|
| 25 | { |
---|
| 26 | const IMFS_jnode_t *node = loc->node_access; |
---|
| 27 | |
---|
| 28 | if ( IMFS_type( node ) != IMFS_HARD_LINK ) { |
---|
| 29 | buf->st_size = strlen( node->info.sym_link.name ); |
---|
| 30 | |
---|
| 31 | return IMFS_stat( loc, buf ); |
---|
| 32 | } else { |
---|
| 33 | rtems_filesystem_location_info_t targetloc = *loc; |
---|
| 34 | |
---|
| 35 | targetloc.node_access = node->info.hard_link.link_node; |
---|
| 36 | IMFS_Set_handlers( &targetloc ); |
---|
| 37 | |
---|
| 38 | return (targetloc.handlers->fstat_h)( &targetloc, buf ); |
---|
| 39 | } |
---|
| 40 | } |
---|
[378fe02] | 41 | |
---|
[699ac7c] | 42 | static const rtems_filesystem_file_handlers_r IMFS_link_handlers = { |
---|
[962571e9] | 43 | rtems_filesystem_default_open, |
---|
| 44 | rtems_filesystem_default_close, |
---|
| 45 | rtems_filesystem_default_read, |
---|
| 46 | rtems_filesystem_default_write, |
---|
| 47 | rtems_filesystem_default_ioctl, |
---|
| 48 | rtems_filesystem_default_lseek, |
---|
[e998c985] | 49 | IMFS_stat_link, |
---|
[962571e9] | 50 | rtems_filesystem_default_ftruncate, |
---|
[4116fce6] | 51 | rtems_filesystem_default_fsync_or_fdatasync, |
---|
| 52 | rtems_filesystem_default_fsync_or_fdatasync, |
---|
[3b7c123] | 53 | rtems_filesystem_default_fcntl |
---|
[378fe02] | 54 | }; |
---|
[699ac7c] | 55 | |
---|
| 56 | static IMFS_jnode_t *IMFS_node_initialize_hard_link( |
---|
| 57 | IMFS_jnode_t *node, |
---|
| 58 | const IMFS_types_union *info |
---|
| 59 | ) |
---|
| 60 | { |
---|
| 61 | node->info.hard_link.link_node = info->hard_link.link_node; |
---|
| 62 | |
---|
| 63 | return node; |
---|
| 64 | } |
---|
| 65 | |
---|
| 66 | static IMFS_jnode_t *IMFS_node_remove_hard_link( |
---|
| 67 | IMFS_jnode_t *node, |
---|
| 68 | const IMFS_jnode_t *root_node |
---|
| 69 | ) |
---|
| 70 | { |
---|
| 71 | IMFS_jnode_t *target = node->info.hard_link.link_node; |
---|
| 72 | |
---|
| 73 | if ( target->st_nlink == 1) { |
---|
| 74 | target = (*target->control->node_remove)( target, root_node ); |
---|
| 75 | if ( target == NULL ) { |
---|
| 76 | node = NULL; |
---|
| 77 | } |
---|
| 78 | } else { |
---|
| 79 | --target->st_nlink; |
---|
| 80 | IMFS_update_ctime( target ); |
---|
| 81 | } |
---|
| 82 | |
---|
| 83 | return node; |
---|
| 84 | } |
---|
| 85 | |
---|
| 86 | const IMFS_node_control IMFS_node_control_hard_link = { |
---|
| 87 | .imfs_type = IMFS_HARD_LINK, |
---|
| 88 | .handlers = &IMFS_link_handlers, |
---|
| 89 | .node_initialize = IMFS_node_initialize_hard_link, |
---|
| 90 | .node_remove = IMFS_node_remove_hard_link, |
---|
| 91 | .node_destroy = IMFS_node_destroy_default |
---|
| 92 | }; |
---|
| 93 | |
---|
| 94 | static IMFS_jnode_t *IMFS_node_initialize_sym_link( |
---|
| 95 | IMFS_jnode_t *node, |
---|
| 96 | const IMFS_types_union *info |
---|
| 97 | ) |
---|
| 98 | { |
---|
| 99 | node->info.sym_link.name = info->sym_link.name; |
---|
| 100 | |
---|
| 101 | return node; |
---|
| 102 | } |
---|
| 103 | |
---|
| 104 | static IMFS_jnode_t *IMFS_node_destroy_sym_link( IMFS_jnode_t *node ) |
---|
| 105 | { |
---|
| 106 | free( node->info.sym_link.name ); |
---|
| 107 | |
---|
| 108 | return node; |
---|
| 109 | } |
---|
| 110 | |
---|
| 111 | const IMFS_node_control IMFS_node_control_sym_link = { |
---|
| 112 | .imfs_type = IMFS_SYM_LINK, |
---|
| 113 | .handlers = &IMFS_link_handlers, |
---|
| 114 | .node_initialize = IMFS_node_initialize_sym_link, |
---|
| 115 | .node_remove = IMFS_node_remove_default, |
---|
| 116 | .node_destroy = IMFS_node_destroy_sym_link |
---|
| 117 | }; |
---|