Commit f2894cc9 authored by Marc Vef's avatar Marc Vef
Browse files

new code directory hierarchy

parent 168fe4ad
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -16,6 +16,6 @@ find_package(FUSE3 REQUIRED)
find_package(Boost 1.56.0 COMPONENTS system filesystem serialization)

include_directories(${FUSE3_INCLUDE_DIR} include/)
set(SOURCE_FILES src/main.cpp src/main.h src/fuse_ops.h src/util.cpp src/metadata.h src/metadata.cpp src/metadata_ops.h src/metadata_ops.cpp src/dentry_ops.cpp src/dentry_ops.h src/configure.h src/fuse_ops/file.cpp src/fuse_ops/directory.cpp src/fuse_ops/permission.cpp src/fuse_utils.h src/fuse_ops/sync.cpp)
set(SOURCE_FILES src/main.cpp src/main.h src/fuse_ops.h src/util.cpp src/classes/metadata.h src/classes/metadata.cpp src/adafs_ops/metadata_ops.h src/adafs_ops/metadata_ops.cpp src/adafs_ops/dentry_ops.cpp src/adafs_ops/dentry_ops.h src/configure.h src/fuse_ops/file.cpp src/fuse_ops/directory.cpp src/fuse_ops/permission.cpp src/fuse_utils.h src/fuse_ops/sync.cpp)
add_executable(adafs ${SOURCE_FILES} src/main.cpp)
target_link_libraries(adafs ${FUSE3_LIBRARIES} -lpthread -lboost_system -lboost_filesystem -lboost_serialization)
 No newline at end of file
+80 −0
Original line number Diff line number Diff line
@@ -36,3 +36,45 @@ bool verify_dentry(const bfs::path& path) {
    // if file path exists leaf name is a valid dentry of parent_dir
    return bfs::exists(d_path);
}


/**
 * Reads all directory entries in a directory with a given @hash. Returns 0 if successful.
 * @dir is assumed to be empty
 */
int read_dentries(vector<string>& dir, const unsigned long hash) {
    auto path = bfs::path(ADAFS_DATA->dentry_path);
    path /= to_string(hash);
    if (!bfs::exists(path)) return 1;
    // shortcut if path is empty = no files in directory
    if (bfs::is_empty(path)) return 0;

    // Below can be simplified with a C++11 range based loop? But how? :( XXX
    bfs::directory_iterator end_dir_it;
    for (bfs::directory_iterator dir_it(path); dir_it != end_dir_it; ++dir_it) {
        const bfs::path cp = (*dir_it);
        dir.push_back(cp.filename().string());
    }
    return 0;
}

/**
 * Creates an empty file in the dentry folder of the parent directory, acting as a dentry for lookup
 * @param parent_dir
 * @param fname
 * @return
 */
int create_dentry(const unsigned long parent_dir_hash, const string& fname) {
    // XXX Errorhandling
    auto f_path = bfs::path(ADAFS_DATA->dentry_path);
    f_path /= to_string(parent_dir_hash);
    if (!bfs::exists(f_path)) return 1;

    f_path /= fname;

    bfs::ofstream ofs{f_path};

    // XXX make sure the file has been created

    return 0;
}
 No newline at end of file
+5 −1
Original line number Diff line number Diff line
@@ -5,10 +5,14 @@
#ifndef FS_DENTRY_OPS_H
#define FS_DENTRY_OPS_H

#include "main.h"
#include "../main.h"

bool init_dentry(const unsigned long& hash);

bool verify_dentry(const bfs::path& path);

int read_dentries(std::vector<std::string>& dir, const unsigned long hash);

int create_dentry(const unsigned long parent_dir_hash, const std::string& fname);

#endif //FS_DENTRY_OPS_H
+0 −40
Original line number Diff line number Diff line
@@ -90,46 +90,6 @@ int get_metadata(Metadata& md, const bfs::path& path) {
    }
}

/**
 * Reads all directory entries in a directory with a given @hash. Returns 0 if successful.
 * @dir is assumed to be empty
 */
int read_dentries(vector<string>& dir, const unsigned long hash) {
    auto path = bfs::path(ADAFS_DATA->dentry_path);
    path /= to_string(hash);
    if (!bfs::exists(path)) return 1;
    // shortcut if path is empty = no files in directory
    if (bfs::is_empty(path)) return 0;

    // Below can be simplified with a C++11 range based loop? But how? :( XXX
    bfs::directory_iterator end_dir_it;
    for (bfs::directory_iterator dir_it(path); dir_it != end_dir_it; ++dir_it) {
        const bfs::path cp = (*dir_it);
        dir.push_back(cp.filename().string());
    }
    return 0;
}

/**
 * Creates an empty file in the dentry folder of the parent directory, acting as a dentry for lookup
 * @param parent_dir
 * @param fname
 * @return
 */
int create_dentry(const unsigned long parent_dir_hash, const string& fname) {
    // XXX Errorhandling
    auto f_path = bfs::path(ADAFS_DATA->dentry_path);
    f_path /= to_string(parent_dir_hash);
    if (!bfs::exists(f_path)) return 1;

    f_path /= fname;

    bfs::ofstream ofs{f_path};

    // XXX make sure the file has been created

    return 0;
}



+2 −6
Original line number Diff line number Diff line
@@ -5,8 +5,8 @@
#ifndef FS_METADATA_OPS_H
#define FS_METADATA_OPS_H

#include "main.h"
#include "metadata.h"
#include "../main.h"
#include "../classes/metadata.h"

using namespace std;

@@ -24,8 +24,4 @@ int get_metadata(Metadata& md, const std::string& path);

int get_metadata(Metadata& md, const boost::filesystem::path& path);

int read_dentries(std::vector<std::string>& dir, const unsigned long hash);

int create_dentry(const unsigned long parent_dir_hash, const std::string& fname);

#endif //FS_METADATA_OPS_H
Loading