Team Fortress 2 Source Code as on 22/4/2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

161 lines
5.7 KiB

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