1 | /** |
---|
2 | * @file |
---|
3 | * |
---|
4 | * @ingroup LibIO |
---|
5 | * |
---|
6 | * @brief Basic IO API. |
---|
7 | */ |
---|
8 | |
---|
9 | /* |
---|
10 | * COPYRIGHT (c) 1989-2008. |
---|
11 | * On-Line Applications Research Corporation (OAR). |
---|
12 | * |
---|
13 | * The license and distribution terms for this file may be |
---|
14 | * found in the file LICENSE in this distribution or at |
---|
15 | * http://www.rtems.com/license/LICENSE. |
---|
16 | * |
---|
17 | * $Id$ |
---|
18 | */ |
---|
19 | |
---|
20 | #ifndef _RTEMS_RTEMS_LIBIO_H |
---|
21 | #define _RTEMS_RTEMS_LIBIO_H |
---|
22 | |
---|
23 | #include <sys/types.h> |
---|
24 | #include <sys/stat.h> |
---|
25 | #include <sys/ioctl.h> |
---|
26 | #include <sys/statvfs.h> |
---|
27 | |
---|
28 | #include <unistd.h> |
---|
29 | #include <termios.h> |
---|
30 | |
---|
31 | #include <rtems.h> |
---|
32 | #include <rtems/fs.h> |
---|
33 | #include <rtems/chain.h> |
---|
34 | |
---|
35 | #ifdef __cplusplus |
---|
36 | extern "C" { |
---|
37 | #endif |
---|
38 | |
---|
39 | /** |
---|
40 | * @defgroup LibIO IO Library |
---|
41 | * |
---|
42 | * @brief Provides system call and file system interface definitions. |
---|
43 | * |
---|
44 | * General purpose communication channel for RTEMS to allow UNIX/POSIX |
---|
45 | * system call behavior under RTEMS. Initially this supported only |
---|
46 | * IO to devices but has since been enhanced to support networking |
---|
47 | * and support for mounted file systems. |
---|
48 | * |
---|
49 | * @{ |
---|
50 | */ |
---|
51 | |
---|
52 | typedef off_t rtems_off64_t __attribute__((deprecated)); |
---|
53 | |
---|
54 | /** |
---|
55 | * @brief File system node types. |
---|
56 | */ |
---|
57 | typedef enum { |
---|
58 | RTEMS_FILESYSTEM_INVALID_NODE_TYPE, |
---|
59 | RTEMS_FILESYSTEM_DIRECTORY, |
---|
60 | RTEMS_FILESYSTEM_DEVICE, |
---|
61 | RTEMS_FILESYSTEM_HARD_LINK, |
---|
62 | RTEMS_FILESYSTEM_SYM_LINK, |
---|
63 | RTEMS_FILESYSTEM_MEMORY_FILE |
---|
64 | } rtems_filesystem_node_types_t; |
---|
65 | |
---|
66 | /** |
---|
67 | * @name File System Node Operations |
---|
68 | * |
---|
69 | * @{ |
---|
70 | */ |
---|
71 | |
---|
72 | /** |
---|
73 | * This type defines the interface to the open(2) system call |
---|
74 | * support which is provided by a file system implementation. |
---|
75 | */ |
---|
76 | typedef int (*rtems_filesystem_open_t)( |
---|
77 | rtems_libio_t *iop, |
---|
78 | const char *pathname, |
---|
79 | uint32_t flag, |
---|
80 | uint32_t mode |
---|
81 | ); |
---|
82 | |
---|
83 | /** |
---|
84 | * This type defines the interface to the close(2) system call |
---|
85 | * support which is provided by a file system implementation. |
---|
86 | */ |
---|
87 | typedef int (*rtems_filesystem_close_t)( |
---|
88 | rtems_libio_t *iop |
---|
89 | ); |
---|
90 | |
---|
91 | /** |
---|
92 | * This type defines the interface to the read(2) system call |
---|
93 | * support which is provided by a file system implementation. |
---|
94 | */ |
---|
95 | typedef ssize_t (*rtems_filesystem_read_t)( |
---|
96 | rtems_libio_t *iop, |
---|
97 | void *buffer, |
---|
98 | size_t count |
---|
99 | ); |
---|
100 | |
---|
101 | /** |
---|
102 | * This type defines the interface to the write(2) system call |
---|
103 | * support which is provided by a file system implementation. |
---|
104 | */ |
---|
105 | typedef ssize_t (*rtems_filesystem_write_t)( |
---|
106 | rtems_libio_t *iop, |
---|
107 | const void *buffer, |
---|
108 | size_t count |
---|
109 | ); |
---|
110 | |
---|
111 | /** |
---|
112 | * This type defines the interface to the ioctl(2) system call |
---|
113 | * support which is provided by a file system implementation. |
---|
114 | */ |
---|
115 | typedef int (*rtems_filesystem_ioctl_t)( |
---|
116 | rtems_libio_t *iop, |
---|
117 | uint32_t command, |
---|
118 | void *buffer |
---|
119 | ); |
---|
120 | |
---|
121 | /** |
---|
122 | * This type defines the interface to the lseek(2) system call |
---|
123 | * support which is provided by a file system implementation. |
---|
124 | */ |
---|
125 | typedef off_t (*rtems_filesystem_lseek_t)( |
---|
126 | rtems_libio_t *iop, |
---|
127 | off_t length, |
---|
128 | int whence |
---|
129 | ); |
---|
130 | |
---|
131 | /** |
---|
132 | * This type defines the interface to the fstat(2) system call |
---|
133 | * support which is provided by a file system implementation. |
---|
134 | */ |
---|
135 | typedef int (*rtems_filesystem_fstat_t)( |
---|
136 | rtems_filesystem_location_info_t *loc, |
---|
137 | struct stat *buf |
---|
138 | ); |
---|
139 | |
---|
140 | /** |
---|
141 | * This type defines the interface to the fchmod(2) system call |
---|
142 | * support which is provided by a file system implementation. |
---|
143 | */ |
---|
144 | typedef int (*rtems_filesystem_fchmod_t)( |
---|
145 | rtems_filesystem_location_info_t *loc, |
---|
146 | mode_t mode |
---|
147 | ); |
---|
148 | |
---|
149 | /** |
---|
150 | * This type defines the interface to the ftruncate(2) system call |
---|
151 | * support which is provided by a file system implementation. |
---|
152 | */ |
---|
153 | typedef int (*rtems_filesystem_ftruncate_t)( |
---|
154 | rtems_libio_t *iop, |
---|
155 | off_t length |
---|
156 | ); |
---|
157 | |
---|
158 | /** |
---|
159 | * This type defines the interface to the fsync(2) system call |
---|
160 | * support which is provided by a file system implementation. |
---|
161 | */ |
---|
162 | typedef int (*rtems_filesystem_fsync_t)( |
---|
163 | rtems_libio_t *iop |
---|
164 | ); |
---|
165 | |
---|
166 | /** |
---|
167 | * This type defines the interface to the fdatasync(2) system call |
---|
168 | * support which is provided by a file system implementation. |
---|
169 | */ |
---|
170 | typedef int (*rtems_filesystem_fdatasync_t)( |
---|
171 | rtems_libio_t *iop |
---|
172 | ); |
---|
173 | |
---|
174 | /** |
---|
175 | * This type defines the interface to the fnctl(2) system call |
---|
176 | * support which is provided by a file system implementation. |
---|
177 | */ |
---|
178 | typedef int (*rtems_filesystem_fcntl_t)( |
---|
179 | int cmd, |
---|
180 | rtems_libio_t *iop |
---|
181 | ); |
---|
182 | |
---|
183 | typedef int (*rtems_filesystem_rmnod_t)( |
---|
184 | rtems_filesystem_location_info_t *parent_loc, /* IN */ |
---|
185 | rtems_filesystem_location_info_t *pathloc /* IN */ |
---|
186 | ); |
---|
187 | |
---|
188 | /** @} */ |
---|
189 | |
---|
190 | /** |
---|
191 | * @brief File system node operations table. |
---|
192 | */ |
---|
193 | struct _rtems_filesystem_file_handlers_r { |
---|
194 | /** |
---|
195 | * This field points to the file system specific implementation |
---|
196 | * of the support routine for the open(2) system call |
---|
197 | * |
---|
198 | * @note This method must have a filesystem specific implementation. |
---|
199 | * |
---|
200 | * @note There is no default implementation. |
---|
201 | */ |
---|
202 | rtems_filesystem_open_t open_h; |
---|
203 | |
---|
204 | /** |
---|
205 | * This field points to the file system specific implementation |
---|
206 | * of the support routine for the close(2) system call |
---|
207 | * |
---|
208 | * @note This method is REQUIRED by all file systems. |
---|
209 | * |
---|
210 | * @note There is no default implementation. |
---|
211 | */ |
---|
212 | rtems_filesystem_close_t close_h; |
---|
213 | |
---|
214 | /** |
---|
215 | * This field points to the file system specific implementation |
---|
216 | * of the support routine for the read(2) system call |
---|
217 | * |
---|
218 | * @note This method must have a filesystem specific implementation. |
---|
219 | * |
---|
220 | * @note The default implementation returns -1 and sets |
---|
221 | * errno to ENOTSUP. |
---|
222 | */ |
---|
223 | rtems_filesystem_read_t read_h; |
---|
224 | |
---|
225 | /** |
---|
226 | * This field points to the file system specific implementation |
---|
227 | * of the support routine for the write(2) system call |
---|
228 | * |
---|
229 | * @note This method may use a default implementation. |
---|
230 | * |
---|
231 | * @note The default implementation returns -1 and sets |
---|
232 | * errno to ENOTSUP. |
---|
233 | */ |
---|
234 | rtems_filesystem_write_t write_h; |
---|
235 | |
---|
236 | /** |
---|
237 | * This field points to the file system specific implementation |
---|
238 | * of the support routine for the ioctl(2) system call |
---|
239 | * |
---|
240 | * @note This method may use a default implementation. |
---|
241 | * |
---|
242 | * @note The default implementation returns -1 and sets |
---|
243 | * errno to ENOTSUP. |
---|
244 | */ |
---|
245 | rtems_filesystem_ioctl_t ioctl_h; |
---|
246 | |
---|
247 | /** |
---|
248 | * This field points to the file system specific implementation |
---|
249 | * of the support routine for the lseek(2) system call |
---|
250 | * |
---|
251 | * @note This method may use a default implementation. |
---|
252 | * |
---|
253 | * @note The default implementation returns -1 and sets |
---|
254 | * errno to ENOTSUP. |
---|
255 | */ |
---|
256 | rtems_filesystem_lseek_t lseek_h; |
---|
257 | |
---|
258 | /** |
---|
259 | * This field points to the file system specific implementation |
---|
260 | * of the support routine for the fstat(2) system call |
---|
261 | * |
---|
262 | * @note This method may use a default implementation. |
---|
263 | * |
---|
264 | * @note The default implementation returns -1 and sets |
---|
265 | * errno to ENOTSUP. |
---|
266 | */ |
---|
267 | rtems_filesystem_fstat_t fstat_h; |
---|
268 | |
---|
269 | /** |
---|
270 | * This field points to the file system specific implementation |
---|
271 | * of the support routine for the fchmod(2) system call |
---|
272 | * |
---|
273 | * @note This method may use a default implementation. |
---|
274 | * |
---|
275 | * @note The default implementation returns -1 and sets |
---|
276 | * errno to ENOTSUP. |
---|
277 | */ |
---|
278 | rtems_filesystem_fchmod_t fchmod_h; |
---|
279 | |
---|
280 | /** |
---|
281 | * This field points to the file system specific implementation |
---|
282 | * of the support routine for the ftruncate(2) system call |
---|
283 | * |
---|
284 | * @note This method may use a default implementation. |
---|
285 | * |
---|
286 | * @note The default implementation returns -1 and sets |
---|
287 | * errno to ENOTSUP. |
---|
288 | */ |
---|
289 | rtems_filesystem_ftruncate_t ftruncate_h; |
---|
290 | |
---|
291 | /** |
---|
292 | * This field points to the file system specific implementation |
---|
293 | * of the support routine for the fsync(2) system call |
---|
294 | * |
---|
295 | * @note This method may use a default implementation. |
---|
296 | * |
---|
297 | * @note The default implementation returns -1 and sets |
---|
298 | * errno to ENOTSUP. |
---|
299 | */ |
---|
300 | rtems_filesystem_fsync_t fsync_h; |
---|
301 | |
---|
302 | /** |
---|
303 | * This field points to the file system specific implementation |
---|
304 | * of the support routine for the fdatasync(2) system call |
---|
305 | * |
---|
306 | * @note This method may use a default implementation. |
---|
307 | * |
---|
308 | * @note The default implementation returns -1 and sets |
---|
309 | * errno to ENOTSUP. |
---|
310 | */ |
---|
311 | rtems_filesystem_fdatasync_t fdatasync_h; |
---|
312 | |
---|
313 | /** |
---|
314 | * This field points to the file system specific implementation |
---|
315 | * of the support routine for the fcntl(2) system call |
---|
316 | * |
---|
317 | * @note This method may use a default implementation. |
---|
318 | * |
---|
319 | * @note The default implementation returns -1 and sets |
---|
320 | * errno to ENOTSUP. |
---|
321 | */ |
---|
322 | rtems_filesystem_fcntl_t fcntl_h; |
---|
323 | |
---|
324 | /** |
---|
325 | * This field points to the file system specific implementation |
---|
326 | * of the support routine for the rmnod(2) system call |
---|
327 | * |
---|
328 | * @note This method may use a default implementation. |
---|
329 | * |
---|
330 | * @note The default implementation returns -1 and sets |
---|
331 | * errno to ENOTSUP. |
---|
332 | */ |
---|
333 | rtems_filesystem_rmnod_t rmnod_h; |
---|
334 | }; |
---|
335 | |
---|
336 | extern const rtems_filesystem_file_handlers_r |
---|
337 | rtems_filesystem_handlers_default; |
---|
338 | |
---|
339 | /** |
---|
340 | * This method defines the interface to the default open(2) |
---|
341 | * system call support which is provided by a file system |
---|
342 | * implementation. |
---|
343 | */ |
---|
344 | int rtems_filesystem_default_open( |
---|
345 | rtems_libio_t *iop, |
---|
346 | const char *pathname, |
---|
347 | uint32_t flag, |
---|
348 | uint32_t mode |
---|
349 | ); |
---|
350 | |
---|
351 | /** |
---|
352 | * This method defines the interface to the default close(2) |
---|
353 | * system call support which is provided by a file system |
---|
354 | * implementation. |
---|
355 | */ |
---|
356 | int rtems_filesystem_default_close( |
---|
357 | rtems_libio_t *iop |
---|
358 | ); |
---|
359 | |
---|
360 | |
---|
361 | /** |
---|
362 | * This method defines the interface to the default read(2) |
---|
363 | * system call support which is provided by a file system |
---|
364 | * implementation. |
---|
365 | */ |
---|
366 | ssize_t rtems_filesystem_default_read( |
---|
367 | rtems_libio_t *iop, |
---|
368 | void *buffer, |
---|
369 | size_t count |
---|
370 | ); |
---|
371 | |
---|
372 | /** |
---|
373 | * This method defines the interface to the default write(2) system call |
---|
374 | * support which is provided by a file system implementation. |
---|
375 | */ |
---|
376 | ssize_t rtems_filesystem_default_write( |
---|
377 | rtems_libio_t *iop, |
---|
378 | const void *buffer, |
---|
379 | size_t count |
---|
380 | ); |
---|
381 | |
---|
382 | /** |
---|
383 | * This method defines the interface to the default ioctl(2) system call |
---|
384 | * support which is provided by a file system implementation. |
---|
385 | */ |
---|
386 | int rtems_filesystem_default_ioctl( |
---|
387 | rtems_libio_t *iop, |
---|
388 | uint32_t command, |
---|
389 | void *buffer |
---|
390 | ); |
---|
391 | |
---|
392 | /** |
---|
393 | * This method defines the interface to the default lseek(2) system call |
---|
394 | * support which is provided by a file system implementation. |
---|
395 | */ |
---|
396 | off_t rtems_filesystem_default_lseek( |
---|
397 | rtems_libio_t *iop, |
---|
398 | off_t length, |
---|
399 | int whence |
---|
400 | ); |
---|
401 | |
---|
402 | /** |
---|
403 | * This method defines the interface to the default fstat(2) system call |
---|
404 | * support which is provided by a file system implementation. |
---|
405 | */ |
---|
406 | int rtems_filesystem_default_fstat( |
---|
407 | rtems_filesystem_location_info_t *loc, |
---|
408 | struct stat *buf |
---|
409 | ); |
---|
410 | |
---|
411 | /** |
---|
412 | * This method defines the interface to the default fchmod(2) system call |
---|
413 | * support which is provided by a file system implementation. |
---|
414 | */ |
---|
415 | int rtems_filesystem_default_fchmod( |
---|
416 | rtems_filesystem_location_info_t *loc, |
---|
417 | mode_t mode |
---|
418 | ); |
---|
419 | |
---|
420 | /** |
---|
421 | * This method defines the interface to the default ftruncate(2) system call |
---|
422 | * support which is provided by a file system implementation. |
---|
423 | */ |
---|
424 | int rtems_filesystem_default_ftruncate( |
---|
425 | rtems_libio_t *iop, |
---|
426 | off_t length |
---|
427 | ); |
---|
428 | |
---|
429 | /** |
---|
430 | * This method defines the interface to the default fsync(2) system call |
---|
431 | * support which is provided by a file system implementation. |
---|
432 | */ |
---|
433 | int rtems_filesystem_default_fsync( |
---|
434 | rtems_libio_t *iop |
---|
435 | ); |
---|
436 | |
---|
437 | /** |
---|
438 | * This method defines the interface to the default fdatasync(2) system call |
---|
439 | * support which is provided by a file system implementation. |
---|
440 | */ |
---|
441 | int rtems_filesystem_default_fdatasync( |
---|
442 | rtems_libio_t *iop |
---|
443 | ); |
---|
444 | |
---|
445 | /** |
---|
446 | * This method defines the interface to the default fnctl(2) system call |
---|
447 | * support which is provided by a file system implementation. |
---|
448 | */ |
---|
449 | int rtems_filesystem_default_fcntl( |
---|
450 | int cmd, |
---|
451 | rtems_libio_t *iop |
---|
452 | ); |
---|
453 | |
---|
454 | /** |
---|
455 | * This method defines the interface to the default rmnod(2) system call |
---|
456 | * support which is provided by a file system implementation. |
---|
457 | */ |
---|
458 | int rtems_filesystem_default_rmnod( |
---|
459 | rtems_filesystem_location_info_t *parent_loc, /* IN */ |
---|
460 | rtems_filesystem_location_info_t *pathloc /* IN */ |
---|
461 | ); |
---|
462 | |
---|
463 | /** |
---|
464 | * @name File System Operations |
---|
465 | * |
---|
466 | * @{ |
---|
467 | */ |
---|
468 | |
---|
469 | /** |
---|
470 | * This type defines the interface to the mknod(2) system call |
---|
471 | * support which is provided by a file system implementation. |
---|
472 | * |
---|
473 | * @note This routine does not allocate any space and |
---|
474 | * rtems_filesystem_freenode_t is not called by the generic |
---|
475 | * after calling this routine. ie. node_access does not have |
---|
476 | * to contain valid data when the routine returns. |
---|
477 | */ |
---|
478 | typedef int (*rtems_filesystem_mknod_t)( |
---|
479 | const char *path, /* IN */ |
---|
480 | mode_t mode, /* IN */ |
---|
481 | dev_t dev, /* IN */ |
---|
482 | rtems_filesystem_location_info_t *pathloc /* IN/OUT */ |
---|
483 | ); |
---|
484 | |
---|
485 | /** |
---|
486 | * This type defines the interface that allows the |
---|
487 | * file system implementation to parse a path and |
---|
488 | * allocate any memory necessary for tracking purposes. |
---|
489 | * |
---|
490 | * @note rtems_filesystem_freenode_t must be called by |
---|
491 | * the generic after calling this routine |
---|
492 | */ |
---|
493 | typedef int (*rtems_filesystem_evalpath_t)( |
---|
494 | const char *pathname, /* IN */ |
---|
495 | size_t pathnamelen, /* IN */ |
---|
496 | int flags, /* IN */ |
---|
497 | rtems_filesystem_location_info_t *pathloc /* IN/OUT */ |
---|
498 | ); |
---|
499 | |
---|
500 | /** |
---|
501 | * This type defines the interface that allows the |
---|
502 | * file system implementation to parse a path with the |
---|
503 | * intent of creating a new node and to |
---|
504 | * allocate any memory necessary for tracking purposes. |
---|
505 | * |
---|
506 | * @note rtems_filesystem_freenode_t must be called by |
---|
507 | * the generic after calling this routine |
---|
508 | */ |
---|
509 | typedef int (*rtems_filesystem_evalmake_t)( |
---|
510 | const char *path, /* IN */ |
---|
511 | rtems_filesystem_location_info_t *pathloc, /* IN/OUT */ |
---|
512 | const char **name /* OUT */ |
---|
513 | ); |
---|
514 | |
---|
515 | /** |
---|
516 | * This type defines the interface to the link(2) system call |
---|
517 | * support which is provided by a file system implementation. |
---|
518 | */ |
---|
519 | typedef int (*rtems_filesystem_link_t)( |
---|
520 | rtems_filesystem_location_info_t *to_loc, /* IN */ |
---|
521 | rtems_filesystem_location_info_t *parent_loc, /* IN */ |
---|
522 | const char *name /* IN */ |
---|
523 | ); |
---|
524 | |
---|
525 | /** |
---|
526 | * This type defines the interface to the unlink(2) system call |
---|
527 | * support which is provided by a file system implementation. |
---|
528 | */ |
---|
529 | typedef int (*rtems_filesystem_unlink_t)( |
---|
530 | rtems_filesystem_location_info_t *parent_pathloc, /* IN */ |
---|
531 | rtems_filesystem_location_info_t *pathloc /* IN */ |
---|
532 | ); |
---|
533 | |
---|
534 | /** |
---|
535 | * This type defines the interface to the chown(2) system call |
---|
536 | * support which is provided by a file system implementation. |
---|
537 | */ |
---|
538 | typedef int (*rtems_filesystem_chown_t)( |
---|
539 | rtems_filesystem_location_info_t *pathloc, /* IN */ |
---|
540 | uid_t owner, /* IN */ |
---|
541 | gid_t group /* IN */ |
---|
542 | ); |
---|
543 | |
---|
544 | /** |
---|
545 | * This type defines the interface to the freenod(2) system call |
---|
546 | * support which is provided by a file system implementation. |
---|
547 | */ |
---|
548 | typedef int (*rtems_filesystem_freenode_t)( |
---|
549 | rtems_filesystem_location_info_t *pathloc /* IN */ |
---|
550 | ); |
---|
551 | |
---|
552 | /** |
---|
553 | * This type defines the interface that allows the implemented |
---|
554 | * filesystem ot mount another filesystem at the given location. |
---|
555 | */ |
---|
556 | typedef int (* rtems_filesystem_mount_t ) ( |
---|
557 | rtems_filesystem_mount_table_entry_t *mt_entry /* IN */ |
---|
558 | ); |
---|
559 | |
---|
560 | /** |
---|
561 | * This type defines the interface that allows a file system |
---|
562 | * implementation to do any necessary work that is needed when |
---|
563 | * it is being mounted. |
---|
564 | */ |
---|
565 | typedef int (* rtems_filesystem_fsmount_me_t )( |
---|
566 | rtems_filesystem_mount_table_entry_t *mt_entry, /* IN */ |
---|
567 | const void *data /* IN */ |
---|
568 | ); |
---|
569 | |
---|
570 | /** |
---|
571 | * This type defines the interface allow the filesystem to |
---|
572 | * unmount a filesystem that was mounted at one of its node |
---|
573 | * locations. |
---|
574 | */ |
---|
575 | typedef int (* rtems_filesystem_unmount_t ) ( |
---|
576 | rtems_filesystem_mount_table_entry_t *mt_entry /* IN */ |
---|
577 | ); |
---|
578 | |
---|
579 | /** |
---|
580 | * This type defines the interface that allows a file system |
---|
581 | * implementation to do any necessary work that is needed when |
---|
582 | * it is being unmounted. |
---|
583 | */ |
---|
584 | typedef int (* rtems_filesystem_fsunmount_me_t ) ( |
---|
585 | rtems_filesystem_mount_table_entry_t *mt_entry /* IN */ |
---|
586 | ); |
---|
587 | |
---|
588 | /** |
---|
589 | * This type defines the interface that will return the |
---|
590 | * type of a filesystem implementations node. |
---|
591 | */ |
---|
592 | typedef rtems_filesystem_node_types_t (* rtems_filesystem_node_type_t) ( |
---|
593 | rtems_filesystem_location_info_t *pathloc /* IN */ |
---|
594 | ); |
---|
595 | |
---|
596 | /** |
---|
597 | * This type defines the interface to the time(2) system call |
---|
598 | * support which is provided by a file system implementation. |
---|
599 | */ |
---|
600 | typedef int (* rtems_filesystem_utime_t)( |
---|
601 | rtems_filesystem_location_info_t *pathloc, /* IN */ |
---|
602 | time_t actime, /* IN */ |
---|
603 | time_t modtime /* IN */ |
---|
604 | ); |
---|
605 | |
---|
606 | /** |
---|
607 | * This type defines the interface to the link(2) system call |
---|
608 | * support which is provided by a file system implementation. |
---|
609 | */ |
---|
610 | typedef int (*rtems_filesystem_evaluate_link_t)( |
---|
611 | rtems_filesystem_location_info_t *pathloc, /* IN/OUT */ |
---|
612 | int flags /* IN */ |
---|
613 | ); |
---|
614 | |
---|
615 | /** |
---|
616 | * This type defines the interface to the symlink(2) system call |
---|
617 | * support which is provided by a file system implementation. |
---|
618 | */ |
---|
619 | typedef int (*rtems_filesystem_symlink_t)( |
---|
620 | rtems_filesystem_location_info_t *loc, /* IN */ |
---|
621 | const char *link_name, /* IN */ |
---|
622 | const char *node_name |
---|
623 | ); |
---|
624 | |
---|
625 | /** |
---|
626 | * This type defines the interface to the readlink(2) system call |
---|
627 | * support which is provided by a file system implementation. |
---|
628 | */ |
---|
629 | typedef ssize_t (*rtems_filesystem_readlink_t)( |
---|
630 | rtems_filesystem_location_info_t *loc, /* IN */ |
---|
631 | char *buf, /* OUT */ |
---|
632 | size_t bufsize |
---|
633 | ); |
---|
634 | |
---|
635 | /** |
---|
636 | * This type defines the interface to the name(2) system call |
---|
637 | * support which is provided by a file system implementation. |
---|
638 | */ |
---|
639 | typedef int (*rtems_filesystem_rename_t)( |
---|
640 | rtems_filesystem_location_info_t *old_parent_loc, /* IN */ |
---|
641 | rtems_filesystem_location_info_t *old_loc, /* IN */ |
---|
642 | rtems_filesystem_location_info_t *new_parent_loc, /* IN */ |
---|
643 | const char *name /* IN */ |
---|
644 | ); |
---|
645 | |
---|
646 | /** |
---|
647 | * This type defines the interface to the statvfs(2) system call |
---|
648 | * support which is provided by a file system implementation. |
---|
649 | */ |
---|
650 | typedef int (*rtems_filesystem_statvfs_t)( |
---|
651 | rtems_filesystem_location_info_t *loc, /* IN */ |
---|
652 | struct statvfs *buf /* OUT */ |
---|
653 | ); |
---|
654 | |
---|
655 | /** @} */ |
---|
656 | |
---|
657 | /** |
---|
658 | * @brief File system operations table. |
---|
659 | */ |
---|
660 | struct _rtems_filesystem_operations_table { |
---|
661 | |
---|
662 | /** |
---|
663 | * This field points to the file system specific implementation |
---|
664 | * of the support routine that evaluates a character path and |
---|
665 | * returns the node assocated with the last node in the path. |
---|
666 | * |
---|
667 | * @note This method must have a filesystem specific implementation. |
---|
668 | * |
---|
669 | * @note There is no default implementation. |
---|
670 | */ |
---|
671 | rtems_filesystem_evalpath_t evalpath_h; |
---|
672 | |
---|
673 | /** |
---|
674 | * This field points to the file system specific implementation |
---|
675 | * of the support routine that evaluates a character path and |
---|
676 | * returns the node assocated with next to the last node in |
---|
677 | * the path. The last node will be the new node to be created. |
---|
678 | * |
---|
679 | * @note This method must have a filesystem specific implementation. |
---|
680 | * |
---|
681 | * @note There is no default implementation. |
---|
682 | */ |
---|
683 | rtems_filesystem_evalmake_t evalformake_h; |
---|
684 | |
---|
685 | /** |
---|
686 | * This field points to the file system specific implementation |
---|
687 | * of the support routine for the link(2) system call |
---|
688 | * |
---|
689 | * @note This method may use a default implementation. |
---|
690 | * |
---|
691 | * @note The default implementation returns -1 and sets |
---|
692 | * errno to ENOTSUP. |
---|
693 | */ |
---|
694 | rtems_filesystem_link_t link_h; |
---|
695 | |
---|
696 | /** |
---|
697 | * This field points to the file system specific implementation |
---|
698 | * of the support routine for the unlink(2) system call |
---|
699 | * |
---|
700 | * @note This method may use a default implementation. |
---|
701 | * |
---|
702 | * @note The default implementation returns -1 and sets |
---|
703 | * errno to ENOTSUP. |
---|
704 | */ |
---|
705 | rtems_filesystem_unlink_t unlink_h; |
---|
706 | |
---|
707 | /** |
---|
708 | * This field points to the file system specific implementation |
---|
709 | * of a method that returns the node type of the given node. |
---|
710 | * |
---|
711 | * @note This method may use a default implementation. |
---|
712 | * |
---|
713 | * @note The default implementation returns -1 and sets |
---|
714 | * errno to ENOTSUP. |
---|
715 | */ |
---|
716 | rtems_filesystem_node_type_t node_type_h; |
---|
717 | |
---|
718 | /** |
---|
719 | * This field points to the file system specific implementation |
---|
720 | * of the support routine for the link(2) system call |
---|
721 | * |
---|
722 | * @note This method may use a mknod implementation. |
---|
723 | * |
---|
724 | * @note The default implementation returns -1 and sets |
---|
725 | * errno to ENOTSUP. |
---|
726 | */ |
---|
727 | rtems_filesystem_mknod_t mknod_h; |
---|
728 | |
---|
729 | /** |
---|
730 | * This field points to the file system specific implementation |
---|
731 | * of the support routine for the link(2) system call |
---|
732 | * |
---|
733 | * @note This method may use a default implementation. |
---|
734 | * |
---|
735 | * @note The default implementation returns -1 and sets |
---|
736 | * errno to ENOTSUP. |
---|
737 | */ |
---|
738 | rtems_filesystem_chown_t chown_h; |
---|
739 | |
---|
740 | /** |
---|
741 | * This field points to the file system specific implementation |
---|
742 | * of the support routine for the freenod(2) system call |
---|
743 | * |
---|
744 | * @note This method may use a default implementation. |
---|
745 | * |
---|
746 | * @note The default implementation returns -1 and sets |
---|
747 | * errno to ENOTSUP. |
---|
748 | */ |
---|
749 | rtems_filesystem_freenode_t freenod_h; |
---|
750 | |
---|
751 | /** |
---|
752 | * This field points to the file system specific implementation |
---|
753 | * of the support routine for the mount(2) system call |
---|
754 | * |
---|
755 | * @note This method may use a default implementation. |
---|
756 | * |
---|
757 | * @note The default implementation returns -1 and sets |
---|
758 | * errno to ENOTSUP. |
---|
759 | */ |
---|
760 | rtems_filesystem_mount_t mount_h; |
---|
761 | |
---|
762 | /** |
---|
763 | * This field points to the file system specific implementation |
---|
764 | * of the support routine for the fsmount(2) system call |
---|
765 | * |
---|
766 | * @note This method may use a default implementation. |
---|
767 | * |
---|
768 | * @note The default implementation returns -1 and sets |
---|
769 | * errno to ENOTSUP. |
---|
770 | */ |
---|
771 | rtems_filesystem_fsmount_me_t fsmount_me_h; |
---|
772 | |
---|
773 | /** |
---|
774 | * This field points to the file system specific implementation |
---|
775 | * of the support routine for the unmount(2) system call |
---|
776 | * |
---|
777 | * @note This method may use a default implementation. |
---|
778 | * |
---|
779 | * @note The default implementation returns -1 and sets |
---|
780 | * errno to ENOTSUP. |
---|
781 | */ |
---|
782 | rtems_filesystem_unmount_t unmount_h; |
---|
783 | |
---|
784 | /** |
---|
785 | * This field points to the file system specific implementation |
---|
786 | * of the support routine for the fsunmount(2) system call |
---|
787 | * |
---|
788 | * @note This method may use a default implementation. |
---|
789 | * |
---|
790 | * @note The default implementation returns -1 and sets |
---|
791 | * errno to ENOTSUP. |
---|
792 | */ |
---|
793 | rtems_filesystem_fsunmount_me_t fsunmount_me_h; |
---|
794 | |
---|
795 | /** |
---|
796 | * This field points to the file system specific implementation |
---|
797 | * of the support routine for the utime(2) system call |
---|
798 | * |
---|
799 | * @note This method may use a default implementation. |
---|
800 | * |
---|
801 | * @note The default implementation returns -1 and sets |
---|
802 | * errno to ENOTSUP. |
---|
803 | */ |
---|
804 | rtems_filesystem_utime_t utime_h; |
---|
805 | |
---|
806 | /** |
---|
807 | * This field points to the file system specific implementation |
---|
808 | * of the support routine for the eval_link(2) system call |
---|
809 | * |
---|
810 | * @note This method may use a default implementation. |
---|
811 | * |
---|
812 | * @note The default implementation returns -1 and sets |
---|
813 | * errno to ENOTSUP. |
---|
814 | */ |
---|
815 | rtems_filesystem_evaluate_link_t eval_link_h; |
---|
816 | |
---|
817 | /** |
---|
818 | * This field points to the file system specific implementation |
---|
819 | * of the support routine for the sumlink(2) system call |
---|
820 | * |
---|
821 | * @note This method may use a default implementation. |
---|
822 | * |
---|
823 | * @note The default implementation returns -1 and sets |
---|
824 | * errno to ENOTSUP. |
---|
825 | */ |
---|
826 | rtems_filesystem_symlink_t symlink_h; |
---|
827 | |
---|
828 | /** |
---|
829 | * This field points to the file system specific implementation |
---|
830 | * of the support routine for the readlink(2) system call |
---|
831 | * |
---|
832 | * @note This method may use a default implementation. |
---|
833 | * |
---|
834 | * @note The default implementation returns -1 and sets |
---|
835 | * errno to ENOTSUP. |
---|
836 | */ |
---|
837 | rtems_filesystem_readlink_t readlink_h; |
---|
838 | |
---|
839 | /** |
---|
840 | * This field points to the file system specific implementation |
---|
841 | * of the support routine for the rename(2) system call |
---|
842 | * |
---|
843 | * @note This method may use a default implementation. |
---|
844 | * |
---|
845 | * @note The default implementation returns -1 and sets |
---|
846 | * errno to ENOTSUP. |
---|
847 | */ |
---|
848 | rtems_filesystem_rename_t rename_h; |
---|
849 | |
---|
850 | /** |
---|
851 | * This field points to the file system specific implementation |
---|
852 | * of the support routine for the statvfs(2) system call |
---|
853 | * |
---|
854 | * @note This method may use a default implementation. |
---|
855 | * |
---|
856 | * @note The default implementation returns -1 and sets |
---|
857 | * errno to ENOTSUP. |
---|
858 | */ |
---|
859 | rtems_filesystem_statvfs_t statvfs_h; |
---|
860 | }; |
---|
861 | |
---|
862 | extern const rtems_filesystem_operations_table |
---|
863 | rtems_filesystem_operations_default; |
---|
864 | |
---|
865 | /** |
---|
866 | * @brief Provides a defualt routine for filesystem |
---|
867 | * implementation of path evaluation. |
---|
868 | */ |
---|
869 | int rtems_filesystem_default_evalpath( |
---|
870 | const char *pathname, |
---|
871 | size_t pathnamelen, |
---|
872 | int flags, |
---|
873 | rtems_filesystem_location_info_t *pathloc |
---|
874 | ); |
---|
875 | |
---|
876 | /** |
---|
877 | * @brief Provides a defualt routine for filesystem |
---|
878 | * implementation of path evaluation for make. |
---|
879 | */ |
---|
880 | int rtems_filesystem_default_evalformake( |
---|
881 | const char *path, |
---|
882 | rtems_filesystem_location_info_t *pathloc, |
---|
883 | const char **name |
---|
884 | ); |
---|
885 | |
---|
886 | /** |
---|
887 | * @brief Provides a defualt routine for filesystem |
---|
888 | * implementation of a link command. |
---|
889 | */ |
---|
890 | int rtems_filesystem_default_link( |
---|
891 | rtems_filesystem_location_info_t *to_loc, /* IN */ |
---|
892 | rtems_filesystem_location_info_t *parent_loc, /* IN */ |
---|
893 | const char *name /* IN */ |
---|
894 | ); |
---|
895 | |
---|
896 | /** |
---|
897 | * @brief Provides a defualt routine for filesystem |
---|
898 | * implementation of a unlink command. |
---|
899 | */ |
---|
900 | int rtems_filesystem_default_unlink( |
---|
901 | rtems_filesystem_location_info_t *parent_pathloc, /* IN */ |
---|
902 | rtems_filesystem_location_info_t *pathloc /* IN */ |
---|
903 | ); |
---|
904 | |
---|
905 | /** |
---|
906 | * @brief Provides a defualt routine for filesystem |
---|
907 | * implementation to determine the node type. |
---|
908 | */ |
---|
909 | rtems_filesystem_node_types_t rtems_filesystem_default_node_type( |
---|
910 | rtems_filesystem_location_info_t *pathloc |
---|
911 | ); |
---|
912 | |
---|
913 | /** |
---|
914 | * @brief Provides a defualt routine for filesystem |
---|
915 | * implementation to create a new node. |
---|
916 | */ |
---|
917 | int rtems_filesystem_default_mknod( |
---|
918 | const char *path, /* IN */ |
---|
919 | mode_t mode, /* IN */ |
---|
920 | dev_t dev, /* IN */ |
---|
921 | rtems_filesystem_location_info_t *pathloc /* IN/OUT */ |
---|
922 | ); |
---|
923 | |
---|
924 | /** |
---|
925 | * @brief Provides a defualt routine for filesystem |
---|
926 | * implementation of a chown command. |
---|
927 | */ |
---|
928 | int rtems_filesystem_default_chown( |
---|
929 | rtems_filesystem_location_info_t *pathloc, /* IN */ |
---|
930 | uid_t owner, /* IN */ |
---|
931 | gid_t group /* IN */ |
---|
932 | ); |
---|
933 | |
---|
934 | /** |
---|
935 | * @brief Provides a defualt routine for filesystem |
---|
936 | * implementation of a freenode command. |
---|
937 | */ |
---|
938 | int rtems_filesystem_default_freenode( |
---|
939 | rtems_filesystem_location_info_t *pathloc /* IN */ |
---|
940 | ); |
---|
941 | |
---|
942 | /** |
---|
943 | * @brief Provides a defualt routine for filesystem |
---|
944 | * implementation of a mount command. |
---|
945 | */ |
---|
946 | int rtems_filesystem_default_mount ( |
---|
947 | rtems_filesystem_mount_table_entry_t *mt_entry /* IN */ |
---|
948 | ); |
---|
949 | |
---|
950 | /** |
---|
951 | * @brief Provides a defualt routine for filesystem |
---|
952 | * implementation of a fsmount command. |
---|
953 | */ |
---|
954 | int rtems_filesystem_default_fsmount( |
---|
955 | rtems_filesystem_mount_table_entry_t *mt_entry, /* IN */ |
---|
956 | const void *data /* IN */ |
---|
957 | ); |
---|
958 | |
---|
959 | /** |
---|
960 | * @brief Provides a defualt routine for filesystem |
---|
961 | * implementation of a unmount command. |
---|
962 | */ |
---|
963 | int rtems_filesystem_default_unmount( |
---|
964 | rtems_filesystem_mount_table_entry_t *mt_entry /* IN */ |
---|
965 | ); |
---|
966 | |
---|
967 | /** |
---|
968 | * @brief Provides a defualt routine for filesystem |
---|
969 | * implementation of a fsunmount command. |
---|
970 | */ |
---|
971 | int rtems_filesystem_default_fsunmount( |
---|
972 | rtems_filesystem_mount_table_entry_t *mt_entry /* IN */ |
---|
973 | ); |
---|
974 | |
---|
975 | |
---|
976 | /** |
---|
977 | * @brief Provides a defualt routine for filesystem |
---|
978 | * implementation of a utime command. |
---|
979 | */ |
---|
980 | int rtems_filesystem_default_utime( |
---|
981 | rtems_filesystem_location_info_t *pathloc, /* IN */ |
---|
982 | time_t actime, /* IN */ |
---|
983 | time_t modtime /* IN */ |
---|
984 | ); |
---|
985 | |
---|
986 | /** |
---|
987 | * @brief Provides a defualt routine for filesystem |
---|
988 | * implementation of a link command. |
---|
989 | */ |
---|
990 | int rtems_filesystem_default_evaluate_link( |
---|
991 | rtems_filesystem_location_info_t *pathloc, /* IN/OUT */ |
---|
992 | int flags /* IN */ |
---|
993 | ); |
---|
994 | |
---|
995 | /** |
---|
996 | * @brief Provides a defualt routine for filesystem |
---|
997 | * implementation of a symlink command. |
---|
998 | */ |
---|
999 | int rtems_filesystem_default_symlink( |
---|
1000 | rtems_filesystem_location_info_t *loc, /* IN */ |
---|
1001 | const char *link_name, /* IN */ |
---|
1002 | const char *node_name |
---|
1003 | ); |
---|
1004 | |
---|
1005 | /** |
---|
1006 | * @brief Provides a defualt routine for filesystem |
---|
1007 | * implementation of a readlink command. |
---|
1008 | */ |
---|
1009 | ssize_t rtems_filesystem_default_readlink( |
---|
1010 | rtems_filesystem_location_info_t *loc, /* IN */ |
---|
1011 | char *buf, /* OUT */ |
---|
1012 | size_t bufsize |
---|
1013 | ); |
---|
1014 | |
---|
1015 | /** |
---|
1016 | * @brief Provides a defualt routine for filesystem |
---|
1017 | * implementation of a rename command. |
---|
1018 | */ |
---|
1019 | int rtems_filesystem_default_rename( |
---|
1020 | rtems_filesystem_location_info_t *old_parent_loc, /* IN */ |
---|
1021 | rtems_filesystem_location_info_t *old_loc, /* IN */ |
---|
1022 | rtems_filesystem_location_info_t *new_parent_loc, /* IN */ |
---|
1023 | const char *name /* IN */ |
---|
1024 | ); |
---|
1025 | |
---|
1026 | /** |
---|
1027 | * @brief Provides a defualt routine for filesystem |
---|
1028 | * implementation of a statvfs command. |
---|
1029 | */ |
---|
1030 | int rtems_filesystem_default_statvfs( |
---|
1031 | rtems_filesystem_location_info_t *loc, /* IN */ |
---|
1032 | struct statvfs *buf /* OUT */ |
---|
1033 | ); |
---|
1034 | |
---|
1035 | /** |
---|
1036 | * @brief Gets the mount handler for the file system @a type. |
---|
1037 | * |
---|
1038 | * @return The file system mount handler associated with the @a type, or |
---|
1039 | * @c NULL if no such association exists. |
---|
1040 | */ |
---|
1041 | rtems_filesystem_fsmount_me_t |
---|
1042 | rtems_filesystem_get_mount_handler( |
---|
1043 | const char *type |
---|
1044 | ); |
---|
1045 | |
---|
1046 | /** |
---|
1047 | * @brief Contain file system specific information which is required to support |
---|
1048 | * fpathconf(). |
---|
1049 | */ |
---|
1050 | typedef struct { |
---|
1051 | int link_max; /* count */ |
---|
1052 | int max_canon; /* max formatted input line size */ |
---|
1053 | int max_input; /* max input line size */ |
---|
1054 | int name_max; /* max name length */ |
---|
1055 | int path_max; /* max path */ |
---|
1056 | int pipe_buf; /* pipe buffer size */ |
---|
1057 | int posix_async_io; /* async IO supported on fs, 0=no, 1=yes */ |
---|
1058 | int posix_chown_restrictions; /* can chown: 0=no, 1=yes */ |
---|
1059 | int posix_no_trunc; /* error on names > max name, 0=no, 1=yes */ |
---|
1060 | int posix_prio_io; /* priority IO, 0=no, 1=yes */ |
---|
1061 | int posix_sync_io; /* file can be sync'ed, 0=no, 1=yes */ |
---|
1062 | int posix_vdisable; /* special char processing, 0=no, 1=yes */ |
---|
1063 | } rtems_filesystem_limits_and_options_t; |
---|
1064 | |
---|
1065 | /** |
---|
1066 | * @brief Default pathconf settings. |
---|
1067 | * |
---|
1068 | * Override in a filesystem. |
---|
1069 | */ |
---|
1070 | extern const rtems_filesystem_limits_and_options_t rtems_filesystem_default_pathconf; |
---|
1071 | |
---|
1072 | /** |
---|
1073 | * @brief An open file data structure. |
---|
1074 | * |
---|
1075 | * It will be indexed by 'fd'. |
---|
1076 | * |
---|
1077 | * @todo Should really have a separate per/file data structure that this points |
---|
1078 | * to (eg: size, offset, driver, pathname should be in that) |
---|
1079 | */ |
---|
1080 | struct rtems_libio_tt { |
---|
1081 | rtems_driver_name_t *driver; |
---|
1082 | off_t size; /* size of file */ |
---|
1083 | off_t offset; /* current offset into file */ |
---|
1084 | uint32_t flags; |
---|
1085 | rtems_filesystem_location_info_t pathinfo; |
---|
1086 | rtems_id sem; |
---|
1087 | uint32_t data0; /* private to "driver" */ |
---|
1088 | void *data1; /* ... */ |
---|
1089 | }; |
---|
1090 | |
---|
1091 | /** |
---|
1092 | * @brief Paramameter block for read/write. |
---|
1093 | * |
---|
1094 | * It must include 'offset' instead of using iop's offset since we can have |
---|
1095 | * multiple outstanding i/o's on a device. |
---|
1096 | */ |
---|
1097 | typedef struct { |
---|
1098 | rtems_libio_t *iop; |
---|
1099 | off_t offset; |
---|
1100 | char *buffer; |
---|
1101 | uint32_t count; |
---|
1102 | uint32_t flags; |
---|
1103 | uint32_t bytes_moved; |
---|
1104 | } rtems_libio_rw_args_t; |
---|
1105 | |
---|
1106 | /** |
---|
1107 | * @brief Parameter block for open/close. |
---|
1108 | */ |
---|
1109 | typedef struct { |
---|
1110 | rtems_libio_t *iop; |
---|
1111 | uint32_t flags; |
---|
1112 | uint32_t mode; |
---|
1113 | } rtems_libio_open_close_args_t; |
---|
1114 | |
---|
1115 | /** |
---|
1116 | * @brief Parameter block for ioctl. |
---|
1117 | */ |
---|
1118 | typedef struct { |
---|
1119 | rtems_libio_t *iop; |
---|
1120 | uint32_t command; |
---|
1121 | void *buffer; |
---|
1122 | uint32_t ioctl_return; |
---|
1123 | } rtems_libio_ioctl_args_t; |
---|
1124 | |
---|
1125 | /** |
---|
1126 | * @name Flag Values |
---|
1127 | * |
---|
1128 | * @{ |
---|
1129 | */ |
---|
1130 | |
---|
1131 | #define LIBIO_FLAGS_NO_DELAY 0x0001U /* return immediately if no data */ |
---|
1132 | #define LIBIO_FLAGS_READ 0x0002U /* reading */ |
---|
1133 | #define LIBIO_FLAGS_WRITE 0x0004U /* writing */ |
---|
1134 | #define LIBIO_FLAGS_OPEN 0x0100U /* device is open */ |
---|
1135 | #define LIBIO_FLAGS_APPEND 0x0200U /* all writes append */ |
---|
1136 | #define LIBIO_FLAGS_CREATE 0x0400U /* create file */ |
---|
1137 | #define LIBIO_FLAGS_CLOSE_ON_EXEC 0x0800U /* close on process exec() */ |
---|
1138 | #define LIBIO_FLAGS_READ_WRITE (LIBIO_FLAGS_READ | LIBIO_FLAGS_WRITE) |
---|
1139 | |
---|
1140 | /** @} */ |
---|
1141 | |
---|
1142 | void rtems_libio_init(void); |
---|
1143 | |
---|
1144 | /** |
---|
1145 | * @name External I/O Handlers |
---|
1146 | * |
---|
1147 | * @{ |
---|
1148 | */ |
---|
1149 | |
---|
1150 | typedef int (*rtems_libio_open_t)( |
---|
1151 | const char *pathname, |
---|
1152 | uint32_t flag, |
---|
1153 | uint32_t mode |
---|
1154 | ); |
---|
1155 | |
---|
1156 | typedef int (*rtems_libio_close_t)( |
---|
1157 | int fd |
---|
1158 | ); |
---|
1159 | |
---|
1160 | typedef ssize_t (*rtems_libio_read_t)( |
---|
1161 | int fd, |
---|
1162 | void *buffer, |
---|
1163 | size_t count |
---|
1164 | ); |
---|
1165 | |
---|
1166 | typedef ssize_t (*rtems_libio_write_t)( |
---|
1167 | int fd, |
---|
1168 | const void *buffer, |
---|
1169 | size_t count |
---|
1170 | ); |
---|
1171 | |
---|
1172 | typedef int (*rtems_libio_ioctl_t)( |
---|
1173 | int fd, |
---|
1174 | uint32_t command, |
---|
1175 | void *buffer |
---|
1176 | ); |
---|
1177 | |
---|
1178 | typedef off_t (*rtems_libio_lseek_t)( |
---|
1179 | int fd, |
---|
1180 | off_t offset, |
---|
1181 | int whence |
---|
1182 | ); |
---|
1183 | |
---|
1184 | /** @} */ |
---|
1185 | |
---|
1186 | /** |
---|
1187 | * @name Permission Macros |
---|
1188 | * |
---|
1189 | * @{ |
---|
1190 | */ |
---|
1191 | |
---|
1192 | /* |
---|
1193 | * The following macros are used to build up the permissions sets |
---|
1194 | * used to check permissions. These are similar in style to the |
---|
1195 | * mode_t bits and should stay compatible with them. |
---|
1196 | */ |
---|
1197 | #define RTEMS_LIBIO_PERMS_READ S_IROTH |
---|
1198 | #define RTEMS_LIBIO_PERMS_WRITE S_IWOTH |
---|
1199 | #define RTEMS_LIBIO_PERMS_RDWR (S_IROTH|S_IWOTH) |
---|
1200 | #define RTEMS_LIBIO_PERMS_EXEC S_IXOTH |
---|
1201 | #define RTEMS_LIBIO_PERMS_SEARCH RTEMS_LIBIO_PERMS_EXEC |
---|
1202 | #define RTEMS_LIBIO_PERMS_RWX S_IRWXO |
---|
1203 | |
---|
1204 | /** @} */ |
---|
1205 | |
---|
1206 | union __rtems_dev_t { |
---|
1207 | dev_t device; |
---|
1208 | struct { |
---|
1209 | rtems_device_major_number major; |
---|
1210 | rtems_device_minor_number minor; |
---|
1211 | } __overlay; |
---|
1212 | }; |
---|
1213 | |
---|
1214 | static inline dev_t rtems_filesystem_make_dev_t( |
---|
1215 | rtems_device_major_number _major, |
---|
1216 | rtems_device_minor_number _minor |
---|
1217 | ) |
---|
1218 | { |
---|
1219 | union __rtems_dev_t temp; |
---|
1220 | |
---|
1221 | temp.__overlay.major = _major; |
---|
1222 | temp.__overlay.minor = _minor; |
---|
1223 | return temp.device; |
---|
1224 | } |
---|
1225 | |
---|
1226 | static inline rtems_device_major_number rtems_filesystem_dev_major_t( |
---|
1227 | dev_t device |
---|
1228 | ) |
---|
1229 | { |
---|
1230 | union __rtems_dev_t temp; |
---|
1231 | |
---|
1232 | temp.device = device; |
---|
1233 | return temp.__overlay.major; |
---|
1234 | } |
---|
1235 | |
---|
1236 | |
---|
1237 | static inline rtems_device_minor_number rtems_filesystem_dev_minor_t( |
---|
1238 | dev_t device |
---|
1239 | ) |
---|
1240 | { |
---|
1241 | union __rtems_dev_t temp; |
---|
1242 | |
---|
1243 | temp.device = device; |
---|
1244 | return temp.__overlay.minor; |
---|
1245 | } |
---|
1246 | |
---|
1247 | #define rtems_filesystem_split_dev_t( _dev, _major, _minor ) \ |
---|
1248 | do { \ |
---|
1249 | (_major) = rtems_filesystem_dev_major_t ( _dev ); \ |
---|
1250 | (_minor) = rtems_filesystem_dev_minor_t( _dev ); \ |
---|
1251 | } while(0) |
---|
1252 | |
---|
1253 | /* |
---|
1254 | * Verifies that the permission flag is valid. |
---|
1255 | */ |
---|
1256 | #define rtems_libio_is_valid_perms( _perm ) \ |
---|
1257 | (((~RTEMS_LIBIO_PERMS_RWX) & _perm ) == 0) |
---|
1258 | |
---|
1259 | /* |
---|
1260 | * Prototypes for filesystem |
---|
1261 | */ |
---|
1262 | |
---|
1263 | void rtems_filesystem_initialize( void ); |
---|
1264 | |
---|
1265 | typedef void (*rtems_libio_init_functions_t)(void); |
---|
1266 | extern rtems_libio_init_functions_t rtems_libio_init_helper; |
---|
1267 | |
---|
1268 | void open_dev_console(void); |
---|
1269 | |
---|
1270 | typedef void (*rtems_libio_supp_functions_t)(void); |
---|
1271 | extern rtems_libio_supp_functions_t rtems_libio_supp_helper; |
---|
1272 | |
---|
1273 | typedef void (*rtems_fs_init_functions_t)(void); |
---|
1274 | extern rtems_fs_init_functions_t rtems_fs_init_helper; |
---|
1275 | |
---|
1276 | /** |
---|
1277 | * @brief Creates a directory and all its parent directories according to |
---|
1278 | * @a path. |
---|
1279 | * |
---|
1280 | * The @a mode value selects the access permissions of the directory. |
---|
1281 | * |
---|
1282 | * @retval 0 Successful operation. |
---|
1283 | * @retval -1 An error occured. The @c errno indicates the error. |
---|
1284 | */ |
---|
1285 | extern int rtems_mkdir(const char *path, mode_t mode); |
---|
1286 | |
---|
1287 | /** @} */ |
---|
1288 | |
---|
1289 | /** |
---|
1290 | * @defgroup FileSystemTypesAndMount File System Types and Mount |
---|
1291 | * |
---|
1292 | * @ingroup LibIO |
---|
1293 | * |
---|
1294 | * @brief File system types and mount. |
---|
1295 | * |
---|
1296 | * @{ |
---|
1297 | */ |
---|
1298 | |
---|
1299 | /** |
---|
1300 | * @name File System Types |
---|
1301 | * |
---|
1302 | * @{ |
---|
1303 | */ |
---|
1304 | |
---|
1305 | #define RTEMS_FILESYSTEM_TYPE_IMFS "imfs" |
---|
1306 | #define RTEMS_FILESYSTEM_TYPE_MINIIMFS "mimfs" |
---|
1307 | #define RTEMS_FILESYSTEM_TYPE_DEVFS "devfs" |
---|
1308 | #define RTEMS_FILESYSTEM_TYPE_FTPFS "ftpfs" |
---|
1309 | #define RTEMS_FILESYSTEM_TYPE_TFTPFS "tftpfs" |
---|
1310 | #define RTEMS_FILESYSTEM_TYPE_NFS "nfs" |
---|
1311 | #define RTEMS_FILESYSTEM_TYPE_DOSFS "dosfs" |
---|
1312 | #define RTEMS_FILESYSTEM_TYPE_RFS "rfs" |
---|
1313 | |
---|
1314 | /** @} */ |
---|
1315 | |
---|
1316 | /** |
---|
1317 | * @brief Mount table entry. |
---|
1318 | */ |
---|
1319 | struct rtems_filesystem_mount_table_entry_tt { |
---|
1320 | rtems_chain_node Node; |
---|
1321 | rtems_filesystem_location_info_t mt_point_node; |
---|
1322 | rtems_filesystem_location_info_t mt_fs_root; |
---|
1323 | int options; |
---|
1324 | void *fs_info; |
---|
1325 | |
---|
1326 | rtems_filesystem_limits_and_options_t pathconf_limits_and_options; |
---|
1327 | |
---|
1328 | /* |
---|
1329 | * The target or mount point of the file system. |
---|
1330 | */ |
---|
1331 | const char *target; |
---|
1332 | |
---|
1333 | /* |
---|
1334 | * The type of filesystem or the name of the filesystem. |
---|
1335 | */ |
---|
1336 | const char *type; |
---|
1337 | |
---|
1338 | /* |
---|
1339 | * When someone adds a mounted filesystem on a real device, |
---|
1340 | * this will need to be used. |
---|
1341 | * |
---|
1342 | * The lower layers can manage how this is managed. Leave as a |
---|
1343 | * string. |
---|
1344 | */ |
---|
1345 | char *dev; |
---|
1346 | }; |
---|
1347 | |
---|
1348 | /** |
---|
1349 | * @brief File system options. |
---|
1350 | */ |
---|
1351 | typedef enum { |
---|
1352 | RTEMS_FILESYSTEM_READ_ONLY, |
---|
1353 | RTEMS_FILESYSTEM_READ_WRITE, |
---|
1354 | RTEMS_FILESYSTEM_BAD_OPTIONS |
---|
1355 | } rtems_filesystem_options_t; |
---|
1356 | |
---|
1357 | /** |
---|
1358 | * @brief File system table entry. |
---|
1359 | */ |
---|
1360 | typedef struct rtems_filesystem_table_t { |
---|
1361 | const char *type; |
---|
1362 | rtems_filesystem_fsmount_me_t mount_h; |
---|
1363 | } rtems_filesystem_table_t; |
---|
1364 | |
---|
1365 | /** |
---|
1366 | * @brief Static table of file systems. |
---|
1367 | * |
---|
1368 | * Externally defined by confdefs.h or the user. |
---|
1369 | */ |
---|
1370 | extern const rtems_filesystem_table_t rtems_filesystem_table []; |
---|
1371 | |
---|
1372 | /** |
---|
1373 | * @brief Registers a file system @a type. |
---|
1374 | * |
---|
1375 | * The @a mount_h handler will be used to mount a file system of this @a type. |
---|
1376 | * |
---|
1377 | * @retval 0 Successful operation. |
---|
1378 | * @retval -1 An error occured. The @c errno indicates the error. |
---|
1379 | */ |
---|
1380 | int rtems_filesystem_register( |
---|
1381 | const char *type, |
---|
1382 | rtems_filesystem_fsmount_me_t mount_h |
---|
1383 | ); |
---|
1384 | |
---|
1385 | /** |
---|
1386 | * @brief Unregisters a file system @a type. |
---|
1387 | * |
---|
1388 | * @retval 0 Successful operation. |
---|
1389 | * @retval -1 An error occured. The @c errno indicates the error. |
---|
1390 | */ |
---|
1391 | int rtems_filesystem_unregister( |
---|
1392 | const char *type |
---|
1393 | ); |
---|
1394 | |
---|
1395 | /** |
---|
1396 | * @brief Unmounts the file system at @a mount_path. |
---|
1397 | * |
---|
1398 | * @todo Due to file system implementation shortcomings it is possible to |
---|
1399 | * unmount file systems in use. This likely leads to heap corruption. Unmount |
---|
1400 | * only file systems which are not in use by the application. |
---|
1401 | * |
---|
1402 | * @retval 0 Successful operation. |
---|
1403 | * @retval -1 An error occured. The @c errno indicates the error. |
---|
1404 | */ |
---|
1405 | int unmount( |
---|
1406 | const char *mount_path |
---|
1407 | ); |
---|
1408 | |
---|
1409 | /** |
---|
1410 | * @brief Mounts a file system at @a target. |
---|
1411 | * |
---|
1412 | * The @a source may be a path to the corresponding device file, or @c NULL. |
---|
1413 | * The @a target path must lead to an existing directory, or @c NULL. In case |
---|
1414 | * @a target is @c NULL, the root file system will be mounted. The @a data |
---|
1415 | * parameter will be forwarded to the file system initialization handler. The |
---|
1416 | * file system type is selected by @a filesystemtype and may be one of |
---|
1417 | * - RTEMS_FILESYSTEM_TYPE_DEVFS, |
---|
1418 | * - RTEMS_FILESYSTEM_TYPE_DOSFS, |
---|
1419 | * - RTEMS_FILESYSTEM_TYPE_FTPFS, |
---|
1420 | * - RTEMS_FILESYSTEM_TYPE_IMFS, |
---|
1421 | * - RTEMS_FILESYSTEM_TYPE_MINIIMFS, |
---|
1422 | * - RTEMS_FILESYSTEM_TYPE_NFS, |
---|
1423 | * - RTEMS_FILESYSTEM_TYPE_RFS, or |
---|
1424 | * - RTEMS_FILESYSTEM_TYPE_TFTPFS. |
---|
1425 | * |
---|
1426 | * Only configured or registered file system types are available. You can add |
---|
1427 | * file system types to your application configuration with |
---|
1428 | * - CONFIGURE_FILESYSTEM_DEVFS, |
---|
1429 | * - CONFIGURE_FILESYSTEM_DOSFS, |
---|
1430 | * - CONFIGURE_FILESYSTEM_FTPFS, |
---|
1431 | * - CONFIGURE_FILESYSTEM_IMFS, |
---|
1432 | * - CONFIGURE_FILESYSTEM_MINIIMFS, |
---|
1433 | * - CONFIGURE_FILESYSTEM_NFS, |
---|
1434 | * - CONFIGURE_FILESYSTEM_RFS, and |
---|
1435 | * - CONFIGURE_FILESYSTEM_TFTPFS. |
---|
1436 | * |
---|
1437 | * @see rtems_filesystem_register() and mount_and_make_target_path(). |
---|
1438 | * |
---|
1439 | * @retval 0 Successful operation. |
---|
1440 | * @retval -1 An error occured. The @c errno indicates the error. |
---|
1441 | */ |
---|
1442 | int mount( |
---|
1443 | const char *source, |
---|
1444 | const char *target, |
---|
1445 | const char *filesystemtype, |
---|
1446 | rtems_filesystem_options_t options, |
---|
1447 | const void *data |
---|
1448 | ); |
---|
1449 | |
---|
1450 | /** |
---|
1451 | * @brief Mounts a file system and makes the @a target path. |
---|
1452 | * |
---|
1453 | * The @a target path will be created with rtems_mkdir() and must not be |
---|
1454 | * @c NULL. |
---|
1455 | * |
---|
1456 | * @see mount(). |
---|
1457 | * |
---|
1458 | * @retval 0 Successful operation. |
---|
1459 | * @retval -1 An error occured. The @c errno indicates the error. |
---|
1460 | */ |
---|
1461 | int mount_and_make_target_path( |
---|
1462 | const char *source, |
---|
1463 | const char *target, |
---|
1464 | const char *filesystemtype, |
---|
1465 | rtems_filesystem_options_t options, |
---|
1466 | const void *data |
---|
1467 | ); |
---|
1468 | |
---|
1469 | /** |
---|
1470 | * @brief Per file system type routine. |
---|
1471 | * |
---|
1472 | * @see rtems_filesystem_iterate(). |
---|
1473 | * |
---|
1474 | * @retval true Stop the iteration. |
---|
1475 | * @retval false Continue the iteration. |
---|
1476 | */ |
---|
1477 | typedef bool (*rtems_per_filesystem_routine)( |
---|
1478 | const rtems_filesystem_table_t *fs_entry, |
---|
1479 | void *arg |
---|
1480 | ); |
---|
1481 | |
---|
1482 | /** |
---|
1483 | * @brief Iterates over all file system types. |
---|
1484 | * |
---|
1485 | * For each file system type the @a routine will be called with the entry and |
---|
1486 | * the @a routine_arg parameter. |
---|
1487 | * |
---|
1488 | * Do not register or unregister file system types in @a routine. |
---|
1489 | * |
---|
1490 | * The iteration is protected by the IO library mutex. |
---|
1491 | * |
---|
1492 | * @retval true Iteration stopped due to @a routine return status. |
---|
1493 | * @retval false Iteration through all entries. |
---|
1494 | */ |
---|
1495 | bool rtems_filesystem_iterate( |
---|
1496 | rtems_per_filesystem_routine routine, |
---|
1497 | void *routine_arg |
---|
1498 | ); |
---|
1499 | |
---|
1500 | /** |
---|
1501 | * @brief Per file system mount routine. |
---|
1502 | * |
---|
1503 | * @see rtems_filesystem_mount_iterate(). |
---|
1504 | * |
---|
1505 | * @retval true Stop the iteration. |
---|
1506 | * @retval false Continue the iteration. |
---|
1507 | */ |
---|
1508 | typedef bool (*rtems_per_filesystem_mount_routine)( |
---|
1509 | const rtems_filesystem_mount_table_entry_t *mt_entry, |
---|
1510 | void *arg |
---|
1511 | ); |
---|
1512 | |
---|
1513 | /** |
---|
1514 | * @brief Iterates over all file system mounts. |
---|
1515 | * |
---|
1516 | * For each file system mount the @a routine will be called with the entry and |
---|
1517 | * the @a routine_arg parameter. |
---|
1518 | * |
---|
1519 | * Do not mount or unmount file systems in @a routine. |
---|
1520 | * |
---|
1521 | * The iteration is protected by the IO library mutex. |
---|
1522 | * |
---|
1523 | * @retval true Iteration stopped due to @a routine return status. |
---|
1524 | * @retval false Iteration through all entries. |
---|
1525 | */ |
---|
1526 | bool |
---|
1527 | rtems_filesystem_mount_iterate( |
---|
1528 | rtems_per_filesystem_mount_routine routine, |
---|
1529 | void *routine_arg |
---|
1530 | ); |
---|
1531 | |
---|
1532 | /** |
---|
1533 | * @brief Boot time mount table entry. |
---|
1534 | */ |
---|
1535 | typedef struct { |
---|
1536 | const char *type; |
---|
1537 | rtems_filesystem_options_t fsoptions; |
---|
1538 | const char *device; |
---|
1539 | const char *mount_point; |
---|
1540 | } rtems_filesystem_mount_table_t; |
---|
1541 | |
---|
1542 | /** |
---|
1543 | * @brief Boot time mount table. |
---|
1544 | * |
---|
1545 | * @todo Only the first entry will be evaluated. Why do we need a table? |
---|
1546 | */ |
---|
1547 | extern const rtems_filesystem_mount_table_t *rtems_filesystem_mount_table; |
---|
1548 | |
---|
1549 | /** |
---|
1550 | * @brief Boot time mount table entry count. |
---|
1551 | * |
---|
1552 | * @todo Only the first entry will be evaluated. Why do we need a table? |
---|
1553 | */ |
---|
1554 | extern const int rtems_filesystem_mount_table_size; |
---|
1555 | |
---|
1556 | /** @} */ |
---|
1557 | |
---|
1558 | /** |
---|
1559 | * @defgroup Termios Termios |
---|
1560 | * |
---|
1561 | * @ingroup LibIO |
---|
1562 | * |
---|
1563 | * @brief Termios |
---|
1564 | * |
---|
1565 | * @{ |
---|
1566 | */ |
---|
1567 | |
---|
1568 | typedef struct rtems_termios_callbacks { |
---|
1569 | int (*firstOpen)(int major, int minor, void *arg); |
---|
1570 | int (*lastClose)(int major, int minor, void *arg); |
---|
1571 | int (*pollRead)(int minor); |
---|
1572 | ssize_t (*write)(int minor, const char *buf, size_t len); |
---|
1573 | int (*setAttributes)(int minor, const struct termios *t); |
---|
1574 | int (*stopRemoteTx)(int minor); |
---|
1575 | int (*startRemoteTx)(int minor); |
---|
1576 | int outputUsesInterrupts; |
---|
1577 | } rtems_termios_callbacks; |
---|
1578 | |
---|
1579 | void rtems_termios_initialize (void); |
---|
1580 | |
---|
1581 | /* |
---|
1582 | * CCJ: Change before opening a tty. Newer code from Eric is coming |
---|
1583 | * so extra work to handle an open tty is not worth it. If the tty |
---|
1584 | * is open, close then open it again. |
---|
1585 | */ |
---|
1586 | rtems_status_code rtems_termios_bufsize ( |
---|
1587 | size_t cbufsize, /* cooked buffer size */ |
---|
1588 | size_t raw_input, /* raw input buffer size */ |
---|
1589 | size_t raw_output /* raw output buffer size */ |
---|
1590 | ); |
---|
1591 | |
---|
1592 | rtems_status_code rtems_termios_open ( |
---|
1593 | rtems_device_major_number major, |
---|
1594 | rtems_device_minor_number minor, |
---|
1595 | void *arg, |
---|
1596 | const rtems_termios_callbacks *callbacks |
---|
1597 | ); |
---|
1598 | |
---|
1599 | rtems_status_code rtems_termios_close( |
---|
1600 | void *arg |
---|
1601 | ); |
---|
1602 | |
---|
1603 | rtems_status_code rtems_termios_read( |
---|
1604 | void *arg |
---|
1605 | ); |
---|
1606 | |
---|
1607 | rtems_status_code rtems_termios_write( |
---|
1608 | void *arg |
---|
1609 | ); |
---|
1610 | |
---|
1611 | rtems_status_code rtems_termios_ioctl( |
---|
1612 | void *arg |
---|
1613 | ); |
---|
1614 | |
---|
1615 | int rtems_termios_enqueue_raw_characters( |
---|
1616 | void *ttyp, |
---|
1617 | const char *buf, |
---|
1618 | int len |
---|
1619 | ); |
---|
1620 | |
---|
1621 | int rtems_termios_dequeue_characters( |
---|
1622 | void *ttyp, |
---|
1623 | int len |
---|
1624 | ); |
---|
1625 | |
---|
1626 | /** @} */ |
---|
1627 | |
---|
1628 | /** |
---|
1629 | * @brief The pathconf setting for a file system. |
---|
1630 | */ |
---|
1631 | #define rtems_filesystem_pathconf(_mte) ((_mte)->pathconf_limits_and_options) |
---|
1632 | |
---|
1633 | /** |
---|
1634 | * @brief The type of file system. Its name. |
---|
1635 | */ |
---|
1636 | #define rtems_filesystem_type(_mte) ((_mte)->type) |
---|
1637 | |
---|
1638 | /** |
---|
1639 | * @brief The mount point of a file system. |
---|
1640 | */ |
---|
1641 | #define rtems_filesystem_mount_point(_mte) ((_mte)->target) |
---|
1642 | |
---|
1643 | /** |
---|
1644 | * @brief The device entry of a file system. |
---|
1645 | */ |
---|
1646 | #define rtems_filesystem_mount_device(_mte) ((_mte)->dev) |
---|
1647 | |
---|
1648 | #ifdef __cplusplus |
---|
1649 | } |
---|
1650 | #endif |
---|
1651 | |
---|
1652 | #endif /* _RTEMS_LIBIO_H */ |
---|