summaryrefslogtreecommitdiff
path: root/src/kernel/vfs
diff options
context:
space:
mode:
Diffstat (limited to 'src/kernel/vfs')
-rw-r--r--src/kernel/vfs/node.h2
-rw-r--r--src/kernel/vfs/vfile.cpp14
-rw-r--r--src/kernel/vfs/vfile.h2
3 files changed, 15 insertions, 3 deletions
diff --git a/src/kernel/vfs/node.h b/src/kernel/vfs/node.h
index b0ade41..c3b1585 100644
--- a/src/kernel/vfs/node.h
+++ b/src/kernel/vfs/node.h
@@ -28,7 +28,7 @@ class node {
virtual size_t get_size() { return 0; }
virtual int link(node* other, int mode) { return E_NOT_IMPLEMENTED; }
- // kind of like dynamic_cast'int these things
+ // kind of like dynamic_cast'ing these things
virtual display *as_display() { return 0; }
virtual vt *as_vt() { return 0; }
};
diff --git a/src/kernel/vfs/vfile.cpp b/src/kernel/vfs/vfile.cpp
index ff57c9e..38ea291 100644
--- a/src/kernel/vfs/vfile.cpp
+++ b/src/kernel/vfs/vfile.cpp
@@ -12,7 +12,19 @@ vfile::~vfile() {
if (own_data) kfree(data);
}
+int vfile::open(process *proc, int mode) {
+ if (mode & FM_TRUNC) {
+ if (own_data) kfree(data);
+ size = 0;
+ own_data = false;
+ data = 0;
+ }
+ return 0;
+}
+
int vfile::read(size_t offset, size_t len, char* buffer) {
+ if (size == 0) return 0;
+
if (offset + len > size) len = size - offset;
memcpy(buffer, data + offset, len);
return len;
@@ -22,7 +34,7 @@ int vfile::write(size_t offset, size_t len, char* buffer) {
size_t new_size = MAX(offset + len, size);
if (!own_data || new_size > size) {
char* new_data = (char*)kmalloc(new_size);
- memcpy(new_data, data, size);
+ if (size > 0) memcpy(new_data, data, size);
if (new_size > size) memset(new_data + size, 0, new_size - size);
if (own_data) kfree(data);
data = new_data;
diff --git a/src/kernel/vfs/vfile.h b/src/kernel/vfs/vfile.h
index 9b68b68..ffbccf9 100644
--- a/src/kernel/vfs/vfile.h
+++ b/src/kernel/vfs/vfile.h
@@ -13,7 +13,7 @@ class vfile : public node {
vfile(node* parent, char* data = 0, size_t size = 0);
virtual ~vfile();
- // TODO: handle open(TRUNC)
+ virtual int open(process *proc, int mode);
virtual int read(size_t offset, size_t len, char* buffer);
virtual int write(size_t offset, size_t len, char* buffer);
virtual size_t get_size() { return size; }