forked from Imagelibrary/rtems
@@ -89,6 +89,24 @@ extern rtems_filesystem_mount_table_entry_t rtems_filesystem_null_mt_entry;
|
||||
*/
|
||||
extern rtems_filesystem_global_location_t rtems_filesystem_global_location_null;
|
||||
|
||||
/**
|
||||
* @brief Sets the iop flags to the specified flags together with
|
||||
* LIBIO_FLAGS_OPEN.
|
||||
*
|
||||
* Use this once a file descriptor allocated via rtems_libio_allocate() is
|
||||
* fully initialized.
|
||||
*
|
||||
* @param[in] iop The iop.
|
||||
* @param[in] flags The flags.
|
||||
*/
|
||||
static inline void rtems_libio_iop_flags_initialize(
|
||||
rtems_libio_t *iop,
|
||||
uint32_t flags
|
||||
)
|
||||
{
|
||||
iop->flags = LIBIO_FLAGS_OPEN | flags;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Sets the specified flags in the iop.
|
||||
*
|
||||
|
||||
@@ -26,15 +26,14 @@
|
||||
|
||||
static int duplicate_iop( rtems_libio_t *iop )
|
||||
{
|
||||
int rv = 0;
|
||||
int rv;
|
||||
int oflag;
|
||||
rtems_libio_t *diop;
|
||||
|
||||
rtems_libio_t *diop = rtems_libio_allocate();
|
||||
oflag = rtems_libio_to_fcntl_flags( iop->flags );
|
||||
diop = rtems_libio_allocate();
|
||||
|
||||
if (diop != NULL) {
|
||||
int oflag = rtems_libio_to_fcntl_flags( iop->flags );
|
||||
|
||||
rtems_libio_iop_flags_set( diop, rtems_libio_fcntl_flags( oflag ) );
|
||||
|
||||
rtems_filesystem_instance_lock( &iop->pathinfo );
|
||||
rtems_filesystem_location_clone( &diop->pathinfo, &iop->pathinfo );
|
||||
rtems_filesystem_instance_unlock( &iop->pathinfo );
|
||||
@@ -46,6 +45,10 @@ static int duplicate_iop( rtems_libio_t *iop )
|
||||
*/
|
||||
rv = (*diop->pathinfo.handlers->open_h)( diop, NULL, oflag, 0 );
|
||||
if ( rv == 0 ) {
|
||||
rtems_libio_iop_flags_initialize(
|
||||
diop,
|
||||
rtems_libio_fcntl_flags( oflag )
|
||||
);
|
||||
rv = rtems_libio_iop_to_descriptor( diop );
|
||||
} else {
|
||||
rtems_libio_free( diop );
|
||||
|
||||
@@ -116,7 +116,6 @@ rtems_libio_t *rtems_libio_allocate( void )
|
||||
iop = rtems_libio_iop_freelist;
|
||||
rtems_libio_iop_freelist = iop->data1;
|
||||
memset( iop, 0, sizeof(*iop) );
|
||||
iop->flags = LIBIO_FLAGS_OPEN;
|
||||
}
|
||||
|
||||
rtems_libio_unlock();
|
||||
|
||||
@@ -96,13 +96,16 @@ static int do_open(
|
||||
}
|
||||
}
|
||||
|
||||
rtems_libio_iop_flags_set( iop, rtems_libio_fcntl_flags( oflag ) );
|
||||
rtems_filesystem_eval_path_extract_currentloc( &ctx, &iop->pathinfo );
|
||||
rtems_filesystem_eval_path_cleanup( &ctx );
|
||||
|
||||
iop->flags = rtems_libio_fcntl_flags( oflag );
|
||||
|
||||
rv = (*iop->pathinfo.handlers->open_h)( iop, path, oflag, mode );
|
||||
|
||||
if ( rv == 0 ) {
|
||||
rtems_libio_iop_flags_set( iop, LIBIO_FLAGS_OPEN );
|
||||
|
||||
if ( truncate ) {
|
||||
rv = ftruncate( fd, 0 );
|
||||
if ( rv != 0 ) {
|
||||
|
||||
@@ -81,12 +81,12 @@ rtems_bsdnet_makeFdForSocket (void *so)
|
||||
rtems_set_errno_and_return_minus_one( ENFILE );
|
||||
|
||||
fd = rtems_libio_iop_to_descriptor(iop);
|
||||
rtems_libio_iop_flags_set(iop, LIBIO_FLAGS_READ_WRITE);
|
||||
iop->data0 = fd;
|
||||
iop->data1 = so;
|
||||
iop->pathinfo.handlers = &socket_handlers;
|
||||
iop->pathinfo.mt_entry = &rtems_filesystem_null_mt_entry;
|
||||
rtems_filesystem_location_add_to_mt_entry(&iop->pathinfo);
|
||||
rtems_libio_iop_flags_initialize(iop, LIBIO_FLAGS_READ_WRITE);
|
||||
return fd;
|
||||
}
|
||||
|
||||
|
||||
@@ -225,6 +225,7 @@ int shm_open( const char *name, int oflag, mode_t mode )
|
||||
POSIX_Shm_Control *shm;
|
||||
size_t len;
|
||||
Objects_Get_by_name_error obj_err;
|
||||
uint32_t flags;
|
||||
|
||||
if ( shm_check_oflag( oflag ) != 0 ) {
|
||||
return -1;
|
||||
@@ -275,12 +276,6 @@ int shm_open( const char *name, int oflag, mode_t mode )
|
||||
}
|
||||
|
||||
fd = rtems_libio_iop_to_descriptor( iop );
|
||||
rtems_libio_iop_flags_set( iop, LIBIO_FLAGS_CLOSE_ON_EXEC );
|
||||
if ( oflag & O_RDONLY ) {
|
||||
rtems_libio_iop_flags_set( iop, LIBIO_FLAGS_READ );
|
||||
} else {
|
||||
rtems_libio_iop_flags_set( iop, LIBIO_FLAGS_READ_WRITE );
|
||||
}
|
||||
iop->data0 = fd;
|
||||
iop->data1 = shm;
|
||||
iop->pathinfo.node_access = shm;
|
||||
@@ -288,6 +283,15 @@ int shm_open( const char *name, int oflag, mode_t mode )
|
||||
iop->pathinfo.mt_entry = &rtems_filesystem_null_mt_entry;
|
||||
rtems_filesystem_location_add_to_mt_entry( &iop->pathinfo );
|
||||
|
||||
flags = LIBIO_FLAGS_CLOSE_ON_EXEC;
|
||||
if ( oflag & O_RDONLY ) {
|
||||
flags |= LIBIO_FLAGS_READ;
|
||||
} else {
|
||||
flags |= LIBIO_FLAGS_READ_WRITE;
|
||||
}
|
||||
|
||||
rtems_libio_iop_flags_initialize( iop, flags );
|
||||
|
||||
return fd;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user