1
by brian
clean slate |
1 |
/* Copyright (C) 2000 MySQL AB
|
2 |
||
3 |
This program is free software; you can redistribute it and/or modify
|
|
4 |
it under the terms of the GNU General Public License as published by
|
|
5 |
the Free Software Foundation; version 2 of the License.
|
|
6 |
||
7 |
This program is distributed in the hope that it will be useful,
|
|
8 |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
9 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
10 |
GNU General Public License for more details.
|
|
11 |
||
12 |
You should have received a copy of the GNU General Public License
|
|
13 |
along with this program; if not, write to the Free Software
|
|
14 |
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
|
|
15 |
||
36
by Brian Aker
Moved pread over to just supporting myisam (someone can refactor from here |
16 |
#include "myisamdef.h" |
212.5.13
by Monty Taylor
Moved my_sys/my_pthread/my_nosys and mysys_err to mysys. |
17 |
#include <mysys/mysys_err.h> |
1
by brian
clean slate |
18 |
#include <errno.h> |
19 |
#include <unistd.h> |
|
20 |
||
21 |
/*
|
|
22 |
Read a chunk of bytes from a file from a given position
|
|
23 |
||
24 |
SYNOPSIOS
|
|
25 |
my_pread()
|
|
26 |
Filedes File decsriptor
|
|
27 |
Buffer Buffer to read data into
|
|
28 |
Count Number of bytes to read
|
|
29 |
offset Position to read from
|
|
30 |
MyFlags Flags
|
|
31 |
||
32 |
NOTES
|
|
33 |
This differs from the normal pread() call in that we don't care
|
|
34 |
to set the position in the file back to the original position
|
|
35 |
if the system doesn't support pread().
|
|
36 |
||
37 |
RETURN
|
|
38 |
(size_t) -1 Error
|
|
39 |
# Number of bytes read
|
|
40 |
*/
|
|
41 |
||
313
by Brian Aker
Further work with ulong in myisam |
42 |
size_t my_pread(File Filedes, unsigned char *Buffer, size_t Count, my_off_t offset, |
1
by brian
clean slate |
43 |
myf MyFlags) |
44 |
{
|
|
45 |
size_t readbytes; |
|
46 |
int error= 0; |
|
47 |
for (;;) |
|
48 |
{
|
|
49 |
errno=0; /* Linux doesn't reset this */ |
|
50 |
if ((error= ((readbytes= pread(Filedes, Buffer, Count, offset)) != Count))) |
|
51 |
my_errno= errno ? errno : -1; |
|
52 |
if (error || readbytes != Count) |
|
53 |
{
|
|
54 |
if ((readbytes == 0 || readbytes == (size_t) -1) && errno == EINTR) |
|
55 |
{
|
|
56 |
continue; /* Interrupted */ |
|
57 |
}
|
|
58 |
if (MyFlags & (MY_WME | MY_FAE | MY_FNABP)) |
|
59 |
{
|
|
60 |
if (readbytes == (size_t) -1) |
|
61 |
my_error(EE_READ, MYF(ME_BELL+ME_WAITTANG), |
|
62 |
my_filename(Filedes),my_errno); |
|
63 |
else if (MyFlags & (MY_NABP | MY_FNABP)) |
|
64 |
my_error(EE_EOFERR, MYF(ME_BELL+ME_WAITTANG), |
|
65 |
my_filename(Filedes),my_errno); |
|
66 |
}
|
|
67 |
if (readbytes == (size_t) -1 || (MyFlags & (MY_FNABP | MY_NABP))) |
|
51.1.118
by Jay Pipes
DBUG symbol removal |
68 |
return(MY_FILE_ERROR); /* Return with error */ |
1
by brian
clean slate |
69 |
}
|
70 |
if (MyFlags & (MY_NABP | MY_FNABP)) |
|
51.1.118
by Jay Pipes
DBUG symbol removal |
71 |
return(0); /* Read went ok; Return 0 */ |
72 |
return(readbytes); /* purecov: inspected */ |
|
1
by brian
clean slate |
73 |
}
|
74 |
} /* my_pread */ |
|
75 |
||
76 |
||
77 |
/*
|
|
78 |
Write a chunk of bytes to a file at a given position
|
|
79 |
||
80 |
SYNOPSIOS
|
|
81 |
my_pwrite()
|
|
82 |
Filedes File decsriptor
|
|
83 |
Buffer Buffer to write data from
|
|
84 |
Count Number of bytes to write
|
|
85 |
offset Position to write to
|
|
86 |
MyFlags Flags
|
|
87 |
||
88 |
NOTES
|
|
89 |
This differs from the normal pwrite() call in that we don't care
|
|
90 |
to set the position in the file back to the original position
|
|
91 |
if the system doesn't support pwrite()
|
|
92 |
||
93 |
RETURN
|
|
94 |
(size_t) -1 Error
|
|
95 |
# Number of bytes read
|
|
96 |
*/
|
|
97 |
||
313
by Brian Aker
Further work with ulong in myisam |
98 |
size_t my_pwrite(int Filedes, const unsigned char *Buffer, size_t Count, |
1
by brian
clean slate |
99 |
my_off_t offset, myf MyFlags) |
100 |
{
|
|
101 |
size_t writenbytes, written; |
|
482
by Brian Aker
Remove uint. |
102 |
uint32_t errors; |
1
by brian
clean slate |
103 |
errors= 0; |
104 |
written= 0; |
|
105 |
||
106 |
for (;;) |
|
107 |
{
|
|
108 |
if ((writenbytes= pwrite(Filedes, Buffer, Count,offset)) == Count) |
|
109 |
break; |
|
110 |
my_errno= errno; |
|
111 |
if (writenbytes != (size_t) -1) |
|
112 |
{ /* Safegueard */ |
|
113 |
written+=writenbytes; |
|
114 |
Buffer+=writenbytes; |
|
115 |
Count-=writenbytes; |
|
116 |
offset+=writenbytes; |
|
117 |
}
|
|
118 |
#ifndef NO_BACKGROUND
|
|
119 |
if (my_thread_var->abort) |
|
120 |
MyFlags&= ~ MY_WAIT_IF_FULL; /* End if aborted by user */ |
|
121 |
if ((my_errno == ENOSPC || my_errno == EDQUOT) && |
|
122 |
(MyFlags & MY_WAIT_IF_FULL)) |
|
123 |
{
|
|
124 |
if (!(errors++ % MY_WAIT_GIVE_USER_A_MESSAGE)) |
|
125 |
my_error(EE_DISK_FULL,MYF(ME_BELL | ME_NOREFRESH), |
|
126 |
my_filename(Filedes),my_errno,MY_WAIT_FOR_USER_TO_FIX_PANIC); |
|
398.1.10
by Monty Taylor
Actually removed VOID() this time. |
127 |
sleep(MY_WAIT_FOR_USER_TO_FIX_PANIC); |
1
by brian
clean slate |
128 |
continue; |
129 |
}
|
|
130 |
if ((writenbytes && writenbytes != (size_t) -1) || my_errno == EINTR) |
|
131 |
continue; /* Retry */ |
|
132 |
#endif
|
|
133 |
if (MyFlags & (MY_NABP | MY_FNABP)) |
|
134 |
{
|
|
135 |
if (MyFlags & (MY_WME | MY_FAE | MY_FNABP)) |
|
136 |
{
|
|
137 |
my_error(EE_WRITE, MYF(ME_BELL | ME_WAITTANG), |
|
138 |
my_filename(Filedes),my_errno); |
|
139 |
}
|
|
51.1.118
by Jay Pipes
DBUG symbol removal |
140 |
return(MY_FILE_ERROR); /* Error on read */ |
1
by brian
clean slate |
141 |
}
|
142 |
else
|
|
143 |
break; /* Return bytes written */ |
|
144 |
}
|
|
145 |
if (MyFlags & (MY_NABP | MY_FNABP)) |
|
51.1.118
by Jay Pipes
DBUG symbol removal |
146 |
return(0); /* Want only errors */ |
147 |
return(writenbytes+written); /* purecov: inspected */ |
|
1
by brian
clean slate |
148 |
} /* my_pwrite */ |