1 | /** |
---|
2 | * @file |
---|
3 | * |
---|
4 | * @brief RTEMS File System Location Support |
---|
5 | * @ingroup LibIOInternal |
---|
6 | */ |
---|
7 | |
---|
8 | /* |
---|
9 | * COPYRIGHT (c) 1989-2008. |
---|
10 | * On-Line Applications Research Corporation (OAR). |
---|
11 | * |
---|
12 | * Modifications to support reference counting in the file system are |
---|
13 | * Copyright (c) 2012 embedded brains GmbH. |
---|
14 | * |
---|
15 | * The license and distribution terms for this file may be |
---|
16 | * found in the file LICENSE in this distribution or at |
---|
17 | * http://www.rtems.org/license/LICENSE. |
---|
18 | */ |
---|
19 | |
---|
20 | #if HAVE_CONFIG_H |
---|
21 | #include "config.h" |
---|
22 | #endif |
---|
23 | |
---|
24 | #include <sys/stat.h> |
---|
25 | |
---|
26 | #include <rtems/libio_.h> |
---|
27 | |
---|
28 | static int null_handler_open( |
---|
29 | rtems_libio_t *iop, |
---|
30 | const char *path, |
---|
31 | int oflag, |
---|
32 | mode_t mode |
---|
33 | ) |
---|
34 | { |
---|
35 | return -1; |
---|
36 | } |
---|
37 | |
---|
38 | static int null_handler_fstat( |
---|
39 | const rtems_filesystem_location_info_t *pathloc, |
---|
40 | struct stat *buf |
---|
41 | ) |
---|
42 | { |
---|
43 | return -1; |
---|
44 | } |
---|
45 | |
---|
46 | const rtems_filesystem_file_handlers_r rtems_filesystem_null_handlers = { |
---|
47 | .open_h = null_handler_open, |
---|
48 | .close_h = rtems_filesystem_default_close, |
---|
49 | .read_h = rtems_filesystem_default_read, |
---|
50 | .write_h = rtems_filesystem_default_write, |
---|
51 | .ioctl_h = rtems_filesystem_default_ioctl, |
---|
52 | .lseek_h = rtems_filesystem_default_lseek, |
---|
53 | .fstat_h = null_handler_fstat, |
---|
54 | .ftruncate_h = rtems_filesystem_default_ftruncate, |
---|
55 | .fsync_h = rtems_filesystem_default_fsync_or_fdatasync, |
---|
56 | .fdatasync_h = rtems_filesystem_default_fsync_or_fdatasync, |
---|
57 | .fcntl_h = rtems_filesystem_default_fcntl, |
---|
58 | .kqfilter_h = rtems_filesystem_default_kqfilter, |
---|
59 | .poll_h = rtems_filesystem_default_poll, |
---|
60 | .readv_h = rtems_filesystem_default_readv, |
---|
61 | .writev_h = rtems_filesystem_default_writev |
---|
62 | }; |
---|
63 | |
---|
64 | static void null_op_lock_or_unlock( |
---|
65 | const rtems_filesystem_mount_table_entry_t *mt_entry |
---|
66 | ) |
---|
67 | { |
---|
68 | /* Do nothing */ |
---|
69 | } |
---|
70 | |
---|
71 | static int null_op_mknod( |
---|
72 | const rtems_filesystem_location_info_t *parentloc, |
---|
73 | const char *name, |
---|
74 | size_t namelen, |
---|
75 | mode_t mode, |
---|
76 | dev_t dev |
---|
77 | ) |
---|
78 | { |
---|
79 | return -1; |
---|
80 | } |
---|
81 | |
---|
82 | static int null_op_rmnod( |
---|
83 | const rtems_filesystem_location_info_t *parentloc, |
---|
84 | const rtems_filesystem_location_info_t *loc |
---|
85 | ) |
---|
86 | { |
---|
87 | return -1; |
---|
88 | } |
---|
89 | |
---|
90 | static int null_op_link( |
---|
91 | const rtems_filesystem_location_info_t *parentloc, |
---|
92 | const rtems_filesystem_location_info_t *targetloc, |
---|
93 | const char *name, |
---|
94 | size_t namelen |
---|
95 | ) |
---|
96 | { |
---|
97 | return -1; |
---|
98 | } |
---|
99 | |
---|
100 | static int null_op_fchmod( |
---|
101 | const rtems_filesystem_location_info_t *pathloc, |
---|
102 | mode_t mode |
---|
103 | ) |
---|
104 | { |
---|
105 | return -1; |
---|
106 | } |
---|
107 | |
---|
108 | static int null_op_chown( |
---|
109 | const rtems_filesystem_location_info_t *loc, |
---|
110 | uid_t owner, |
---|
111 | gid_t group |
---|
112 | ) |
---|
113 | { |
---|
114 | return -1; |
---|
115 | } |
---|
116 | |
---|
117 | static int null_op_clonenode( |
---|
118 | rtems_filesystem_location_info_t *loc |
---|
119 | ) |
---|
120 | { |
---|
121 | return -1; |
---|
122 | } |
---|
123 | |
---|
124 | static int null_op_mount( |
---|
125 | rtems_filesystem_mount_table_entry_t *mt_entry |
---|
126 | ) |
---|
127 | { |
---|
128 | return -1; |
---|
129 | } |
---|
130 | |
---|
131 | static int null_op_fsmount_me( |
---|
132 | rtems_filesystem_mount_table_entry_t *mt_entry, |
---|
133 | const void *data |
---|
134 | ) |
---|
135 | { |
---|
136 | return -1; |
---|
137 | } |
---|
138 | |
---|
139 | static int null_op_unmount( |
---|
140 | rtems_filesystem_mount_table_entry_t *mt_entry |
---|
141 | ) |
---|
142 | { |
---|
143 | return -1; |
---|
144 | } |
---|
145 | |
---|
146 | static void null_op_fsunmount_me( |
---|
147 | rtems_filesystem_mount_table_entry_t *mt_entry |
---|
148 | ) |
---|
149 | { |
---|
150 | /* Do nothing */ |
---|
151 | } |
---|
152 | |
---|
153 | static int null_op_utime( |
---|
154 | const rtems_filesystem_location_info_t *loc, |
---|
155 | time_t actime, |
---|
156 | time_t modtime |
---|
157 | ) |
---|
158 | { |
---|
159 | return -1; |
---|
160 | } |
---|
161 | |
---|
162 | static int null_op_symlink( |
---|
163 | const rtems_filesystem_location_info_t *parentloc, |
---|
164 | const char *name, |
---|
165 | size_t namelen, |
---|
166 | const char *target |
---|
167 | ) |
---|
168 | { |
---|
169 | return -1; |
---|
170 | } |
---|
171 | |
---|
172 | static ssize_t null_op_readlink( |
---|
173 | const rtems_filesystem_location_info_t *loc, |
---|
174 | char *buf, |
---|
175 | size_t bufsize |
---|
176 | ) |
---|
177 | { |
---|
178 | return -1; |
---|
179 | } |
---|
180 | |
---|
181 | static int null_op_rename( |
---|
182 | const rtems_filesystem_location_info_t *oldparentloc, |
---|
183 | const rtems_filesystem_location_info_t *oldloc, |
---|
184 | const rtems_filesystem_location_info_t *newparentloc, |
---|
185 | const char *name, |
---|
186 | size_t namelen |
---|
187 | ) |
---|
188 | { |
---|
189 | return -1; |
---|
190 | } |
---|
191 | |
---|
192 | static int null_op_statvfs( |
---|
193 | const rtems_filesystem_location_info_t *__restrict loc, |
---|
194 | struct statvfs *__restrict buf |
---|
195 | ) |
---|
196 | { |
---|
197 | return -1; |
---|
198 | } |
---|
199 | |
---|
200 | static const rtems_filesystem_operations_table null_ops = { |
---|
201 | .lock_h = null_op_lock_or_unlock, |
---|
202 | .unlock_h = null_op_lock_or_unlock, |
---|
203 | .eval_path_h = rtems_filesystem_default_eval_path, |
---|
204 | .link_h = null_op_link, |
---|
205 | .are_nodes_equal_h = rtems_filesystem_default_are_nodes_equal, |
---|
206 | .mknod_h = null_op_mknod, |
---|
207 | .rmnod_h = null_op_rmnod, |
---|
208 | .fchmod_h = null_op_fchmod, |
---|
209 | .chown_h = null_op_chown, |
---|
210 | .clonenod_h = null_op_clonenode, |
---|
211 | .freenod_h = rtems_filesystem_default_freenode, |
---|
212 | .mount_h = null_op_mount, |
---|
213 | .fsmount_me_h = null_op_fsmount_me, |
---|
214 | .unmount_h = null_op_unmount, |
---|
215 | .fsunmount_me_h = null_op_fsunmount_me, |
---|
216 | .utime_h = null_op_utime, |
---|
217 | .symlink_h = null_op_symlink, |
---|
218 | .readlink_h = null_op_readlink, |
---|
219 | .rename_h = null_op_rename, |
---|
220 | .statvfs_h = null_op_statvfs |
---|
221 | }; |
---|
222 | |
---|
223 | rtems_filesystem_mount_table_entry_t rtems_filesystem_null_mt_entry = { |
---|
224 | .location_chain = RTEMS_CHAIN_INITIALIZER_ONE_NODE( |
---|
225 | &rtems_filesystem_global_location_null.location.mt_entry_node |
---|
226 | ), |
---|
227 | .ops = &null_ops, |
---|
228 | .mt_point_node = &rtems_filesystem_global_location_null, |
---|
229 | .mt_fs_root = &rtems_filesystem_global_location_null, |
---|
230 | .mounted = false, |
---|
231 | .writeable = false, |
---|
232 | .type = "" |
---|
233 | }; |
---|
234 | |
---|
235 | rtems_filesystem_global_location_t rtems_filesystem_global_location_null = { |
---|
236 | .location = { |
---|
237 | .mt_entry_node = RTEMS_CHAIN_NODE_INITIALIZER_ONE_NODE_CHAIN( |
---|
238 | &rtems_filesystem_null_mt_entry.location_chain |
---|
239 | ), |
---|
240 | .handlers = &rtems_filesystem_null_handlers, |
---|
241 | .mt_entry = &rtems_filesystem_null_mt_entry |
---|
242 | }, |
---|
243 | |
---|
244 | /* |
---|
245 | * The initial reference count accounts for the following references |
---|
246 | * o the root directory of the user environment, |
---|
247 | * o the current directory of the user environment, |
---|
248 | * o the root node of the null file system instance, and |
---|
249 | * o the mount point node of the null file system instance. |
---|
250 | */ |
---|
251 | .reference_count = 4 |
---|
252 | }; |
---|
253 | |
---|
254 | rtems_user_env_t rtems_global_user_env = { |
---|
255 | .current_directory = &rtems_filesystem_global_location_null, |
---|
256 | .root_directory = &rtems_filesystem_global_location_null, |
---|
257 | .umask = S_IWGRP | S_IWOTH |
---|
258 | }; |
---|
259 | |
---|
260 | pthread_key_t rtems_current_user_env_key; |
---|