00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #include "myisam_priv.h"
00017 #include <drizzled/error.h>
00018 #include <cerrno>
00019 #include <unistd.h>
00020
00021 using namespace drizzled;
00022
00023 #define MY_WAIT_FOR_USER_TO_FIX_PANIC 60
00024 #define MY_WAIT_GIVE_USER_A_MESSAGE 10
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047 size_t my_pread(int Filedes, unsigned char *Buffer, size_t Count, internal::my_off_t offset,
00048 myf MyFlags)
00049 {
00050 size_t readbytes;
00051 int error= 0;
00052 for (;;)
00053 {
00054 errno=0;
00055 if ((error= ((readbytes= pread(Filedes, Buffer, Count, offset)) != Count)))
00056 errno= errno ? errno : -1;
00057 if (error || readbytes != Count)
00058 {
00059 if ((readbytes == 0 || readbytes == (size_t) -1) && errno == EINTR)
00060 {
00061 continue;
00062 }
00063 if (MyFlags & (MY_WME | MY_FAE | MY_FNABP))
00064 {
00065 if (readbytes == (size_t) -1)
00066 my_error(EE_READ, MYF(ME_BELL+ME_WAITTANG), "unknown", errno);
00067 else if (MyFlags & (MY_NABP | MY_FNABP))
00068 my_error(EE_EOFERR, MYF(ME_BELL+ME_WAITTANG), "unknown", errno);
00069 }
00070 if (readbytes == (size_t) -1 || (MyFlags & (MY_FNABP | MY_NABP)))
00071 return(MY_FILE_ERROR);
00072 }
00073 if (MyFlags & (MY_NABP | MY_FNABP))
00074 return(0);
00075 return(readbytes);
00076 }
00077 }
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101 size_t my_pwrite(int Filedes, const unsigned char *Buffer, size_t Count,
00102 internal::my_off_t offset, myf MyFlags)
00103 {
00104 size_t writenbytes, written;
00105 uint32_t errors;
00106 errors= 0;
00107 written= 0;
00108
00109 for (;;)
00110 {
00111 if ((writenbytes= pwrite(Filedes, Buffer, Count,offset)) == Count)
00112 break;
00113 errno= errno;
00114 if (writenbytes != (size_t) -1)
00115 {
00116 written+=writenbytes;
00117 Buffer+=writenbytes;
00118 Count-=writenbytes;
00119 offset+=writenbytes;
00120 }
00121 #ifndef NO_BACKGROUND
00122 if ((errno == ENOSPC || errno == EDQUOT) &&
00123 (MyFlags & MY_WAIT_IF_FULL))
00124 {
00125 if (!(errors++ % MY_WAIT_GIVE_USER_A_MESSAGE))
00126 my_error(EE_DISK_FULL,MYF(ME_BELL | ME_NOREFRESH),
00127 "unknown", errno, MY_WAIT_FOR_USER_TO_FIX_PANIC);
00128 sleep(MY_WAIT_FOR_USER_TO_FIX_PANIC);
00129 continue;
00130 }
00131 if ((writenbytes && writenbytes != (size_t) -1) || errno == EINTR)
00132 continue;
00133 #endif
00134 if (MyFlags & (MY_NABP | MY_FNABP))
00135 {
00136 if (MyFlags & (MY_WME | MY_FAE | MY_FNABP))
00137 {
00138 my_error(EE_WRITE, MYF(ME_BELL | ME_WAITTANG), "unknown", errno);
00139 }
00140 return(MY_FILE_ERROR);
00141 }
00142 else
00143 break;
00144 }
00145 if (MyFlags & (MY_NABP | MY_FNABP))
00146 return(0);
00147 return(writenbytes+written);
00148 }