Eneboo - Documentación para desarrolladores
|
00001 /* Copyright (C) 2000 MySQL AB 00002 00003 This program is free software; you can redistribute it and/or modify 00004 it under the terms of the GNU General Public License as published by 00005 the Free Software Foundation; version 2 of the License. 00006 00007 This program is distributed in the hope that it will be useful, 00008 but WITHOUT ANY WARRANTY; without even the implied warranty of 00009 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00010 GNU General Public License for more details. 00011 00012 You should have received a copy of the GNU General Public License 00013 along with this program; if not, write to the Free Software 00014 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ 00015 00016 /* Parser needs these defines always, even if USE_RAID is not defined */ 00017 #define RAID_TYPE_0 1 /* Striping */ 00018 #define RAID_TYPE_x 2 /* Some new modes */ 00019 #define RAID_TYPE_y 3 00020 00021 #define RAID_DEFAULT_CHUNKS 4 00022 #define RAID_DEFAULT_CHUNKSIZE 256*1024 /* 256kB */ 00023 00024 C_MODE_START 00025 #define my_raid_type(raid_type) raid_type_string[(int)(raid_type)] 00026 extern const char *raid_type_string[]; 00027 C_MODE_END 00028 00029 #ifdef DONT_USE_RAID 00030 #undef USE_RAID 00031 #endif 00032 #if defined(USE_RAID) 00033 00034 #include "my_dir.h" 00035 00036 /* Trap all occurences of my_...() in source and use our wrapper around this function */ 00037 00038 #ifdef MAP_TO_USE_RAID 00039 #define my_read(A,B,C,D) my_raid_read(A,B,C,D) 00040 #define my_write(A,B,C,D) my_raid_write(A,B,C,D) 00041 #define my_pwrite(A,B,C,D,E) my_raid_pwrite(A,B,C,D,E) 00042 #define my_pread(A,B,C,D,E) my_raid_pread(A,B,C,D,E) 00043 #define my_chsize(A,B,C,D) my_raid_chsize(A,B,C,D) 00044 #define my_close(A,B) my_raid_close(A,B) 00045 #define my_tell(A,B) my_raid_tell(A,B) 00046 #define my_seek(A,B,C,D) my_raid_seek(A,B,C,D) 00047 #define my_lock(A,B,C,D,E) my_raid_lock(A,B,C,D,E) 00048 #define my_fstat(A,B,C) my_raid_fstat(A,B,C) 00049 #endif /* MAP_TO_USE_RAID */ 00050 00051 #ifdef __cplusplus 00052 extern "C" { 00053 #endif 00054 00055 void init_raid(void); 00056 void end_raid(void); 00057 00058 bool is_raid(File fd); 00059 File my_raid_create(const char *FileName, int CreateFlags, int access_flags, 00060 uint raid_type, uint raid_chunks, ulong raid_chunksize, 00061 myf MyFlags); 00062 File my_raid_open(const char *FileName, int Flags, 00063 uint raid_type, uint raid_chunks, ulong raid_chunksize, 00064 myf MyFlags); 00065 int my_raid_rename(const char *from, const char *to, uint raid_chunks, 00066 myf MyFlags); 00067 int my_raid_delete(const char *from, uint raid_chunks, myf MyFlags); 00068 int my_raid_redel(const char *old_name, const char *new_name, 00069 uint raid_chunks, myf MyFlags); 00070 00071 my_off_t my_raid_seek(File fd, my_off_t pos, int whence, myf MyFlags); 00072 my_off_t my_raid_tell(File fd, myf MyFlags); 00073 00074 uint my_raid_write(File,const byte *Buffer, uint Count, myf MyFlags); 00075 uint my_raid_read(File Filedes, byte *Buffer, uint Count, myf MyFlags); 00076 00077 uint my_raid_pread(File Filedes, byte *Buffer, uint Count, my_off_t offset, 00078 myf MyFlags); 00079 uint my_raid_pwrite(int Filedes, const byte *Buffer, uint Count, 00080 my_off_t offset, myf MyFlags); 00081 00082 int my_raid_lock(File,int locktype, my_off_t start, my_off_t length, 00083 myf MyFlags); 00084 int my_raid_chsize(File fd, my_off_t newlength, int filler, myf MyFlags); 00085 int my_raid_close(File, myf MyFlags); 00086 int my_raid_fstat(int Filedes, struct stat *buf, myf MyFlags); 00087 00088 #ifdef __cplusplus 00089 } 00090 00091 #ifdef USE_PRAGMA_INTERFACE 00092 #pragma interface /* gcc class implementation */ 00093 #endif 00094 00095 class RaidName { 00096 public: 00097 RaidName(const char *FileName); 00098 ~RaidName(); 00099 bool IsRaid(); 00100 int Rename(const char * from, const char * to, myf MyFlags); 00101 private: 00102 uint _raid_type; /* RAID_TYPE_0 or RAID_TYPE_1 or RAID_TYPE_5 */ 00103 uint _raid_chunks; /* 1..n */ 00104 ulong _raid_chunksize; /* 1..n in bytes */ 00105 }; 00106 00107 class RaidFd { 00108 public: 00109 RaidFd(uint raid_type, uint raid_chunks , ulong raid_chunksize); 00110 ~RaidFd(); 00111 File Create(const char *FileName, int CreateFlags, int access_flags, 00112 myf MyFlags); 00113 File Open(const char *FileName, int Flags, myf MyFlags); 00114 my_off_t Seek(my_off_t pos,int whence,myf MyFlags); 00115 my_off_t Tell(myf MyFlags); 00116 int Write(const byte *Buffer, uint Count, myf MyFlags); 00117 int Read(const byte *Buffer, uint Count, myf MyFlags); 00118 int Lock(int locktype, my_off_t start, my_off_t length, myf MyFlags); 00119 int Chsize(File fd, my_off_t newlength, int filler, myf MyFlags); 00120 int Fstat(int fd, MY_STAT *stat_area, myf MyFlags ); 00121 int Close(myf MyFlags); 00122 static bool IsRaid(File fd); 00123 static DYNAMIC_ARRAY _raid_map; /* Map of RaidFD* */ 00124 private: 00125 00126 uint _raid_type; /* RAID_TYPE_0 or RAID_TYPE_1 or RAID_TYPE_5 */ 00127 uint _raid_chunks; /* 1..n */ 00128 ulong _raid_chunksize; /* 1..n in bytes */ 00129 00130 ulong _total_block; /* We are operating with block no x (can be 0..many). */ 00131 uint _this_block; /* can be 0.._raid_chunks */ 00132 uint _remaining_bytes; /* Maximum bytes that can be written in this block */ 00133 00134 my_off_t _position; 00135 my_off_t _size; /* Cached file size for faster seek(SEEK_END) */ 00136 File _fd; 00137 File *_fd_vector; /* Array of File */ 00138 off_t *_seek_vector; /* Array of cached seek positions */ 00139 00140 inline void Calculate() 00141 { 00142 DBUG_ENTER("RaidFd::_Calculate"); 00143 DBUG_PRINT("info",("_position: %lu _raid_chunksize: %lu _size: %lu", 00144 (ulong) _position, _raid_chunksize, (ulong) _size)); 00145 00146 _total_block = (ulong) (_position / _raid_chunksize); 00147 _this_block = _total_block % _raid_chunks; /* can be 0.._raid_chunks */ 00148 _remaining_bytes = (uint) (_raid_chunksize - 00149 (_position - _total_block * _raid_chunksize)); 00150 DBUG_PRINT("info", 00151 ("_total_block: %lu this_block: %d _remaining_bytes: %d", 00152 _total_block, _this_block, _remaining_bytes)); 00153 DBUG_VOID_RETURN; 00154 } 00155 }; 00156 00157 #endif /* __cplusplus */ 00158 #endif /* USE_RAID */