Annotation of win32/sql/mysql/include/raid.h, revision 1.2

1.2     ! misha       1: /* Copyright (C) 2000 MySQL AB
1.1       parser      2: 
1.2     ! misha       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 */
1.1       parser     15: 
                     16: /* Parser needs these defines  always, even if USE_RAID is not defined */
1.2     ! misha      17: #define RAID_TYPE_0 1       /* Striping */
        !            18: #define RAID_TYPE_x 2       /* Some new modes */
        !            19: #define RAID_TYPE_y 3
1.1       parser     20: 
                     21: #define RAID_DEFAULT_CHUNKS 4
                     22: #define RAID_DEFAULT_CHUNKSIZE 256*1024 /* 256kB */
                     23: 
1.2     ! misha      24: C_MODE_START
        !            25: #define my_raid_type(raid_type)  raid_type_string[(int)(raid_type)]
1.1       parser     26: extern const char *raid_type_string[];
1.2     ! misha      27: C_MODE_END
1.1       parser     28: 
1.2     ! misha      29: #ifdef DONT_USE_RAID
        !            30: #undef USE_RAID
        !            31: #endif
1.1       parser     32: #if defined(USE_RAID)
                     33: 
                     34: #include "my_dir.h"
                     35: 
                     36: /* Trap all occurences of my_...() in source and use our wrapper around this function */
                     37: 
                     38: #ifdef MAP_TO_USE_RAID
                     39: #define my_read(A,B,C,D)     my_raid_read(A,B,C,D)
                     40: #define my_write(A,B,C,D)    my_raid_write(A,B,C,D)
                     41: #define my_pwrite(A,B,C,D,E) my_raid_pwrite(A,B,C,D,E)
                     42: #define my_pread(A,B,C,D,E)  my_raid_pread(A,B,C,D,E)
1.2     ! misha      43: #define my_chsize(A,B,C,D)   my_raid_chsize(A,B,C,D)
1.1       parser     44: #define my_close(A,B)        my_raid_close(A,B)
                     45: #define my_tell(A,B)         my_raid_tell(A,B)
                     46: #define my_seek(A,B,C,D)     my_raid_seek(A,B,C,D)
                     47: #define my_lock(A,B,C,D,E)     my_raid_lock(A,B,C,D,E)
                     48: #define my_fstat(A,B,C)     my_raid_fstat(A,B,C)
                     49: #endif /* MAP_TO_USE_RAID */
                     50: 
                     51: #ifdef __cplusplus
                     52: extern "C" {
                     53: #endif
                     54: 
                     55:   void init_raid(void);
                     56:   void end_raid(void);
                     57: 
                     58:   bool is_raid(File fd);
                     59:   File my_raid_create(const char *FileName, int CreateFlags, int access_flags,
                     60:                      uint raid_type, uint raid_chunks, ulong raid_chunksize,
                     61:                      myf MyFlags);
                     62:   File my_raid_open(const char *FileName, int Flags,
                     63:                    uint raid_type, uint raid_chunks, ulong raid_chunksize,
                     64:                    myf MyFlags);
                     65:   int my_raid_rename(const char *from, const char *to, uint raid_chunks,
                     66:                     myf MyFlags);
                     67:   int my_raid_delete(const char *from, uint raid_chunks, myf MyFlags);
                     68:   int my_raid_redel(const char *old_name, const char *new_name,
                     69:                    uint raid_chunks, myf MyFlags);
                     70: 
                     71:   my_off_t my_raid_seek(File fd, my_off_t pos, int whence, myf MyFlags);
                     72:   my_off_t my_raid_tell(File fd, myf MyFlags);
                     73: 
                     74:   uint my_raid_write(File,const byte *Buffer, uint Count, myf MyFlags);
                     75:   uint my_raid_read(File Filedes, byte *Buffer, uint Count, myf MyFlags);
                     76: 
                     77:   uint my_raid_pread(File Filedes, byte *Buffer, uint Count, my_off_t offset,
                     78:                     myf MyFlags);
                     79:   uint my_raid_pwrite(int Filedes, const byte *Buffer, uint Count,
                     80:                      my_off_t offset, myf MyFlags);
                     81: 
                     82:   int my_raid_lock(File,int locktype, my_off_t start, my_off_t length,
                     83:                   myf MyFlags);
1.2     ! misha      84:   int my_raid_chsize(File fd, my_off_t newlength, int filler, myf MyFlags);
1.1       parser     85:   int my_raid_close(File, myf MyFlags);
                     86:   int my_raid_fstat(int Filedes, struct stat *buf,  myf MyFlags);
                     87: 
                     88: #ifdef __cplusplus
                     89: }
                     90: 
1.2     ! misha      91: #ifdef USE_PRAGMA_INTERFACE
        !            92: #pragma interface                      /* gcc class implementation */
        !            93: #endif
        !            94: 
1.1       parser     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:
1.2     ! misha     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 */
1.1       parser    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);
1.2     ! misha     119:     int Chsize(File fd, my_off_t newlength, int filler, myf MyFlags);
1.1       parser    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: 
1.2     ! misha     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 */
1.1       parser    133: 
                    134:     my_off_t _position;
1.2     ! misha     135:     my_off_t _size;        /* Cached file size for faster seek(SEEK_END) */
1.1       parser    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");
1.2     ! misha     143:       DBUG_PRINT("info",("_position: %lu  _raid_chunksize: %lu  _size: %lu",
1.1       parser    144:                         (ulong) _position, _raid_chunksize, (ulong) _size));
                    145: 
                    146:       _total_block = (ulong) (_position / _raid_chunksize);
1.2     ! misha     147:       _this_block = _total_block % _raid_chunks;    /* can be 0.._raid_chunks */
1.1       parser    148:       _remaining_bytes = (uint) (_raid_chunksize -
                    149:                                 (_position - _total_block * _raid_chunksize));
                    150:       DBUG_PRINT("info",
1.2     ! misha     151:                 ("_total_block: %lu  this_block: %d  _remaining_bytes: %d",
1.1       parser    152:                  _total_block, _this_block, _remaining_bytes));
                    153:       DBUG_VOID_RETURN;
                    154:     }
                    155: };
                    156: 
                    157: #endif /* __cplusplus */
                    158: #endif /* USE_RAID */

E-mail: