mirror of
https://github.com/Atmosphere-NX/Atmosphere
synced 2024-12-22 12:21:18 +00:00
haze: refactor constant use for cleaner separation
This commit is contained in:
parent
ba91f070e8
commit
6b72dbd22d
4 changed files with 226 additions and 189 deletions
|
@ -42,6 +42,4 @@ namespace haze {
|
|||
|
||||
using Result = ::ams::Result;
|
||||
|
||||
static constexpr u32 UsbBulkPacketBufferSize = 1_MB;
|
||||
|
||||
}
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
#include <haze/async_usb_server.hpp>
|
||||
#include <haze/ptp_object_heap.hpp>
|
||||
#include <haze/ptp_object_database.hpp>
|
||||
#include <haze/ptp_responder_types.hpp>
|
||||
|
||||
namespace haze {
|
||||
|
||||
|
@ -30,12 +31,13 @@ namespace haze {
|
|||
FileSystemProxy m_fs;
|
||||
PtpUsbBulkContainer m_request_header;
|
||||
PtpObjectHeap *m_object_heap;
|
||||
PtpBuffers* m_buffers;
|
||||
u32 m_send_object_id;
|
||||
bool m_session_open;
|
||||
|
||||
PtpObjectDatabase m_object_database;
|
||||
public:
|
||||
constexpr explicit PtpResponder() : m_usb_server(), m_fs(), m_request_header(), m_object_heap(), m_send_object_id(), m_session_open(), m_object_database() { /* ... */ }
|
||||
constexpr explicit PtpResponder() : m_usb_server(), m_fs(), m_request_header(), m_object_heap(), m_buffers(), m_send_object_id(), m_session_open(), m_object_database() { /* ... */ }
|
||||
|
||||
Result Initialize(EventReactor *reactor, PtpObjectHeap *object_heap);
|
||||
void Finalize();
|
||||
|
@ -48,10 +50,14 @@ namespace haze {
|
|||
Result HandleCommandRequest(PtpDataParser &dp);
|
||||
void ForceCloseSession();
|
||||
|
||||
template <typename Data>
|
||||
Result WriteResponse(PtpResponseCode code, Data &&data);
|
||||
Result WriteResponse(PtpResponseCode code, const void* data, size_t size);
|
||||
Result WriteResponse(PtpResponseCode code);
|
||||
|
||||
template <typename Data> requires (util::is_pod<Data>::value)
|
||||
Result WriteResponse(PtpResponseCode code, const Data &data) {
|
||||
R_RETURN(this->WriteResponse(code, std::addressof(data), sizeof(data)));
|
||||
}
|
||||
|
||||
/* PTP operations. */
|
||||
Result GetDeviceInfo(PtpDataParser &dp);
|
||||
Result OpenSession(PtpDataParser &dp);
|
||||
|
|
177
troposphere/haze/include/haze/ptp_responder_types.hpp
Normal file
177
troposphere/haze/include/haze/ptp_responder_types.hpp
Normal file
|
@ -0,0 +1,177 @@
|
|||
/*
|
||||
* Copyright (c) Atmosphère-NX
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include <haze.hpp>
|
||||
|
||||
namespace haze {
|
||||
|
||||
constexpr UsbCommsInterfaceInfo MtpInterfaceInfo = {
|
||||
.bInterfaceClass = 0x06,
|
||||
.bInterfaceSubClass = 0x01,
|
||||
.bInterfaceProtocol = 0x01,
|
||||
};
|
||||
|
||||
/* This is a VID:PID recognized by libmtp. */
|
||||
constexpr u16 SwitchMtpIdVendor = 0x057e;
|
||||
constexpr u16 SwitchMtpIdProduct = 0x201d;
|
||||
|
||||
/* Constants used for MTP GetDeviceInfo response. */
|
||||
constexpr u16 MtpStandardVersion = 100;
|
||||
constexpr u32 MtpVendorExtensionId = 6;
|
||||
constexpr auto MtpVendorExtensionDesc = "microsoft.com: 1.0;";
|
||||
constexpr u16 MtpFunctionalModeDefault = 0;
|
||||
constexpr auto MtpDeviceManufacturer = "Nintendo";
|
||||
constexpr auto MtpDeviceModel = "Nintendo Switch";
|
||||
|
||||
enum StorageId : u32 {
|
||||
StorageId_SdmcFs = 0xffffffffu - 1,
|
||||
};
|
||||
|
||||
constexpr PtpOperationCode SupportedOperationCodes[] = {
|
||||
PtpOperationCode_GetDeviceInfo,
|
||||
PtpOperationCode_OpenSession,
|
||||
PtpOperationCode_CloseSession,
|
||||
PtpOperationCode_GetStorageIds,
|
||||
PtpOperationCode_GetStorageInfo,
|
||||
PtpOperationCode_GetObjectHandles,
|
||||
PtpOperationCode_GetObjectInfo,
|
||||
PtpOperationCode_GetObject,
|
||||
PtpOperationCode_SendObjectInfo,
|
||||
PtpOperationCode_SendObject,
|
||||
PtpOperationCode_DeleteObject,
|
||||
PtpOperationCode_MtpGetObjectPropsSupported,
|
||||
PtpOperationCode_MtpGetObjectPropDesc,
|
||||
PtpOperationCode_MtpGetObjectPropValue,
|
||||
PtpOperationCode_MtpSetObjectPropValue,
|
||||
};
|
||||
|
||||
constexpr const PtpEventCode SupportedEventCodes[] = { /* ... */ };
|
||||
constexpr const PtpDevicePropertyCode SupportedDeviceProperties[] = { /* ... */ };
|
||||
constexpr const PtpObjectFormatCode SupportedCaptureFormats[] = { /* ... */ };
|
||||
|
||||
constexpr const PtpObjectFormatCode SupportedPlaybackFormats[] = {
|
||||
PtpObjectFormatCode_Undefined,
|
||||
PtpObjectFormatCode_Association,
|
||||
};
|
||||
|
||||
constexpr const PtpObjectPropertyCode SupportedObjectProperties[] = {
|
||||
PtpObjectPropertyCode_StorageId,
|
||||
PtpObjectPropertyCode_ObjectFormat,
|
||||
PtpObjectPropertyCode_ObjectSize,
|
||||
PtpObjectPropertyCode_ObjectFileName,
|
||||
PtpObjectPropertyCode_ParentObject,
|
||||
PtpObjectPropertyCode_PersistentUniqueObjectIdentifier,
|
||||
};
|
||||
|
||||
constexpr bool IsSupportedObjectPropertyCode(PtpObjectPropertyCode c) {
|
||||
for (size_t i = 0; i < util::size(SupportedObjectProperties); i++) {
|
||||
if (SupportedObjectProperties[i] == c) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
constexpr const StorageId SupportedStorageIds[] = {
|
||||
StorageId_SdmcFs,
|
||||
};
|
||||
|
||||
struct PtpStorageInfo {
|
||||
PtpStorageType storage_type;
|
||||
PtpFilesystemType filesystem_type;
|
||||
PtpAccessCapability access_capability;
|
||||
u64 max_capacity;
|
||||
u64 free_space_in_bytes;
|
||||
u32 free_space_in_images;
|
||||
const char *storage_description;
|
||||
const char *volume_label;
|
||||
};
|
||||
|
||||
constexpr PtpStorageInfo DefaultStorageInfo = {
|
||||
.storage_type = PtpStorageType_FixedRam,
|
||||
.filesystem_type = PtpFilesystemType_GenericHierarchical,
|
||||
.access_capability = PtpAccessCapability_ReadWrite,
|
||||
.max_capacity = 0,
|
||||
.free_space_in_bytes = 0,
|
||||
.free_space_in_images = 0,
|
||||
.storage_description = "",
|
||||
.volume_label = "",
|
||||
};
|
||||
|
||||
struct PtpObjectInfo {
|
||||
StorageId storage_id;
|
||||
PtpObjectFormatCode object_format;
|
||||
PtpProtectionStatus protection_status;
|
||||
u32 object_compressed_size;
|
||||
u16 thumb_format;
|
||||
u32 thumb_compressed_size;
|
||||
u32 thumb_width;
|
||||
u32 thumb_height;
|
||||
u32 image_width;
|
||||
u32 image_height;
|
||||
u32 image_depth;
|
||||
u32 parent_object;
|
||||
PtpAssociationType association_type;
|
||||
u32 association_desc;
|
||||
u32 sequence_number;
|
||||
const char *filename;
|
||||
const char *capture_date;
|
||||
const char *modification_date;
|
||||
const char *keywords;
|
||||
};
|
||||
|
||||
constexpr PtpObjectInfo DefaultObjectInfo = {
|
||||
.storage_id = StorageId_SdmcFs,
|
||||
.object_format = {},
|
||||
.protection_status = PtpProtectionStatus_NoProtection,
|
||||
.object_compressed_size = 0,
|
||||
.thumb_format = 0,
|
||||
.thumb_compressed_size = 0,
|
||||
.thumb_width = 0,
|
||||
.thumb_height = 0,
|
||||
.image_width = 0,
|
||||
.image_height = 0,
|
||||
.image_depth = 0,
|
||||
.parent_object = PtpGetObjectHandles_RootParent,
|
||||
.association_type = PtpAssociationType_Undefined,
|
||||
.association_desc = 0,
|
||||
.sequence_number = 0,
|
||||
.filename = nullptr,
|
||||
.capture_date = "",
|
||||
.modification_date = "",
|
||||
.keywords = "",
|
||||
};
|
||||
|
||||
constexpr u32 UsbBulkPacketBufferSize = 1_MB;
|
||||
constexpr u64 FsBufferSize = UsbBulkPacketBufferSize;
|
||||
constexpr s64 DirectoryReadSize = 32;
|
||||
|
||||
struct PtpBuffers {
|
||||
char filename_string_buffer[PtpStringMaxLength + 1];
|
||||
char capture_date_string_buffer[PtpStringMaxLength + 1];
|
||||
char modification_date_string_buffer[PtpStringMaxLength + 1];
|
||||
char keywords_string_buffer[PtpStringMaxLength + 1];
|
||||
|
||||
FsDirectoryEntry file_system_entry_buffer[DirectoryReadSize];
|
||||
u8 file_system_data_buffer[FsBufferSize];
|
||||
|
||||
alignas(4_KB) u8 usb_bulk_write_buffer[UsbBulkPacketBufferSize];
|
||||
alignas(4_KB) u8 usb_bulk_read_buffer[UsbBulkPacketBufferSize];
|
||||
};
|
||||
|
||||
}
|
|
@ -16,167 +16,22 @@
|
|||
#include <haze.hpp>
|
||||
#include <haze/ptp_data_builder.hpp>
|
||||
#include <haze/ptp_data_parser.hpp>
|
||||
#include <haze/ptp_responder_types.hpp>
|
||||
|
||||
namespace haze {
|
||||
|
||||
namespace {
|
||||
|
||||
constexpr UsbCommsInterfaceInfo MtpInterfaceInfo = {
|
||||
.bInterfaceClass = 0x06,
|
||||
.bInterfaceSubClass = 0x01,
|
||||
.bInterfaceProtocol = 0x01,
|
||||
};
|
||||
|
||||
/* This is a VID:PID recognized by libmtp. */
|
||||
constexpr u16 SwitchMtpIdVendor = 0x057e;
|
||||
constexpr u16 SwitchMtpIdProduct = 0x201d;
|
||||
|
||||
/* Constants used for MTP GetDeviceInfo response. */
|
||||
constexpr u16 MtpStandardVersion = 100;
|
||||
constexpr u32 MtpVendorExtensionId = 6;
|
||||
constexpr auto MtpVendorExtensionDesc = "microsoft.com: 1.0;";
|
||||
constexpr u16 MtpFunctionalModeDefault = 0;
|
||||
constexpr auto MtpDeviceManufacturer = "Nintendo";
|
||||
constexpr auto MtpDeviceModel = "Nintendo Switch";
|
||||
|
||||
enum StorageId : u32 {
|
||||
StorageId_SdmcFs = 0xffffffffu - 1,
|
||||
};
|
||||
|
||||
constexpr PtpOperationCode SupportedOperationCodes[] = {
|
||||
PtpOperationCode_GetDeviceInfo,
|
||||
PtpOperationCode_OpenSession,
|
||||
PtpOperationCode_CloseSession,
|
||||
PtpOperationCode_GetStorageIds,
|
||||
PtpOperationCode_GetStorageInfo,
|
||||
PtpOperationCode_GetObjectHandles,
|
||||
PtpOperationCode_GetObjectInfo,
|
||||
PtpOperationCode_GetObject,
|
||||
PtpOperationCode_SendObjectInfo,
|
||||
PtpOperationCode_SendObject,
|
||||
PtpOperationCode_DeleteObject,
|
||||
PtpOperationCode_MtpGetObjectPropsSupported,
|
||||
PtpOperationCode_MtpGetObjectPropDesc,
|
||||
PtpOperationCode_MtpGetObjectPropValue,
|
||||
PtpOperationCode_MtpSetObjectPropValue,
|
||||
};
|
||||
|
||||
constexpr const PtpEventCode SupportedEventCodes[] = { /* ... */ };
|
||||
constexpr const PtpDevicePropertyCode SupportedDeviceProperties[] = { /* ... */ };
|
||||
constexpr const PtpObjectFormatCode SupportedCaptureFormats[] = { /* ... */ };
|
||||
|
||||
constexpr const PtpObjectFormatCode SupportedPlaybackFormats[] = {
|
||||
PtpObjectFormatCode_Undefined,
|
||||
PtpObjectFormatCode_Association,
|
||||
};
|
||||
|
||||
constexpr const PtpObjectPropertyCode SupportedObjectProperties[] = {
|
||||
PtpObjectPropertyCode_StorageId,
|
||||
PtpObjectPropertyCode_ObjectFormat,
|
||||
PtpObjectPropertyCode_ObjectSize,
|
||||
PtpObjectPropertyCode_ObjectFileName,
|
||||
PtpObjectPropertyCode_ParentObject,
|
||||
PtpObjectPropertyCode_PersistentUniqueObjectIdentifier,
|
||||
};
|
||||
|
||||
constexpr bool IsSupportedObjectPropertyCode(PtpObjectPropertyCode c) {
|
||||
for (size_t i = 0; i < util::size(SupportedObjectProperties); i++) {
|
||||
if (SupportedObjectProperties[i] == c) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
PtpBuffers* GetBuffers() {
|
||||
static constinit PtpBuffers buffers = {};
|
||||
return std::addressof(buffers);
|
||||
}
|
||||
|
||||
constexpr const StorageId SupportedStorageIds[] = {
|
||||
StorageId_SdmcFs,
|
||||
};
|
||||
|
||||
struct PtpStorageInfo {
|
||||
PtpStorageType storage_type;
|
||||
PtpFilesystemType filesystem_type;
|
||||
PtpAccessCapability access_capability;
|
||||
u64 max_capacity;
|
||||
u64 free_space_in_bytes;
|
||||
u32 free_space_in_images;
|
||||
const char *storage_description;
|
||||
const char *volume_label;
|
||||
};
|
||||
|
||||
constexpr PtpStorageInfo DefaultStorageInfo = {
|
||||
.storage_type = PtpStorageType_FixedRam,
|
||||
.filesystem_type = PtpFilesystemType_GenericHierarchical,
|
||||
.access_capability = PtpAccessCapability_ReadWrite,
|
||||
.max_capacity = 0,
|
||||
.free_space_in_bytes = 0,
|
||||
.free_space_in_images = 0,
|
||||
.storage_description = "",
|
||||
.volume_label = "",
|
||||
};
|
||||
|
||||
struct PtpObjectInfo {
|
||||
StorageId storage_id;
|
||||
PtpObjectFormatCode object_format;
|
||||
PtpProtectionStatus protection_status;
|
||||
u32 object_compressed_size;
|
||||
u16 thumb_format;
|
||||
u32 thumb_compressed_size;
|
||||
u32 thumb_width;
|
||||
u32 thumb_height;
|
||||
u32 image_width;
|
||||
u32 image_height;
|
||||
u32 image_depth;
|
||||
u32 parent_object;
|
||||
PtpAssociationType association_type;
|
||||
u32 association_desc;
|
||||
u32 sequence_number;
|
||||
const char *filename;
|
||||
const char *capture_date;
|
||||
const char *modification_date;
|
||||
const char *keywords;
|
||||
};
|
||||
|
||||
constexpr PtpObjectInfo DefaultObjectInfo = {
|
||||
.storage_id = StorageId_SdmcFs,
|
||||
.object_format = {},
|
||||
.protection_status = PtpProtectionStatus_NoProtection,
|
||||
.object_compressed_size = 0,
|
||||
.thumb_format = 0,
|
||||
.thumb_compressed_size = 0,
|
||||
.thumb_width = 0,
|
||||
.thumb_height = 0,
|
||||
.image_width = 0,
|
||||
.image_height = 0,
|
||||
.image_depth = 0,
|
||||
.parent_object = PtpGetObjectHandles_RootParent,
|
||||
.association_type = PtpAssociationType_Undefined,
|
||||
.association_desc = 0,
|
||||
.sequence_number = 0,
|
||||
.filename = nullptr,
|
||||
.capture_date = "",
|
||||
.modification_date = "",
|
||||
.keywords = "",
|
||||
};
|
||||
|
||||
constexpr s64 DirectoryReadSize = 32;
|
||||
constexpr u64 FsBufferSize = haze::UsbBulkPacketBufferSize;
|
||||
|
||||
constinit char g_filename_str[PtpStringMaxLength + 1] = {};
|
||||
constinit char g_capture_date_str[PtpStringMaxLength + 1] = {};
|
||||
constinit char g_modification_date_str[PtpStringMaxLength + 1] = {};
|
||||
constinit char g_keywords_str[PtpStringMaxLength + 1] = {};
|
||||
|
||||
constinit FsDirectoryEntry g_dir_entries[DirectoryReadSize] = {};
|
||||
constinit u8 g_fs_buffer[FsBufferSize] = {};
|
||||
|
||||
alignas(4_KB) constinit u8 g_bulk_write_buffer[haze::UsbBulkPacketBufferSize] = {};
|
||||
alignas(4_KB) constinit u8 g_bulk_read_buffer[haze::UsbBulkPacketBufferSize] = {};
|
||||
|
||||
}
|
||||
|
||||
Result PtpResponder::Initialize(EventReactor *reactor, PtpObjectHeap *object_heap) {
|
||||
m_object_heap = object_heap;
|
||||
m_buffers = GetBuffers();
|
||||
|
||||
/* Configure fs proxy. */
|
||||
m_fs.Initialize(reactor, fsdevGetDeviceFileSystem("sdmc"));
|
||||
|
@ -246,7 +101,7 @@ namespace haze {
|
|||
}
|
||||
|
||||
Result PtpResponder::HandleRequestImpl() {
|
||||
PtpDataParser dp(g_bulk_read_buffer, std::addressof(m_usb_server));
|
||||
PtpDataParser dp(m_buffers->usb_bulk_read_buffer, std::addressof(m_usb_server));
|
||||
R_TRY(dp.Read(std::addressof(m_request_header)));
|
||||
|
||||
switch (m_request_header.type) {
|
||||
|
@ -287,22 +142,21 @@ namespace haze {
|
|||
}
|
||||
}
|
||||
|
||||
template <typename Data>
|
||||
Result PtpResponder::WriteResponse(PtpResponseCode code, Data &&data) {
|
||||
PtpDataBuilder db(g_bulk_write_buffer, std::addressof(m_usb_server));
|
||||
R_TRY(db.AddResponseHeader(m_request_header, code, sizeof(Data)));
|
||||
R_TRY(db.Add(data));
|
||||
Result PtpResponder::WriteResponse(PtpResponseCode code, const void* data, size_t size) {
|
||||
PtpDataBuilder db(m_buffers->usb_bulk_write_buffer, std::addressof(m_usb_server));
|
||||
R_TRY(db.AddResponseHeader(m_request_header, code, size));
|
||||
R_TRY(db.AddBuffer(reinterpret_cast<const u8*>(data), size));
|
||||
R_RETURN(db.Commit());
|
||||
}
|
||||
|
||||
Result PtpResponder::WriteResponse(PtpResponseCode code) {
|
||||
PtpDataBuilder db(g_bulk_write_buffer, std::addressof(m_usb_server));
|
||||
PtpDataBuilder db(m_buffers->usb_bulk_write_buffer, std::addressof(m_usb_server));
|
||||
R_TRY(db.AddResponseHeader(m_request_header, code, 0));
|
||||
R_RETURN(db.Commit());
|
||||
}
|
||||
|
||||
Result PtpResponder::GetDeviceInfo(PtpDataParser &dp) {
|
||||
PtpDataBuilder db(g_bulk_write_buffer, std::addressof(m_usb_server));
|
||||
PtpDataBuilder db(m_buffers->usb_bulk_write_buffer, std::addressof(m_usb_server));
|
||||
|
||||
/* Write the device info data. */
|
||||
R_TRY(db.WriteVariableLengthData(m_request_header, [&] () {
|
||||
|
@ -361,7 +215,7 @@ namespace haze {
|
|||
Result PtpResponder::GetStorageIds(PtpDataParser &dp) {
|
||||
R_TRY(dp.Finalize());
|
||||
|
||||
PtpDataBuilder db(g_bulk_write_buffer, std::addressof(m_usb_server));
|
||||
PtpDataBuilder db(m_buffers->usb_bulk_write_buffer, std::addressof(m_usb_server));
|
||||
|
||||
/* Write the storage ID array. */
|
||||
R_TRY(db.WriteVariableLengthData(m_request_header, [&] {
|
||||
|
@ -373,7 +227,7 @@ namespace haze {
|
|||
}
|
||||
|
||||
Result PtpResponder::GetStorageInfo(PtpDataParser &dp) {
|
||||
PtpDataBuilder db(g_bulk_write_buffer, std::addressof(m_usb_server));
|
||||
PtpDataBuilder db(m_buffers->usb_bulk_write_buffer, std::addressof(m_usb_server));
|
||||
PtpStorageInfo storage_info(DefaultStorageInfo);
|
||||
|
||||
/* Get the storage ID the client requested information for. */
|
||||
|
@ -418,7 +272,7 @@ namespace haze {
|
|||
}
|
||||
|
||||
Result PtpResponder::GetObjectHandles(PtpDataParser &dp) {
|
||||
PtpDataBuilder db(g_bulk_write_buffer, std::addressof(m_usb_server));
|
||||
PtpDataBuilder db(m_buffers->usb_bulk_write_buffer, std::addressof(m_usb_server));
|
||||
|
||||
/* Get the object ID the client requested enumeration for. */
|
||||
u32 storage_id, object_format_code, association_object_handle;
|
||||
|
@ -462,12 +316,14 @@ namespace haze {
|
|||
while (true) {
|
||||
/* Get the next batch. */
|
||||
s64 read_count = 0;
|
||||
R_TRY(m_fs.ReadDirectory(std::addressof(dir), std::addressof(read_count), DirectoryReadSize, g_dir_entries));
|
||||
R_TRY(m_fs.ReadDirectory(std::addressof(dir), std::addressof(read_count), DirectoryReadSize, m_buffers->file_system_entry_buffer));
|
||||
|
||||
/* Write to output. */
|
||||
for (s64 i = 0; i < read_count; i++) {
|
||||
const char *name = m_buffers->file_system_entry_buffer[i].name;
|
||||
u32 handle;
|
||||
R_TRY(m_object_database.CreateAndRegisterObjectId(obj->GetName(), g_dir_entries[i].name, obj->GetObjectId(), std::addressof(handle)));
|
||||
|
||||
R_TRY(m_object_database.CreateAndRegisterObjectId(obj->GetName(), name, obj->GetObjectId(), std::addressof(handle)));
|
||||
R_TRY(db.Add(handle));
|
||||
}
|
||||
|
||||
|
@ -485,7 +341,7 @@ namespace haze {
|
|||
}
|
||||
|
||||
Result PtpResponder::GetObjectInfo(PtpDataParser &dp) {
|
||||
PtpDataBuilder db(g_bulk_write_buffer, std::addressof(m_usb_server));
|
||||
PtpDataBuilder db(m_buffers->usb_bulk_write_buffer, std::addressof(m_usb_server));
|
||||
|
||||
/* Get the object ID the client requested info for. */
|
||||
u32 object_id;
|
||||
|
@ -564,7 +420,7 @@ namespace haze {
|
|||
}
|
||||
|
||||
Result PtpResponder::GetObject(PtpDataParser &dp) {
|
||||
PtpDataBuilder db(g_bulk_write_buffer, std::addressof(m_usb_server));
|
||||
PtpDataBuilder db(m_buffers->usb_bulk_write_buffer, std::addressof(m_usb_server));
|
||||
|
||||
/* Get the object ID the client requested. */
|
||||
u32 object_id;
|
||||
|
@ -594,12 +450,12 @@ namespace haze {
|
|||
while (true) {
|
||||
/* Get the next batch. */
|
||||
u64 bytes_read;
|
||||
R_TRY(m_fs.ReadFile(std::addressof(file), offset, g_fs_buffer, FsBufferSize, FsReadOption_None, std::addressof(bytes_read)));
|
||||
R_TRY(m_fs.ReadFile(std::addressof(file), offset, m_buffers->file_system_data_buffer, FsBufferSize, FsReadOption_None, std::addressof(bytes_read)));
|
||||
|
||||
offset += bytes_read;
|
||||
|
||||
/* Write to output. */
|
||||
R_TRY(db.AddBuffer(g_fs_buffer, bytes_read));
|
||||
R_TRY(db.AddBuffer(m_buffers->file_system_data_buffer, bytes_read));
|
||||
|
||||
/* If we read fewer bytes than the batch size, we're done. */
|
||||
if (bytes_read < FsBufferSize) {
|
||||
|
@ -621,7 +477,7 @@ namespace haze {
|
|||
R_TRY(rdp.Read(std::addressof(parent_object)));
|
||||
R_TRY(rdp.Finalize());
|
||||
|
||||
PtpDataParser dp(g_bulk_read_buffer, std::addressof(m_usb_server));
|
||||
PtpDataParser dp(m_buffers->usb_bulk_read_buffer, std::addressof(m_usb_server));
|
||||
PtpObjectInfo info(DefaultObjectInfo);
|
||||
|
||||
/* Ensure we have a data header. */
|
||||
|
@ -647,10 +503,10 @@ namespace haze {
|
|||
R_TRY(dp.Read(std::addressof(info.association_type)));
|
||||
R_TRY(dp.Read(std::addressof(info.association_desc)));
|
||||
R_TRY(dp.Read(std::addressof(info.sequence_number)));
|
||||
R_TRY(dp.ReadString(g_filename_str));
|
||||
R_TRY(dp.ReadString(g_capture_date_str));
|
||||
R_TRY(dp.ReadString(g_modification_date_str));
|
||||
R_TRY(dp.ReadString(g_keywords_str));
|
||||
R_TRY(dp.ReadString(m_buffers->filename_string_buffer));
|
||||
R_TRY(dp.ReadString(m_buffers->capture_date_string_buffer));
|
||||
R_TRY(dp.ReadString(m_buffers->modification_date_string_buffer));
|
||||
R_TRY(dp.ReadString(m_buffers->keywords_string_buffer));
|
||||
R_TRY(dp.Finalize());
|
||||
|
||||
/* Rewrite requests for creating in storage directories. */
|
||||
|
@ -669,7 +525,7 @@ namespace haze {
|
|||
|
||||
/* Create the object in the database. */
|
||||
PtpObject *obj;
|
||||
R_TRY(m_object_database.CreateOrFindObject(parentobj->GetName(), g_filename_str, parentobj->GetObjectId(), std::addressof(obj)));
|
||||
R_TRY(m_object_database.CreateOrFindObject(parentobj->GetName(), m_buffers->filename_string_buffer, parentobj->GetObjectId(), std::addressof(obj)));
|
||||
|
||||
/* Ensure we maintain a clean state on failure. */
|
||||
ON_RESULT_FAILURE { m_object_database.DeleteObject(obj); };
|
||||
|
@ -697,7 +553,7 @@ namespace haze {
|
|||
|
||||
R_TRY(rdp.Finalize());
|
||||
|
||||
PtpDataParser dp(g_bulk_read_buffer, std::addressof(m_usb_server));
|
||||
PtpDataParser dp(m_buffers->usb_bulk_read_buffer, std::addressof(m_usb_server));
|
||||
|
||||
/* Ensure we have a data header. */
|
||||
PtpUsbBulkContainer data_header;
|
||||
|
@ -730,10 +586,10 @@ namespace haze {
|
|||
while (true) {
|
||||
/* Read as many bytes as we can. */
|
||||
u32 bytes_received;
|
||||
const Result read_res = dp.ReadBuffer(g_fs_buffer, FsBufferSize, std::addressof(bytes_received));
|
||||
const Result read_res = dp.ReadBuffer(m_buffers->file_system_data_buffer, FsBufferSize, std::addressof(bytes_received));
|
||||
|
||||
/* Write to the file. */
|
||||
R_TRY(m_fs.WriteFile(std::addressof(file), offset, g_fs_buffer, bytes_received, 0));
|
||||
R_TRY(m_fs.WriteFile(std::addressof(file), offset, m_buffers->file_system_data_buffer, bytes_received, 0));
|
||||
|
||||
offset += bytes_received;
|
||||
|
||||
|
@ -786,7 +642,7 @@ namespace haze {
|
|||
Result PtpResponder::GetObjectPropsSupported(PtpDataParser &dp) {
|
||||
R_TRY(dp.Finalize());
|
||||
|
||||
PtpDataBuilder db(g_bulk_write_buffer, std::addressof(m_usb_server));
|
||||
PtpDataBuilder db(m_buffers->usb_bulk_write_buffer, std::addressof(m_usb_server));
|
||||
|
||||
/* Write information about all object properties we can support. */
|
||||
R_TRY(db.WriteVariableLengthData(m_request_header, [&] {
|
||||
|
@ -809,7 +665,7 @@ namespace haze {
|
|||
R_UNLESS(IsSupportedObjectPropertyCode(property_code), haze::ResultUnknownPropertyCode());
|
||||
|
||||
/* Begin writing information about the property code. */
|
||||
PtpDataBuilder db(g_bulk_write_buffer, std::addressof(m_usb_server));
|
||||
PtpDataBuilder db(m_buffers->usb_bulk_write_buffer, std::addressof(m_usb_server));
|
||||
|
||||
R_TRY(db.WriteVariableLengthData(m_request_header, [&] {
|
||||
R_TRY(db.Add(property_code));
|
||||
|
@ -913,7 +769,7 @@ namespace haze {
|
|||
};
|
||||
|
||||
/* Begin writing the requested object property. */
|
||||
PtpDataBuilder db(g_bulk_write_buffer, std::addressof(m_usb_server));
|
||||
PtpDataBuilder db(m_buffers->usb_bulk_write_buffer, std::addressof(m_usb_server));
|
||||
|
||||
R_TRY(db.WriteVariableLengthData(m_request_header, [&] {
|
||||
switch (property_code) {
|
||||
|
@ -969,7 +825,7 @@ namespace haze {
|
|||
R_TRY(rdp.Read(std::addressof(property_code)));
|
||||
R_TRY(rdp.Finalize());
|
||||
|
||||
PtpDataParser dp(g_bulk_read_buffer, std::addressof(m_usb_server));
|
||||
PtpDataParser dp(m_buffers->usb_bulk_read_buffer, std::addressof(m_usb_server));
|
||||
|
||||
/* Ensure we have a data header. */
|
||||
PtpUsbBulkContainer data_header;
|
||||
|
@ -986,12 +842,12 @@ namespace haze {
|
|||
R_UNLESS(obj != nullptr, haze::ResultInvalidObjectId());
|
||||
|
||||
/* We are reading a file name. */
|
||||
R_TRY(dp.ReadString(g_filename_str));
|
||||
R_TRY(dp.ReadString(m_buffers->filename_string_buffer));
|
||||
R_TRY(dp.Finalize());
|
||||
|
||||
/* Ensure we can actually process the new name. */
|
||||
const bool is_empty = g_filename_str[0] == '\x00';
|
||||
const bool contains_slashes = std::strchr(g_filename_str, '/') != nullptr;
|
||||
const bool is_empty = m_buffers->filename_string_buffer[0] == '\x00';
|
||||
const bool contains_slashes = std::strchr(m_buffers->filename_string_buffer, '/') != nullptr;
|
||||
R_UNLESS(!is_empty && !contains_slashes, haze::ResultInvalidPropertyValue());
|
||||
|
||||
/* Add a new object in the database with the new name. */
|
||||
|
@ -1005,7 +861,7 @@ namespace haze {
|
|||
*pathsep = '\x00';
|
||||
ON_SCOPE_EXIT { *pathsep = '/'; };
|
||||
|
||||
R_TRY(m_object_database.CreateOrFindObject(obj->GetName(), g_filename_str, obj->GetParentId(), std::addressof(newobj)));
|
||||
R_TRY(m_object_database.CreateOrFindObject(obj->GetName(), m_buffers->filename_string_buffer, obj->GetParentId(), std::addressof(newobj)));
|
||||
}
|
||||
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue