From 23f91b58f377a1d9bbb50030b45e2f4f43075ded Mon Sep 17 00:00:00 2001 From: Ben Vanik Date: Sat, 27 Jun 2015 17:01:25 -0700 Subject: [PATCH] Moving code out of vfs/ that doesn't need to be there. Progress on #294. --- src/xenia/kernel/objects/xfile.h | 59 ---------- src/xenia/kernel/xboxkrnl_io.cc | 110 ++++++++++++++---- src/xenia/vfs/device.cc | 52 --------- src/xenia/vfs/device.h | 10 +- src/xenia/vfs/devices/disc_image_device.h | 8 ++ src/xenia/vfs/devices/host_path_device.h | 5 + src/xenia/vfs/devices/stfs_container_device.h | 8 ++ src/xenia/vfs/entry.h | 3 - 8 files changed, 113 insertions(+), 142 deletions(-) diff --git a/src/xenia/kernel/objects/xfile.h b/src/xenia/kernel/objects/xfile.h index e4cd2b153..967f49a2c 100644 --- a/src/xenia/kernel/objects/xfile.h +++ b/src/xenia/kernel/objects/xfile.h @@ -73,65 +73,6 @@ class X_FILE_DIRECTORY_INFORMATION { }; static_assert_size(X_FILE_DIRECTORY_INFORMATION, 72); -// http://msdn.microsoft.com/en-us/library/windows/hardware/ff540287.aspx -class X_FILE_FS_VOLUME_INFORMATION { - public: - // FILE_FS_VOLUME_INFORMATION - uint64_t creation_time; - uint32_t serial_number; - uint32_t label_length; - uint32_t supports_objects; - char label[1]; - - void Write(uint8_t* base, uint32_t p) { - uint8_t* dst = base + p; - xe::store_and_swap(dst + 0, this->creation_time); - xe::store_and_swap(dst + 8, this->serial_number); - xe::store_and_swap(dst + 12, this->label_length); - xe::store_and_swap(dst + 16, this->supports_objects); - memcpy(dst + 20, this->label, this->label_length); - } -}; -static_assert_size(X_FILE_FS_VOLUME_INFORMATION, 24); - -// https://msdn.microsoft.com/en-us/library/windows/hardware/ff540282.aspx -class X_FILE_FS_SIZE_INFORMATION { - public: - // FILE_FS_SIZE_INFORMATION - uint64_t total_allocation_units; - uint64_t available_allocation_units; - uint32_t sectors_per_allocation_unit; - uint32_t bytes_per_sector; - - void Write(uint8_t* base, uint32_t p) { - uint8_t* dst = base + p; - xe::store_and_swap(dst + 0, this->total_allocation_units); - xe::store_and_swap(dst + 8, this->available_allocation_units); - xe::store_and_swap(dst + 16, this->sectors_per_allocation_unit); - xe::store_and_swap(dst + 20, this->bytes_per_sector); - } -}; -static_assert_size(X_FILE_FS_SIZE_INFORMATION, 24); - -// http://msdn.microsoft.com/en-us/library/windows/hardware/ff540251(v=vs.85).aspx -class X_FILE_FS_ATTRIBUTE_INFORMATION { - public: - // FILE_FS_ATTRIBUTE_INFORMATION - uint32_t attributes; - int32_t maximum_component_name_length; - uint32_t fs_name_length; - char fs_name[1]; - - void Write(uint8_t* base, uint32_t p) { - uint8_t* dst = base + p; - xe::store_and_swap(dst + 0, this->attributes); - xe::store_and_swap(dst + 4, this->maximum_component_name_length); - xe::store_and_swap(dst + 8, this->fs_name_length); - memcpy(dst + 12, this->fs_name, this->fs_name_length); - } -}; -static_assert_size(X_FILE_FS_ATTRIBUTE_INFORMATION, 16); - class XFile : public XObject { public: virtual ~XFile(); diff --git a/src/xenia/kernel/xboxkrnl_io.cc b/src/xenia/kernel/xboxkrnl_io.cc index dc19732b0..5101912b1 100644 --- a/src/xenia/kernel/xboxkrnl_io.cc +++ b/src/xenia/kernel/xboxkrnl_io.cc @@ -93,6 +93,65 @@ class X_OBJECT_ATTRIBUTES { } }; +// http://msdn.microsoft.com/en-us/library/windows/hardware/ff540287.aspx +class X_FILE_FS_VOLUME_INFORMATION { + public: + // FILE_FS_VOLUME_INFORMATION + uint64_t creation_time; + uint32_t serial_number; + uint32_t label_length; + uint32_t supports_objects; + char label[1]; + + void Write(uint8_t* base, uint32_t p) { + uint8_t* dst = base + p; + xe::store_and_swap(dst + 0, this->creation_time); + xe::store_and_swap(dst + 8, this->serial_number); + xe::store_and_swap(dst + 12, this->label_length); + xe::store_and_swap(dst + 16, this->supports_objects); + memcpy(dst + 20, this->label, this->label_length); + } +}; +static_assert_size(X_FILE_FS_VOLUME_INFORMATION, 24); + +// https://msdn.microsoft.com/en-us/library/windows/hardware/ff540282.aspx +class X_FILE_FS_SIZE_INFORMATION { + public: + // FILE_FS_SIZE_INFORMATION + uint64_t total_allocation_units; + uint64_t available_allocation_units; + uint32_t sectors_per_allocation_unit; + uint32_t bytes_per_sector; + + void Write(uint8_t* base, uint32_t p) { + uint8_t* dst = base + p; + xe::store_and_swap(dst + 0, this->total_allocation_units); + xe::store_and_swap(dst + 8, this->available_allocation_units); + xe::store_and_swap(dst + 16, this->sectors_per_allocation_unit); + xe::store_and_swap(dst + 20, this->bytes_per_sector); + } +}; +static_assert_size(X_FILE_FS_SIZE_INFORMATION, 24); + +// http://msdn.microsoft.com/en-us/library/windows/hardware/ff540251(v=vs.85).aspx +class X_FILE_FS_ATTRIBUTE_INFORMATION { + public: + // FILE_FS_ATTRIBUTE_INFORMATION + uint32_t attributes; + int32_t maximum_component_name_length; + uint32_t fs_name_length; + char fs_name[1]; + + void Write(uint8_t* base, uint32_t p) { + uint8_t* dst = base + p; + xe::store_and_swap(dst + 0, this->attributes); + xe::store_and_swap(dst + 4, this->maximum_component_name_length); + xe::store_and_swap(dst + 8, this->fs_name_length); + memcpy(dst + 12, this->fs_name, this->fs_name_length); + } +}; +static_assert_size(X_FILE_FS_ATTRIBUTE_INFORMATION, 16); + struct FileDisposition { static const uint32_t X_FILE_SUPERSEDE = 0x00000000; static const uint32_t X_FILE_OPEN = 0x00000001; @@ -671,34 +730,41 @@ SHIM_CALL NtQueryVolumeInformationFile_shim(PPCContext* ppc_context, if (file) { switch (fs_info_class) { case 1: { // FileFsVolumeInformation - auto volume_info = (X_FILE_FS_VOLUME_INFORMATION*)calloc(length, 1); - result = file->device()->QueryVolumeInfo(volume_info, length); - if (XSUCCEEDED(result)) { - volume_info->Write(SHIM_MEM_BASE, fs_info_ptr); - info = length; - } - free(volume_info); + // TODO(gibbed): actual value + std::string name = "test"; + X_FILE_FS_VOLUME_INFORMATION volume_info = {0}; + volume_info.creation_time = 0; + volume_info.serial_number = 12345678; + volume_info.supports_objects = 0; + volume_info.label_length = uint32_t(name.size()); + std::memcpy(volume_info.label, name.data(), name.size()); + volume_info.Write(SHIM_MEM_BASE, fs_info_ptr); + info = length; break; } case 3: { // FileFsSizeInformation - auto fs_attribute_info = (X_FILE_FS_SIZE_INFORMATION*)calloc(length, 1); - result = file->device()->QuerySizeInfo(fs_attribute_info, length); - if (XSUCCEEDED(result)) { - fs_attribute_info->Write(SHIM_MEM_BASE, fs_info_ptr); - info = length; - } - free(fs_attribute_info); + X_FILE_FS_SIZE_INFORMATION fs_size_info = {0}; + fs_size_info.total_allocation_units = + file->device()->total_allocation_units(); + fs_size_info.available_allocation_units = + file->device()->available_allocation_units(); + fs_size_info.sectors_per_allocation_unit = + file->device()->sectors_per_allocation_unit(); + fs_size_info.bytes_per_sector = file->device()->bytes_per_sector(); + fs_size_info.Write(SHIM_MEM_BASE, fs_info_ptr); + info = length; break; } case 5: { // FileFsAttributeInformation - auto fs_attribute_info = - (X_FILE_FS_ATTRIBUTE_INFORMATION*)calloc(length, 1); - result = file->device()->QueryAttributeInfo(fs_attribute_info, length); - if (XSUCCEEDED(result)) { - fs_attribute_info->Write(SHIM_MEM_BASE, fs_info_ptr); - info = length; - } - free(fs_attribute_info); + // TODO(gibbed): actual value + std::string name = "test"; + X_FILE_FS_ATTRIBUTE_INFORMATION fs_attribute_info = {0}; + fs_attribute_info.attributes = 0; + fs_attribute_info.maximum_component_name_length = 255; + fs_attribute_info.fs_name_length = uint32_t(name.size()); + std::memcpy(fs_attribute_info.fs_name, name.data(), name.size()); + fs_attribute_info.Write(SHIM_MEM_BASE, fs_info_ptr); + info = length; break; } case 2: // FileFsLabelInformation diff --git a/src/xenia/vfs/device.cc b/src/xenia/vfs/device.cc index a1e3a44b7..18f4d1ea8 100644 --- a/src/xenia/vfs/device.cc +++ b/src/xenia/vfs/device.cc @@ -9,8 +9,6 @@ #include "xenia/vfs/device.h" -#include "xenia/kernel/objects/xfile.h" - namespace xe { namespace vfs { @@ -18,55 +16,5 @@ Device::Device(const std::string& mount_path) : mount_path_(mount_path) {} Device::~Device() = default; -// TODO(gibbed): make virtual + move implementation into HostPathDevice/etc. -X_STATUS Device::QueryVolumeInfo(X_FILE_FS_VOLUME_INFORMATION* out_info, - size_t length) { - assert_not_null(out_info); - const char* name = "test"; // TODO(gibbed): actual value - - auto end = (uint8_t*)out_info + length; - size_t name_length = strlen(name); - if (((uint8_t*)&out_info->label[0]) + name_length > end) { - return X_STATUS_BUFFER_OVERFLOW; - } - - out_info->creation_time = 0; - out_info->serial_number = 12345678; - out_info->supports_objects = 0; - out_info->label_length = (uint32_t)name_length; - memcpy(out_info->label, name, name_length); - return X_STATUS_SUCCESS; -} - -// TODO(gibbed): make virtual + move implementation into HostPathDevice/etc. -X_STATUS Device::QuerySizeInfo(X_FILE_FS_SIZE_INFORMATION* out_info, - size_t length) { - assert_not_null(out_info); - out_info->total_allocation_units = 1234; // TODO(gibbed): actual value - out_info->available_allocation_units = 0; // TODO(gibbed): actual value - out_info->sectors_per_allocation_unit = 1; // TODO(gibbed): actual value - out_info->bytes_per_sector = 1024; // TODO(gibbed): actual value - return X_STATUS_SUCCESS; -} - -// TODO(gibbed): make virtual + move implementation into HostPathDevice/etc. -X_STATUS Device::QueryAttributeInfo(X_FILE_FS_ATTRIBUTE_INFORMATION* out_info, - size_t length) { - assert_not_null(out_info); - const char* name = "test"; // TODO(gibbed): actual value - - auto end = (uint8_t*)out_info + length; - size_t name_length = strlen(name); - if (((uint8_t*)&out_info->fs_name[0]) + name_length > end) { - return X_STATUS_BUFFER_OVERFLOW; - } - - out_info->attributes = 0; - out_info->maximum_component_name_length = 255; // TODO(gibbed): actual value - out_info->fs_name_length = (uint32_t)name_length; - memcpy(out_info->fs_name, name, name_length); - return X_STATUS_SUCCESS; -} - } // namespace vfs } // namespace xe diff --git a/src/xenia/vfs/device.h b/src/xenia/vfs/device.h index 3108d79ea..6c9ca8e17 100644 --- a/src/xenia/vfs/device.h +++ b/src/xenia/vfs/device.h @@ -29,12 +29,10 @@ class Device { virtual std::unique_ptr ResolvePath(const char* path) = 0; - virtual X_STATUS QueryVolumeInfo(X_FILE_FS_VOLUME_INFORMATION* out_info, - size_t length); - virtual X_STATUS QuerySizeInfo(X_FILE_FS_SIZE_INFORMATION* out_info, - size_t length); - virtual X_STATUS QueryAttributeInfo(X_FILE_FS_ATTRIBUTE_INFORMATION* out_info, - size_t length); + virtual uint32_t total_allocation_units() const = 0; + virtual uint32_t available_allocation_units() const = 0; + virtual uint32_t sectors_per_allocation_unit() const = 0; + virtual uint32_t bytes_per_sector() const = 0; protected: std::string mount_path_; diff --git a/src/xenia/vfs/devices/disc_image_device.h b/src/xenia/vfs/devices/disc_image_device.h index 0884c1d54..1c1151c96 100644 --- a/src/xenia/vfs/devices/disc_image_device.h +++ b/src/xenia/vfs/devices/disc_image_device.h @@ -31,6 +31,14 @@ class DiscImageDevice : public Device { std::unique_ptr ResolvePath(const char* path) override; + uint32_t total_allocation_units() const override { + return uint32_t(mmap_->size() / sectors_per_allocation_unit() / + bytes_per_sector()); + } + uint32_t available_allocation_units() const override { return 0; } + uint32_t sectors_per_allocation_unit() const override { return 1; } + uint32_t bytes_per_sector() const override { return 2 * 1024; } + private: std::wstring local_path_; std::unique_ptr mmap_; diff --git a/src/xenia/vfs/devices/host_path_device.h b/src/xenia/vfs/devices/host_path_device.h index fc4d3ee49..d5d569d8b 100644 --- a/src/xenia/vfs/devices/host_path_device.h +++ b/src/xenia/vfs/devices/host_path_device.h @@ -27,6 +27,11 @@ class HostPathDevice : public Device { std::unique_ptr ResolvePath(const char* path) override; + uint32_t total_allocation_units() const override { return 128 * 1024; } + uint32_t available_allocation_units() const override { return 128 * 1024; } + uint32_t sectors_per_allocation_unit() const override { return 1; } + uint32_t bytes_per_sector() const override { return 2 * 1024; } + private: std::wstring local_path_; bool read_only_; diff --git a/src/xenia/vfs/devices/stfs_container_device.h b/src/xenia/vfs/devices/stfs_container_device.h index b52fcbdf9..13d1a9402 100644 --- a/src/xenia/vfs/devices/stfs_container_device.h +++ b/src/xenia/vfs/devices/stfs_container_device.h @@ -31,6 +31,14 @@ class STFSContainerDevice : public Device { std::unique_ptr ResolvePath(const char* path) override; + uint32_t total_allocation_units() const override { + return uint32_t(mmap_->size() / sectors_per_allocation_unit() / + bytes_per_sector()); + } + uint32_t available_allocation_units() const override { return 0; } + uint32_t sectors_per_allocation_unit() const override { return 1; } + uint32_t bytes_per_sector() const override { return 4 * 1024; } + private: std::wstring local_path_; std::unique_ptr mmap_; diff --git a/src/xenia/vfs/entry.h b/src/xenia/vfs/entry.h index 073d2a14e..32b44e3df 100644 --- a/src/xenia/vfs/entry.h +++ b/src/xenia/vfs/entry.h @@ -21,9 +21,6 @@ class KernelState; class XFile; struct X_FILE_NETWORK_OPEN_INFORMATION; class X_FILE_DIRECTORY_INFORMATION; -class X_FILE_FS_ATTRIBUTE_INFORMATION; -class X_FILE_FS_SIZE_INFORMATION; -class X_FILE_FS_VOLUME_INFORMATION; } // namespace kernel } // namespace xe