/* * Copyright (c) 2004, Bull SA. All rights reserved. * Created by: Laurent.Vivier@bull.net * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. */ /* * assertion: * * if mode is LIO_WAIT, lio_listio() shall return the value zero when * all I/O has completed successfully. * * method: * * - open a file for writing * - submit a list of writes to lio_listio in LIO_WAIT mode * - check that lio_listio returns 0 upon completion * */ #define _XOPEN_SOURCE 600 #include #include #include #include #include #include #include "posixtest.h" #define TNAME "lio_listio/12-1.c" #define NUM_AIOCBS 10 #define BUF_SIZE 1024 int main() { char tmpfname[256]; int fd; struct aiocb *aiocbs[NUM_AIOCBS]; char *bufs; int errors = 0; int ret; int err; int i; #if _POSIX_ASYNCHRONOUS_IO != 200112L exit(PTS_UNSUPPORTED); #endif snprintf(tmpfname, sizeof(tmpfname), "/tmp/pts_lio_listio_12_1_%d", getpid()); unlink(tmpfname); fd = open(tmpfname, O_CREAT | O_RDWR | O_EXCL, S_IRUSR | S_IWUSR); if (fd == -1) { printf(TNAME " Error at open(): %s\n", strerror(errno)); exit(PTS_UNRESOLVED); } unlink(tmpfname); bufs = (char *) malloc (NUM_AIOCBS*BUF_SIZE); if (bufs == NULL) { printf (TNAME " Error at malloc(): %s\n", strerror (errno)); close (fd); exit(PTS_UNRESOLVED); } /* Queue up a bunch of aio writes */ for (i = 0; i < NUM_AIOCBS; i++) { aiocbs[i] = (struct aiocb *)malloc(sizeof(struct aiocb)); memset(aiocbs[i], 0, sizeof(struct aiocb)); aiocbs[i]->aio_fildes = fd; aiocbs[i]->aio_offset = 0; aiocbs[i]->aio_buf = &bufs[i*BUF_SIZE]; aiocbs[i]->aio_nbytes = BUF_SIZE; aiocbs[i]->aio_lio_opcode = LIO_WRITE; } /* Submit request list */ ret = lio_listio(LIO_WAIT, aiocbs, NUM_AIOCBS, NULL); if (ret) { printf(TNAME " Error at lio_listio() %d: %s\n", errno, strerror(errno)); for (i=0; i