c - fsync on newly created folder? -
can explain why fsync can return einval when pass folder descriptor in it? there code, 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) \ { 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 output:
r = -1 22
i using linux ver. 2.6.32 (ubuntu 10.04 remember)
so why got error when call fsync on folder? when call fsync file descriptor passed in, fine
in case problem because have ubuntu installed in virtualbox , run program shared folder. virtualbox shared had vboxsf file system doesn't support fsync on folder. @twalberg
Comments
Post a Comment