summaryrefslogtreecommitdiff
path: root/Source/Kernel/FileSystems
diff options
context:
space:
mode:
authorAlexis211 <alexis211@gmail.com>2009-11-27 20:43:25 +0100
committerAlexis211 <alexis211@gmail.com>2009-11-27 20:43:25 +0100
commit56ace5efd6ccc02004ddafb1e564a3f9d5d538d2 (patch)
treec8219690b234d5ac1b761236e4c43b9706057462 /Source/Kernel/FileSystems
parenta40fe1166ab1db972a8ca0380d603c4d90eede62 (diff)
downloadMelon-56ace5efd6ccc02004ddafb1e564a3f9d5d538d2.tar.gz
Melon-56ace5efd6ccc02004ddafb1e564a3f9d5d538d2.zip
Added some screenshots, re-organized some stuff.
Diffstat (limited to 'Source/Kernel/FileSystems')
-rw-r--r--Source/Kernel/FileSystems/FAT/FATFS.class.cpp26
-rw-r--r--Source/Kernel/FileSystems/FAT/FATFS.class.h6
-rw-r--r--Source/Kernel/FileSystems/RamFS/RamFS.class.h2
3 files changed, 23 insertions, 11 deletions
diff --git a/Source/Kernel/FileSystems/FAT/FATFS.class.cpp b/Source/Kernel/FileSystems/FAT/FATFS.class.cpp
index 4c662de..e4cb40c 100644
--- a/Source/Kernel/FileSystems/FAT/FATFS.class.cpp
+++ b/Source/Kernel/FileSystems/FAT/FATFS.class.cpp
@@ -12,14 +12,15 @@
((FATDirectoryNode*)(node))->m_firstDirEntryID : \
((FATFileNode*)(node))->m_firstDirEntryID))
-FATFS* FATFS::mount(Partition* p, DirectoryNode* mountpoint) {
+FileSystem* FATFS::mount(Partition* p, DirectoryNode* mountpoint, bool readwrite) {
+ if (readwrite) return 0;
if (mountpoint != 0 and !mountpoint->mountpointable()) return 0;
// *** READ BOOT SECTOR ***
union {
fat_BS_t s;
u8int c[512];
} bs;
- p->readBlocks(0, 1, bs.c);
+ if (!p->readBlocks(0, 1, bs.c)) return 0;
// *** CHECK FILESYSTEM TYPE ***
if (bs.s.extBS_16.boot_signature != 0x28 and bs.s.extBS_16.boot_signature != 0x29
and bs.s.extBS_32.boot_signature != 0x28 and bs.s.extBS_32.boot_signature != 0x29) return 0;
@@ -46,14 +47,19 @@ FATFS* FATFS::mount(Partition* p, DirectoryNode* mountpoint) {
fs->m_rootNode = new FATDirectoryNode("/", fs, mountpoint);
FIRSTCLUS(fs->m_rootNode) = 2;
if (fs->m_fatType == 32) FIRSTCLUS(fs->m_rootNode) = bs.s.extBS_32.root_cluster;
+ if (!fs->m_rootNode->loadContent()) {
+ *kvt << "Could not read FAT filesystem root directory.\n";
+ delete fs;
+ return 0;
+ }
if (mountpoint != 0) mountpoint->mount(fs->m_rootNode);
VFS::registerFilesystem(fs);
- *kvt << "\nDetected a FAT" << (s64int)fs->m_fatType << " filesystem.\n" <<
+ *kvt << "Detected 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 <<
- " cluster_size:" << fs->m_clusterSize;
- return 0;
+ " cluster_size:" << fs->m_clusterSize << "\n";
+ return fs;
}
u32int FATFS::nextCluster(u32int cluster) {
@@ -87,10 +93,10 @@ u32int FATFS::nextCluster(u32int cluster) {
return val;
}
-void FATFS::readCluster(u32int cluster, u8int* data) {
+bool FATFS::readCluster(u32int cluster, u8int* data) {
u32int firstSector = ((cluster - 2) * m_bs.sectors_per_cluster) + m_firstDataSector;
if (cluster > 2 and m_fatType != 32) firstSector += m_rootDirSectors;
- m_part->readBlocks(firstSector, m_bs.sectors_per_cluster, data);
+ return m_part->readBlocks(firstSector, m_bs.sectors_per_cluster, data);
}
bool FATFS::unmount() {
@@ -170,14 +176,16 @@ bool FATFS::loadContents(DirectoryNode* dir) {
u32int entries = m_clusterSize / sizeof(fat_dir_entry_t);
if (cluster == 2 and m_fatType != 32) { //This is the value we use for the root directory
e.c = (u8int*)Mem::alloc(m_rootDirSectors * m_part->getBlockSize());
- m_part->readBlocks(m_firstDataSector, m_rootDirSectors, e.c);
+ if (!m_part->readBlocks(m_firstDataSector, m_rootDirSectors, e.c)) return false;
} else {
e.c = (u8int*)Mem::alloc(m_clusterSize);
}
ByteArray lfnBuffer;
while (cluster != 0) {
- if (cluster != 2 or m_fatType == 32) readCluster(cluster, e.c);
+ if (cluster != 2 or m_fatType == 32) {
+ if (!readCluster(cluster, e.c)) return false;
+ }
for (u32int i = 0; i < entries; i++) {
if (e.e[i].attributes == FA_LFN && e.c[i*32] != 0xE5) { //Long file name entry
u8int num = e.c[i*32] & 0x3;
diff --git a/Source/Kernel/FileSystems/FAT/FATFS.class.h b/Source/Kernel/FileSystems/FAT/FATFS.class.h
index 50ff479..251b2a8 100644
--- a/Source/Kernel/FileSystems/FAT/FATFS.class.h
+++ b/Source/Kernel/FileSystems/FAT/FATFS.class.h
@@ -103,13 +103,15 @@ class FATFS : public FileSystem {
Partition* m_part;
u32int nextCluster(u32int cluster); //Get the next cluster number in the chain (0 = EOF)
- void readCluster(u32int cluster, u8int* data); //Read the content of a cluster to a buffer
+ bool readCluster(u32int cluster, u8int* data); //Read the content of a cluster to a buffer
public:
- static FATFS* mount(Partition* p, DirectoryNode* mountpoint);
+ static FileSystem* mount(Partition* p, DirectoryNode* mountpoint, bool readwrite = false);
bool unmount();
+ String getDevDescription() { return Part::partIdentifier(m_part); }
+
bool setName(FSNode* node, String name);
bool setPermissions(FSNode* node, u32int permissions);
bool setUid(FSNode* node, u32int uid);
diff --git a/Source/Kernel/FileSystems/RamFS/RamFS.class.h b/Source/Kernel/FileSystems/RamFS/RamFS.class.h
index 5ce85f1..042baa9 100644
--- a/Source/Kernel/FileSystems/RamFS/RamFS.class.h
+++ b/Source/Kernel/FileSystems/RamFS/RamFS.class.h
@@ -35,6 +35,8 @@ class RamFS : public FileSystem {
bool setGid(FSNode* node, u32int gid);
bool setParent(FSNode* node, FSNode* parent);
+ String getDevDescription() { return "ramfs"; }
+
u32int read(FileNode* file, u64int position, u32int max_length, u8int *data);
bool write(FileNode* file, u64int position, u32int length, u8int *data);
bool truncate(FileNode* file);