[4d3017a] | 1 | /** |
---|
| 2 | * @file rtems/libio.h |
---|
| 3 | */ |
---|
| 4 | |
---|
[b06e68ef] | 5 | /* |
---|
[07a3253d] | 6 | * System call and file system interface definition |
---|
[b06e68ef] | 7 | * |
---|
[07a3253d] | 8 | * General purpose communication channel for RTEMS to allow UNIX/POSIX |
---|
| 9 | * system call behavior under RTEMS. Initially this supported only |
---|
| 10 | * IO to devices but has since been enhanced to support networking |
---|
| 11 | * and support for mounted file systems. |
---|
| 12 | * |
---|
[08311cc3] | 13 | * COPYRIGHT (c) 1989-1999. |
---|
[07a3253d] | 14 | * On-Line Applications Research Corporation (OAR). |
---|
| 15 | * |
---|
| 16 | * The license and distribution terms for this file may be |
---|
| 17 | * found in the file LICENSE in this distribution or at |
---|
[0eae36c7] | 18 | * http://www.rtems.com/license/LICENSE. |
---|
[b06e68ef] | 19 | * |
---|
| 20 | * $Id$ |
---|
| 21 | */ |
---|
| 22 | |
---|
[7945944] | 23 | #ifndef _RTEMS_RTEMS_LIBIO_H |
---|
| 24 | #define _RTEMS_RTEMS_LIBIO_H |
---|
[b06e68ef] | 25 | |
---|
[2fe47ff] | 26 | #include <rtems.h> |
---|
[7a3878b] | 27 | #include <sys/types.h> |
---|
[dcec5a4] | 28 | #include <sys/stat.h> |
---|
[9b05600] | 29 | #include <sys/ioctl.h> |
---|
[dcec5a4] | 30 | |
---|
[07a3253d] | 31 | /* |
---|
| 32 | * Define data types which must be constructed using forward references. |
---|
| 33 | */ |
---|
| 34 | |
---|
[d09ad1f0] | 35 | #include <rtems/fs.h> |
---|
[07a3253d] | 36 | |
---|
[80c2966] | 37 | #ifdef __cplusplus |
---|
| 38 | extern "C" { |
---|
| 39 | #endif |
---|
| 40 | |
---|
[07a3253d] | 41 | /* |
---|
| 42 | * Valid RTEMS file types. |
---|
| 43 | */ |
---|
[a1f1011] | 44 | |
---|
| 45 | #define RTEMS_FILESYSTEM_DIRECTORY 1 |
---|
| 46 | #define RTEMS_FILESYSTEM_DEVICE 2 |
---|
| 47 | #define RTEMS_FILESYSTEM_HARD_LINK 3 |
---|
| 48 | #define RTEMS_FILESYSTEM_SYM_LINK 4 |
---|
| 49 | #define RTEMS_FILESYSTEM_MEMORY_FILE 5 |
---|
| 50 | typedef int rtems_filesystem_node_types_t; |
---|
[07a3253d] | 51 | |
---|
| 52 | /* |
---|
| 53 | * File Handler Operations Table |
---|
| 54 | */ |
---|
| 55 | |
---|
| 56 | typedef int (*rtems_filesystem_open_t)( |
---|
| 57 | rtems_libio_t *iop, |
---|
| 58 | const char *pathname, |
---|
[83c5fc1] | 59 | uint32_t flag, |
---|
| 60 | uint32_t mode |
---|
[07a3253d] | 61 | ); |
---|
| 62 | |
---|
| 63 | typedef int (*rtems_filesystem_close_t)( |
---|
| 64 | rtems_libio_t *iop |
---|
| 65 | ); |
---|
| 66 | |
---|
[5d0b2f7] | 67 | typedef ssize_t (*rtems_filesystem_read_t)( |
---|
[07a3253d] | 68 | rtems_libio_t *iop, |
---|
| 69 | void *buffer, |
---|
[7192476f] | 70 | size_t count |
---|
[07a3253d] | 71 | ); |
---|
| 72 | |
---|
[5d0b2f7] | 73 | typedef ssize_t (*rtems_filesystem_write_t)( |
---|
[07a3253d] | 74 | rtems_libio_t *iop, |
---|
| 75 | const void *buffer, |
---|
[7192476f] | 76 | size_t count |
---|
[07a3253d] | 77 | ); |
---|
| 78 | |
---|
| 79 | typedef int (*rtems_filesystem_ioctl_t)( |
---|
| 80 | rtems_libio_t *iop, |
---|
[83c5fc1] | 81 | uint32_t command, |
---|
[07a3253d] | 82 | void *buffer |
---|
| 83 | ); |
---|
| 84 | |
---|
| 85 | typedef int (*rtems_filesystem_lseek_t)( |
---|
| 86 | rtems_libio_t *iop, |
---|
| 87 | off_t length, |
---|
| 88 | int whence |
---|
| 89 | ); |
---|
| 90 | |
---|
| 91 | typedef int (*rtems_filesystem_fstat_t)( |
---|
| 92 | rtems_filesystem_location_info_t *loc, |
---|
| 93 | struct stat *buf |
---|
| 94 | ); |
---|
| 95 | |
---|
| 96 | typedef int (*rtems_filesystem_fchmod_t)( |
---|
| 97 | rtems_filesystem_location_info_t *loc, |
---|
| 98 | mode_t mode |
---|
| 99 | ); |
---|
| 100 | |
---|
| 101 | typedef int (*rtems_filesystem_ftruncate_t)( |
---|
| 102 | rtems_libio_t *iop, |
---|
| 103 | off_t length |
---|
| 104 | ); |
---|
| 105 | |
---|
| 106 | typedef int (*rtems_filesystem_fpathconf_t)( |
---|
| 107 | rtems_libio_t *iop, |
---|
| 108 | int name |
---|
| 109 | ); |
---|
| 110 | |
---|
| 111 | typedef int (*rtems_filesystem_fsync_t)( |
---|
| 112 | rtems_libio_t *iop |
---|
| 113 | ); |
---|
| 114 | |
---|
| 115 | typedef int (*rtems_filesystem_fdatasync_t)( |
---|
| 116 | rtems_libio_t *iop |
---|
| 117 | ); |
---|
| 118 | |
---|
[af020036] | 119 | typedef int (*rtems_filesystem_fcntl_t)( |
---|
[e2116f9] | 120 | int cmd, |
---|
[af020036] | 121 | rtems_libio_t *iop |
---|
| 122 | ); |
---|
| 123 | |
---|
[4a07d2b] | 124 | typedef int (*rtems_filesystem_rmnod_t)( |
---|
| 125 | rtems_filesystem_location_info_t *pathloc /* IN */ |
---|
| 126 | ); |
---|
| 127 | |
---|
[d09ad1f0] | 128 | struct _rtems_filesystem_file_handlers_r { |
---|
[9c3fa30] | 129 | rtems_filesystem_open_t open_h; |
---|
| 130 | rtems_filesystem_close_t close_h; |
---|
| 131 | rtems_filesystem_read_t read_h; |
---|
| 132 | rtems_filesystem_write_t write_h; |
---|
| 133 | rtems_filesystem_ioctl_t ioctl_h; |
---|
| 134 | rtems_filesystem_lseek_t lseek_h; |
---|
| 135 | rtems_filesystem_fstat_t fstat_h; |
---|
| 136 | rtems_filesystem_fchmod_t fchmod_h; |
---|
| 137 | rtems_filesystem_ftruncate_t ftruncate_h; |
---|
| 138 | rtems_filesystem_fpathconf_t fpathconf_h; |
---|
| 139 | rtems_filesystem_fsync_t fsync_h; |
---|
| 140 | rtems_filesystem_fdatasync_t fdatasync_h; |
---|
| 141 | rtems_filesystem_fcntl_t fcntl_h; |
---|
| 142 | rtems_filesystem_rmnod_t rmnod_h; |
---|
[d09ad1f0] | 143 | }; |
---|
[07a3253d] | 144 | |
---|
| 145 | /* |
---|
| 146 | * File System Operations Table |
---|
| 147 | */ |
---|
| 148 | |
---|
| 149 | /* |
---|
| 150 | * XXX |
---|
[50f32b11] | 151 | * This routine does not allocate any space and rtems_filesystem_freenode_t |
---|
[07a3253d] | 152 | * is not called by the generic after calling this routine. |
---|
[50f32b11] | 153 | * ie. node_access does not have to contain valid data when the |
---|
[07a3253d] | 154 | * routine returns. |
---|
| 155 | */ |
---|
| 156 | |
---|
| 157 | typedef int (*rtems_filesystem_mknod_t)( |
---|
| 158 | const char *path, /* IN */ |
---|
| 159 | mode_t mode, /* IN */ |
---|
| 160 | dev_t dev, /* IN */ |
---|
| 161 | rtems_filesystem_location_info_t *pathloc /* IN/OUT */ |
---|
| 162 | ); |
---|
| 163 | |
---|
| 164 | /* |
---|
| 165 | * rtems_filesystem_freenode_t must be called by the generic after |
---|
| 166 | * calling this routine |
---|
| 167 | */ |
---|
| 168 | |
---|
| 169 | typedef int (*rtems_filesystem_evalpath_t)( |
---|
| 170 | const char *pathname, /* IN */ |
---|
| 171 | int flags, /* IN */ |
---|
| 172 | rtems_filesystem_location_info_t *pathloc /* IN/OUT */ |
---|
| 173 | ); |
---|
| 174 | |
---|
| 175 | typedef int (*rtems_filesystem_evalmake_t)( |
---|
| 176 | const char *path, /* IN */ |
---|
| 177 | rtems_filesystem_location_info_t *pathloc, /* IN/OUT */ |
---|
| 178 | const char **name /* OUT */ |
---|
| 179 | ); |
---|
| 180 | |
---|
| 181 | typedef int (*rtems_filesystem_link_t)( |
---|
| 182 | rtems_filesystem_location_info_t *to_loc, /* IN */ |
---|
| 183 | rtems_filesystem_location_info_t *parent_loc, /* IN */ |
---|
| 184 | const char *name /* IN */ |
---|
| 185 | ); |
---|
| 186 | |
---|
| 187 | typedef int (*rtems_filesystem_unlink_t)( |
---|
| 188 | rtems_filesystem_location_info_t *pathloc /* IN */ |
---|
| 189 | ); |
---|
| 190 | |
---|
| 191 | typedef int (*rtems_filesystem_chown_t)( |
---|
| 192 | rtems_filesystem_location_info_t *pathloc, /* IN */ |
---|
| 193 | uid_t owner, /* IN */ |
---|
| 194 | gid_t group /* IN */ |
---|
| 195 | ); |
---|
| 196 | |
---|
| 197 | typedef int (*rtems_filesystem_freenode_t)( |
---|
| 198 | rtems_filesystem_location_info_t *pathloc /* IN */ |
---|
| 199 | ); |
---|
| 200 | |
---|
| 201 | typedef int (* rtems_filesystem_mount_t ) ( |
---|
| 202 | rtems_filesystem_mount_table_entry_t *mt_entry /* in */ |
---|
| 203 | ); |
---|
| 204 | |
---|
| 205 | typedef int (* rtems_filesystem_fsmount_me_t )( |
---|
| 206 | rtems_filesystem_mount_table_entry_t *mt_entry |
---|
| 207 | ); |
---|
| 208 | |
---|
| 209 | typedef int (* rtems_filesystem_unmount_t ) ( |
---|
| 210 | rtems_filesystem_mount_table_entry_t *mt_entry /* in */ |
---|
| 211 | ); |
---|
| 212 | |
---|
| 213 | typedef int (* rtems_filesystem_fsunmount_me_t ) ( |
---|
| 214 | rtems_filesystem_mount_table_entry_t *mt_entry /* in */ |
---|
| 215 | ); |
---|
| 216 | |
---|
| 217 | typedef rtems_filesystem_node_types_t (* rtems_filesystem_node_type_t) ( |
---|
| 218 | rtems_filesystem_location_info_t *pathloc /* in */ |
---|
| 219 | ); |
---|
| 220 | |
---|
| 221 | typedef int (* rtems_filesystem_utime_t)( |
---|
| 222 | rtems_filesystem_location_info_t *pathloc, /* IN */ |
---|
| 223 | time_t actime, /* IN */ |
---|
| 224 | time_t modtime /* IN */ |
---|
| 225 | ); |
---|
| 226 | |
---|
| 227 | typedef int (*rtems_filesystem_evaluate_link_t)( |
---|
| 228 | rtems_filesystem_location_info_t *pathloc, /* IN/OUT */ |
---|
| 229 | int flags /* IN */ |
---|
| 230 | ); |
---|
| 231 | |
---|
| 232 | typedef int (*rtems_filesystem_symlink_t)( |
---|
| 233 | rtems_filesystem_location_info_t *loc, /* IN */ |
---|
| 234 | const char *link_name, /* IN */ |
---|
| 235 | const char *node_name |
---|
| 236 | ); |
---|
| 237 | |
---|
| 238 | typedef int (*rtems_filesystem_readlink_t)( |
---|
[50f32b11] | 239 | rtems_filesystem_location_info_t *loc, /* IN */ |
---|
| 240 | char *buf, /* OUT */ |
---|
| 241 | size_t bufsize |
---|
[07a3253d] | 242 | ); |
---|
| 243 | |
---|
| 244 | /* |
---|
| 245 | * operations table that must be defined for every file system. |
---|
| 246 | */ |
---|
| 247 | |
---|
| 248 | /* |
---|
| 249 | * File system types |
---|
| 250 | */ |
---|
[d09ad1f0] | 251 | struct _rtems_filesystem_operations_table { |
---|
[9c3fa30] | 252 | rtems_filesystem_evalpath_t evalpath_h; |
---|
| 253 | rtems_filesystem_evalmake_t evalformake_h; |
---|
| 254 | rtems_filesystem_link_t link_h; |
---|
| 255 | rtems_filesystem_unlink_t unlink_h; |
---|
| 256 | rtems_filesystem_node_type_t node_type_h; |
---|
| 257 | rtems_filesystem_mknod_t mknod_h; |
---|
| 258 | rtems_filesystem_chown_t chown_h; |
---|
| 259 | rtems_filesystem_freenode_t freenod_h; |
---|
| 260 | rtems_filesystem_mount_t mount_h; |
---|
| 261 | rtems_filesystem_fsmount_me_t fsmount_me_h; |
---|
| 262 | rtems_filesystem_unmount_t unmount_h; |
---|
| 263 | rtems_filesystem_fsunmount_me_t fsunmount_me_h; |
---|
| 264 | rtems_filesystem_utime_t utime_h; |
---|
| 265 | rtems_filesystem_evaluate_link_t eval_link_h; |
---|
| 266 | rtems_filesystem_symlink_t symlink_h; |
---|
| 267 | rtems_filesystem_readlink_t readlink_h; |
---|
[d09ad1f0] | 268 | }; |
---|
| 269 | |
---|
| 270 | #if 0 |
---|
| 271 | /* Now in exec/include/rtems/fs.h */ |
---|
[07a3253d] | 272 | |
---|
[b06e68ef] | 273 | /* |
---|
[07a3253d] | 274 | * Structure used to determine a location/filesystem in the tree. |
---|
| 275 | */ |
---|
| 276 | |
---|
| 277 | struct rtems_filesystem_location_info_tt |
---|
| 278 | { |
---|
| 279 | void *node_access; |
---|
| 280 | rtems_filesystem_file_handlers_r *handlers; |
---|
| 281 | rtems_filesystem_operations_table *ops; |
---|
| 282 | rtems_filesystem_mount_table_entry_t *mt_entry; |
---|
| 283 | }; |
---|
[d09ad1f0] | 284 | #endif |
---|
[07a3253d] | 285 | |
---|
| 286 | /* |
---|
| 287 | * Structure used to contain file system specific information which |
---|
| 288 | * is required to support fpathconf(). |
---|
[b06e68ef] | 289 | */ |
---|
| 290 | |
---|
| 291 | typedef struct { |
---|
[07a3253d] | 292 | int link_max; |
---|
| 293 | int max_canon; |
---|
| 294 | int max_input; |
---|
| 295 | int name_max; |
---|
| 296 | int path_max; |
---|
| 297 | int pipe_buf; |
---|
| 298 | int posix_async_io; |
---|
| 299 | int posix_chown_restrictions; |
---|
| 300 | int posix_no_trunc; |
---|
| 301 | int posix_prio_io; |
---|
| 302 | int posix_sync_io; |
---|
| 303 | int posix_vdisable; |
---|
| 304 | } rtems_filesystem_limits_and_options_t; |
---|
| 305 | |
---|
| 306 | /* |
---|
| 307 | * Structure for a mount table entry. |
---|
| 308 | */ |
---|
| 309 | |
---|
[657e1bf6] | 310 | struct rtems_filesystem_mount_table_entry_tt { |
---|
[07a3253d] | 311 | Chain_Node Node; |
---|
| 312 | rtems_filesystem_location_info_t mt_point_node; |
---|
| 313 | rtems_filesystem_location_info_t mt_fs_root; |
---|
| 314 | int options; |
---|
| 315 | void *fs_info; |
---|
| 316 | |
---|
| 317 | rtems_filesystem_limits_and_options_t pathconf_limits_and_options; |
---|
[b06e68ef] | 318 | |
---|
[07a3253d] | 319 | /* |
---|
| 320 | * When someone adds a mounted filesystem on a real device, |
---|
| 321 | * this will need to be used. |
---|
| 322 | * |
---|
| 323 | * The best option long term for this is probably an open file descriptor. |
---|
| 324 | */ |
---|
| 325 | char *dev; |
---|
| 326 | }; |
---|
[b06e68ef] | 327 | |
---|
| 328 | /* |
---|
[07a3253d] | 329 | * Valid RTEMS file systems options |
---|
| 330 | */ |
---|
| 331 | |
---|
| 332 | typedef enum |
---|
| 333 | { |
---|
| 334 | RTEMS_FILESYSTEM_READ_ONLY, |
---|
[4ecc390] | 335 | RTEMS_FILESYSTEM_READ_WRITE, |
---|
[07a3253d] | 336 | RTEMS_FILESYSTEM_BAD_OPTIONS |
---|
| 337 | } rtems_filesystem_options_t; |
---|
| 338 | |
---|
| 339 | |
---|
| 340 | /* |
---|
| 341 | * An open file data structure, indexed by 'fd' |
---|
| 342 | * TODO: |
---|
| 343 | * should really have a separate per/file data structure that this |
---|
| 344 | * points to (eg: size, offset, driver, pathname should be in that) |
---|
| 345 | */ |
---|
| 346 | |
---|
| 347 | struct rtems_libio_tt { |
---|
| 348 | rtems_driver_name_t *driver; |
---|
| 349 | off_t size; /* size of file */ |
---|
| 350 | off_t offset; /* current offset into file */ |
---|
[83c5fc1] | 351 | uint32_t flags; |
---|
[07a3253d] | 352 | rtems_filesystem_location_info_t pathinfo; |
---|
[a29d2e7] | 353 | rtems_id sem; |
---|
[83c5fc1] | 354 | uint32_t data0; /* private to "driver" */ |
---|
[07a3253d] | 355 | void *data1; /* ... */ |
---|
| 356 | void *file_info; /* used by file handlers */ |
---|
| 357 | rtems_filesystem_file_handlers_r *handlers; /* type specific handlers */ |
---|
| 358 | }; |
---|
| 359 | |
---|
| 360 | /* |
---|
| 361 | * param block for read/write |
---|
| 362 | * Note: it must include 'offset' instead of using iop's offset since |
---|
| 363 | * we can have multiple outstanding i/o's on a device. |
---|
[b06e68ef] | 364 | */ |
---|
| 365 | |
---|
| 366 | typedef struct { |
---|
| 367 | rtems_libio_t *iop; |
---|
[07a3253d] | 368 | off_t offset; |
---|
[a29d2e7] | 369 | char *buffer; |
---|
[83c5fc1] | 370 | uint32_t count; |
---|
| 371 | uint32_t flags; |
---|
| 372 | uint32_t bytes_moved; |
---|
[b06e68ef] | 373 | } rtems_libio_rw_args_t; |
---|
| 374 | |
---|
| 375 | /* |
---|
[07a3253d] | 376 | * param block for open/close |
---|
[b06e68ef] | 377 | */ |
---|
| 378 | |
---|
| 379 | typedef struct { |
---|
| 380 | rtems_libio_t *iop; |
---|
[83c5fc1] | 381 | uint32_t flags; |
---|
| 382 | uint32_t mode; |
---|
[b06e68ef] | 383 | } rtems_libio_open_close_args_t; |
---|
| 384 | |
---|
| 385 | /* |
---|
[07a3253d] | 386 | * param block for ioctl |
---|
[b06e68ef] | 387 | */ |
---|
| 388 | |
---|
| 389 | typedef struct { |
---|
| 390 | rtems_libio_t *iop; |
---|
[83c5fc1] | 391 | uint32_t command; |
---|
[b06e68ef] | 392 | void *buffer; |
---|
[83c5fc1] | 393 | uint32_t ioctl_return; |
---|
[b06e68ef] | 394 | } rtems_libio_ioctl_args_t; |
---|
| 395 | |
---|
| 396 | /* |
---|
[07a3253d] | 397 | * Values for 'flag' |
---|
[b06e68ef] | 398 | */ |
---|
| 399 | |
---|
| 400 | #define LIBIO_FLAGS_NO_DELAY 0x0001 /* return immediately if no data */ |
---|
| 401 | #define LIBIO_FLAGS_READ 0x0002 /* reading */ |
---|
| 402 | #define LIBIO_FLAGS_WRITE 0x0004 /* writing */ |
---|
| 403 | #define LIBIO_FLAGS_OPEN 0x0100 /* device is open */ |
---|
| 404 | #define LIBIO_FLAGS_APPEND 0x0200 /* all writes append */ |
---|
| 405 | #define LIBIO_FLAGS_CREATE 0x0400 /* create file */ |
---|
[07a3253d] | 406 | #define LIBIO_FLAGS_CLOSE_ON_EXEC 0x0800 /* close on process exec() */ |
---|
[b06e68ef] | 407 | #define LIBIO_FLAGS_READ_WRITE (LIBIO_FLAGS_READ | LIBIO_FLAGS_WRITE) |
---|
| 408 | |
---|
[07a3253d] | 409 | void rtems_libio_init(void); |
---|
[b06e68ef] | 410 | |
---|
[e2d79559] | 411 | /* |
---|
[07a3253d] | 412 | * External I/O handlers |
---|
[e2d79559] | 413 | */ |
---|
[07a3253d] | 414 | |
---|
| 415 | typedef int (*rtems_libio_open_t)( |
---|
| 416 | const char *pathname, |
---|
[83c5fc1] | 417 | uint32_t flag, |
---|
| 418 | uint32_t mode |
---|
[07a3253d] | 419 | ); |
---|
| 420 | |
---|
| 421 | typedef int (*rtems_libio_close_t)( |
---|
| 422 | int fd |
---|
| 423 | ); |
---|
| 424 | |
---|
| 425 | typedef int (*rtems_libio_read_t)( |
---|
| 426 | int fd, |
---|
| 427 | void *buffer, |
---|
[83c5fc1] | 428 | uint32_t count |
---|
[07a3253d] | 429 | ); |
---|
| 430 | |
---|
| 431 | typedef int (*rtems_libio_write_t)( |
---|
| 432 | int fd, |
---|
| 433 | const void *buffer, |
---|
[83c5fc1] | 434 | uint32_t count |
---|
[07a3253d] | 435 | ); |
---|
| 436 | |
---|
| 437 | typedef int (*rtems_libio_ioctl_t)( |
---|
| 438 | int fd, |
---|
[83c5fc1] | 439 | uint32_t command, |
---|
[07a3253d] | 440 | void *buffer |
---|
| 441 | ); |
---|
| 442 | |
---|
| 443 | typedef int (*rtems_libio_lseek_t)( |
---|
| 444 | int fd, |
---|
| 445 | off_t offset, |
---|
| 446 | int whence |
---|
| 447 | ); |
---|
| 448 | |
---|
| 449 | /* |
---|
| 450 | * The following macros are used to build up the permissions sets |
---|
| 451 | * used to check permissions. These are similar in style to the |
---|
| 452 | * mode_t bits and should stay compatible with them. |
---|
| 453 | */ |
---|
| 454 | |
---|
| 455 | #define RTEMS_LIBIO_PERMS_READ S_IROTH |
---|
| 456 | #define RTEMS_LIBIO_PERMS_WRITE S_IWOTH |
---|
| 457 | #define RTEMS_LIBIO_PERMS_RDWR (S_IROTH|S_IWOTH) |
---|
| 458 | #define RTEMS_LIBIO_PERMS_EXEC S_IXOTH |
---|
| 459 | #define RTEMS_LIBIO_PERMS_SEARCH RTEMS_LIBIO_PERMS_EXEC |
---|
| 460 | #define RTEMS_LIBIO_PERMS_RWX S_IRWXO |
---|
| 461 | |
---|
| 462 | /* |
---|
| 463 | * Macros |
---|
| 464 | */ |
---|
| 465 | |
---|
[7e476f0] | 466 | #if 0 |
---|
[07a3253d] | 467 | #define rtems_filesystem_make_dev_t( _major, _minor ) \ |
---|
| 468 | ((((dev_t)(_major)) << 32) | (dev_t)(_minor)) |
---|
| 469 | |
---|
[dd19c0b] | 470 | #define rtems_filesystem_dev_major_t( _dev ) \ |
---|
| 471 | (rtems_device_major_number) ((_dev) >> 32) |
---|
| 472 | |
---|
| 473 | #define rtems_filesystem_dev_minor_t( _dev ) \ |
---|
| 474 | (rtems_device_minor_number) ((_dev) & 0xFFFFFFFF) |
---|
[7e476f0] | 475 | #else |
---|
| 476 | |
---|
| 477 | #include <unistd.h> |
---|
| 478 | |
---|
[0b178f04] | 479 | union __rtems_dev_t { |
---|
[7e476f0] | 480 | dev_t device; |
---|
| 481 | struct { |
---|
| 482 | rtems_device_major_number major; |
---|
| 483 | rtems_device_minor_number minor; |
---|
| 484 | } __overlay; |
---|
| 485 | }; |
---|
| 486 | |
---|
[50f32b11] | 487 | static inline dev_t rtems_filesystem_make_dev_t( |
---|
| 488 | rtems_device_major_number _major, |
---|
[7e476f0] | 489 | rtems_device_minor_number _minor |
---|
| 490 | ) |
---|
| 491 | { |
---|
[0b178f04] | 492 | union __rtems_dev_t temp; |
---|
[7e476f0] | 493 | |
---|
| 494 | temp.__overlay.major = _major; |
---|
| 495 | temp.__overlay.minor = _minor; |
---|
| 496 | return temp.device; |
---|
| 497 | } |
---|
| 498 | |
---|
| 499 | static inline rtems_device_major_number rtems_filesystem_dev_major_t( |
---|
| 500 | dev_t device |
---|
| 501 | ) |
---|
| 502 | { |
---|
[0b178f04] | 503 | union __rtems_dev_t temp; |
---|
[7e476f0] | 504 | |
---|
| 505 | temp.device = device; |
---|
| 506 | return temp.__overlay.major; |
---|
| 507 | } |
---|
| 508 | |
---|
| 509 | |
---|
| 510 | static inline rtems_device_minor_number rtems_filesystem_dev_minor_t( |
---|
| 511 | dev_t device |
---|
| 512 | ) |
---|
| 513 | { |
---|
[0b178f04] | 514 | union __rtems_dev_t temp; |
---|
[7e476f0] | 515 | |
---|
| 516 | temp.device = device; |
---|
| 517 | return temp.__overlay.minor; |
---|
| 518 | } |
---|
| 519 | |
---|
| 520 | #endif |
---|
[dd19c0b] | 521 | |
---|
[07a3253d] | 522 | #define rtems_filesystem_split_dev_t( _dev, _major, _minor ) \ |
---|
| 523 | do { \ |
---|
[dd19c0b] | 524 | (_major) = rtems_filesystem_dev_major_t ( _dev ); \ |
---|
| 525 | (_minor) = rtems_filesystem_dev_minor_t( _dev ); \ |
---|
[07a3253d] | 526 | } while(0) |
---|
| 527 | |
---|
| 528 | /* |
---|
| 529 | * Verifies that the permission flag is valid. |
---|
| 530 | */ |
---|
| 531 | #define rtems_libio_is_valid_perms( _perm ) \ |
---|
| 532 | (~ ((~RTEMS_LIBIO_PERMS_RWX) & _perm )) |
---|
| 533 | |
---|
| 534 | |
---|
| 535 | /* |
---|
| 536 | * Prototypes for filesystem |
---|
| 537 | */ |
---|
| 538 | |
---|
| 539 | void rtems_filesystem_initialize( void ); |
---|
| 540 | |
---|
| 541 | |
---|
[ae35953d] | 542 | /* |
---|
[161e1b3f] | 543 | * Callbacks from TERMIOS routines to device-dependent code |
---|
| 544 | */ |
---|
[07a3253d] | 545 | |
---|
[161e1b3f] | 546 | #include <termios.h> |
---|
[07a3253d] | 547 | |
---|
[161e1b3f] | 548 | typedef struct rtems_termios_callbacks { |
---|
[07a3253d] | 549 | int (*firstOpen)(int major, int minor, void *arg); |
---|
| 550 | int (*lastClose)(int major, int minor, void *arg); |
---|
| 551 | int (*pollRead)(int minor); |
---|
| 552 | int (*write)(int minor, const char *buf, int len); |
---|
| 553 | int (*setAttributes)(int minor, const struct termios *t); |
---|
| 554 | int (*stopRemoteTx)(int minor); |
---|
| 555 | int (*startRemoteTx)(int minor); |
---|
| 556 | int outputUsesInterrupts; |
---|
[161e1b3f] | 557 | } rtems_termios_callbacks; |
---|
| 558 | |
---|
| 559 | /* |
---|
[07a3253d] | 560 | * Device-independent TERMIOS routines |
---|
[ae35953d] | 561 | */ |
---|
[07a3253d] | 562 | |
---|
[ae35953d] | 563 | void rtems_termios_initialize (void); |
---|
[07a3253d] | 564 | |
---|
[1f5d2ba] | 565 | /* |
---|
| 566 | * CCJ: Change before opening a tty. Newer code from Eric is coming |
---|
| 567 | * so extra work to handle an open tty is not worth it. If the tty |
---|
| 568 | * is open, close then open it again. |
---|
| 569 | */ |
---|
| 570 | rtems_status_code rtems_termios_bufsize ( |
---|
| 571 | int cbufsize, /* cooked buffer size */ |
---|
| 572 | int raw_input, /* raw input buffer size */ |
---|
| 573 | int raw_output /* raw output buffer size */ |
---|
| 574 | ); |
---|
| 575 | |
---|
[ae35953d] | 576 | rtems_status_code rtems_termios_open ( |
---|
[161e1b3f] | 577 | rtems_device_major_number major, |
---|
| 578 | rtems_device_minor_number minor, |
---|
| 579 | void *arg, |
---|
| 580 | const rtems_termios_callbacks *callbacks |
---|
[07a3253d] | 581 | ); |
---|
| 582 | |
---|
| 583 | rtems_status_code rtems_termios_close( |
---|
| 584 | void *arg |
---|
| 585 | ); |
---|
| 586 | |
---|
| 587 | rtems_status_code rtems_termios_read( |
---|
| 588 | void *arg |
---|
| 589 | ); |
---|
| 590 | |
---|
| 591 | rtems_status_code rtems_termios_write( |
---|
| 592 | void *arg |
---|
| 593 | ); |
---|
| 594 | |
---|
| 595 | rtems_status_code rtems_termios_ioctl( |
---|
| 596 | void *arg |
---|
| 597 | ); |
---|
| 598 | |
---|
| 599 | int rtems_termios_enqueue_raw_characters( |
---|
| 600 | void *ttyp, |
---|
| 601 | char *buf, |
---|
| 602 | int len |
---|
| 603 | ); |
---|
| 604 | |
---|
| 605 | int rtems_termios_dequeue_characters( |
---|
| 606 | void *ttyp, |
---|
| 607 | int len |
---|
| 608 | ); |
---|
| 609 | |
---|
[118a812] | 610 | void rtems_termios_reserve_resources( |
---|
| 611 | rtems_configuration_table *configuration, |
---|
[83c5fc1] | 612 | uint32_t number_of_devices |
---|
[118a812] | 613 | ); |
---|
[ae35953d] | 614 | |
---|
[07a3253d] | 615 | int unmount( |
---|
| 616 | const char *mount_path |
---|
| 617 | ); |
---|
| 618 | |
---|
| 619 | int mount( |
---|
| 620 | rtems_filesystem_mount_table_entry_t **mt_entry, |
---|
| 621 | rtems_filesystem_operations_table *fs_ops, |
---|
[937ab62c] | 622 | rtems_filesystem_options_t fsoptions, |
---|
[07a3253d] | 623 | char *device, |
---|
| 624 | char *mount_point |
---|
| 625 | ); |
---|
| 626 | |
---|
[4bde8072] | 627 | /* |
---|
| 628 | * Boot Time Mount Table Structure |
---|
| 629 | */ |
---|
| 630 | |
---|
| 631 | typedef struct { |
---|
| 632 | rtems_filesystem_operations_table *fs_ops; |
---|
| 633 | rtems_filesystem_options_t fsoptions; |
---|
| 634 | char *device; |
---|
| 635 | char *mount_point; |
---|
| 636 | } rtems_filesystem_mount_table_t; |
---|
| 637 | |
---|
| 638 | extern rtems_filesystem_mount_table_t *rtems_filesystem_mount_table; |
---|
| 639 | extern int rtems_filesystem_mount_table_size; |
---|
| 640 | |
---|
[80c2966] | 641 | #ifdef __cplusplus |
---|
| 642 | } |
---|
| 643 | #endif |
---|
| 644 | |
---|
[b06e68ef] | 645 | #endif /* _RTEMS_LIBIO_H */ |
---|