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 | /** |
---|
53 | * @brief A 64-bit file offset for internal use by RTEMS. Based on the Newlib |
---|
54 | * type. |
---|
55 | */ |
---|
56 | typedef _off64_t rtems_off64_t; |
---|
57 | |
---|
58 | /** |
---|
59 | * @name File System Node Types |
---|
60 | * |
---|
61 | * @{ |
---|
62 | */ |
---|
63 | |
---|
64 | #define RTEMS_FILESYSTEM_DIRECTORY 1 |
---|
65 | #define RTEMS_FILESYSTEM_DEVICE 2 |
---|
66 | #define RTEMS_FILESYSTEM_HARD_LINK 3 |
---|
67 | #define RTEMS_FILESYSTEM_SYM_LINK 4 |
---|
68 | #define RTEMS_FILESYSTEM_MEMORY_FILE 5 |
---|
69 | |
---|
70 | /** @} */ |
---|
71 | |
---|
72 | typedef int rtems_filesystem_node_types_t; |
---|
73 | |
---|
74 | /** |
---|
75 | * @name File System Node Operations |
---|
76 | * |
---|
77 | * @{ |
---|
78 | */ |
---|
79 | |
---|
80 | typedef int (*rtems_filesystem_open_t)( |
---|
81 | rtems_libio_t *iop, |
---|
82 | const char *pathname, |
---|
83 | uint32_t flag, |
---|
84 | uint32_t mode |
---|
85 | ); |
---|
86 | |
---|
87 | typedef int (*rtems_filesystem_close_t)( |
---|
88 | rtems_libio_t *iop |
---|
89 | ); |
---|
90 | |
---|
91 | typedef ssize_t (*rtems_filesystem_read_t)( |
---|
92 | rtems_libio_t *iop, |
---|
93 | void *buffer, |
---|
94 | size_t count |
---|
95 | ); |
---|
96 | |
---|
97 | typedef ssize_t (*rtems_filesystem_write_t)( |
---|
98 | rtems_libio_t *iop, |
---|
99 | const void *buffer, |
---|
100 | size_t count |
---|
101 | ); |
---|
102 | |
---|
103 | typedef int (*rtems_filesystem_ioctl_t)( |
---|
104 | rtems_libio_t *iop, |
---|
105 | uint32_t command, |
---|
106 | void *buffer |
---|
107 | ); |
---|
108 | |
---|
109 | typedef rtems_off64_t (*rtems_filesystem_lseek_t)( |
---|
110 | rtems_libio_t *iop, |
---|
111 | rtems_off64_t length, |
---|
112 | int whence |
---|
113 | ); |
---|
114 | |
---|
115 | typedef int (*rtems_filesystem_fstat_t)( |
---|
116 | rtems_filesystem_location_info_t *loc, |
---|
117 | struct stat *buf |
---|
118 | ); |
---|
119 | |
---|
120 | typedef int (*rtems_filesystem_fchmod_t)( |
---|
121 | rtems_filesystem_location_info_t *loc, |
---|
122 | mode_t mode |
---|
123 | ); |
---|
124 | |
---|
125 | typedef int (*rtems_filesystem_ftruncate_t)( |
---|
126 | rtems_libio_t *iop, |
---|
127 | rtems_off64_t length |
---|
128 | ); |
---|
129 | |
---|
130 | typedef int (*rtems_filesystem_fpathconf_t)( |
---|
131 | rtems_libio_t *iop, |
---|
132 | int name |
---|
133 | ); |
---|
134 | |
---|
135 | typedef int (*rtems_filesystem_fsync_t)( |
---|
136 | rtems_libio_t *iop |
---|
137 | ); |
---|
138 | |
---|
139 | typedef int (*rtems_filesystem_fdatasync_t)( |
---|
140 | rtems_libio_t *iop |
---|
141 | ); |
---|
142 | |
---|
143 | typedef int (*rtems_filesystem_fcntl_t)( |
---|
144 | int cmd, |
---|
145 | rtems_libio_t *iop |
---|
146 | ); |
---|
147 | |
---|
148 | typedef int (*rtems_filesystem_rmnod_t)( |
---|
149 | rtems_filesystem_location_info_t *parent_loc, /* IN */ |
---|
150 | rtems_filesystem_location_info_t *pathloc /* IN */ |
---|
151 | ); |
---|
152 | |
---|
153 | /** @} */ |
---|
154 | |
---|
155 | /** |
---|
156 | * @brief File system node operations table. |
---|
157 | */ |
---|
158 | struct _rtems_filesystem_file_handlers_r { |
---|
159 | rtems_filesystem_open_t open_h; |
---|
160 | rtems_filesystem_close_t close_h; |
---|
161 | rtems_filesystem_read_t read_h; |
---|
162 | rtems_filesystem_write_t write_h; |
---|
163 | rtems_filesystem_ioctl_t ioctl_h; |
---|
164 | rtems_filesystem_lseek_t lseek_h; |
---|
165 | rtems_filesystem_fstat_t fstat_h; |
---|
166 | rtems_filesystem_fchmod_t fchmod_h; |
---|
167 | rtems_filesystem_ftruncate_t ftruncate_h; |
---|
168 | rtems_filesystem_fpathconf_t fpathconf_h; |
---|
169 | rtems_filesystem_fsync_t fsync_h; |
---|
170 | rtems_filesystem_fdatasync_t fdatasync_h; |
---|
171 | rtems_filesystem_fcntl_t fcntl_h; |
---|
172 | rtems_filesystem_rmnod_t rmnod_h; |
---|
173 | }; |
---|
174 | |
---|
175 | /** |
---|
176 | * @name File System Operations |
---|
177 | * |
---|
178 | * @{ |
---|
179 | */ |
---|
180 | |
---|
181 | /* |
---|
182 | * XXX |
---|
183 | * This routine does not allocate any space and rtems_filesystem_freenode_t |
---|
184 | * is not called by the generic after calling this routine. |
---|
185 | * ie. node_access does not have to contain valid data when the |
---|
186 | * routine returns. |
---|
187 | */ |
---|
188 | typedef int (*rtems_filesystem_mknod_t)( |
---|
189 | const char *path, /* IN */ |
---|
190 | mode_t mode, /* IN */ |
---|
191 | dev_t dev, /* IN */ |
---|
192 | rtems_filesystem_location_info_t *pathloc /* IN/OUT */ |
---|
193 | ); |
---|
194 | |
---|
195 | /* |
---|
196 | * rtems_filesystem_freenode_t must be called by the generic after |
---|
197 | * calling this routine |
---|
198 | */ |
---|
199 | |
---|
200 | typedef int (*rtems_filesystem_evalpath_t)( |
---|
201 | const char *pathname, /* IN */ |
---|
202 | size_t pathnamelen, /* IN */ |
---|
203 | int flags, /* IN */ |
---|
204 | rtems_filesystem_location_info_t *pathloc /* IN/OUT */ |
---|
205 | ); |
---|
206 | |
---|
207 | typedef int (*rtems_filesystem_evalmake_t)( |
---|
208 | const char *path, /* IN */ |
---|
209 | rtems_filesystem_location_info_t *pathloc, /* IN/OUT */ |
---|
210 | const char **name /* OUT */ |
---|
211 | ); |
---|
212 | |
---|
213 | typedef int (*rtems_filesystem_link_t)( |
---|
214 | rtems_filesystem_location_info_t *to_loc, /* IN */ |
---|
215 | rtems_filesystem_location_info_t *parent_loc, /* IN */ |
---|
216 | const char *name /* IN */ |
---|
217 | ); |
---|
218 | |
---|
219 | typedef int (*rtems_filesystem_unlink_t)( |
---|
220 | rtems_filesystem_location_info_t *parent_pathloc, /* IN */ |
---|
221 | rtems_filesystem_location_info_t *pathloc /* IN */ |
---|
222 | ); |
---|
223 | |
---|
224 | typedef int (*rtems_filesystem_chown_t)( |
---|
225 | rtems_filesystem_location_info_t *pathloc, /* IN */ |
---|
226 | uid_t owner, /* IN */ |
---|
227 | gid_t group /* IN */ |
---|
228 | ); |
---|
229 | |
---|
230 | typedef int (*rtems_filesystem_freenode_t)( |
---|
231 | rtems_filesystem_location_info_t *pathloc /* IN */ |
---|
232 | ); |
---|
233 | |
---|
234 | typedef int (* rtems_filesystem_mount_t ) ( |
---|
235 | rtems_filesystem_mount_table_entry_t *mt_entry /* IN */ |
---|
236 | ); |
---|
237 | |
---|
238 | typedef int (* rtems_filesystem_fsmount_me_t )( |
---|
239 | rtems_filesystem_mount_table_entry_t *mt_entry, /* IN */ |
---|
240 | const void *data /* IN */ |
---|
241 | ); |
---|
242 | |
---|
243 | typedef int (* rtems_filesystem_unmount_t ) ( |
---|
244 | rtems_filesystem_mount_table_entry_t *mt_entry /* IN */ |
---|
245 | ); |
---|
246 | |
---|
247 | typedef int (* rtems_filesystem_fsunmount_me_t ) ( |
---|
248 | rtems_filesystem_mount_table_entry_t *mt_entry /* IN */ |
---|
249 | ); |
---|
250 | |
---|
251 | typedef rtems_filesystem_node_types_t (* rtems_filesystem_node_type_t) ( |
---|
252 | rtems_filesystem_location_info_t *pathloc /* IN */ |
---|
253 | ); |
---|
254 | |
---|
255 | typedef int (* rtems_filesystem_utime_t)( |
---|
256 | rtems_filesystem_location_info_t *pathloc, /* IN */ |
---|
257 | time_t actime, /* IN */ |
---|
258 | time_t modtime /* IN */ |
---|
259 | ); |
---|
260 | |
---|
261 | typedef int (*rtems_filesystem_evaluate_link_t)( |
---|
262 | rtems_filesystem_location_info_t *pathloc, /* IN/OUT */ |
---|
263 | int flags /* IN */ |
---|
264 | ); |
---|
265 | |
---|
266 | typedef int (*rtems_filesystem_symlink_t)( |
---|
267 | rtems_filesystem_location_info_t *loc, /* IN */ |
---|
268 | const char *link_name, /* IN */ |
---|
269 | const char *node_name |
---|
270 | ); |
---|
271 | |
---|
272 | typedef int (*rtems_filesystem_readlink_t)( |
---|
273 | rtems_filesystem_location_info_t *loc, /* IN */ |
---|
274 | char *buf, /* OUT */ |
---|
275 | size_t bufsize |
---|
276 | ); |
---|
277 | |
---|
278 | typedef int (*rtems_filesystem_rename_t)( |
---|
279 | rtems_filesystem_location_info_t *old_parent_loc, /* IN */ |
---|
280 | rtems_filesystem_location_info_t *old_loc, /* IN */ |
---|
281 | rtems_filesystem_location_info_t *new_parent_loc, /* IN */ |
---|
282 | const char *name /* IN */ |
---|
283 | ); |
---|
284 | |
---|
285 | typedef int (*rtems_filesystem_statvfs_t)( |
---|
286 | rtems_filesystem_location_info_t *loc, /* IN */ |
---|
287 | struct statvfs *buf /* OUT */ |
---|
288 | ); |
---|
289 | |
---|
290 | /** @} */ |
---|
291 | |
---|
292 | /** |
---|
293 | * @brief File system operations table. |
---|
294 | */ |
---|
295 | struct _rtems_filesystem_operations_table { |
---|
296 | rtems_filesystem_evalpath_t evalpath_h; |
---|
297 | rtems_filesystem_evalmake_t evalformake_h; |
---|
298 | rtems_filesystem_link_t link_h; |
---|
299 | rtems_filesystem_unlink_t unlink_h; |
---|
300 | rtems_filesystem_node_type_t node_type_h; |
---|
301 | rtems_filesystem_mknod_t mknod_h; |
---|
302 | rtems_filesystem_chown_t chown_h; |
---|
303 | rtems_filesystem_freenode_t freenod_h; |
---|
304 | rtems_filesystem_mount_t mount_h; |
---|
305 | rtems_filesystem_fsmount_me_t fsmount_me_h; |
---|
306 | rtems_filesystem_unmount_t unmount_h; |
---|
307 | rtems_filesystem_fsunmount_me_t fsunmount_me_h; |
---|
308 | rtems_filesystem_utime_t utime_h; |
---|
309 | rtems_filesystem_evaluate_link_t eval_link_h; |
---|
310 | rtems_filesystem_symlink_t symlink_h; |
---|
311 | rtems_filesystem_readlink_t readlink_h; |
---|
312 | rtems_filesystem_rename_t rename_h; |
---|
313 | rtems_filesystem_statvfs_t statvfs_h; |
---|
314 | }; |
---|
315 | |
---|
316 | /** |
---|
317 | * @brief Gets the mount handler for the file system @a type. |
---|
318 | * |
---|
319 | * @return The file system mount handler associated with the @a type, or |
---|
320 | * @c NULL if no such association exists. |
---|
321 | */ |
---|
322 | rtems_filesystem_fsmount_me_t |
---|
323 | rtems_filesystem_get_mount_handler( |
---|
324 | const char *type |
---|
325 | ); |
---|
326 | |
---|
327 | /** |
---|
328 | * @brief Contain file system specific information which is required to support |
---|
329 | * fpathconf(). |
---|
330 | */ |
---|
331 | typedef struct { |
---|
332 | int link_max; /* count */ |
---|
333 | int max_canon; /* max formatted input line size */ |
---|
334 | int max_input; /* max input line size */ |
---|
335 | int name_max; /* max name length */ |
---|
336 | int path_max; /* max path */ |
---|
337 | int pipe_buf; /* pipe buffer size */ |
---|
338 | int posix_async_io; /* async IO supported on fs, 0=no, 1=yes */ |
---|
339 | int posix_chown_restrictions; /* can chown: 0=no, 1=yes */ |
---|
340 | int posix_no_trunc; /* error on names > max name, 0=no, 1=yes */ |
---|
341 | int posix_prio_io; /* priority IO, 0=no, 1=yes */ |
---|
342 | int posix_sync_io; /* file can be sync'ed, 0=no, 1=yes */ |
---|
343 | int posix_vdisable; /* special char processing, 0=no, 1=yes */ |
---|
344 | } rtems_filesystem_limits_and_options_t; |
---|
345 | |
---|
346 | /** |
---|
347 | * @brief Default pathconf settings. |
---|
348 | * |
---|
349 | * Override in a filesystem. |
---|
350 | */ |
---|
351 | extern const rtems_filesystem_limits_and_options_t rtems_filesystem_default_pathconf; |
---|
352 | |
---|
353 | /** |
---|
354 | * @brief An open file data structure. |
---|
355 | * |
---|
356 | * It will be indexed by 'fd'. |
---|
357 | * |
---|
358 | * @todo Should really have a separate per/file data structure that this points |
---|
359 | * to (eg: size, offset, driver, pathname should be in that) |
---|
360 | */ |
---|
361 | struct rtems_libio_tt { |
---|
362 | rtems_driver_name_t *driver; |
---|
363 | rtems_off64_t size; /* size of file */ |
---|
364 | rtems_off64_t offset; /* current offset into file */ |
---|
365 | uint32_t flags; |
---|
366 | rtems_filesystem_location_info_t pathinfo; |
---|
367 | rtems_id sem; |
---|
368 | uint32_t data0; /* private to "driver" */ |
---|
369 | void *data1; /* ... */ |
---|
370 | void *file_info; /* used by file handlers */ |
---|
371 | const rtems_filesystem_file_handlers_r *handlers; /* type specific handlers */ |
---|
372 | }; |
---|
373 | |
---|
374 | /** |
---|
375 | * @brief Paramameter block for read/write. |
---|
376 | * |
---|
377 | * It must include 'offset' instead of using iop's offset since we can have |
---|
378 | * multiple outstanding i/o's on a device. |
---|
379 | */ |
---|
380 | typedef struct { |
---|
381 | rtems_libio_t *iop; |
---|
382 | rtems_off64_t offset; |
---|
383 | char *buffer; |
---|
384 | uint32_t count; |
---|
385 | uint32_t flags; |
---|
386 | uint32_t bytes_moved; |
---|
387 | } rtems_libio_rw_args_t; |
---|
388 | |
---|
389 | /** |
---|
390 | * @brief Parameter block for open/close. |
---|
391 | */ |
---|
392 | typedef struct { |
---|
393 | rtems_libio_t *iop; |
---|
394 | uint32_t flags; |
---|
395 | uint32_t mode; |
---|
396 | } rtems_libio_open_close_args_t; |
---|
397 | |
---|
398 | /** |
---|
399 | * @brief Parameter block for ioctl. |
---|
400 | */ |
---|
401 | typedef struct { |
---|
402 | rtems_libio_t *iop; |
---|
403 | uint32_t command; |
---|
404 | void *buffer; |
---|
405 | uint32_t ioctl_return; |
---|
406 | } rtems_libio_ioctl_args_t; |
---|
407 | |
---|
408 | /** |
---|
409 | * @name Flag Values |
---|
410 | * |
---|
411 | * @{ |
---|
412 | */ |
---|
413 | |
---|
414 | #define LIBIO_FLAGS_NO_DELAY 0x0001 /* return immediately if no data */ |
---|
415 | #define LIBIO_FLAGS_READ 0x0002 /* reading */ |
---|
416 | #define LIBIO_FLAGS_WRITE 0x0004 /* writing */ |
---|
417 | #define LIBIO_FLAGS_OPEN 0x0100 /* device is open */ |
---|
418 | #define LIBIO_FLAGS_APPEND 0x0200 /* all writes append */ |
---|
419 | #define LIBIO_FLAGS_CREATE 0x0400 /* create file */ |
---|
420 | #define LIBIO_FLAGS_CLOSE_ON_EXEC 0x0800 /* close on process exec() */ |
---|
421 | #define LIBIO_FLAGS_READ_WRITE (LIBIO_FLAGS_READ | LIBIO_FLAGS_WRITE) |
---|
422 | |
---|
423 | /** @} */ |
---|
424 | |
---|
425 | void rtems_libio_init(void); |
---|
426 | |
---|
427 | /** |
---|
428 | * @name External I/O Handlers |
---|
429 | * |
---|
430 | * @{ |
---|
431 | */ |
---|
432 | |
---|
433 | typedef int (*rtems_libio_open_t)( |
---|
434 | const char *pathname, |
---|
435 | uint32_t flag, |
---|
436 | uint32_t mode |
---|
437 | ); |
---|
438 | |
---|
439 | typedef int (*rtems_libio_close_t)( |
---|
440 | int fd |
---|
441 | ); |
---|
442 | |
---|
443 | typedef int (*rtems_libio_read_t)( |
---|
444 | int fd, |
---|
445 | void *buffer, |
---|
446 | uint32_t count |
---|
447 | ); |
---|
448 | |
---|
449 | typedef int (*rtems_libio_write_t)( |
---|
450 | int fd, |
---|
451 | const void *buffer, |
---|
452 | uint32_t count |
---|
453 | ); |
---|
454 | |
---|
455 | typedef int (*rtems_libio_ioctl_t)( |
---|
456 | int fd, |
---|
457 | uint32_t command, |
---|
458 | void *buffer |
---|
459 | ); |
---|
460 | |
---|
461 | typedef rtems_off64_t (*rtems_libio_lseek_t)( |
---|
462 | int fd, |
---|
463 | rtems_off64_t offset, |
---|
464 | int whence |
---|
465 | ); |
---|
466 | |
---|
467 | /** @} */ |
---|
468 | |
---|
469 | /** |
---|
470 | * @name Permission Macros |
---|
471 | * |
---|
472 | * @{ |
---|
473 | */ |
---|
474 | |
---|
475 | /* |
---|
476 | * The following macros are used to build up the permissions sets |
---|
477 | * used to check permissions. These are similar in style to the |
---|
478 | * mode_t bits and should stay compatible with them. |
---|
479 | */ |
---|
480 | #define RTEMS_LIBIO_PERMS_READ S_IROTH |
---|
481 | #define RTEMS_LIBIO_PERMS_WRITE S_IWOTH |
---|
482 | #define RTEMS_LIBIO_PERMS_RDWR (S_IROTH|S_IWOTH) |
---|
483 | #define RTEMS_LIBIO_PERMS_EXEC S_IXOTH |
---|
484 | #define RTEMS_LIBIO_PERMS_SEARCH RTEMS_LIBIO_PERMS_EXEC |
---|
485 | #define RTEMS_LIBIO_PERMS_RWX S_IRWXO |
---|
486 | |
---|
487 | /** @} */ |
---|
488 | |
---|
489 | union __rtems_dev_t { |
---|
490 | dev_t device; |
---|
491 | struct { |
---|
492 | rtems_device_major_number major; |
---|
493 | rtems_device_minor_number minor; |
---|
494 | } __overlay; |
---|
495 | }; |
---|
496 | |
---|
497 | static inline dev_t rtems_filesystem_make_dev_t( |
---|
498 | rtems_device_major_number _major, |
---|
499 | rtems_device_minor_number _minor |
---|
500 | ) |
---|
501 | { |
---|
502 | union __rtems_dev_t temp; |
---|
503 | |
---|
504 | temp.__overlay.major = _major; |
---|
505 | temp.__overlay.minor = _minor; |
---|
506 | return temp.device; |
---|
507 | } |
---|
508 | |
---|
509 | static inline rtems_device_major_number rtems_filesystem_dev_major_t( |
---|
510 | dev_t device |
---|
511 | ) |
---|
512 | { |
---|
513 | union __rtems_dev_t temp; |
---|
514 | |
---|
515 | temp.device = device; |
---|
516 | return temp.__overlay.major; |
---|
517 | } |
---|
518 | |
---|
519 | |
---|
520 | static inline rtems_device_minor_number rtems_filesystem_dev_minor_t( |
---|
521 | dev_t device |
---|
522 | ) |
---|
523 | { |
---|
524 | union __rtems_dev_t temp; |
---|
525 | |
---|
526 | temp.device = device; |
---|
527 | return temp.__overlay.minor; |
---|
528 | } |
---|
529 | |
---|
530 | #define rtems_filesystem_split_dev_t( _dev, _major, _minor ) \ |
---|
531 | do { \ |
---|
532 | (_major) = rtems_filesystem_dev_major_t ( _dev ); \ |
---|
533 | (_minor) = rtems_filesystem_dev_minor_t( _dev ); \ |
---|
534 | } while(0) |
---|
535 | |
---|
536 | /* |
---|
537 | * Verifies that the permission flag is valid. |
---|
538 | */ |
---|
539 | #define rtems_libio_is_valid_perms( _perm ) \ |
---|
540 | (~ ((~RTEMS_LIBIO_PERMS_RWX) & _perm )) |
---|
541 | |
---|
542 | /* |
---|
543 | * Prototypes for filesystem |
---|
544 | */ |
---|
545 | |
---|
546 | void rtems_filesystem_initialize( void ); |
---|
547 | |
---|
548 | typedef void (*rtems_libio_init_functions_t)(void); |
---|
549 | extern rtems_libio_init_functions_t rtems_libio_init_helper; |
---|
550 | |
---|
551 | void open_dev_console(void); |
---|
552 | |
---|
553 | typedef void (*rtems_libio_supp_functions_t)(void); |
---|
554 | extern rtems_libio_supp_functions_t rtems_libio_supp_helper; |
---|
555 | |
---|
556 | typedef void (*rtems_fs_init_functions_t)(void); |
---|
557 | extern rtems_fs_init_functions_t rtems_fs_init_helper; |
---|
558 | |
---|
559 | /** |
---|
560 | * @brief Creates a directory and all its parent directories according to |
---|
561 | * @a path. |
---|
562 | * |
---|
563 | * The @a mode value selects the access permissions of the directory. |
---|
564 | * |
---|
565 | * @retval 0 Successful operation. |
---|
566 | * @retval -1 An error occured. The @c errno indicates the error. |
---|
567 | */ |
---|
568 | extern int rtems_mkdir(const char *path, mode_t mode); |
---|
569 | |
---|
570 | /** @} */ |
---|
571 | |
---|
572 | /** |
---|
573 | * @defgroup FileSystemTypesAndMount File System Types and Mount |
---|
574 | * |
---|
575 | * @ingroup LibIO |
---|
576 | * |
---|
577 | * @brief File system types and mount. |
---|
578 | * |
---|
579 | * @{ |
---|
580 | */ |
---|
581 | |
---|
582 | /** |
---|
583 | * @name File System Types |
---|
584 | * |
---|
585 | * @{ |
---|
586 | */ |
---|
587 | |
---|
588 | #define RTEMS_FILESYSTEM_TYPE_IMFS "imfs" |
---|
589 | #define RTEMS_FILESYSTEM_TYPE_MINIIMFS "mimfs" |
---|
590 | #define RTEMS_FILESYSTEM_TYPE_DEVFS "devfs" |
---|
591 | #define RTEMS_FILESYSTEM_TYPE_FTPFS "ftpfs" |
---|
592 | #define RTEMS_FILESYSTEM_TYPE_TFTPFS "tftpfs" |
---|
593 | #define RTEMS_FILESYSTEM_TYPE_NFS "nfs" |
---|
594 | #define RTEMS_FILESYSTEM_TYPE_DOSFS "dosfs" |
---|
595 | #define RTEMS_FILESYSTEM_TYPE_RFS "rfs" |
---|
596 | |
---|
597 | /** @} */ |
---|
598 | |
---|
599 | /** |
---|
600 | * @brief Mount table entry. |
---|
601 | */ |
---|
602 | struct rtems_filesystem_mount_table_entry_tt { |
---|
603 | rtems_chain_node Node; |
---|
604 | rtems_filesystem_location_info_t mt_point_node; |
---|
605 | rtems_filesystem_location_info_t mt_fs_root; |
---|
606 | int options; |
---|
607 | void *fs_info; |
---|
608 | |
---|
609 | rtems_filesystem_limits_and_options_t pathconf_limits_and_options; |
---|
610 | |
---|
611 | /* |
---|
612 | * The target or mount point of the file system. |
---|
613 | */ |
---|
614 | const char *target; |
---|
615 | |
---|
616 | /* |
---|
617 | * The type of filesystem or the name of the filesystem. |
---|
618 | */ |
---|
619 | const char *type; |
---|
620 | |
---|
621 | /* |
---|
622 | * When someone adds a mounted filesystem on a real device, |
---|
623 | * this will need to be used. |
---|
624 | * |
---|
625 | * The lower layers can manage how this is managed. Leave as a |
---|
626 | * string. |
---|
627 | */ |
---|
628 | char *dev; |
---|
629 | }; |
---|
630 | |
---|
631 | /** |
---|
632 | * @brief File system options. |
---|
633 | */ |
---|
634 | typedef enum { |
---|
635 | RTEMS_FILESYSTEM_READ_ONLY, |
---|
636 | RTEMS_FILESYSTEM_READ_WRITE, |
---|
637 | RTEMS_FILESYSTEM_BAD_OPTIONS |
---|
638 | } rtems_filesystem_options_t; |
---|
639 | |
---|
640 | /** |
---|
641 | * @brief File system table entry. |
---|
642 | */ |
---|
643 | typedef struct rtems_filesystem_table_t { |
---|
644 | const char *type; |
---|
645 | rtems_filesystem_fsmount_me_t mount_h; |
---|
646 | } rtems_filesystem_table_t; |
---|
647 | |
---|
648 | /** |
---|
649 | * @brief Static table of file systems. |
---|
650 | * |
---|
651 | * Externally defined by confdefs.h or the user. |
---|
652 | */ |
---|
653 | extern const rtems_filesystem_table_t rtems_filesystem_table []; |
---|
654 | |
---|
655 | /** |
---|
656 | * @brief Registers a file system @a type. |
---|
657 | * |
---|
658 | * The @a mount_h handler will be used to mount a file system of this @a type. |
---|
659 | * |
---|
660 | * @retval 0 Successful operation. |
---|
661 | * @retval -1 An error occured. The @c errno indicates the error. |
---|
662 | */ |
---|
663 | int rtems_filesystem_register( |
---|
664 | const char *type, |
---|
665 | rtems_filesystem_fsmount_me_t mount_h |
---|
666 | ); |
---|
667 | |
---|
668 | /** |
---|
669 | * @brief Unregisters a file system @a type. |
---|
670 | * |
---|
671 | * @retval 0 Successful operation. |
---|
672 | * @retval -1 An error occured. The @c errno indicates the error. |
---|
673 | */ |
---|
674 | int rtems_filesystem_unregister( |
---|
675 | const char *type |
---|
676 | ); |
---|
677 | |
---|
678 | /** |
---|
679 | * @brief Unmounts the file system at @a mount_path. |
---|
680 | * |
---|
681 | * @todo Due to file system implementation shortcomings it is possible to |
---|
682 | * unmount file systems in use. This likely leads to heap corruption. Unmount |
---|
683 | * only file systems which are not in use by the application. |
---|
684 | * |
---|
685 | * @retval 0 Successful operation. |
---|
686 | * @retval -1 An error occured. The @c errno indicates the error. |
---|
687 | */ |
---|
688 | int unmount( |
---|
689 | const char *mount_path |
---|
690 | ); |
---|
691 | |
---|
692 | /** |
---|
693 | * @brief Mounts a file system at @a target. |
---|
694 | * |
---|
695 | * The @a source may be a path to the corresponding device file, or @c NULL. |
---|
696 | * The @a target path must lead to an existing directory, or @c NULL. In case |
---|
697 | * @a target is @c NULL, the root file system will be mounted. The @a data |
---|
698 | * parameter will be forwarded to the file system initialization handler. The |
---|
699 | * file system type is selected by @a filesystemtype and may be one of |
---|
700 | * - RTEMS_FILESYSTEM_TYPE_DEVFS, |
---|
701 | * - RTEMS_FILESYSTEM_TYPE_DOSFS, |
---|
702 | * - RTEMS_FILESYSTEM_TYPE_FTPFS, |
---|
703 | * - RTEMS_FILESYSTEM_TYPE_IMFS, |
---|
704 | * - RTEMS_FILESYSTEM_TYPE_MINIIMFS, |
---|
705 | * - RTEMS_FILESYSTEM_TYPE_NFS, |
---|
706 | * - RTEMS_FILESYSTEM_TYPE_RFS, or |
---|
707 | * - RTEMS_FILESYSTEM_TYPE_TFTPFS. |
---|
708 | * |
---|
709 | * Only configured or registered file system types are available. You can add |
---|
710 | * file system types to your application configuration with |
---|
711 | * - CONFIGURE_FILESYSTEM_DEVFS, |
---|
712 | * - CONFIGURE_FILESYSTEM_DOSFS, |
---|
713 | * - CONFIGURE_FILESYSTEM_FTPFS, |
---|
714 | * - CONFIGURE_FILESYSTEM_IMFS, |
---|
715 | * - CONFIGURE_FILESYSTEM_MINIIMFS, |
---|
716 | * - CONFIGURE_FILESYSTEM_NFS, |
---|
717 | * - CONFIGURE_FILESYSTEM_RFS, and |
---|
718 | * - CONFIGURE_FILESYSTEM_TFTPFS. |
---|
719 | * |
---|
720 | * @see rtems_filesystem_register() and mount_and_make_target_path(). |
---|
721 | * |
---|
722 | * @retval 0 Successful operation. |
---|
723 | * @retval -1 An error occured. The @c errno indicates the error. |
---|
724 | */ |
---|
725 | int mount( |
---|
726 | const char *source, |
---|
727 | const char *target, |
---|
728 | const char *filesystemtype, |
---|
729 | rtems_filesystem_options_t options, |
---|
730 | const void *data |
---|
731 | ); |
---|
732 | |
---|
733 | /** |
---|
734 | * @brief Mounts a file system and makes the @a target path. |
---|
735 | * |
---|
736 | * The @a target path will be created with rtems_mkdir() and must not be |
---|
737 | * @c NULL. |
---|
738 | * |
---|
739 | * @see mount(). |
---|
740 | * |
---|
741 | * @retval 0 Successful operation. |
---|
742 | * @retval -1 An error occured. The @c errno indicates the error. |
---|
743 | */ |
---|
744 | int mount_and_make_target_path( |
---|
745 | const char *source, |
---|
746 | const char *target, |
---|
747 | const char *filesystemtype, |
---|
748 | rtems_filesystem_options_t options, |
---|
749 | const void *data |
---|
750 | ); |
---|
751 | |
---|
752 | /** |
---|
753 | * @brief Per file system type routine. |
---|
754 | * |
---|
755 | * @see rtems_filesystem_iterate(). |
---|
756 | * |
---|
757 | * @retval true Stop the iteration. |
---|
758 | * @retval false Continue the iteration. |
---|
759 | */ |
---|
760 | typedef bool (*rtems_per_filesystem_routine)( |
---|
761 | const rtems_filesystem_table_t *fs_entry, |
---|
762 | void *arg |
---|
763 | ); |
---|
764 | |
---|
765 | /** |
---|
766 | * @brief Iterates over all file system types. |
---|
767 | * |
---|
768 | * For each file system type the @a routine will be called with the entry and |
---|
769 | * the @a routine_arg parameter. |
---|
770 | * |
---|
771 | * Do not register or unregister file system types in @a routine. |
---|
772 | * |
---|
773 | * The iteration is protected by the IO library mutex. |
---|
774 | * |
---|
775 | * @retval true Iteration stopped due to @a routine return status. |
---|
776 | * @retval false Iteration through all entries. |
---|
777 | */ |
---|
778 | bool rtems_filesystem_iterate( |
---|
779 | rtems_per_filesystem_routine routine, |
---|
780 | void *routine_arg |
---|
781 | ); |
---|
782 | |
---|
783 | /** |
---|
784 | * @brief Per file system mount routine. |
---|
785 | * |
---|
786 | * @see rtems_filesystem_mount_iterate(). |
---|
787 | * |
---|
788 | * @retval true Stop the iteration. |
---|
789 | * @retval false Continue the iteration. |
---|
790 | */ |
---|
791 | typedef bool (*rtems_per_filesystem_mount_routine)( |
---|
792 | const rtems_filesystem_mount_table_entry_t *mt_entry, |
---|
793 | void *arg |
---|
794 | ); |
---|
795 | |
---|
796 | /** |
---|
797 | * @brief Iterates over all file system mounts. |
---|
798 | * |
---|
799 | * For each file system mount the @a routine will be called with the entry and |
---|
800 | * the @a routine_arg parameter. |
---|
801 | * |
---|
802 | * Do not mount or unmount file systems in @a routine. |
---|
803 | * |
---|
804 | * The iteration is protected by the IO library mutex. |
---|
805 | * |
---|
806 | * @retval true Iteration stopped due to @a routine return status. |
---|
807 | * @retval false Iteration through all entries. |
---|
808 | */ |
---|
809 | bool |
---|
810 | rtems_filesystem_mount_iterate( |
---|
811 | rtems_per_filesystem_mount_routine routine, |
---|
812 | void *routine_arg |
---|
813 | ); |
---|
814 | |
---|
815 | /** |
---|
816 | * @brief Boot time mount table entry. |
---|
817 | */ |
---|
818 | typedef struct { |
---|
819 | const char *type; |
---|
820 | rtems_filesystem_options_t fsoptions; |
---|
821 | const char *device; |
---|
822 | const char *mount_point; |
---|
823 | } rtems_filesystem_mount_table_t; |
---|
824 | |
---|
825 | extern const rtems_filesystem_mount_table_t *rtems_filesystem_mount_table; |
---|
826 | extern const int rtems_filesystem_mount_table_size; |
---|
827 | |
---|
828 | /** |
---|
829 | * @brief Creates a directory and all its parrent directories according to |
---|
830 | * @a path. |
---|
831 | * |
---|
832 | * The @a mode value selects the access permissions of the directory. |
---|
833 | * |
---|
834 | * @retval 0 Successful operation. |
---|
835 | * @retval -1 An error occured. The @c errno indicates the error. |
---|
836 | */ |
---|
837 | extern int rtems_mkdir(const char *path, mode_t mode); |
---|
838 | |
---|
839 | /** @} */ |
---|
840 | |
---|
841 | /** |
---|
842 | * @defgroup Termios Termios |
---|
843 | * |
---|
844 | * @ingroup LibIO |
---|
845 | * |
---|
846 | * @brief Termios |
---|
847 | * |
---|
848 | * @{ |
---|
849 | */ |
---|
850 | |
---|
851 | typedef struct rtems_termios_callbacks { |
---|
852 | int (*firstOpen)(int major, int minor, void *arg); |
---|
853 | int (*lastClose)(int major, int minor, void *arg); |
---|
854 | int (*pollRead)(int minor); |
---|
855 | ssize_t (*write)(int minor, const char *buf, size_t len); |
---|
856 | int (*setAttributes)(int minor, const struct termios *t); |
---|
857 | int (*stopRemoteTx)(int minor); |
---|
858 | int (*startRemoteTx)(int minor); |
---|
859 | int outputUsesInterrupts; |
---|
860 | } rtems_termios_callbacks; |
---|
861 | |
---|
862 | void rtems_termios_initialize (void); |
---|
863 | |
---|
864 | /* |
---|
865 | * CCJ: Change before opening a tty. Newer code from Eric is coming |
---|
866 | * so extra work to handle an open tty is not worth it. If the tty |
---|
867 | * is open, close then open it again. |
---|
868 | */ |
---|
869 | rtems_status_code rtems_termios_bufsize ( |
---|
870 | int cbufsize, /* cooked buffer size */ |
---|
871 | int raw_input, /* raw input buffer size */ |
---|
872 | int raw_output /* raw output buffer size */ |
---|
873 | ); |
---|
874 | |
---|
875 | rtems_status_code rtems_termios_open ( |
---|
876 | rtems_device_major_number major, |
---|
877 | rtems_device_minor_number minor, |
---|
878 | void *arg, |
---|
879 | const rtems_termios_callbacks *callbacks |
---|
880 | ); |
---|
881 | |
---|
882 | rtems_status_code rtems_termios_close( |
---|
883 | void *arg |
---|
884 | ); |
---|
885 | |
---|
886 | rtems_status_code rtems_termios_read( |
---|
887 | void *arg |
---|
888 | ); |
---|
889 | |
---|
890 | rtems_status_code rtems_termios_write( |
---|
891 | void *arg |
---|
892 | ); |
---|
893 | |
---|
894 | rtems_status_code rtems_termios_ioctl( |
---|
895 | void *arg |
---|
896 | ); |
---|
897 | |
---|
898 | int rtems_termios_enqueue_raw_characters( |
---|
899 | void *ttyp, |
---|
900 | char *buf, |
---|
901 | int len |
---|
902 | ); |
---|
903 | |
---|
904 | int rtems_termios_dequeue_characters( |
---|
905 | void *ttyp, |
---|
906 | int len |
---|
907 | ); |
---|
908 | |
---|
909 | /** @} */ |
---|
910 | |
---|
911 | /** |
---|
912 | * @brief The pathconf setting for a file system. |
---|
913 | */ |
---|
914 | #define rtems_filesystem_pathconf(_mte) ((_mte)->pathconf_limits_and_options) |
---|
915 | |
---|
916 | /** |
---|
917 | * @brief The type of file system. Its name. |
---|
918 | */ |
---|
919 | #define rtems_filesystem_type(_mte) ((_mte)->type) |
---|
920 | |
---|
921 | /** |
---|
922 | * @brief The mount point of a file system. |
---|
923 | */ |
---|
924 | #define rtems_filesystem_mount_point(_mte) ((_mte)->target) |
---|
925 | |
---|
926 | /** |
---|
927 | * @brief The device entry of a file system. |
---|
928 | */ |
---|
929 | #define rtems_filesystem_mount_device(_mte) ((_mte)->dev) |
---|
930 | |
---|
931 | #ifdef __cplusplus |
---|
932 | } |
---|
933 | #endif |
---|
934 | |
---|
935 | #endif /* _RTEMS_LIBIO_H */ |
---|