Loading fs/src/adafs_ops/dentry_ops.cpp +44 −2 Original line number Diff line number Diff line Loading @@ -7,11 +7,11 @@ using namespace std; /** * Called when a directory is created to init the corresponding dentry dir. * Initializes the dentry directory to hold future dentries * @param hash * @return */ bool init_dentry(const unsigned long& hash) { bool init_dentry_dir(const unsigned long& hash) { auto d_path = bfs::path(ADAFS_DATA->dentry_path); d_path /= to_string(hash); bfs::create_directories(d_path); Loading @@ -19,6 +19,21 @@ bool init_dentry(const unsigned long& hash) { return bfs::exists(d_path); } /** * Destroys the dentry directory * @param hash * @return true if successfully deleted */ bool destroy_dentry_dir(const unsigned long& hash) { auto d_path = bfs::path(ADAFS_DATA->dentry_path); d_path /= to_string(hash); // remove dentry dir bfs::remove_all(d_path); return !bfs::exists(d_path); } /** * Check if the file name can be found in the directory entries of parent_dir_hash * @param parent_dir_hash Loading Loading @@ -80,6 +95,13 @@ int create_dentry(const unsigned long parent_dir_hash, const string& fname) { return 0; } /** * Removes a dentry from the parent directory * @param parent_dir_hash * @param fname * @return */ // XXX errorhandling int remove_dentry(const unsigned long parent_dir_hash, const string& fname) { auto f_path = bfs::path(ADAFS_DATA->dentry_path); f_path /= to_string(parent_dir_hash); Loading @@ -96,3 +118,23 @@ int remove_dentry(const unsigned long parent_dir_hash, const string& fname) { return 0; } /** * Checks if a directory has no dentries, i.e., is empty. * @param adafs_path * @return bool */ bool is_dir_empty(const bfs::path& adafs_path) { auto d_path = bfs::path(ADAFS_DATA->dentry_path); // use hash function to path and append it to d_path d_path /= to_string(ADAFS_DATA->hashf(adafs_path.string())); return bfs::is_empty(d_path); } /** * wraps is_dir_empty(bfs::path) */ bool is_dir_empty(const string& adafs_path) { return is_dir_empty(bfs::path(adafs_path)); } No newline at end of file fs/src/adafs_ops/dentry_ops.h +7 −1 Original line number Diff line number Diff line Loading @@ -7,7 +7,9 @@ #include "../main.h" bool init_dentry(const unsigned long& hash); bool init_dentry_dir(const unsigned long& hash); bool destroy_dentry_dir(const unsigned long& hash); bool verify_dentry(const bfs::path& path); Loading @@ -17,4 +19,8 @@ int create_dentry(const unsigned long parent_dir_hash, const std::string& fname) int remove_dentry(const unsigned long parent_dir_hash, const std::string& fname); bool is_dir_empty(const bfs::path& adafs_path); bool is_dir_empty(const std::string& adafs_path); #endif //FS_DENTRY_OPS_H fs/src/fuse_ops/directory.cpp +21 −5 Original line number Diff line number Diff line Loading @@ -115,24 +115,40 @@ int adafs_mkdir(const char* p, mode_t mode) { // XXX check permissions (omittable) // XXX create directory entry for parent directory (can fail) // create directory entry for parent directory (can fail) create_dentry(ADAFS_DATA->hashf(path.parent_path().string()), path.filename().string()); // XXX create metadata of new file // create metadata of new file // mode is used here to init metadata auto md = make_unique<Metadata>(S_IFDIR | mode); md->size(4096); // XXX just visual. size computation of directory should be done properly at some point write_all_metadata(*md, ADAFS_DATA->hashf(path.string())); // Init structure to hold dentries of new directory init_dentry(ADAFS_DATA->hashf(path.string())); init_dentry_dir(ADAFS_DATA->hashf(path.string())); return 0; } /** Remove a directory */ /** Remove a directory. Has to be empty */ // XXX errorhandling err doesnt really work with fuse... int adafs_rmdir(const char* p) { ADAFS_DATA->logger->debug("##### FUSE FUNC ###### adafs_rmdir() enter: name '{}'", p); // XXX to be implemented for rmdir auto path = bfs::path(p); // check that directory is empty if (!is_dir_empty(path)) return -ENOTEMPTY; // remove dentry XXX duplicate code in adafs_unlink() auto err = remove_dentry(ADAFS_DATA->hashf(path.parent_path().string()), path.filename().string()); if (err) return err; // remove dentry directory destroy_dentry_dir(ADAFS_DATA->hashf(path.string())); // remove directory inode err = remove_metadata(ADAFS_DATA->hashf(path.string())); if (err) return err; return 0; } No newline at end of file fs/src/fuse_ops/file.cpp +6 −6 Original line number Diff line number Diff line Loading @@ -58,10 +58,10 @@ int adafs_mknod(const char* p, mode_t mode, dev_t dev) { // XXX check permissions (omittable) // XXX create directory entry (can fail) // create directory entry (can fail) create_dentry(ADAFS_DATA->hashf(path.parent_path().string()), path.filename().string()); // XXX create metadata of new file // create metadata of new file // mode is used here to init metadata auto md = make_unique<Metadata>(S_IFREG | mode); write_all_metadata(*md, ADAFS_DATA->hashf(path.string())); Loading Loading @@ -107,7 +107,7 @@ int adafs_open(const char* p, struct fuse_file_info* fi) { } /** Remove a file */ // XXX Errorhandling // XXX Errorhandling err doesnt really work with fuse... int adafs_unlink(const char* p) { ADAFS_DATA->logger->debug("##### FUSE FUNC ###### adafs_unlink() enter: name '{}'", p); auto path = bfs::path(p); Loading @@ -118,11 +118,11 @@ int adafs_unlink(const char* p) { // adafs_access was called first by the VFS. Thus, path exists and access is ok (not guaranteed though!). auto err = remove_dentry(ADAFS_DATA->hashf(path.parent_path().string()), path.filename().string()); if (!err) return err; if (err) return err; // XXX remove inode // remove inode err = remove_metadata(ADAFS_DATA->hashf(path.string())); if (!err) return err; if (err) return err; // XXX delete unused data blocks (asynchronously) Loading fs/src/main.cpp +1 −1 Original line number Diff line number Diff line Loading @@ -49,7 +49,7 @@ void* adafs_init(struct fuse_conn_info* conn, struct fuse_config* cfg) { ADAFS_DATA->logger->debug("Writing / metadata to disk..."s); write_all_metadata(*md, ADAFS_DATA->hashf("/"s)); ADAFS_DATA->logger->debug("Initializing dentry for /"s); init_dentry(ADAFS_DATA->hashf("/"s)); init_dentry_dir(ADAFS_DATA->hashf("/"s)); ADAFS_DATA->logger->debug("Creating Metadata object"s); } #ifdef LOG_DEBUG Loading Loading
fs/src/adafs_ops/dentry_ops.cpp +44 −2 Original line number Diff line number Diff line Loading @@ -7,11 +7,11 @@ using namespace std; /** * Called when a directory is created to init the corresponding dentry dir. * Initializes the dentry directory to hold future dentries * @param hash * @return */ bool init_dentry(const unsigned long& hash) { bool init_dentry_dir(const unsigned long& hash) { auto d_path = bfs::path(ADAFS_DATA->dentry_path); d_path /= to_string(hash); bfs::create_directories(d_path); Loading @@ -19,6 +19,21 @@ bool init_dentry(const unsigned long& hash) { return bfs::exists(d_path); } /** * Destroys the dentry directory * @param hash * @return true if successfully deleted */ bool destroy_dentry_dir(const unsigned long& hash) { auto d_path = bfs::path(ADAFS_DATA->dentry_path); d_path /= to_string(hash); // remove dentry dir bfs::remove_all(d_path); return !bfs::exists(d_path); } /** * Check if the file name can be found in the directory entries of parent_dir_hash * @param parent_dir_hash Loading Loading @@ -80,6 +95,13 @@ int create_dentry(const unsigned long parent_dir_hash, const string& fname) { return 0; } /** * Removes a dentry from the parent directory * @param parent_dir_hash * @param fname * @return */ // XXX errorhandling int remove_dentry(const unsigned long parent_dir_hash, const string& fname) { auto f_path = bfs::path(ADAFS_DATA->dentry_path); f_path /= to_string(parent_dir_hash); Loading @@ -96,3 +118,23 @@ int remove_dentry(const unsigned long parent_dir_hash, const string& fname) { return 0; } /** * Checks if a directory has no dentries, i.e., is empty. * @param adafs_path * @return bool */ bool is_dir_empty(const bfs::path& adafs_path) { auto d_path = bfs::path(ADAFS_DATA->dentry_path); // use hash function to path and append it to d_path d_path /= to_string(ADAFS_DATA->hashf(adafs_path.string())); return bfs::is_empty(d_path); } /** * wraps is_dir_empty(bfs::path) */ bool is_dir_empty(const string& adafs_path) { return is_dir_empty(bfs::path(adafs_path)); } No newline at end of file
fs/src/adafs_ops/dentry_ops.h +7 −1 Original line number Diff line number Diff line Loading @@ -7,7 +7,9 @@ #include "../main.h" bool init_dentry(const unsigned long& hash); bool init_dentry_dir(const unsigned long& hash); bool destroy_dentry_dir(const unsigned long& hash); bool verify_dentry(const bfs::path& path); Loading @@ -17,4 +19,8 @@ int create_dentry(const unsigned long parent_dir_hash, const std::string& fname) int remove_dentry(const unsigned long parent_dir_hash, const std::string& fname); bool is_dir_empty(const bfs::path& adafs_path); bool is_dir_empty(const std::string& adafs_path); #endif //FS_DENTRY_OPS_H
fs/src/fuse_ops/directory.cpp +21 −5 Original line number Diff line number Diff line Loading @@ -115,24 +115,40 @@ int adafs_mkdir(const char* p, mode_t mode) { // XXX check permissions (omittable) // XXX create directory entry for parent directory (can fail) // create directory entry for parent directory (can fail) create_dentry(ADAFS_DATA->hashf(path.parent_path().string()), path.filename().string()); // XXX create metadata of new file // create metadata of new file // mode is used here to init metadata auto md = make_unique<Metadata>(S_IFDIR | mode); md->size(4096); // XXX just visual. size computation of directory should be done properly at some point write_all_metadata(*md, ADAFS_DATA->hashf(path.string())); // Init structure to hold dentries of new directory init_dentry(ADAFS_DATA->hashf(path.string())); init_dentry_dir(ADAFS_DATA->hashf(path.string())); return 0; } /** Remove a directory */ /** Remove a directory. Has to be empty */ // XXX errorhandling err doesnt really work with fuse... int adafs_rmdir(const char* p) { ADAFS_DATA->logger->debug("##### FUSE FUNC ###### adafs_rmdir() enter: name '{}'", p); // XXX to be implemented for rmdir auto path = bfs::path(p); // check that directory is empty if (!is_dir_empty(path)) return -ENOTEMPTY; // remove dentry XXX duplicate code in adafs_unlink() auto err = remove_dentry(ADAFS_DATA->hashf(path.parent_path().string()), path.filename().string()); if (err) return err; // remove dentry directory destroy_dentry_dir(ADAFS_DATA->hashf(path.string())); // remove directory inode err = remove_metadata(ADAFS_DATA->hashf(path.string())); if (err) return err; return 0; } No newline at end of file
fs/src/fuse_ops/file.cpp +6 −6 Original line number Diff line number Diff line Loading @@ -58,10 +58,10 @@ int adafs_mknod(const char* p, mode_t mode, dev_t dev) { // XXX check permissions (omittable) // XXX create directory entry (can fail) // create directory entry (can fail) create_dentry(ADAFS_DATA->hashf(path.parent_path().string()), path.filename().string()); // XXX create metadata of new file // create metadata of new file // mode is used here to init metadata auto md = make_unique<Metadata>(S_IFREG | mode); write_all_metadata(*md, ADAFS_DATA->hashf(path.string())); Loading Loading @@ -107,7 +107,7 @@ int adafs_open(const char* p, struct fuse_file_info* fi) { } /** Remove a file */ // XXX Errorhandling // XXX Errorhandling err doesnt really work with fuse... int adafs_unlink(const char* p) { ADAFS_DATA->logger->debug("##### FUSE FUNC ###### adafs_unlink() enter: name '{}'", p); auto path = bfs::path(p); Loading @@ -118,11 +118,11 @@ int adafs_unlink(const char* p) { // adafs_access was called first by the VFS. Thus, path exists and access is ok (not guaranteed though!). auto err = remove_dentry(ADAFS_DATA->hashf(path.parent_path().string()), path.filename().string()); if (!err) return err; if (err) return err; // XXX remove inode // remove inode err = remove_metadata(ADAFS_DATA->hashf(path.string())); if (!err) return err; if (err) return err; // XXX delete unused data blocks (asynchronously) Loading
fs/src/main.cpp +1 −1 Original line number Diff line number Diff line Loading @@ -49,7 +49,7 @@ void* adafs_init(struct fuse_conn_info* conn, struct fuse_config* cfg) { ADAFS_DATA->logger->debug("Writing / metadata to disk..."s); write_all_metadata(*md, ADAFS_DATA->hashf("/"s)); ADAFS_DATA->logger->debug("Initializing dentry for /"s); init_dentry(ADAFS_DATA->hashf("/"s)); init_dentry_dir(ADAFS_DATA->hashf("/"s)); ADAFS_DATA->logger->debug("Creating Metadata object"s); } #ifdef LOG_DEBUG Loading