1 | /** |
---|
2 | * @file |
---|
3 | * |
---|
4 | * @brief Link Operations Table for the IMFS |
---|
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 <stdlib.h> |
---|
24 | #include <string.h> |
---|
25 | |
---|
26 | static int IMFS_stat_link( |
---|
27 | const rtems_filesystem_location_info_t *loc, |
---|
28 | struct stat *buf |
---|
29 | ) |
---|
30 | { |
---|
31 | const IMFS_jnode_t *node = loc->node_access; |
---|
32 | |
---|
33 | if ( IMFS_type( node ) != IMFS_HARD_LINK ) { |
---|
34 | buf->st_size = strlen( node->info.sym_link.name ); |
---|
35 | |
---|
36 | return IMFS_stat( loc, buf ); |
---|
37 | } else { |
---|
38 | rtems_filesystem_location_info_t targetloc = *loc; |
---|
39 | |
---|
40 | targetloc.node_access = node->info.hard_link.link_node; |
---|
41 | IMFS_Set_handlers( &targetloc ); |
---|
42 | |
---|
43 | return (targetloc.handlers->fstat_h)( &targetloc, buf ); |
---|
44 | } |
---|
45 | } |
---|
46 | |
---|
47 | static const rtems_filesystem_file_handlers_r IMFS_link_handlers = { |
---|
48 | .open_h = rtems_filesystem_default_open, |
---|
49 | .close_h = rtems_filesystem_default_close, |
---|
50 | .read_h = rtems_filesystem_default_read, |
---|
51 | .write_h = rtems_filesystem_default_write, |
---|
52 | .ioctl_h = rtems_filesystem_default_ioctl, |
---|
53 | .lseek_h = rtems_filesystem_default_lseek, |
---|
54 | .fstat_h = IMFS_stat_link, |
---|
55 | .ftruncate_h = rtems_filesystem_default_ftruncate, |
---|
56 | .fsync_h = rtems_filesystem_default_fsync_or_fdatasync, |
---|
57 | .fdatasync_h = rtems_filesystem_default_fsync_or_fdatasync, |
---|
58 | .fcntl_h = rtems_filesystem_default_fcntl, |
---|
59 | .kqfilter_h = rtems_filesystem_default_kqfilter, |
---|
60 | .poll_h = rtems_filesystem_default_poll, |
---|
61 | .readv_h = rtems_filesystem_default_readv, |
---|
62 | .writev_h = rtems_filesystem_default_writev |
---|
63 | }; |
---|
64 | |
---|
65 | static IMFS_jnode_t *IMFS_node_initialize_hard_link( |
---|
66 | IMFS_jnode_t *node, |
---|
67 | const IMFS_types_union *info |
---|
68 | ) |
---|
69 | { |
---|
70 | node->info.hard_link.link_node = info->hard_link.link_node; |
---|
71 | |
---|
72 | return node; |
---|
73 | } |
---|
74 | |
---|
75 | static IMFS_jnode_t *IMFS_node_remove_hard_link( |
---|
76 | IMFS_jnode_t *node |
---|
77 | ) |
---|
78 | { |
---|
79 | IMFS_jnode_t *target = node->info.hard_link.link_node; |
---|
80 | |
---|
81 | _Assert( target != NULL ); |
---|
82 | |
---|
83 | if ( target->st_nlink == 1) { |
---|
84 | target = (*target->control->node_remove)( target ); |
---|
85 | if ( target == NULL ) { |
---|
86 | node = NULL; |
---|
87 | } |
---|
88 | } else { |
---|
89 | --target->st_nlink; |
---|
90 | IMFS_update_ctime( target ); |
---|
91 | } |
---|
92 | |
---|
93 | return node; |
---|
94 | } |
---|
95 | |
---|
96 | const IMFS_node_control IMFS_node_control_hard_link = { |
---|
97 | .imfs_type = IMFS_HARD_LINK, |
---|
98 | .handlers = &IMFS_link_handlers, |
---|
99 | .node_initialize = IMFS_node_initialize_hard_link, |
---|
100 | .node_remove = IMFS_node_remove_hard_link, |
---|
101 | .node_destroy = IMFS_node_destroy_default |
---|
102 | }; |
---|
103 | |
---|
104 | static IMFS_jnode_t *IMFS_node_initialize_sym_link( |
---|
105 | IMFS_jnode_t *node, |
---|
106 | const IMFS_types_union *info |
---|
107 | ) |
---|
108 | { |
---|
109 | node->info.sym_link.name = info->sym_link.name; |
---|
110 | |
---|
111 | return node; |
---|
112 | } |
---|
113 | |
---|
114 | static IMFS_jnode_t *IMFS_node_destroy_sym_link( IMFS_jnode_t *node ) |
---|
115 | { |
---|
116 | free( node->info.sym_link.name ); |
---|
117 | |
---|
118 | return node; |
---|
119 | } |
---|
120 | |
---|
121 | const IMFS_node_control IMFS_node_control_sym_link = { |
---|
122 | .imfs_type = IMFS_SYM_LINK, |
---|
123 | .handlers = &IMFS_link_handlers, |
---|
124 | .node_initialize = IMFS_node_initialize_sym_link, |
---|
125 | .node_remove = IMFS_node_remove_default, |
---|
126 | .node_destroy = IMFS_node_destroy_sym_link |
---|
127 | }; |
---|