~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to mysys/my_sync.c

  • Committer: Stewart Smith
  • Date: 2008-07-13 06:56:15 UTC
  • mto: (210.1.1 drizzle)
  • mto: This revision was merged to the branch mainline in revision 211.
  • Revision ID: stewart@flamingspork.com-20080713065615-vzok75kgnnviokl9
Move MD5() into a UDF

Show diffs side-by-side

added added

removed removed

Lines of Context:
13
13
   along with this program; if not, write to the Free Software
14
14
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
15
15
 
16
 
#include "config.h"
17
 
#include "drizzled/internal/my_sys.h"
18
 
 
 
16
#include "mysys_priv.h"
 
17
#include "mysys_err.h"
19
18
#include <errno.h>
20
 
#include <fcntl.h>
21
 
 
22
 
#include "drizzled/error.h"
23
 
 
24
 
namespace drizzled
25
 
{
26
 
namespace internal
27
 
{
28
19
 
29
20
/*
30
21
  Sync data in file to disk
49
40
    -1 error
50
41
*/
51
42
 
52
 
int my_sync(int fd, myf my_flags)
 
43
int my_sync(File fd, myf my_flags)
53
44
{
54
45
  int res;
 
46
  DBUG_ENTER("my_sync");
 
47
  DBUG_PRINT("my",("Fd: %d  my_flags: %d", fd, my_flags));
55
48
 
56
49
  do
57
50
  {
63
56
    if (!(res= fcntl(fd, F_FULLFSYNC, 0)))
64
57
      break; /* ok */
65
58
    /* Some file systems don't support F_FULLFSYNC and fail above: */
 
59
    DBUG_PRINT("info",("fcntl(F_FULLFSYNC) failed, falling back"));
66
60
#endif
67
61
#if defined(HAVE_FDATASYNC)
68
62
    res= fdatasync(fd);
69
 
#else
 
63
#elif defined(HAVE_FSYNC)
70
64
    res= fsync(fd);
 
65
#else
 
66
#error Cannot find a way to sync a file, durability in danger
 
67
    res= 0;                                     /* No sync (strange OS) */
71
68
#endif
72
69
  } while (res == -1 && errno == EINTR);
73
70
 
74
71
  if (res)
75
72
  {
76
73
    int er= errno;
77
 
    if (!(errno= er))
78
 
      errno= -1;                             /* Unknown error */
 
74
    if (!(my_errno= er))
 
75
      my_errno= -1;                             /* Unknown error */
79
76
    if ((my_flags & MY_IGNORE_BADFD) &&
80
77
        (er == EBADF || er == EINVAL || er == EROFS))
81
78
    {
 
79
      DBUG_PRINT("info", ("ignoring errno %d", er));
82
80
      res= 0;
83
81
    }
84
82
    else if (my_flags & MY_WME)
85
 
      my_error(EE_SYNC, MYF(ME_BELL+ME_WAITTANG), "unknown", errno);
 
83
      my_error(EE_SYNC, MYF(ME_BELL+ME_WAITTANG), my_filename(fd), my_errno);
86
84
  }
87
 
  return(res);
 
85
  DBUG_RETURN(res);
88
86
} /* my_sync */
89
87
 
90
88
 
100
98
  RETURN
101
99
    0 if ok, !=0 if error
102
100
*/
103
 
#ifdef NEED_EXPLICIT_SYNC_DIR
104
101
int my_sync_dir(const char *dir_name, myf my_flags)
105
102
{
106
 
  int dir_fd;
 
103
#ifdef NEED_EXPLICIT_SYNC_DIR
 
104
  DBUG_ENTER("my_sync_dir");
 
105
  DBUG_PRINT("my",("Dir: '%s'  my_flags: %d", dir_name, my_flags));
 
106
  File dir_fd;
107
107
  int res= 0;
108
108
  const char *correct_dir_name;
109
109
  /* Sometimes the path does not contain an explicit directory */
121
121
  }
122
122
  else
123
123
    res= 1;
124
 
  return(res);
125
 
}
 
124
  DBUG_RETURN(res);
126
125
#else
127
 
int my_sync_dir(const char *, myf)
128
 
{
129
126
  return 0;
130
 
}
131
127
#endif
 
128
}
132
129
 
133
130
 
134
131
/*
142
139
  RETURN
143
140
    0 if ok, !=0 if error
144
141
*/
145
 
#ifdef NEED_EXPLICIT_SYNC_DIR
146
142
int my_sync_dir_by_file(const char *file_name, myf my_flags)
147
143
{
 
144
#ifdef NEED_EXPLICIT_SYNC_DIR
148
145
  char dir_name[FN_REFLEN];
149
146
  size_t dir_name_length;
150
147
  dirname_part(dir_name, file_name, &dir_name_length);
151
148
  return my_sync_dir(dir_name, my_flags);
152
 
}
153
149
#else
154
 
int my_sync_dir_by_file(const char *, myf)
155
 
{
156
150
  return 0;
157
 
}
158
151
#endif
 
152
}
159
153
 
160
 
} /* namespace internal */
161
 
} /* namespace drizzled */