191 lines
4.4 KiB
C++
191 lines
4.4 KiB
C++
#ifndef COMMON_H
|
|
#define COMMON_H
|
|
|
|
#define FUSE_USE_VERSION 31
|
|
#define HASH_SIZE 20
|
|
#define PATH_SIZE 255
|
|
#define CLEANER_DELAY 1000
|
|
#define DEFAULT_BLK_SIZE 16777216
|
|
#define APP_NAME "DBFS"
|
|
#define APP_VER "1.0"
|
|
#define APP_TARGET "dbfs"
|
|
#define D_DIR "/.d"
|
|
#define SNAP_DIR "/.d/snapshots/"
|
|
#define FORK_DIR "/.d/forks/"
|
|
#define TMP_DIR "/.d/tmp"
|
|
#define SNAPSHOT_P_INDEX "fsPSIndex_"
|
|
#define SNAPSHOT_H_INDEX "fsHSIndex_"
|
|
#define FORK_P_INDEX "fsPFIndex_"
|
|
#define FORK_H_INDEX "fsHFIndex_"
|
|
#define ORIGIN_P_INDEX "fsPOIndex_root"
|
|
#define ORIGIN_H_INDEX "fsHOIndex_root"
|
|
#define ORIGIN_NAME "root"
|
|
#define DBDRV_SQLITE "QSQLITE"
|
|
#define DBDRV_MYSQL "QMYSQL"
|
|
|
|
#include <QCoreApplication>
|
|
#include <QRegularExpression>
|
|
#include <QTextStream>
|
|
#include <QThread>
|
|
#include <QFile>
|
|
#include <QSqlDatabase>
|
|
#include <QJsonObject>
|
|
#include <QJsonDocument>
|
|
#include <QDir>
|
|
#include <QSqlError>
|
|
#include <QSqlQuery>
|
|
#include <QProcess>
|
|
#include <QStringList>
|
|
#include <QDateTime>
|
|
#include <QFileInfo>
|
|
#include <QCryptographicHash>
|
|
#include <QMutex>
|
|
#include <QHash>
|
|
#include <QDebug>
|
|
#include <QTimer>
|
|
#include <fuse3/fuse.h>
|
|
#include <fuse3/fuse_lowlevel.h>
|
|
#include <fuse3/fuse_common.h>
|
|
#include <errno.h>
|
|
#include <cstring>
|
|
#include <unistd.h>
|
|
#include <thread>
|
|
#include <sstream>
|
|
#include <string>
|
|
#include <limits>
|
|
#include <tgmath.h>
|
|
#include <time.h>
|
|
#include <sys/types.h>
|
|
|
|
#include "unix_signal.h"
|
|
|
|
enum PathOp
|
|
{
|
|
READ_ONLY = 1,
|
|
READ_WRITE = 1 << 1,
|
|
NO_DIR = 1 << 2,
|
|
DIR_ONLY = 1 << 3
|
|
};
|
|
|
|
enum DataSetTypes
|
|
{
|
|
SNAPSHOT,
|
|
FORK,
|
|
ORIGIN
|
|
};
|
|
|
|
enum TableTypes
|
|
{
|
|
P_TABLE,
|
|
H_TABLE
|
|
};
|
|
|
|
QString genInstanceName();
|
|
QString escapeChars(const QString &str, const QChar &escapeChr, const QChar &chr);
|
|
QString escapeChars(const QString &str, const QChar &escapeChr, const QString &chrs);
|
|
QStringList parseArgs(const QString &line, int maxArgs);
|
|
QByteArray genHash(const QByteArray &bytes);
|
|
QByteArray genHash(const char *bytes, quint64 len);
|
|
QString extExpand(const QString &text, int &retCode);
|
|
QString dbDrvr();
|
|
quint64 toBytes(QString txt);
|
|
quint32 genSerial();
|
|
mode_t fileDefaultMode();
|
|
mode_t symmDefaultMode();
|
|
mode_t dirDefaultMode();
|
|
bool isDDir(const QString &path);
|
|
bool validPath(const QString &path);
|
|
bool validDataset(const QString &name);
|
|
bool parseConfig(int &ret);
|
|
bool fsFull();
|
|
char *defaultConfig();
|
|
void dbCleanup();
|
|
void dumpFile(const char *path, QTextStream &strm);
|
|
void addStdErrStr(int errnum);
|
|
void expandDbError(const QSqlError &err, QSqlQuery &query);
|
|
void expandDbError(const QSqlError &err, QSqlQuery &query, int &errnum);
|
|
void expandDbError(const QSqlError &err, int &errnum);
|
|
void calcBlkOffsAndPos(quint64 dataOffs, int &firstBlkOffs, int &blkNum);
|
|
int calcNumOfBlocks(quint64 len, bool countZero = true);
|
|
quint64 calcSizeOfLastBlk(quint64 len);
|
|
quint64 calcDiff(quint64 numA, quint64 numB);
|
|
|
|
struct Block
|
|
{
|
|
QByteArray blk;
|
|
QString dataset;
|
|
quint32 ino;
|
|
int blkNum;
|
|
bool update;
|
|
};
|
|
|
|
class Cleaner;
|
|
|
|
class SharedData
|
|
{
|
|
|
|
public:
|
|
|
|
static struct fuse *fuseHandle;
|
|
|
|
static QHash<quint32, Block> *hashCache;
|
|
static QHash<QString, quint32> *inoCache;
|
|
static Cleaner *fsCleaner;
|
|
static QMutex *mutex;
|
|
static QJsonObject *confObj;
|
|
static QCoreApplication *app;
|
|
static QStringList *dbConnections;
|
|
static QString *mntDataset;
|
|
static quint64 *maxBytes;
|
|
static quint64 *bytesUsed;
|
|
static quint64 *blkSize;
|
|
static char *configPath;
|
|
static char *mntPnt;
|
|
static bool *readonly;
|
|
|
|
explicit SharedData();
|
|
};
|
|
|
|
class Path
|
|
{
|
|
|
|
private:
|
|
|
|
QFileInfo info;
|
|
|
|
public:
|
|
|
|
static QChar Sep();
|
|
|
|
explicit Path(const QString &fullPath);
|
|
|
|
QString dir();
|
|
QString fileName();
|
|
bool root();
|
|
};
|
|
|
|
class FuseMain : public QObject
|
|
{
|
|
Q_OBJECT
|
|
|
|
private:
|
|
|
|
QThread *worker;
|
|
struct fuse_operations *fs_oper;
|
|
|
|
private slots:
|
|
|
|
void onStart();
|
|
|
|
public slots:
|
|
|
|
void onTerm();
|
|
int loop();
|
|
|
|
public:
|
|
|
|
explicit FuseMain(struct fuse_operations *oper, QObject *parent = NULL);
|
|
};
|
|
|
|
#endif // COMMON_H
|