Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --- cache.h.orig 2008-03-31 00:49:26.000000000 -0700
- +++ cache.h 2008-03-31 01:16:05.000000000 -0700
- @@ -67,6 +67,8 @@ Precondition: offset + size <= BYTES_PER
- */
- bool _FAT_cache_readPartialSector (CACHE* cache, void* buffer, u32 sector, u32 offset, u32 size);
- +bool _FAT_cache_readLittleEndianValue (CACHE* cache, u32 *value, u32 sector, u32 offset, u32 num_bytes);
- +
- /*
- Write data to a sector in the cache
- If the sector is not in the cache, it will be swapped in.
- @@ -77,6 +79,8 @@ Precondition: offset + size <= BYTES_PER
- */
- bool _FAT_cache_writePartialSector (CACHE* cache, const void* buffer, u32 sector, u32 offset, u32 size);
- +bool _FAT_cache_writeLittleEndianValue (CACHE* cache, const u32 value, u32 sector, u32 offset, u32 num_bytes);
- +
- /*
- Write data to a sector in the cache, zeroing the sector first
- If the sector is not in the cache, it will be swapped in.
- --- cache.c.orig 2008-03-31 00:49:12.000000000 -0700
- +++ cache.c 2008-03-31 01:14:10.000000000 -0700
- @@ -40,6 +40,7 @@
- #include "disc_io/disc.h"
- #include "mem_allocate.h"
- +#include "bit_ops.h"
- #define CACHE_FREE 0xFFFFFFFF
- @@ -163,6 +164,19 @@ bool _FAT_cache_readPartialSector (CACHE
- return true;
- }
- +bool _FAT_cache_readLittleEndianValue (CACHE* cache, u32 *value, u32 sector, u32 offset, u32 num_bytes) {
- + u8 buf[4];
- + if (!_FAT_cache_readPartialSector(cache, buf, sector, offset, num_bytes)) return false;
- +
- + switch(num_bytes) {
- + case 1: *value = buf[0]; break;
- + case 2: *value = u8array_to_u16(buf,0); break;
- + case 4: *value = u8array_to_u32(buf,0); break;
- + default: return false;
- + }
- + return true;
- +}
- +
- /*
- Writes some data to a cache page, making sure it is loaded into memory first.
- */
- @@ -184,6 +198,19 @@ bool _FAT_cache_writePartialSector (CACH
- return true;
- }
- +bool _FAT_cache_writeLittleEndianValue (CACHE* cache, const u32 value, u32 sector, u32 offset, u32 size) {
- + u8 buf[4] = {0, 0, 0, 0};
- +
- + switch(size) {
- + case 1: buf[0] = value; break;
- + case 2: u16_to_u8array(buf, 0, value); break;
- + case 4: u32_to_u8array(buf, 0, value); break;
- + default: return false;
- + }
- +
- + return _FAT_cache_writePartialSector(cache, buf, sector, offset, size);
- +}
- +
- /*
- Writes some data to a cache page, zeroing out the page first
- */
- --- file_allocation_table.c.orig 2008-03-31 00:45:41.000000000 -0700
- +++ file_allocation_table.c 2008-03-31 01:14:57.000000000 -0700
- @@ -71,7 +71,7 @@ u32 _FAT_fat_nextCluster(PARTITION* part
- offset = ((cluster * 3) / 2) % BYTES_PER_READ;
- - _FAT_cache_readPartialSector (partition->cache, &nextCluster, sector, offset, sizeof(u8));
- + _FAT_cache_readLittleEndianValue (partition->cache, &nextCluster, sector, offset, sizeof(u8));
- offset++;
- @@ -79,9 +79,11 @@ u32 _FAT_fat_nextCluster(PARTITION* part
- offset = 0;
- sector++;
- }
- -
- - _FAT_cache_readPartialSector (partition->cache, ((u8*)&nextCluster) + sizeof(u8), sector, offset, sizeof(u8));
- -
- + u32 nextCluster_h = 0;
- +
- + _FAT_cache_readLittleEndianValue (partition->cache, &nextCluster_h, sector, offset, sizeof(u8));
- + nextCluster |= (nextCluster_h << 8);
- +
- if (cluster & 0x01) {
- nextCluster = nextCluster >> 4;
- } else {
- @@ -99,7 +101,7 @@ u32 _FAT_fat_nextCluster(PARTITION* part
- sector = partition->fat.fatStart + ((cluster << 1) / BYTES_PER_READ);
- offset = (cluster % (BYTES_PER_READ >> 1)) << 1;
- - _FAT_cache_readPartialSector (partition->cache, &nextCluster, sector, offset, sizeof(u16));
- + _FAT_cache_readLittleEndianValue (partition->cache, &nextCluster, sector, offset, sizeof(u16));
- if (nextCluster >= 0xFFF7)
- {
- @@ -111,7 +113,7 @@ u32 _FAT_fat_nextCluster(PARTITION* part
- sector = partition->fat.fatStart + ((cluster << 2) / BYTES_PER_READ);
- offset = (cluster % (BYTES_PER_READ >> 2)) << 2;
- - _FAT_cache_readPartialSector (partition->cache, &nextCluster, sector, offset, sizeof(u32));
- + _FAT_cache_readLittleEndianValue (partition->cache, &nextCluster, sector, offset, sizeof(u32));
- if (nextCluster >= 0x0FFFFFF7)
- {
- @@ -134,7 +136,7 @@ on the cluster number.
- static bool _FAT_fat_writeFatEntry (PARTITION* partition, u32 cluster, u32 value) {
- u32 sector;
- int offset;
- - u8 oldValue;
- + u32 oldValue;
- if ((cluster < CLUSTER_FIRST) || (cluster > partition->fat.lastCluster /* This will catch CLUSTER_ERROR */))
- {
- @@ -153,11 +155,11 @@ static bool _FAT_fat_writeFatEntry (PART
- if (cluster & 0x01) {
- - _FAT_cache_readPartialSector (partition->cache, &oldValue, sector, offset, sizeof(u8));
- + _FAT_cache_readLittleEndianValue (partition->cache, &oldValue, sector, offset, sizeof(u8));
- value = (value << 4) | (oldValue & 0x0F);
- - _FAT_cache_writePartialSector (partition->cache, &value, sector, offset, sizeof(u8));
- + _FAT_cache_writeLittleEndianValue (partition->cache, value & 0xFF, sector, offset, sizeof(u8));
- offset++;
- if (offset >= BYTES_PER_READ) {
- @@ -165,11 +167,11 @@ static bool _FAT_fat_writeFatEntry (PART
- sector++;
- }
- - _FAT_cache_writePartialSector (partition->cache, ((u8*)&value) + sizeof(u8), sector, offset, sizeof(u8));
- + _FAT_cache_writeLittleEndianValue (partition->cache, (value >> 8) & 0xFF, sector, offset, sizeof(u8));
- } else {
- - _FAT_cache_writePartialSector (partition->cache, &value, sector, offset, sizeof(u8));
- + _FAT_cache_writeLittleEndianValue (partition->cache, value, sector, offset, sizeof(u8));
- offset++;
- if (offset >= BYTES_PER_READ) {
- @@ -177,11 +179,11 @@ static bool _FAT_fat_writeFatEntry (PART
- sector++;
- }
- - _FAT_cache_readPartialSector (partition->cache, &oldValue, sector, offset, sizeof(u8));
- + _FAT_cache_readLittleEndianValue (partition->cache, &oldValue, sector, offset, sizeof(u8));
- value = ((value >> 8) & 0x0F) | (oldValue & 0xF0);
- - _FAT_cache_writePartialSector (partition->cache, &value, sector, offset, sizeof(u8));
- + _FAT_cache_writeLittleEndianValue (partition->cache, value, sector, offset, sizeof(u8));
- }
- break;
- @@ -190,7 +192,7 @@ static bool _FAT_fat_writeFatEntry (PART
- sector = partition->fat.fatStart + ((cluster << 1) / BYTES_PER_READ);
- offset = (cluster % (BYTES_PER_READ >> 1)) << 1;
- - _FAT_cache_writePartialSector (partition->cache, &value, sector, offset, sizeof(u16));
- + _FAT_cache_writeLittleEndianValue (partition->cache, value, sector, offset, sizeof(u16));
- break;
- @@ -198,7 +200,7 @@ static bool _FAT_fat_writeFatEntry (PART
- sector = partition->fat.fatStart + ((cluster << 2) / BYTES_PER_READ);
- offset = (cluster % (BYTES_PER_READ >> 2)) << 2;
- - _FAT_cache_writePartialSector (partition->cache, &value, sector, offset, sizeof(u32));
- + _FAT_cache_writeLittleEndianValue (partition->cache, value, sector, offset, sizeof(u32));
- break;
Add Comment
Please, Sign In to add comment