summaryrefslogtreecommitdiff
path: root/Source
diff options
context:
space:
mode:
authorAlexis211 <alexis211@gmail.com>2009-11-15 19:33:04 +0100
committerAlexis211 <alexis211@gmail.com>2009-11-15 19:33:04 +0100
commit3833a92d5823f0f54030dedbcadbda4ef8583b41 (patch)
tree79b7a82191d7bc9e07debd7c9377c71809828a1a /Source
parentca1b573ef87498595a30b757d6d9c66d12d14ae6 (diff)
downloadMelon-3833a92d5823f0f54030dedbcadbda4ef8583b41.tar.gz
Melon-3833a92d5823f0f54030dedbcadbda4ef8583b41.zip
Screwy implementation of FATFS::read
Diffstat (limited to 'Source')
-rw-r--r--Source/Kernel/Core/Sys.ns.cpp2
-rw-r--r--Source/Kernel/FileSystems/FAT/FATFS.class.cpp28
2 files changed, 27 insertions, 3 deletions
diff --git a/Source/Kernel/Core/Sys.ns.cpp b/Source/Kernel/Core/Sys.ns.cpp
index eeb92ee..49b2725 100644
--- a/Source/Kernel/Core/Sys.ns.cpp
+++ b/Source/Kernel/Core/Sys.ns.cpp
@@ -83,7 +83,7 @@ void dumpRegs(registers_t *regs, VirtualTerminal& vt) {
void stackTrace(u32int ebp, VirtualTerminal& vt, u32int maxframes) {
u32int *stack = (u32int*)ebp;
- for (u32int i = 0; i < maxframes and (u32int)stack > 0xC0000000; i++) {
+ for (u32int i = 0; i < maxframes and (u32int)stack > 0xC0000000 and (u32int)stack < (ebp + 0x10000); i++) {
vt << "Frame: " << (u32int)stack << " n:" << stack[0] << " r:" << stack[1] << "\n";
stack = (u32int*)stack[0];
}
diff --git a/Source/Kernel/FileSystems/FAT/FATFS.class.cpp b/Source/Kernel/FileSystems/FAT/FATFS.class.cpp
index 2590785..00107e5 100644
--- a/Source/Kernel/FileSystems/FAT/FATFS.class.cpp
+++ b/Source/Kernel/FileSystems/FAT/FATFS.class.cpp
@@ -50,7 +50,8 @@ FATFS* FATFS::mount(Partition* p, DirectoryNode* mountpoint) {
*kvt << "\nDetected a FAT" << (s64int)fs->m_fatType << " filesystem.\n" <<
"root_dir_sectors:" << fs->m_rootDirSectors << " fat_size:" << fs->m_fatSize << " total_sectors:" <<
fs->m_totalSectors << " data_sectors:" << dataSectors << " count_of_clusters:" << fs->m_countOfClusters <<
- " sizeof(fat_dir_entry_t):" << sizeof(fat_dir_entry_t) << " first_data_sector:" << fs->m_firstDataSector;
+ " sizeof(fat_dir_entry_t):" << sizeof(fat_dir_entry_t) << " first_data_sector:" << fs->m_firstDataSector <<
+ " cluster_size:" << fs->m_clusterSize;
return 0;
}
@@ -122,7 +123,30 @@ bool FATFS::setParent(FSNode* node, FSNode* parent) {
}
u32int FATFS::read(FileNode* file, u64int position, u32int max_length, u8int *data) {
- return 0;
+ u32int len = max_length;
+ if (position >= file->getLength()) return 0;
+ if (position + len > file->getLength()) len = len - position;
+ u32int firstCluster = position / m_clusterSize, clusterOffset = position % m_clusterSize;
+ u32int clusters = (len + clusterOffset) / m_clusterSize + 1, lastClusBytesToRead = (len + clusterOffset) % m_clusterSize;
+ u32int clust = FIRSTCLUS(file);
+ //Find first cluster
+ for (u32int i = 0; i < firstCluster and clust != 0; i++) clust = nextCluster(clust);
+ if (clust == 0) return 0;
+ //Read first cluster
+ u8int* temp = (u8int*)Mem::alloc(m_clusterSize);
+ readCluster(clust, temp);
+ memcpy(data, temp + clusterOffset, (m_clusterSize - clusterOffset));
+ //Read next clusters
+ u32int pos = (m_clusterSize - clusterOffset);
+ for (u32int i = 1; i < clusters; i++) {
+ clust = nextCluster(clust);
+ if (clust == 0) break;
+ readCluster(clust, temp);
+ memcpy(data + pos, temp, (i == clusters - 1 ? lastClusBytesToRead : m_clusterSize));
+ pos += m_clusterSize;
+ }
+ Mem::free(temp);
+ return len;
}
bool FATFS::write(FileNode* file, u64int position, u32int length, u8int* data) {