#include "mysys_priv.h"#include <m_string.h>#include <stdarg.h>#include <m_ctype.h>Include dependency graph for mf_iocache2.c:

Go to the source code of this file.
Defines | |
| #define | MAP_TO_USE_RAID |
Functions | |
| my_off_t | my_b_append_tell (IO_CACHE *info) |
| my_off_t | my_b_safe_tell (IO_CACHE *info) |
| void | my_b_seek (IO_CACHE *info, my_off_t pos) |
| uint | my_b_fill (IO_CACHE *info) |
| uint | my_b_gets (IO_CACHE *info, char *to, uint max_length) |
| my_off_t | my_b_filelength (IO_CACHE *info) |
| uint | my_b_printf (IO_CACHE *info, const char *fmt,...) |
| uint | my_b_vprintf (IO_CACHE *info, const char *fmt, va_list args) |
| #define MAP_TO_USE_RAID |
Definition at line 21 of file mf_iocache2.c.
Definition at line 27 of file mf_iocache2.c.
References st_io_cache::append_read_pos, DBUG_ASSERT, dbug_volatile, st_io_cache::end_of_file, st_io_cache::file, my_seek(), MY_SEEK_END, MY_SEEK_SET, my_tell(), MYF, pthread_mutex_lock, pthread_mutex_unlock, st_io_cache::write_buffer, and st_io_cache::write_pos.
00028 { 00029 /* 00030 Prevent optimizer from putting res in a register when debugging 00031 we need this to be able to see the value of res when the assert fails 00032 */ 00033 dbug_volatile my_off_t res; 00034 00035 /* 00036 We need to lock the append buffer mutex to keep flush_io_cache() 00037 from messing with the variables that we need in order to provide the 00038 answer to the question. 00039 */ 00040 #ifdef THREAD 00041 pthread_mutex_lock(&info->append_buffer_lock); 00042 #endif 00043 #ifndef DBUG_OFF 00044 /* 00045 Make sure EOF is where we think it is. Note that we cannot just use 00046 my_tell() because we have a reader thread that could have left the 00047 file offset in a non-EOF location 00048 */ 00049 { 00050 volatile my_off_t save_pos; 00051 save_pos = my_tell(info->file,MYF(0)); 00052 my_seek(info->file,(my_off_t)0,MY_SEEK_END,MYF(0)); 00053 /* 00054 Save the value of my_tell in res so we can see it when studying coredump 00055 */ 00056 DBUG_ASSERT(info->end_of_file - (info->append_read_pos-info->write_buffer) 00057 == (res=my_tell(info->file,MYF(0)))); 00058 my_seek(info->file,save_pos,MY_SEEK_SET,MYF(0)); 00059 } 00060 #endif 00061 res = info->end_of_file + (info->write_pos-info->append_read_pos); 00062 #ifdef THREAD 00063 pthread_mutex_unlock(&info->append_buffer_lock); 00064 #endif 00065 return res; 00066 }
Here is the call graph for this function:

Definition at line 221 of file mf_iocache2.c.
References st_io_cache::file, my_b_tell, my_seek(), MY_SEEK_END, MYF, st_io_cache::seek_not_done, st_io_cache::type, and WRITE_CACHE.
00222 { 00223 if (info->type == WRITE_CACHE) 00224 { 00225 return my_b_tell(info); 00226 } 00227 else 00228 { 00229 info->seek_not_done=1; 00230 return my_seek(info->file,0L,MY_SEEK_END,MYF(0)); 00231 } 00232 }
Here is the call graph for this function:

Definition at line 140 of file mf_iocache2.c.
References st_io_cache::buffer, st_io_cache::end_of_file, st_io_cache::error, st_io_cache::file, IO_SIZE, MY_FILEPOS_ERROR, my_read, my_seek(), MY_SEEK_SET, MYF, st_io_cache::myflags, st_io_cache::pos_in_file, st_io_cache::read_end, st_io_cache::read_length, st_io_cache::read_pos, and st_io_cache::seek_not_done.
00141 { 00142 my_off_t pos_in_file=(info->pos_in_file+ 00143 (uint) (info->read_end - info->buffer)); 00144 my_off_t max_length; 00145 uint diff_length,length; 00146 if (info->seek_not_done) 00147 { /* File touched, do seek */ 00148 if (my_seek(info->file,pos_in_file,MY_SEEK_SET,MYF(0)) == 00149 MY_FILEPOS_ERROR) 00150 { 00151 info->error= 0; 00152 return 0; 00153 } 00154 info->seek_not_done=0; 00155 } 00156 diff_length=(uint) (pos_in_file & (IO_SIZE-1)); 00157 max_length= (my_off_t) (info->end_of_file - pos_in_file); 00158 if (max_length > (my_off_t) (info->read_length-diff_length)) 00159 max_length=(my_off_t) (info->read_length-diff_length); 00160 if (!max_length) 00161 { 00162 info->error= 0; 00163 return 0; /* EOF */ 00164 } 00165 else if ((length=my_read(info->file,info->buffer,(uint) max_length, 00166 info->myflags)) == (uint) -1) 00167 { 00168 info->error= -1; 00169 return 0; 00170 } 00171 info->read_pos=info->buffer; 00172 info->read_end=info->buffer+length; 00173 info->pos_in_file=pos_in_file; 00174 return length; 00175 }
Here is the call graph for this function:

Definition at line 185 of file mf_iocache2.c.
References my_b_bytes_in_cache, my_b_fill(), pos(), st_io_cache::read_pos, and start().
00186 { 00187 char *start = to; 00188 uint length; 00189 max_length--; /* Save place for end \0 */ 00190 /* Calculate number of characters in buffer */ 00191 if (!(length= my_b_bytes_in_cache(info)) && 00192 !(length= my_b_fill(info))) 00193 return 0; 00194 for (;;) 00195 { 00196 char *pos,*end; 00197 if (length > max_length) 00198 length=max_length; 00199 for (pos=info->read_pos,end=pos+length ; pos < end ;) 00200 { 00201 if ((*to++ = *pos++) == '\n') 00202 { 00203 info->read_pos=pos; 00204 *to='\0'; 00205 return (uint) (to-start); 00206 } 00207 } 00208 if (!(max_length-=length)) 00209 { 00210 /* Found enough charcters; Return found string */ 00211 info->read_pos=pos; 00212 *to='\0'; 00213 return (uint) (to-start); 00214 } 00215 if (!(length=my_b_fill(info))) 00216 return 0; 00217 } 00218 }
Here is the call graph for this function:

Definition at line 241 of file mf_iocache2.c.
References args, and my_b_vprintf().
00242 { 00243 int result; 00244 va_list args; 00245 va_start(args,fmt); 00246 result=my_b_vprintf(info, fmt, args); 00247 va_end(args); 00248 return result; 00249 }
Here is the call graph for this function:

Definition at line 68 of file mf_iocache2.c.
References my_b_append_tell(), my_b_tell, SEQ_READ_APPEND, st_io_cache::type, and unlikely.
00069 { 00070 if (unlikely(info->type == SEQ_READ_APPEND)) 00071 return my_b_append_tell(info); 00072 return my_b_tell(info); 00073 }
Here is the call graph for this function:

Definition at line 80 of file mf_iocache2.c.
References DBUG_ENTER, DBUG_PRINT, DBUG_VOID_RETURN, flush_io_cache, IO_SIZE, offset, READ_CACHE, SEQ_READ_APPEND, st_io_cache::type, VOID, and WRITE_CACHE.
00081 { 00082 my_off_t offset; 00083 DBUG_ENTER("my_b_seek"); 00084 DBUG_PRINT("enter",("pos: %lu", (ulong) pos)); 00085 00086 /* 00087 TODO: 00088 Verify that it is OK to do seek in the non-append 00089 area in SEQ_READ_APPEND cache 00090 a) see if this always works 00091 b) see if there is a better way to make it work 00092 */ 00093 if (info->type == SEQ_READ_APPEND) 00094 VOID(flush_io_cache(info)); 00095 00096 offset=(pos - info->pos_in_file); 00097 00098 if (info->type == READ_CACHE || info->type == SEQ_READ_APPEND) 00099 { 00100 /* TODO: explain why this works if pos < info->pos_in_file */ 00101 if ((ulonglong) offset < (ulonglong) (info->read_end - info->buffer)) 00102 { 00103 /* The read is in the current buffer; Reuse it */ 00104 info->read_pos = info->buffer + offset; 00105 DBUG_VOID_RETURN; 00106 } 00107 else 00108 { 00109 /* Force a new read on next my_b_read */ 00110 info->read_pos=info->read_end=info->buffer; 00111 } 00112 } 00113 else if (info->type == WRITE_CACHE) 00114 { 00115 /* If write is in current buffer, reuse it */ 00116 if ((ulonglong) offset < 00117 (ulonglong) (info->write_end - info->write_buffer)) 00118 { 00119 info->write_pos = info->write_buffer + offset; 00120 DBUG_VOID_RETURN; 00121 } 00122 VOID(flush_io_cache(info)); 00123 /* Correct buffer end so that we write in increments of IO_SIZE */ 00124 info->write_end=(info->write_buffer+info->buffer_length- 00125 (pos & (IO_SIZE-1))); 00126 } 00127 info->pos_in_file=pos; 00128 info->seek_not_done=1; 00129 DBUG_VOID_RETURN; 00130 }
Definition at line 252 of file mf_iocache2.c.
References DBUG_ASSERT, err, int(), int10_to_str(), my_b_write, my_charset_latin1, my_isdigit, out_length, reg2, start(), and strlen().
00253 { 00254 uint out_length=0; 00255 uint minimum_width; /* as yet unimplemented */ 00256 uint minimum_width_sign; 00257 uint precision; /* as yet unimplemented for anything but %b */ 00258 00259 /* 00260 Store the location of the beginning of a format directive, for the 00261 case where we learn we shouldn't have been parsing a format string 00262 at all, and we don't want to lose the flag/precision/width/size 00263 information. 00264 */ 00265 const char* backtrack; 00266 00267 for (; *fmt != '\0'; fmt++) 00268 { 00269 /* Copy everything until '%' or end of string */ 00270 const char *start=fmt; 00271 uint length; 00272 00273 for (; (*fmt != '\0') && (*fmt != '%'); fmt++) ; 00274 00275 length= (uint) (fmt - start); 00276 out_length+=length; 00277 if (my_b_write(info, start, length)) 00278 goto err; 00279 00280 if (*fmt == '\0') /* End of format */ 00281 { 00282 return out_length; 00283 } 00284 00285 /* 00286 By this point, *fmt must be a percent; Keep track of this location and 00287 skip over the percent character. 00288 */ 00289 DBUG_ASSERT(*fmt == '%'); 00290 backtrack= fmt; 00291 fmt++; 00292 00293 minimum_width= 0; 00294 precision= 0; 00295 minimum_width_sign= 1; 00296 /* Skip if max size is used (to be compatible with printf) */ 00297 while (*fmt == '-') { fmt++; minimum_width_sign= -1; } 00298 if (*fmt == '*') { 00299 precision= (int) va_arg(args, int); 00300 fmt++; 00301 } else { 00302 while (my_isdigit(&my_charset_latin1, *fmt)) { 00303 minimum_width=(minimum_width * 10) + (*fmt - '0'); 00304 fmt++; 00305 } 00306 } 00307 minimum_width*= minimum_width_sign; 00308 00309 if (*fmt == '.') { 00310 fmt++; 00311 if (*fmt == '*') { 00312 precision= (int) va_arg(args, int); 00313 fmt++; 00314 } else { 00315 while (my_isdigit(&my_charset_latin1, *fmt)) { 00316 precision=(precision * 10) + (*fmt - '0'); 00317 fmt++; 00318 } 00319 } 00320 } 00321 00322 if (*fmt == 's') /* String parameter */ 00323 { 00324 reg2 char *par = va_arg(args, char *); 00325 uint length = (uint) strlen(par); 00326 /* TODO: implement minimum width and precision */ 00327 out_length+=length; 00328 if (my_b_write(info, par, length)) 00329 goto err; 00330 } 00331 else if (*fmt == 'b') /* Sized buffer parameter, only precision makes sense */ 00332 { 00333 char *par = va_arg(args, char *); 00334 out_length+= precision; 00335 if (my_b_write(info, par, precision)) 00336 goto err; 00337 } 00338 else if (*fmt == 'd' || *fmt == 'u') /* Integer parameter */ 00339 { 00340 register int iarg; 00341 uint length; 00342 char buff[17]; 00343 00344 iarg = va_arg(args, int); 00345 if (*fmt == 'd') 00346 length= (uint) (int10_to_str((long) iarg,buff, -10) - buff); 00347 else 00348 length= (uint) (int10_to_str((long) (uint) iarg,buff,10)- buff); 00349 out_length+=length; 00350 if (my_b_write(info, buff, length)) 00351 goto err; 00352 } 00353 else if ((*fmt == 'l' && fmt[1] == 'd') || fmt[1] == 'u') 00354 /* long parameter */ 00355 { 00356 register long iarg; 00357 uint length; 00358 char buff[17]; 00359 00360 iarg = va_arg(args, long); 00361 if (*++fmt == 'd') 00362 length= (uint) (int10_to_str(iarg,buff, -10) - buff); 00363 else 00364 length= (uint) (int10_to_str(iarg,buff,10)- buff); 00365 out_length+=length; 00366 if (my_b_write(info, buff, length)) 00367 goto err; 00368 } 00369 else 00370 { 00371 /* %% or unknown code */ 00372 if (my_b_write(info, backtrack, fmt-backtrack)) 00373 goto err; 00374 out_length+= fmt-backtrack; 00375 } 00376 } 00377 return out_length; 00378 00379 err: 00380 return (uint) -1; 00381 }
Here is the call graph for this function:

1.4.7

