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