16 #include "mysys_priv.h"
17 #include "mysys_err.h"
20 static void (*before_sync_wait)(void)= 0;
21 static void (*after_sync_wait)(void)= 0;
23 void thr_set_sync_wait_callback(
void (*before_wait)(
void),
24 void (*after_wait)(
void))
26 before_sync_wait= before_wait;
27 after_sync_wait= after_wait;
53 int my_sync(File fd, myf my_flags)
56 DBUG_ENTER(
"my_sync");
57 DBUG_PRINT(
"my",(
"Fd: %d my_flags: %d", fd, my_flags));
60 (*before_sync_wait)();
63 #if defined(F_FULLFSYNC)
68 if (!(res= fcntl(fd, F_FULLFSYNC, 0)))
71 DBUG_PRINT(
"info",(
"fcntl(F_FULLFSYNC) failed, falling back"));
73 #if defined(HAVE_FDATASYNC) && HAVE_DECL_FDATASYNC
75 #elif defined(HAVE_FSYNC)
78 res= my_win_fsync(fd);
80 #error Cannot find a way to sync a file, durability in danger
83 }
while (res == -1 && errno == EINTR);
92 if ((my_flags & MY_IGNORE_BADFD) &&
93 (er == EBADF || er == EINVAL || er == EROFS))
95 DBUG_PRINT(
"info", (
"ignoring errno %d", er));
98 else if (my_flags & MY_WME)
100 char errbuf[MYSYS_STRERROR_SIZE];
101 my_error(EE_SYNC, MYF(ME_BELL+ME_WAITTANG), my_filename(fd),
102 my_errno, my_strerror(errbuf,
sizeof(errbuf), my_errno));
108 (*after_sync_wait)();
114 static const char cur_dir_name[]= {FN_CURLIB, 0};
129 #ifdef NEED_EXPLICIT_SYNC_DIR
131 int my_sync_dir(
const char *dir_name, myf my_flags)
135 const char *correct_dir_name;
136 DBUG_ENTER(
"my_sync_dir");
137 DBUG_PRINT(
"my",(
"Dir: '%s' my_flags: %d", dir_name, my_flags));
139 correct_dir_name= (dir_name[0] == 0) ? cur_dir_name : dir_name;
144 if ((dir_fd= my_open(correct_dir_name, O_RDONLY, MYF(my_flags))) >= 0)
146 if (my_sync(dir_fd, MYF(my_flags | MY_IGNORE_BADFD)))
148 if (my_close(dir_fd, MYF(my_flags)))
158 int my_sync_dir(
const char *dir_name __attribute__((unused)),
159 myf my_flags __attribute__((unused)))
179 #ifdef NEED_EXPLICIT_SYNC_DIR
181 int my_sync_dir_by_file(
const char *file_name, myf my_flags)
183 char dir_name[FN_REFLEN];
184 size_t dir_name_length;
185 dirname_part(dir_name, file_name, &dir_name_length);
186 return my_sync_dir(dir_name, my_flags);
191 int my_sync_dir_by_file(
const char *file_name __attribute__((unused)),
192 myf my_flags __attribute__((unused)))