Skip to content

Commit

Permalink
Make VFS test environment build again.
Browse files Browse the repository at this point in the history
  • Loading branch information
awesomekling committed Nov 7, 2018
1 parent 83172e6 commit 981a3ae
Show file tree
Hide file tree
Showing 12 changed files with 40 additions and 34 deletions.
6 changes: 3 additions & 3 deletions AK/Lock.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@

#ifdef SERENITY
#include "i386.h"
int sched_yield();
#else
#include <sched.h>
typedef int InterruptDisabler;
#endif

Expand All @@ -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)
Expand Down Expand Up @@ -51,7 +51,7 @@ class SpinLock {
#endif
return;
}
yield();
sched_yield();
}
}

Expand Down
3 changes: 2 additions & 1 deletion Kernel/Disk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "IO.h"
#include "i386.h"
#include "PIC.h"
#include <AK/Lock.h>

//#define DISK_DEBUG

Expand Down Expand Up @@ -55,7 +56,7 @@ static bool waitForInterrupt()
#endif
// FIXME: Add timeout.
while (!interrupted) {
yield();
sched_yield();
}
#ifdef DISK_DEBUG
kprintf("disk: got interrupt!\n");
Expand Down
17 changes: 9 additions & 8 deletions Kernel/Process.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ int Process::exec(const String& path, Vector<String>&& arguments, Vector<String>
#endif

if (current == this)
yield();
sched_yield();

return 0;
}
Expand Down Expand Up @@ -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();
}
}
Expand Down Expand Up @@ -865,7 +865,7 @@ void Process::doHouseKeeping()
s_deadProcesses->clear();
}

void yield()
int sched_yield()
{
if (!current) {
kprintf( "PANIC: yield() with !current" );
Expand All @@ -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()
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand All @@ -1374,15 +1375,15 @@ void Process::block(Process::State state)
void block(Process::State state)
{
current->block(state);
yield();
sched_yield();
}

void sleep(DWORD ticks)
{
ASSERT(current->state() == Process::Running);
current->setWakeupTime(system.uptime + ticks);
current->block(Process::BlockedSleep);
yield();
sched_yield();
}

Process* Process::kernelProcess()
Expand Down
2 changes: 1 addition & 1 deletion Kernel/Process.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion Kernel/Syscall.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
11 changes: 9 additions & 2 deletions VirtualFileSystem/FileDescriptor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)));
Expand Down Expand Up @@ -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())
Expand All @@ -199,6 +203,7 @@ TTY* FileDescriptor::tty()
return static_cast<TTY*>(device);
return nullptr;
}
#endif

int FileDescriptor::close()
{
Expand All @@ -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 changes: 4 additions & 0 deletions VirtualFileSystem/FileDescriptor.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
#include <AK/ByteBuffer.h>
#include <AK/Retainable.h>

#ifdef SERENITY
class TTY;
#endif

class FileDescriptor : public Retainable<FileDescriptor> {
public:
Expand All @@ -31,9 +33,11 @@ class FileDescriptor : public Retainable<FileDescriptor> {

bool isDirectory() const;

#ifdef SERENITY
bool isTTY() const;
const TTY* tty() const;
TTY* tty();
#endif

InodeMetadata metadata() const { return m_vnode->metadata(); }

Expand Down
2 changes: 1 addition & 1 deletion VirtualFileSystem/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ VFS_OBJS = \
FileSystem.o \
Ext2FileSystem.o \
VirtualFileSystem.o \
FileHandle.o \
FileDescriptor.o \
DiskBackedFileSystem.o \
SyntheticFileSystem.o \
InodeIdentifier.o \
Expand Down
4 changes: 2 additions & 2 deletions VirtualFileSystem/SyntheticFileSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
13 changes: 4 additions & 9 deletions VirtualFileSystem/VirtualFileSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down
2 changes: 0 additions & 2 deletions VirtualFileSystem/VirtualFileSystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -31,7 +30,6 @@ class VirtualFileSystem {
AK_MAKE_ETERNAL
public:
static void initializeGlobals();
static SpinLock& lock();

class Mount {
public:
Expand Down
8 changes: 4 additions & 4 deletions VirtualFileSystem/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down

0 comments on commit 981a3ae

Please sign in to comment.