Changeset 07a3253d in rtems
- Timestamp:
- 11/23/98 19:07:58 (24 years ago)
- Branches:
- 4.10, 4.11, 4.8, 4.9, 5, master
- Children:
- d1ee44e
- Parents:
- cd3fb80
- Files:
-
- 248 added
- 7 deleted
- 74 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
c/src/exec/libcsupport/include/rtems/libio.h
rcd3fb80 r07a3253d 1 1 /* 2 * General purpose communication channel for RTEMS to allow UNIX/POSIX 3 * system call behavior on top of RTEMS IO devices. 2 * System call and file system interface definition 4 3 * 5 * TODO 6 * stat(2) 7 * unlink(2) 8 * rename(2) 4 * General purpose communication channel for RTEMS to allow UNIX/POSIX 5 * system call behavior under RTEMS. Initially this supported only 6 * IO to devices but has since been enhanced to support networking 7 * and support for mounted file systems. 8 * 9 * COPYRIGHT (c) 1989-1998. 10 * On-Line Applications Research Corporation (OAR). 11 * Copyright assigned to U.S. Government, 1994. 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.OARcorp.com/rtems/license.html. 9 16 * 10 17 * $Id$ … … 16 23 #include <sys/stat.h> 17 24 18 typedef unsigned32 rtems_libio_offset_t; 19 20 /* 21 * An open file data structure, indexed by 'fd' 22 * TODO: 23 * should really have a separate per/file data structure that this 24 * points to (eg: size, offset, driver, pathname should be in that) 25 */ 26 27 typedef struct { 28 rtems_driver_name_t *driver; 29 rtems_libio_offset_t size; /* size of file */ 30 rtems_libio_offset_t offset; /* current offset into the file */ 31 unsigned32 flags; 32 char *pathname; /* opened pathname */ 33 Objects_Id sem; 34 unsigned32 data0; /* private to "driver" */ 35 void *data1; /* ... */ 36 } rtems_libio_t; 37 38 39 /* 40 * param block for read/write 41 * Note: it must include 'offset' instead of using iop's offset since 42 * we can have multiple outstanding i/o's on a device. 25 /* 26 * Define data types which must be constructed using forward references. 27 */ 28 29 typedef struct rtems_libio_tt rtems_libio_t; 30 31 struct rtems_filesystem_location_info_tt; 32 typedef struct rtems_filesystem_location_info_tt 33 rtems_filesystem_location_info_t; 34 35 struct rtems_filesystem_mount_table_entry_tt; 36 typedef struct rtems_filesystem_mount_table_entry_tt 37 rtems_filesystem_mount_table_entry_t; 38 39 /* 40 * Valid RTEMS file types. 41 */ 42 typedef enum { 43 RTEMS_FILESYSTEM_DIRECTORY, 44 RTEMS_FILESYSTEM_DEVICE, 45 RTEMS_FILESYSTEM_HARD_LINK, 46 RTEMS_FILESYSTEM_SYM_LINK, 47 RTEMS_FILESYSTEM_MEMORY_FILE 48 } rtems_filesystem_node_types_t; 49 50 /* 51 * File Handler Operations Table 52 */ 53 54 typedef int (*rtems_filesystem_open_t)( 55 rtems_libio_t *iop, 56 const char *pathname, 57 unsigned32 flag, 58 unsigned32 mode 59 ); 60 61 typedef int (*rtems_filesystem_close_t)( 62 rtems_libio_t *iop 63 ); 64 65 typedef int (*rtems_filesystem_read_t)( 66 rtems_libio_t *iop, 67 void *buffer, 68 unsigned32 count 69 ); 70 71 typedef int (*rtems_filesystem_write_t)( 72 rtems_libio_t *iop, 73 const void *buffer, 74 unsigned32 count 75 ); 76 77 typedef int (*rtems_filesystem_ioctl_t)( 78 rtems_libio_t *iop, 79 unsigned32 command, 80 void *buffer 81 ); 82 83 typedef int (*rtems_filesystem_lseek_t)( 84 rtems_libio_t *iop, 85 off_t length, 86 int whence 87 ); 88 89 typedef int (*rtems_filesystem_fstat_t)( 90 rtems_filesystem_location_info_t *loc, 91 struct stat *buf 92 ); 93 94 typedef int (*rtems_filesystem_fchmod_t)( 95 rtems_filesystem_location_info_t *loc, 96 mode_t mode 97 ); 98 99 typedef int (*rtems_filesystem_ftruncate_t)( 100 rtems_libio_t *iop, 101 off_t length 102 ); 103 104 typedef int (*rtems_filesystem_fpathconf_t)( 105 rtems_libio_t *iop, 106 int name 107 ); 108 109 typedef int (*rtems_filesystem_fsync_t)( 110 rtems_libio_t *iop 111 ); 112 113 typedef int (*rtems_filesystem_fdatasync_t)( 114 rtems_libio_t *iop 115 ); 116 117 typedef struct { 118 rtems_filesystem_open_t open; 119 rtems_filesystem_close_t close; 120 rtems_filesystem_read_t read; 121 rtems_filesystem_write_t write; 122 rtems_filesystem_ioctl_t ioctl; 123 rtems_filesystem_lseek_t lseek; 124 rtems_filesystem_fstat_t fstat; 125 rtems_filesystem_fchmod_t fchmod; 126 rtems_filesystem_ftruncate_t ftruncate; 127 rtems_filesystem_fpathconf_t fpathconf; 128 rtems_filesystem_fsync_t fsync; 129 rtems_filesystem_fdatasync_t fdatasync; 130 } rtems_filesystem_file_handlers_r; 131 132 /* 133 * File System Operations Table 134 */ 135 136 /* 137 * XXX 138 * This routine does not allocate any space and rtems_filesystem_freenode_t 139 * is not called by the generic after calling this routine. 140 * ie. node_access does not have to contain valid data when the 141 * routine returns. 142 */ 143 144 typedef int (*rtems_filesystem_mknod_t)( 145 const char *path, /* IN */ 146 mode_t mode, /* IN */ 147 dev_t dev, /* IN */ 148 rtems_filesystem_location_info_t *pathloc /* IN/OUT */ 149 ); 150 151 /* 152 * rtems_filesystem_freenode_t must be called by the generic after 153 * calling this routine 154 */ 155 156 typedef int (*rtems_filesystem_evalpath_t)( 157 const char *pathname, /* IN */ 158 int flags, /* IN */ 159 rtems_filesystem_location_info_t *pathloc /* IN/OUT */ 160 ); 161 162 typedef int (*rtems_filesystem_evalmake_t)( 163 const char *path, /* IN */ 164 rtems_filesystem_location_info_t *pathloc, /* IN/OUT */ 165 const char **name /* OUT */ 166 ); 167 168 typedef int (*rtems_filesystem_link_t)( 169 rtems_filesystem_location_info_t *to_loc, /* IN */ 170 rtems_filesystem_location_info_t *parent_loc, /* IN */ 171 const char *name /* IN */ 172 ); 173 174 typedef int (*rtems_filesystem_unlink_t)( 175 rtems_filesystem_location_info_t *pathloc /* IN */ 176 ); 177 178 typedef int (*rtems_filesystem_chown_t)( 179 rtems_filesystem_location_info_t *pathloc, /* IN */ 180 uid_t owner, /* IN */ 181 gid_t group /* IN */ 182 ); 183 184 typedef int (*rtems_filesystem_freenode_t)( 185 rtems_filesystem_location_info_t *pathloc /* IN */ 186 ); 187 188 typedef int (*rtems_filesystem_rmnod_t)( 189 rtems_filesystem_location_info_t *pathloc /* IN */ 190 ); 191 192 typedef int (* rtems_filesystem_mount_t ) ( 193 rtems_filesystem_mount_table_entry_t *mt_entry /* in */ 194 ); 195 196 typedef int (* rtems_filesystem_fsmount_me_t )( 197 rtems_filesystem_mount_table_entry_t *mt_entry 198 ); 199 200 typedef int (* rtems_filesystem_unmount_t ) ( 201 rtems_filesystem_mount_table_entry_t *mt_entry /* in */ 202 ); 203 204 typedef int (* rtems_filesystem_fsunmount_me_t ) ( 205 rtems_filesystem_mount_table_entry_t *mt_entry /* in */ 206 ); 207 208 typedef rtems_filesystem_node_types_t (* rtems_filesystem_node_type_t) ( 209 rtems_filesystem_location_info_t *pathloc /* in */ 210 ); 211 212 typedef int (* rtems_filesystem_utime_t)( 213 rtems_filesystem_location_info_t *pathloc, /* IN */ 214 time_t actime, /* IN */ 215 time_t modtime /* IN */ 216 ); 217 218 typedef int (*rtems_filesystem_evaluate_link_t)( 219 rtems_filesystem_location_info_t *pathloc, /* IN/OUT */ 220 int flags /* IN */ 221 ); 222 223 typedef int (*rtems_filesystem_symlink_t)( 224 rtems_filesystem_location_info_t *loc, /* IN */ 225 const char *link_name, /* IN */ 226 const char *node_name 227 ); 228 229 typedef int (*rtems_filesystem_readlink_t)( 230 rtems_filesystem_location_info_t *loc, /* IN */ 231 char *buf, /* OUT */ 232 size_t bufsize 233 ); 234 235 /* 236 * operations table that must be defined for every file system. 237 */ 238 239 /* 240 * File system types 241 */ 242 typedef struct { 243 rtems_filesystem_evalpath_t evalpath; 244 rtems_filesystem_evalmake_t evalformake; 245 rtems_filesystem_link_t link; 246 rtems_filesystem_unlink_t unlink; 247 rtems_filesystem_node_type_t node_type; 248 rtems_filesystem_mknod_t mknod; 249 rtems_filesystem_rmnod_t rmnod; 250 rtems_filesystem_chown_t chown; 251 rtems_filesystem_freenode_t freenod; 252 rtems_filesystem_mount_t mount; 253 rtems_filesystem_fsmount_me_t fsmount_me; 254 rtems_filesystem_unmount_t unmount; 255 rtems_filesystem_fsunmount_me_t fsunmount_me; 256 rtems_filesystem_utime_t utime; 257 rtems_filesystem_evaluate_link_t eval_link; 258 rtems_filesystem_symlink_t symlink; 259 rtems_filesystem_readlink_t readlink; 260 } rtems_filesystem_operations_table; 261 262 #define IMFS_FILE_SYSTEM IMFS_ops 263 extern rtems_filesystem_operations_table IMFS_ops; 264 265 266 /* 267 * Structure used to determine a location/filesystem in the tree. 268 */ 269 270 struct rtems_filesystem_location_info_tt 271 { 272 void *node_access; 273 rtems_filesystem_file_handlers_r *handlers; 274 rtems_filesystem_operations_table *ops; 275 rtems_filesystem_mount_table_entry_t *mt_entry; 276 }; 277 278 /* 279 * Structure used to contain file system specific information which 280 * is required to support fpathconf(). 281 */ 282 283 typedef struct { 284 int link_max; 285 int max_canon; 286 int max_input; 287 int name_max; 288 int path_max; 289 int pipe_buf; 290 int posix_async_io; 291 int posix_chown_restrictions; 292 int posix_no_trunc; 293 int posix_prio_io; 294 int posix_sync_io; 295 int posix_vdisable; 296 } rtems_filesystem_limits_and_options_t; 297 298 /* 299 * Structure for a mount table entry. 300 */ 301 302 struct rtems_filesystem_mount_table_entry_tt{ 303 Chain_Node Node; 304 rtems_filesystem_location_info_t mt_point_node; 305 rtems_filesystem_location_info_t mt_fs_root; 306 int options; 307 void *fs_info; 308 309 rtems_filesystem_limits_and_options_t pathconf_limits_and_options; 310 311 /* 312 * When someone adds a mounted filesystem on a real device, 313 * this will need to be used. 314 * 315 * The best option long term for this is probably an open file descriptor. 316 */ 317 char *dev; 318 }; 319 320 /* 321 * Valid RTEMS file systems options 322 */ 323 324 typedef enum 325 { 326 RTEMS_FILESYSTEM_READ_ONLY, 327 RTEMS_FILESYSTEM_READ_WRITE_ONLY, 328 RTEMS_FILESYSTEM_BAD_OPTIONS 329 } rtems_filesystem_options_t; 330 331 332 /* 333 * An open file data structure, indexed by 'fd' 334 * TODO: 335 * should really have a separate per/file data structure that this 336 * points to (eg: size, offset, driver, pathname should be in that) 337 */ 338 339 struct rtems_libio_tt { 340 rtems_driver_name_t *driver; 341 off_t size; /* size of file */ 342 off_t offset; /* current offset into file */ 343 unsigned32 flags; 344 rtems_filesystem_location_info_t pathinfo; 345 Objects_Id sem; 346 unsigned32 data0; /* private to "driver" */ 347 void *data1; /* ... */ 348 void *file_info; /* used by file handlers */ 349 rtems_filesystem_file_handlers_r *handlers; /* type specific handlers */ 350 }; 351 352 /* 353 * param block for read/write 354 * Note: it must include 'offset' instead of using iop's offset since 355 * we can have multiple outstanding i/o's on a device. 43 356 */ 44 357 45 358 typedef struct { 46 359 rtems_libio_t *iop; 47 rtems_libio_offset_toffset;360 off_t offset; 48 361 unsigned8 *buffer; 49 362 unsigned32 count; … … 53 366 54 367 /* 55 * param block for open/close368 * param block for open/close 56 369 */ 57 370 … … 63 376 64 377 /* 65 * param block for ioctl378 * param block for ioctl 66 379 */ 67 380 … … 73 386 } rtems_libio_ioctl_args_t; 74 387 75 76 /* 77 * Values for 'flag' 388 /* 389 * Values for 'flag' 78 390 */ 79 391 … … 85 397 #define LIBIO_FLAGS_APPEND 0x0200 /* all writes append */ 86 398 #define LIBIO_FLAGS_CREATE 0x0400 /* create file */ 399 #define LIBIO_FLAGS_CLOSE_ON_EXEC 0x0800 /* close on process exec() */ 87 400 88 401 #define LIBIO_FLAGS_READ_WRITE (LIBIO_FLAGS_READ | LIBIO_FLAGS_WRITE) 89 402 403 90 404 void rtems_libio_init(void); 91 405 92 int __rtems_open(const char *pathname, unsigned32 flag, unsigned32 mode); 93 int __rtems_close(int fd); 94 int __rtems_read(int fd, void *buffer, unsigned32 count); 95 int __rtems_write(int fd, const void *buffer, unsigned32 count); 96 int __rtems_ioctl(int fd, unsigned32 command, void *buffer); 97 int __rtems_lseek(int fd, rtems_libio_offset_t offset, int whence); 98 int __rtems_fstat(int _fd, struct stat* _sbuf); 99 100 /* 101 * External I/O handlers 102 */ 103 typedef struct { 104 int (*open)(const char *pathname, unsigned32 flag, unsigned32 mode); 105 int (*close)(int fd); 106 int (*read)(int fd, void *buffer, unsigned32 count); 107 int (*write)(int fd, const void *buffer, unsigned32 count); 108 int (*ioctl)(int fd, unsigned32 command, void *buffer); 109 int (*lseek)(int fd, rtems_libio_offset_t offset, int whence); 406 /* 407 * External I/O handlers 408 */ 409 410 typedef int (*rtems_libio_open_t)( 411 const char *pathname, 412 unsigned32 flag, 413 unsigned32 mode 414 ); 415 416 typedef int (*rtems_libio_close_t)( 417 int fd 418 ); 419 420 typedef int (*rtems_libio_read_t)( 421 int fd, 422 void *buffer, 423 unsigned32 count 424 ); 425 426 typedef int (*rtems_libio_write_t)( 427 int fd, 428 const void *buffer, 429 unsigned32 count 430 ); 431 432 typedef int (*rtems_libio_ioctl_t)( 433 int fd, 434 unsigned32 command, 435 void *buffer 436 ); 437 438 typedef int (*rtems_libio_lseek_t)( 439 int fd, 440 off_t offset, 441 int whence 442 ); 443 444 typedef struct { 445 rtems_libio_open_t open; 446 rtems_libio_close_t close; 447 rtems_libio_read_t read; 448 rtems_libio_write_t write; 449 rtems_libio_ioctl_t ioctl; 450 rtems_libio_lseek_t lseek; 110 451 } rtems_libio_handler_t; 111 452 112 void rtems_register_libio_handler(int handler_flag, 113 const rtems_libio_handler_t *handler); 453 /* 454 * Register a set of external handlers 455 */ 456 457 void rtems_register_libio_handler( 458 int handler_flag, 459 const rtems_libio_handler_t *handler 460 ); 461 462 /* 463 * Macros to assist in management of external IO handlers. 464 */ 114 465 115 466 #define RTEMS_FILE_DESCRIPTOR_TYPE_FILE 0x0000 … … 129 480 130 481 /* 482 * The following macros are used to build up the permissions sets 483 * used to check permissions. These are similar in style to the 484 * mode_t bits and should stay compatible with them. 485 */ 486 487 #define RTEMS_LIBIO_PERMS_READ S_IROTH 488 #define RTEMS_LIBIO_PERMS_WRITE S_IWOTH 489 #define RTEMS_LIBIO_PERMS_RDWR (S_IROTH|S_IWOTH) 490 #define RTEMS_LIBIO_PERMS_EXEC S_IXOTH 491 #define RTEMS_LIBIO_PERMS_SEARCH RTEMS_LIBIO_PERMS_EXEC 492 #define RTEMS_LIBIO_PERMS_RWX S_IRWXO 493 494 /* 495 * Macros 496 */ 497 498 #define rtems_filesystem_make_dev_t( _major, _minor ) \ 499 ((((dev_t)(_major)) << 32) | (dev_t)(_minor)) 500 501 #define rtems_filesystem_split_dev_t( _dev, _major, _minor ) \ 502 do { \ 503 (_major) = (rtems_device_major_number) ((_dev) >> 32); \ 504 (_minor) = (rtems_device_minor_number) ((_dev) & 0xFFFFFFFF); \ 505 } while(0) 506 507 /* 508 * Verifies that the permission flag is valid. 509 */ 510 #define rtems_libio_is_valid_perms( _perm ) \ 511 (~ ((~RTEMS_LIBIO_PERMS_RWX) & _perm )) 512 513 514 /* 515 * Prototypes for filesystem 516 */ 517 518 void rtems_filesystem_initialize( void ); 519 520 521 /* 131 522 * Callbacks from TERMIOS routines to device-dependent code 132 523 */ 524 133 525 #include <termios.h> 526 134 527 typedef struct rtems_termios_callbacks { 135 int 136 int 137 int 138 int 139 int 140 int 141 int 142 int 528 int (*firstOpen)(int major, int minor, void *arg); 529 int (*lastClose)(int major, int minor, void *arg); 530 int (*pollRead)(int minor); 531 int (*write)(int minor, const char *buf, int len); 532 int (*setAttributes)(int minor, const struct termios *t); 533 int (*stopRemoteTx)(int minor); 534 int (*startRemoteTx)(int minor); 535 int outputUsesInterrupts; 143 536 } rtems_termios_callbacks; 144 537 145 538 /* 146 * Device-independent TERMIOS routines 147 */ 539 * Device-independent TERMIOS routines 540 */ 541 148 542 void rtems_termios_initialize (void); 543 149 544 rtems_status_code rtems_termios_open ( 150 545 rtems_device_major_number major, … … 152 547 void *arg, 153 548 const rtems_termios_callbacks *callbacks 154 ); 155 rtems_status_code rtems_termios_close (void *arg); 156 rtems_status_code rtems_termios_read (void *arg); 157 rtems_status_code rtems_termios_write (void *arg); 158 rtems_status_code rtems_termios_ioctl (void *arg); 159 int rtems_termios_enqueue_raw_characters (void *ttyp, char *buf, int len); 160 int rtems_termios_dequeue_characters (void *ttyp, int len); 549 ); 550 551 rtems_status_code rtems_termios_close( 552 void *arg 553 ); 554 555 rtems_status_code rtems_termios_read( 556 void *arg 557 ); 558 559 rtems_status_code rtems_termios_write( 560 void *arg 561 ); 562 563 rtems_status_code rtems_termios_ioctl( 564 void *arg 565 ); 566 567 int rtems_termios_enqueue_raw_characters( 568 void *ttyp, 569 char *buf, 570 int len 571 ); 572 573 int rtems_termios_dequeue_characters( 574 void *ttyp, 575 int len 576 ); 577 161 578 void rtems_termios_reserve_resources( 162 579 rtems_configuration_table *configuration, … … 164 581 ); 165 582 583 int unmount( 584 const char *mount_path 585 ); 586 587 int mount( 588 rtems_filesystem_mount_table_entry_t **mt_entry, 589 rtems_filesystem_operations_table *fs_ops, 590 char *fsoptions, 591 char *device, 592 char *mount_point 593 ); 594 166 595 #endif /* _RTEMS_LIBIO_H */ -
c/src/exec/libcsupport/src/__brk.c
rcd3fb80 r07a3253d 1 #if !defined(RTEMS_UNIX)2 3 1 /* 4 * RTEMS "Broken" __brk /__sbrkImplementation2 * RTEMS "Broken" __brk Implementation 5 3 * 6 * NOTE: sbrk is BSP provided. 7 * 4 * NOTE: sbrk() is provided by each BSP. 8 5 * 9 6 * COPYRIGHT (c) 1989-1998. … … 19 16 20 17 #include <rtems.h> 18 #if !defined(RTEMS_UNIX) 21 19 22 #include <signal.h>23 20 #include <errno.h> 24 #include <sys/types.h>25 #ifdef RTEMS_NEWLIB26 #include <reent.h>27 #endif28 #include <unistd.h>29 21 30 /* we use RTEMS for memory management. We don't need sbrk */ 31 32 void * __sbrk(int incr) 33 { 34 errno = EINVAL; 35 return (void *)0; 36 } 37 38 int __brk( const void *endds ) 22 int __brk( 23 const void *endds 24 ) 39 25 { 40 26 errno = EINVAL; 41 27 return -1; 42 28 } 43 44 29 #endif -
c/src/exec/libcsupport/src/__gettod.c
rcd3fb80 r07a3253d 1 #define __RTEMS_VIOLATE_KERNEL_VISIBILITY__2 3 #include <rtems.h>4 5 #if !defined(RTEMS_UNIX)6 1 /* 7 * RTEMS gettimeofday Implementation 8 * 2 * gettimeofday() - SVR4 and BSD4.3 extension required by Newlib 9 3 * 10 4 * COPYRIGHT (c) 1989-1998. … … 19 13 */ 20 14 15 #define __RTEMS_VIOLATE_KERNEL_VISIBILITY__ 16 17 #include <rtems.h> 18 19 #if !defined(RTEMS_UNIX) 21 20 #ifdef RTEMS_NEWLIB 22 21 #include <sys/reent.h> … … 62 61 * NOTE: XXX this routine should really be in the executive proper. 63 62 */ 64 63 65 64 rtems_interrupt_disable(level); 66 65 seconds = _TOD_Seconds_since_epoch; … … 87 86 } 88 87 89 #if defined(RTEMS_NEWLIB) 88 #if defined(RTEMS_NEWLIB) 90 89 91 90 /* … … 103 102 104 103 /* 105 * "System call" version 104 * "System call" version 106 105 */ 107 106 -
c/src/exec/libcsupport/src/__times.c
rcd3fb80 r07a3253d 1 1 /* 2 * RTEMS _times Implementation 3 * 2 * times() - POSIX 1003.1b 4.5.2 - Get Process Times 4 3 * 5 4 * COPYRIGHT (c) 1989-1998. … … 26 25 ) 27 26 { 28 rtems_status_code 29 rtems_interval ticks_since_boot;27 rtems_status_code status; 28 rtems_interval ticks; 30 29 31 30 if ( !ptms ) { … … 35 34 36 35 /* "POSIX" does not seem to allow for not having a TOD */ 37 status = rtems_clock_get( 38 RTEMS_CLOCK_GET_TICKS_SINCE_BOOT, 39 &ticks_since_boot 40 ); 36 status = rtems_clock_get( RTEMS_CLOCK_GET_TICKS_SINCE_BOOT, &ticks ); 41 37 if ( status != RTEMS_SUCCESSFUL ) { 42 38 assert( 0 ); … … 45 41 46 42 /* 47 * RTEMS has no notion of system versus user time and does 48 * not (as of 3.2.0) keep track of CPU usage on a per task basis. 43 * RTEMS has no notion of system versus user time and although 44 * a way to keep track of per task CPU usage was added since 45 * 3.6.0, this routine does not utilize it yet. 49 46 */ 50 47 51 ptms->tms_utime = ticks _since_boot;48 ptms->tms_utime = ticks; 52 49 ptms->tms_stime = 0; 53 50 ptms->tms_cutime = 0; … … 56 53 return 0; 57 54 } 55 56 /* 57 * times() 58 * 59 * times() system call wrapper for _times() above. 60 */ 58 61 59 62 clock_t times( … … 64 67 } 65 68 69 /* 70 * _times_r 71 * 72 * This is the Newlib dependent reentrant version of times(). 73 */ 74 66 75 #if defined(RTEMS_NEWLIB) 76 77 #include <reent.h> 78 67 79 clock_t _times_r( 68 80 struct _reent *ptr, … … 70 82 ) 71 83 { 72 return _times( ptms);84 return _times( ptms ); 73 85 } 74 86 #endif -
c/src/exec/libcsupport/src/closedir.c
rcd3fb80 r07a3253d 2 2 * closedir() - POSIX 1003.1b - XXX 3 3 * 4 * $Id$ 4 * This was copied from Newlib 1.8.0. 5 * 6 * 7 * Copyright (c) 1983 Regents of the University of California. 8 * All rights reserved. 9 * 10 * Redistribution and use in source and binary forms, with or without 11 * modification, are permitted provided that the following conditions 12 * are met: 13 * 1. Redistributions of source code must retain the above copyright 14 * notice, this list of conditions and the following disclaimer. 15 * 2. Redistributions in binary form must reproduce the above copyright 16 * notice, this list of conditions and the following disclaimer in the 17 * documentation and/or other materials provided with the distribution. 18 * 3. All advertising materials mentioning features or use of this software 19 * must display the following acknowledgement: 20 * This product includes software developed by the University of 21 * California, Berkeley and its contributors. 22 * 4. Neither the name of the University nor the names of its contributors 23 * may be used to endorse or promote products derived from this software 24 * without specific prior written permission. 25 * 26 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 27 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 28 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 29 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 30 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 31 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 32 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 33 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 36 * SUCH DAMAGE. 5 37 */ 6 38 39 #if defined(LIBC_SCCS) && !defined(lint) 40 static char sccsid[] = "@(#)closedir.c 5.9 (Berkeley) 2/23/91"; 41 #endif /* LIBC_SCCS and not lint */ 7 42 8 43 #include <sys/types.h> … … 12 47 #include <errno.h> 13 48 14 int closedir( 15 register DIR *dirp 16 ) 49 50 #include "libio_.h" 51 52 /* 53 * close a directory. 54 */ 55 int 56 closedir(dirp) 57 register DIR *dirp; 17 58 { 18 errno = ENOSYS; 19 return -1; 59 int fd; 60 61 if ( !dirp ) 62 set_errno_and_return_minus_one( EBADF ); 63 64 fd = dirp->dd_fd; 65 dirp->dd_fd = -1; 66 dirp->dd_loc = 0; 67 (void)free((void *)dirp->dd_buf); 68 (void)free((void *)dirp); 69 return(close(fd)); 20 70 } -
c/src/exec/libcsupport/src/getdents.c
rcd3fb80 r07a3253d 1 1 /* 2 * Just enough to make newlib return an error. 2 * getdents() - Get Directory Entries 3 * 4 * SVR4 and SVID extension required by Newlib readdir() family. 5 * 6 * This routine will dd_len / (sizeof dirent) directory entries relative to 7 * the current directory position index. These entries will be placed in 8 * character array pointed to by -dd_buf- 9 * 10 * COPYRIGHT (c) 1989-1998. 11 * On-Line Applications Research Corporation (OAR). 12 * Copyright assigned to U.S. Government, 1994. 13 * 14 * The license and distribution terms for this file may be 15 * found in the file LICENSE in this distribution or at 16 * http://www.OARcorp.com/rtems/license.html. 3 17 * 4 18 * $Id$ 5 19 */ 6 20 21 #include <errno.h> 22 23 #include "libio_.h" 24 7 25 int getdents( 8 int fd,9 void *buf,10 int len26 int dd_fd, 27 char *dd_buf, 28 int dd_len 11 29 ) 12 30 { 13 return -1; 31 rtems_libio_t *iop; 32 rtems_filesystem_location_info_t loc; 33 34 /* 35 * Get the file control block structure associated with the file descriptor 36 */ 37 38 iop = rtems_libio_iop( dd_fd ); 39 40 /* 41 * Make sure we are working on a directory 42 */ 43 loc = iop->pathinfo; 44 if ( !loc.ops->node_type ) 45 set_errno_and_return_minus_one( ENOTSUP ); 46 47 if ( (*loc.ops->node_type)( &loc ) != RTEMS_FILESYSTEM_DIRECTORY ) 48 set_errno_and_return_minus_one( ENOTDIR ); 49 50 /* 51 * Return the number of bytes that were actually transfered as a result 52 * of the read attempt. 53 */ 54 55 if ( !iop->handlers->read ) 56 set_errno_and_return_minus_one( ENOTSUP ); 57 58 return (*iop->handlers->read)( iop, dd_buf, dd_len ); 14 59 } -
c/src/exec/libcsupport/src/hosterr.c
rcd3fb80 r07a3253d 14 14 15 15 #include <rtems.h> 16 #if defined(RTEMS_UNIX) 16 17 #include <errno.h> 17 18 18 int host_errno( void);19 int host_errno( void ); 19 20 20 21 /* 21 * copy host errno, if any to thread aware errno, if any 22 * fix_syscall_errno 23 * 24 * copy host errno, if any to thread aware errno, if any 22 25 */ 23 26 24 void fix_syscall_errno( void)27 void fix_syscall_errno( void ) 25 28 { 26 29 errno = host_errno(); 27 30 } 28 31 29 32 /* 30 * Get the host system errno, if any 31 * When using newlib (or possibly other libc's) on top of UNIX 32 * the errno returned by system calls may be unavailable due 33 * to trickery of making errno thread aware. 34 * This provides a kludge of getting at it. 33 * host_errno 34 * 35 * Get the host system errno, if any 36 * When using newlib (or possibly other libc's) on top of UNIX 37 * the errno returned by system calls may be unavailable due 38 * to trickery of making errno thread aware. 39 * This provides a kludge of getting at it. 35 40 */ 36 41 … … 39 44 int host_errno(void) 40 45 { 41 46 return errno; 42 47 } 43 48 #endif -
c/src/exec/libcsupport/src/libio.c
rcd3fb80 r07a3253d 1 1 /* 2 * Provide UNIX/POSIX-like io system calls for RTEMS using the 3 * RTEMS IO manager 2 * This file contains the support infrastructure used to manage the 3 * table of integer style file descriptors used by the low level 4 * POSIX system calls like open(), read, fstat(), etc. 5 * 6 * This provides the foundation for POSIX compliant IO system calls 7 * for RTEMS. 8 * 9 * COPYRIGHT (c) 1989-1998. 10 * On-Line Applications Research Corporation (OAR). 11 * Copyright assigned to U.S. Government, 1994. 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.OARcorp.com/rtems/license.html. 4 16 * 5 17 * $Id$ 6 18 */ 7 19 8 #include <rtems.h> 9 #include <rtems/assoc.h> /* assoc.h not included by rtems.h */ 10 11 #include <stdio.h> /* O_RDONLY, et.al. */ 12 #include <fcntl.h> /* O_RDONLY, et.al. */ 13 #include <assert.h> 14 15 #if ! defined(O_NDELAY) 16 # if defined(solaris2) 17 # define O_NDELAY O_NONBLOCK 18 # elif defined(RTEMS_NEWLIB) 19 # define O_NDELAY _FNBIO 20 # endif 21 #endif 22 23 24 #include <errno.h> 25 #include <string.h> /* strcmp */ 26 #include <unistd.h> 27 #include <stdlib.h> /* calloc() */ 28 29 #include "libio.h" /* libio.h not pulled in by rtems */ 30 31 /* 32 * Semaphore to protect the io table 33 */ 34 35 Objects_Id rtems_libio_semaphore; 36 37 #define RTEMS_LIBIO_SEM rtems_build_name('L', 'B', 'I', 'O') 38 #define RTEMS_LIBIO_IOP_SEM(n) rtems_build_name('L', 'B', 'I', n) 39 40 extern unsigned32 rtems_libio_number_iops; 41 rtems_libio_t *rtems_libio_iops; 42 rtems_libio_t *rtems_libio_last_iop; 43 44 #define rtems_libio_iop(fd) ((((unsigned32)(fd)) < rtems_libio_number_iops) ? \ 45 &rtems_libio_iops[fd] : 0) 46 47 #define rtems_libio_check_fd(fd) \ 48 do { \ 49 if ((unsigned32) (fd) >= rtems_libio_number_iops) \ 50 { \ 51 errno = EBADF; \ 52 return -1; \ 53 } \ 54 } while (0) 55 56 #define rtems_libio_check_buffer(buffer) \ 57 do { \ 58 if ((buffer) == 0) \ 59 { \ 60 errno = EINVAL; \ 61 return -1; \ 62 } \ 63 } while (0) 64 65 #define rtems_libio_check_count(count) \ 66 do { \ 67 if ((count) == 0) \ 68 { \ 69 return 0; \ 70 } \ 71 } while (0) 72 73 #define rtems_libio_check_permissions(iop, flag) \ 74 do { \ 75 if (((iop)->flags & (flag)) == 0) \ 76 { \ 77 errno = EINVAL; \ 78 return -1; \ 79 } \ 80 } while (0) 81 82 /* 83 * External I/O handlers 84 * 85 * Space for all possible handlers is preallocated 86 * to speed up dispatch to external handlers. 87 */ 88 89 static rtems_libio_handler_t handlers[15]; 90 91 void 92 rtems_register_libio_handler( 93 int handler_flag, 94 const rtems_libio_handler_t *handler 95 ) 96 { 97 int handler_index = rtems_file_descriptor_type_index(handler_flag); 20 #include "libio_.h" /* libio_.h pulls in rtems */ 21 22 /* 23 * Global variables used to manage the File Descriptor Table. 24 * IOP = IO Pointer. 25 */ 26 27 rtems_id rtems_libio_semaphore; 28 rtems_libio_t *rtems_libio_iops; 29 rtems_libio_t *rtems_libio_last_iop; 30 rtems_libio_handler_t rtems_libio_handlers[15]; 31 32 /* 33 * rtems_register_libio_handler 34 * 35 * This function registers an external IO handler set. This lets 36 * other subsystems have their own versions of many of the system 37 * calls. For example, the networking code registers handlers which 38 * map the system calls for read() and write() to socket calls. 39 * 40 */ 41 42 void rtems_register_libio_handler( 43 int handler_flag, 44 const rtems_libio_handler_t *handler 45 ) 46 { 47 int handler_index = rtems_file_descriptor_type_index( handler_flag ); 48 98 49 99 50 if ((handler_index < 0) || (handler_index >= 15)) 100 51 rtems_fatal_error_occurred( RTEMS_INVALID_NUMBER ); 101 handlers[handler_index] = *handler; 102 } 103 104 /* 105 * Called by bsp startup code to init the libio area. 106 */ 107 108 void 109 rtems_libio_init(void) 110 { 111 rtems_status_code rc; 112 113 if (rtems_libio_number_iops > 0) 114 { 115 rtems_libio_iops = (rtems_libio_t *) calloc(rtems_libio_number_iops, 116 sizeof(rtems_libio_t)); 117 if (rtems_libio_iops == NULL) 118 rtems_fatal_error_occurred(RTEMS_NO_MEMORY); 119 120 rtems_libio_last_iop = rtems_libio_iops + (rtems_libio_number_iops - 1); 52 53 rtems_libio_handlers[handler_index] = *handler; 54 } 55 56 /* 57 * rtems_libio_init 58 * 59 * Called by BSP startup code to initialize the libio subsystem. 60 */ 61 62 void rtems_libio_init( void ) 63 { 64 rtems_status_code rc; 65 66 /* 67 * Allocate memory for the IOP Table 68 */ 69 70 if ( rtems_libio_number_iops > 0 ) { 71 rtems_libio_iops = 72 (rtems_libio_t *) calloc(rtems_libio_number_iops, sizeof(rtems_libio_t)); 73 74 if (rtems_libio_iops == NULL) 75 rtems_fatal_error_occurred( RTEMS_NO_MEMORY ); 76 77 rtems_libio_last_iop = rtems_libio_iops + (rtems_libio_number_iops - 1); 78 } 79 80 /* 81 * Create the binary semaphore used to provide mutual exclusion 82 * on the IOP Table. 83 */ 84 85 rc = rtems_semaphore_create( 86 RTEMS_LIBIO_SEM, 87 1, 88 RTEMS_BINARY_SEMAPHORE | RTEMS_INHERIT_PRIORITY | RTEMS_PRIORITY, 89 RTEMS_NO_PRIORITY, 90 &rtems_libio_semaphore 91 ); 92 if ( rc != RTEMS_SUCCESSFUL ) 93 rtems_fatal_error_occurred( rc ); 94 95 /* 96 * Initialize the base file system infrastructure. 97 */ 98 99 rtems_filesystem_initialize(); 100 } 101 102 /* 103 * rtems_libio_fcntl_flags 104 * 105 * Convert UNIX fnctl(2) flags to ones that RTEMS drivers understand 106 */ 107 108 rtems_assoc_t access_modes_assoc[] = { 109 { "READ", LIBIO_FLAGS_READ, O_RDONLY }, 110 { "WRITE", LIBIO_FLAGS_WRITE, O_WRONLY }, 111 { "READ/WRITE", LIBIO_FLAGS_READ_WRITE, O_RDWR }, 112 { 0, 0, 0 }, 113 }; 114 115 rtems_assoc_t status_flags_assoc[] = { 116 { "NO DELAY", LIBIO_FLAGS_NO_DELAY, O_NDELAY }, 117 { "APPEND", LIBIO_FLAGS_APPEND, O_APPEND }, 118 { "CREATE", LIBIO_FLAGS_CREATE, O_CREAT }, 119 { 0, 0, 0 }, 120 }; 121 122 unsigned32 rtems_libio_fcntl_flags( 123 unsigned32 fcntl_flags 124 ) 125 { 126 unsigned32 flags = 0; 127 unsigned32 access_modes; 128 129 /* 130 * Access mode is a small integer 131 */ 132 133 access_modes = fcntl_flags & O_ACCMODE; 134 fcntl_flags &= ~O_ACCMODE; 135 flags = rtems_assoc_local_by_remote( access_modes_assoc, access_modes ); 136 137 /* 138 * Everything else is single bits 139 */ 140 141 flags |= 142 rtems_assoc_local_by_remote_bitfield(status_flags_assoc, fcntl_flags); 143 return flags; 144 } 145 146 /* 147 * rtems_libio_allocate 148 * 149 * This routine searches the IOP Table for an unused entry. If it 150 * finds one, it returns it. Otherwise, it returns NULL. 151 */ 152 153 rtems_libio_t *rtems_libio_allocate( void ) 154 { 155 rtems_libio_t *iop; 156 rtems_status_code rc; 157 158 rtems_semaphore_obtain( rtems_libio_semaphore, RTEMS_WAIT, RTEMS_NO_TIMEOUT ); 159 160 for (iop = rtems_libio_iops; iop <= rtems_libio_last_iop; iop++) 161 if ((iop->flags & LIBIO_FLAGS_OPEN) == 0) { 162 /* 163 * Got an IOP -- create a semaphore for it. 164 */ 165 166 rc = rtems_semaphore_create( 167 RTEMS_LIBIO_IOP_SEM(iop - rtems_libio_iops), 168 1, 169 RTEMS_BINARY_SEMAPHORE | RTEMS_INHERIT_PRIORITY | RTEMS_PRIORITY, 170 RTEMS_NO_PRIORITY, 171 &iop->sem 172 ); 173 if ( rc != RTEMS_SUCCESSFUL ) 174 goto failed; 175 176 iop->flags = LIBIO_FLAGS_OPEN; 177 goto done; 178 } 179 180 failed: 181 iop = 0; 182 183 done: 184 rtems_semaphore_release( rtems_libio_semaphore ); 185 return iop; 186 } 187 188 /* 189 * rtems_libio_free 190 * 191 * This routine frees the resources associated with an IOP (file descriptor) 192 * and clears the slot in the IOP Table. 193 */ 194 195 void rtems_libio_free( 196 rtems_libio_t *iop 197 ) 198 { 199 rtems_semaphore_obtain( rtems_libio_semaphore, RTEMS_WAIT, RTEMS_NO_TIMEOUT ); 200 201 if (iop->sem) 202 rtems_semaphore_delete(iop->sem); 203 204 (void) memset(iop, 0, sizeof(*iop)); 205 206 rtems_semaphore_release( rtems_libio_semaphore ); 207 } 208 209 /* 210 * rtems_libio_is_open_files_in_fs 211 * 212 * This routine scans the entire file descriptor table to determine if the 213 * are any active file descriptors that refer to the atleast one node in the 214 * file system that we are trying to dismount. 215 * 216 * If there is at least one node in the file system referenced by the mount 217 * table entry a 1 is returned, otherwise a 0 is returned. 218 */ 219 220 int rtems_libio_is_open_files_in_fs( 221 rtems_filesystem_mount_table_entry_t * fs_mt_entry 222 ) 223 { 224 rtems_libio_t *iop; 225 int result = 0; 226 227 rtems_semaphore_obtain( rtems_libio_semaphore, RTEMS_WAIT, RTEMS_NO_TIMEOUT ); 228 229 /* 230 * Look for any active file descriptor entry. 231 */ 232 233 for ( iop=rtems_libio_iops ; iop <= rtems_libio_last_iop ; iop++ ) { 234 235 if ((iop->flags & LIBIO_FLAGS_OPEN) != 0) { 236 237 /* 238 * Check if this node is under the file system that we 239 * are trying to dismount. 240 */ 241 242 if ( iop->pathinfo.mt_entry == fs_mt_entry ) { 243 result = 1; 244 break; 245 } 121 246 } 122 123 rc = rtems_semaphore_create( 124 RTEMS_LIBIO_SEM, 125 1, 126 RTEMS_BINARY_SEMAPHORE | RTEMS_INHERIT_PRIORITY | RTEMS_PRIORITY, 127 RTEMS_NO_PRIORITY, 128 &rtems_libio_semaphore 129 ); 130 if (rc != RTEMS_SUCCESSFUL) 131 rtems_fatal_error_occurred(rc); 132 } 133 134 /* 135 * Convert RTEMS status to a UNIX errno 136 */ 137 138 rtems_assoc_t errno_assoc[] = { 139 { "OK", RTEMS_SUCCESSFUL, 0 }, 140 { "BUSY", RTEMS_RESOURCE_IN_USE, EBUSY }, 141 { "INVALID NAME", RTEMS_INVALID_NAME, EINVAL }, 142 { "NOT IMPLEMENTED", RTEMS_NOT_IMPLEMENTED, ENOSYS }, 143 { "TIMEOUT", RTEMS_TIMEOUT, ETIMEDOUT }, 144 { "NO MEMORY", RTEMS_NO_MEMORY, ENOMEM }, 145 { "NO DEVICE", RTEMS_UNSATISFIED, ENODEV }, 146 { "INVALID NUMBER", RTEMS_INVALID_NUMBER, EBADF}, 147 { "NOT RESOURCE OWNER", RTEMS_NOT_OWNER_OF_RESOURCE, EPERM}, 148 { "IO ERROR", RTEMS_IO_ERROR, EIO}, 149 { 0, 0, 0 }, 150 }; 151 152 static unsigned32 153 rtems_libio_errno(rtems_status_code code) 154 { 155 int rc; 156 157 if ((rc = rtems_assoc_remote_by_local(errno_assoc, (unsigned32) code))) 158 { 159 errno = rc; 160 return -1; 247 } 248 249 rtems_semaphore_release( rtems_libio_semaphore ); 250 251 return result; 252 } 253 254 /* 255 * rtems_libio_is_file_open 256 * 257 * This routine scans the entire file descriptor table to determine if the 258 * given file refers to an active file descriptor. 259 * 260 * If the given file is open a 1 is returned, otherwise a 0 is returned. 261 */ 262 263 int rtems_libio_is_file_open( 264 void *node_access 265 ) 266 { 267 rtems_libio_t *iop; 268 int result=0; 269 270 rtems_semaphore_obtain( rtems_libio_semaphore, RTEMS_WAIT, RTEMS_NO_TIMEOUT ); 271 272 /* 273 * Look for any active file descriptor entry. 274 */ 275 276 for ( iop=rtems_libio_iops ; iop <= rtems_libio_last_iop ; iop++ ) { 277 278 if ((iop->flags & LIBIO_FLAGS_OPEN) != 0) { 279 280 /* 281 * Check if this node is under the file system that we 282 * are trying to dismount. 283 */ 284 285 if ( iop->pathinfo.node_access == node_access ) { 286 result = 1; 287 break; 288 } 161 289 } 162 return -1; 163 } 164 165 /* 166 * Convert UNIX fnctl(2) flags to ones that RTEMS drivers understand 167 */ 168 169 rtems_assoc_t access_modes_assoc[] = { 170 { "READ", LIBIO_FLAGS_READ, O_RDONLY }, 171 { "WRITE", LIBIO_FLAGS_WRITE, O_WRONLY }, 172 { "READ/WRITE", LIBIO_FLAGS_READ_WRITE, O_RDWR }, 173 { 0, 0, 0 }, 174 }; 175 176 rtems_assoc_t status_flags_assoc[] = { 177 { "NO DELAY", LIBIO_FLAGS_NO_DELAY, O_NDELAY }, 178 { "APPEND", LIBIO_FLAGS_APPEND, O_APPEND }, 179 { "CREATE", LIBIO_FLAGS_CREATE, O_CREAT }, 180 { 0, 0, 0 }, 181 }; 182 183 static unsigned32 184 rtems_libio_fcntl_flags(unsigned32 fcntl_flags) 185 { 186 unsigned32 flags = 0; 187 unsigned32 access_modes; 188 189 /* 190 * Access mode is a small integer 191 */ 192 193 access_modes = fcntl_flags & O_ACCMODE; 194 fcntl_flags &= ~O_ACCMODE; 195 flags = rtems_assoc_local_by_remote(access_modes_assoc, access_modes); 196 197 /* 198 * Everything else is single bits 199 */ 200 201 flags |= rtems_assoc_local_by_remote_bitfield(status_flags_assoc, fcntl_flags); 202 return flags; 203 } 204 205 206 static rtems_libio_t * 207 rtems_libio_allocate(void) 208 { 209 rtems_libio_t *iop; 210 rtems_status_code rc; 211 212 rtems_semaphore_obtain(rtems_libio_semaphore, RTEMS_WAIT, RTEMS_NO_TIMEOUT); 213 214 for (iop = rtems_libio_iops; iop <= rtems_libio_last_iop; iop++) 215 if ((iop->flags & LIBIO_FLAGS_OPEN) == 0) 216 { 217 /* 218 * Got one; create a semaphore for it 219 */ 220 221 rc = rtems_semaphore_create( 222 RTEMS_LIBIO_IOP_SEM(iop - rtems_libio_iops), 223 1, 224 RTEMS_BINARY_SEMAPHORE | RTEMS_INHERIT_PRIORITY | RTEMS_PRIORITY, 225 RTEMS_NO_PRIORITY, 226 &iop->sem 227 ); 228 if (rc != RTEMS_SUCCESSFUL) 229 goto failed; 230 231 iop->flags = LIBIO_FLAGS_OPEN; 232 goto done; 233 } 234 235 failed: 236 iop = 0; 237 238 done: 239 rtems_semaphore_release(rtems_libio_semaphore); 240 return iop; 241 } 242 243 static void 244 rtems_libio_free(rtems_libio_t *iop) 245 { 246 rtems_semaphore_obtain(rtems_libio_semaphore, RTEMS_WAIT, RTEMS_NO_TIMEOUT); 247 248 if (iop->sem) 249 rtems_semaphore_delete(iop->sem); 250 (void) memset(iop, 0, sizeof(*iop)); 251 252 rtems_semaphore_release(rtems_libio_semaphore); 253 } 254 255 int 256 __rtems_open( 257 const char *pathname, 258 unsigned32 flag, 259 unsigned32 mode) 260 { 261 rtems_status_code rc; 262 rtems_libio_t *iop = 0; 263 rtems_driver_name_t *np; 264 rtems_libio_open_close_args_t args; 265 266 /* 267 * Additional external I/O handlers would be supported by 268 * adding code to pick apart the pathname appropriately. 269 * The networking code does not require changes here since 270 * network file descriptors are obtained using socket(), not 271 * open(). 272 */ 273 274 if ((rc = rtems_io_lookup_name(pathname, &np)) != RTEMS_SUCCESSFUL) 275 goto done; 276 277 iop = rtems_libio_allocate(); 278 if (iop == 0) 279 { 280 rc = RTEMS_TOO_MANY; 281 goto done; 282 } 283 284 iop->driver = np; 285 iop->pathname = (char *) pathname; 286 iop->flags |= rtems_libio_fcntl_flags(flag); 287 288 args.iop = iop; 289 args.flags = iop->flags; 290 args.mode = mode; 291 292 rc = rtems_io_open(np->major, np->minor, (void *) &args); 293 294 done: 295 296 if (rc != RTEMS_SUCCESSFUL) 297 { 298 if (iop) 299 rtems_libio_free(iop); 300 return rtems_libio_errno(rc); 301 } 302 303 return iop - rtems_libio_iops; 304 } 305 306 int 307 __rtems_close( 308 int fd 309 ) 310 { 311 rtems_status_code rc; 312 rtems_driver_name_t *np; 313 rtems_libio_t *iop; 314 rtems_libio_open_close_args_t args; 315 int status; 316 317 if (rtems_file_descriptor_type(fd)) { 318 int (*fp)(int fd); 319 320 fp = handlers[rtems_file_descriptor_type_index(fd)].close; 321 if (fp == NULL) { 322 errno = EBADF; 323 return -1; 324 } 325 status = (*fp)(fd); 326 return status; 327 } 328 iop = rtems_libio_iop(fd); 329 rtems_libio_check_fd(fd); 330 331 np = iop->driver; 332 333 args.iop = iop; 334 args.flags = 0; 335 args.mode = 0; 336 337 rc = rtems_io_close(np->major, np->minor, (void *) &args); 338 339 rtems_libio_free(iop); 340 341 if (rc != RTEMS_SUCCESSFUL) 342 return rtems_libio_errno(rc); 343 return 0; 344 } 345 346 int 347 __rtems_read( 348 int fd, 349 void * buffer, 350 unsigned32 count 351 ) 352 { 353 rtems_status_code rc; 354 rtems_driver_name_t *np; 355 rtems_libio_t *iop; 356 rtems_libio_rw_args_t args; 357 358 if (rtems_file_descriptor_type(fd)) { 359 int (*fp)(int fd, void *buffer, unsigned32 count); 360 361 fp = handlers[rtems_file_descriptor_type_index(fd)].read; 362 if (fp == NULL) { 363 errno = EBADF; 364 return -1; 365 } 366 return (*fp)(fd, buffer, count); 367 } 368 iop = rtems_libio_iop(fd); 369 rtems_libio_check_fd(fd); 370 rtems_libio_check_buffer(buffer); 371 rtems_libio_check_count(count); 372 rtems_libio_check_permissions(iop, LIBIO_FLAGS_READ); 373 374 np = iop->driver; 375 376 args.iop = iop; 377 args.offset = iop->offset; 378 args.buffer = buffer; 379 args.count = count; 380 args.flags = iop->flags; 381 args.bytes_moved = 0; 382 383 rc = rtems_io_read(np->major, np->minor, (void *) &args); 384 385 iop->offset += args.bytes_moved; 386 387 if (rc != RTEMS_SUCCESSFUL) 388 return rtems_libio_errno(rc); 389 390 return args.bytes_moved; 391 } 392 393 int 394 __rtems_write( 395 int fd, 396 const void *buffer, 397 unsigned32 count 398 ) 399 { 400 rtems_status_code rc; 401 rtems_driver_name_t *np; 402 rtems_libio_t *iop; 403 rtems_libio_rw_args_t args; 404 405 if (rtems_file_descriptor_type(fd)) { 406 int (*fp)(int fd, const void *buffer, unsigned32 count); 407 408 fp = handlers[rtems_file_descriptor_type_index(fd)].write; 409 if (fp == NULL) { 410 errno = EBADF; 411 return -1; 412 } 413 return (*fp)(fd, buffer, count); 414 } 415 iop = rtems_libio_iop(fd); 416 rtems_libio_check_fd(fd); 417 rtems_libio_check_buffer(buffer); 418 rtems_libio_check_count(count); 419 rtems_libio_check_permissions(iop, LIBIO_FLAGS_WRITE); 420 421 np = iop->driver; 422 423 args.iop = iop; 424 args.offset = iop->offset; 425 args.buffer = (void *) buffer; 426 args.count = count; 427 args.flags = iop->flags; 428 args.bytes_moved = 0; 429 430 rc = rtems_io_write(np->major, np->minor, (void *) &args); 431 432 iop->offset += args.bytes_moved; 433 434 if (rc != RTEMS_SUCCESSFUL) 435 return rtems_libio_errno(rc); 436 437 return args.bytes_moved; 438 } 439 440 int 441 __rtems_ioctl( 442 int fd, 443 unsigned32 command, 444 void * buffer) 445 { 446 rtems_status_code rc; 447 rtems_driver_name_t *np; 448 rtems_libio_t *iop; 449 rtems_libio_ioctl_args_t args; 450 451 if (rtems_file_descriptor_type(fd)) { 452 int (*fp)(int fd, unsigned32 command, void *buffer); 453 454 fp = handlers[rtems_file_descriptor_type_index(fd)].ioctl; 455 if (fp == NULL) { 456 errno = EBADF; 457 return -1; 458 } 459 return (*fp)(fd, command, buffer); 460 } 461 iop = rtems_libio_iop(fd); 462 rtems_libio_check_fd(fd); 463 464 np = iop->driver; 465 466 args.iop = iop; 467 args.command = command; 468 args.buffer = buffer; 469 470 rc = rtems_io_control(np->major, np->minor, (void *) &args); 471 472 if (rc != RTEMS_SUCCESSFUL) 473 return rtems_libio_errno(rc); 474 475 return args.ioctl_return; 476 } 477 478 /* 479 * internal only?? 480 */ 481 482 483 int 484 __rtems_lseek( 485 int fd, 486 rtems_libio_offset_t offset, 487 int whence 488 ) 489 { 490 rtems_libio_t *iop; 491 492 if (rtems_file_descriptor_type(fd)) { 493 int (*fp)(int fd, rtems_libio_offset_t offset, int whence); 494 495 fp = handlers[rtems_file_descriptor_type_index(fd)].lseek; 496 if (fp == NULL) { 497 errno = EBADF; 498 return -1; 499 } 500 return (*fp)(fd, offset, whence); 501 } 502 iop = rtems_libio_iop(fd); 503 rtems_libio_check_fd(fd); 504 505 switch (whence) 506 { 507 case SEEK_SET: 508 iop->offset = offset; 509 break; 510 511 case SEEK_CUR: 512 iop->offset += offset; 513 break; 514 515 case SEEK_END: 516 iop->offset = iop->size - offset; 517 break; 518 519 default: 520 errno = EINVAL; 521 return -1; 522 } 523 return 0; 524 } 290 } 291 292 rtems_semaphore_release( rtems_libio_semaphore ); 293 294 return result; 295 } -
c/src/exec/libcsupport/src/malloc.c
rcd3fb80 r07a3253d 136 136 #ifdef MALLOC_STATS 137 137 /* zero all the stats */ 138 (void) memset( &rtems_malloc_stats, 0, sizeof(rtems_malloc_stats));138 (void) memset( &rtems_malloc_stats, 0, sizeof(rtems_malloc_stats) ); 139 139 #endif 140 140 … … 221 221 unsigned32 actual_size; 222 222 unsigned32 current_depth; 223 status = rtems_region_get_segment_size(RTEMS_Malloc_Heap, return_this, &actual_size); 223 status = rtems_region_get_segment_size( 224 RTEMS_Malloc_Heap, return_this, &actual_size); 224 225 MSBUMP(lifetime_allocated, actual_size); 225 current_depth = rtems_malloc_stats.lifetime_allocated - rtems_malloc_stats.lifetime_freed; 226 current_depth = rtems_malloc_stats.lifetime_allocated - 227 rtems_malloc_stats.lifetime_freed; 226 228 if (current_depth > rtems_malloc_stats.max_depth) 227 229 rtems_malloc_stats.max_depth = current_depth; … … 336 338 void malloc_dump(void) 337 339 { 338 unsigned32 allocated = rtems_malloc_stats.lifetime_allocated - rtems_malloc_stats.lifetime_freed; 340 unsigned32 allocated = rtems_malloc_stats.lifetime_allocated - 341 rtems_malloc_stats.lifetime_freed; 339 342 340 343 printf("Malloc stats\n"); 341 printf(" avail:%uk allocated:%uk (%d%%) max:%uk (%d%%) lifetime:%Luk freed:%Luk\n", 344 printf(" avail:%uk allocated:%uk (%d%%) " 345 "max:%uk (%d%%) lifetime:%Luk freed:%Luk\n", 342 346 (unsigned int) rtems_malloc_stats.space_available / 1024, 343 347 (unsigned int) allocated / 1024, -
c/src/exec/libcsupport/src/newlibc.c
rcd3fb80 r07a3253d 1 2 /* 1 /* 2 * Implementation of hooks for the CYGNUS newlib libc 3 * These hooks set things up so that: 4 * + '_REENT' is switched at task switch time. 5 * 3 6 * COPYRIGHT (c) 1994 by Division Incorporated 4 7 * … … 6 9 * found in the file LICENSE in this distribution or at 7 10 * http://www.OARcorp.com/rtems/license.html. 8 *9 * Description:10 * Implementation of hooks for the CYGNUS newlib libc11 * These hooks set things up so that:12 * '_REENT' is switched at task switch time.13 *14 *15 * TODO:16 *17 * NOTE:18 11 * 19 12 * $Id$ … … 48 41 #endif 49 42 50 #include "internal.h" 43 /* 44 * Private routines 45 */ 46 47 void MY_task_set_note( 48 rtems_tcb *tcb, 49 rtems_unsigned32 notepad, 50 rtems_unsigned32 note 51 ); 52 53 rtems_unsigned32 MY_task_get_note( 54 rtems_tcb *tcb, 55 rtems_unsigned32 notepad 56 ); 57 51 58 52 59 #define LIBC_NOTEPAD RTEMS_NOTEPAD_LAST … … 305 312 &libc_extension, &extension_id); 306 313 if (rc != RTEMS_SUCCESSFUL) 307 rtems_fatal_error_occurred( rc);314 rtems_fatal_error_occurred( rc ); 308 315 309 316 libc_reentrant = reentrant; … … 354 361 /* #if !defined(RTEMS_UNIX) && !defined(__GO32__) && !defined(_AM29K) */ 355 362 #if !defined(RTEMS_UNIX) && !defined(_AM29K) 363 #if !defined(pc386) 356 364 void _exit(int status) 357 365 { … … 359 367 rtems_shutdown_executive(status); 360 368 } 369 #endif 370 361 371 #else 362 372 … … 427 437 428 438 429 #endif 439 /* 440 * Newlib Interface Support 441 * 442 * Routines to Access Internal RTEMS Resources without violating 443 * kernel visibility. 444 * 445 */ 446 447 void MY_task_set_note( 448 Thread_Control *the_thread, 449 unsigned32 notepad, 450 unsigned32 note 451 ) 452 { 453 RTEMS_API_Control *api; 454 455 api = the_thread->API_Extensions[ THREAD_API_RTEMS ]; 456 457 if ( api ) 458 api->Notepads[ notepad ] = note; 459 } 460 461 462 unsigned32 MY_task_get_note( 463 Thread_Control *the_thread, 464 unsigned32 notepad 465 ) 466 { 467 RTEMS_API_Control *api; 468 469 api = the_thread->API_Extensions[ THREAD_API_RTEMS ]; 470 471 return api->Notepads[ notepad ]; 472 } 473 474 void *MY_CPU_Context_FP_start( 475 void *base, 476 unsigned32 offset 477 ) 478 { 479 return _CPU_Context_Fp_start( base, offset ); 480 } 481 #endif -
c/src/exec/libcsupport/src/no_libc.c
rcd3fb80 r07a3253d 1 2 /* no_libc.h 3 * 1 /* 4 2 * This file contains stubs for the reentrancy hooks when 5 3 * an unknown C library is used. … … 18 16 19 17 #include <rtems.h> 20 #if 18 #if !defined(RTEMS_NEWLIB) && !defined(RTEMS_UNIX) 21 19 22 20 #include "libcsupport.h" 23 #include "internal.h"24 21 25 22 #include <stdlib.h> /* for free() */ 26 23 27 void 28 libc_init(int reentrant) 24 void libc_init( 25 int reentrant 26 ) 29 27 { 30 28 } … … 35 33 36 34 37 void libc_global_exit(rtems_unsigned32 code) 35 void libc_global_exit( 36 rtems_unsigned32 code 37 ) 38 38 { 39 39 } 40 40 41 void _exit(int status) 41 void _exit( 42 int status 43 ) 42 44 { 43 45 } -
c/src/exec/libcsupport/src/opendir.c
rcd3fb80 r07a3253d 2 2 * opendir() - POSIX 1003.1b - XXX 3 3 * 4 * $Id$ 4 * This was copied from Newlib 1.8.0. 5 * 6 * 7 * Copyright (c) 1983 Regents of the University of California. 8 * All rights reserved. 9 * 10 * Redistribution and use in source and binary forms, with or without 11 * modification, are permitted provided that the following conditions 12 * are met: 13 * 1. Redistributions of source code must retain the above copyright 14 * notice, this list of conditions and the following disclaimer. 15 * 2. Redistributions in binary form must reproduce the above copyright 16 * notice, this list of conditions and the following disclaimer in the 17 * documentation and/or other materials provided with the distribution. 18 * 3. All advertising materials mentioning features or use of this software 19 * must display the following acknowledgement: 20 * This product includes software developed by the University of 21 * California, Berkeley and its contributors. 22 * 4. Neither the name of the University nor the names of its contributors 23 * may be used to endorse or promote products derived from this software 24 * without specific prior written permission. 25 * 26 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 27 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 28 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 29 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 30 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 31 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 32 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 33 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 36 * SUCH DAMAGE. 5 37 */ 38 39 #if defined(LIBC_SCCS) && !defined(lint) 40 static char sccsid[] = "@(#)opendir.c 5.11 (Berkeley) 2/23/91"; 41 #endif /* LIBC_SCCS and not lint */ 6 42 7 43 #include <dirent.h> … … 10 46 #include <unistd.h> 11 47 12 DIR *opendir( 13 const char *name 14 ) 48 /* 49 * open a directory. 50 */ 51 DIR * 52 opendir(name) 53 const char *name; 15 54 { 16 return NULL; 55 register DIR *dirp; 56 register int fd; 57 58 if ((fd = open(name, 0)) == -1) 59 return NULL; 60 if (fcntl(fd, F_SETFD, 1) == -1 || 61 (dirp = (DIR *)malloc(sizeof(DIR))) == NULL) { 62 close (fd); 63 return NULL; 64 } 65 /* 66 * If CLSIZE is an exact multiple of DIRBLKSIZ, use a CLSIZE 67 * buffer that it cluster boundary aligned. 68 * Hopefully this can be a big win someday by allowing page trades 69 * to user space to be done by getdirentries() 70 */ 71 dirp->dd_buf = malloc (512); 72 dirp->dd_len = 512; 73 74 if (dirp->dd_buf == NULL) { 75 close (fd); 76 return NULL; 77 } 78 dirp->dd_fd = fd; 79 dirp->dd_loc = 0; 80 dirp->dd_seek = 0; 81 /* 82 * Set up seek point for rewinddir. 83 */ 84 return dirp; 17 85 } -
c/src/exec/libcsupport/src/readdir.c
rcd3fb80 r07a3253d 2 2 * readdir() - POSIX 1003.1b - XXX 3 3 * 4 * $Id$ 4 * This was copied from Newlib 1.8.0. 5 * 6 * 7 * Copyright (c) 1983 Regents of the University of California. 8 * All rights reserved. 9 * 10 * Redistribution and use in source and binary forms, with or without 11 * modification, are permitted provided that the following conditions 12 * are met: 13 * 1. Redistributions of source code must retain the above copyright 14 * notice, this list of conditions and the following disclaimer. 15 * 2. Redistributions in binary form must reproduce the above copyright 16 * notice, this list of conditions and the following disclaimer in the 17 * documentation and/or other materials provided with the distribution. 18 * 3. All advertising materials mentioning features or use of this software 19 * must display the following acknowledgement: 20 * This product includes software developed by the University of 21 * California, Berkeley and its contributors. 22 * 4. Neither the name of the University nor the names of its contributors 23 * may be used to endorse or promote products derived from this software 24 * without specific prior written permission. 25 * 26 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 27 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 28 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 29 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 30 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 31 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 32 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 33 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 36 * SUCH DAMAGE. 5 37 */ 38 39 #if defined(LIBC_SCCS) && !defined(lint) 40 static char sccsid[] = "@(#)readdir.c 5.7 (Berkeley) 6/1/90"; 41 #endif /* LIBC_SCCS and not lint */ 6 42 7 43 #include <dirent.h> 8 44 9 struct dirent *readdir( 10 register DIR *dirp 11 ) 12 { 13 return NULL; 45 /* 46 * get next entry in a directory. 47 */ 48 struct dirent * 49 readdir(dirp) 50 register DIR *dirp; { 51 register struct dirent *dp; 52 53 for (;;) { 54 if (dirp->dd_loc == 0) { 55 dirp->dd_size = getdents (dirp->dd_fd, 56 dirp->dd_buf, 57 dirp->dd_len); 58 59 if (dirp->dd_size <= 0) 60 return NULL; 61 } 62 if (dirp->dd_loc >= dirp->dd_size) { 63 dirp->dd_loc = 0; 64 continue; 65 } 66 dp = (struct dirent *)(dirp->dd_buf + dirp->dd_loc); 67 if ((int)dp & 03) /* bogus pointer check */ 68 return NULL; 69 if (dp->d_reclen <= 0 || 70 dp->d_reclen > dirp->dd_len + 1 - dirp->dd_loc) 71 return NULL; 72 dirp->dd_loc += dp->d_reclen; 73 if (dp->d_ino == 0) 74 continue; 75 return (dp); 76 } 14 77 } -
c/src/exec/libcsupport/src/rewinddir.c
rcd3fb80 r07a3253d 2 2 * rewinddir() - POSIX 1003.1b - XXX 3 3 * 4 * $Id$ 4 * COPYRIGHT (c) 1989-1998. 5 * On-Line Applications Research Corporation (OAR). 6 * Copyright assigned to U.S. Government, 1994. 7 * 8 * The license and distribution terms for this file may be 9 * found in the file LICENSE in this distribution or at 10 * http://www.OARcorp.com/rtems/license.html. 11 * 5 12 */ 6 13 … … 16 23 ) 17 24 { 18 errno = ENOSYS; 19 return -1; 25 off_t status; 26 27 status = lseek( dirp->dd_fd, 0, SEEK_SET ); 28 29 if( status == -1 ) 30 return; 31 32 dirp->dd_loc = 0; 33 34 20 35 } -
c/src/exec/libcsupport/src/scandir.c
rcd3fb80 r07a3253d 2 2 * scandir() - POSIX 1003.1b - XXX 3 3 * 4 * $Id$ 4 * This was copied from Newlib 1.8.0. 5 * 6 * 7 * Copyright (c) 1983 Regents of the University of California. 8 * All rights reserved. 9 * 10 * Redistribution and use in source and binary forms, with or without 11 * modification, are permitted provided that the following conditions 12 * are met: 13 * 1. Redistributions of source code must retain the above copyright 14 * notice, this list of conditions and the following disclaimer. 15 * 2. Redistributions in binary form must reproduce the above copyright 16 * notice, this list of conditions and the following disclaimer in the 17 * documentation and/or other materials provided with the distribution. 18 * 3. All advertising materials mentioning features or use of this software 19 * must display the following acknowledgement: 20 * This product includes software developed by the University of 21 * California, Berkeley and its contributors. 22 * 4. Neither the name of the University nor the names of its contributors 23 * may be used to endorse or promote products derived from this software 24 * without specific prior written permission. 25 * 26 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 27 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 28 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 29 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 30 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 31 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 32 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 33 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 36 * SUCH DAMAGE. 37 */ 38 39 #if defined(LIBC_SCCS) && !defined(lint) 40 static char sccsid[] = "@(#)scandir.c 5.10 (Berkeley) 2/23/91"; 41 #endif /* LIBC_SCCS and not lint */ 42 43 /* 44 * Scan the directory dirname calling select to make a list of selected 45 * directory entries then sort using qsort and compare routine dcomp. 46 * Returns the number of entries and a pointer to a list of pointers to 47 * struct dirent (through namelist). Returns -1 if there were any errors. 5 48 */ 6 49 … … 10 53 #include <stdlib.h> 11 54 #include <string.h> 12 #include <errno.h>13 55 14 int scandir( 15 const char *dirname, 16 struct dirent ***namelist, 17 int (*select)(struct dirent *), 18 int (*dcomp)(const void *, const void *) 19 ) 56 /* 57 * The DIRSIZ macro gives the minimum record length which will hold 58 * the directory entry. This requires the amount of space in struct dirent 59 * without the d_name field, plus enough space for the name with a terminating 60 * null byte (dp->d_namlen+1), rounded up to a 4 byte boundary. 61 */ 62 #undef DIRSIZ 63 /* 64 #define DIRSIZ(dp) \ 65 ((sizeof (struct dirent) - (MAXNAMLEN+1)) + (((dp)->d_namlen+1 + 3) &~ 3)) 66 */ 67 68 #define DIRSIZ(dp) \ 69 ((sizeof (struct dirent) - (NAME_MAX+1)) + (((dp)->d_namlen+1 + 3) &~ 3)) 70 71 #ifndef __P 72 #define __P(args) () 73 #endif 74 75 int 76 scandir(dirname, namelist, select, dcomp) 77 const char *dirname; 78 struct dirent ***namelist; 79 int (*select) __P((struct dirent *)); 80 int (*dcomp) __P((const void *, const void *)); 20 81 { 21 errno = ENOSYS; 22 return -1; 82 register struct dirent *d, *p, **names; 83 register size_t nitems; 84 struct stat stb; 85 long arraysz; 86 DIR *dirp; 87 88 if ((dirp = opendir(dirname)) == NULL) 89 return(-1); 90 if (fstat(dirp->dd_fd, &stb) < 0) 91 return(-1); 92 93 /* 94 * estimate the array size by taking the size of the directory file 95 * and dividing it by a multiple of the minimum size entry. 96 */ 97 arraysz = (stb.st_size / 24); 98 names = (struct dirent **)malloc(arraysz * sizeof(struct dirent *)); 99 if (names == NULL) 100 return(-1); 101 102 nitems = 0; 103 while ((d = readdir(dirp)) != NULL) { 104 if (select != NULL && !(*select)(d)) 105 continue; /* just selected names */ 106 /* 107 * Make a minimum size copy of the data 108 */ 109 p = (struct dirent *)malloc(DIRSIZ(d)); 110 if (p == NULL) 111 return(-1); 112 p->d_ino = d->d_ino; 113 p->d_reclen = d->d_reclen; 114 p->d_namlen = d->d_namlen; 115 bcopy(d->d_name, p->d_name, p->d_namlen + 1); 116 /* 117 * Check to make sure the array has space left and 118 * realloc the maximum size. 119 */ 120 if (++nitems >= arraysz) { 121 if (fstat(dirp->dd_fd, &stb) < 0) 122 return(-1); /* just might have grown */ 123 arraysz = stb.st_size / 12; 124 names = (struct dirent **)realloc((char *)names, 125 arraysz * sizeof(struct dirent *)); 126 if (names == NULL) 127 return(-1); 128 } 129 names[nitems-1] = p; 130 } 131 closedir(dirp); 132 if (nitems && dcomp != NULL){ 133 qsort(names, nitems, sizeof(struct dirent *), dcomp); 134 } 135 *namelist = names; 136 return(nitems); 23 137 } 138 139 /* 140 * Alphabetic order comparison routine for those who want it. 141 */ 142 int 143 alphasort(d1, d2) 144 const void *d1; 145 const void *d2; 146 { 147 return(strcmp((*(struct dirent **)d1)->d_name, 148 (*(struct dirent **)d2)->d_name)); 149 } -
c/src/exec/libcsupport/src/seekdir.c
rcd3fb80 r07a3253d 2 2 * seekdir() - POSIX 1003.1b - XXX 3 3 * 4 * $Id$ 4 * COPYRIGHT (c) 1989-1998. 5 * On-Line Applications Research Corporation (OAR). 6 * Copyright assigned to U.S. Government, 1994. 7 * 8 * The license and distribution terms for this file may be 9 * found in the file LICENSE in this distribution or at 10 * http://www.OARcorp.com/rtems/license.html. 11 * 5 12 */ 6 13 … … 13 20 14 21 void seekdir( 15 DIR *dirp,16 long loc22 DIR *dirp, 23 long loc 17 24 ) 18 25 { 19 errno = ENOSYS; 20 return -1; 26 off_t status; 27 28 status = lseek( dirp->dd_fd, loc, SEEK_SET ); 29 30 /* 31 * This is not a nice way to error out, but we have no choice here. 32 */ 33 if( status == -1 ) 34 return; 35 36 dirp->dd_loc = 0; 37 21 38 } -
c/src/exec/libcsupport/src/tcdrain.c
rcd3fb80 r07a3253d 1 1 /* 2 * This file contains the RTEMS implementation of the POSIX API 3 * routines tcdrain. 2 * tcdrain() - POSIX 1003.1b 7.2.2 - Line Control Functions 3 * 4 * COPYRIGHT (c) 1989-1998. 5 * On-Line Applications Research Corporation (OAR). 6 * Copyright assigned to U.S. Government, 1994. 7 * 8 * The license and distribution terms for this file may be 9 * found in the file LICENSE in this distribution or at 10 * http://www.OARcorp.com/rtems/license.html. 4 11 * 5 12 * $Id$ 6 *7 13 */ 8 14 … … 14 20 #include <errno.h> 15 21 #include <termios.h> 22 #include <sys/ioctl.h> 16 23 17 #include "internal.h"18 24 #include "libio.h" 19 25 20 int 21 tcdrain(int fd) 26 int tcdrain( 27 int fd 28 ) 22 29 { 23 return __rtems_ioctl(fd,RTEMS_IO_TCDRAIN,0);30 return ioctl( fd, RTEMS_IO_TCDRAIN, 0 ); 24 31 } 25 32 -
c/src/exec/libcsupport/src/telldir.c
rcd3fb80 r07a3253d 2 2 * telldir() - XXX 3 3 * 4 * $Id$ 4 * COPYRIGHT (c) 1989-1998. 5 * On-Line Applications Research Corporation (OAR). 6 * Copyright assigned to U.S. Government, 1994. 7 * 8 * The license and distribution terms for this file may be 9 * found in the file LICENSE in this distribution or at 10 * http://www.OARcorp.com/rtems/license.html. 11 * 5 12 */ 6 13 … … 10 17 #include <stdlib.h> 11 18 #include <unistd.h> 12 #include <errno.h>13 19 14 #include <rtems.h>15 #include "libio.h" 20 #include "libio_.h" 21 16 22 17 23 long telldir( … … 19 25 ) 20 26 { 21 errno = ENOSYS; 22 return -1; 27 rtems_libio_t *iop; 28 29 /* 30 * Get the file control block structure associated with the file descriptor 31 */ 32 33 iop = rtems_libio_iop( dirp->dd_fd ); 34 35 if (iop == NULL) 36 assert(0); 37 38 return (long)( iop->offset ); 23 39 } -
c/src/exec/libcsupport/src/unixlibc.c
rcd3fb80 r07a3253d 1 1 /* 2 2 * $Id$ 3 * UNIX Port C Library Support 4 * 5 * COPYRIGHT (c) 1989-1998. 6 * On-Line Applications Research Corporation (OAR). 7 * Copyright assigned to U.S. Government, 1994. 8 * 9 * The license and distribution terms for this file may be 10 * found in the file LICENSE in this distribution or at 11 * http://www.OARcorp.com/rtems/license.html. 12 * 3 13 */ 4 14 -
c/src/exec/posix/include/sys/Makefile.in
rcd3fb80 r07a3253d 10 10 11 11 #H_PIECES=utsname 12 H_PIECES= 12 H_PIECES=utime ioctl 13 13 H_FILES=$(H_PIECES:%=$(srcdir)/%.h) 14 14 -
c/src/exec/posix/src/getpid.c
rcd3fb80 r07a3253d 21 21 return _Objects_Local_node; 22 22 } 23 24 /* 25 * _getpid_r 26 * 27 * This is the Newlib dependent reentrant version of getpid(). 28 */ 29 30 #if defined(RTEMS_NEWLIB) 31 32 #include <reent.h> 33 34 pid_t _getpid_r( 35 struct _reent *ptr 36 ) 37 { 38 return getpid(); 39 } 40 #endif 41 -
c/src/exec/posix/src/psignal.c
rcd3fb80 r07a3253d 1223 1223 1224 1224 /* 1225 * _kill_r 1226 * 1227 * This is the Newlib dependent reentrant version of kill(). 1228 */ 1229 1230 #if defined(RTEMS_NEWLIB) 1231 1232 #include <reent.h> 1233 1234 int _kill_r( 1235 struct _reent *ptr, 1236 pid_t pid, 1237 int sig 1238 ) 1239 { 1240 return kill( pid, sig ); 1241 } 1242 #endif 1243 1244 /* 1225 1245 * 3.3.9 Queue a Signal to a Process, P1003.1b-1993, p. 78 1226 1246 */ -
c/src/exec/posix/sys/Makefile.in
rcd3fb80 r07a3253d 10 10 11 11 #H_PIECES=utsname 12 H_PIECES= 12 H_PIECES=utime ioctl 13 13 H_FILES=$(H_PIECES:%=$(srcdir)/%.h) 14 14 -
c/src/exec/sapi/src/io.c
rcd3fb80 r07a3253d 93 93 */ 94 94 95 #if 0 95 96 rtems_status_code rtems_io_register_name( 96 97 char *device_name, … … 125 126 return RTEMS_TOO_MANY; 126 127 } 128 #endif 127 129 128 130 /*PAGE … … 141 143 */ 142 144 145 #if 0 143 146 rtems_status_code rtems_io_lookup_name( 144 147 const char *name, … … 162 165 return RTEMS_UNSATISFIED; 163 166 } 167 #endif 164 168 165 169 -
c/src/lib/include/rtems/libio.h
rcd3fb80 r07a3253d 1 1 /* 2 * General purpose communication channel for RTEMS to allow UNIX/POSIX 3 * system call behavior on top of RTEMS IO devices. 2 * System call and file system interface definition 4 3 * 5 * TODO 6 * stat(2) 7 * unlink(2) 8 * rename(2) 4 * General purpose communication channel for RTEMS to allow UNIX/POSIX 5 * system call behavior under RTEMS. Initially this supported only 6 * IO to devices but has since been enhanced to support networking 7 * and support for mounted file systems. 8 * 9 * COPYRIGHT (c) 1989-1998. 10 * On-Line Applications Research Corporation (OAR). 11 * Copyright assigned to U.S. Government, 1994. 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.OARcorp.com/rtems/license.html. 9 16 * 10 17 * $Id$ … … 16 23 #include <sys/stat.h> 17 24 18 typedef unsigned32 rtems_libio_offset_t; 19 20 /* 21 * An open file data structure, indexed by 'fd' 22 * TODO: 23 * should really have a separate per/file data structure that this 24 * points to (eg: size, offset, driver, pathname should be in that) 25 */ 26 27 typedef struct { 28 rtems_driver_name_t *driver; 29 rtems_libio_offset_t size; /* size of file */ 30 rtems_libio_offset_t offset; /* current offset into the file */ 31 unsigned32 flags; 32 char *pathname; /* opened pathname */ 33 Objects_Id sem; 34 unsigned32 data0; /* private to "driver" */ 35 void *data1; /* ... */ 36 } rtems_libio_t; 37 38 39 /* 40 * param block for read/write 41 * Note: it must include 'offset' instead of using iop's offset since 42 * we can have multiple outstanding i/o's on a device. 25 /* 26 * Define data types which must be constructed using forward references. 27 */ 28 29 typedef struct rtems_libio_tt rtems_libio_t; 30 31 struct rtems_filesystem_location_info_tt; 32 typedef struct rtems_filesystem_location_info_tt 33 rtems_filesystem_location_info_t; 34 35 struct rtems_filesystem_mount_table_entry_tt; 36 typedef struct rtems_filesystem_mount_table_entry_tt 37 rtems_filesystem_mount_table_entry_t; 38 39 /* 40 * Valid RTEMS file types. 41 */ 42 typedef enum { 43 RTEMS_FILESYSTEM_DIRECTORY, 44 RTEMS_FILESYSTEM_DEVICE, 45 RTEMS_FILESYSTEM_HARD_LINK, 46 RTEMS_FILESYSTEM_SYM_LINK, 47 RTEMS_FILESYSTEM_MEMORY_FILE 48 } rtems_filesystem_node_types_t; 49 50 /* 51 * File Handler Operations Table 52 */ 53 54 typedef int (*rtems_filesystem_open_t)( 55 rtems_libio_t *iop, 56 const char *pathname, 57 unsigned32 flag, 58 unsigned32 mode 59 ); 60 61 typedef int (*rtems_filesystem_close_t)( 62 rtems_libio_t *iop 63 ); 64 65 typedef int (*rtems_filesystem_read_t)( 66 rtems_libio_t *iop, 67 void *buffer, 68 unsigned32 count 69 ); 70 71 typedef int (*rtems_filesystem_write_t)( 72 rtems_libio_t *iop, 73 const void *buffer, 74 unsigned32 count 75 ); 76 77 typedef int (*rtems_filesystem_ioctl_t)( 78 rtems_libio_t *iop, 79 unsigned32 command, 80 void *buffer 81 ); 82 83 typedef int (*rtems_filesystem_lseek_t)( 84 rtems_libio_t *iop, 85 off_t length, 86 int whence 87 ); 88 89 typedef int (*rtems_filesystem_fstat_t)( 90 rtems_filesystem_location_info_t *loc, 91 struct stat *buf 92 ); 93 94 typedef int (*rtems_filesystem_fchmod_t)( 95 rtems_filesystem_location_info_t *loc, 96 mode_t mode 97 ); 98 99 typedef int (*rtems_filesystem_ftruncate_t)( 100 rtems_libio_t *iop, 101 off_t length 102 ); 103 104 typedef int (*rtems_filesystem_fpathconf_t)( 105 rtems_libio_t *iop, 106 int name 107 ); 108 109 typedef int (*rtems_filesystem_fsync_t)( 110 rtems_libio_t *iop 111 ); 112 113 typedef int (*rtems_filesystem_fdatasync_t)( 114 rtems_libio_t *iop 115 ); 116 117 typedef struct { 118 rtems_filesystem_open_t open; 119 rtems_filesystem_close_t close; 120 rtems_filesystem_read_t read; 121 rtems_filesystem_write_t write; 122 rtems_filesystem_ioctl_t ioctl; 123 rtems_filesystem_lseek_t lseek; 124 rtems_filesystem_fstat_t fstat; 125 rtems_filesystem_fchmod_t fchmod; 126 rtems_filesystem_ftruncate_t ftruncate; 127 rtems_filesystem_fpathconf_t fpathconf; 128 rtems_filesystem_fsync_t fsync; 129 rtems_filesystem_fdatasync_t fdatasync; 130 } rtems_filesystem_file_handlers_r; 131 132 /* 133 * File System Operations Table 134 */ 135 136 /* 137 * XXX 138 * This routine does not allocate any space and rtems_filesystem_freenode_t 139 * is not called by the generic after calling this routine. 140 * ie. node_access does not have to contain valid data when the 141 * routine returns. 142 */ 143 144 typedef int (*rtems_filesystem_mknod_t)( 145 const char *path, /* IN */ 146 mode_t mode, /* IN */ 147 dev_t dev, /* IN */ 148 rtems_filesystem_location_info_t *pathloc /* IN/OUT */ 149 ); 150 151 /* 152 * rtems_filesystem_freenode_t must be called by the generic after 153 * calling this routine 154 */ 155 156 typedef int (*rtems_filesystem_evalpath_t)( 157 const char *pathname, /* IN */ 158 int flags, /* IN */ 159 rtems_filesystem_location_info_t *pathloc /* IN/OUT */ 160 ); 161 162 typedef int (*rtems_filesystem_evalmake_t)( 163 const char *path, /* IN */ 164 rtems_filesystem_location_info_t *pathloc, /* IN/OUT */ 165 const char **name /* OUT */ 166 ); 167 168 typedef int (*rtems_filesystem_link_t)( 169 rtems_filesystem_location_info_t *to_loc, /* IN */ 170 rtems_filesystem_location_info_t *parent_loc, /* IN */ 171 const char *name /* IN */ 172 ); 173 174 typedef int (*rtems_filesystem_unlink_t)( 175 rtems_filesystem_location_info_t *pathloc /* IN */ 176 ); 177 178 typedef int (*rtems_filesystem_chown_t)( 179 rtems_filesystem_location_info_t *pathloc, /* IN */ 180 uid_t owner, /* IN */ 181 gid_t group /* IN */ 182 ); 183 184 typedef int (*rtems_filesystem_freenode_t)( 185 rtems_filesystem_location_info_t *pathloc /* IN */ 186 ); 187 188 typedef int (*rtems_filesystem_rmnod_t)( 189 rtems_filesystem_location_info_t *pathloc /* IN */ 190 ); 191 192 typedef int (* rtems_filesystem_mount_t ) ( 193 rtems_filesystem_mount_table_entry_t *mt_entry /* in */ 194 ); 195 196 typedef int (* rtems_filesystem_fsmount_me_t )( 197 rtems_filesystem_mount_table_entry_t *mt_entry 198 ); 199 200 typedef int (* rtems_filesystem_unmount_t ) ( 201 rtems_filesystem_mount_table_entry_t *mt_entry /* in */ 202 ); 203 204 typedef int (* rtems_filesystem_fsunmount_me_t ) ( 205 rtems_filesystem_mount_table_entry_t *mt_entry /* in */ 206 ); 207 208 typedef rtems_filesystem_node_types_t (* rtems_filesystem_node_type_t) ( 209 rtems_filesystem_location_info_t *pathloc /* in */ 210 ); 211 212 typedef int (* rtems_filesystem_utime_t)( 213 rtems_filesystem_location_info_t *pathloc, /* IN */ 214 time_t actime, /* IN */ 215 time_t modtime /* IN */ 216 ); 217 218 typedef int (*rtems_filesystem_evaluate_link_t)( 219 rtems_filesystem_location_info_t *pathloc, /* IN/OUT */ 220 int flags /* IN */ 221 ); 222 223 typedef int (*rtems_filesystem_symlink_t)( 224 rtems_filesystem_location_info_t *loc, /* IN */ 225 const char *link_name, /* IN */ 226 const char *node_name 227 ); 228 229 typedef int (*rtems_filesystem_readlink_t)( 230 rtems_filesystem_location_info_t *loc, /* IN */ 231 char *buf, /* OUT */ 232 size_t bufsize 233 ); 234 235 /* 236 * operations table that must be defined for every file system. 237 */ 238 239 /* 240 * File system types 241 */ 242 typedef struct { 243 rtems_filesystem_evalpath_t evalpath; 244 rtems_filesystem_evalmake_t evalformake; 245 rtems_filesystem_link_t link; 246 rtems_filesystem_unlink_t unlink; 247 rtems_filesystem_node_type_t node_type; 248 rtems_filesystem_mknod_t mknod; 249 rtems_filesystem_rmnod_t rmnod; 250 rtems_filesystem_chown_t chown; 251 rtems_filesystem_freenode_t freenod; 252 rtems_filesystem_mount_t mount; 253 rtems_filesystem_fsmount_me_t fsmount_me; 254 rtems_filesystem_unmount_t unmount; 255 rtems_filesystem_fsunmount_me_t fsunmount_me; 256 rtems_filesystem_utime_t utime; 257 rtems_filesystem_evaluate_link_t eval_link; 258 rtems_filesystem_symlink_t symlink; 259 rtems_filesystem_readlink_t readlink; 260 } rtems_filesystem_operations_table; 261 262 #define IMFS_FILE_SYSTEM IMFS_ops 263 extern rtems_filesystem_operations_table IMFS_ops; 264 265 266 /* 267 * Structure used to determine a location/filesystem in the tree. 268 */ 269 270 struct rtems_filesystem_location_info_tt 271 { 272 void *node_access; 273 rtems_filesystem_file_handlers_r *handlers; 274 rtems_filesystem_operations_table *ops; 275 rtems_filesystem_mount_table_entry_t *mt_entry; 276 }; 277 278 /* 279 * Structure used to contain file system specific information which 280 * is required to support fpathconf(). 281 */ 282 283 typedef struct { 284 int link_max; 285 int max_canon; 286 int max_input; 287 int name_max; 288 int path_max; 289 int pipe_buf; 290 int posix_async_io; 291 int posix_chown_restrictions; 292 int posix_no_trunc; 293 int posix_prio_io; 294 int posix_sync_io; 295 int posix_vdisable; 296 } rtems_filesystem_limits_and_options_t; 297 298 /* 299 * Structure for a mount table entry. 300 */ 301 302 struct rtems_filesystem_mount_table_entry_tt{ 303 Chain_Node Node; 304 rtems_filesystem_location_info_t mt_point_node; 305 rtems_filesystem_location_info_t mt_fs_root; 306 int options; 307 void *fs_info; 308 309 rtems_filesystem_limits_and_options_t pathconf_limits_and_options; 310 311 /* 312 * When someone adds a mounted filesystem on a real device, 313 * this will need to be used. 314 * 315 * The best option long term for this is probably an open file descriptor. 316 */ 317 char *dev; 318 }; 319 320 /* 321 * Valid RTEMS file systems options 322 */ 323 324 typedef enum 325 { 326 RTEMS_FILESYSTEM_READ_ONLY, 327 RTEMS_FILESYSTEM_READ_WRITE_ONLY, 328 RTEMS_FILESYSTEM_BAD_OPTIONS 329 } rtems_filesystem_options_t; 330 331 332 /* 333 * An open file data structure, indexed by 'fd' 334 * TODO: 335 * should really have a separate per/file data structure that this 336 * points to (eg: size, offset, driver, pathname should be in that) 337 */ 338 339 struct rtems_libio_tt { 340 rtems_driver_name_t *driver; 341 off_t size; /* size of file */ 342 off_t offset; /* current offset into file */ 343 unsigned32 flags; 344 rtems_filesystem_location_info_t pathinfo; 345 Objects_Id sem; 346 unsigned32 data0; /* private to "driver" */ 347 void *data1; /* ... */ 348 void *file_info; /* used by file handlers */ 349 rtems_filesystem_file_handlers_r *handlers; /* type specific handlers */ 350 }; 351 352 /* 353 * param block for read/write 354 * Note: it must include 'offset' instead of using iop's offset since 355 * we can have multiple outstanding i/o's on a device. 43 356 */ 44 357 45 358 typedef struct { 46 359 rtems_libio_t *iop; 47 rtems_libio_offset_toffset;360 off_t offset; 48 361 unsigned8 *buffer; 49 362 unsigned32 count; … … 53 366 54 367 /* 55 * param block for open/close368 * param block for open/close 56 369 */ 57 370 … … 63 376 64 377 /* 65 * param block for ioctl378 * param block for ioctl 66 379 */ 67 380 … … 73 386 } rtems_libio_ioctl_args_t; 74 387 75 76 /* 77 * Values for 'flag' 388 /* 389 * Values for 'flag' 78 390 */ 79 391 … … 85 397 #define LIBIO_FLAGS_APPEND 0x0200 /* all writes append */ 86 398 #define LIBIO_FLAGS_CREATE 0x0400 /* create file */ 399 #define LIBIO_FLAGS_CLOSE_ON_EXEC 0x0800 /* close on process exec() */ 87 400 88 401 #define LIBIO_FLAGS_READ_WRITE (LIBIO_FLAGS_READ | LIBIO_FLAGS_WRITE) 89 402 403 90 404 void rtems_libio_init(void); 91 405 92 int __rtems_open(const char *pathname, unsigned32 flag, unsigned32 mode); 93 int __rtems_close(int fd); 94 int __rtems_read(int fd, void *buffer, unsigned32 count); 95 int __rtems_write(int fd, const void *buffer, unsigned32 count); 96 int __rtems_ioctl(int fd, unsigned32 command, void *buffer); 97 int __rtems_lseek(int fd, rtems_libio_offset_t offset, int whence); 98 int __rtems_fstat(int _fd, struct stat* _sbuf); 99 100 /* 101 * External I/O handlers 102 */ 103 typedef struct { 104 int (*open)(const char *pathname, unsigned32 flag, unsigned32 mode); 105 int (*close)(int fd); 106 int (*read)(int fd, void *buffer, unsigned32 count); 107 int (*write)(int fd, const void *buffer, unsigned32 count); 108 int (*ioctl)(int fd, unsigned32 command, void *buffer); 109 int (*lseek)(int fd, rtems_libio_offset_t offset, int whence); 406 /* 407 * External I/O handlers 408 */ 409 410 typedef int (*rtems_libio_open_t)( 411 const char *pathname, 412 unsigned32 flag, 413 unsigned32 mode 414 ); 415 416 typedef int (*rtems_libio_close_t)( 417 int fd 418 ); 419 420 typedef int (*rtems_libio_read_t)( 421 int fd, 422 void *buffer, 423 unsigned32 count 424 ); 425 426 typedef int (*rtems_libio_write_t)( 427 int fd, 428 const void *buffer, 429 unsigned32 count 430 ); 431 432 typedef int (*rtems_libio_ioctl_t)( 433 int fd, 434 unsigned32 command, 435 void *buffer 436 ); 437 438 typedef int (*rtems_libio_lseek_t)( 439 int fd, 440 off_t offset, 441 int whence 442 ); 443 444 typedef struct { 445 rtems_libio_open_t open; 446 rtems_libio_close_t close; 447 rtems_libio_read_t read; 448 rtems_libio_write_t write; 449 rtems_libio_ioctl_t ioctl; 450 rtems_libio_lseek_t lseek; 110 451 } rtems_libio_handler_t; 111 452 112 void rtems_register_libio_handler(int handler_flag, 113 const rtems_libio_handler_t *handler); 453 /* 454 * Register a set of external handlers 455 */ 456 457 void rtems_register_libio_handler( 458 int handler_flag, 459 const rtems_libio_handler_t *handler 460 ); 461 462 /* 463 * Macros to assist in management of external IO handlers. 464 */ 114 465 115 466 #define RTEMS_FILE_DESCRIPTOR_TYPE_FILE 0x0000 … … 129 480 130 481 /* 482 * The following macros are used to build up the permissions sets 483 * used to check permissions. These are similar in style to the 484 * mode_t bits and should stay compatible with them. 485 */ 486 487 #define RTEMS_LIBIO_PERMS_READ S_IROTH 488 #define RTEMS_LIBIO_PERMS_WRITE S_IWOTH 489 #define RTEMS_LIBIO_PERMS_RDWR (S_IROTH|S_IWOTH) 490 #define RTEMS_LIBIO_PERMS_EXEC S_IXOTH 491 #define RTEMS_LIBIO_PERMS_SEARCH RTEMS_LIBIO_PERMS_EXEC 492 #define RTEMS_LIBIO_PERMS_RWX S_IRWXO 493 494 /* 495 * Macros 496 */ 497 498 #define rtems_filesystem_make_dev_t( _major, _minor ) \ 499 ((((dev_t)(_major)) << 32) | (dev_t)(_minor)) 500 501 #define rtems_filesystem_split_dev_t( _dev, _major, _minor ) \ 502 do { \ 503 (_major) = (rtems_device_major_number) ((_dev) >> 32); \ 504 (_minor) = (rtems_device_minor_number) ((_dev) & 0xFFFFFFFF); \ 505 } while(0) 506 507 /* 508 * Verifies that the permission flag is valid. 509 */ 510 #define rtems_libio_is_valid_perms( _perm ) \ 511 (~ ((~RTEMS_LIBIO_PERMS_RWX) & _perm )) 512 513 514 /* 515 * Prototypes for filesystem 516 */ 517 518 void rtems_filesystem_initialize( void ); 519 520 521 /* 131 522 * Callbacks from TERMIOS routines to device-dependent code 132 523 */ 524 133 525 #include <termios.h> 526 134 527 typedef struct rtems_termios_callbacks { 135 int 136 int 137 int 138 int 139 int 140 int 141 int 142 int 528 int (*firstOpen)(int major, int minor, void *arg); 529 int (*lastClose)(int major, int minor, void *arg); 530 int (*pollRead)(int minor); 531 int (*write)(int minor, const char *buf, int len); 532 int (*setAttributes)(int minor, const struct termios *t); 533 int (*stopRemoteTx)(int minor); 534 int (*startRemoteTx)(int minor); 535 int outputUsesInterrupts; 143 536 } rtems_termios_callbacks; 144 537 145 538 /* 146 * Device-independent TERMIOS routines 147 */ 539 * Device-independent TERMIOS routines 540 */ 541 148 542 void rtems_termios_initialize (void); 543 149 544 rtems_status_code rtems_termios_open ( 150 545 rtems_device_major_number major, … … 152 547 void *arg, 153 548 const rtems_termios_callbacks *callbacks 154 ); 155 rtems_status_code rtems_termios_close (void *arg); 156 rtems_status_code rtems_termios_read (void *arg); 157 rtems_status_code rtems_termios_write (void *arg); 158 rtems_status_code rtems_termios_ioctl (void *arg); 159 int rtems_termios_enqueue_raw_characters (void *ttyp, char *buf, int len); 160 int rtems_termios_dequeue_characters (void *ttyp, int len); 549 ); 550 551 rtems_status_code rtems_termios_close( 552 void *arg 553 ); 554 555 rtems_status_code rtems_termios_read( 556 void *arg 557 ); 558 559 rtems_status_code rtems_termios_write( 560 void *arg 561 ); 562 563 rtems_status_code rtems_termios_ioctl( 564 void *arg 565 ); 566 567 int rtems_termios_enqueue_raw_characters( 568 void *ttyp, 569 char *buf, 570 int len 571 ); 572 573 int rtems_termios_dequeue_characters( 574 void *ttyp, 575 int len 576 ); 577 161 578 void rtems_termios_reserve_resources( 162 579 rtems_configuration_table *configuration, … … 164 581 ); 165 582 583 int unmount( 584 const char *mount_path 585 ); 586 587 int mount( 588 rtems_filesystem_mount_table_entry_t **mt_entry, 589 rtems_filesystem_operations_table *fs_ops, 590 char *fsoptions, 591 char *device, 592 char *mount_point 593 ); 594 166 595 #endif /* _RTEMS_LIBIO_H */ -
c/src/lib/libbsp/shared/bsplibc.c
rcd3fb80 r07a3253d 23 23 /* 24 24 * Init the RTEMS libio facility to provide UNIX-like system 25 * calls for use by newlib (ie: provide __rtems_open, __rtems_close, etc)25 * calls for use by newlib (ie: provide open, close, etc) 26 26 * Uses malloc() to get area for the iops, so must be after malloc init 27 27 */ -
c/src/lib/libbsp/shared/bsppost.c
rcd3fb80 r07a3253d 23 23 error_code = 'S' << 24 | 'T' << 16; 24 24 25 if ((stdin_fd = __rtems_open("/dev/console", O_RDONLY, 0)) == -1)25 if ((stdin_fd = open("/dev/console", O_RDONLY, 0)) == -1) 26 26 rtems_fatal_error_occurred( error_code | 'D' << 8 | '0' ); 27 27 28 if ((stdout_fd = __rtems_open("/dev/console", O_WRONLY, 0)) == -1)28 if ((stdout_fd = open("/dev/console", O_WRONLY, 0)) == -1) 29 29 rtems_fatal_error_occurred( error_code | 'D' << 8 | '1' ); 30 30 31 if ((stderr_fd = __rtems_open("/dev/console", O_WRONLY, 0)) == -1)31 if ((stderr_fd = open("/dev/console", O_WRONLY, 0)) == -1) 32 32 rtems_fatal_error_occurred( error_code | 'D' << 8 | '2' ); 33 33 -
c/src/lib/libc/Makefile.in
rcd3fb80 r07a3253d 12 12 LIB=${ARCH}/${LIBNAME} 13 13 14 # define TARGET_PIECES later based on RTEMS_CPU definition 14 BASE_FS_PIECES=base_fs mount unmount ioman \ 15 libio eval 16 17 IMFS_PIECES= imfs_chown imfs_creat imfs_directory imfs_eval imfs_free \ 18 imfs_gtkn imfs_init imfs_link imfs_mknod imfs_mount imfs_fchmod \ 19 imfs_rmnod imfs_unlink imfs_unmount imfs_utime imfs_ntype imfs_stat \ 20 imfs_getchild memfile deviceio imfs_handlers imfs_debug imfs_symlink \ 21 imfs_readlink 22 23 TERMIOS_PIECES= cfgetispeed cfgetospeed cfsetispeed cfsetospeed \ 24 tcgetattr tcsetattr tcdrain termios 25 26 SYSTEM_CALL_PIECES=\ 27 open close read write lseek ioctl \ 28 mkdir mknod mkfifo rmdir chdir \ 29 chmod fchmod chown \ 30 link unlink umask ftruncate utime \ 31 fstat fcntl fpathconf getdents \ 32 fsync fdatasync pipe dup dup2 \ 33 symlink readlink 34 35 DIRECTORY_SCAN_PIECES=\ 36 opendir closedir readdir rewinddir scandir seekdir telldir 37 38 LIBC_GLUE_PIECES=\ 39 malloc __brk __sbrk \ 40 __gettod __times \ 41 truncate access stat pathconf \ 42 newlibc no_libc unixlibc hosterr 15 43 16 44 # C and C++ source names, if any, go here -- minus the .c or .cc 17 C_PIECES=__times _execve malloc syscalls \ 18 no_libc support libio hosterr tcattr tcdrain \ 19 cfiospeed termios $(TARGET_PIECES) 45 C_PIECES=\ 46 $(LIBC_GLUE_PIECES) \ 47 $(TERMIOS_PIECES) \ 48 $(SYSTEM_CALL_PIECES) \ 49 $(DIRECTORY_SCAN_PIECES) \ 50 $(BASE_FS_PIECES) \ 51 $(IMFS_PIECES) 52 20 53 C_FILES=$(C_PIECES:%=%.c) 21 54 C_O_FILES=$(C_PIECES:%=${ARCH}/%.o) … … 24 57 SYS_H_FILES= 25 58 RTEMS_H_FILES=$(srcdir)/libio.h 26 PRIVATE_H_FILES=$(srcdir)/internal.h27 59 28 60 INSTALLED_H_FILES=$(srcdir)/libio.h $(srcdir)/libcsupport.h 29 SRCS=$(C_FILES) $(H_FILES) $(SYS_H_FILES) $(RTEMS_H_FILES) $(PRIVATE_H_FILES)61 SRCS=$(C_FILES) $(H_FILES) $(SYS_H_FILES) $(RTEMS_H_FILES) 30 62 OBJS=$(C_O_FILES) 31 63 32 64 include $(RTEMS_ROOT)/make/custom/$(RTEMS_BSP).cfg 33 65 include $(RTEMS_ROOT)/make/lib.cfg 34 35 ifeq ($(RTEMS_CPU),unix)36 TARGET_PIECES=unixlibc37 else38 TARGET_PIECES=__brk __gettod newlibc newlibif newlibifr \39 getdents readdir opendir closedir rewinddir scandir seekdir telldir40 endif41 66 42 67 # -
c/src/lib/libc/__brk.c
rcd3fb80 r07a3253d 1 #if !defined(RTEMS_UNIX)2 3 1 /* 4 * RTEMS "Broken" __brk /__sbrkImplementation2 * RTEMS "Broken" __brk Implementation 5 3 * 6 * NOTE: sbrk is BSP provided. 7 * 4 * NOTE: sbrk() is provided by each BSP. 8 5 * 9 6 * COPYRIGHT (c) 1989-1998. … … 19 16 20 17 #include <rtems.h> 18 #if !defined(RTEMS_UNIX) 21 19 22 #include <signal.h>23 20 #include <errno.h> 24 #include <sys/types.h>25 #ifdef RTEMS_NEWLIB26 #include <reent.h>27 #endif28 #include <unistd.h>29 21 30 /* we use RTEMS for memory management. We don't need sbrk */ 31 32 void * __sbrk(int incr) 33 { 34 errno = EINVAL; 35 return (void *)0; 36 } 37 38 int __brk( const void *endds ) 22 int __brk( 23 const void *endds 24 ) 39 25 { 40 26 errno = EINVAL; 41 27 return -1; 42 28 } 43 44 29 #endif -
c/src/lib/libc/__gettod.c
rcd3fb80 r07a3253d 1 #define __RTEMS_VIOLATE_KERNEL_VISIBILITY__2 3 #include <rtems.h>4 5 #if !defined(RTEMS_UNIX)6 1 /* 7 * RTEMS gettimeofday Implementation 8 * 2 * gettimeofday() - SVR4 and BSD4.3 extension required by Newlib 9 3 * 10 4 * COPYRIGHT (c) 1989-1998. … … 19 13 */ 20 14 15 #define __RTEMS_VIOLATE_KERNEL_VISIBILITY__ 16 17 #include <rtems.h> 18 19 #if !defined(RTEMS_UNIX) 21 20 #ifdef RTEMS_NEWLIB 22 21 #include <sys/reent.h> … … 62 61 * NOTE: XXX this routine should really be in the executive proper. 63 62 */ 64 63 65 64 rtems_interrupt_disable(level); 66 65 seconds = _TOD_Seconds_since_epoch; … … 87 86 } 88 87 89 #if defined(RTEMS_NEWLIB) 88 #if defined(RTEMS_NEWLIB) 90 89 91 90 /* … … 103 102 104 103 /* 105 * "System call" version 104 * "System call" version 106 105 */ 107 106 -
c/src/lib/libc/__times.c
rcd3fb80 r07a3253d 1 1 /* 2 * RTEMS _times Implementation 3 * 2 * times() - POSIX 1003.1b 4.5.2 - Get Process Times 4 3 * 5 4 * COPYRIGHT (c) 1989-1998. … … 26 25 ) 27 26 { 28 rtems_status_code 29 rtems_interval ticks_since_boot;27 rtems_status_code status; 28 rtems_interval ticks; 30 29 31 30 if ( !ptms ) { … … 35 34 36 35 /* "POSIX" does not seem to allow for not having a TOD */ 37 status = rtems_clock_get( 38 RTEMS_CLOCK_GET_TICKS_SINCE_BOOT, 39 &ticks_since_boot 40 ); 36 status = rtems_clock_get( RTEMS_CLOCK_GET_TICKS_SINCE_BOOT, &ticks ); 41 37 if ( status != RTEMS_SUCCESSFUL ) { 42 38 assert( 0 ); … … 45 41 46 42 /* 47 * RTEMS has no notion of system versus user time and does 48 * not (as of 3.2.0) keep track of CPU usage on a per task basis. 43 * RTEMS has no notion of system versus user time and although 44 * a way to keep track of per task CPU usage was added since 45 * 3.6.0, this routine does not utilize it yet. 49 46 */ 50 47 51 ptms->tms_utime = ticks _since_boot;48 ptms->tms_utime = ticks; 52 49 ptms->tms_stime = 0; 53 50 ptms->tms_cutime = 0; … … 56 53 return 0; 57 54 } 55 56 /* 57 * times() 58 * 59 * times() system call wrapper for _times() above. 60 */ 58 61 59 62 clock_t times( … … 64 67 } 65 68 69 /* 70 * _times_r 71 * 72 * This is the Newlib dependent reentrant version of times(). 73 */ 74 66 75 #if defined(RTEMS_NEWLIB) 76 77 #include <reent.h> 78 67 79 clock_t _times_r( 68 80 struct _reent *ptr, … … 70 82 ) 71 83 { 72 return _times( ptms);84 return _times( ptms ); 73 85 } 74 86 #endif -
c/src/lib/libc/closedir.c
rcd3fb80 r07a3253d 2 2 * closedir() - POSIX 1003.1b - XXX 3 3 * 4 * $Id$ 4 * This was copied from Newlib 1.8.0. 5 * 6 * 7 * Copyright (c) 1983 Regents of the University of California. 8 * All rights reserved. 9 * 10 * Redistribution and use in source and binary forms, with or without 11 * modification, are permitted provided that the following conditions 12 * are met: 13 * 1. Redistributions of source code must retain the above copyright 14 * notice, this list of conditions and the following disclaimer. 15 * 2. Redistributions in binary form must reproduce the above copyright 16 * notice, this list of conditions and the following disclaimer in the 17 * documentation and/or other materials provided with the distribution. 18 * 3. All advertising materials mentioning features or use of this software 19 * must display the following acknowledgement: 20 * This product includes software developed by the University of 21 * California, Berkeley and its contributors. 22 * 4. Neither the name of the University nor the names of its contributors 23 * may be used to endorse or promote products derived from this software 24 * without specific prior written permission. 25 * 26 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 27 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 28 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 29 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 30 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 31 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 32 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 33 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 36 * SUCH DAMAGE. 5 37 */ 6 38 39 #if defined(LIBC_SCCS) && !defined(lint) 40 static char sccsid[] = "@(#)closedir.c 5.9 (Berkeley) 2/23/91"; 41 #endif /* LIBC_SCCS and not lint */ 7 42 8 43 #include <sys/types.h> … … 12 47 #include <errno.h> 13 48 14 int closedir( 15 register DIR *dirp 16 ) 49 50 #include "libio_.h" 51 52 /* 53 * close a directory. 54 */ 55 int 56 closedir(dirp) 57 register DIR *dirp; 17 58 { 18 errno = ENOSYS; 19 return -1; 59 int fd; 60 61 if ( !dirp ) 62 set_errno_and_return_minus_one( EBADF ); 63 64 fd = dirp->dd_fd; 65 dirp->dd_fd = -1; 66 dirp->dd_loc = 0; 67 (void)free((void *)dirp->dd_buf); 68 (void)free((void *)dirp); 69 return(close(fd)); 20 70 } -
c/src/lib/libc/getdents.c
rcd3fb80 r07a3253d 1 1 /* 2 * Just enough to make newlib return an error. 2 * getdents() - Get Directory Entries 3 * 4 * SVR4 and SVID extension required by Newlib readdir() family. 5 * 6 * This routine will dd_len / (sizeof dirent) directory entries relative to 7 * the current directory position index. These entries will be placed in 8 * character array pointed to by -dd_buf- 9 * 10 * COPYRIGHT (c) 1989-1998. 11 * On-Line Applications Research Corporation (OAR). 12 * Copyright assigned to U.S. Government, 1994. 13 * 14 * The license and distribution terms for this file may be 15 * found in the file LICENSE in this distribution or at 16 * http://www.OARcorp.com/rtems/license.html. 3 17 * 4 18 * $Id$ 5 19 */ 6 20 21 #include <errno.h> 22 23 #include "libio_.h" 24 7 25 int getdents( 8 int fd,9 void *buf,10 int len26 int dd_fd, 27 char *dd_buf, 28 int dd_len 11 29 ) 12 30 { 13 return -1; 31 rtems_libio_t *iop; 32 rtems_filesystem_location_info_t loc; 33 34 /* 35 * Get the file control block structure associated with the file descriptor 36 */ 37 38 iop = rtems_libio_iop( dd_fd ); 39 40 /* 41 * Make sure we are working on a directory 42 */ 43 loc = iop->pathinfo; 44 if ( !loc.ops->node_type ) 45 set_errno_and_return_minus_one( ENOTSUP ); 46 47 if ( (*loc.ops->node_type)( &loc ) != RTEMS_FILESYSTEM_DIRECTORY ) 48 set_errno_and_return_minus_one( ENOTDIR ); 49 50 /* 51 * Return the number of bytes that were actually transfered as a result 52 * of the read attempt. 53 */ 54 55 if ( !iop->handlers->read ) 56 set_errno_and_return_minus_one( ENOTSUP ); 57 58 return (*iop->handlers->read)( iop, dd_buf, dd_len ); 14 59 } -
c/src/lib/libc/hosterr.c
rcd3fb80 r07a3253d 14 14 15 15 #include <rtems.h> 16 #if defined(RTEMS_UNIX) 16 17 #include <errno.h> 17 18 18 int host_errno( void);19 int host_errno( void ); 19 20 20 21 /* 21 * copy host errno, if any to thread aware errno, if any 22 * fix_syscall_errno 23 * 24 * copy host errno, if any to thread aware errno, if any 22 25 */ 23 26 24 void fix_syscall_errno( void)27 void fix_syscall_errno( void ) 25 28 { 26 29 errno = host_errno(); 27 30 } 28 31 29 32 /* 30 * Get the host system errno, if any 31 * When using newlib (or possibly other libc's) on top of UNIX 32 * the errno returned by system calls may be unavailable due 33 * to trickery of making errno thread aware. 34 * This provides a kludge of getting at it. 33 * host_errno 34 * 35 * Get the host system errno, if any 36 * When using newlib (or possibly other libc's) on top of UNIX 37 * the errno returned by system calls may be unavailable due 38 * to trickery of making errno thread aware. 39 * This provides a kludge of getting at it. 35 40 */ 36 41 … … 39 44 int host_errno(void) 40 45 { 41 46 return errno; 42 47 } 43 48 #endif -
c/src/lib/libc/libio.c
rcd3fb80 r07a3253d 1 1 /* 2 * Provide UNIX/POSIX-like io system calls for RTEMS using the 3 * RTEMS IO manager 2 * This file contains the support infrastructure used to manage the 3 * table of integer style file descriptors used by the low level 4 * POSIX system calls like open(), read, fstat(), etc. 5 * 6 * This provides the foundation for POSIX compliant IO system calls 7 * for RTEMS. 8 * 9 * COPYRIGHT (c) 1989-1998. 10 * On-Line Applications Research Corporation (OAR). 11 * Copyright assigned to U.S. Government, 1994. 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.OARcorp.com/rtems/license.html. 4 16 * 5 17 * $Id$ 6 18 */ 7 19 8 #include <rtems.h> 9 #include <rtems/assoc.h> /* assoc.h not included by rtems.h */ 10 11 #include <stdio.h> /* O_RDONLY, et.al. */ 12 #include <fcntl.h> /* O_RDONLY, et.al. */ 13 #include <assert.h> 14 15 #if ! defined(O_NDELAY) 16 # if defined(solaris2) 17 # define O_NDELAY O_NONBLOCK 18 # elif defined(RTEMS_NEWLIB) 19 # define O_NDELAY _FNBIO 20 # endif 21 #endif 22 23 24 #include <errno.h> 25 #include <string.h> /* strcmp */ 26 #include <unistd.h> 27 #include <stdlib.h> /* calloc() */ 28 29 #include "libio.h" /* libio.h not pulled in by rtems */ 30 31 /* 32 * Semaphore to protect the io table 33 */ 34 35 Objects_Id rtems_libio_semaphore; 36 37 #define RTEMS_LIBIO_SEM rtems_build_name('L', 'B', 'I', 'O') 38 #define RTEMS_LIBIO_IOP_SEM(n) rtems_build_name('L', 'B', 'I', n) 39 40 extern unsigned32 rtems_libio_number_iops; 41 rtems_libio_t *rtems_libio_iops; 42 rtems_libio_t *rtems_libio_last_iop; 43 44 #define rtems_libio_iop(fd) ((((unsigned32)(fd)) < rtems_libio_number_iops) ? \ 45 &rtems_libio_iops[fd] : 0) 46 47 #define rtems_libio_check_fd(fd) \ 48 do { \ 49 if ((unsigned32) (fd) >= rtems_libio_number_iops) \ 50 { \ 51 errno = EBADF; \ 52 return -1; \ 53 } \ 54 } while (0) 55 56 #define rtems_libio_check_buffer(buffer) \ 57 do { \ 58 if ((buffer) == 0) \ 59 { \ 60 errno = EINVAL; \ 61 return -1; \ 62 } \ 63 } while (0) 64 65 #define rtems_libio_check_count(count) \ 66 do { \ 67 if ((count) == 0) \ 68 { \ 69 return 0; \ 70 } \ 71 } while (0) 72 73 #define rtems_libio_check_permissions(iop, flag) \ 74 do { \ 75 if (((iop)->flags & (flag)) == 0) \ 76 { \ 77 errno = EINVAL; \ 78 return -1; \ 79 } \ 80 } while (0) 81 82 /* 83 * External I/O handlers 84 * 85 * Space for all possible handlers is preallocated 86 * to speed up dispatch to external handlers. 87 */ 88 89 static rtems_libio_handler_t handlers[15]; 90 91 void 92 rtems_register_libio_handler( 93 int handler_flag, 94 const rtems_libio_handler_t *handler 95 ) 96 { 97 int handler_index = rtems_file_descriptor_type_index(handler_flag); 20 #include "libio_.h" /* libio_.h pulls in rtems */ 21 22 /* 23 * Global variables used to manage the File Descriptor Table. 24 * IOP = IO Pointer. 25 */ 26 27 rtems_id rtems_libio_semaphore; 28 rtems_libio_t *rtems_libio_iops; 29 rtems_libio_t *rtems_libio_last_iop; 30 rtems_libio_handler_t rtems_libio_handlers[15]; 31 32 /* 33 * rtems_register_libio_handler 34 * 35 * This function registers an external IO handler set. This lets 36 * other subsystems have their own versions of many of the system 37 * calls. For example, the networking code registers handlers which 38 * map the system calls for read() and write() to socket calls. 39 * 40 */ 41 42 void rtems_register_libio_handler( 43 int handler_flag, 44 const rtems_libio_handler_t *handler 45 ) 46 { 47 int handler_index = rtems_file_descriptor_type_index( handler_flag ); 48 98 49 99 50 if ((handler_index < 0) || (handler_index >= 15)) 100 51 rtems_fatal_error_occurred( RTEMS_INVALID_NUMBER ); 101 handlers[handler_index] = *handler; 102 } 103 104 /* 105 * Called by bsp startup code to init the libio area. 106 */ 107 108 void 109 rtems_libio_init(void) 110 { 111 rtems_status_code rc; 112 113 if (rtems_libio_number_iops > 0) 114 { 115 rtems_libio_iops = (rtems_libio_t *) calloc(rtems_libio_number_iops, 116 sizeof(rtems_libio_t)); 117 if (rtems_libio_iops == NULL) 118 rtems_fatal_error_occurred(RTEMS_NO_MEMORY); 119 120 rtems_libio_last_iop = rtems_libio_iops + (rtems_libio_number_iops - 1); 52 53 rtems_libio_handlers[handler_index] = *handler; 54 } 55 56 /* 57 * rtems_libio_init 58 * 59 * Called by BSP startup code to initialize the libio subsystem. 60 */ 61 62 void rtems_libio_init( void ) 63 { 64 rtems_status_code rc; 65 66 /* 67 * Allocate memory for the IOP Table 68 */ 69 70 if ( rtems_libio_number_iops > 0 ) { 71 rtems_libio_iops = 72 (rtems_libio_t *) calloc(rtems_libio_number_iops, sizeof(rtems_libio_t)); 73 74 if (rtems_libio_iops == NULL) 75 rtems_fatal_error_occurred( RTEMS_NO_MEMORY ); 76 77 rtems_libio_last_iop = rtems_libio_iops + (rtems_libio_number_iops - 1); 78 } 79 80 /* 81 * Create the binary semaphore used to provide mutual exclusion 82 * on the IOP Table. 83 */ 84 85 rc = rtems_semaphore_create( 86 RTEMS_LIBIO_SEM, 87 1, 88 RTEMS_BINARY_SEMAPHORE | RTEMS_INHERIT_PRIORITY | RTEMS_PRIORITY, 89 RTEMS_NO_PRIORITY, 90 &rtems_libio_semaphore 91 ); 92 if ( rc != RTEMS_SUCCESSFUL ) 93 rtems_fatal_error_occurred( rc ); 94 95 /* 96 * Initialize the base file system infrastructure. 97 */ 98 99 rtems_filesystem_initialize(); 100 } 101 102 /* 103 * rtems_libio_fcntl_flags 104 * 105 * Convert UNIX fnctl(2) flags to ones that RTEMS drivers understand 106 */ 107 108 rtems_assoc_t access_modes_assoc[] = { 109 { "READ", LIBIO_FLAGS_READ, O_RDONLY }, 110 { "WRITE", LIBIO_FLAGS_WRITE, O_WRONLY }, 111 { "READ/WRITE", LIBIO_FLAGS_READ_WRITE, O_RDWR }, 112 { 0, 0, 0 }, 113 }; 114 115 rtems_assoc_t status_flags_assoc[] = { 116 { "NO DELAY", LIBIO_FLAGS_NO_DELAY, O_NDELAY }, 117 { "APPEND", LIBIO_FLAGS_APPEND, O_APPEND }, 118 { "CREATE", LIBIO_FLAGS_CREATE, O_CREAT }, 119 { 0, 0, 0 }, 120 }; 121 122 unsigned32 rtems_libio_fcntl_flags( 123 unsigned32 fcntl_flags 124 ) 125 { 126 unsigned32 flags = 0; 127 unsigned32 access_modes; 128 129 /* 130 * Access mode is a small integer 131 */ 132 133 access_modes = fcntl_flags & O_ACCMODE; 134 fcntl_flags &= ~O_ACCMODE; 135 flags = rtems_assoc_local_by_remote( access_modes_assoc, access_modes ); 136 137 /* 138 * Everything else is single bits 139 */ 140 141 flags |= 142 rtems_assoc_local_by_remote_bitfield(status_flags_assoc, fcntl_flags); 143 return flags; 144 } 145 146 /* 147 * rtems_libio_allocate 148 * 149 * This routine searches the IOP Table for an unused entry. If it 150 * finds one, it returns it. Otherwise, it returns NULL. 151 */ 152 153 rtems_libio_t *rtems_libio_allocate( void ) 154 { 155 rtems_libio_t *iop; 156 rtems_status_code rc; 157 158 rtems_semaphore_obtain( rtems_libio_semaphore, RTEMS_WAIT, RTEMS_NO_TIMEOUT ); 159 160 for (iop = rtems_libio_iops; iop <= rtems_libio_last_iop; iop++) 161 if ((iop->flags & LIBIO_FLAGS_OPEN) == 0) { 162 /* 163 * Got an IOP -- create a semaphore for it. 164 */ 165 166 rc = rtems_semaphore_create( 167 RTEMS_LIBIO_IOP_SEM(iop - rtems_libio_iops), 168 1, 169 RTEMS_BINARY_SEMAPHORE | RTEMS_INHERIT_PRIORITY | RTEMS_PRIORITY, 170 RTEMS_NO_PRIORITY, 171 &iop->sem 172 ); 173 if ( rc != RTEMS_SUCCESSFUL ) 174 goto failed; 175 176 iop->flags = LIBIO_FLAGS_OPEN; 177 goto done; 178 } 179 180 failed: 181 iop = 0; 182 183 done: 184 rtems_semaphore_release( rtems_libio_semaphore ); 185 return iop; 186 } 187 188 /* 189 * rtems_libio_free 190 * 191 * This routine frees the resources associated with an IOP (file descriptor) 192 * and clears the slot in the IOP Table. 193 */ 194 195 void rtems_libio_free( 196 rtems_libio_t *iop 197 ) 198 { 199 rtems_semaphore_obtain( rtems_libio_semaphore, RTEMS_WAIT, RTEMS_NO_TIMEOUT ); 200 201 if (iop->sem) 202 rtems_semaphore_delete(iop->sem); 203 204 (void) memset(iop, 0, sizeof(*iop)); 205 206 rtems_semaphore_release( rtems_libio_semaphore ); 207 } 208 209 /* 210 * rtems_libio_is_open_files_in_fs 211 * 212 * This routine scans the entire file descriptor table to determine if the 213 * are any active file descriptors that refer to the atleast one node in the 214 * file system that we are trying to dismount. 215 * 216 * If there is at least one node in the file system referenced by the mount 217 * table entry a 1 is returned, otherwise a 0 is returned. 218 */ 219 220 int rtems_libio_is_open_files_in_fs( 221 rtems_filesystem_mount_table_entry_t * fs_mt_entry 222 ) 223 { 224 rtems_libio_t *iop; 225 int result = 0; 226 227 rtems_semaphore_obtain( rtems_libio_semaphore, RTEMS_WAIT, RTEMS_NO_TIMEOUT ); 228 229 /* 230 * Look for any active file descriptor entry. 231 */ 232 233 for ( iop=rtems_libio_iops ; iop <= rtems_libio_last_iop ; iop++ ) { 234 235 if ((iop->flags & LIBIO_FLAGS_OPEN) != 0) { 236 237 /* 238 * Check if this node is under the file system that we 239 * are trying to dismount. 240 */ 241 242 if ( iop->pathinfo.mt_entry == fs_mt_entry ) { 243 result = 1; 244 break; 245 } 121 246 } 122 123 rc = rtems_semaphore_create( 124 RTEMS_LIBIO_SEM, 125 1, 126 RTEMS_BINARY_SEMAPHORE | RTEMS_INHERIT_PRIORITY | RTEMS_PRIORITY, 127 RTEMS_NO_PRIORITY, 128 &rtems_libio_semaphore 129 ); 130 if (rc != RTEMS_SUCCESSFUL) 131 rtems_fatal_error_occurred(rc); 132 } 133 134 /* 135 * Convert RTEMS status to a UNIX errno 136 */ 137 138 rtems_assoc_t errno_assoc[] = { 139 { "OK", RTEMS_SUCCESSFUL, 0 }, 140 { "BUSY", RTEMS_RESOURCE_IN_USE, EBUSY }, 141 { "INVALID NAME", RTEMS_INVALID_NAME, EINVAL }, 142 { "NOT IMPLEMENTED", RTEMS_NOT_IMPLEMENTED, ENOSYS }, 143 { "TIMEOUT", RTEMS_TIMEOUT, ETIMEDOUT }, 144 { "NO MEMORY", RTEMS_NO_MEMORY, ENOMEM }, 145 { "NO DEVICE", RTEMS_UNSATISFIED, ENODEV }, 146 { "INVALID NUMBER", RTEMS_INVALID_NUMBER, EBADF}, 147 { "NOT RESOURCE OWNER", RTEMS_NOT_OWNER_OF_RESOURCE, EPERM}, 148 { "IO ERROR", RTEMS_IO_ERROR, EIO}, 149 { 0, 0, 0 }, 150 }; 151 152 static unsigned32 153 rtems_libio_errno(rtems_status_code code) 154 { 155 int rc; 156 157 if ((rc = rtems_assoc_remote_by_local(errno_assoc, (unsigned32) code))) 158 { 159 errno = rc; 160 return -1; 247 } 248 249 rtems_semaphore_release( rtems_libio_semaphore ); 250 251 return result; 252 } 253 254 /* 255 * rtems_libio_is_file_open 256 * 257 * This routine scans the entire file descriptor table to determine if the 258 * given file refers to an active file descriptor. 259 * 260 * If the given file is open a 1 is returned, otherwise a 0 is returned. 261 */ 262 263 int rtems_libio_is_file_open( 264 void *node_access 265 ) 266 { 267 rtems_libio_t *iop; 268 int result=0; 269 270 rtems_semaphore_obtain( rtems_libio_semaphore, RTEMS_WAIT, RTEMS_NO_TIMEOUT ); 271 272 /* 273 * Look for any active file descriptor entry. 274 */ 275 276 for ( iop=rtems_libio_iops ; iop <= rtems_libio_last_iop ; iop++ ) { 277 278 if ((iop->flags & LIBIO_FLAGS_OPEN) != 0) { 279 280 /* 281 * Check if this node is under the file system that we 282 * are trying to dismount. 283 */ 284 285 if ( iop->pathinfo.node_access == node_access ) { 286 result = 1; 287 break; 288 } 161 289 } 162 return -1; 163 } 164 165 /* 166 * Convert UNIX fnctl(2) flags to ones that RTEMS drivers understand 167 */ 168 169 rtems_assoc_t access_modes_assoc[] = { 170 { "READ", LIBIO_FLAGS_READ, O_RDONLY }, 171 { "WRITE", LIBIO_FLAGS_WRITE, O_WRONLY }, 172 { "READ/WRITE", LIBIO_FLAGS_READ_WRITE, O_RDWR }, 173 { 0, 0, 0 }, 174 }; 175 176 rtems_assoc_t status_flags_assoc[] = { 177 { "NO DELAY", LIBIO_FLAGS_NO_DELAY, O_NDELAY }, 178 { "APPEND", LIBIO_FLAGS_APPEND, O_APPEND }, 179 { "CREATE", LIBIO_FLAGS_CREATE, O_CREAT }, 180 { 0, 0, 0 }, 181 }; 182 183 static unsigned32 184 rtems_libio_fcntl_flags(unsigned32 fcntl_flags) 185 { 186 unsigned32 flags = 0; 187 unsigned32 access_modes; 188 189 /* 190 * Access mode is a small integer 191 */ 192 193 access_modes = fcntl_flags & O_ACCMODE; 194 fcntl_flags &= ~O_ACCMODE; 195 flags = rtems_assoc_local_by_remote(access_modes_assoc, access_modes); 196 197 /* 198 * Everything else is single bits 199 */ 200 201 flags |= rtems_assoc_local_by_remote_bitfield(status_flags_assoc, fcntl_flags); 202 return flags; 203 } 204 205 206 static rtems_libio_t * 207 rtems_libio_allocate(void) 208 { 209 rtems_libio_t *iop; 210 rtems_status_code rc; 211 212 rtems_semaphore_obtain(rtems_libio_semaphore, RTEMS_WAIT, RTEMS_NO_TIMEOUT); 213 214 for (iop = rtems_libio_iops; iop <= rtems_libio_last_iop; iop++) 215 if ((iop->flags & LIBIO_FLAGS_OPEN) == 0) 216 { 217 /* 218 * Got one; create a semaphore for it 219 */ 220 221 rc = rtems_semaphore_create( 222 RTEMS_LIBIO_IOP_SEM(iop - rtems_libio_iops), 223 1, 224 RTEMS_BINARY_SEMAPHORE | RTEMS_INHERIT_PRIORITY | RTEMS_PRIORITY, 225 RTEMS_NO_PRIORITY, 226 &iop->sem 227 ); 228 if (rc != RTEMS_SUCCESSFUL) 229 goto failed; 230 231 iop->flags = LIBIO_FLAGS_OPEN; 232 goto done; 233 } 234 235 failed: 236 iop = 0; 237 238 done: 239 rtems_semaphore_release(rtems_libio_semaphore); 240 return iop; 241 } 242 243 static void 244 rtems_libio_free(rtems_libio_t *iop) 245 { 246 rtems_semaphore_obtain(rtems_libio_semaphore, RTEMS_WAIT, RTEMS_NO_TIMEOUT); 247 248 if (iop->sem) 249 rtems_semaphore_delete(iop->sem); 250 (void) memset(iop, 0, sizeof(*iop)); 251 252 rtems_semaphore_release(rtems_libio_semaphore); 253 } 254 255 int 256 __rtems_open( 257 const char *pathname, 258 unsigned32 flag, 259 unsigned32 mode) 260 { 261 rtems_status_code rc; 262 rtems_libio_t *iop = 0; 263 rtems_driver_name_t *np; 264 rtems_libio_open_close_args_t args; 265 266 /* 267 * Additional external I/O handlers would be supported by 268 * adding code to pick apart the pathname appropriately. 269 * The networking code does not require changes here since 270 * network file descriptors are obtained using socket(), not 271 * open(). 272 */ 273 274 if ((rc = rtems_io_lookup_name(pathname, &np)) != RTEMS_SUCCESSFUL) 275 goto done; 276 277 iop = rtems_libio_allocate(); 278 if (iop == 0) 279 { 280 rc = RTEMS_TOO_MANY; 281 goto done; 282 } 283 284 iop->driver = np; 285 iop->pathname = (char *) pathname; 286 iop->flags |= rtems_libio_fcntl_flags(flag); 287 288 args.iop = iop; 289 args.flags = iop->flags; 290 args.mode = mode; 291 292 rc = rtems_io_open(np->major, np->minor, (void *) &args); 293 294 done: 295 296 if (rc != RTEMS_SUCCESSFUL) 297 { 298 if (iop) 299 rtems_libio_free(iop); 300 return rtems_libio_errno(rc); 301 } 302 303 return iop - rtems_libio_iops; 304 } 305 306 int 307 __rtems_close( 308 int fd 309 ) 310 { 311 rtems_status_code rc; 312 rtems_driver_name_t *np; 313 rtems_libio_t *iop; 314 rtems_libio_open_close_args_t args; 315 int status; 316 317 if (rtems_file_descriptor_type(fd)) { 318 int (*fp)(int fd); 319 320 fp = handlers[rtems_file_descriptor_type_index(fd)].close; 321 if (fp == NULL) { 322 errno = EBADF; 323 return -1; 324 } 325 status = (*fp)(fd); 326 return status; 327 } 328 iop = rtems_libio_iop(fd); 329 rtems_libio_check_fd(fd); 330 331 np = iop->driver; 332 333 args.iop = iop; 334 args.flags = 0; 335 args.mode = 0; 336 337 rc = rtems_io_close(np->major, np->minor, (void *) &args); 338 339 rtems_libio_free(iop); 340 341 if (rc != RTEMS_SUCCESSFUL) 342 return rtems_libio_errno(rc); 343 return 0; 344 } 345 346 int 347 __rtems_read( 348 int fd, 349 void * buffer, 350 unsigned32 count 351 ) 352 { 353 rtems_status_code rc; 354 rtems_driver_name_t *np; 355 rtems_libio_t *iop; 356 rtems_libio_rw_args_t args; 357 358 if (rtems_file_descriptor_type(fd)) { 359 int (*fp)(int fd, void *buffer, unsigned32 count); 360 361 fp = handlers[rtems_file_descriptor_type_index(fd)].read; 362 if (fp == NULL) { 363 errno = EBADF; 364 return -1; 365 } 366 return (*fp)(fd, buffer, count); 367 } 368 iop = rtems_libio_iop(fd); 369 rtems_libio_check_fd(fd); 370 rtems_libio_check_buffer(buffer); 371 rtems_libio_check_count(count); 372 rtems_libio_check_permissions(iop, LIBIO_FLAGS_READ); 373 374 np = iop->driver; 375 376 args.iop = iop; 377 args.offset = iop->offset; 378 args.buffer = buffer; 379 args.count = count; 380 args.flags = iop->flags; 381 args.bytes_moved = 0; 382 383 rc = rtems_io_read(np->major, np->minor, (void *) &args); 384 385 iop->offset += args.bytes_moved; 386 387 if (rc != RTEMS_SUCCESSFUL) 388 return rtems_libio_errno(rc); 389 390 return args.bytes_moved; 391 } 392 393 int 394 __rtems_write( 395 int fd, 396 const void *buffer, 397 unsigned32 count 398 ) 399 { 400 rtems_status_code rc; 401 rtems_driver_name_t *np; 402 rtems_libio_t *iop; 403 rtems_libio_rw_args_t args; 404 405 if (rtems_file_descriptor_type(fd)) { 406 int (*fp)(int fd, const void *buffer, unsigned32 count); 407 408 fp = handlers[rtems_file_descriptor_type_index(fd)].write; 409 if (fp == NULL) { 410 errno = EBADF; 411 return -1; 412 } 413 return (*fp)(fd, buffer, count); 414 } 415 iop = rtems_libio_iop(fd); 416 rtems_libio_check_fd(fd); 417 rtems_libio_check_buffer(buffer); 418 rtems_libio_check_count(count); 419 rtems_libio_check_permissions(iop, LIBIO_FLAGS_WRITE); 420 421 np = iop->driver; 422 423 args.iop = iop; 424 args.offset = iop->offset; 425 args.buffer = (void *) buffer; 426 args.count = count; 427 args.flags = iop->flags; 428 args.bytes_moved = 0; 429 430 rc = rtems_io_write(np->major, np->minor, (void *) &args); 431 432 iop->offset += args.bytes_moved; 433 434 if (rc != RTEMS_SUCCESSFUL) 435 return rtems_libio_errno(rc); 436 437 return args.bytes_moved; 438 } 439 440 int 441 __rtems_ioctl( 442 int fd, 443 unsigned32 command, 444 void * buffer) 445 { 446 rtems_status_code rc; 447 rtems_driver_name_t *np; 448 rtems_libio_t *iop; 449 rtems_libio_ioctl_args_t args; 450 451 if (rtems_file_descriptor_type(fd)) { 452 int (*fp)(int fd, unsigned32 command, void *buffer); 453 454 fp = handlers[rtems_file_descriptor_type_index(fd)].ioctl; 455 if (fp == NULL) { 456 errno = EBADF; 457 return -1; 458 } 459 return (*fp)(fd, command, buffer); 460 } 461 iop = rtems_libio_iop(fd); 462 rtems_libio_check_fd(fd); 463 464 np = iop->driver; 465 466 args.iop = iop; 467 args.command = command; 468 args.buffer = buffer; 469 470 rc = rtems_io_control(np->major, np->minor, (void *) &args); 471 472 if (rc != RTEMS_SUCCESSFUL) 473 return rtems_libio_errno(rc); 474 475 return args.ioctl_return; 476 } 477 478 /* 479 * internal only?? 480 */ 481 482 483 int 484 __rtems_lseek( 485 int fd, 486 rtems_libio_offset_t offset, 487 int whence 488 ) 489 { 490 rtems_libio_t *iop; 491 492 if (rtems_file_descriptor_type(fd)) { 493 int (*fp)(int fd, rtems_libio_offset_t offset, int whence); 494 495 fp = handlers[rtems_file_descriptor_type_index(fd)].lseek; 496 if (fp == NULL) { 497 errno = EBADF; 498 return -1; 499 } 500 return (*fp)(fd, offset, whence); 501 } 502 iop = rtems_libio_iop(fd); 503 rtems_libio_check_fd(fd); 504 505 switch (whence) 506 { 507 case SEEK_SET: 508 iop->offset = offset; 509 break; 510 511 case SEEK_CUR: 512 iop->offset += offset; 513 break; 514 515 case SEEK_END: 516 iop->offset = iop->size - offset; 517 break; 518 519 default: 520 errno = EINVAL; 521 return -1; 522 } 523 return 0; 524 } 290 } 291 292 rtems_semaphore_release( rtems_libio_semaphore ); 293 294 return result; 295 } -
c/src/lib/libc/libio.h
rcd3fb80 r07a3253d 1 1 /* 2 * General purpose communication channel for RTEMS to allow UNIX/POSIX 3 * system call behavior on top of RTEMS IO devices. 2 * System call and file system interface definition 4 3 * 5 * TODO 6 * stat(2) 7 * unlink(2) 8 * rename(2) 4 * General purpose communication channel for RTEMS to allow UNIX/POSIX 5 * system call behavior under RTEMS. Initially this supported only 6 * IO to devices but has since been enhanced to support networking 7 * and support for mounted file systems. 8 * 9 * COPYRIGHT (c) 1989-1998. 10 * On-Line Applications Research Corporation (OAR). 11 * Copyright assigned to U.S. Government, 1994. 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.OARcorp.com/rtems/license.html. 9 16 * 10 17 * $Id$ … … 16 23 #include <sys/stat.h> 17 24 18 typedef unsigned32 rtems_libio_offset_t; 19 20 /* 21 * An open file data structure, indexed by 'fd' 22 * TODO: 23 * should really have a separate per/file data structure that this 24 * points to (eg: size, offset, driver, pathname should be in that) 25 */ 26 27 typedef struct { 28 rtems_driver_name_t *driver; 29 rtems_libio_offset_t size; /* size of file */ 30 rtems_libio_offset_t offset; /* current offset into the file */ 31 unsigned32 flags; 32 char *pathname; /* opened pathname */ 33 Objects_Id sem; 34 unsigned32 data0; /* private to "driver" */ 35 void *data1; /* ... */ 36 } rtems_libio_t; 37 38 39 /* 40 * param block for read/write 41 * Note: it must include 'offset' instead of using iop's offset since 42 * we can have multiple outstanding i/o's on a device. 25 /* 26 * Define data types which must be constructed using forward references. 27 */ 28 29 typedef struct rtems_libio_tt rtems_libio_t; 30 31 struct rtems_filesystem_location_info_tt; 32 typedef struct rtems_filesystem_location_info_tt 33 rtems_filesystem_location_info_t; 34 35 struct rtems_filesystem_mount_table_entry_tt; 36 typedef struct rtems_filesystem_mount_table_entry_tt 37 rtems_filesystem_mount_table_entry_t; 38 39 /* 40 * Valid RTEMS file types. 41 */ 42 typedef enum { 43 RTEMS_FILESYSTEM_DIRECTORY, 44 RTEMS_FILESYSTEM_DEVICE, 45 RTEMS_FILESYSTEM_HARD_LINK, 46 RTEMS_FILESYSTEM_SYM_LINK, 47 RTEMS_FILESYSTEM_MEMORY_FILE 48 } rtems_filesystem_node_types_t; 49 50 /* 51 * File Handler Operations Table 52 */ 53 54 typedef int (*rtems_filesystem_open_t)( 55 rtems_libio_t *iop, 56 const char *pathname, 57 unsigned32 flag, 58 unsigned32 mode 59 ); 60 61 typedef int (*rtems_filesystem_close_t)( 62 rtems_libio_t *iop 63 ); 64 65 typedef int (*rtems_filesystem_read_t)( 66 rtems_libio_t *iop, 67 void *buffer, 68 unsigned32 count 69 ); 70 71 typedef int (*rtems_filesystem_write_t)( 72 rtems_libio_t *iop, 73 const void *buffer, 74 unsigned32 count 75 ); 76 77 typedef int (*rtems_filesystem_ioctl_t)( 78 rtems_libio_t *iop, 79 unsigned32 command, 80 void *buffer 81 ); 82 83 typedef int (*rtems_filesystem_lseek_t)( 84 rtems_libio_t *iop, 85 off_t length, 86 int whence 87 ); 88 89 typedef int (*rtems_filesystem_fstat_t)( 90 rtems_filesystem_location_info_t *loc, 91 struct stat *buf 92 ); 93 94 typedef int (*rtems_filesystem_fchmod_t)( 95 rtems_filesystem_location_info_t *loc, 96 mode_t mode 97 ); 98 99 typedef int (*rtems_filesystem_ftruncate_t)( 100 rtems_libio_t *iop, 101 off_t length 102 ); 103 104 typedef int (*rtems_filesystem_fpathconf_t)( 105 rtems_libio_t *iop, 106 int name 107 ); 108 109 typedef int (*rtems_filesystem_fsync_t)( 110 rtems_libio_t *iop 111 ); 112 113 typedef int (*rtems_filesystem_fdatasync_t)( 114 rtems_libio_t *iop 115 ); 116 117 typedef struct { 118 rtems_filesystem_open_t open; 119 rtems_filesystem_close_t close; 120 rtems_filesystem_read_t read; 121 rtems_filesystem_write_t write; 122 rtems_filesystem_ioctl_t ioctl; 123 rtems_filesystem_lseek_t lseek; 124 rtems_filesystem_fstat_t fstat; 125 rtems_filesystem_fchmod_t fchmod; 126 rtems_filesystem_ftruncate_t ftruncate; 127 rtems_filesystem_fpathconf_t fpathconf; 128 rtems_filesystem_fsync_t fsync; 129 rtems_filesystem_fdatasync_t fdatasync; 130 } rtems_filesystem_file_handlers_r; 131 132 /* 133 * File System Operations Table 134 */ 135 136 /* 137 * XXX 138 * This routine does not allocate any space and rtems_filesystem_freenode_t 139 * is not called by the generic after calling this routine. 140 * ie. node_access does not have to contain valid data when the 141 * routine returns. 142 */ 143 144 typedef int (*rtems_filesystem_mknod_t)( 145 const char *path, /* IN */ 146 mode_t mode, /* IN */ 147 dev_t dev, /* IN */ 148 rtems_filesystem_location_info_t *pathloc /* IN/OUT */ 149 ); 150 151 /* 152 * rtems_filesystem_freenode_t must be called by the generic after 153 * calling this routine 154 */ 155 156 typedef int (*rtems_filesystem_evalpath_t)( 157 const char *pathname, /* IN */ 158 int flags, /* IN */ 159 rtems_filesystem_location_info_t *pathloc /* IN/OUT */ 160 ); 161 162 typedef int (*rtems_filesystem_evalmake_t)( 163 const char *path, /* IN */ 164 rtems_filesystem_location_info_t *pathloc, /* IN/OUT */ 165 const char **name /* OUT */ 166 ); 167 168 typedef int (*rtems_filesystem_link_t)( 169 rtems_filesystem_location_info_t *to_loc, /* IN */ 170 rtems_filesystem_location_info_t *parent_loc, /* IN */ 171 const char *name /* IN */ 172 ); 173 174 typedef int (*rtems_filesystem_unlink_t)( 175 rtems_filesystem_location_info_t *pathloc /* IN */ 176 ); 177 178 typedef int (*rtems_filesystem_chown_t)( 179 rtems_filesystem_location_info_t *pathloc, /* IN */ 180 uid_t owner, /* IN */ 181 gid_t group /* IN */ 182 ); 183 184 typedef int (*rtems_filesystem_freenode_t)( 185 rtems_filesystem_location_info_t *pathloc /* IN */ 186 ); 187 188 typedef int (*rtems_filesystem_rmnod_t)( 189 rtems_filesystem_location_info_t *pathloc /* IN */ 190 ); 191 192 typedef int (* rtems_filesystem_mount_t ) ( 193 rtems_filesystem_mount_table_entry_t *mt_entry /* in */ 194 ); 195 196 typedef int (* rtems_filesystem_fsmount_me_t )( 197 rtems_filesystem_mount_table_entry_t *mt_entry 198 ); 199 200 typedef int (* rtems_filesystem_unmount_t ) ( 201 rtems_filesystem_mount_table_entry_t *mt_entry /* in */ 202 ); 203 204 typedef int (* rtems_filesystem_fsunmount_me_t ) ( 205 rtems_filesystem_mount_table_entry_t *mt_entry /* in */ 206 ); 207 208 typedef rtems_filesystem_node_types_t (* rtems_filesystem_node_type_t) ( 209 rtems_filesystem_location_info_t *pathloc /* in */ 210 ); 211 212 typedef int (* rtems_filesystem_utime_t)( 213 rtems_filesystem_location_info_t *pathloc, /* IN */ 214 time_t actime, /* IN */ 215 time_t modtime /* IN */ 216 ); 217 218 typedef int (*rtems_filesystem_evaluate_link_t)( 219 rtems_filesystem_location_info_t *pathloc, /* IN/OUT */ 220 int flags /* IN */ 221 ); 222 223 typedef int (*rtems_filesystem_symlink_t)( 224 rtems_filesystem_location_info_t *loc, /* IN */ 225 const char *link_name, /* IN */ 226 const char *node_name 227 ); 228 229 typedef int (*rtems_filesystem_readlink_t)( 230 rtems_filesystem_location_info_t *loc, /* IN */ 231 char *buf, /* OUT */ 232 size_t bufsize 233 ); 234 235 /* 236 * operations table that must be defined for every file system. 237 */ 238 239 /* 240 * File system types 241 */ 242 typedef struct { 243 rtems_filesystem_evalpath_t evalpath; 244 rtems_filesystem_evalmake_t evalformake; 245 rtems_filesystem_link_t link; 246 rtems_filesystem_unlink_t unlink; 247 rtems_filesystem_node_type_t node_type; 248 rtems_filesystem_mknod_t mknod; 249 rtems_filesystem_rmnod_t rmnod; 250 rtems_filesystem_chown_t chown; 251 rtems_filesystem_freenode_t freenod; 252 rtems_filesystem_mount_t mount; 253 rtems_filesystem_fsmount_me_t fsmount_me; 254 rtems_filesystem_unmount_t unmount; 255 rtems_filesystem_fsunmount_me_t fsunmount_me; 256 rtems_filesystem_utime_t utime; 257 rtems_filesystem_evaluate_link_t eval_link; 258 rtems_filesystem_symlink_t symlink; 259 rtems_filesystem_readlink_t readlink; 260 } rtems_filesystem_operations_table; 261 262 #define IMFS_FILE_SYSTEM IMFS_ops 263 extern rtems_filesystem_operations_table IMFS_ops; 264 265 266 /* 267 * Structure used to determine a location/filesystem in the tree. 268 */ 269 270 struct rtems_filesystem_location_info_tt 271 { 272 void *node_access; 273 rtems_filesystem_file_handlers_r *handlers; 274 rtems_filesystem_operations_table *ops; 275 rtems_filesystem_mount_table_entry_t *mt_entry; 276 }; 277 278 /* 279 * Structure used to contain file system specific information which 280 * is required to support fpathconf(). 281 */ 282 283 typedef struct { 284 int link_max; 285 int max_canon; 286 int max_input; 287 int name_max; 288 int path_max; 289 int pipe_buf; 290 int posix_async_io; 291 int posix_chown_restrictions; 292 int posix_no_trunc; 293 int posix_prio_io; 294 int posix_sync_io; 295 int posix_vdisable; 296 } rtems_filesystem_limits_and_options_t; 297 298 /* 299 * Structure for a mount table entry. 300 */ 301 302 struct rtems_filesystem_mount_table_entry_tt{ 303 Chain_Node Node; 304 rtems_filesystem_location_info_t mt_point_node; 305 rtems_filesystem_location_info_t mt_fs_root; 306 int options; 307 void *fs_info; 308 309 rtems_filesystem_limits_and_options_t pathconf_limits_and_options; 310 311 /* 312 * When someone adds a mounted filesystem on a real device, 313 * this will need to be used. 314 * 315 * The best option long term for this is probably an open file descriptor. 316 */ 317 char *dev; 318 }; 319 320 /* 321 * Valid RTEMS file systems options 322 */ 323 324 typedef enum 325 { 326 RTEMS_FILESYSTEM_READ_ONLY, 327 RTEMS_FILESYSTEM_READ_WRITE_ONLY, 328 RTEMS_FILESYSTEM_BAD_OPTIONS 329 } rtems_filesystem_options_t; 330 331 332 /* 333 * An open file data structure, indexed by 'fd' 334 * TODO: 335 * should really have a separate per/file data structure that this 336 * points to (eg: size, offset, driver, pathname should be in that) 337 */ 338 339 struct rtems_libio_tt { 340 rtems_driver_name_t *driver; 341 off_t size; /* size of file */ 342 off_t offset; /* current offset into file */ 343 unsigned32 flags; 344 rtems_filesystem_location_info_t pathinfo; 345 Objects_Id sem; 346 unsigned32 data0; /* private to "driver" */ 347 void *data1; /* ... */ 348 void *file_info; /* used by file handlers */ 349 rtems_filesystem_file_handlers_r *handlers; /* type specific handlers */ 350 }; 351 352 /* 353 * param block for read/write 354 * Note: it must include 'offset' instead of using iop's offset since 355 * we can have multiple outstanding i/o's on a device. 43 356 */ 44 357 45 358 typedef struct { 46 359 rtems_libio_t *iop; 47 rtems_libio_offset_toffset;360 off_t offset; 48 361 unsigned8 *buffer; 49 362 unsigned32 count; … … 53 366 54 367 /* 55 * param block for open/close368 * param block for open/close 56 369 */ 57 370 … … 63 376 64 377 /* 65 * param block for ioctl378 * param block for ioctl 66 379 */ 67 380 … … 73 386 } rtems_libio_ioctl_args_t; 74 387 75 76 /* 77 * Values for 'flag' 388 /* 389 * Values for 'flag' 78 390 */ 79 391 … … 85 397 #define LIBIO_FLAGS_APPEND 0x0200 /* all writes append */ 86 398 #define LIBIO_FLAGS_CREATE 0x0400 /* create file */ 399 #define LIBIO_FLAGS_CLOSE_ON_EXEC 0x0800 /* close on process exec() */ 87 400 88 401 #define LIBIO_FLAGS_READ_WRITE (LIBIO_FLAGS_READ | LIBIO_FLAGS_WRITE) 89 402 403 90 404 void rtems_libio_init(void); 91 405 92 int __rtems_open(const char *pathname, unsigned32 flag, unsigned32 mode); 93 int __rtems_close(int fd); 94 int __rtems_read(int fd, void *buffer, unsigned32 count); 95 int __rtems_write(int fd, const void *buffer, unsigned32 count); 96 int __rtems_ioctl(int fd, unsigned32 command, void *buffer); 97 int __rtems_lseek(int fd, rtems_libio_offset_t offset, int whence); 98 int __rtems_fstat(int _fd, struct stat* _sbuf); 99 100 /* 101 * External I/O handlers 102 */ 103 typedef struct { 104 int (*open)(const char *pathname, unsigned32 flag, unsigned32 mode); 105 int (*close)(int fd); 106 int (*read)(int fd, void *buffer, unsigned32 count); 107 int (*write)(int fd, const void *buffer, unsigned32 count); 108 int (*ioctl)(int fd, unsigned32 command, void *buffer); 109 int (*lseek)(int fd, rtems_libio_offset_t offset, int whence); 406 /* 407 * External I/O handlers 408 */ 409 410 typedef int (*rtems_libio_open_t)( 411 const char *pathname, 412 unsigned32 flag, 413 unsigned32 mode 414 ); 415 416 typedef int (*rtems_libio_close_t)( 417 int fd 418 ); 419 420 typedef int (*rtems_libio_read_t)( 421 int fd, 422 void *buffer, 423 unsigned32 count 424 ); 425 426 typedef int (*rtems_libio_write_t)( 427 int fd, 428 const void *buffer, 429 unsigned32 count 430 ); 431 432 typedef int (*rtems_libio_ioctl_t)( 433 int fd, 434 unsigned32 command, 435 void *buffer 436 ); 437 438 typedef int (*rtems_libio_lseek_t)( 439 int fd, 440 off_t offset, 441 int whence 442 ); 443 444 typedef struct { 445 rtems_libio_open_t open; 446 rtems_libio_close_t close; 447 rtems_libio_read_t read; 448 rtems_libio_write_t write; 449 rtems_libio_ioctl_t ioctl; 450 rtems_libio_lseek_t lseek; 110 451 } rtems_libio_handler_t; 111 452 112 void rtems_register_libio_handler(int handler_flag, 113 const rtems_libio_handler_t *handler); 453 /* 454 * Register a set of external handlers 455 */ 456 457 void rtems_register_libio_handler( 458 int handler_flag, 459 const rtems_libio_handler_t *handler 460 ); 461 462 /* 463 * Macros to assist in management of external IO handlers. 464 */ 114 465 115 466 #define RTEMS_FILE_DESCRIPTOR_TYPE_FILE 0x0000 … … 129 480 130 481 /* 482 * The following macros are used to build up the permissions sets 483 * used to check permissions. These are similar in style to the 484 * mode_t bits and should stay compatible with them. 485 */ 486 487 #define RTEMS_LIBIO_PERMS_READ S_IROTH 488 #define RTEMS_LIBIO_PERMS_WRITE S_IWOTH 489 #define RTEMS_LIBIO_PERMS_RDWR (S_IROTH|S_IWOTH) 490 #define RTEMS_LIBIO_PERMS_EXEC S_IXOTH 491 #define RTEMS_LIBIO_PERMS_SEARCH RTEMS_LIBIO_PERMS_EXEC 492 #define RTEMS_LIBIO_PERMS_RWX S_IRWXO 493 494 /* 495 * Macros 496 */ 497 498 #define rtems_filesystem_make_dev_t( _major, _minor ) \ 499 ((((dev_t)(_major)) << 32) | (dev_t)(_minor)) 500 501 #define rtems_filesystem_split_dev_t( _dev, _major, _minor ) \ 502 do { \ 503 (_major) = (rtems_device_major_number) ((_dev) >> 32); \ 504 (_minor) = (rtems_device_minor_number) ((_dev) & 0xFFFFFFFF); \ 505 } while(0) 506 507 /* 508 * Verifies that the permission flag is valid. 509 */ 510 #define rtems_libio_is_valid_perms( _perm ) \ 511 (~ ((~RTEMS_LIBIO_PERMS_RWX) & _perm )) 512 513 514 /* 515 * Prototypes for filesystem 516 */ 517 518 void rtems_filesystem_initialize( void ); 519 520 521 /* 131 522 * Callbacks from TERMIOS routines to device-dependent code 132 523 */ 524 133 525 #include <termios.h> 526 134 527 typedef struct rtems_termios_callbacks { 135 int 136 int 137 int 138 int 139 int 140 int 141 int 142 int 528 int (*firstOpen)(int major, int minor, void *arg); 529 int (*lastClose)(int major, int minor, void *arg); 530 int (*pollRead)(int minor); 531 int (*write)(int minor, const char *buf, int len); 532 int (*setAttributes)(int minor, const struct termios *t); 533 int (*stopRemoteTx)(int minor); 534 int (*startRemoteTx)(int minor); 535 int outputUsesInterrupts; 143 536 } rtems_termios_callbacks; 144 537 145 538 /* 146 * Device-independent TERMIOS routines 147 */ 539 * Device-independent TERMIOS routines 540 */ 541 148 542 void rtems_termios_initialize (void); 543 149 544 rtems_status_code rtems_termios_open ( 150 545 rtems_device_major_number major, … … 152 547 void *arg, 153 548 const rtems_termios_callbacks *callbacks 154 ); 155 rtems_status_code rtems_termios_close (void *arg); 156 rtems_status_code rtems_termios_read (void *arg); 157 rtems_status_code rtems_termios_write (void *arg); 158 rtems_status_code rtems_termios_ioctl (void *arg); 159 int rtems_termios_enqueue_raw_characters (void *ttyp, char *buf, int len); 160 int rtems_termios_dequeue_characters (void *ttyp, int len); 549 ); 550 551 rtems_status_code rtems_termios_close( 552 void *arg 553 ); 554 555 rtems_status_code rtems_termios_read( 556 void *arg 557 ); 558 559 rtems_status_code rtems_termios_write( 560 void *arg 561 ); 562 563 rtems_status_code rtems_termios_ioctl( 564 void *arg 565 ); 566 567 int rtems_termios_enqueue_raw_characters( 568 void *ttyp, 569 char *buf, 570 int len 571 ); 572 573 int rtems_termios_dequeue_characters( 574 void *ttyp, 575 int len 576 ); 577 161 578 void rtems_termios_reserve_resources( 162 579 rtems_configuration_table *configuration, … … 164 581 ); 165 582 583 int unmount( 584 const char *mount_path 585 ); 586 587 int mount( 588 rtems_filesystem_mount_table_entry_t **mt_entry, 589 rtems_filesystem_operations_table *fs_ops, 590 char *fsoptions, 591 char *device, 592 char *mount_point 593 ); 594 166 595 #endif /* _RTEMS_LIBIO_H */ -
c/src/lib/libc/malloc.c
rcd3fb80 r07a3253d 136 136 #ifdef MALLOC_STATS 137 137 /* zero all the stats */ 138 (void) memset( &rtems_malloc_stats, 0, sizeof(rtems_malloc_stats));138 (void) memset( &rtems_malloc_stats, 0, sizeof(rtems_malloc_stats) ); 139 139 #endif 140 140 … … 221 221 unsigned32 actual_size; 222 222 unsigned32 current_depth; 223 status = rtems_region_get_segment_size(RTEMS_Malloc_Heap, return_this, &actual_size); 223 status = rtems_region_get_segment_size( 224 RTEMS_Malloc_Heap, return_this, &actual_size); 224 225 MSBUMP(lifetime_allocated, actual_size); 225 current_depth = rtems_malloc_stats.lifetime_allocated - rtems_malloc_stats.lifetime_freed; 226 current_depth = rtems_malloc_stats.lifetime_allocated - 227 rtems_malloc_stats.lifetime_freed; 226 228 if (current_depth > rtems_malloc_stats.max_depth) 227 229 rtems_malloc_stats.max_depth = current_depth; … … 336 338 void malloc_dump(void) 337 339 { 338 unsigned32 allocated = rtems_malloc_stats.lifetime_allocated - rtems_malloc_stats.lifetime_freed; 340 unsigned32 allocated = rtems_malloc_stats.lifetime_allocated - 341 rtems_malloc_stats.lifetime_freed; 339 342 340 343 printf("Malloc stats\n"); 341 printf(" avail:%uk allocated:%uk (%d%%) max:%uk (%d%%) lifetime:%Luk freed:%Luk\n", 344 printf(" avail:%uk allocated:%uk (%d%%) " 345 "max:%uk (%d%%) lifetime:%Luk freed:%Luk\n", 342 346 (unsigned int) rtems_malloc_stats.space_available / 1024, 343 347 (unsigned int) allocated / 1024, -
c/src/lib/libc/newlibc.c
rcd3fb80 r07a3253d 1 2 /* 1 /* 2 * Implementation of hooks for the CYGNUS newlib libc 3 * These hooks set things up so that: 4 * + '_REENT' is switched at task switch time. 5 * 3 6 * COPYRIGHT (c) 1994 by Division Incorporated 4 7 * … … 6 9 * found in the file LICENSE in this distribution or at 7 10 * http://www.OARcorp.com/rtems/license.html. 8 *9 * Description:10 * Implementation of hooks for the CYGNUS newlib libc11 * These hooks set things up so that:12 * '_REENT' is switched at task switch time.13 *14 *15 * TODO:16 *17 * NOTE:18 11 * 19 12 * $Id$ … … 48 41 #endif 49 42 50 #include "internal.h" 43 /* 44 * Private routines 45 */ 46 47 void MY_task_set_note( 48 rtems_tcb *tcb, 49 rtems_unsigned32 notepad, 50 rtems_unsigned32 note 51 ); 52 53 rtems_unsigned32 MY_task_get_note( 54 rtems_tcb *tcb, 55 rtems_unsigned32 notepad 56 ); 57 51 58 52 59 #define LIBC_NOTEPAD RTEMS_NOTEPAD_LAST … … 305 312 &libc_extension, &extension_id); 306 313 if (rc != RTEMS_SUCCESSFUL) 307 rtems_fatal_error_occurred( rc);314 rtems_fatal_error_occurred( rc ); 308 315 309 316 libc_reentrant = reentrant; … … 354 361 /* #if !defined(RTEMS_UNIX) && !defined(__GO32__) && !defined(_AM29K) */ 355 362 #if !defined(RTEMS_UNIX) && !defined(_AM29K) 363 #if !defined(pc386) 356 364 void _exit(int status) 357 365 { … … 359 367 rtems_shutdown_executive(status); 360 368 } 369 #endif 370 361 371 #else 362 372 … … 427 437 428 438 429 #endif 439 /* 440 * Newlib Interface Support 441 * 442 * Routines to Access Internal RTEMS Resources without violating 443 * kernel visibility. 444 * 445 */ 446 447 void MY_task_set_note( 448 Thread_Control *the_thread, 449 unsigned32 notepad, 450 unsigned32 note 451 ) 452 { 453 RTEMS_API_Control *api; 454 455 api = the_thread->API_Extensions[ THREAD_API_RTEMS ]; 456 457 if ( api ) 458 api->Notepads[ notepad ] = note; 459 } 460 461 462 unsigned32 MY_task_get_note( 463 Thread_Control *the_thread, 464 unsigned32 notepad 465 ) 466 { 467 RTEMS_API_Control *api; 468 469 api = the_thread->API_Extensions[ THREAD_API_RTEMS ]; 470 471 return api->Notepads[ notepad ]; 472 } 473 474 void *MY_CPU_Context_FP_start( 475 void *base, 476 unsigned32 offset 477 ) 478 { 479 return _CPU_Context_Fp_start( base, offset ); 480 } 481 #endif -
c/src/lib/libc/no_libc.c
rcd3fb80 r07a3253d 1 2 /* no_libc.h 3 * 1 /* 4 2 * This file contains stubs for the reentrancy hooks when 5 3 * an unknown C library is used. … … 18 16 19 17 #include <rtems.h> 20 #if 18 #if !defined(RTEMS_NEWLIB) && !defined(RTEMS_UNIX) 21 19 22 20 #include "libcsupport.h" 23 #include "internal.h"24 21 25 22 #include <stdlib.h> /* for free() */ 26 23 27 void 28 libc_init(int reentrant) 24 void libc_init( 25 int reentrant 26 ) 29 27 { 30 28 } … … 35 33 36 34 37 void libc_global_exit(rtems_unsigned32 code) 35 void libc_global_exit( 36 rtems_unsigned32 code 37 ) 38 38 { 39 39 } 40 40 41 void _exit(int status) 41 void _exit( 42 int status 43 ) 42 44 { 43 45 } -
c/src/lib/libc/opendir.c
rcd3fb80 r07a3253d 2 2 * opendir() - POSIX 1003.1b - XXX 3 3 * 4 * $Id$ 4 * This was copied from Newlib 1.8.0. 5 * 6 * 7 * Copyright (c) 1983 Regents of the University of California. 8 * All rights reserved. 9 * 10 * Redistribution and use in source and binary forms, with or without 11 * modification, are permitted provided that the following conditions 12 * are met: 13 * 1. Redistributions of source code must retain the above copyright 14 * notice, this list of conditions and the following disclaimer. 15 * 2. Redistributions in binary form must reproduce the above copyright 16 * notice, this list of conditions and the following disclaimer in the 17 * documentation and/or other materials provided with the distribution. 18 * 3. All advertising materials mentioning features or use of this software 19 * must display the following acknowledgement: 20 * This product includes software developed by the University of 21 * California, Berkeley and its contributors. 22 * 4. Neither the name of the University nor the names of its contributors 23 * may be used to endorse or promote products derived from this software 24 * without specific prior written permission. 25 * 26 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 27 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 28 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 29 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 30 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 31 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 32 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 33 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 36 * SUCH DAMAGE. 5 37 */ 38 39 #if defined(LIBC_SCCS) && !defined(lint) 40 static char sccsid[] = "@(#)opendir.c 5.11 (Berkeley) 2/23/91"; 41 #endif /* LIBC_SCCS and not lint */ 6 42 7 43 #include <dirent.h> … … 10 46 #include <unistd.h> 11 47 12 DIR *opendir( 13 const char *name 14 ) 48 /* 49 * open a directory. 50 */ 51 DIR * 52 opendir(name) 53 const char *name; 15 54 { 16 return NULL; 55 register DIR *dirp; 56 register int fd; 57 58 if ((fd = open(name, 0)) == -1) 59 return NULL; 60 if (fcntl(fd, F_SETFD, 1) == -1 || 61 (dirp = (DIR *)malloc(sizeof(DIR))) == NULL) { 62 close (fd); 63 return NULL; 64 } 65 /* 66 * If CLSIZE is an exact multiple of DIRBLKSIZ, use a CLSIZE 67 * buffer that it cluster boundary aligned. 68 * Hopefully this can be a big win someday by allowing page trades 69 * to user space to be done by getdirentries() 70 */ 71 dirp->dd_buf = malloc (512); 72 dirp->dd_len = 512; 73 74 if (dirp->dd_buf == NULL) { 75 close (fd); 76 return NULL; 77 } 78 dirp->dd_fd = fd; 79 dirp->dd_loc = 0; 80 dirp->dd_seek = 0; 81 /* 82 * Set up seek point for rewinddir. 83 */ 84 return dirp; 17 85 } -
c/src/lib/libc/pipe.c
rcd3fb80 r07a3253d 1 #include <rtems.h>2 3 #if defined(RTEMS_NEWLIB)4 1 /* 5 * RTEMS Dummy _execveImplementation 6 * 2 * pipe() - POSIX 1003.1b 6.1.1 Create an Inter-Process Channel 7 3 * 8 4 * COPYRIGHT (c) 1989-1998. … … 17 13 */ 18 14 19 #include <unistd.h>20 15 #include <errno.h> 21 16 22 int _execve( 23 const char *path, 24 char *const argv[], 25 char *const environ[] 17 int pipe( 18 int filsdes[2] 26 19 ) 27 20 { … … 29 22 return -1; 30 23 } 31 #endif -
c/src/lib/libc/readdir.c
rcd3fb80 r07a3253d 2 2 * readdir() - POSIX 1003.1b - XXX 3 3 * 4 * $Id$ 4 * This was copied from Newlib 1.8.0. 5 * 6 * 7 * Copyright (c) 1983 Regents of the University of California. 8 * All rights reserved. 9 * 10 * Redistribution and use in source and binary forms, with or without 11 * modification, are permitted provided that the following conditions 12 * are met: 13 * 1. Redistributions of source code must retain the above copyright 14 * notice, this list of conditions and the following disclaimer. 15 * 2. Redistributions in binary form must reproduce the above copyright 16 * notice, this list of conditions and the following disclaimer in the 17 * documentation and/or other materials provided with the distribution. 18 * 3. All advertising materials mentioning features or use of this software 19 * must display the following acknowledgement: 20 * This product includes software developed by the University of 21 * California, Berkeley and its contributors. 22 * 4. Neither the name of the University nor the names of its contributors 23 * may be used to endorse or promote products derived from this software 24 * without specific prior written permission. 25 * 26 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 27 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 28 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 29 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 30 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 31 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 32 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 33 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 36 * SUCH DAMAGE. 5 37 */ 38 39 #if defined(LIBC_SCCS) && !defined(lint) 40 static char sccsid[] = "@(#)readdir.c 5.7 (Berkeley) 6/1/90"; 41 #endif /* LIBC_SCCS and not lint */ 6 42 7 43 #include <dirent.h> 8 44 9 struct dirent *readdir( 10 register DIR *dirp 11 ) 12 { 13 return NULL; 45 /* 46 * get next entry in a directory. 47 */ 48 struct dirent * 49 readdir(dirp) 50 register DIR *dirp; { 51 register struct dirent *dp; 52 53 for (;;) { 54 if (dirp->dd_loc == 0) { 55 dirp->dd_size = getdents (dirp->dd_fd, 56 dirp->dd_buf, 57 dirp->dd_len); 58 59 if (dirp->dd_size <= 0) 60 return NULL; 61 } 62 if (dirp->dd_loc >= dirp->dd_size) { 63 dirp->dd_loc = 0; 64 continue; 65 } 66 dp = (struct dirent *)(dirp->dd_buf + dirp->dd_loc); 67 if ((int)dp & 03) /* bogus pointer check */ 68 return NULL; 69 if (dp->d_reclen <= 0 || 70 dp->d_reclen > dirp->dd_len + 1 - dirp->dd_loc) 71 return NULL; 72 dirp->dd_loc += dp->d_reclen; 73 if (dp->d_ino == 0) 74 continue; 75 return (dp); 76 } 14 77 } -
c/src/lib/libc/rewinddir.c
rcd3fb80 r07a3253d 2 2 * rewinddir() - POSIX 1003.1b - XXX 3 3 * 4 * $Id$ 4 * COPYRIGHT (c) 1989-1998. 5 * On-Line Applications Research Corporation (OAR). 6 * Copyright assigned to U.S. Government, 1994. 7 * 8 * The license and distribution terms for this file may be 9 * found in the file LICENSE in this distribution or at 10 * http://www.OARcorp.com/rtems/license.html. 11 * 5 12 */ 6 13 … … 16 23 ) 17 24 { 18 errno = ENOSYS; 19 return -1; 25 off_t status; 26 27 status = lseek( dirp->dd_fd, 0, SEEK_SET ); 28 29 if( status == -1 ) 30 return; 31 32 dirp->dd_loc = 0; 33 34 20 35 } -
c/src/lib/libc/scandir.c
rcd3fb80 r07a3253d