Guest User

Untitled

a guest
Apr 24th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.87 KB | None | 0 0
  1. --- cache.h.orig 2008-03-31 00:49:26.000000000 -0700
  2. +++ cache.h 2008-03-31 01:16:05.000000000 -0700
  3. @@ -67,6 +67,8 @@ Precondition: offset + size <= BYTES_PER
  4. */
  5. bool _FAT_cache_readPartialSector (CACHE* cache, void* buffer, u32 sector, u32 offset, u32 size);
  6.  
  7. +bool _FAT_cache_readLittleEndianValue (CACHE* cache, u32 *value, u32 sector, u32 offset, u32 num_bytes);
  8. +
  9. /*
  10. Write data to a sector in the cache
  11. If the sector is not in the cache, it will be swapped in.
  12. @@ -77,6 +79,8 @@ Precondition: offset + size <= BYTES_PER
  13. */
  14. bool _FAT_cache_writePartialSector (CACHE* cache, const void* buffer, u32 sector, u32 offset, u32 size);
  15.  
  16. +bool _FAT_cache_writeLittleEndianValue (CACHE* cache, const u32 value, u32 sector, u32 offset, u32 num_bytes);
  17. +
  18. /*
  19. Write data to a sector in the cache, zeroing the sector first
  20. If the sector is not in the cache, it will be swapped in.
  21. --- cache.c.orig 2008-03-31 00:49:12.000000000 -0700
  22. +++ cache.c 2008-03-31 01:14:10.000000000 -0700
  23. @@ -40,6 +40,7 @@
  24. #include "disc_io/disc.h"
  25.  
  26. #include "mem_allocate.h"
  27. +#include "bit_ops.h"
  28.  
  29. #define CACHE_FREE 0xFFFFFFFF
  30.  
  31. @@ -163,6 +164,19 @@ bool _FAT_cache_readPartialSector (CACHE
  32. return true;
  33. }
  34.  
  35. +bool _FAT_cache_readLittleEndianValue (CACHE* cache, u32 *value, u32 sector, u32 offset, u32 num_bytes) {
  36. + u8 buf[4];
  37. + if (!_FAT_cache_readPartialSector(cache, buf, sector, offset, num_bytes)) return false;
  38. +
  39. + switch(num_bytes) {
  40. + case 1: *value = buf[0]; break;
  41. + case 2: *value = u8array_to_u16(buf,0); break;
  42. + case 4: *value = u8array_to_u32(buf,0); break;
  43. + default: return false;
  44. + }
  45. + return true;
  46. +}
  47. +
  48. /*
  49. Writes some data to a cache page, making sure it is loaded into memory first.
  50. */
  51. @@ -184,6 +198,19 @@ bool _FAT_cache_writePartialSector (CACH
  52. return true;
  53. }
  54.  
  55. +bool _FAT_cache_writeLittleEndianValue (CACHE* cache, const u32 value, u32 sector, u32 offset, u32 size) {
  56. + u8 buf[4] = {0, 0, 0, 0};
  57. +
  58. + switch(size) {
  59. + case 1: buf[0] = value; break;
  60. + case 2: u16_to_u8array(buf, 0, value); break;
  61. + case 4: u32_to_u8array(buf, 0, value); break;
  62. + default: return false;
  63. + }
  64. +
  65. + return _FAT_cache_writePartialSector(cache, buf, sector, offset, size);
  66. +}
  67. +
  68. /*
  69. Writes some data to a cache page, zeroing out the page first
  70. */
  71. --- file_allocation_table.c.orig 2008-03-31 00:45:41.000000000 -0700
  72. +++ file_allocation_table.c 2008-03-31 01:14:57.000000000 -0700
  73. @@ -71,7 +71,7 @@ u32 _FAT_fat_nextCluster(PARTITION* part
  74. offset = ((cluster * 3) / 2) % BYTES_PER_READ;
  75.  
  76.  
  77. - _FAT_cache_readPartialSector (partition->cache, &nextCluster, sector, offset, sizeof(u8));
  78. + _FAT_cache_readLittleEndianValue (partition->cache, &nextCluster, sector, offset, sizeof(u8));
  79.  
  80. offset++;
  81.  
  82. @@ -79,9 +79,11 @@ u32 _FAT_fat_nextCluster(PARTITION* part
  83. offset = 0;
  84. sector++;
  85. }
  86. -
  87. - _FAT_cache_readPartialSector (partition->cache, ((u8*)&nextCluster) + sizeof(u8), sector, offset, sizeof(u8));
  88. -
  89. + u32 nextCluster_h = 0;
  90. +
  91. + _FAT_cache_readLittleEndianValue (partition->cache, &nextCluster_h, sector, offset, sizeof(u8));
  92. + nextCluster |= (nextCluster_h << 8);
  93. +
  94. if (cluster & 0x01) {
  95. nextCluster = nextCluster >> 4;
  96. } else {
  97. @@ -99,7 +101,7 @@ u32 _FAT_fat_nextCluster(PARTITION* part
  98. sector = partition->fat.fatStart + ((cluster << 1) / BYTES_PER_READ);
  99. offset = (cluster % (BYTES_PER_READ >> 1)) << 1;
  100.  
  101. - _FAT_cache_readPartialSector (partition->cache, &nextCluster, sector, offset, sizeof(u16));
  102. + _FAT_cache_readLittleEndianValue (partition->cache, &nextCluster, sector, offset, sizeof(u16));
  103.  
  104. if (nextCluster >= 0xFFF7)
  105. {
  106. @@ -111,7 +113,7 @@ u32 _FAT_fat_nextCluster(PARTITION* part
  107. sector = partition->fat.fatStart + ((cluster << 2) / BYTES_PER_READ);
  108. offset = (cluster % (BYTES_PER_READ >> 2)) << 2;
  109.  
  110. - _FAT_cache_readPartialSector (partition->cache, &nextCluster, sector, offset, sizeof(u32));
  111. + _FAT_cache_readLittleEndianValue (partition->cache, &nextCluster, sector, offset, sizeof(u32));
  112.  
  113. if (nextCluster >= 0x0FFFFFF7)
  114. {
  115. @@ -134,7 +136,7 @@ on the cluster number.
  116. static bool _FAT_fat_writeFatEntry (PARTITION* partition, u32 cluster, u32 value) {
  117. u32 sector;
  118. int offset;
  119. - u8 oldValue;
  120. + u32 oldValue;
  121.  
  122. if ((cluster < CLUSTER_FIRST) || (cluster > partition->fat.lastCluster /* This will catch CLUSTER_ERROR */))
  123. {
  124. @@ -153,11 +155,11 @@ static bool _FAT_fat_writeFatEntry (PART
  125.  
  126. if (cluster & 0x01) {
  127.  
  128. - _FAT_cache_readPartialSector (partition->cache, &oldValue, sector, offset, sizeof(u8));
  129. + _FAT_cache_readLittleEndianValue (partition->cache, &oldValue, sector, offset, sizeof(u8));
  130.  
  131. value = (value << 4) | (oldValue & 0x0F);
  132.  
  133. - _FAT_cache_writePartialSector (partition->cache, &value, sector, offset, sizeof(u8));
  134. + _FAT_cache_writeLittleEndianValue (partition->cache, value & 0xFF, sector, offset, sizeof(u8));
  135.  
  136. offset++;
  137. if (offset >= BYTES_PER_READ) {
  138. @@ -165,11 +167,11 @@ static bool _FAT_fat_writeFatEntry (PART
  139. sector++;
  140. }
  141.  
  142. - _FAT_cache_writePartialSector (partition->cache, ((u8*)&value) + sizeof(u8), sector, offset, sizeof(u8));
  143. + _FAT_cache_writeLittleEndianValue (partition->cache, (value >> 8) & 0xFF, sector, offset, sizeof(u8));
  144.  
  145. } else {
  146.  
  147. - _FAT_cache_writePartialSector (partition->cache, &value, sector, offset, sizeof(u8));
  148. + _FAT_cache_writeLittleEndianValue (partition->cache, value, sector, offset, sizeof(u8));
  149.  
  150. offset++;
  151. if (offset >= BYTES_PER_READ) {
  152. @@ -177,11 +179,11 @@ static bool _FAT_fat_writeFatEntry (PART
  153. sector++;
  154. }
  155.  
  156. - _FAT_cache_readPartialSector (partition->cache, &oldValue, sector, offset, sizeof(u8));
  157. + _FAT_cache_readLittleEndianValue (partition->cache, &oldValue, sector, offset, sizeof(u8));
  158.  
  159. value = ((value >> 8) & 0x0F) | (oldValue & 0xF0);
  160.  
  161. - _FAT_cache_writePartialSector (partition->cache, &value, sector, offset, sizeof(u8));
  162. + _FAT_cache_writeLittleEndianValue (partition->cache, value, sector, offset, sizeof(u8));
  163. }
  164.  
  165. break;
  166. @@ -190,7 +192,7 @@ static bool _FAT_fat_writeFatEntry (PART
  167. sector = partition->fat.fatStart + ((cluster << 1) / BYTES_PER_READ);
  168. offset = (cluster % (BYTES_PER_READ >> 1)) << 1;
  169.  
  170. - _FAT_cache_writePartialSector (partition->cache, &value, sector, offset, sizeof(u16));
  171. + _FAT_cache_writeLittleEndianValue (partition->cache, value, sector, offset, sizeof(u16));
  172.  
  173. break;
  174.  
  175. @@ -198,7 +200,7 @@ static bool _FAT_fat_writeFatEntry (PART
  176. sector = partition->fat.fatStart + ((cluster << 2) / BYTES_PER_READ);
  177. offset = (cluster % (BYTES_PER_READ >> 2)) << 2;
  178.  
  179. - _FAT_cache_writePartialSector (partition->cache, &value, sector, offset, sizeof(u32));
  180. + _FAT_cache_writeLittleEndianValue (partition->cache, value, sector, offset, sizeof(u32));
  181.  
  182. break;
Add Comment
Please, Sign In to add comment