summaryrefslogtreecommitdiff
path: root/cpukit/posix/src/aio_fsync.c
blob: 62f516ba7729e276506b60f0910e2b3c1e475559 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/**
 * @file
 *
 * @brief Syncing of all Outstanding Asynchronous I/O Operations
 * @ingroup POSIXAPI
 */

/*
 * Copyright 2010, Alin Rus <alin.codejunkie@gmail.com> 
 * 
 * The license and distribution terms for this file may be
 * found in the file LICENSE in this distribution or at
 * http://www.rtems.org/license/LICENSE.
 */

#if HAVE_CONFIG_H
#include "config.h"
#endif

#include <aio.h>
#include <errno.h>
#include <stdlib.h>
#include <rtems/posix/aio_misc.h>
#include <rtems/seterr.h>

/*
 *  aio_fsync
 *
 * Asynchronous file synchronization
 *
 *  Input parameters:
 *        op     - O_SYNC
 *        aiocbp - asynchronous I/O control block
 *
 *  Output parameters:
 *        -1 - request could not pe enqueued
 *           - FD not opened for write
 *           - not enough memory
 *           - op is not O_SYNC
 *         0 - otherwise
 */

int aio_fsync(
  int            op,
  struct aiocb  *aiocbp
)
{
  rtems_aio_request *req;
  int mode;

  if (op != O_SYNC)
    rtems_aio_set_errno_return_minus_one (EINVAL, aiocbp);
  
  mode = fcntl (aiocbp->aio_fildes, F_GETFL);
  if (!(((mode & O_ACCMODE) == O_WRONLY) || ((mode & O_ACCMODE) == O_RDWR)))
    rtems_aio_set_errno_return_minus_one (EBADF, aiocbp);

  req = malloc (sizeof (rtems_aio_request));
  if (req == NULL)
    rtems_aio_set_errno_return_minus_one (EAGAIN, aiocbp);

  req->aiocbp = aiocbp;
  req->aiocbp->aio_lio_opcode = LIO_SYNC; 
  
  return rtems_aio_enqueue (req);
    
}