home *** CD-ROM | disk | FTP | other *** search
/ PC World 2003 July & August / PCWorld_2003-07-08_cd.bin / Software / Vyzkuste / mysql / data1.cab / Development / include / raid.h < prev   
C/C++ Source or Header  |  2003-05-17  |  6KB  |  159 lines

  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; either version 2 of the License, or
  6.    (at your option) any later version.
  7.  
  8.    This program is distributed in the hope that it will be useful,
  9.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  10.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  11.    GNU General Public License for more details.
  12.  
  13.    You should have received a copy of the GNU General Public License
  14.    along with this program; if not, write to the Free Software
  15.    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
  16.  
  17. /* Parser needs these defines  always, even if USE_RAID is not defined */
  18. #define RAID_TYPE_0 1       /* Striping */
  19. #define RAID_TYPE_x 2       /* Some new modes */
  20. #define RAID_TYPE_y 3
  21.  
  22. #define RAID_DEFAULT_CHUNKS 4
  23. #define RAID_DEFAULT_CHUNKSIZE 256*1024 /* 256kB */
  24.  
  25. C_MODE_START
  26. #define my_raid_type(raid_type)  raid_type_string[(int)(raid_type)]
  27. extern const char *raid_type_string[];
  28. C_MODE_END
  29.  
  30. #ifdef DONT_USE_RAID
  31. #undef USE_RAID
  32. #endif
  33. #if defined(USE_RAID)
  34.  
  35. #ifdef __GNUC__
  36. #pragma interface            /* gcc class implementation */
  37. #endif
  38. #include "my_dir.h"
  39.  
  40. /* Trap all occurences of my_...() in source and use our wrapper around this function */
  41.  
  42. #ifdef MAP_TO_USE_RAID
  43. #define my_read(A,B,C,D)     my_raid_read(A,B,C,D)
  44. #define my_write(A,B,C,D)    my_raid_write(A,B,C,D)
  45. #define my_pwrite(A,B,C,D,E) my_raid_pwrite(A,B,C,D,E)
  46. #define my_pread(A,B,C,D,E)  my_raid_pread(A,B,C,D,E)
  47. #define my_chsize(A,B,C,D)   my_raid_chsize(A,B,C,D)
  48. #define my_close(A,B)        my_raid_close(A,B)
  49. #define my_tell(A,B)         my_raid_tell(A,B)
  50. #define my_seek(A,B,C,D)     my_raid_seek(A,B,C,D)
  51. #define my_lock(A,B,C,D,E)     my_raid_lock(A,B,C,D,E)
  52. #define my_fstat(A,B,C)     my_raid_fstat(A,B,C)
  53. #endif /* MAP_TO_USE_RAID */
  54.  
  55. #ifdef __cplusplus
  56. extern "C" {
  57. #endif
  58.  
  59.   void init_raid(void);
  60.   void end_raid(void);
  61.  
  62.   bool is_raid(File fd);
  63.   File my_raid_create(const char *FileName, int CreateFlags, int access_flags,
  64.               uint raid_type, uint raid_chunks, ulong raid_chunksize,
  65.               myf MyFlags);
  66.   File my_raid_open(const char *FileName, int Flags,
  67.             uint raid_type, uint raid_chunks, ulong raid_chunksize,
  68.             myf MyFlags);
  69.   int my_raid_rename(const char *from, const char *to, uint raid_chunks,
  70.              myf MyFlags);
  71.   int my_raid_delete(const char *from, uint raid_chunks, myf MyFlags);
  72.   int my_raid_redel(const char *old_name, const char *new_name,
  73.             uint raid_chunks, myf MyFlags);
  74.  
  75.   my_off_t my_raid_seek(File fd, my_off_t pos, int whence, myf MyFlags);
  76.   my_off_t my_raid_tell(File fd, myf MyFlags);
  77.  
  78.   uint my_raid_write(File,const byte *Buffer, uint Count, myf MyFlags);
  79.   uint my_raid_read(File Filedes, byte *Buffer, uint Count, myf MyFlags);
  80.  
  81.   uint my_raid_pread(File Filedes, byte *Buffer, uint Count, my_off_t offset,
  82.              myf MyFlags);
  83.   uint my_raid_pwrite(int Filedes, const byte *Buffer, uint Count,
  84.               my_off_t offset, myf MyFlags);
  85.  
  86.   int my_raid_lock(File,int locktype, my_off_t start, my_off_t length,
  87.            myf MyFlags);
  88.   int my_raid_chsize(File fd, my_off_t newlength, int filler, myf MyFlags);
  89.   int my_raid_close(File, myf MyFlags);
  90.   int my_raid_fstat(int Filedes, struct stat *buf,  myf MyFlags);
  91.  
  92. #ifdef __cplusplus
  93. }
  94.  
  95. class RaidName {
  96.   public:
  97.     RaidName(const char *FileName);
  98.     ~RaidName();
  99.     bool IsRaid();
  100.     int Rename(const char * from, const char * to, myf MyFlags);
  101.   private:
  102.     uint _raid_type;       /* RAID_TYPE_0 or RAID_TYPE_1 or RAID_TYPE_5 */
  103.     uint _raid_chunks;     /* 1..n */
  104.     ulong _raid_chunksize; /* 1..n in bytes */
  105. };
  106.  
  107. class RaidFd {
  108.   public:
  109.     RaidFd(uint raid_type, uint raid_chunks , ulong raid_chunksize);
  110.     ~RaidFd();
  111.     File Create(const char *FileName, int CreateFlags, int access_flags,
  112.         myf MyFlags);
  113.     File Open(const char *FileName, int Flags, myf MyFlags);
  114.     my_off_t Seek(my_off_t pos,int whence,myf MyFlags);
  115.     my_off_t Tell(myf MyFlags);
  116.     int Write(const byte *Buffer, uint Count, myf MyFlags);
  117.     int Read(const byte *Buffer, uint Count, myf MyFlags);
  118.     int Lock(int locktype, my_off_t start, my_off_t length, myf MyFlags);
  119.     int Chsize(File fd, my_off_t newlength, int filler, myf MyFlags);
  120.     int Fstat(int fd, MY_STAT *stat_area, myf MyFlags );
  121.     int Close(myf MyFlags);
  122.     static bool IsRaid(File fd);
  123.     static DYNAMIC_ARRAY _raid_map;        /* Map of RaidFD* */
  124.   private:
  125.  
  126.     uint _raid_type;       /* RAID_TYPE_0 or RAID_TYPE_1 or RAID_TYPE_5 */
  127.     uint _raid_chunks;     /* 1..n */
  128.     ulong _raid_chunksize; /* 1..n in bytes */
  129.  
  130.     ulong _total_block;    /* We are operating with block no x (can be 0..many). */
  131.     uint _this_block;      /* can be 0.._raid_chunks */
  132.     uint _remaining_bytes; /* Maximum bytes that can be written in this block */
  133.  
  134.     my_off_t _position;
  135.     my_off_t _size;        /* Cached file size for faster seek(SEEK_END) */
  136.     File _fd;
  137.     File *_fd_vector;        /* Array of File */
  138.     off_t *_seek_vector;    /* Array of cached seek positions */
  139.  
  140.     inline void Calculate()
  141.     {
  142.       DBUG_ENTER("RaidFd::_Calculate");
  143.       DBUG_PRINT("info",("_position: %lu _raid_chunksize: %d, _size: %lu",
  144.              (ulong) _position, _raid_chunksize, (ulong) _size));
  145.  
  146.       _total_block = (ulong) (_position / _raid_chunksize);
  147.       _this_block = _total_block % _raid_chunks;    /* can be 0.._raid_chunks */
  148.       _remaining_bytes = (uint) (_raid_chunksize -
  149.                  (_position - _total_block * _raid_chunksize));
  150.       DBUG_PRINT("info",
  151.          ("_total_block: %d  this_block: %d  _remaining_bytes:%d",
  152.           _total_block, _this_block, _remaining_bytes));
  153.       DBUG_VOID_RETURN;
  154.     }
  155. };
  156.  
  157. #endif /* __cplusplus */
  158. #endif /* USE_RAID */
  159.