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