Fsync in a newly created folder?

Can anyone explain why fsync can return EINVAL when I pass in a folder descriptor in it? There is my code, it's pretty simple:

#include <dirent.h>     /* Defines DT_* constants */
#include <fcntl.h>
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <sys/syscall.h>
#include <sys/types.h>
#include <errno.h>


#define handle_error(msg) \
do { trace(msg); exit(0); } while (0)
#define trace printf


int createDir(const char* name) {
    int r = ::mkdir( name, 0777 );
    if (r != 0) {
        trace("error r!=0 %d\n",errno);
    }
    r = open(name, O_RDONLY | O_DIRECTORY);
    if (r < 0) {
        trace("error create dir r <0\n");
    }
    return r;
}

int main(int argc, const char * argv[]) {

    int r;

    int dir = createDir("test");

    r = fsync(dir);
    trace("r = %d %d\n",r,errno);
    close(dir);


    return 0;
}

      

it gives me this result:

r = -1 22

      

I am using linux ver. 2.6.32 (Ubuntu 10.04 as far as I remember)

So why did I get an error when I call fsync on a folder? When I call fsync with the passed file descriptor everything is fine

+3


source to share


2 answers


In my case, the problem was that I had Ubuntu installed in VirtualBox and I was running my program from a shared folder. The vboxsf filesystem was shared for VirtualBox, which does not support fsync in the folder. Thanks for @twalberg



0


source


@lobster - which workaround did you choose? I'm still having the same problem with Ubuntu 18.04 VM on Virtualbox with Windows 10 host machine ... I'm having fsync problems when running Elasticsearch embedded in my JUnits .. in our project.



0


source







All Articles