[4d3017a] | 1 | /** |
---|
[615d8cc] | 2 | * @file |
---|
| 3 | * |
---|
| 4 | * @ingroup LibIO |
---|
| 5 | * |
---|
| 6 | * @brief Basic IO API. |
---|
[4d3017a] | 7 | */ |
---|
| 8 | |
---|
[b06e68ef] | 9 | /* |
---|
[ad78965d] | 10 | * COPYRIGHT (c) 1989-2008. |
---|
[07a3253d] | 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 |
---|
[0eae36c7] | 15 | * http://www.rtems.com/license/LICENSE. |
---|
[b06e68ef] | 16 | * |
---|
| 17 | * $Id$ |
---|
| 18 | */ |
---|
| 19 | |
---|
[7945944] | 20 | #ifndef _RTEMS_RTEMS_LIBIO_H |
---|
| 21 | #define _RTEMS_RTEMS_LIBIO_H |
---|
[b06e68ef] | 22 | |
---|
[7a3878b] | 23 | #include <sys/types.h> |
---|
[dcec5a4] | 24 | #include <sys/stat.h> |
---|
[9b05600] | 25 | #include <sys/ioctl.h> |
---|
[eb649786] | 26 | #include <sys/statvfs.h> |
---|
[dcec5a4] | 27 | |
---|
[615d8cc] | 28 | #include <unistd.h> |
---|
| 29 | #include <termios.h> |
---|
[07a3253d] | 30 | |
---|
[615d8cc] | 31 | #include <rtems.h> |
---|
[d09ad1f0] | 32 | #include <rtems/fs.h> |
---|
[615d8cc] | 33 | #include <rtems/chain.h> |
---|
[07a3253d] | 34 | |
---|
[80c2966] | 35 | #ifdef __cplusplus |
---|
| 36 | extern "C" { |
---|
| 37 | #endif |
---|
| 38 | |
---|
[615d8cc] | 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. |
---|
[07d6fd5] | 55 | */ |
---|
| 56 | typedef _off64_t rtems_off64_t; |
---|
| 57 | |
---|
[615d8cc] | 58 | /** |
---|
[3d3a18e6] | 59 | * @name File System Node Types |
---|
[615d8cc] | 60 | * |
---|
| 61 | * @{ |
---|
[07a3253d] | 62 | */ |
---|
[615d8cc] | 63 | |
---|
[a1f1011] | 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 |
---|
[615d8cc] | 69 | |
---|
| 70 | /** @} */ |
---|
| 71 | |
---|
[a1f1011] | 72 | typedef int rtems_filesystem_node_types_t; |
---|
[07a3253d] | 73 | |
---|
[615d8cc] | 74 | /** |
---|
| 75 | * @name File System Node Operations |
---|
| 76 | * |
---|
| 77 | * @{ |
---|
[07a3253d] | 78 | */ |
---|
[615d8cc] | 79 | |
---|
[07a3253d] | 80 | typedef int (*rtems_filesystem_open_t)( |
---|
| 81 | rtems_libio_t *iop, |
---|
| 82 | const char *pathname, |
---|
[83c5fc1] | 83 | uint32_t flag, |
---|
| 84 | uint32_t mode |
---|
[07a3253d] | 85 | ); |
---|
| 86 | |
---|
| 87 | typedef int (*rtems_filesystem_close_t)( |
---|
| 88 | rtems_libio_t *iop |
---|
| 89 | ); |
---|
| 90 | |
---|
[5d0b2f7] | 91 | typedef ssize_t (*rtems_filesystem_read_t)( |
---|
[07a3253d] | 92 | rtems_libio_t *iop, |
---|
| 93 | void *buffer, |
---|
[7192476f] | 94 | size_t count |
---|
[07a3253d] | 95 | ); |
---|
| 96 | |
---|
[5d0b2f7] | 97 | typedef ssize_t (*rtems_filesystem_write_t)( |
---|
[07a3253d] | 98 | rtems_libio_t *iop, |
---|
| 99 | const void *buffer, |
---|
[7192476f] | 100 | size_t count |
---|
[07a3253d] | 101 | ); |
---|
| 102 | |
---|
| 103 | typedef int (*rtems_filesystem_ioctl_t)( |
---|
| 104 | rtems_libio_t *iop, |
---|
[83c5fc1] | 105 | uint32_t command, |
---|
[07a3253d] | 106 | void *buffer |
---|
| 107 | ); |
---|
| 108 | |
---|
[07d6fd5] | 109 | typedef rtems_off64_t (*rtems_filesystem_lseek_t)( |
---|
[07a3253d] | 110 | rtems_libio_t *iop, |
---|
[07d6fd5] | 111 | rtems_off64_t length, |
---|
[07a3253d] | 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, |
---|
[07d6fd5] | 127 | rtems_off64_t length |
---|
[07a3253d] | 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 | |
---|
[af020036] | 143 | typedef int (*rtems_filesystem_fcntl_t)( |
---|
[e2116f9] | 144 | int cmd, |
---|
[af020036] | 145 | rtems_libio_t *iop |
---|
| 146 | ); |
---|
| 147 | |
---|
[4a07d2b] | 148 | typedef int (*rtems_filesystem_rmnod_t)( |
---|
[7baa484] | 149 | rtems_filesystem_location_info_t *parent_loc, /* IN */ |
---|
[4a07d2b] | 150 | rtems_filesystem_location_info_t *pathloc /* IN */ |
---|
| 151 | ); |
---|
| 152 | |
---|
[615d8cc] | 153 | /** @} */ |
---|
| 154 | |
---|
| 155 | /** |
---|
| 156 | * @brief File system node operations table. |
---|
| 157 | */ |
---|
[d09ad1f0] | 158 | struct _rtems_filesystem_file_handlers_r { |
---|
[9c3fa30] | 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; |
---|
[d09ad1f0] | 173 | }; |
---|
[07a3253d] | 174 | |
---|
[615d8cc] | 175 | /** |
---|
| 176 | * @name File System Operations |
---|
| 177 | * |
---|
| 178 | * @{ |
---|
[07a3253d] | 179 | */ |
---|
| 180 | |
---|
| 181 | /* |
---|
| 182 | * XXX |
---|
[50f32b11] | 183 | * This routine does not allocate any space and rtems_filesystem_freenode_t |
---|
[07a3253d] | 184 | * is not called by the generic after calling this routine. |
---|
[50f32b11] | 185 | * ie. node_access does not have to contain valid data when the |
---|
[07a3253d] | 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 */ |
---|
[fb1b349] | 202 | size_t pathnamelen, /* IN */ |
---|
[07a3253d] | 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)( |
---|
[7baa484] | 220 | rtems_filesystem_location_info_t *parent_pathloc, /* IN */ |
---|
| 221 | rtems_filesystem_location_info_t *pathloc /* IN */ |
---|
[07a3253d] | 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 ) ( |
---|
[29e92b0] | 235 | rtems_filesystem_mount_table_entry_t *mt_entry /* IN */ |
---|
[07a3253d] | 236 | ); |
---|
| 237 | |
---|
| 238 | typedef int (* rtems_filesystem_fsmount_me_t )( |
---|
[29e92b0] | 239 | rtems_filesystem_mount_table_entry_t *mt_entry, /* IN */ |
---|
| 240 | const void *data /* IN */ |
---|
[07a3253d] | 241 | ); |
---|
| 242 | |
---|
| 243 | typedef int (* rtems_filesystem_unmount_t ) ( |
---|
[29e92b0] | 244 | rtems_filesystem_mount_table_entry_t *mt_entry /* IN */ |
---|
[07a3253d] | 245 | ); |
---|
| 246 | |
---|
| 247 | typedef int (* rtems_filesystem_fsunmount_me_t ) ( |
---|
[29e92b0] | 248 | rtems_filesystem_mount_table_entry_t *mt_entry /* IN */ |
---|
[07a3253d] | 249 | ); |
---|
| 250 | |
---|
| 251 | typedef rtems_filesystem_node_types_t (* rtems_filesystem_node_type_t) ( |
---|
[29e92b0] | 252 | rtems_filesystem_location_info_t *pathloc /* IN */ |
---|
[07a3253d] | 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)( |
---|
[50f32b11] | 273 | rtems_filesystem_location_info_t *loc, /* IN */ |
---|
| 274 | char *buf, /* OUT */ |
---|
| 275 | size_t bufsize |
---|
[07a3253d] | 276 | ); |
---|
| 277 | |
---|
[8ec7abb] | 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 | |
---|
[eb649786] | 285 | typedef int (*rtems_filesystem_statvfs_t)( |
---|
| 286 | rtems_filesystem_location_info_t *loc, /* IN */ |
---|
| 287 | struct statvfs *buf /* OUT */ |
---|
| 288 | ); |
---|
| 289 | |
---|
[615d8cc] | 290 | /** @} */ |
---|
[07a3253d] | 291 | |
---|
[615d8cc] | 292 | /** |
---|
| 293 | * @brief File system operations table. |
---|
[07a3253d] | 294 | */ |
---|
[d09ad1f0] | 295 | struct _rtems_filesystem_operations_table { |
---|
[9c3fa30] | 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; |
---|
[8ec7abb] | 312 | rtems_filesystem_rename_t rename_h; |
---|
[eb649786] | 313 | rtems_filesystem_statvfs_t statvfs_h; |
---|
[d09ad1f0] | 314 | }; |
---|
| 315 | |
---|
[00bf6744] | 316 | /** |
---|
| 317 | * @brief File system table entry. |
---|
[29e92b0] | 318 | */ |
---|
[dfce6724] | 319 | typedef struct rtems_filesystem_table_t { |
---|
[29e92b0] | 320 | const char *type; |
---|
| 321 | rtems_filesystem_fsmount_me_t mount_h; |
---|
| 322 | } rtems_filesystem_table_t; |
---|
| 323 | |
---|
[00bf6744] | 324 | /** |
---|
| 325 | * @brief Static table of file systems. |
---|
| 326 | * |
---|
| 327 | * Externally defined by confdefs.h or the user. |
---|
[29e92b0] | 328 | */ |
---|
[00bf6744] | 329 | extern const rtems_filesystem_table_t rtems_filesystem_table []; |
---|
[29e92b0] | 330 | |
---|
[00bf6744] | 331 | /** |
---|
| 332 | * @brief Per file system table entry routine type. |
---|
| 333 | * |
---|
[615d8cc] | 334 | * @see rtems_filesystem_iterate(). |
---|
| 335 | * |
---|
| 336 | * @retval true Continue the iteration. |
---|
| 337 | * @retval false Stop the iteration. |
---|
[29e92b0] | 338 | */ |
---|
[00bf6744] | 339 | typedef bool (*rtems_per_filesystem_routine)( |
---|
| 340 | const rtems_filesystem_table_t *entry, |
---|
| 341 | void *arg |
---|
| 342 | ); |
---|
[29e92b0] | 343 | |
---|
[00bf6744] | 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 | /** |
---|
[615d8cc] | 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 |
---|
[00bf6744] | 360 | * @c NULL if no such association exists. |
---|
[29e92b0] | 361 | */ |
---|
[00bf6744] | 362 | rtems_filesystem_fsmount_me_t |
---|
| 363 | rtems_filesystem_get_mount_handler( |
---|
| 364 | const char *type |
---|
| 365 | ); |
---|
[29e92b0] | 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 | |
---|
[615d8cc] | 396 | /** |
---|
| 397 | * @brief Contain file system specific information which is required to support |
---|
| 398 | * fpathconf(). |
---|
[b06e68ef] | 399 | */ |
---|
| 400 | typedef struct { |
---|
[29e92b0] | 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 */ |
---|
[07a3253d] | 413 | } rtems_filesystem_limits_and_options_t; |
---|
| 414 | |
---|
[615d8cc] | 415 | /** |
---|
| 416 | * @brief Default pathconf settings. |
---|
| 417 | * |
---|
| 418 | * Override in a filesystem. |
---|
[29e92b0] | 419 | */ |
---|
| 420 | extern const rtems_filesystem_limits_and_options_t rtems_filesystem_default_pathconf; |
---|
| 421 | |
---|
[615d8cc] | 422 | /** |
---|
| 423 | * @brief Mount table entry. |
---|
[07a3253d] | 424 | */ |
---|
[657e1bf6] | 425 | struct rtems_filesystem_mount_table_entry_tt { |
---|
[72d2ec4d] | 426 | rtems_chain_node Node; |
---|
[07a3253d] | 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; |
---|
[b06e68ef] | 433 | |
---|
[29e92b0] | 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 | |
---|
[07a3253d] | 444 | /* |
---|
| 445 | * When someone adds a mounted filesystem on a real device, |
---|
| 446 | * this will need to be used. |
---|
| 447 | * |
---|
[7baa484] | 448 | * The lower layers can manage how this is managed. Leave as a |
---|
| 449 | * string. |
---|
[07a3253d] | 450 | */ |
---|
| 451 | char *dev; |
---|
| 452 | }; |
---|
[b06e68ef] | 453 | |
---|
[29e92b0] | 454 | /** |
---|
[615d8cc] | 455 | * @brief The pathconf setting for a file system. |
---|
[29e92b0] | 456 | */ |
---|
| 457 | #define rtems_filesystem_pathconf(_mte) ((_mte)->pathconf_limits_and_options) |
---|
| 458 | |
---|
| 459 | /** |
---|
[615d8cc] | 460 | * @brief The type of file system. Its name. |
---|
[29e92b0] | 461 | */ |
---|
| 462 | #define rtems_filesystem_type(_mte) ((_mte)->type) |
---|
| 463 | |
---|
| 464 | /** |
---|
[615d8cc] | 465 | * @brief The mount point of a file system. |
---|
[29e92b0] | 466 | */ |
---|
| 467 | #define rtems_filesystem_mount_point(_mte) ((_mte)->target) |
---|
| 468 | |
---|
| 469 | /** |
---|
[615d8cc] | 470 | * @brief The device entry of a file system. |
---|
[29e92b0] | 471 | */ |
---|
| 472 | #define rtems_filesystem_mount_device(_mte) ((_mte)->dev) |
---|
| 473 | |
---|
[615d8cc] | 474 | /** |
---|
| 475 | * @brief File systems options. |
---|
[07a3253d] | 476 | */ |
---|
[aa61d53] | 477 | typedef enum { |
---|
[07a3253d] | 478 | RTEMS_FILESYSTEM_READ_ONLY, |
---|
[4ecc390] | 479 | RTEMS_FILESYSTEM_READ_WRITE, |
---|
[07a3253d] | 480 | RTEMS_FILESYSTEM_BAD_OPTIONS |
---|
| 481 | } rtems_filesystem_options_t; |
---|
| 482 | |
---|
[615d8cc] | 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) |
---|
[07a3253d] | 490 | */ |
---|
| 491 | struct rtems_libio_tt { |
---|
[aa61d53] | 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 */ |
---|
[07a3253d] | 502 | }; |
---|
| 503 | |
---|
[615d8cc] | 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. |
---|
[b06e68ef] | 509 | */ |
---|
| 510 | typedef struct { |
---|
[aa61d53] | 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; |
---|
[b06e68ef] | 517 | } rtems_libio_rw_args_t; |
---|
| 518 | |
---|
[615d8cc] | 519 | /** |
---|
| 520 | * @brief Parameter block for open/close. |
---|
[b06e68ef] | 521 | */ |
---|
| 522 | typedef struct { |
---|
[aa61d53] | 523 | rtems_libio_t *iop; |
---|
| 524 | uint32_t flags; |
---|
| 525 | uint32_t mode; |
---|
[b06e68ef] | 526 | } rtems_libio_open_close_args_t; |
---|
| 527 | |
---|
[615d8cc] | 528 | /** |
---|
| 529 | * @brief Parameter block for ioctl. |
---|
[b06e68ef] | 530 | */ |
---|
| 531 | typedef struct { |
---|
[aa61d53] | 532 | rtems_libio_t *iop; |
---|
| 533 | uint32_t command; |
---|
| 534 | void *buffer; |
---|
| 535 | uint32_t ioctl_return; |
---|
[b06e68ef] | 536 | } rtems_libio_ioctl_args_t; |
---|
| 537 | |
---|
[615d8cc] | 538 | /** |
---|
| 539 | * @name Flag Values |
---|
| 540 | * |
---|
| 541 | * @{ |
---|
[b06e68ef] | 542 | */ |
---|
[615d8cc] | 543 | |
---|
[b06e68ef] | 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 */ |
---|
[07a3253d] | 550 | #define LIBIO_FLAGS_CLOSE_ON_EXEC 0x0800 /* close on process exec() */ |
---|
[b06e68ef] | 551 | #define LIBIO_FLAGS_READ_WRITE (LIBIO_FLAGS_READ | LIBIO_FLAGS_WRITE) |
---|
| 552 | |
---|
[615d8cc] | 553 | /** @} */ |
---|
| 554 | |
---|
[07a3253d] | 555 | void rtems_libio_init(void); |
---|
[b06e68ef] | 556 | |
---|
[615d8cc] | 557 | /** |
---|
| 558 | * @name External I/O Handlers |
---|
| 559 | * |
---|
| 560 | * @{ |
---|
[e2d79559] | 561 | */ |
---|
[07a3253d] | 562 | |
---|
| 563 | typedef int (*rtems_libio_open_t)( |
---|
| 564 | const char *pathname, |
---|
[83c5fc1] | 565 | uint32_t flag, |
---|
| 566 | uint32_t mode |
---|
[07a3253d] | 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, |
---|
[83c5fc1] | 576 | uint32_t count |
---|
[07a3253d] | 577 | ); |
---|
| 578 | |
---|
| 579 | typedef int (*rtems_libio_write_t)( |
---|
| 580 | int fd, |
---|
| 581 | const void *buffer, |
---|
[83c5fc1] | 582 | uint32_t count |
---|
[07a3253d] | 583 | ); |
---|
| 584 | |
---|
| 585 | typedef int (*rtems_libio_ioctl_t)( |
---|
| 586 | int fd, |
---|
[83c5fc1] | 587 | uint32_t command, |
---|
[07a3253d] | 588 | void *buffer |
---|
| 589 | ); |
---|
| 590 | |
---|
[07d6fd5] | 591 | typedef rtems_off64_t (*rtems_libio_lseek_t)( |
---|
| 592 | int fd, |
---|
| 593 | rtems_off64_t offset, |
---|
| 594 | int whence |
---|
[07a3253d] | 595 | ); |
---|
| 596 | |
---|
[615d8cc] | 597 | /** @} */ |
---|
| 598 | |
---|
| 599 | /** |
---|
| 600 | * @name Permission Macros |
---|
| 601 | * |
---|
| 602 | * @{ |
---|
| 603 | */ |
---|
| 604 | |
---|
[07a3253d] | 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 | |
---|
[615d8cc] | 617 | /** @} */ |
---|
[7e476f0] | 618 | |
---|
[0b178f04] | 619 | union __rtems_dev_t { |
---|
[7e476f0] | 620 | dev_t device; |
---|
| 621 | struct { |
---|
| 622 | rtems_device_major_number major; |
---|
| 623 | rtems_device_minor_number minor; |
---|
| 624 | } __overlay; |
---|
| 625 | }; |
---|
| 626 | |
---|
[50f32b11] | 627 | static inline dev_t rtems_filesystem_make_dev_t( |
---|
| 628 | rtems_device_major_number _major, |
---|
[7e476f0] | 629 | rtems_device_minor_number _minor |
---|
| 630 | ) |
---|
| 631 | { |
---|
[0b178f04] | 632 | union __rtems_dev_t temp; |
---|
[7e476f0] | 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 | { |
---|
[0b178f04] | 643 | union __rtems_dev_t temp; |
---|
[7e476f0] | 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 | { |
---|
[0b178f04] | 654 | union __rtems_dev_t temp; |
---|
[7e476f0] | 655 | |
---|
| 656 | temp.device = device; |
---|
| 657 | return temp.__overlay.minor; |
---|
| 658 | } |
---|
| 659 | |
---|
[07a3253d] | 660 | #define rtems_filesystem_split_dev_t( _dev, _major, _minor ) \ |
---|
| 661 | do { \ |
---|
[dd19c0b] | 662 | (_major) = rtems_filesystem_dev_major_t ( _dev ); \ |
---|
| 663 | (_minor) = rtems_filesystem_dev_minor_t( _dev ); \ |
---|
[07a3253d] | 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 | |
---|
[3d3a18e6] | 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 | |
---|
[07a3253d] | 689 | /* |
---|
| 690 | * Prototypes for filesystem |
---|
| 691 | */ |
---|
| 692 | |
---|
| 693 | void rtems_filesystem_initialize( void ); |
---|
| 694 | |
---|
[615d8cc] | 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 | |
---|
[3d3a18e6] | 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 | |
---|
[ae35953d] | 726 | /* |
---|
[615d8cc] | 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. |
---|
[3d3a18e6] | 758 | * @retval -1 An error occured. The @c errno indicates the error. |
---|
[615d8cc] | 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 | * @{ |
---|
[161e1b3f] | 772 | */ |
---|
[07a3253d] | 773 | |
---|
[161e1b3f] | 774 | typedef struct rtems_termios_callbacks { |
---|
[07a3253d] | 775 | int (*firstOpen)(int major, int minor, void *arg); |
---|
| 776 | int (*lastClose)(int major, int minor, void *arg); |
---|
| 777 | int (*pollRead)(int minor); |
---|
[b2cc165] | 778 | ssize_t (*write)(int minor, const char *buf, size_t len); |
---|
[07a3253d] | 779 | int (*setAttributes)(int minor, const struct termios *t); |
---|
| 780 | int (*stopRemoteTx)(int minor); |
---|
| 781 | int (*startRemoteTx)(int minor); |
---|
| 782 | int outputUsesInterrupts; |
---|
[161e1b3f] | 783 | } rtems_termios_callbacks; |
---|
| 784 | |
---|
[ae35953d] | 785 | void rtems_termios_initialize (void); |
---|
[07a3253d] | 786 | |
---|
[1f5d2ba] | 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 | |
---|
[ae35953d] | 798 | rtems_status_code rtems_termios_open ( |
---|
[161e1b3f] | 799 | rtems_device_major_number major, |
---|
| 800 | rtems_device_minor_number minor, |
---|
| 801 | void *arg, |
---|
| 802 | const rtems_termios_callbacks *callbacks |
---|
[07a3253d] | 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 | |
---|
[615d8cc] | 832 | /** @} */ |
---|
[d40da79b] | 833 | |
---|
[80c2966] | 834 | #ifdef __cplusplus |
---|
| 835 | } |
---|
| 836 | #endif |
---|
| 837 | |
---|
[b06e68ef] | 838 | #endif /* _RTEMS_LIBIO_H */ |
---|