[Kernel] Added Support For: XFileRenameInformation

This commit is contained in:
Gliniak
2024-01-29 22:03:58 +01:00
parent 8b14b4bbc4
commit 74b52711a3
11 changed files with 134 additions and 64 deletions

View File

@@ -40,6 +40,10 @@ class HostPathDevice : public Device {
uint32_t sectors_per_allocation_unit() const override { return 1; }
uint32_t bytes_per_sector() const override { return 0x200; }
protected:
friend class HostPathEntry;
std::filesystem::path host_path() const { return host_path_; }
private:
void PopulateEntry(HostPathEntry* parent_entry);

View File

@@ -15,6 +15,7 @@
#include "xenia/base/math.h"
#include "xenia/base/string.h"
#include "xenia/vfs/device.h"
#include "xenia/vfs/devices/host_path_device.h"
#include "xenia/vfs/devices/host_path_file.h"
namespace xe {
@@ -110,6 +111,15 @@ bool HostPathEntry::DeleteEntryInternal(Entry* entry) {
}
}
void HostPathEntry::RenameEntryInternal(const std::filesystem::path file_path) {
const std::string new_host_path_ = xe::utf8::join_paths(
xe::path_to_utf8(((HostPathDevice*)device_)->host_path()),
xe::path_to_utf8(file_path));
std::filesystem::rename(host_path_, new_host_path_);
host_path_ = new_host_path_;
}
void HostPathEntry::update() {
xe::filesystem::FileInfo file_info;
if (!xe::filesystem::GetInfo(host_path_, &file_info)) {

View File

@@ -46,6 +46,7 @@ class HostPathEntry : public Entry {
std::unique_ptr<Entry> CreateEntryInternal(const std::string_view name,
uint32_t attributes) override;
bool DeleteEntryInternal(Entry* entry) override;
void RenameEntryInternal(const std::filesystem::path file_path) override;
std::filesystem::path host_path_;
};

View File

@@ -133,5 +133,22 @@ void Entry::Touch() {
// TODO(benvanik): update timestamps.
}
void Entry::Rename(const std::filesystem::path file_path) {
std::vector<std::string_view> splitted_path =
xe::utf8::split_path(xe::path_to_utf8(file_path));
splitted_path.erase(splitted_path.begin());
const std::string guest_path_without_root =
xe::utf8::join_guest_paths(splitted_path);
RenameEntryInternal(guest_path_without_root);
absolute_path_ = xe::utf8::join_guest_paths(device_->mount_path(),
guest_path_without_root);
path_ = guest_path_without_root;
name_ = xe::path_to_utf8(file_path.filename());
}
} // namespace vfs
} // namespace xe

View File

@@ -111,6 +111,7 @@ class Entry {
bool Delete();
void Touch();
void Rename(const std::filesystem::path file_path);
// If successful, out_file points to a new file. When finished, call
// file->Destroy()
virtual X_STATUS Open(uint32_t desired_access, File** out_file) = 0;
@@ -131,6 +132,7 @@ class Entry {
return nullptr;
}
virtual bool DeleteEntryInternal(Entry* entry) { return false; }
virtual void RenameEntryInternal(const std::filesystem::path file_path) {}
xe::global_critical_region global_critical_region_;
Device* device_;

View File

@@ -45,6 +45,9 @@ class File {
}
virtual X_STATUS SetLength(size_t length) { return X_STATUS_NOT_IMPLEMENTED; }
virtual X_STATUS Rename(const std::filesystem::path file_path) {
return X_STATUS_NOT_IMPLEMENTED;
}
// xe::filesystem::FileAccess
uint32_t file_access() const { return file_access_; }