1 /* 2 * Copyright (c) 2004, Bull SA. All rights reserved. 3 * Created by: Laurent.Vivier (at) 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 #define _XOPEN_SOURCE 600 10 #include <stdio.h> 11 #include <sys/types.h> 12 #include <unistd.h> 13 #include <sys/stat.h> 14 #include <fcntl.h> 15 #include <string.h> 16 #include <errno.h> 17 #include <stdlib.h> 18 #include <aio.h> 19 20 #include "posixtest.h" 21 22 #define TNAME "aio_fsync/5-1.c" 23 24 #define BUF_SIZE 1024 25 26 int main(void) 27 { 28 char tmpfname[256]; 29 char buf[BUF_SIZE]; 30 int fd; 31 struct aiocb aiocb_write; 32 struct aiocb aiocb_fsync; 33 int ret, err; 34 35 if (sysconf(_SC_ASYNCHRONOUS_IO) < 200112L) 36 return PTS_UNSUPPORTED; 37 38 snprintf(tmpfname, sizeof(tmpfname), "/tmp/pts_aio_fsync_5_1_%d", 39 getpid()); 40 unlink(tmpfname); 41 fd = open(tmpfname, O_CREAT | O_RDWR | O_EXCL, S_IRUSR | S_IWUSR); 42 if (fd == -1) { 43 printf(TNAME " Error at open(): %s\n", strerror(errno)); 44 exit(PTS_UNRESOLVED); 45 } 46 47 unlink(tmpfname); 48 49 memset(&aiocb_write, 0, sizeof(aiocb_write)); 50 aiocb_write.aio_fildes = fd; 51 aiocb_write.aio_buf = buf; 52 aiocb_write.aio_nbytes = BUF_SIZE; 53 54 if (aio_write(&aiocb_write) == -1) { 55 printf(TNAME " Error at aio_write(): %s\n", strerror(errno)); 56 exit(PTS_FAIL); 57 } 58 59 memset(&aiocb_fsync, 0, sizeof(aiocb_fsync)); 60 aiocb_fsync.aio_fildes = fd; 61 62 if (aio_fsync(O_SYNC, &aiocb_fsync) != 0) { 63 printf(TNAME " Error at aio_fsync(): %s\n", strerror(errno)); 64 exit(PTS_FAIL); 65 } 66 67 ret = PTS_UNTESTED; 68 if (aio_error(&aiocb_fsync) == EINPROGRESS) 69 ret = PTS_PASS; 70 71 /* allow to check if aio_error() move from EINPROGRESS to 72 * something else otherwise test hangs 73 */ 74 do { 75 usleep(10000); 76 err = aio_error(&aiocb_fsync); 77 } while (err == EINPROGRESS); 78 if (err < 0) { 79 printf(TNAME " Error at aio_error() : %s\n", strerror(ret)); 80 exit(PTS_FAIL); 81 } 82 83 close(fd); 84 85 /* we didn't check if the operation is really performed */ 86 if (ret == PTS_PASS) 87 printf("Test PASSED\n"); 88 89 return ret; 90 } 91