1 /* 2 * Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de. 3 * Distributed under the terms of the MIT License. 4 */ 5 #ifndef USERLAND_FS_FUSE_FILE_SYSTEM_H 6 #define USERLAND_FS_FUSE_FILE_SYSTEM_H 7 8 #include "../FileSystem.h" 9 10 #include "fuse_api.h" 11 #include "fuse_config.h" 12 13 14 namespace UserlandFS { 15 16 class FUSEFileSystem : public FileSystem { 17 public: 18 FUSEFileSystem(const char* fsName, 19 int (*mainFunction)(int, 20 const char* const*)); 21 virtual ~FUSEFileSystem(); 22 23 static FUSEFileSystem* GetInstance(); 24 25 void GetVolumeCapabilities( 26 FSVolumeCapabilities& capabilities) const 27 { capabilities = fVolumeCapabilities; } 28 void GetNodeCapabilities( 29 FSVNodeCapabilities& capabilities) const 30 { capabilities = fNodeCapabilities; } 31 const FSVNodeCapabilities& GetNodeCapabilities() const 32 { return fNodeCapabilities; } 33 34 fuse_fs* GetFS() const { return fFS; } 35 36 const fuse_config& GetFUSEConfig() const { return fFUSEConfig; } 37 38 virtual status_t CreateVolume(Volume** _volume, dev_t id); 39 virtual status_t DeleteVolume(Volume* volume); 40 41 virtual void InitRequestThreadContext( 42 RequestThreadContext* context); 43 44 status_t InitClientFS(const char* parameters); 45 void ExitClientFS(status_t status); 46 47 status_t FinishInitClientFS(fuse_config* config, 48 const fuse_operations* ops, size_t opSize, 49 void* userData); 50 status_t MainLoop(bool multithreaded); 51 52 private: 53 class ArgumentVector; 54 55 private: 56 static status_t _InitializationThreadEntry(void* data); 57 status_t _InitializationThread(); 58 59 status_t _InitClientFS(const fuse_operations* ops, 60 size_t opSize, void* userData); 61 62 void _InitCapabilities(); 63 64 private: 65 int (*fMainFunction)(int, const char* const*); 66 thread_id fInitThread; 67 status_t fInitStatus; 68 status_t fExitStatus; 69 sem_id fInitSemaphore; 70 sem_id fExitSemaphore; 71 fuse_operations fOps; 72 const char* fInitParameters; 73 fuse_fs* fFS; 74 fuse_conn_info fConnectionInfo; 75 fuse_config fFUSEConfig; 76 77 FSVolumeCapabilities fVolumeCapabilities; 78 FSVNodeCapabilities fNodeCapabilities; 79 }; 80 81 } // namespace UserlandFS 82 83 using UserlandFS::FUSEFileSystem; 84 85 86 /*static*/ inline FUSEFileSystem* 87 FUSEFileSystem::GetInstance() 88 { 89 return static_cast<FUSEFileSystem*>(sInstance); 90 } 91 92 93 #endif // USERLAND_FS_FUSE_FILE_SYSTEM_H 94