1/* 2 * Copyright (c) 2004, Bull SA. All rights reserved. 3 * Created by: Laurent.Vivier@bull.net 4 * This file is licensed under the GPL license. For the full content 5 * of this license, see the COPYING file at the top level of this 6 * source tree. 7 */ 8 9/* 10 * assertion: 11 * 12 * aio_lio_opcode shall be ignored. 13 * 14 * method: 15 * 16 * - write data to a file 17 * - fill in an aiocb with an LIO_WRITE aio_lio_opcode 18 * - call aio_read with this aiocb 19 * - check data is effectively read (ignoring aio_lio_opcode) 20 */ 21 22#define _XOPEN_SOURCE 600 23#include <stdio.h> 24#include <sys/types.h> 25#include <unistd.h> 26#include <sys/stat.h> 27#include <fcntl.h> 28#include <string.h> 29#include <errno.h> 30#include <stdlib.h> 31#include <aio.h> 32 33#include "posixtest.h" 34 35#define TNAME "aio_read/5-1.c" 36 37int main(void) 38{ 39 char tmpfname[256]; 40#define BUF_SIZE 111 41 unsigned char buf[BUF_SIZE]; 42 unsigned char check[BUF_SIZE]; 43 int fd; 44 struct aiocb aiocb; 45 int i; 46 47 if (sysconf(_SC_ASYNCHRONOUS_IO) < 200112L) 48 return PTS_UNSUPPORTED; 49 50 snprintf(tmpfname, sizeof(tmpfname), "/tmp/pts_aio_read_5_1_%d", 51 getpid()); 52 unlink(tmpfname); 53 fd = open(tmpfname, O_CREAT | O_RDWR | O_EXCL, S_IRUSR | S_IWUSR); 54 if (fd == -1) { 55 printf(TNAME " Error at open(): %s\n", strerror(errno)); 56 exit(PTS_UNRESOLVED); 57 } 58 59 unlink(tmpfname); 60 61 for (i = 0; i < BUF_SIZE; i++) 62 buf[i] = i; 63 64 if (write(fd, buf, BUF_SIZE) != BUF_SIZE) { 65 printf(TNAME " Error at write(): %s\n", strerror(errno)); 66 exit(PTS_UNRESOLVED); 67 } 68 69 memset(check, 0xaa, BUF_SIZE); 70 memset(&aiocb, 0, sizeof(struct aiocb)); 71 aiocb.aio_fildes = fd; 72 aiocb.aio_buf = check; 73 aiocb.aio_nbytes = BUF_SIZE; 74 aiocb.aio_lio_opcode = LIO_WRITE; 75 76 if (aio_read(&aiocb) == -1) { 77 printf(TNAME " Error at aio_read(): %s\n", strerror(errno)); 78 exit(PTS_FAIL); 79 } 80 81 int err; 82 int ret; 83 84 /* Wait until end of transaction */ 85 do { 86 usleep(10000); 87 err = aio_error(&aiocb); 88 } while (err == EINPROGRESS); 89 90 ret = aio_return(&aiocb); 91 92 if (err != 0) { 93 printf(TNAME " Error at aio_error() : %s\n", strerror(err)); 94 close(fd); 95 exit(PTS_FAIL); 96 } 97 98 if (ret != BUF_SIZE) { 99 printf(TNAME " Error at aio_return()\n"); 100 close(fd); 101 exit(PTS_FAIL); 102 } 103 104 /* check it */ 105 106 for (i = 0; i < BUF_SIZE; i++) { 107 if (buf[i] != check[i]) { 108 printf(TNAME " read values are corrupted\n"); 109 exit(PTS_FAIL); 110 } 111 } 112 113 close(fd); 114 printf("Test PASSED\n"); 115 return PTS_PASS; 116} 117