Name

fdatasync - synchronizes a fileâs in-core data with that on disk

Library

libc.lib

Synopsis

  #include <unistd.h>
  int fdatasync (int fd);

Return values

If successful,the function shall return the value 0; otherwise, it shall return the value -1 and set errno to indicate the error.

Detailed description

The fdatasync system call causes all modified data and attributes of fd to be moved to a permanent storage device. This normally results in all in-core modified copies of buffers for the associated file to be written to a disk. The fdatasync() function forces all the queued I/O operations associated that file, as indicated by the file descriptor fd, to the synchronized I/O completion state.

The functionality shall be equivalent to fsync() with the symbol -> _POSIX_SYNCHRONIZED_IO defined. This has an exception that all I/O operations shall be completed, before the call.

The fdatasync should be used by programs that require a file to be in a known state, for example, in building a simple transaction facility.


Examples

#include<unistd.h>
#include<stdio.h>
#define KMAXCHARS 100
int test_fdatasync()
{
   char* array = "abcdefghijklmnopqrstuvwxyz";
   struct stat buf;
   if((fd = open(file , O_CREAT | O_RDWR , 0666))  < 0)
   {
      printf("Failed  to create file");
   }
   size_t size = write(fd,array, KMAXCHARS);
   if(fdatasync(fd) < 0)
   {
     printf("Fdatasync failed");
     int retrn = remove(file);
     return -1;
   }
  int retVal2 = fstat( fp, &buf );
  if(!retVal2)
  {
    size_t bufsize = buf.st_size;
    if (bufsize == size)
    {
      printf("file size = %d\n", size);
      printf("Fdatasync passed");
      int retrn = remove(file);
      return 0;
    }
  }
}

         

Output

file size = 50
Fdatasync passed

         

Errors

The errors defined for fsync are the ones defined for fdatasync.


See also

sync, fsync


Feedback

For additional information or queries on this page send feedback

© 2008-2009 Nokia Corporation. All rights reserved. This documentation can be used in the connection with this Product to help and support the user.

Top