浏览代码

Make VFS test environment build again.

Andreas Kling 6 年之前
父节点
当前提交
981a3ae4b3

+ 3 - 3
AK/Lock.h

@@ -4,7 +4,9 @@
 
 #ifdef SERENITY
 #include "i386.h"
+int sched_yield();
 #else
+#include <sched.h>
 typedef int InterruptDisabler;
 #endif
 
@@ -14,8 +16,6 @@ void log_try_lock(const char*);
 void log_locked(const char*);
 void log_unlocked(const char*);
 
-void yield();
-
 namespace AK {
 
 static inline dword CAS(volatile dword* mem, dword newval, dword oldval)
@@ -51,7 +51,7 @@ public:
 #endif
                 return;
             }
-            yield();
+            sched_yield();
         }
     }
 

+ 2 - 1
Kernel/Disk.cpp

@@ -7,6 +7,7 @@
 #include "IO.h"
 #include "i386.h"
 #include "PIC.h"
+#include <AK/Lock.h>
 
 //#define DISK_DEBUG
 
@@ -55,7 +56,7 @@ static bool waitForInterrupt()
 #endif
     // FIXME: Add timeout.
     while (!interrupted) {
-        yield();
+        sched_yield();
     }
 #ifdef DISK_DEBUG
     kprintf("disk: got interrupt!\n");

+ 9 - 8
Kernel/Process.cpp

@@ -388,7 +388,7 @@ int Process::exec(const String& path, Vector<String>&& arguments, Vector<String>
 #endif
 
     if (current == this)
-        yield();
+        sched_yield();
 
     return 0;
 }
@@ -814,7 +814,7 @@ void Process::send_signal(int signal, Process* sender)
     dbgprintf("signal: %s(%u) sent %d to %s(%u)\n", sender->name().characters(), sender->pid(), signal, name().characters(), pid());
 
     if (sender == this) {
-        yield();
+        sched_yield();
         ASSERT_NOT_REACHED();
     }
 }
@@ -865,7 +865,7 @@ void Process::doHouseKeeping()
     s_deadProcesses->clear();
 }
 
-void yield()
+int sched_yield()
 {
     if (!current) {
         kprintf( "PANIC: yield() with !current" );
@@ -876,10 +876,11 @@ void yield()
 
     InterruptDisabler disabler;
     if (!scheduleNewProcess())
-        return;
+        return 1;
 
     //kprintf("yield() jumping to new process: %x (%s)\n", current->farPtr().selector, current->name().characters());
     switchNow();
+    return 0;
 }
 
 void switchNow()
@@ -1121,7 +1122,7 @@ ssize_t Process::sys$read(int fd, void* outbuf, size_t nread)
         if (!descriptor->hasDataAvailableForRead()) {
             m_fdBlockedOnRead = fd;
             block(BlockedRead);
-            yield();
+            sched_yield();
         }
     }
     nread = descriptor->read((byte*)outbuf, nread);
@@ -1351,7 +1352,7 @@ pid_t Process::sys$waitpid(pid_t waitee, int* wstatus, int options)
     m_waitee = waitee;
     m_waiteeStatus = 0;
     block(BlockedWait);
-    yield();
+    sched_yield();
     if (wstatus)
         *wstatus = m_waiteeStatus;
     return m_waitee;
@@ -1374,7 +1375,7 @@ void Process::block(Process::State state)
 void block(Process::State state)
 {
     current->block(state);
-    yield();
+    sched_yield();
 }
 
 void sleep(DWORD ticks)
@@ -1382,7 +1383,7 @@ void sleep(DWORD ticks)
     ASSERT(current->state() == Process::Running);
     current->setWakeupTime(system.uptime + ticks);
     current->block(Process::BlockedSleep);
-    yield();
+    sched_yield();
 }
 
 Process* Process::kernelProcess()

+ 1 - 1
Kernel/Process.h

@@ -284,7 +284,7 @@ static inline const char* toString(Process::State state)
     return nullptr;
 }
 
-extern void yield();
+extern int sched_yield();
 extern bool scheduleNewProcess();
 extern void switchNow();
 extern void block(Process::State);

+ 1 - 1
Kernel/Syscall.cpp

@@ -48,7 +48,7 @@ static DWORD handle(RegisterDump& regs, DWORD function, DWORD arg1, DWORD arg2,
     ASSERT_INTERRUPTS_ENABLED();
     switch (function) {
     case Syscall::SC_yield:
-        yield();
+        sched_yield();
         break;
     case Syscall::SC_putch:
         Console::the().putChar(arg1 & 0xff);

+ 9 - 2
VirtualFileSystem/FileDescriptor.cpp

@@ -3,9 +3,12 @@
 #include "CharacterDevice.h"
 #include "sys-errno.h"
 #include "UnixTypes.h"
-#include "TTY.h"
 #include <AK/BufferStream.h>
 
+#ifdef SERENITY
+#include "TTY.h"
+#endif
+
 RetainPtr<FileDescriptor> FileDescriptor::create(RetainPtr<VirtualFileSystem::Node>&& vnode)
 {
     return adopt(*new FileDescriptor(move(vnode)));
@@ -178,7 +181,8 @@ ssize_t FileDescriptor::get_dir_entries(byte* buffer, Unix::size_t size)
     memcpy(buffer, tempBuffer.pointer(), stream.offset());
     return stream.offset();
 }
-
+\
+#ifdef SERENITY
 bool FileDescriptor::isTTY() const
 {
     if (auto* device = m_vnode->characterDevice())
@@ -199,6 +203,7 @@ TTY* FileDescriptor::tty()
         return static_cast<TTY*>(device);
     return nullptr;
 }
+#endif
 
 int FileDescriptor::close()
 {
@@ -207,7 +212,9 @@ int FileDescriptor::close()
 
 String FileDescriptor::absolute_path() const
 {
+#ifdef SERENITY
     if (isTTY())
         return tty()->ttyName();
+#endif
     return VirtualFileSystem::the().absolutePath(m_vnode->inode);
 }

+ 4 - 0
VirtualFileSystem/FileDescriptor.h

@@ -5,7 +5,9 @@
 #include <AK/ByteBuffer.h>
 #include <AK/Retainable.h>
 
+#ifdef SERENITY
 class TTY;
+#endif
 
 class FileDescriptor : public Retainable<FileDescriptor> {
 public:
@@ -31,9 +33,11 @@ public:
 
     bool isDirectory() const;
 
+#ifdef SERENITY
     bool isTTY() const;
     const TTY* tty() const;
     TTY* tty();
+#endif
 
     InodeMetadata metadata() const { return m_vnode->metadata(); }
 

+ 1 - 1
VirtualFileSystem/Makefile

@@ -15,7 +15,7 @@ VFS_OBJS = \
     FileSystem.o \
     Ext2FileSystem.o \
     VirtualFileSystem.o \
-    FileHandle.o \
+    FileDescriptor.o \
     DiskBackedFileSystem.o \
     SyntheticFileSystem.o \
     InodeIdentifier.o \

+ 2 - 2
VirtualFileSystem/SyntheticFileSystem.cpp

@@ -37,8 +37,8 @@ bool SyntheticFileSystem::initialize()
     m_inodes.set(RootInodeIndex, move(rootDir));
 
 #ifndef SERENITY
-    addFile(createTextFile("file", "I'm a synthetic file!\n"));
-    addFile(createTextFile("message", "Hey! This isn't my bottle!\n"));
+    addFile(createTextFile("file", String("I'm a synthetic file!\n").toByteBuffer(), 0100644));
+    addFile(createTextFile("message", String("Hey! This isn't my bottle!\n").toByteBuffer(), 0100644));
     addFile(createGeneratedFile("lunk", [] { return String("/home/andreas/file1").toByteBuffer(); }, 00120777));
 #endif
     return true;

+ 4 - 9
VirtualFileSystem/VirtualFileSystem.cpp

@@ -12,24 +12,19 @@
 
 static VirtualFileSystem* s_the;
 
+#ifndef SERENITY
+typedef int InterruptDisabler;
+#endif
+
 VirtualFileSystem& VirtualFileSystem::the()
 {
     ASSERT(s_the);
     return *s_the;
 }
 
-static SpinLock* s_vfsLock;
-
-SpinLock& VirtualFileSystem::lock()
-{
-    ASSERT(s_vfsLock);
-    return *s_vfsLock;
-}
-
 void VirtualFileSystem::initializeGlobals()
 {
     s_the = nullptr;
-    s_vfsLock = new SpinLock;
     FileSystem::initializeGlobals();
 }
 

+ 0 - 2
VirtualFileSystem/VirtualFileSystem.h

@@ -5,7 +5,6 @@
 #include <AK/RetainPtr.h>
 #include <AK/String.h>
 #include <AK/Vector.h>
-#include <AK/Lock.h>
 #include <AK/Function.h>
 #include "InodeIdentifier.h"
 #include "InodeMetadata.h"
@@ -31,7 +30,6 @@ class VirtualFileSystem {
     AK_MAKE_ETERNAL
 public:
     static void initializeGlobals();
-    static SpinLock& lock();
 
     class Mount {
     public:

+ 4 - 4
VirtualFileSystem/test.cpp

@@ -26,16 +26,16 @@ int main(int c, char** v)
     VirtualFileSystem vfs;
 
     auto zero = make<ZeroDevice>();
-    vfs.registerCharacterDevice(1, 5, *zero);
+    vfs.registerCharacterDevice(*zero);
 
     auto null = make<NullDevice>();
-    vfs.registerCharacterDevice(1, 3, *null);
+    vfs.registerCharacterDevice(*null);
 
     auto full = make<FullDevice>();
-    vfs.registerCharacterDevice(1, 7, *full);
+    vfs.registerCharacterDevice(*full);
 
     auto random = make<RandomDevice>();
-    vfs.registerCharacterDevice(1, 8, *random);
+    vfs.registerCharacterDevice(*random);
 
     if (!vfs.mountRoot(makeFileSystem(filename))) {
         printf("Failed to mount root :(\n");