Moving mmap to poly, cleaning up devices.
This commit is contained in:
@@ -9,33 +9,22 @@
|
||||
|
||||
#include <xenia/kernel/fs/devices/host_path_entry.h>
|
||||
|
||||
#include <poly/mapped_memory.h>
|
||||
#include <xenia/kernel/fs/devices/host_path_file.h>
|
||||
|
||||
|
||||
using namespace xe;
|
||||
using namespace xe::kernel;
|
||||
using namespace xe::kernel::fs;
|
||||
|
||||
|
||||
namespace {
|
||||
|
||||
namespace xe {
|
||||
namespace kernel {
|
||||
namespace fs {
|
||||
|
||||
class HostPathMemoryMapping : public MemoryMapping {
|
||||
public:
|
||||
HostPathMemoryMapping(uint8_t* address, size_t length, xe_mmap_ref mmap) :
|
||||
MemoryMapping(address, length) {
|
||||
mmap_ = xe_mmap_retain(mmap);
|
||||
}
|
||||
virtual ~HostPathMemoryMapping() {
|
||||
xe_mmap_release(mmap_);
|
||||
}
|
||||
private:
|
||||
xe_mmap_ref mmap_;
|
||||
public:
|
||||
HostPathMemoryMapping(std::unique_ptr<poly::MappedMemory> mmap)
|
||||
: MemoryMapping(mmap->data(), mmap->size()), mmap_(std::move(mmap)) {}
|
||||
|
||||
private:
|
||||
std::unique_ptr<poly::MappedMemory> mmap_;
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
|
||||
HostPathEntry::HostPathEntry(Type type, Device* device, const char* path,
|
||||
const std::wstring& local_path)
|
||||
: Entry(type, device, path),
|
||||
@@ -54,24 +43,23 @@ X_STATUS HostPathEntry::QueryInfo(XFileInfo* out_info) {
|
||||
assert_not_null(out_info);
|
||||
|
||||
WIN32_FILE_ATTRIBUTE_DATA data;
|
||||
if (!GetFileAttributesEx(
|
||||
local_path_.c_str(), GetFileExInfoStandard, &data)) {
|
||||
if (!GetFileAttributesEx(local_path_.c_str(), GetFileExInfoStandard, &data)) {
|
||||
return X_STATUS_ACCESS_DENIED;
|
||||
}
|
||||
|
||||
out_info->creation_time = COMBINE_TIME(data.ftCreationTime);
|
||||
out_info->last_access_time = COMBINE_TIME(data.ftLastAccessTime);
|
||||
out_info->last_write_time = COMBINE_TIME(data.ftLastWriteTime);
|
||||
out_info->change_time = COMBINE_TIME(data.ftLastWriteTime);
|
||||
out_info->allocation_size = 4096;
|
||||
out_info->file_length =
|
||||
out_info->creation_time = COMBINE_TIME(data.ftCreationTime);
|
||||
out_info->last_access_time = COMBINE_TIME(data.ftLastAccessTime);
|
||||
out_info->last_write_time = COMBINE_TIME(data.ftLastWriteTime);
|
||||
out_info->change_time = COMBINE_TIME(data.ftLastWriteTime);
|
||||
out_info->allocation_size = 4096;
|
||||
out_info->file_length =
|
||||
((uint64_t)data.nFileSizeHigh << 32) | data.nFileSizeLow;
|
||||
out_info->attributes = (X_FILE_ATTRIBUTES)data.dwFileAttributes;
|
||||
out_info->attributes = (X_FILE_ATTRIBUTES)data.dwFileAttributes;
|
||||
return X_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
X_STATUS HostPathEntry::QueryDirectory(
|
||||
XDirectoryInfo* out_info, size_t length, const char* file_name, bool restart) {
|
||||
X_STATUS HostPathEntry::QueryDirectory(XDirectoryInfo* out_info, size_t length,
|
||||
const char* file_name, bool restart) {
|
||||
assert_not_null(out_info);
|
||||
|
||||
WIN32_FIND_DATA ffd;
|
||||
@@ -97,8 +85,7 @@ X_STATUS HostPathEntry::QueryDirectory(
|
||||
}
|
||||
return X_STATUS_UNSUCCESSFUL;
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
if (FindNextFile(handle, &ffd) == FALSE) {
|
||||
FindClose(handle);
|
||||
find_file_ = INVALID_HANDLE_VALUE;
|
||||
@@ -115,62 +102,62 @@ X_STATUS HostPathEntry::QueryDirectory(
|
||||
}
|
||||
|
||||
out_info->next_entry_offset = 0;
|
||||
out_info->file_index = 0xCDCDCDCD;
|
||||
out_info->creation_time = COMBINE_TIME(ffd.ftCreationTime);
|
||||
out_info->last_access_time = COMBINE_TIME(ffd.ftLastAccessTime);
|
||||
out_info->last_write_time = COMBINE_TIME(ffd.ftLastWriteTime);
|
||||
out_info->change_time = COMBINE_TIME(ffd.ftLastWriteTime);
|
||||
out_info->end_of_file =
|
||||
out_info->file_index = 0xCDCDCDCD;
|
||||
out_info->creation_time = COMBINE_TIME(ffd.ftCreationTime);
|
||||
out_info->last_access_time = COMBINE_TIME(ffd.ftLastAccessTime);
|
||||
out_info->last_write_time = COMBINE_TIME(ffd.ftLastWriteTime);
|
||||
out_info->change_time = COMBINE_TIME(ffd.ftLastWriteTime);
|
||||
out_info->end_of_file =
|
||||
((uint64_t)ffd.nFileSizeHigh << 32) | ffd.nFileSizeLow;
|
||||
out_info->allocation_size = 4096;
|
||||
out_info->attributes = (X_FILE_ATTRIBUTES)ffd.dwFileAttributes;
|
||||
out_info->allocation_size = 4096;
|
||||
out_info->attributes = (X_FILE_ATTRIBUTES)ffd.dwFileAttributes;
|
||||
|
||||
out_info->file_name_length = (uint32_t)entry_name_length;
|
||||
out_info->file_name_length = (uint32_t)entry_name_length;
|
||||
for (size_t i = 0; i < entry_name_length; ++i) {
|
||||
out_info->file_name[i] =
|
||||
ffd.cFileName[i] < 256 ? (char)ffd.cFileName[i] : '?';
|
||||
out_info->file_name[i] =
|
||||
ffd.cFileName[i] < 256 ? (char)ffd.cFileName[i] : '?';
|
||||
}
|
||||
|
||||
return X_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
MemoryMapping* HostPathEntry::CreateMemoryMapping(xe_file_mode file_mode,
|
||||
MemoryMapping* HostPathEntry::CreateMemoryMapping(Mode map_mode,
|
||||
const size_t offset,
|
||||
const size_t length) {
|
||||
xe_mmap_ref mmap =
|
||||
xe_mmap_open(file_mode, local_path_.c_str(), offset, length);
|
||||
auto mmap = poly::MappedMemory::Open(
|
||||
local_path_,
|
||||
map_mode == Mode::READ ? poly::MappedMemory::Mode::READ
|
||||
: poly::MappedMemory::Mode::READ_WRITE,
|
||||
offset, length);
|
||||
if (!mmap) {
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
HostPathMemoryMapping* lfmm = new HostPathMemoryMapping(
|
||||
(uint8_t*)xe_mmap_get_addr(mmap), xe_mmap_get_length(mmap),
|
||||
mmap);
|
||||
xe_mmap_release(mmap);
|
||||
HostPathMemoryMapping* lfmm = new HostPathMemoryMapping(std::move(mmap));
|
||||
|
||||
return lfmm;
|
||||
}
|
||||
|
||||
X_STATUS HostPathEntry::Open(
|
||||
KernelState* kernel_state,
|
||||
uint32_t desired_access, bool async,
|
||||
XFile** out_file) {
|
||||
X_STATUS HostPathEntry::Open(KernelState* kernel_state, Mode mode,
|
||||
bool async, XFile** out_file) {
|
||||
DWORD desired_access =
|
||||
mode == Mode::READ ? GENERIC_READ : (GENERIC_READ | GENERIC_WRITE);
|
||||
DWORD share_mode = FILE_SHARE_READ;
|
||||
DWORD creation_disposition = OPEN_EXISTING;
|
||||
DWORD flags_and_attributes = async ? FILE_FLAG_OVERLAPPED : 0;
|
||||
HANDLE file = CreateFile(
|
||||
local_path_.c_str(),
|
||||
desired_access,
|
||||
share_mode,
|
||||
NULL,
|
||||
creation_disposition,
|
||||
flags_and_attributes | FILE_FLAG_BACKUP_SEMANTICS,
|
||||
NULL);
|
||||
HANDLE file =
|
||||
CreateFile(local_path_.c_str(), desired_access, share_mode, NULL,
|
||||
creation_disposition,
|
||||
flags_and_attributes | FILE_FLAG_BACKUP_SEMANTICS, NULL);
|
||||
if (file == INVALID_HANDLE_VALUE) {
|
||||
// TODO(benvanik): pick correct response.
|
||||
return X_STATUS_ACCESS_DENIED;
|
||||
}
|
||||
|
||||
*out_file = new HostPathFile(kernel_state, desired_access, this, file);
|
||||
*out_file = new HostPathFile(kernel_state, mode, this, file);
|
||||
return X_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
} // namespace fs
|
||||
} // namespace kernel
|
||||
} // namespace xe
|
||||
|
||||
Reference in New Issue
Block a user