2014-11-15 15:16:18 +01:00
|
|
|
#pragma once
|
2015-10-15 13:04:57 +02:00
|
|
|
#ifndef MESSMER_FSPP_IMPL_FILESYSTEMIMPL_H_
|
|
|
|
#define MESSMER_FSPP_IMPL_FILESYSTEMIMPL_H_
|
2014-11-15 15:16:18 +01:00
|
|
|
|
2014-11-15 17:24:07 +01:00
|
|
|
#include "FuseOpenFileList.h"
|
2015-02-17 00:48:49 +01:00
|
|
|
#include "../fuse/Filesystem.h"
|
2014-11-15 15:16:18 +01:00
|
|
|
|
2015-06-21 17:44:30 +02:00
|
|
|
#include <messmer/cpp-utils/pointer/unique_ref.h>
|
2015-09-29 21:47:50 +02:00
|
|
|
#include <atomic>
|
|
|
|
|
|
|
|
//Remove this line if you don't want profiling
|
2015-10-14 15:39:44 +02:00
|
|
|
//#define FSPP_PROFILE 1
|
2014-11-15 15:16:18 +01:00
|
|
|
|
2016-02-06 13:56:33 +01:00
|
|
|
//TODO Test
|
|
|
|
|
2014-11-16 00:05:28 +01:00
|
|
|
namespace fspp {
|
2014-11-15 23:47:38 +01:00
|
|
|
class Node;
|
|
|
|
class File;
|
2015-04-22 16:00:14 +02:00
|
|
|
class Symlink;
|
2014-11-15 23:47:38 +01:00
|
|
|
class OpenFile;
|
2014-11-15 15:16:18 +01:00
|
|
|
|
2015-11-27 14:05:48 +01:00
|
|
|
class FilesystemImpl final: public fuse::Filesystem {
|
2014-11-15 15:16:18 +01:00
|
|
|
public:
|
2015-04-27 18:21:33 +02:00
|
|
|
explicit FilesystemImpl(Device *device);
|
2014-11-15 17:24:07 +01:00
|
|
|
virtual ~FilesystemImpl();
|
2014-11-15 15:16:18 +01:00
|
|
|
|
2014-11-19 00:14:35 +01:00
|
|
|
int openFile(const boost::filesystem::path &path, int flags) override;
|
2014-11-21 01:11:24 +01:00
|
|
|
void flush(int descriptor) override;
|
2014-11-19 00:14:35 +01:00
|
|
|
void closeFile(int descriptor) override;
|
|
|
|
void lstat(const boost::filesystem::path &path, struct ::stat *stbuf) override;
|
|
|
|
void fstat(int descriptor, struct ::stat *stbuf) override;
|
2015-04-21 21:08:23 +02:00
|
|
|
void chmod(const boost::filesystem::path &path, mode_t mode) override;
|
|
|
|
void chown(const boost::filesystem::path &path, uid_t uid, gid_t gid) override;
|
2014-11-19 00:14:35 +01:00
|
|
|
void truncate(const boost::filesystem::path &path, off_t size) override;
|
|
|
|
void ftruncate(int descriptor, off_t size) override;
|
2015-12-07 12:13:23 +01:00
|
|
|
size_t read(int descriptor, void *buf, size_t count, off_t offset) override;
|
2014-11-19 00:14:35 +01:00
|
|
|
void write(int descriptor, const void *buf, size_t count, off_t offset) override;
|
|
|
|
void fsync(int descriptor) override;
|
|
|
|
void fdatasync(int descriptor) override;
|
|
|
|
void access(const boost::filesystem::path &path, int mask) override;
|
2015-04-22 14:31:15 +02:00
|
|
|
int createAndOpenFile(const boost::filesystem::path &path, mode_t mode, uid_t uid, gid_t gid) override;
|
|
|
|
void mkdir(const boost::filesystem::path &path, mode_t mode, uid_t uid, gid_t gid) override;
|
2014-11-19 00:14:35 +01:00
|
|
|
void rmdir(const boost::filesystem::path &path) override;
|
|
|
|
void unlink(const boost::filesystem::path &path) override;
|
|
|
|
void rename(const boost::filesystem::path &from, const boost::filesystem::path &to) override;
|
2015-06-18 19:30:52 +02:00
|
|
|
cpputils::unique_ref<std::vector<Dir::Entry>> readDir(const boost::filesystem::path &path) override;
|
2014-11-19 00:14:35 +01:00
|
|
|
void utimens(const boost::filesystem::path &path, const timespec times[2]) override;
|
|
|
|
void statfs(const boost::filesystem::path &path, struct statvfs *fsstat) override;
|
2015-04-23 09:17:23 +02:00
|
|
|
void createSymlink(const boost::filesystem::path &to, const boost::filesystem::path &from, uid_t uid, gid_t gid) override;
|
|
|
|
void readSymlink(const boost::filesystem::path &path, char *buf, size_t size) override;
|
2014-11-15 15:16:18 +01:00
|
|
|
|
|
|
|
private:
|
2015-06-18 19:30:52 +02:00
|
|
|
cpputils::unique_ref<File> LoadFile(const boost::filesystem::path &path);
|
|
|
|
cpputils::unique_ref<Dir> LoadDir(const boost::filesystem::path &path);
|
|
|
|
cpputils::unique_ref<Symlink> LoadSymlink(const boost::filesystem::path &path);
|
2016-02-06 13:02:21 +01:00
|
|
|
cpputils::unique_ref<Node> LoadFileOrSymlink(const boost::filesystem::path &path);
|
2014-11-15 23:47:38 +01:00
|
|
|
int openFile(const File &file, int flags);
|
2014-11-15 17:24:07 +01:00
|
|
|
|
2015-09-29 21:47:50 +02:00
|
|
|
#ifdef FSPP_PROFILE
|
|
|
|
std::atomic<uint64_t> _loadFileNanosec;
|
|
|
|
std::atomic<uint64_t> _loadDirNanosec;
|
|
|
|
std::atomic<uint64_t> _loadSymlinkNanosec;
|
2016-02-06 13:02:21 +01:00
|
|
|
std::atomic<uint64_t> _loadFileOrSymlinkNanosec;
|
2015-09-29 21:47:50 +02:00
|
|
|
std::atomic<uint64_t> _openFileNanosec;
|
|
|
|
std::atomic<uint64_t> _flushNanosec;
|
|
|
|
std::atomic<uint64_t> _closeFileNanosec;
|
|
|
|
std::atomic<uint64_t> _lstatNanosec;
|
|
|
|
std::atomic<uint64_t> _fstatNanosec;
|
|
|
|
std::atomic<uint64_t> _chmodNanosec;
|
|
|
|
std::atomic<uint64_t> _chownNanosec;
|
|
|
|
std::atomic<uint64_t> _truncateNanosec;
|
|
|
|
std::atomic<uint64_t> _ftruncateNanosec;
|
|
|
|
std::atomic<uint64_t> _readNanosec;
|
|
|
|
std::atomic<uint64_t> _writeNanosec;
|
|
|
|
std::atomic<uint64_t> _fsyncNanosec;
|
|
|
|
std::atomic<uint64_t> _fdatasyncNanosec;
|
|
|
|
std::atomic<uint64_t> _accessNanosec;
|
|
|
|
std::atomic<uint64_t> _createAndOpenFileNanosec;
|
|
|
|
std::atomic<uint64_t> _createAndOpenFileNanosec_withoutLoading;
|
|
|
|
std::atomic<uint64_t> _mkdirNanosec;
|
|
|
|
std::atomic<uint64_t> _mkdirNanosec_withoutLoading;
|
|
|
|
std::atomic<uint64_t> _rmdirNanosec;
|
|
|
|
std::atomic<uint64_t> _rmdirNanosec_withoutLoading;
|
|
|
|
std::atomic<uint64_t> _unlinkNanosec;
|
|
|
|
std::atomic<uint64_t> _unlinkNanosec_withoutLoading;
|
|
|
|
std::atomic<uint64_t> _renameNanosec;
|
|
|
|
std::atomic<uint64_t> _readDirNanosec;
|
|
|
|
std::atomic<uint64_t> _readDirNanosec_withoutLoading;
|
|
|
|
std::atomic<uint64_t> _utimensNanosec;
|
|
|
|
std::atomic<uint64_t> _statfsNanosec;
|
|
|
|
std::atomic<uint64_t> _createSymlinkNanosec;
|
|
|
|
std::atomic<uint64_t> _createSymlinkNanosec_withoutLoading;
|
|
|
|
std::atomic<uint64_t> _readSymlinkNanosec;
|
|
|
|
std::atomic<uint64_t> _readSymlinkNanosec_withoutLoading;
|
|
|
|
#endif
|
|
|
|
|
2014-11-15 23:47:38 +01:00
|
|
|
Device *_device;
|
2014-11-15 15:16:18 +01:00
|
|
|
FuseOpenFileList _open_files;
|
|
|
|
|
2014-11-15 17:24:07 +01:00
|
|
|
DISALLOW_COPY_AND_ASSIGN(FilesystemImpl);
|
2014-11-15 15:16:18 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2015-11-27 14:05:48 +01:00
|
|
|
#endif
|