Loading media/mtp/MtpFfsHandle.cpp +23 −0 Original line number Original line Diff line number Diff line Loading @@ -38,6 +38,8 @@ #define cpu_to_le16(x) htole16(x) #define cpu_to_le16(x) htole16(x) #define cpu_to_le32(x) htole32(x) #define cpu_to_le32(x) htole32(x) #define FUNCTIONFS_ENDPOINT_ALLOC _IOR('g', 131, __u32) namespace { namespace { constexpr char FFS_MTP_EP_IN[] = "/dev/usb-ffs/mtp/ep1"; constexpr char FFS_MTP_EP_IN[] = "/dev/usb-ffs/mtp/ep1"; Loading Loading @@ -467,6 +469,24 @@ void MtpFfsHandle::close() { mLock.unlock(); mLock.unlock(); } } class ScopedEndpointBufferAlloc { private: const int mFd; const unsigned int mAllocSize; public: ScopedEndpointBufferAlloc(int fd, unsigned alloc_size) : mFd(fd), mAllocSize(alloc_size) { if (ioctl(mFd, FUNCTIONFS_ENDPOINT_ALLOC, static_cast<__u32>(mAllocSize))) PLOG(DEBUG) << "FFS endpoint alloc failed!"; } ~ScopedEndpointBufferAlloc() { if (ioctl(mFd, FUNCTIONFS_ENDPOINT_ALLOC, static_cast<__u32>(0))) PLOG(DEBUG) << "FFS endpoint alloc reset failed!"; } }; /* Read from USB and write to a local file. */ /* Read from USB and write to a local file. */ int MtpFfsHandle::receiveFile(mtp_file_range mfr) { int MtpFfsHandle::receiveFile(mtp_file_range mfr) { // When receiving files, the incoming length is given in 32 bits. // When receiving files, the incoming length is given in 32 bits. Loading Loading @@ -494,6 +514,7 @@ int MtpFfsHandle::receiveFile(mtp_file_range mfr) { bool write = false; bool write = false; posix_fadvise(mfr.fd, 0, 0, POSIX_FADV_SEQUENTIAL | POSIX_FADV_NOREUSE); posix_fadvise(mfr.fd, 0, 0, POSIX_FADV_SEQUENTIAL | POSIX_FADV_NOREUSE); ScopedEndpointBufferAlloc(mBulkOut, mMaxRead); // Break down the file into pieces that fit in buffers // Break down the file into pieces that fit in buffers while (file_length > 0 || write) { while (file_length > 0 || write) { Loading Loading @@ -609,6 +630,8 @@ int MtpFfsHandle::sendFile(mtp_file_range mfr) { if (writeHandle(mBulkIn, data, packet_size) == -1) return -1; if (writeHandle(mBulkIn, data, packet_size) == -1) return -1; if (file_length == 0) return 0; if (file_length == 0) return 0; ScopedEndpointBufferAlloc(mBulkIn, mMaxWrite); // Break down the file into pieces that fit in buffers // Break down the file into pieces that fit in buffers while(file_length > 0) { while(file_length > 0) { if (read) { if (read) { Loading Loading
media/mtp/MtpFfsHandle.cpp +23 −0 Original line number Original line Diff line number Diff line Loading @@ -38,6 +38,8 @@ #define cpu_to_le16(x) htole16(x) #define cpu_to_le16(x) htole16(x) #define cpu_to_le32(x) htole32(x) #define cpu_to_le32(x) htole32(x) #define FUNCTIONFS_ENDPOINT_ALLOC _IOR('g', 131, __u32) namespace { namespace { constexpr char FFS_MTP_EP_IN[] = "/dev/usb-ffs/mtp/ep1"; constexpr char FFS_MTP_EP_IN[] = "/dev/usb-ffs/mtp/ep1"; Loading Loading @@ -467,6 +469,24 @@ void MtpFfsHandle::close() { mLock.unlock(); mLock.unlock(); } } class ScopedEndpointBufferAlloc { private: const int mFd; const unsigned int mAllocSize; public: ScopedEndpointBufferAlloc(int fd, unsigned alloc_size) : mFd(fd), mAllocSize(alloc_size) { if (ioctl(mFd, FUNCTIONFS_ENDPOINT_ALLOC, static_cast<__u32>(mAllocSize))) PLOG(DEBUG) << "FFS endpoint alloc failed!"; } ~ScopedEndpointBufferAlloc() { if (ioctl(mFd, FUNCTIONFS_ENDPOINT_ALLOC, static_cast<__u32>(0))) PLOG(DEBUG) << "FFS endpoint alloc reset failed!"; } }; /* Read from USB and write to a local file. */ /* Read from USB and write to a local file. */ int MtpFfsHandle::receiveFile(mtp_file_range mfr) { int MtpFfsHandle::receiveFile(mtp_file_range mfr) { // When receiving files, the incoming length is given in 32 bits. // When receiving files, the incoming length is given in 32 bits. Loading Loading @@ -494,6 +514,7 @@ int MtpFfsHandle::receiveFile(mtp_file_range mfr) { bool write = false; bool write = false; posix_fadvise(mfr.fd, 0, 0, POSIX_FADV_SEQUENTIAL | POSIX_FADV_NOREUSE); posix_fadvise(mfr.fd, 0, 0, POSIX_FADV_SEQUENTIAL | POSIX_FADV_NOREUSE); ScopedEndpointBufferAlloc(mBulkOut, mMaxRead); // Break down the file into pieces that fit in buffers // Break down the file into pieces that fit in buffers while (file_length > 0 || write) { while (file_length > 0 || write) { Loading Loading @@ -609,6 +630,8 @@ int MtpFfsHandle::sendFile(mtp_file_range mfr) { if (writeHandle(mBulkIn, data, packet_size) == -1) return -1; if (writeHandle(mBulkIn, data, packet_size) == -1) return -1; if (file_length == 0) return 0; if (file_length == 0) return 0; ScopedEndpointBufferAlloc(mBulkIn, mMaxWrite); // Break down the file into pieces that fit in buffers // Break down the file into pieces that fit in buffers while(file_length > 0) { while(file_length > 0) { if (read) { if (read) { Loading