1 | /* |
---|
2 | * COPYRIGHT (c) 2010 Chris Johns <chrisj@rtems.org> |
---|
3 | * |
---|
4 | * The license and distribution terms for this file may be |
---|
5 | * found in the file LICENSE in this distribution or at |
---|
6 | * http://www.rtems.com/license/LICENSE. |
---|
7 | * |
---|
8 | * $Id$ |
---|
9 | */ |
---|
10 | /** |
---|
11 | * @file |
---|
12 | * |
---|
13 | * @ingroup rtems-rfs |
---|
14 | * |
---|
15 | * RTEMS File System RTEMS Header file. |
---|
16 | * |
---|
17 | * This file is not to be installed. It binds the RFS file system to RTEMS. |
---|
18 | */ |
---|
19 | |
---|
20 | #if !defined(RTEMS_RFS_RTEMS_DEFINED) |
---|
21 | #define RTEMS_RFS_RTEMS_DEFINED |
---|
22 | |
---|
23 | #include <stdbool.h> |
---|
24 | #include <stdint.h> |
---|
25 | #include <errno.h> |
---|
26 | |
---|
27 | /** |
---|
28 | * RTEMS RFS RTEMS Error Enable. Set to 1 for printing of errors. Default is off. |
---|
29 | */ |
---|
30 | #define RTEMS_RFS_RTEMS_ERROR 0 |
---|
31 | |
---|
32 | /** |
---|
33 | * RTEMS RFS RTEMS Trace Enable. Set to 1 for printing of errors. Default is off. |
---|
34 | */ |
---|
35 | #define RTEMS_RFS_RTEMS_TRACE 0 |
---|
36 | |
---|
37 | /** |
---|
38 | * If we are not handling errors provide a define that removes the strings from |
---|
39 | * the code. |
---|
40 | */ |
---|
41 | #if !RTEMS_RFS_RTEMS_ERROR |
---|
42 | #define rtems_rfs_rtems_error(_m, _e) \ |
---|
43 | (((errno = (_e)) == 0) ? 0 : -1) |
---|
44 | #else |
---|
45 | /** |
---|
46 | * Take the result code and set errno with it and if non-zero return -1 else |
---|
47 | * return 0. |
---|
48 | * |
---|
49 | * @param what The message to print is the error is not zero. |
---|
50 | * @param error The error code. |
---|
51 | * @retval -1 An error has occured. |
---|
52 | * @retval 0 No error. |
---|
53 | */ |
---|
54 | int rtems_rfs_rtems_error (const char* mesg, int error); |
---|
55 | #endif |
---|
56 | |
---|
57 | /** |
---|
58 | * Trace message defines the RTEMS bindings of the RTEMS RFS. This is a |
---|
59 | * development tool where can edit the values below to control the various trace |
---|
60 | * output. |
---|
61 | */ |
---|
62 | #define RTEMS_RFS_RTEMS_DEBUG_ALL (0xffffffff) |
---|
63 | #define RTEMS_RFS_RTEMS_DEBUG_ERROR_MSGS (1 << 0) |
---|
64 | #define RTEMS_RFS_RTEMS_DEBUG_EVAL_PATH (1 << 1) |
---|
65 | #define RTEMS_RFS_RTEMS_DEBUG_EVAL_FOR_MAKE (1 << 2) |
---|
66 | #define RTEMS_RFS_RTEMS_DEBUG_EVAL_PERMS (1 << 3) |
---|
67 | #define RTEMS_RFS_RTEMS_DEBUG_MKNOD (1 << 4) |
---|
68 | #define RTEMS_RFS_RTEMS_DEBUG_RMNOD (1 << 5) |
---|
69 | #define RTEMS_RFS_RTEMS_DEBUG_LINK (1 << 6) |
---|
70 | #define RTEMS_RFS_RTEMS_DEBUG_UNLINK (1 << 7) |
---|
71 | #define RTEMS_RFS_RTEMS_DEBUG_CHOWN (1 << 8) |
---|
72 | #define RTEMS_RFS_RTEMS_DEBUG_READLINK (1 << 9) |
---|
73 | #define RTEMS_RFS_RTEMS_DEBUG_FCHMOD (1 << 10) |
---|
74 | #define RTEMS_RFS_RTEMS_DEBUG_STAT (1 << 11) |
---|
75 | #define RTEMS_RFS_RTEMS_DEBUG_RENAME (1 << 12) |
---|
76 | #define RTEMS_RFS_RTEMS_DEBUG_DIR_RMNOD (1 << 13) |
---|
77 | #define RTEMS_RFS_RTEMS_DEBUG_FILE_OPEN (1 << 14) |
---|
78 | #define RTEMS_RFS_RTEMS_DEBUG_FILE_CLOSE (1 << 15) |
---|
79 | #define RTEMS_RFS_RTEMS_DEBUG_FILE_READ (1 << 16) |
---|
80 | #define RTEMS_RFS_RTEMS_DEBUG_FILE_WRITE (1 << 17) |
---|
81 | #define RTEMS_RFS_RTEMS_DEBUG_FILE_LSEEK (1 << 18) |
---|
82 | #define RTEMS_RFS_RTEMS_DEBUG_FILE_FTRUNC (1 << 19) |
---|
83 | |
---|
84 | /** |
---|
85 | * Call to check if this part is bring traced. If RTEMS_RFS_RTEMS_TRACE is |
---|
86 | * defined to 0 the code is dead code elminiated when built with -Os, -O2, or |
---|
87 | * higher. |
---|
88 | * |
---|
89 | * @param mask The part of the API to trace. |
---|
90 | * @retval true Tracing is active for the mask. |
---|
91 | * @retval false Do not trace. |
---|
92 | */ |
---|
93 | #if RTEMS_RFS_RTEMS_TRACE |
---|
94 | bool rtems_rfs_rtems_trace (uint32_t mask); |
---|
95 | #else |
---|
96 | #define rtems_rfs_rtems_trace(_m) (0) |
---|
97 | #endif |
---|
98 | |
---|
99 | /** |
---|
100 | * Set the mask. |
---|
101 | * |
---|
102 | * @param mask The mask bits to set. |
---|
103 | * @return The previous mask. |
---|
104 | */ |
---|
105 | #if RTEMS_RFS_RTEMS_TRACE |
---|
106 | void rtems_rfs_rtems_trace_set_mask (uint32_t mask); |
---|
107 | #else |
---|
108 | #define rtems_rfs_rtems_trace_set_mask(_m) |
---|
109 | #endif |
---|
110 | |
---|
111 | /** |
---|
112 | * Clear the mask. |
---|
113 | * |
---|
114 | * @param mask The mask bits to clear. |
---|
115 | * @return The previous mask. |
---|
116 | */ |
---|
117 | #if RTEMS_RFS_RTEMS_TRACE |
---|
118 | void rtems_rfs_rtems_trace_clear_mask (uint32_t mask); |
---|
119 | #else |
---|
120 | #define rtems_rfs_rtems_trace_clear_mask(_m) |
---|
121 | #endif |
---|
122 | |
---|
123 | /** |
---|
124 | * Add shell trace shell command. |
---|
125 | */ |
---|
126 | #if RTEMS_RFS_RTEMS_TRACE |
---|
127 | int rtems_rfs_rtems_trace_shell_command (int argc, char *argv[]); |
---|
128 | #endif |
---|
129 | |
---|
130 | #include <rtems/rfs/rtems-rfs-file-system.h> |
---|
131 | #include <rtems/rfs/rtems-rfs-inode.h> |
---|
132 | #include <rtems/rfs/rtems-rfs-mutex.h> |
---|
133 | #include <rtems/libio_.h> |
---|
134 | #include <rtems/fs.h> |
---|
135 | |
---|
136 | /** |
---|
137 | * Private RFS RTEMS Port data. |
---|
138 | */ |
---|
139 | typedef struct rtems_rfs_rtems_private |
---|
140 | { |
---|
141 | /** |
---|
142 | * The access lock. |
---|
143 | */ |
---|
144 | rtems_rfs_mutex access; |
---|
145 | } rtems_rfs_rtems_private; |
---|
146 | /** |
---|
147 | * Return the file system structure given a path location. |
---|
148 | * |
---|
149 | * @param _loc Pointer to the path location. |
---|
150 | * @return rtems_rfs_file_system* |
---|
151 | */ |
---|
152 | #define rtems_rfs_rtems_pathloc_dev(_loc) \ |
---|
153 | ((rtems_rfs_file_system*)((_loc)->mt_entry->fs_info)) |
---|
154 | |
---|
155 | /** |
---|
156 | * Set the inode number (ino) into the path location. |
---|
157 | * |
---|
158 | * @param _loc Pointer to the path location. |
---|
159 | * @param _ino The ino to set in the path location. |
---|
160 | */ |
---|
161 | #define rtems_rfs_rtems_set_pathloc_ino(_loc, _ino) \ |
---|
162 | (_loc)->node_access = (void*)((intptr_t)(_ino)) |
---|
163 | |
---|
164 | /** |
---|
165 | * Get the inode number (ino) given a path location. |
---|
166 | * |
---|
167 | * @param _loc Pointer to the path location. |
---|
168 | * @return rtems_rfs_ino The inode number in the path location. |
---|
169 | */ |
---|
170 | #define rtems_rfs_rtems_get_pathloc_ino(_loc) \ |
---|
171 | ((rtems_rfs_ino) (intptr_t)((_loc)->node_access)) |
---|
172 | |
---|
173 | /** |
---|
174 | * Set the directory offset (doff) into the path location. |
---|
175 | * |
---|
176 | * @param _loc Pointer to the path location. |
---|
177 | * @param _doff The doff to set in the path location. |
---|
178 | */ |
---|
179 | #define rtems_rfs_rtems_set_pathloc_doff(_loc, _doff) \ |
---|
180 | (_loc)->node_access_2 = (void*)((intptr_t)(_doff)) |
---|
181 | |
---|
182 | /** |
---|
183 | * Get the directory offset (doff) given a path location. |
---|
184 | * |
---|
185 | * @param _loc Pointer to the path location. |
---|
186 | * @return uin32_t The doff in the path location. |
---|
187 | */ |
---|
188 | #define rtems_rfs_rtems_get_pathloc_doff(_loc) \ |
---|
189 | ((uint32_t) (intptr_t)((_loc)->node_access_2)) |
---|
190 | |
---|
191 | /** |
---|
192 | * Get the ino from the I/O pointer. |
---|
193 | * |
---|
194 | * @param _iop The I/O pointer. |
---|
195 | * @return ino |
---|
196 | */ |
---|
197 | #define rtems_rfs_rtems_get_iop_ino(_iop) \ |
---|
198 | ((intptr_t)(_iop)->pathinfo.node_access) |
---|
199 | |
---|
200 | /** |
---|
201 | * Get the file handle from the I/O pointer. |
---|
202 | * |
---|
203 | * @param _iop The I/O pointer. |
---|
204 | * @return filehandle The file handle |
---|
205 | */ |
---|
206 | #define rtems_rfs_rtems_get_iop_file_handle(_iop) \ |
---|
207 | ((rtems_rfs_file_handle*)(_iop)->pathinfo.node_access_2) |
---|
208 | |
---|
209 | /** |
---|
210 | * Set the file handle in the I/O pointer. |
---|
211 | * |
---|
212 | * @param _iop The I/O pointer. |
---|
213 | * @param _fh The file handle. |
---|
214 | */ |
---|
215 | #define rtems_rfs_rtems_set_iop_file_handle(_iop, _fh) \ |
---|
216 | (_iop)->pathinfo.node_access_2 = (_fh) |
---|
217 | |
---|
218 | /** |
---|
219 | * Create the name of the handler's table given the type of handlers. |
---|
220 | * |
---|
221 | * @param _h The name of the handlers. |
---|
222 | * @return label The name of the handler's table. |
---|
223 | */ |
---|
224 | #define rtems_rfs_rtems_handlers(_h) \ |
---|
225 | &rtems_rfs_rtems_ ## _h ## _handlers |
---|
226 | |
---|
227 | /** |
---|
228 | * Evaluate the permissions of the inode's mode against the flags. |
---|
229 | * |
---|
230 | * @param inode The inode handler to check the mode, uid and gid. |
---|
231 | * @param flags The flags to check permissions of. |
---|
232 | * @retval true The permissions allow access to the inode. |
---|
233 | * @retval false Access to the inode is not permitted. |
---|
234 | */ |
---|
235 | bool rtems_rfs_rtems_eval_perms (rtems_rfs_inode_handle* inode, int flags); |
---|
236 | |
---|
237 | /** |
---|
238 | * Set the handlers in the path location based on the mode of the inode. |
---|
239 | * |
---|
240 | * @param loc Pointer to the path location to set the handlers in. |
---|
241 | * @param inode The inode handle to check the mode of for the type of handlers. |
---|
242 | * @retval true The handlers have been set. |
---|
243 | * @retval false There are no handlers for the mode. |
---|
244 | */ |
---|
245 | bool rtems_rfs_rtems_set_handlers (rtems_filesystem_location_info_t* pathloc, |
---|
246 | rtems_rfs_inode_handle* inode); |
---|
247 | |
---|
248 | /** |
---|
249 | * Convert the system mode flags to inode mode flags. |
---|
250 | * |
---|
251 | * @param mode The system mode flags. |
---|
252 | * @return uint16_t The inode mode flags. |
---|
253 | */ |
---|
254 | uint16_t rtems_rfs_rtems_imode (mode_t mode); |
---|
255 | |
---|
256 | /** |
---|
257 | * Convert the inode mode flags to system mode flags. |
---|
258 | * |
---|
259 | * @param imode The inode mode flags |
---|
260 | * @return mode_t The system mode flags. |
---|
261 | */ |
---|
262 | mode_t rtems_rfs_rtems_mode (int imode); |
---|
263 | |
---|
264 | /** |
---|
265 | * Lock the RFS file system. |
---|
266 | */ |
---|
267 | static inline void |
---|
268 | rtems_rfs_rtems_lock (rtems_rfs_file_system* fs) |
---|
269 | { |
---|
270 | rtems_rfs_rtems_private* rtems = rtems_rfs_fs_user (fs); |
---|
271 | rtems_rfs_mutex_lock (&rtems->access); |
---|
272 | } |
---|
273 | |
---|
274 | /** |
---|
275 | * Unlock the RFS file system. |
---|
276 | */ |
---|
277 | static inline void |
---|
278 | rtems_rfs_rtems_unlock (rtems_rfs_file_system* fs) |
---|
279 | { |
---|
280 | rtems_rfs_rtems_private* rtems = rtems_rfs_fs_user (fs); |
---|
281 | rtems_rfs_buffers_release (fs); |
---|
282 | rtems_rfs_mutex_unlock (&rtems->access); |
---|
283 | } |
---|
284 | |
---|
285 | /** |
---|
286 | * The handlers. |
---|
287 | */ |
---|
288 | extern const rtems_filesystem_file_handlers_r rtems_rfs_rtems_dir_handlers; |
---|
289 | extern const rtems_filesystem_file_handlers_r rtems_rfs_rtems_device_handlers; |
---|
290 | extern const rtems_filesystem_file_handlers_r rtems_rfs_rtems_link_handlers; |
---|
291 | extern const rtems_filesystem_file_handlers_r rtems_rfs_rtems_file_handlers; |
---|
292 | |
---|
293 | /** |
---|
294 | * The following routine does a stat on a node. |
---|
295 | * |
---|
296 | * @param iop |
---|
297 | * @param buf |
---|
298 | * @return int |
---|
299 | */ |
---|
300 | int rtems_rfs_rtems_fstat (rtems_filesystem_location_info_t* pathloc, |
---|
301 | struct stat* buf); |
---|
302 | |
---|
303 | /** |
---|
304 | * File change mode routine. |
---|
305 | * |
---|
306 | * @param iop |
---|
307 | * @param mode |
---|
308 | * @return int |
---|
309 | */ |
---|
310 | int rtems_rfs_rtems_fchmod (rtems_filesystem_location_info_t* pathloc, |
---|
311 | mode_t mode); |
---|
312 | |
---|
313 | /** |
---|
314 | * Routine to remove a node from the RFS file system. |
---|
315 | * |
---|
316 | * @param parent_pathloc |
---|
317 | * @param pathloc |
---|
318 | */ |
---|
319 | int rtems_rfs_rtems_rmnod (rtems_filesystem_location_info_t* parent_pathloc, |
---|
320 | rtems_filesystem_location_info_t* pathloc); |
---|
321 | |
---|
322 | /** |
---|
323 | * The following routine does a sync on an inode node. Currently it flushes |
---|
324 | * everything related to this device. |
---|
325 | * |
---|
326 | * @param iop |
---|
327 | */ |
---|
328 | int rtems_rfs_rtems_fdatasync (rtems_libio_t* iop); |
---|
329 | |
---|
330 | #endif |
---|