Most of XamContent* methods, besides enumeration.

Progress on #152.
This commit is contained in:
Ben Vanik
2015-02-12 14:16:43 -08:00
parent 53eaeff690
commit dc731f6a31
25 changed files with 849 additions and 14 deletions

View File

@@ -27,6 +27,8 @@ class Device {
const std::string& path() const { return path_; }
virtual bool is_read_only() const { return true; }
virtual std::unique_ptr<Entry> ResolvePath(const char* path) = 0;
virtual X_STATUS QueryVolume(XVolumeInfo* out_info, size_t length);

View File

@@ -17,8 +17,8 @@ namespace kernel {
namespace fs {
HostPathDevice::HostPathDevice(const std::string& path,
const std::wstring& local_path)
: Device(path), local_path_(local_path) {}
const std::wstring& local_path, bool read_only)
: Device(path), local_path_(local_path), read_only_(read_only) {}
HostPathDevice::~HostPathDevice() {}

View File

@@ -21,13 +21,17 @@ namespace fs {
class HostPathDevice : public Device {
public:
HostPathDevice(const std::string& path, const std::wstring& local_path);
HostPathDevice(const std::string& path, const std::wstring& local_path,
bool read_only);
~HostPathDevice() override;
bool is_read_only() const { return read_only_; }
std::unique_ptr<Entry> ResolvePath(const char* path) override;
private:
std::wstring local_path_;
bool read_only_;
};
} // namespace fs

View File

@@ -140,7 +140,7 @@ X_STATUS HostPathEntry::Open(KernelState* kernel_state, Mode mode, bool async,
DWORD desired_access =
mode == Mode::READ ? GENERIC_READ : (GENERIC_READ | GENERIC_WRITE);
DWORD share_mode = FILE_SHARE_READ;
DWORD creation_disposition = OPEN_EXISTING;
DWORD creation_disposition = mode == Mode::READ ? OPEN_EXISTING : OPEN_ALWAYS;
DWORD flags_and_attributes = async ? FILE_FLAG_OVERLAPPED : 0;
HANDLE file =
CreateFile(local_path_.c_str(), desired_access, share_mode, NULL,

View File

@@ -69,6 +69,23 @@ X_STATUS HostPathFile::ReadSync(void* buffer, size_t buffer_length,
}
}
X_STATUS HostPathFile::WriteSync(const void* buffer, size_t buffer_length,
size_t byte_offset,
size_t* out_bytes_written) {
OVERLAPPED overlapped;
overlapped.Pointer = (PVOID)byte_offset;
overlapped.hEvent = NULL;
DWORD bytes_written = 0;
BOOL wrote = WriteFile(file_handle_, buffer, (DWORD)buffer_length,
&bytes_written, &overlapped);
if (wrote) {
*out_bytes_written = bytes_written;
return X_STATUS_SUCCESS;
} else {
return X_STATUS_END_OF_FILE;
}
}
} // namespace fs
} // namespace kernel
} // namespace xe

View File

@@ -41,6 +41,8 @@ class HostPathFile : public XFile {
protected:
X_STATUS ReadSync(void* buffer, size_t buffer_length, size_t byte_offset,
size_t* out_bytes_read) override;
X_STATUS WriteSync(const void* buffer, size_t buffer_length,
size_t byte_offset, size_t* out_bytes_written) override;
private:
HostPathEntry* entry_;

View File

@@ -29,6 +29,10 @@ Entry::Entry(Device* device, const std::string& path)
Entry::~Entry() = default;
bool Entry::is_read_only() const {
return device_->is_read_only();
}
} // namespace fs
} // namespace kernel
} // namespace xe

View File

@@ -61,6 +61,8 @@ class Entry {
const std::string& absolute_path() const { return absolute_path_; }
const std::string& name() const { return name_; }
bool is_read_only() const;
virtual X_STATUS QueryInfo(XFileInfo* out_info) = 0;
virtual X_STATUS QueryDirectory(XDirectoryInfo* out_info, size_t length,
const char* file_name, bool restart) = 0;

View File

@@ -74,7 +74,7 @@ int FileSystem::InitializeFromPath(fs::FileSystemType type,
// Register the local directory in the virtual filesystem.
int result_code = RegisterHostPathDevice(
"\\Device\\Harddisk1\\Partition0", parent_path);
"\\Device\\Harddisk1\\Partition0", parent_path, true);
if (result_code) {
XELOGE("Unable to mount local directory");
return result_code;
@@ -108,8 +108,9 @@ int FileSystem::RegisterDevice(const std::string& path, Device* device) {
}
int FileSystem::RegisterHostPathDevice(const std::string& path,
const std::wstring& local_path) {
Device* device = new HostPathDevice(path, local_path);
const std::wstring& local_path,
bool read_only) {
Device* device = new HostPathDevice(path, local_path, read_only);
return RegisterDevice(path, device);
}

View File

@@ -40,7 +40,8 @@ class FileSystem {
int RegisterDevice(const std::string& path, Device* device);
int RegisterHostPathDevice(const std::string& path,
const std::wstring& local_path);
const std::wstring& local_path,
bool read_only);
int RegisterDiscImageDevice(const std::string& path,
const std::wstring& local_path);
int RegisterSTFSContainerDevice(const std::string& path,