summaryrefslogtreecommitdiff
path: root/Source/Kernel/VFS/File.class.cpp
diff options
context:
space:
mode:
authorAlexis211 <alexis211@gmail.com>2009-09-19 19:21:28 +0200
committerAlexis211 <alexis211@gmail.com>2009-09-19 19:21:28 +0200
commit64fc3862f602750733b7dc0447d22ae5d4146821 (patch)
tree19d5a575c72744c75670543cdaedb1dce176a145 /Source/Kernel/VFS/File.class.cpp
parent435b36921c10fecc363a61010e35cc8e508425dc (diff)
downloadMelon-64fc3862f602750733b7dc0447d22ae5d4146821.tar.gz
Melon-64fc3862f602750733b7dc0447d22ae5d4146821.zip
Implemented ByteArray and wf command.
Diffstat (limited to 'Source/Kernel/VFS/File.class.cpp')
-rw-r--r--Source/Kernel/VFS/File.class.cpp27
1 files changed, 26 insertions, 1 deletions
diff --git a/Source/Kernel/VFS/File.class.cpp b/Source/Kernel/VFS/File.class.cpp
index ba837e9..f3c7d54 100644
--- a/Source/Kernel/VFS/File.class.cpp
+++ b/Source/Kernel/VFS/File.class.cpp
@@ -18,7 +18,11 @@ bool File::open(String filename, u8int mode, FSNode* start) {
if (m_valid) return false;
FSNode* node = VFS::find(filename, start);
- if (node == NULL) return false;
+ if (node == NULL){
+ if (mode == FM_READ) return false;
+ node = VFS::createFile(filename, start);
+ if (node == 0) return false;
+ }
if (node->type() != NT_FILE) return false;
m_file = (FileNode*) node;
@@ -62,6 +66,27 @@ bool File::write(u32int length, u8int *data) {
return false;
}
+u32int File::read(ByteArray &data) {
+ if (!m_valid) {
+ data.clear();
+ return 0;
+ }
+ u32int l = m_file->read(m_position, data.size(), (u8int*)data);
+ m_position += l;
+ if (l != data.size()) data.resize(l);
+ return l;
+}
+
+bool File::write(ByteArray &data) {
+ if (!m_valid) return false;
+ if (!m_writable) return false;
+ if (m_file->write(m_position, data.size(), (u8int*)data)) {
+ m_position += data.size();
+ return true;
+ }
+ return false;
+}
+
bool File::seek(u64int count, u8int mode) {
if (!m_valid) return false;
if (mode == SM_FORWARD) {