summaryrefslogtreecommitdiff
path: root/Source/Kernel/VFS
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
parent435b36921c10fecc363a61010e35cc8e508425dc (diff)
downloadMelon-64fc3862f602750733b7dc0447d22ae5d4146821.tar.gz
Melon-64fc3862f602750733b7dc0447d22ae5d4146821.zip
Implemented ByteArray and wf command.
Diffstat (limited to 'Source/Kernel/VFS')
-rw-r--r--Source/Kernel/VFS/File.class.cpp27
-rw-r--r--Source/Kernel/VFS/File.class.h7
2 files changed, 32 insertions, 2 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) {
diff --git a/Source/Kernel/VFS/File.class.h b/Source/Kernel/VFS/File.class.h
index 955db85..460036c 100644
--- a/Source/Kernel/VFS/File.class.h
+++ b/Source/Kernel/VFS/File.class.h
@@ -2,6 +2,7 @@
#define DEF_FILE_CLASS_H
#include <VFS/FileNode.class.h>
+#include <Library/ByteArray.class.h>
enum {
FM_READ = 0, //Open for read, put cursor at beginning
@@ -30,12 +31,16 @@ class File {
~File();
bool open(String filename, u8int mode = FM_READ, FSNode* start = 0);
+ void close(bool unregisterFD = true); //unregisterFD = whether or not we must unregister the file descriptor from process
+
u32int read(u32int max_length, u8int *data);
bool write(u32int length, u8int *data);
+ u32int read(ByteArray &data); //Fills ByteArray at its current length or shrinks it if necessary
+ bool write(ByteArray &data);
+
bool seek(u64int count, u8int mode);
u64int position() { return m_position; }
u64int length() { return m_file->getLength(); }
- void close(bool unregisterFD = true); //unregisterFD = whether or not we must unregister the file descriptor from process
bool valid() { return m_valid; }
};