diff --git a/include/xenia/kernel/fs/device.h b/include/xenia/kernel/fs/device.h new file mode 100644 index 000000000..9925a16e5 --- /dev/null +++ b/include/xenia/kernel/fs/device.h @@ -0,0 +1,41 @@ +/** + ****************************************************************************** + * Xenia : Xbox 360 Emulator Research Project * + ****************************************************************************** + * Copyright 2013 Ben Vanik. All rights reserved. * + * Released under the BSD license - see LICENSE in the root for more details. * + ****************************************************************************** + */ + +#ifndef XENIA_KERNEL_FS_DEVICE_H_ +#define XENIA_KERNEL_FS_DEVICE_H_ + +#include +#include + +#include + + +namespace xe { +namespace kernel { +namespace fs { + + +class Device { +public: + Device(xe_pal_ref pal); + virtual ~Device(); + + virtual Entry* ResolvePath(const char* path) = 0; + +protected: + xe_pal_ref pal_; +}; + + +} // namespace fs +} // namespace kernel +} // namespace xe + + +#endif // XENIA_KERNEL_FS_DEVICE_H_ diff --git a/include/xenia/kernel/fs/entry.h b/include/xenia/kernel/fs/entry.h new file mode 100644 index 000000000..3c4359e9b --- /dev/null +++ b/include/xenia/kernel/fs/entry.h @@ -0,0 +1,71 @@ +/** + ****************************************************************************** + * Xenia : Xbox 360 Emulator Research Project * + ****************************************************************************** + * Copyright 2013 Ben Vanik. All rights reserved. * + * Released under the BSD license - see LICENSE in the root for more details. * + ****************************************************************************** + */ + +#ifndef XENIA_KERNEL_FS_ENTRY_H_ +#define XENIA_KERNEL_FS_ENTRY_H_ + +#include +#include + + +namespace xe { +namespace kernel { +namespace fs { + + +class Device; + + +class Entry { +public: + enum Type { + kTypeFile, + kTypeDirectory, + }; + + Entry(Type type, Device* device, const char* path); + virtual ~Entry(); + + Type type(); + Device* device(); + const char* path(); + const char* name(); + +private: + Type type_; + Device* device_; + char* path_; + char* name_; +}; + + +class FileEntry : public Entry { +public: + FileEntry(Device* device, const char* path); + virtual ~FileEntry(); + + //virtual void Query(); +}; + + +class DirectoryEntry : public Entry { +public: + DirectoryEntry(Device* device, const char* path); + virtual ~DirectoryEntry(); + + //virtual void Query(); +}; + + +} // namespace fs +} // namespace kernel +} // namespace xe + + +#endif // XENIA_KERNEL_FS_ENTRY_H_ diff --git a/include/xenia/kernel/fs/filesystem.h b/include/xenia/kernel/fs/filesystem.h new file mode 100644 index 000000000..fc85b059d --- /dev/null +++ b/include/xenia/kernel/fs/filesystem.h @@ -0,0 +1,52 @@ +/** + ****************************************************************************** + * Xenia : Xbox 360 Emulator Research Project * + ****************************************************************************** + * Copyright 2013 Ben Vanik. All rights reserved. * + * Released under the BSD license - see LICENSE in the root for more details. * + ****************************************************************************** + */ + +#ifndef XENIA_KERNEL_FS_FILESYSTEM_H_ +#define XENIA_KERNEL_FS_FILESYSTEM_H_ + +#include +#include + +#include + + +namespace xe { +namespace kernel { +namespace fs { + + +class Device; + + +class FileSystem { +public: + FileSystem(xe_pal_ref pal); + ~FileSystem(); + + int RegisterDevice(const char* path, Device* device); + int RegisterLocalDirectoryDevice(const char* path, + const xechar_t* local_path); + int RegisterDiscImageDevice(const char* path, const xechar_t* local_path); + + int CreateSymbolicLink(const char* path, const char* target); + int DeleteSymbolicLink(const char* path); + + Entry* ResolvePath(const char* path); + +private: + xe_pal_ref pal_; +}; + + +} // namespace fs +} // namespace kernel +} // namespace xe + + +#endif // XENIA_KERNEL_FS_FILESYSTEM_H_ diff --git a/include/xenia/kernel/runtime.h b/include/xenia/kernel/runtime.h index 36f52aad0..30bca2910 100644 --- a/include/xenia/kernel/runtime.h +++ b/include/xenia/kernel/runtime.h @@ -16,6 +16,7 @@ #include #include +#include namespace xe { @@ -45,20 +46,24 @@ public: const xechar_t* command_line); ~Runtime(); + const xechar_t* command_line(); + xe_pal_ref pal(); xe_memory_ref memory(); shared_ptr processor(); shared_ptr export_resolver(); - const xechar_t* command_line(); + shared_ptr filesystem(); int LaunchModule(const xechar_t* path); private: + xechar_t command_line_[2048]; + xe_pal_ref pal_; xe_memory_ref memory_; shared_ptr processor_; - xechar_t command_line_[2048]; shared_ptr export_resolver_; + shared_ptr filesystem_; auto_ptr xboxkrnl_; auto_ptr xam_; diff --git a/src/kernel/fs/device.cc b/src/kernel/fs/device.cc new file mode 100644 index 000000000..85d45a23b --- /dev/null +++ b/src/kernel/fs/device.cc @@ -0,0 +1,24 @@ +/** + ****************************************************************************** + * Xenia : Xbox 360 Emulator Research Project * + ****************************************************************************** + * Copyright 2013 Ben Vanik. All rights reserved. * + * Released under the BSD license - see LICENSE in the root for more details. * + ****************************************************************************** + */ + +#include + + +using namespace xe; +using namespace xe::kernel; +using namespace xe::kernel::fs; + + +Device::Device(xe_pal_ref pal) { + pal_ = xe_pal_retain(pal); +} + +Device::~Device() { + xe_pal_release(pal_); +} diff --git a/src/kernel/fs/devices/disc_image_device.cc b/src/kernel/fs/devices/disc_image_device.cc new file mode 100644 index 000000000..68dfaf27f --- /dev/null +++ b/src/kernel/fs/devices/disc_image_device.cc @@ -0,0 +1,29 @@ +/** + ****************************************************************************** + * Xenia : Xbox 360 Emulator Research Project * + ****************************************************************************** + * Copyright 2013 Ben Vanik. All rights reserved. * + * Released under the BSD license - see LICENSE in the root for more details. * + ****************************************************************************** + */ + +#include "kernel/fs/devices/disc_image_device.h" + + +using namespace xe; +using namespace xe::kernel; +using namespace xe::kernel::fs; + + +DiscImageDevice::DiscImageDevice(xe_pal_ref pal, const xechar_t* local_path) : + Device(pal) { + local_path_ = xestrdup(local_path); +} + +DiscImageDevice::~DiscImageDevice() { + xe_free(local_path_); +} + +Entry* DiscImageDevice::ResolvePath(const char* path) { + return NULL; +} diff --git a/src/kernel/fs/devices/disc_image_device.h b/src/kernel/fs/devices/disc_image_device.h new file mode 100644 index 000000000..ffcc0a24f --- /dev/null +++ b/src/kernel/fs/devices/disc_image_device.h @@ -0,0 +1,41 @@ +/** + ****************************************************************************** + * Xenia : Xbox 360 Emulator Research Project * + ****************************************************************************** + * Copyright 2013 Ben Vanik. All rights reserved. * + * Released under the BSD license - see LICENSE in the root for more details. * + ****************************************************************************** + */ + +#ifndef XENIA_KERNEL_FS_DEVICES_DISC_IMAGE_DEVICE_H_ +#define XENIA_KERNEL_FS_DEVICES_DISC_IMAGE_DEVICE_H_ + +#include +#include + +#include + + +namespace xe { +namespace kernel { +namespace fs { + + +class DiscImageDevice : public Device { +public: + DiscImageDevice(xe_pal_ref pal, const xechar_t* local_path); + virtual ~DiscImageDevice(); + + virtual Entry* ResolvePath(const char* path); + +private: + xechar_t* local_path_; +}; + + +} // namespace fs +} // namespace kernel +} // namespace xe + + +#endif // XENIA_KERNEL_FS_DEVICES_DISC_IMAGE_DEVICE_H_ diff --git a/src/kernel/fs/devices/local_directory_device.cc b/src/kernel/fs/devices/local_directory_device.cc new file mode 100644 index 000000000..ed0819c3f --- /dev/null +++ b/src/kernel/fs/devices/local_directory_device.cc @@ -0,0 +1,30 @@ +/** + ****************************************************************************** + * Xenia : Xbox 360 Emulator Research Project * + ****************************************************************************** + * Copyright 2013 Ben Vanik. All rights reserved. * + * Released under the BSD license - see LICENSE in the root for more details. * + ****************************************************************************** + */ + +#include "kernel/fs/devices/local_directory_device.h" + + +using namespace xe; +using namespace xe::kernel; +using namespace xe::kernel::fs; + + +LocalDirectoryDevice::LocalDirectoryDevice(xe_pal_ref pal, + const xechar_t* local_path) : + Device(pal) { + local_path_ = xestrdup(local_path); +} + +LocalDirectoryDevice::~LocalDirectoryDevice() { + xe_free(local_path_); +} + +Entry* LocalDirectoryDevice::ResolvePath(const char* path) { + return NULL; +} diff --git a/src/kernel/fs/devices/local_directory_device.h b/src/kernel/fs/devices/local_directory_device.h new file mode 100644 index 000000000..4126183af --- /dev/null +++ b/src/kernel/fs/devices/local_directory_device.h @@ -0,0 +1,41 @@ +/** + ****************************************************************************** + * Xenia : Xbox 360 Emulator Research Project * + ****************************************************************************** + * Copyright 2013 Ben Vanik. All rights reserved. * + * Released under the BSD license - see LICENSE in the root for more details. * + ****************************************************************************** + */ + +#ifndef XENIA_KERNEL_FS_DEVICES_LOCAL_DIRECTORY_DEVICE_H_ +#define XENIA_KERNEL_FS_DEVICES_LOCAL_DIRECTORY_DEVICE_H_ + +#include +#include + +#include + + +namespace xe { +namespace kernel { +namespace fs { + + +class LocalDirectoryDevice : public Device { +public: + LocalDirectoryDevice(xe_pal_ref pal, const xechar_t* local_path); + virtual ~LocalDirectoryDevice(); + + virtual Entry* ResolvePath(const char* path); + +private: + xechar_t* local_path_; +}; + + +} // namespace fs +} // namespace kernel +} // namespace xe + + +#endif // XENIA_KERNEL_FS_DEVICES_LOCAL_DIRECTORY_DEVICE_H_ diff --git a/src/kernel/fs/devices/sources.gypi b/src/kernel/fs/devices/sources.gypi new file mode 100644 index 000000000..57229c60d --- /dev/null +++ b/src/kernel/fs/devices/sources.gypi @@ -0,0 +1,7 @@ +# Copyright 2013 Ben Vanik. All Rights Reserved. +{ + 'sources': [ + 'disc_image_device.cc', + 'local_directory_device.cc', + ], +} diff --git a/src/kernel/fs/entry.cc b/src/kernel/fs/entry.cc new file mode 100644 index 000000000..12ae28a2b --- /dev/null +++ b/src/kernel/fs/entry.cc @@ -0,0 +1,61 @@ +/** + ****************************************************************************** + * Xenia : Xbox 360 Emulator Research Project * + ****************************************************************************** + * Copyright 2013 Ben Vanik. All rights reserved. * + * Released under the BSD license - see LICENSE in the root for more details. * + ****************************************************************************** + */ + +#include + + +using namespace xe; +using namespace xe::kernel; +using namespace xe::kernel::fs; + + +Entry::Entry(Type type, Device* device, const char* path) : + type_(type), + device_(device) { + path_ = xestrdupa(path); + // TODO(benvanik): last index of \, unless \ at end, then before that + name_ = NULL; +} + +Entry::~Entry() { + xe_free(path_); + xe_free(name_); +} + +Entry::Type Entry::type() { + return type_; +} + +Device* Entry::device() { + return device_; +} + +const char* Entry::path() { + return path_; +} + +const char* Entry::name() { + return name_; +} + + +FileEntry::FileEntry(Device* device, const char* path) : + Entry(kTypeFile, device, path) { +} + +FileEntry::~FileEntry() { +} + + +DirectoryEntry::DirectoryEntry(Device* device, const char* path) : + Entry(kTypeDirectory, device, path) { +} + +DirectoryEntry::~DirectoryEntry() { +} diff --git a/src/kernel/fs/filesystem.cc b/src/kernel/fs/filesystem.cc new file mode 100644 index 000000000..80c949667 --- /dev/null +++ b/src/kernel/fs/filesystem.cc @@ -0,0 +1,55 @@ +/** + ****************************************************************************** + * Xenia : Xbox 360 Emulator Research Project * + ****************************************************************************** + * Copyright 2013 Ben Vanik. All rights reserved. * + * Released under the BSD license - see LICENSE in the root for more details. * + ****************************************************************************** + */ + +#include + +#include "kernel/fs/devices/disc_image_device.h" +#include "kernel/fs/devices/local_directory_device.h" + + +using namespace xe; +using namespace xe::kernel; +using namespace xe::kernel::fs; + + +FileSystem::FileSystem(xe_pal_ref pal) { + pal_ = xe_pal_retain(pal); +} + +FileSystem::~FileSystem() { + xe_pal_release(pal_); +} + +int FileSystem::RegisterDevice(const char* path, Device* device) { + return 1; +} + +int FileSystem::RegisterLocalDirectoryDevice( + const char* path, const xechar_t* local_path) { + Device* device = new LocalDirectoryDevice(pal_, local_path); + return RegisterDevice(path, device); +} + +int FileSystem::RegisterDiscImageDevice( + const char* path, const xechar_t* local_path) { + Device* device = new DiscImageDevice(pal_, local_path); + return RegisterDevice(path, device); +} + +int FileSystem::CreateSymbolicLink(const char* path, const char* target) { + return 1; +} + +int FileSystem::DeleteSymbolicLink(const char* path) { + return 1; +} + +Entry* FileSystem::ResolvePath(const char* path) { + return NULL; +} diff --git a/src/kernel/fs/sources.gypi b/src/kernel/fs/sources.gypi new file mode 100644 index 000000000..62acd6181 --- /dev/null +++ b/src/kernel/fs/sources.gypi @@ -0,0 +1,12 @@ +# Copyright 2013 Ben Vanik. All Rights Reserved. +{ + 'sources': [ + 'device.cc', + 'entry.cc', + 'filesystem.cc', + ], + + 'includes': [ + 'devices/sources.gypi', + ], +} diff --git a/src/kernel/runtime.cc b/src/kernel/runtime.cc index 35165093d..cac8a9c2b 100644 --- a/src/kernel/runtime.cc +++ b/src/kernel/runtime.cc @@ -15,6 +15,7 @@ using namespace xe; using namespace xe::cpu; using namespace xe::kernel; +using namespace xe::kernel::fs; Runtime::Runtime(xe_pal_ref pal, shared_ptr processor, @@ -25,6 +26,8 @@ Runtime::Runtime(xe_pal_ref pal, shared_ptr processor, XEIGNORE(xestrcpy(command_line_, XECOUNT(command_line_), command_line)); export_resolver_ = shared_ptr(new ExportResolver()); + filesystem_ = shared_ptr(new FileSystem(pal_)); + xboxkrnl_ = auto_ptr( new xboxkrnl::XboxkrnlModule(this)); xam_ = auto_ptr( @@ -36,6 +39,10 @@ Runtime::~Runtime() { xe_pal_release(pal_); } +const xechar_t* Runtime::command_line() { + return command_line_; +} + xe_pal_ref Runtime::pal() { return xe_pal_retain(pal_); } @@ -52,8 +59,8 @@ shared_ptr Runtime::export_resolver() { return export_resolver_; } -const xechar_t* Runtime::command_line() { - return command_line_; +shared_ptr Runtime::filesystem() { + return filesystem_; } int Runtime::LaunchModule(const xechar_t* path) { diff --git a/src/kernel/sources.gypi b/src/kernel/sources.gypi index 9b88b39d5..589dc307e 100644 --- a/src/kernel/sources.gypi +++ b/src/kernel/sources.gypi @@ -7,6 +7,7 @@ ], 'includes': [ + 'fs/sources.gypi', 'modules/sources.gypi', ], }