diff --git a/cpukit/include/aio.h b/cpukit/include/aio.h index 01f7ca4436..14a0ff0859 100644 --- a/cpukit/include/aio.h +++ b/cpukit/include/aio.h @@ -98,19 +98,6 @@ extern "C" { /** Request a write() */ #define LIO_WRITE 2 -/** Needed by aio_fsync() */ -#define LIO_SYNC 3 - -/* - * Constants to track return status - */ - -/** The aio operation return value has been retrieved */ -#define AIO_RETURNED 0 - -/** The aio operation return value has not been retrieved */ -#define AIO_NOTRETURNED 1 - /** * @brief Asynchronous I/O Control Block * @@ -272,7 +259,7 @@ int aio_suspend( * * 6.7.9 Asynchronous File Synchronization, P1003.1b-1993, p. 166 * - * @param[in] op O_SYNC + * @param[in] op O_SYNC or O_DSYNC * @param[in,out] aiocbp is a pointer to the asynchronous I/O control block * * @retval 0 The request was correctly enqueued. @@ -281,8 +268,7 @@ int aio_suspend( * due to temporary resource limitations. * - EBADF The aio_fildes member of the aiocb structure referenced * by the aiocbp argument is not a valid file descriptor. - * - EINVAL A value of op other than O_SYNC was specified. - * The current implemetation only supports O_SYNC. + * - EINVAL A value of op other than O_SYNC or O_DSYNC was specified. * - EINVAL aiocbp is a NULL pointer. * - EINVAL aiocbp->sigevent is not valid. */ diff --git a/cpukit/include/rtems/posix/aio_misc.h b/cpukit/include/rtems/posix/aio_misc.h index b4bb0c4e0a..f1c7073e1a 100644 --- a/cpukit/include/rtems/posix/aio_misc.h +++ b/cpukit/include/rtems/posix/aio_misc.h @@ -57,6 +57,30 @@ extern "C" { #endif +/** Constants to identify op type */ + +/** Needed by aio_fsync() */ +#define AIO_OP_READ 0 + +/** Needed by aio_fsync() */ +#define AIO_OP_WRITE 1 + +/** Needed by aio_fsync() */ +#define AIO_OP_SYNC 2 + +/** Needed by aio_fsync() */ +#define AIO_OP_DSYNC 3 + +/* + * Constants to track return status + */ + +/** The aio operation return value has been retrieved */ +#define AIO_RETURNED 0 + +/** The aio operation return value has not been retrieved */ +#define AIO_NOTRETURNED 1 + /** * @brief The request being processed */ @@ -76,6 +100,10 @@ typedef struct /** @brief Aio control block */ struct aiocb *aiocbp; + + /** @brief Operation type */ + int op_type; + } rtems_aio_request; /** diff --git a/cpukit/posix/src/aio_error.c b/cpukit/posix/src/aio_error.c index 1a9b92f4b8..8b4fd658b0 100644 --- a/cpukit/posix/src/aio_error.c +++ b/cpukit/posix/src/aio_error.c @@ -42,6 +42,7 @@ #include #include +#include #include diff --git a/cpukit/posix/src/aio_fsync.c b/cpukit/posix/src/aio_fsync.c index fa946da484..a552752d83 100644 --- a/cpukit/posix/src/aio_fsync.c +++ b/cpukit/posix/src/aio_fsync.c @@ -57,7 +57,7 @@ int aio_fsync( if ( aiocbp == NULL ) rtems_set_errno_and_return_minus_one( EINVAL ); - if ( op != O_SYNC ) + if ( op != O_SYNC && op != O_DSYNC ) rtems_set_errno_and_return_minus_one( EINVAL ); if ( rtems_aio_check_sigevent( &aiocbp->aio_sigevent ) == 0 ) @@ -77,7 +77,11 @@ int aio_fsync( rtems_set_errno_and_return_minus_one( EAGAIN ); req->aiocbp = aiocbp; - req->aiocbp->aio_lio_opcode = LIO_SYNC; + if ( op == O_SYNC ) { + req->op_type = AIO_OP_SYNC; + } else { + req->op_type = AIO_OP_DSYNC; + } return rtems_aio_enqueue( req ); } diff --git a/cpukit/posix/src/aio_misc.c b/cpukit/posix/src/aio_misc.c index 301a6712f1..62a68de322 100644 --- a/cpukit/posix/src/aio_misc.c +++ b/cpukit/posix/src/aio_misc.c @@ -613,8 +613,8 @@ static void rtems_aio_handle_helper( rtems_aio_request *req ) { int result; - switch ( req->aiocbp->aio_lio_opcode ) { - case LIO_READ: + switch ( req->op_type ) { + case AIO_OP_READ: AIO_printf( "read\n" ); result = pread( req->aiocbp->aio_fildes, @@ -623,7 +623,7 @@ static void rtems_aio_handle_helper( rtems_aio_request *req ) ); break; - case LIO_WRITE: + case AIO_OP_WRITE: AIO_printf( "write\n" ); result = pwrite( req->aiocbp->aio_fildes, @@ -632,10 +632,15 @@ static void rtems_aio_handle_helper( rtems_aio_request *req ) ); break; - case LIO_SYNC: + case AIO_OP_SYNC: AIO_printf( "sync\n" ); result = fsync( req->aiocbp->aio_fildes ); break; + + case AIO_OP_DSYNC: + AIO_printf( "data sync\n" ); + result = fdatasync( req->aiocbp->aio_fildes ); + break; default: result = -1; diff --git a/cpukit/posix/src/aio_read.c b/cpukit/posix/src/aio_read.c index 876042bfd8..70bf469999 100644 --- a/cpukit/posix/src/aio_read.c +++ b/cpukit/posix/src/aio_read.c @@ -79,7 +79,7 @@ int aio_read( struct aiocb *aiocbp ) rtems_set_errno_and_return_minus_one( EAGAIN ); req->aiocbp = aiocbp; - req->aiocbp->aio_lio_opcode = LIO_READ; + req->op_type = AIO_OP_READ; return rtems_aio_enqueue( req ); } diff --git a/cpukit/posix/src/aio_return.c b/cpukit/posix/src/aio_return.c index d4189609d9..a2b2f28485 100644 --- a/cpukit/posix/src/aio_return.c +++ b/cpukit/posix/src/aio_return.c @@ -43,6 +43,7 @@ #include #include #include +#include ssize_t aio_return( struct aiocb *aiocbp ) { diff --git a/cpukit/posix/src/aio_write.c b/cpukit/posix/src/aio_write.c index 3f7999ef93..5492e61367 100644 --- a/cpukit/posix/src/aio_write.c +++ b/cpukit/posix/src/aio_write.c @@ -76,7 +76,7 @@ int aio_write( struct aiocb *aiocbp ) rtems_set_errno_and_return_minus_one( EAGAIN ); req->aiocbp = aiocbp; - req->aiocbp->aio_lio_opcode = LIO_WRITE; + req->op_type = AIO_OP_WRITE; return rtems_aio_enqueue( req ); } diff --git a/testsuites/psxtests/psxaio01/init.c b/testsuites/psxtests/psxaio01/init.c index f5a3545e00..3a67bc6ac6 100644 --- a/testsuites/psxtests/psxaio01/init.c +++ b/testsuites/psxtests/psxaio01/init.c @@ -86,6 +86,41 @@ void *POSIX_Init( void *argument ) TEST_BEGIN(); + /* NULL aiocbp */ + + result = aio_write( NULL ); + status = errno; + rtems_test_assert( result == -1 ); + rtems_test_assert( status == EINVAL ); + + /* NULL aiocbp */ + + result = aio_read( NULL ); + status = errno; + rtems_test_assert( result == -1 ); + rtems_test_assert( status == EINVAL ); + + /* NULL aiocbp */ + + result = aio_fsync( O_SYNC, NULL ); + status = errno; + rtems_test_assert( result == -1 ); + rtems_test_assert( status == EINVAL ); + + /* NULL aiocbp */ + + result = aio_return( NULL ); + status = errno; + rtems_test_assert( result == -1 ); + rtems_test_assert( status == ENOENT ); + + /* NULL aiocbp */ + + result = aio_error( NULL ); + status = errno; + rtems_test_assert( result == -1 ); + rtems_test_assert( status == EINVAL ); + aiocbp = create_aiocb( WRONG_FD ); /* Bad file descriptor */ @@ -147,7 +182,7 @@ void *POSIX_Init( void *argument ) rtems_test_assert( result == -1 ); rtems_test_assert( status == EINVAL ); - /* Invalid request priority */ + /* Invalid request priority */ result = aio_read( aiocbp ); status = errno; @@ -168,6 +203,25 @@ void *POSIX_Init( void *argument ) status = errno; rtems_test_assert( result == -1 ); rtems_test_assert( status == EINVAL ); + aiocbp->aio_fildes = fd; + + /* Bad sigevent */ + + aiocbp->aio_sigevent.sigev_notify = SIGEV_SIGNAL; + aiocbp->aio_sigevent.sigev_notify_function = NULL; + result = aio_fsync( O_SYNC, aiocbp ); + status = errno; + rtems_test_assert( result == -1 ); + rtems_test_assert( status == EINVAL ); + + /* Bad sigevent */ + + aiocbp->aio_sigevent.sigev_notify = SIGEV_THREAD; + aiocbp->aio_sigevent.sigev_signo = 0; + result = aio_fsync( O_SYNC, aiocbp ); + status = errno; + rtems_test_assert( result == -1 ); + rtems_test_assert( status == EINVAL ); free_aiocb( aiocbp ); diff --git a/testsuites/psxtests/psxaio02/init.c b/testsuites/psxtests/psxaio02/init.c index 518e861b59..d5ac824874 100644 --- a/testsuites/psxtests/psxaio02/init.c +++ b/testsuites/psxtests/psxaio02/init.c @@ -148,6 +148,10 @@ void *POSIX_Init( void *argument ) status = aio_fsync( O_SYNC, aiocbp[9] ); rtems_test_assert( status != -1 ); + aiocbp[9] = create_aiocb( fd[0] ); + status = aio_fsync( O_DSYNC, aiocbp[9] ); + rtems_test_assert( status != -1 ); + status = aio_cancel( WRONG_FD, NULL ); rtems_test_assert( status == -1 ); @@ -170,6 +174,22 @@ void *POSIX_Init( void *argument ) status = aio_cancel( fd[5], aiocbp[6] ); rtems_test_assert( status == AIO_CANCELED ); + /* tests for aio error and aio test */ + + int result = aio_error( aiocbp[6] ); + rtems_test_assert( result == ECANCELED ); + + result = aio_return( aiocbp[6] ); + rtems_test_assert( result == -1 ); + + result = aio_return( aiocbp[6] ); + rtems_test_assert( result == -1 ); + + rtems_test_assert( errno == EINVAL ); + result = aio_error( aiocbp[6] ); + rtems_test_assert( result == -1 ); + rtems_test_assert( errno == EINVAL ); + status = aio_cancel( fd[0], aiocbp[9] ); rtems_test_assert( status == AIO_CANCELED );