From af32bb9c4f4f06e92de3435ed2db3153c0701094 Mon Sep 17 00:00:00 2001 From: bigbiff bigbiff Date: Tue, 18 Dec 2018 18:39:53 -0500 Subject: MTP FFS updates: This update splits old MTP code and new MTP code from Google into two trees, legacy and ffs. Depending on the SDK level, the build system will select the correct version. The reason for separating the versions out are due to older android trees not supporting the updated MTP code from Google. Most MTP code is from Google, with additions needed from implementing the Java functions in C++ for TWRP and FFS. We assume if you are in android-9.0 or above, your kernel has support for FFS over MTP. Verify that your init.rc is mounting the MTP FFS driver to the proper location. Change-Id: I4b107b239bd9bc5699527f9c8c77d9079f264a7e --- mtp/ffs/MtpStorage.h | 103 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 103 insertions(+) create mode 100755 mtp/ffs/MtpStorage.h (limited to 'mtp/ffs/MtpStorage.h') diff --git a/mtp/ffs/MtpStorage.h b/mtp/ffs/MtpStorage.h new file mode 100755 index 000000000..9d6d29115 --- /dev/null +++ b/mtp/ffs/MtpStorage.h @@ -0,0 +1,103 @@ +/* + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef _MTP_STORAGE_H +#define _MTP_STORAGE_H + +#include "MtpObjectInfo.h" +#include "MtpServer.h" +#include "MtpStringBuffer.h" +#include "MtpTypes.h" +#include "mtp.h" +#include "btree.hpp" +#include "../../tw_atomic.hpp" + +class MtpDatabase; + +class MtpStorage { + +public: + struct PropEntry { + MtpObjectHandle handle; + uint16_t property; + uint16_t datatype; + uint64_t intvalue; + std::string strvalue; + }; + +private: + MtpStorageID mStorageID; + MtpStringBuffer mFilePath; + MtpStringBuffer mDescription; + uint64_t mMaxCapacity; + uint64_t mMaxFileSize; + bool mRemovable; + typedef std::map maptree; + typedef maptree::iterator iter; + maptree mtpmap; + std::string mtpstorageparent; + MtpObjectHandle handleCurrentlySending; + int inotify_fd; + std::map inotifymap; // inotify wd -> tree + bool sendEvents; + MtpServer* mServer; + typedef int (MtpStorage::*ThreadPtr)(void); + typedef void* (*PThreadPtr)(void *); + bool use_mutex; + pthread_mutex_t inMutex; // inotify mutex + pthread_mutex_t mtpMutex; // main mtp mutex + TWAtomicInt inotify_thread_kill; + pthread_t inotify_thread; + Node* findNode(MtpObjectHandle handle); + std::string getNodePath(Node* node); + Node* addNewNode(bool isDir, Tree* tree, const std::string& name); + void queryNodeProperties(std::vector& results, Node* node, uint32_t property, int groupCode, MtpStorageID storageID); + int addInotify(Tree* tree); + void handleInotifyEvent(struct inotify_event* event); + +public: + MtpStorage(MtpStorageID id, const char* filePath, + const char* description, + bool removable, uint64_t maxFileSize, MtpServer* refserver); + virtual ~MtpStorage(); + inline MtpStorageID getStorageID() const { return mStorageID; } + int getType() const; + int getFileSystemType() const; + int getAccessCapability() const; + uint64_t getMaxCapacity(); + uint64_t getFreeSpace(); + const char* getDescription() const; + inline const char* getPath() const { return (const char *)mFilePath; } + inline bool isRemovable() const { return mRemovable; } + inline uint64_t getMaxFileSize() const { return mMaxFileSize; } + int renameObject(MtpObjectHandle handle, std::string newName); + MtpObjectHandle beginSendObject(const char* path, MtpObjectFormat format, MtpObjectHandle parent, uint64_t size, time_t modified); + MtpObjectHandleList* getObjectList(MtpStorageID storageID, MtpObjectHandle parent); + int getObjectPropertyList(MtpObjectHandle handle, uint32_t format, uint32_t property, int groupCode, int depth, MtpDataPacket& packet); + int readDir(const std::string& path, Tree* tree); + int getObjectPropertyValue(MtpObjectHandle handle, MtpObjectProperty property, PropEntry& prop); + int getObjectInfo(MtpObjectHandle handle, MtpObjectInfo& info); + void endSendObject(const char* path, MtpObjectHandle handle, MtpObjectFormat format, bool succeeded); + int getObjectFilePath(MtpObjectHandle handle, MtpStringBuffer& outFilePath, int64_t& outFileLength, MtpObjectFormat& outFormat); + int deleteFile(MtpObjectHandle handle); + int createDB(); + pthread_t inotify(); + int inotify_t(); + void lockMutex(int thread_type); + void unlockMutex(int thread_type); +}; + +#endif // _MTP_STORAGE_H -- cgit v1.2.3