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 File system table entry. |
---|
318 | */ |
---|
319 | typedef struct rtems_filesystem_table_t { |
---|
320 | const char *type; |
---|
321 | rtems_filesystem_fsmount_me_t mount_h; |
---|
322 | } rtems_filesystem_table_t; |
---|
323 | |
---|
324 | /** |
---|
325 | * @brief Static table of file systems. |
---|
326 | * |
---|
327 | * Externally defined by confdefs.h or the user. |
---|
328 | */ |
---|
329 | extern const rtems_filesystem_table_t rtems_filesystem_table []; |
---|
330 | |
---|
331 | /** |
---|
332 | * @brief Per file system table entry routine type. |
---|
333 | * |
---|
334 | * @see rtems_filesystem_iterate(). |
---|
335 | * |
---|
336 | * @retval true Continue the iteration. |
---|
337 | * @retval false Stop the iteration. |
---|
338 | */ |
---|
339 | typedef bool (*rtems_per_filesystem_routine)( |
---|
340 | const rtems_filesystem_table_t *entry, |
---|
341 | void *arg |
---|
342 | ); |
---|
343 | |
---|
344 | /** |
---|
345 | * @brief Iterates over the file system table. |
---|
346 | * |
---|
347 | * For each file system table entry the @a routine will be called with the |
---|
348 | * table entry and the @a routine_arg parameter. |
---|
349 | */ |
---|
350 | void |
---|
351 | rtems_filesystem_iterate( |
---|
352 | rtems_per_filesystem_routine routine, |
---|
353 | void *routine_arg |
---|
354 | ); |
---|
355 | |
---|
356 | /** |
---|
357 | * @brief Gets the mount handler for the file system @a type. |
---|
358 | * |
---|
359 | * @return The file system mount handler associated with the @a type, or |
---|
360 | * @c NULL if no such association exists. |
---|
361 | */ |
---|
362 | rtems_filesystem_fsmount_me_t |
---|
363 | rtems_filesystem_get_mount_handler( |
---|
364 | const char *type |
---|
365 | ); |
---|
366 | |
---|
367 | /* |
---|
368 | * Get the first entry in the mount table. |
---|
369 | */ |
---|
370 | rtems_filesystem_mount_table_entry_t* |
---|
371 | rtems_filesystem_mounts_first( void ); |
---|
372 | |
---|
373 | /* |
---|
374 | * Get the next entry in the mount table. |
---|
375 | */ |
---|
376 | rtems_filesystem_mount_table_entry_t* |
---|
377 | rtems_filesystem_mounts_next( rtems_filesystem_mount_table_entry_t *entry ); |
---|
378 | |
---|
379 | /* |
---|
380 | * Register a file system. |
---|
381 | */ |
---|
382 | int |
---|
383 | rtems_filesystem_register( |
---|
384 | const char *type, |
---|
385 | rtems_filesystem_fsmount_me_t mount_h |
---|
386 | ); |
---|
387 | |
---|
388 | /* |
---|
389 | * Unregister a file system. |
---|
390 | */ |
---|
391 | int |
---|
392 | rtems_filesystem_unregister( |
---|
393 | const char *type |
---|
394 | ); |
---|
395 | |
---|
396 | /** |
---|
397 | * @brief Contain file system specific information which is required to support |
---|
398 | * fpathconf(). |
---|
399 | */ |
---|
400 | typedef struct { |
---|
401 | int link_max; /* count */ |
---|
402 | int max_canon; /* max formatted input line size */ |
---|
403 | int max_input; /* max input line size */ |
---|
404 | int name_max; /* max name length */ |
---|
405 | int path_max; /* max path */ |
---|
406 | int pipe_buf; /* pipe buffer size */ |
---|
407 | int posix_async_io; /* async IO supported on fs, 0=no, 1=yes */ |
---|
408 | int posix_chown_restrictions; /* can chown: 0=no, 1=yes */ |
---|
409 | int posix_no_trunc; /* error on names > max name, 0=no, 1=yes */ |
---|
410 | int posix_prio_io; /* priority IO, 0=no, 1=yes */ |
---|
411 | int posix_sync_io; /* file can be sync'ed, 0=no, 1=yes */ |
---|
412 | int posix_vdisable; /* special char processing, 0=no, 1=yes */ |
---|
413 | } rtems_filesystem_limits_and_options_t; |
---|
414 | |
---|
415 | /** |
---|
416 | * @brief Default pathconf settings. |
---|
417 | * |
---|
418 | * Override in a filesystem. |
---|
419 | */ |
---|
420 | extern const rtems_filesystem_limits_and_options_t rtems_filesystem_default_pathconf; |
---|
421 | |
---|
422 | /** |
---|
423 | * @brief Mount table entry. |
---|
424 | */ |
---|
425 | struct rtems_filesystem_mount_table_entry_tt { |
---|
426 | rtems_chain_node Node; |
---|
427 | rtems_filesystem_location_info_t mt_point_node; |
---|
428 | rtems_filesystem_location_info_t mt_fs_root; |
---|
429 | int options; |
---|
430 | void *fs_info; |
---|
431 | |
---|
432 | rtems_filesystem_limits_and_options_t pathconf_limits_and_options; |
---|
433 | |
---|
434 | /* |
---|
435 | * The target or mount point of the file system. |
---|
436 | */ |
---|
437 | const char *target; |
---|
438 | |
---|
439 | /* |
---|
440 | * The type of filesystem or the name of the filesystem. |
---|
441 | */ |
---|
442 | const char *type; |
---|
443 | |
---|
444 | /* |
---|
445 | * When someone adds a mounted filesystem on a real device, |
---|
446 | * this will need to be used. |
---|
447 | * |
---|
448 | * The lower layers can manage how this is managed. Leave as a |
---|
449 | * string. |
---|
450 | */ |
---|
451 | char *dev; |
---|
452 | }; |
---|
453 | |
---|
454 | /** |
---|
455 | * @brief The pathconf setting for a file system. |
---|
456 | */ |
---|
457 | #define rtems_filesystem_pathconf(_mte) ((_mte)->pathconf_limits_and_options) |
---|
458 | |
---|
459 | /** |
---|
460 | * @brief The type of file system. Its name. |
---|
461 | */ |
---|
462 | #define rtems_filesystem_type(_mte) ((_mte)->type) |
---|
463 | |
---|
464 | /** |
---|
465 | * @brief The mount point of a file system. |
---|
466 | */ |
---|
467 | #define rtems_filesystem_mount_point(_mte) ((_mte)->target) |
---|
468 | |
---|
469 | /** |
---|
470 | * @brief The device entry of a file system. |
---|
471 | */ |
---|
472 | #define rtems_filesystem_mount_device(_mte) ((_mte)->dev) |
---|
473 | |
---|
474 | /** |
---|
475 | * @brief File systems options. |
---|
476 | */ |
---|
477 | typedef enum { |
---|
478 | RTEMS_FILESYSTEM_READ_ONLY, |
---|
479 | RTEMS_FILESYSTEM_READ_WRITE, |
---|
480 | RTEMS_FILESYSTEM_BAD_OPTIONS |
---|
481 | } rtems_filesystem_options_t; |
---|
482 | |
---|
483 | /** |
---|
484 | * @brief An open file data structure. |
---|
485 | * |
---|
486 | * It will be indexed by 'fd'. |
---|
487 | * |
---|
488 | * @todo Should really have a separate per/file data structure that this points |
---|
489 | * to (eg: size, offset, driver, pathname should be in that) |
---|
490 | */ |
---|
491 | struct rtems_libio_tt { |
---|
492 | rtems_driver_name_t *driver; |
---|
493 | rtems_off64_t size; /* size of file */ |
---|
494 | rtems_off64_t offset; /* current offset into file */ |
---|
495 | uint32_t flags; |
---|
496 | rtems_filesystem_location_info_t pathinfo; |
---|
497 | rtems_id sem; |
---|
498 | uint32_t data0; /* private to "driver" */ |
---|
499 | void *data1; /* ... */ |
---|
500 | void *file_info; /* used by file handlers */ |
---|
501 | const rtems_filesystem_file_handlers_r *handlers; /* type specific handlers */ |
---|
502 | }; |
---|
503 | |
---|
504 | /** |
---|
505 | * @brief Paramameter block for read/write. |
---|
506 | * |
---|
507 | * It must include 'offset' instead of using iop's offset since we can have |
---|
508 | * multiple outstanding i/o's on a device. |
---|
509 | */ |
---|
510 | typedef struct { |
---|
511 | rtems_libio_t *iop; |
---|
512 | rtems_off64_t offset; |
---|
513 | char *buffer; |
---|
514 | uint32_t count; |
---|
515 | uint32_t flags; |
---|
516 | uint32_t bytes_moved; |
---|
517 | } rtems_libio_rw_args_t; |
---|
518 | |
---|
519 | /** |
---|
520 | * @brief Parameter block for open/close. |
---|
521 | */ |
---|
522 | typedef struct { |
---|
523 | rtems_libio_t *iop; |
---|
524 | uint32_t flags; |
---|
525 | uint32_t mode; |
---|
526 | } rtems_libio_open_close_args_t; |
---|
527 | |
---|
528 | /** |
---|
529 | * @brief Parameter block for ioctl. |
---|
530 | */ |
---|
531 | typedef struct { |
---|
532 | rtems_libio_t *iop; |
---|
533 | uint32_t command; |
---|
534 | void *buffer; |
---|
535 | uint32_t ioctl_return; |
---|
536 | } rtems_libio_ioctl_args_t; |
---|
537 | |
---|
538 | /** |
---|
539 | * @name Flag Values |
---|
540 | * |
---|
541 | * @{ |
---|
542 | */ |
---|
543 | |
---|
544 | #define LIBIO_FLAGS_NO_DELAY 0x0001 /* return immediately if no data */ |
---|
545 | #define LIBIO_FLAGS_READ 0x0002 /* reading */ |
---|
546 | #define LIBIO_FLAGS_WRITE 0x0004 /* writing */ |
---|
547 | #define LIBIO_FLAGS_OPEN 0x0100 /* device is open */ |
---|
548 | #define LIBIO_FLAGS_APPEND 0x0200 /* all writes append */ |
---|
549 | #define LIBIO_FLAGS_CREATE 0x0400 /* create file */ |
---|
550 | #define LIBIO_FLAGS_CLOSE_ON_EXEC 0x0800 /* close on process exec() */ |
---|
551 | #define LIBIO_FLAGS_READ_WRITE (LIBIO_FLAGS_READ | LIBIO_FLAGS_WRITE) |
---|
552 | |
---|
553 | /** @} */ |
---|
554 | |
---|
555 | void rtems_libio_init(void); |
---|
556 | |
---|
557 | /** |
---|
558 | * @name External I/O Handlers |
---|
559 | * |
---|
560 | * @{ |
---|
561 | */ |
---|
562 | |
---|
563 | typedef int (*rtems_libio_open_t)( |
---|
564 | const char *pathname, |
---|
565 | uint32_t flag, |
---|
566 | uint32_t mode |
---|
567 | ); |
---|
568 | |
---|
569 | typedef int (*rtems_libio_close_t)( |
---|
570 | int fd |
---|
571 | ); |
---|
572 | |
---|
573 | typedef int (*rtems_libio_read_t)( |
---|
574 | int fd, |
---|
575 | void *buffer, |
---|
576 | uint32_t count |
---|
577 | ); |
---|
578 | |
---|
579 | typedef int (*rtems_libio_write_t)( |
---|
580 | int fd, |
---|
581 | const void *buffer, |
---|
582 | uint32_t count |
---|
583 | ); |
---|
584 | |
---|
585 | typedef int (*rtems_libio_ioctl_t)( |
---|
586 | int fd, |
---|
587 | uint32_t command, |
---|
588 | void *buffer |
---|
589 | ); |
---|
590 | |
---|
591 | typedef rtems_off64_t (*rtems_libio_lseek_t)( |
---|
592 | int fd, |
---|
593 | rtems_off64_t offset, |
---|
594 | int whence |
---|
595 | ); |
---|
596 | |
---|
597 | /** @} */ |
---|
598 | |
---|
599 | /** |
---|
600 | * @name Permission Macros |
---|
601 | * |
---|
602 | * @{ |
---|
603 | */ |
---|
604 | |
---|
605 | /* |
---|
606 | * The following macros are used to build up the permissions sets |
---|
607 | * used to check permissions. These are similar in style to the |
---|
608 | * mode_t bits and should stay compatible with them. |
---|
609 | */ |
---|
610 | #define RTEMS_LIBIO_PERMS_READ S_IROTH |
---|
611 | #define RTEMS_LIBIO_PERMS_WRITE S_IWOTH |
---|
612 | #define RTEMS_LIBIO_PERMS_RDWR (S_IROTH|S_IWOTH) |
---|
613 | #define RTEMS_LIBIO_PERMS_EXEC S_IXOTH |
---|
614 | #define RTEMS_LIBIO_PERMS_SEARCH RTEMS_LIBIO_PERMS_EXEC |
---|
615 | #define RTEMS_LIBIO_PERMS_RWX S_IRWXO |
---|
616 | |
---|
617 | /** @} */ |
---|
618 | |
---|
619 | union __rtems_dev_t { |
---|
620 | dev_t device; |
---|
621 | struct { |
---|
622 | rtems_device_major_number major; |
---|
623 | rtems_device_minor_number minor; |
---|
624 | } __overlay; |
---|
625 | }; |
---|
626 | |
---|
627 | static inline dev_t rtems_filesystem_make_dev_t( |
---|
628 | rtems_device_major_number _major, |
---|
629 | rtems_device_minor_number _minor |
---|
630 | ) |
---|
631 | { |
---|
632 | union __rtems_dev_t temp; |
---|
633 | |
---|
634 | temp.__overlay.major = _major; |
---|
635 | temp.__overlay.minor = _minor; |
---|
636 | return temp.device; |
---|
637 | } |
---|
638 | |
---|
639 | static inline rtems_device_major_number rtems_filesystem_dev_major_t( |
---|
640 | dev_t device |
---|
641 | ) |
---|
642 | { |
---|
643 | union __rtems_dev_t temp; |
---|
644 | |
---|
645 | temp.device = device; |
---|
646 | return temp.__overlay.major; |
---|
647 | } |
---|
648 | |
---|
649 | |
---|
650 | static inline rtems_device_minor_number rtems_filesystem_dev_minor_t( |
---|
651 | dev_t device |
---|
652 | ) |
---|
653 | { |
---|
654 | union __rtems_dev_t temp; |
---|
655 | |
---|
656 | temp.device = device; |
---|
657 | return temp.__overlay.minor; |
---|
658 | } |
---|
659 | |
---|
660 | #define rtems_filesystem_split_dev_t( _dev, _major, _minor ) \ |
---|
661 | do { \ |
---|
662 | (_major) = rtems_filesystem_dev_major_t ( _dev ); \ |
---|
663 | (_minor) = rtems_filesystem_dev_minor_t( _dev ); \ |
---|
664 | } while(0) |
---|
665 | |
---|
666 | /* |
---|
667 | * Verifies that the permission flag is valid. |
---|
668 | */ |
---|
669 | #define rtems_libio_is_valid_perms( _perm ) \ |
---|
670 | (~ ((~RTEMS_LIBIO_PERMS_RWX) & _perm )) |
---|
671 | |
---|
672 | /** |
---|
673 | * @name File System Types |
---|
674 | * |
---|
675 | * @{ |
---|
676 | */ |
---|
677 | |
---|
678 | #define RTEMS_FILESYSTEM_TYPE_IMFS "imfs" |
---|
679 | #define RTEMS_FILESYSTEM_TYPE_MINIIMFS "mimfs" |
---|
680 | #define RTEMS_FILESYSTEM_TYPE_DEVFS "devfs" |
---|
681 | #define RTEMS_FILESYSTEM_TYPE_FTPFS "ftpfs" |
---|
682 | #define RTEMS_FILESYSTEM_TYPE_TFTPFS "tftpfs" |
---|
683 | #define RTEMS_FILESYSTEM_TYPE_NFS "nfs" |
---|
684 | #define RTEMS_FILESYSTEM_TYPE_DOSFS "dosfs" |
---|
685 | #define RTEMS_FILESYSTEM_TYPE_RFS "rfs" |
---|
686 | |
---|
687 | /** @} */ |
---|
688 | |
---|
689 | /* |
---|
690 | * Prototypes for filesystem |
---|
691 | */ |
---|
692 | |
---|
693 | void rtems_filesystem_initialize( void ); |
---|
694 | |
---|
695 | int unmount( |
---|
696 | const char *mount_path |
---|
697 | ); |
---|
698 | |
---|
699 | int mount( |
---|
700 | const char *source, |
---|
701 | const char *target, |
---|
702 | const char *filesystemtype, |
---|
703 | rtems_filesystem_options_t options, |
---|
704 | const void *data |
---|
705 | ); |
---|
706 | |
---|
707 | /** |
---|
708 | * @brief Mounts a file system and makes the @a target path. |
---|
709 | * |
---|
710 | * The @a target path will be created with rtems_mkdir() and must not be |
---|
711 | * @c NULL. |
---|
712 | * |
---|
713 | * @see mount(). |
---|
714 | * |
---|
715 | * @retval 0 Successful operation. |
---|
716 | * @retval -1 An error occured. The @c errno indicates the error. |
---|
717 | */ |
---|
718 | int mount_and_make_target_path( |
---|
719 | const char *source, |
---|
720 | const char *target, |
---|
721 | const char *filesystemtype, |
---|
722 | rtems_filesystem_options_t options, |
---|
723 | const void *data |
---|
724 | ); |
---|
725 | |
---|
726 | /* |
---|
727 | * Boot Time Mount Table Structure |
---|
728 | */ |
---|
729 | |
---|
730 | typedef struct { |
---|
731 | const char *type; |
---|
732 | rtems_filesystem_options_t fsoptions; |
---|
733 | const char *device; |
---|
734 | const char *mount_point; |
---|
735 | } rtems_filesystem_mount_table_t; |
---|
736 | |
---|
737 | extern const rtems_filesystem_mount_table_t *rtems_filesystem_mount_table; |
---|
738 | extern const int rtems_filesystem_mount_table_size; |
---|
739 | |
---|
740 | typedef void (*rtems_libio_init_functions_t)(void); |
---|
741 | extern rtems_libio_init_functions_t rtems_libio_init_helper; |
---|
742 | |
---|
743 | void open_dev_console(void); |
---|
744 | |
---|
745 | typedef void (*rtems_libio_supp_functions_t)(void); |
---|
746 | extern rtems_libio_supp_functions_t rtems_libio_supp_helper; |
---|
747 | |
---|
748 | typedef void (*rtems_fs_init_functions_t)(void); |
---|
749 | extern rtems_fs_init_functions_t rtems_fs_init_helper; |
---|
750 | |
---|
751 | /** |
---|
752 | * @brief Creates a directory and all its parrent directories according to |
---|
753 | * @a path. |
---|
754 | * |
---|
755 | * The @a mode value selects the access permissions of the directory. |
---|
756 | * |
---|
757 | * @retval 0 Successful operation. |
---|
758 | * @retval -1 An error occured. The @c errno indicates the error. |
---|
759 | */ |
---|
760 | extern int rtems_mkdir(const char *path, mode_t mode); |
---|
761 | |
---|
762 | /** @} */ |
---|
763 | |
---|
764 | /** |
---|
765 | * @defgroup Termios Termios |
---|
766 | * |
---|
767 | * @ingroup LibIO |
---|
768 | * |
---|
769 | * @brief Termios |
---|
770 | * |
---|
771 | * @{ |
---|
772 | */ |
---|
773 | |
---|
774 | typedef struct rtems_termios_callbacks { |
---|
775 | int (*firstOpen)(int major, int minor, void *arg); |
---|
776 | int (*lastClose)(int major, int minor, void *arg); |
---|
777 | int (*pollRead)(int minor); |
---|
778 | ssize_t (*write)(int minor, const char *buf, size_t len); |
---|
779 | int (*setAttributes)(int minor, const struct termios *t); |
---|
780 | int (*stopRemoteTx)(int minor); |
---|
781 | int (*startRemoteTx)(int minor); |
---|
782 | int outputUsesInterrupts; |
---|
783 | } rtems_termios_callbacks; |
---|
784 | |
---|
785 | void rtems_termios_initialize (void); |
---|
786 | |
---|
787 | /* |
---|
788 | * CCJ: Change before opening a tty. Newer code from Eric is coming |
---|
789 | * so extra work to handle an open tty is not worth it. If the tty |
---|
790 | * is open, close then open it again. |
---|
791 | */ |
---|
792 | rtems_status_code rtems_termios_bufsize ( |
---|
793 | int cbufsize, /* cooked buffer size */ |
---|
794 | int raw_input, /* raw input buffer size */ |
---|
795 | int raw_output /* raw output buffer size */ |
---|
796 | ); |
---|
797 | |
---|
798 | rtems_status_code rtems_termios_open ( |
---|
799 | rtems_device_major_number major, |
---|
800 | rtems_device_minor_number minor, |
---|
801 | void *arg, |
---|
802 | const rtems_termios_callbacks *callbacks |
---|
803 | ); |
---|
804 | |
---|
805 | rtems_status_code rtems_termios_close( |
---|
806 | void *arg |
---|
807 | ); |
---|
808 | |
---|
809 | rtems_status_code rtems_termios_read( |
---|
810 | void *arg |
---|
811 | ); |
---|
812 | |
---|
813 | rtems_status_code rtems_termios_write( |
---|
814 | void *arg |
---|
815 | ); |
---|
816 | |
---|
817 | rtems_status_code rtems_termios_ioctl( |
---|
818 | void *arg |
---|
819 | ); |
---|
820 | |
---|
821 | int rtems_termios_enqueue_raw_characters( |
---|
822 | void *ttyp, |
---|
823 | char *buf, |
---|
824 | int len |
---|
825 | ); |
---|
826 | |
---|
827 | int rtems_termios_dequeue_characters( |
---|
828 | void *ttyp, |
---|
829 | int len |
---|
830 | ); |
---|
831 | |
---|
832 | /** @} */ |
---|
833 | |
---|
834 | #ifdef __cplusplus |
---|
835 | } |
---|
836 | #endif |
---|
837 | |
---|
838 | #endif /* _RTEMS_LIBIO_H */ |
---|