summaryrefslogtreecommitdiff
path: root/Source/Kernel
diff options
context:
space:
mode:
authorAlexis211 <alexis211@gmail.com>2009-10-24 18:24:46 +0200
committerAlexis211 <alexis211@gmail.com>2009-10-24 18:24:46 +0200
commitb639b99b3e8f4cf77560d8d473b13d992ac8eb10 (patch)
tree63ebeec75f4ab71d73d743afca04a98636dee165 /Source/Kernel
parentf62cfdc8ff6297616d68f6b195db7abc82ab457b (diff)
downloadMelon-b639b99b3e8f4cf77560d8d473b13d992ac8eb10.tar.gz
Melon-b639b99b3e8f4cf77560d8d473b13d992ac8eb10.zip
More work on userland syscalls : Files are implemented.
TextFile now is a common (= kernel and userland) library.
Diffstat (limited to 'Source/Kernel')
-rw-r--r--Source/Kernel/Core/Log.ns.h2
-rw-r--r--Source/Kernel/Core/Sys.ns.cpp5
-rw-r--r--Source/Kernel/Core/kmain.wtf.cpp1
-rw-r--r--Source/Kernel/Makefile4
-rw-r--r--Source/Kernel/Shell/KernelShell-fs.class.cpp3
-rw-r--r--Source/Kernel/SyscallManager/Res.ns.cpp2
-rw-r--r--Source/Kernel/TaskManager/Process.class.cpp42
-rw-r--r--Source/Kernel/TaskManager/Process.class.h4
-rw-r--r--Source/Kernel/UserManager/Usr.ns.cpp11
-rw-r--r--Source/Kernel/VFS/FSNode-sc.proto.cpp4
-rw-r--r--Source/Kernel/VFS/File-sc.class.cpp68
-rw-r--r--Source/Kernel/VFS/File.class.cpp29
-rw-r--r--Source/Kernel/VFS/File.class.h39
-rw-r--r--Source/Kernel/VFS/FileNode.class.h2
-rw-r--r--Source/Kernel/VFS/TextFile.class.cpp21
-rw-r--r--Source/Kernel/VFS/TextFile.class.h21
-rw-r--r--Source/Kernel/VFS/VFS.ns.cpp43
-rw-r--r--Source/Kernel/VFS/VFS.ns.h5
-rw-r--r--Source/Kernel/VTManager/FileVT.class.h2
19 files changed, 172 insertions, 136 deletions
diff --git a/Source/Kernel/Core/Log.ns.h b/Source/Kernel/Core/Log.ns.h
index d825f62..dc126dc 100644
--- a/Source/Kernel/Core/Log.ns.h
+++ b/Source/Kernel/Core/Log.ns.h
@@ -1,7 +1,7 @@
#ifndef DEF_LOG_NS_H
#define DEF_LOG_NS_H
-#include <VFS/TextFile.class.h>
+#include <TextFile.class.h>
#define KL_PANIC 0
#define KL_CRITICAL 1
diff --git a/Source/Kernel/Core/Sys.ns.cpp b/Source/Kernel/Core/Sys.ns.cpp
index 1b52c0f..e5dbdc0 100644
--- a/Source/Kernel/Core/Sys.ns.cpp
+++ b/Source/Kernel/Core/Sys.ns.cpp
@@ -5,6 +5,8 @@
#include <SyscallManager/IDT.ns.h>
#include <Sys.iface.h>
#include <UserManager/Usr.ns.h>
+#include <MemoryManager/PhysMem.ns.h>
+#include <DeviceManager/Time.ns.h>
#define DEBUGVT(x) SimpleVT *x = new SimpleVT(4, 56, 0, 15); x->map(); x->put('\n');
@@ -146,6 +148,9 @@ void halt() {
u32int scall(u8int wat, u32int a, u32int b, u32int c, u32int d) {
if (wat == SYIF_HALT && ISROOT) halt();
if (wat == SYIF_REBOOT && ISROOT) reboot();
+ if (wat == SYIF_UPTIME) return Time::uptime();
+ if (wat == SYIF_TOTALRAM) return PhysMem::total() * 4;
+ if (wat == SYIF_FREERAM) return PhysMem::free() * 4;
return (u32int) - 1;
}
diff --git a/Source/Kernel/Core/kmain.wtf.cpp b/Source/Kernel/Core/kmain.wtf.cpp
index d2f8c7b..76d8971 100644
--- a/Source/Kernel/Core/kmain.wtf.cpp
+++ b/Source/Kernel/Core/kmain.wtf.cpp
@@ -26,7 +26,6 @@
#include <VFS/FileNode.class.h>
#include <VFS/VFS.ns.h>
#include <VFS/DirectoryNode.class.h>
-#include <VFS/TextFile.class.h>
#include <Core/Log.ns.h>
#include <Shell/KernelShell.class.h>
diff --git a/Source/Kernel/Makefile b/Source/Kernel/Makefile
index 4f332d6..301d64c 100644
--- a/Source/Kernel/Makefile
+++ b/Source/Kernel/Makefile
@@ -52,12 +52,13 @@ Objects = Core/loader.wtf.o \
../Library/Common/Heap.class.o \
../Library/Common/Heap-index.class.o \
../Library/Common/Mutex.class.o \
+ ../Library/Common/TextFile.class.o \
VFS/Partition.class.o \
VFS/Part.ns.o \
VFS/VFS.ns.o \
VFS/FSNode-sc.proto.o \
VFS/File.class.o \
- VFS/TextFile.class.o \
+ VFS/File-sc.class.o \
VFS/DirectoryNode.class.o \
UserManager/Usr.ns.o \
FileSystems/RamFS/RamFS.class.o \
@@ -94,6 +95,7 @@ $(OutFile): $(Objects)
clean:
echo "* Removing object files..."
+ rm -rf $(Objects)
rm -rf *.o
rm -rf */*.o
rm -rf */*/*.o
diff --git a/Source/Kernel/Shell/KernelShell-fs.class.cpp b/Source/Kernel/Shell/KernelShell-fs.class.cpp
index f013f1b..bc7e137 100644
--- a/Source/Kernel/Shell/KernelShell-fs.class.cpp
+++ b/Source/Kernel/Shell/KernelShell-fs.class.cpp
@@ -115,6 +115,9 @@ void KernelShell::run(Vector<String>& args) {
} else {
p->setInVT(m_vt);
p->setOutVT(m_vt);
+ for (u32int i = 2; i < args.size(); i++) {
+ p->pushArg(args[i]);
+ }
p->start();
while (p->getState() != P_FINISHED) Task::currThread()->sleep(10);
delete p;
diff --git a/Source/Kernel/SyscallManager/Res.ns.cpp b/Source/Kernel/SyscallManager/Res.ns.cpp
index c554166..128f315 100644
--- a/Source/Kernel/SyscallManager/Res.ns.cpp
+++ b/Source/Kernel/SyscallManager/Res.ns.cpp
@@ -6,6 +6,7 @@
#include <FSNode.iface.h>
#include <Sys.iface.h>
#include <TaskManager/Task.ns.h>
+#include <VFS/File.class.h>
namespace Res {
@@ -21,6 +22,7 @@ static_call_t staticCalls[] = {
{PRIF_OBJTYPE, Process::scall},
{THIF_OBJTYPE, Thread::scall},
{FNIF_OBJTYPE, FSNode::scall},
+ {FLIF_OBJTYPE, File::scall},
{SYIF_IFID, Sys::scall},
{0, 0}
};
diff --git a/Source/Kernel/TaskManager/Process.class.cpp b/Source/Kernel/TaskManager/Process.class.cpp
index 5859f86..a7e7d7c 100644
--- a/Source/Kernel/TaskManager/Process.class.cpp
+++ b/Source/Kernel/TaskManager/Process.class.cpp
@@ -6,6 +6,8 @@
#include <Process.iface.h>
#include <UserManager/Usr.ns.h>
+#define ISPARENT Task::currProcess()->getPid() == m_ppid
+
namespace Mem {
extern Heap kheap;
}
@@ -16,7 +18,8 @@ call_t Process::m_callTable[] = {
CALL1(PRIF_FREEPAGE, &Process::freePageSC),
CALL0(PRIF_GETPID, &Process::getPid),
CALL0(PRIF_GETPPID, &Process::getPpid),
- CALL0(PRIF_GETCMDLINE, &Process::getCmdlineSC),
+ CALL0(PRIF_ARGC, &Process::argcSC),
+ CALL1(PRIF_ARGV, &Process::argvSC),
CALL0(0, 0)
};
@@ -100,16 +103,20 @@ void Process::start() {
if (m_state == P_STARTING) m_state = P_RUNNING;
}
+void Process::pushArg(const String& arg) {
+ m_arguments.push(arg);
+}
+
void Process::exit() {
for (u32int i = 0; i < m_threads.size(); i++) {
delete m_threads[i];
}
m_threads.clear();
- for (SimpleList<File*> *iter = m_fileDescriptors; iter != 0; iter = iter->next()) {
- iter->v()->close(false);
- delete iter->v();
+ while (m_fileDescriptors != 0) {
+ m_fileDescriptors->v()->close(false);
+ delete m_fileDescriptors->v();
+ m_fileDescriptors = m_fileDescriptors->delThis();
}
- if (m_fileDescriptors != 0) delete m_fileDescriptors; //Will recursively delete whole list
m_state = P_FINISHED;
}
@@ -177,20 +184,17 @@ u32int Process::allocPageSC(u32int pos) {
return 0;
}
-u32int Process::getCmdlineSC() {
- if (Usr::uid() == m_uid or ISROOT) {
- String cmdline;
- for (u32int i = 0; i < m_arguments.size(); i++) {
- if (i != 0) cmdline += " ";
- if (m_arguments[i].contains(" ")) {
- cmdline += "'";
- cmdline += m_arguments[i];
- cmdline += "'";
- } else {
- cmdline += m_arguments[i];
- }
- }
- return cmdline.serialize();
+u32int Process::argcSC() {
+ if (Usr::uid() == m_uid or ISROOT or ISPARENT) {
+ return (m_arguments.size());
+ }
+ return (u32int) - 1;
+}
+
+u32int Process::argvSC(u32int idx) {
+ if (idx >= m_arguments.size()) return (u32int) - 1;
+ if (Usr::uid() == m_uid or ISROOT or ISPARENT) {
+ return m_arguments[idx].serialize();
}
return (u32int) - 1;
}
diff --git a/Source/Kernel/TaskManager/Process.class.h b/Source/Kernel/TaskManager/Process.class.h
index d0556e5..ec5a90d 100644
--- a/Source/Kernel/TaskManager/Process.class.h
+++ b/Source/Kernel/TaskManager/Process.class.h
@@ -53,7 +53,8 @@ class Process : public Ressource {
//System calls
static call_t m_callTable[];
u32int exitSC();
- u32int getCmdlineSC();
+ u32int argcSC();
+ u32int argvSC(u32int);
u32int allocPageSC(u32int);
u32int freePageSC(u32int);
bool accessible();
@@ -69,6 +70,7 @@ class Process : public Ressource {
Heap& heap() { return *m_userHeap; }
void start(); //Starts thread execution - sets m_state to P_RUNNING if == P_STARTING
+ void pushArg(const String& arg);
void exit(); //Exits properly process by killing all threads and deleting file descriptors
void registerThread(Thread* t); //Called when a thread starts
void threadFinishes(Thread* thread, u32int retval); //Called when a thread finishes
diff --git a/Source/Kernel/UserManager/Usr.ns.cpp b/Source/Kernel/UserManager/Usr.ns.cpp
index a551344..db371ae 100644
--- a/Source/Kernel/UserManager/Usr.ns.cpp
+++ b/Source/Kernel/UserManager/Usr.ns.cpp
@@ -1,9 +1,10 @@
#include "Usr.ns.h"
+#include <Core/Log.ns.h>
#include <UserManager/User.class.h>
#include <SimpleList.class.h>
#include <TaskManager/Task.ns.h>
-#include <VFS/TextFile.class.h>
+#include <TextFile.class.h>
/*
* Syntax for Users and Groups configuration files : one entry per line
@@ -29,6 +30,10 @@ void load() {
m_groups = m_groups->cons(Group(data[1], data[0].toInt()));
}
}
+ if (m_groups == 0) {
+ m_groups = m_groups->cons(Group("root", 0)); //In case, add a default group
+ Log::log(KL_WARNING, "Usr.ns : group file invalid, had to add default group.");
+ }
TextFile users("/System/Configuration/Users", FM_READ);
while (!users.eof()) {
@@ -38,6 +43,10 @@ void load() {
m_users = m_users->cons(User(data[1], data[4], group(data[2].toInt()), data[3], data[0].toInt()));
}
}
+ if (m_users == 0) {
+ m_users = m_users->cons(User("melon", "MelOS", group(0), "", 0));
+ Log::log(KL_WARNING, "Usr.ns : users file invalid, had to add default users.");
+ }
}
void save() {
diff --git a/Source/Kernel/VFS/FSNode-sc.proto.cpp b/Source/Kernel/VFS/FSNode-sc.proto.cpp
index 279303b..717ccef 100644
--- a/Source/Kernel/VFS/FSNode-sc.proto.cpp
+++ b/Source/Kernel/VFS/FSNode-sc.proto.cpp
@@ -35,9 +35,9 @@ u32int FSNode::scall(u8int wat, u32int a, u32int b, u32int c, u32int d) {
String* path = (String*)a;
FSNode* n;
if (b == 0) {
- n = VFS::mkdir(*path);
+ n = VFS::createDirectory(*path, 0, true);
} else {
- n = VFS::mkdir(*path, Res::get<DirectoryNode>(b, FNIF_OBJTYPE));
+ n = VFS::createDirectory(*path, Res::get<DirectoryNode>(b, FNIF_OBJTYPE), true);
}
if (n != 0) return n->resId();
}
diff --git a/Source/Kernel/VFS/File-sc.class.cpp b/Source/Kernel/VFS/File-sc.class.cpp
new file mode 100644
index 0000000..e5e8e25
--- /dev/null
+++ b/Source/Kernel/VFS/File-sc.class.cpp
@@ -0,0 +1,68 @@
+#include "File.class.h"
+#include <VFS/VFS.ns.h>
+#include <TaskManager/Task.ns.h>
+#include <FSNode.iface.h>
+#include <SyscallManager/Res.ns.h>
+
+u32int File::scall(u8int wat, u32int a, u32int b, u32int c, u32int d) {
+ if (wat == FLIF_SOPEN) {
+ String* name = (String*)a;
+ FSNode* start = Res::get<FSNode>(c, FNIF_OBJTYPE);
+ File* f = new File();
+ if (!f->open(*name, b, start, true)) {
+ delete f;
+ } else {
+ return f->resId();
+ }
+ }
+ return (u32int) - 1;
+}
+
+u32int File::closeSC() {
+ if (!valid()) return 1;
+ close();
+ return 0;
+}
+
+u32int File::validSC() {
+ return (valid() ? 1 : 0);
+}
+
+u32int File::readSC(u32int max_length, u32int ptr) {
+ if (!m_file->readable()) return 0;
+ return read(max_length, (u8int*)ptr);
+}
+
+u32int File::writeSC(u32int length, u32int ptr) {
+ if (!m_file->writable()) return 0;
+ return (write(length, (u8int*)ptr) ? 1 : 0);
+}
+
+u32int File::seekSC(u32int counta, u32int countb, u32int mode) {
+ union {
+ u32int a[2];
+ u64int x;
+ } wat = {{counta, countb}};
+ return (seek(wat.x, mode) ? 1 : 0);
+}
+
+u32int File::positionSC() {
+ u64int* w = (u64int*)Mem::mkXchgSpace(sizeof(u64int));
+ *w = position();
+ return (u32int)w;
+}
+
+u32int File::lengthSC() {
+ u64int* w = (u64int*)Mem::mkXchgSpace(sizeof(u64int));
+ *w = length();
+ return (u32int)w;
+}
+
+u32int File::eofSC() {
+ return (eof() ? 1 : 0);
+}
+
+bool File::accessible() {
+ if (ISROOT or Usr::uid() == m_process->getUid()) return true;
+ return false;
+}
diff --git a/Source/Kernel/VFS/File.class.cpp b/Source/Kernel/VFS/File.class.cpp
index fbaabbe..c5ddcd6 100644
--- a/Source/Kernel/VFS/File.class.cpp
+++ b/Source/Kernel/VFS/File.class.cpp
@@ -2,11 +2,23 @@
#include <VFS/VFS.ns.h>
#include <TaskManager/Task.ns.h>
-File::File() : m_file(NULL), m_valid(false), m_writable(false), m_position(0) {
+call_t File::m_callTable[] = {
+ CALL0(FLIF_CLOSE, &File::closeSC),
+ CALL0(FLIF_VALID, &File::validSC),
+ CALL2(FLIF_READ, &File::readSC),
+ CALL2(FLIF_WRITE, &File::writeSC),
+ CALL3(FLIF_SEEK, &File::seekSC),
+ CALL0(FLIF_POSITION, &File::positionSC),
+ CALL0(FLIF_LENGTH, &File::lengthSC),
+ CALL0(FLIF_EOF, &File::eofSC),
+ CALL0(0, 0)
+};
+
+File::File() : Ressource(FLIF_OBJTYPE, m_callTable), m_file(NULL), m_valid(false), m_writable(false), m_position(0) {
}
File::File(String filename, u8int mode, FSNode* start) :
- m_file(NULL), m_valid(false), m_writable(false), m_position(0) {
+ Ressource(FLIF_OBJTYPE, m_callTable), m_file(NULL), m_valid(false), m_writable(false), m_position(0) {
open(filename, mode, start);
}
@@ -14,13 +26,13 @@ File::~File() {
close();
}
-bool File::open(String filename, u8int mode, FSNode* start) {
+bool File::open(String filename, u8int mode, FSNode* start, bool vrfyperm) {
if (m_valid) return false;
FSNode* node = VFS::find(filename, start);
if (node == NULL){
if (mode == FM_READ) return false;
- node = VFS::createFile(filename, start);
+ node = VFS::createFile(filename, start, vrfyperm);
if (node == 0) return false;
}
if (node->type() != NT_FILE) return false;
@@ -28,7 +40,9 @@ bool File::open(String filename, u8int mode, FSNode* start) {
m_file = (FileNode*) node;
m_writable = (mode != FM_READ);
- if (!m_file->writable() and m_writable) return false;
+ if (vrfyperm and m_writable and !m_file->writable()) return false;
+ if (vrfyperm and !m_file->readable()) return false;
+ if (!m_file->fsWritable() and m_writable) return false;
if (mode == FM_READ or mode == FM_REPLACE) {
m_position = 0;
@@ -44,7 +58,8 @@ bool File::open(String filename, u8int mode, FSNode* start) {
else
m_file->m_writers++;
- Task::currProcess()->registerFileDescriptor(this);
+ m_process = Task::currProcess();
+ m_process->registerFileDescriptor(this);
m_valid = true;
return true;
}
@@ -135,5 +150,5 @@ void File::close(bool unregisterFD) {
m_file = NULL;
m_position = 0;
m_writable = false;
- if (unregisterFD) Task::currProcess()->unregisterFileDescriptor(this);
+ if (unregisterFD) m_process->unregisterFileDescriptor(this);
}
diff --git a/Source/Kernel/VFS/File.class.h b/Source/Kernel/VFS/File.class.h
index f5d0c56..00b92b6 100644
--- a/Source/Kernel/VFS/File.class.h
+++ b/Source/Kernel/VFS/File.class.h
@@ -3,35 +3,40 @@
#include <VFS/FileNode.class.h>
#include <ByteArray.class.h>
+#include <File.iface.h>
+#include <SyscallManager/Ressource.class.h>
+class Process;
-enum {
- FM_READ = 0, //Open for read, put cursor at beginning
- FM_TRUNCATE = 1, //Open for write, truncating file before
- FM_APPEND = 2, //Open for write, put cursor at end
- FM_REPLACE = 3 //Open for write, put cursor at beginning
-};
-
-enum {
- SM_FORWARD = 0, //Seek from actual position
- SM_BACKWARD = 1, //Seek from actual position, backward
- SM_BEGINNING = 2, //Seek from start of file
- SM_END = 3, //Seek from end of file
-};
-
-class File {
+class File : public Ressource {
protected:
FileNode* m_file;
bool m_valid; //Is a file opened and valid ?
bool m_writable; //Is file opened for write ?
u64int m_position;
+ Process* m_process;
+
+ //Syscalls
+ static call_t m_callTable[];
+ u32int closeSC();
+ u32int validSC();
+ u32int readSC(u32int, u32int);
+ u32int writeSC(u32int, u32int);
+ u32int seekSC(u32int, u32int, u32int);
+ u32int positionSC();
+ u32int lengthSC();
+ u32int eofSC();
+ bool accessible();
public:
+ static u32int scall(u8int, u32int, u32int, u32int, u32int);
+
File();
File(String filename, u8int mode = FM_READ, FSNode* start = 0);
virtual ~File();
- bool open(String filename, u8int mode = FM_READ, FSNode* start = 0);
+ bool open(String filename, u8int mode = FM_READ, FSNode* start = 0, bool vrfyperm = false);
void close(bool unregisterFD = true); //unregisterFD = whether or not we must unregister the file descriptor from process
+ bool valid() { return m_valid; }
u32int read(u32int max_length, u8int *data);
bool write(u32int length, u8int *data);
@@ -49,8 +54,6 @@ class File {
u64int position() { return m_position; }
u64int length() { return m_file->getLength(); }
bool eof();
-
- bool valid() { return m_valid; }
};
#endif
diff --git a/Source/Kernel/VFS/FileNode.class.h b/Source/Kernel/VFS/FileNode.class.h
index 7ab617f..e99ef5e 100644
--- a/Source/Kernel/VFS/FileNode.class.h
+++ b/Source/Kernel/VFS/FileNode.class.h
@@ -19,7 +19,7 @@ class FileNode : public FSNode {
u8int type() { return NT_FILE; }
bool removable() { return true; }
bool used() { return (m_readers != 0 or m_writers != 0); }
- bool writable() { return m_fs->isWritable(); }
+ bool fsWritable() { return m_fs->isWritable(); }
u32int read(u64int position, u32int max_length, u8int *data) {
return m_fs->read(this, position, max_length, data);
diff --git a/Source/Kernel/VFS/TextFile.class.cpp b/Source/Kernel/VFS/TextFile.class.cpp
deleted file mode 100644
index a877392..0000000
--- a/Source/Kernel/VFS/TextFile.class.cpp
+++ /dev/null
@@ -1,21 +0,0 @@
-#include "TextFile.class.h"
-
-bool TextFile::write(String str, bool addnl) {
- ByteArray a(str, m_encoding);
- if (addnl) a += (u8int)'\n';
- return File::write(a);
-}
-
-String TextFile::readLine(char separator) {
- ByteArray buffer;
- while (1) {
- char c;
- if (read(1, (u8int*)&c) == 0) {
- return buffer.toString(m_encoding);
- }
- if (c == separator) {
- return buffer.toString(m_encoding);
- }
- buffer += (u8int)c;
- }
-}
diff --git a/Source/Kernel/VFS/TextFile.class.h b/Source/Kernel/VFS/TextFile.class.h
deleted file mode 100644
index a0cd505..0000000
--- a/Source/Kernel/VFS/TextFile.class.h
+++ /dev/null
@@ -1,21 +0,0 @@
-#ifndef DEF_TEXTFILE_CLASS_H
-#define DEF_TEXTFILE_CLASS_H
-
-#include <VFS/File.class.h>
-
-class TextFile : public File {
- private:
- u8int m_encoding;
-
- public:
- TextFile(u8int encoding = UE_UTF8) : File() { m_encoding = encoding; }
- TextFile(String filename, u8int mode = FM_READ, FSNode* start = 0, u8int encoding = UE_UTF8)
- : File(filename, mode, start) { m_encoding = encoding; }
- ~TextFile() {}
-
- void setEncoding(u8int encoding = UE_UTF8) { m_encoding = encoding; }
- bool write(String str, bool addnl = false); // Addnl = wether or not to add \n at end
- String readLine(char separator = '\n');
-};
-
-#endif
diff --git a/Source/Kernel/VFS/VFS.ns.cpp b/Source/Kernel/VFS/VFS.ns.cpp
index fdfc265..e95b911 100644
--- a/Source/Kernel/VFS/VFS.ns.cpp
+++ b/Source/Kernel/VFS/VFS.ns.cpp
@@ -39,7 +39,7 @@ FSNode* find(const String& path, FSNode* start) {
return node;
}
-FSNode* createFile(const String& path, FSNode* start) {
+FSNode* createFile(const String& path, FSNode* start, bool vrfyperm) {
if (find(path, start) != NULL) return NULL; //Something already has that name.
if (start == 0) start = rootNode;
@@ -65,13 +65,12 @@ FSNode* createFile(const String& path, FSNode* start) {
}
if (node->type() == NT_DIRECTORY) {
- return ((DirectoryNode*)node)->createFile(name);
- } else {
- return NULL;
+ if ((vrfyperm && node->writable()) or !vrfyperm) return ((DirectoryNode*)node)->createFile(name);
}
+ return NULL;
}
-FSNode* createDirectory(const String& path, FSNode* start) {
+FSNode* createDirectory(const String& path, FSNode* start, bool vrfyperm) {
if (find(path, start) != NULL) return NULL; //Something already has that name.
if (start == 0) start = rootNode;
@@ -97,40 +96,8 @@ FSNode* createDirectory(const String& path, FSNode* start) {
}
if (node->type() == NT_DIRECTORY) {
- return ((DirectoryNode*)node)->createDirectory(name);
- } else {
- return NULL;
+ if ((vrfyperm && node->writable()) or !vrfyperm) return ((DirectoryNode*)node)->createDirectory(name);
}
-}
-
-//Same as createDirectory but checks for parent directory permissions for current process
-FSNode* mkdir(const String& path, FSNode* start) {
- if (find(path, start) != NULL) return NULL; //Something already has that name.
- if (start == 0) start = rootNode;
-
- Vector<String> p = path.split("/");
- String name = p.back();
- p.pop();
-
- FSNode* node = start;
- if (!path.empty()) {
- if (p[0].empty()) node = rootNode;
- for (u32int i = 0; i < p.size(); i++) {
- if (p[i] == "..") {
- node = node->getParent();
- } else if (!p[i].empty() and p[i] != ".") {
- if (node->type() == NT_DIRECTORY) {
- node = ((DirectoryNode*)node)->getChild(p[i]);
- } else {
- node = NULL;
- }
- }
- if (node == NULL) return node;
- }
- }
-
- if (node->type() == NT_DIRECTORY)
- if (node->writable()) return ((DirectoryNode*)node)->createDirectory(name);
return NULL;
}
diff --git a/Source/Kernel/VFS/VFS.ns.h b/Source/Kernel/VFS/VFS.ns.h
index 63229bf..f1d628f 100644
--- a/Source/Kernel/VFS/VFS.ns.h
+++ b/Source/Kernel/VFS/VFS.ns.h
@@ -13,9 +13,8 @@ namespace VFS {
DirectoryNode* getRootNode();
FSNode* find(const String& path, FSNode* start = 0);
- FSNode* createFile(const String& path, FSNode* start = 0);
- FSNode* createDirectory(const String& path, FSNode* start = 0);
- FSNode* mkdir(const String& path, FSNode* start = 0); //Same as createDirectory, except it checks for parent directory writablilty by current process
+ FSNode* createFile(const String& path, FSNode* start = 0, bool vrfyperm = false);
+ FSNode* createDirectory(const String& path, FSNode* start = 0, bool vrfyperm = false);
bool remove(FSNode* node);
bool remove(const String& path, FSNode* start = 0); //Returns false for non-empty directories
String path(FSNode* node); //Returns complete path for a node
diff --git a/Source/Kernel/VTManager/FileVT.class.h b/Source/Kernel/VTManager/FileVT.class.h
index 61f4d6f..ed3e224 100644
--- a/Source/Kernel/VTManager/FileVT.class.h
+++ b/Source/Kernel/VTManager/FileVT.class.h
@@ -1,7 +1,7 @@
#ifndef DEF_FILEVT_CLASS_H
#define DEF_FILEVT_CLASS_H
-#include <VFS/TextFile.class.h>
+#include <TextFile.class.h>
#include <VTManager/VirtualTerminal.proto.h>
class FileVT : public VirtualTerminal {