namespace replica { ///////////////////////////////////////////////////////////// static int saga_getattr(const char *path, struct stat *stbuf) { std::ofstream log(saga_opts.log, std::ios::app); log << "getattr" << std::endl; std::string npath(saga_opts.prefix); npath += path; log << "path " << npath << std::endl; if(strcmp("/", path) == 0) { stbuf->st_mode = S_IFDIR | 0755; } else { try { boost::filesystem::path cur_path(path, boost::filesystem::native); std::string parent(cur_path.branch_path().string()); parent = saga_opts.prefix + parent; saga::directory saga_parent(parent); if(saga_parent.is_dir(npath)) //is a directory { saga::directory saga_dir(npath); saga::file saga_file(npath); //use permission model when implemented for gid and uid //Mode stbuf->st_mode = 0755 | S_IFDIR; stbuf->st_nlink = 1; // Number of Hard Links stbuf->st_uid = getuid(); //Set uid of dir current uid stbuf->st_gid = getgid(); //Set gid of dir current gid stbuf->st_size = saga_file.get_size(); //Set dir size stbuf->st_blksize = saga_opts.blocksize; //Set blocksize (predefined) //Set Number of Blocks allocated with magic stbuf->st_blocks = ((stbuf->st_size + stbuf->st_blksize - 1) & ~(stbuf->st_blksize - 1)) >> 9; //SAGA has no way of knowing this, set to current time stbuf->st_atime = time(NULL); stbuf->st_mtime = time(NULL); stbuf->st_ctime = time(NULL); } else //is a file { saga::file saga_file(npath); int acl = 0; //Mode stbuf->st_mode = 0755 | S_IFREG; //acl = saga_file.get_acl(); if(acl & saga::namespace_entry::ACL_Write) { //Set write permissions for everyone stbuf->st_mode |= S_IWUSR; stbuf->st_mode |= S_IWGRP; stbuf->st_mode |= S_IWOTH; } if(acl & saga::namespace_entry::ACL_Read) { //Set read permissions for everyone stbuf->st_mode |= S_IRUSR; stbuf->st_mode |= S_IRGRP; stbuf->st_mode |= S_IROTH; } if(acl & saga::namespace_entry::ACL_Exec) { //Set execute permissions for everyone stbuf->st_mode |= S_IXUSR; stbuf->st_mode |= S_IXGRP; stbuf->st_mode |= S_IXOTH; } /* //User //Assemble user-id string for functions std::string userid = "user-" + getuid(); if(saga_file.permissions_check(userid, saga::Read)) stbuf->st_mode |= S_IRUSR; if(saga_file.permissions_check(userid, saga::Write)) stbuf->st_mode |= S_IWUSR; if(saga_file.permissions_check(userid, saga::Exec)) stbuf->st_mode |= S_IXUSR; //Group //Assemble group-id string for functions std::string groupid = "user-" + getgid(); if(saga_file.permissions_check(groupid, saga::Read)) stbuf->st_mode |= S_IRGRP; if(saga_file.permissions_check(groupid, saga::Write)) stbuf->st_mode |= S_IWGRP; if(saga_file.permissions_check(groupid, saga::Exec)) stbuf->st_mode |= S_IXGRP; //Other if(saga_file.permissions_check("*", saga::Read)) stbuf->st_mode |= S_IROTH; if(saga_file.permissions_check("*", saga::Write)) stbuf->st_mode |= S_IWOTH; if(saga_file.permissions_check("*", saga::Exec)) stbuf->st_mode |= S_IXOTH; */ stbuf->st_nlink = 1; // Number of Hard Links stbuf->st_uid = getuid(); //Set uid of file current uid stbuf->st_gid = getgid(); //Set gid of file current gid stbuf->st_size = saga_file.get_size(); //Set file size stbuf->st_blksize = saga_opts.blocksize; //Set blocksize (predefined) //Set Number of Blocks allocated with magic stbuf->st_blocks = ((stbuf->st_size + stbuf->st_blksize - 1) & ~(stbuf->st_blksize - 1)) >> 9; //SAGA has no way of knowing this, set to current time stbuf->st_atime = time(NULL); stbuf->st_mtime = time(NULL); stbuf->st_ctime = time(NULL); } } catch (const saga::exception &e) { log << e.what() << std::endl; return -ENOENT; } catch (const std::exception &e) { log << e.what() << std::endl; return -ENOENT; } catch (...) { log << "Unknown Error" << std::endl; return -ENOENT; } } return 0; } ///////////////////////////////////////////////////////////// static int saga_readlink(const char *path, char *buf, size_t size) { std::ofstream log(saga_opts.log, std::ios::app); log << "readlink" << std::endl; return 0; } ///////////////////////////////////////////////////////////// static int saga_mknod(const char *path, mode_t mode, dev_t rdev) { std::ofstream log(saga_opts.log, std::ios::app); log << "mknod" << std::endl; int saga_mode = saga::file::Create | saga::file::CreateParents | saga::file::Overwrite; std::string npath(saga_opts.prefix); npath += path; try { if(S_ISREG(mode)) //Is a regular file { // WHAT IS DESIRED EFFECT // saga::file file(npath, saga_mode); } } catch (const saga::exception &e) { log << e.what() << std::endl; } catch (const std::exception &e) { log << e.what() << std::endl; } catch (...) { log << "Unknown Error" << std::endl; } return 0; } ///////////////////////////////////////////////////////////// static int saga_mkdir(const char *path, mode_t mode) { std::ofstream log(saga_opts.log, std::ios::app); log << "mkdir" << std::endl; int saga_mode = saga::namespace_dir::Create | saga::namespace_dir::CreateParents | saga::namespace_dir::Overwrite; try { //Find parent directory call make_dir boost::filesystem::path cur_path(path, boost::filesystem::native); std::string parent(cur_path.branch_path().string()); parent = saga_opts.prefix + parent; saga::logical_directory saga_parent(parent); // WHAT IS DESIRED EFFECT // saga_parent.make_dir(path, saga_mode); } catch (const saga::exception &e) { log << e.what() << std::endl; } catch (const std::exception &e) { log << e.what() << std::endl; } catch (...) { log << "Unknown Error" << std::endl; } return 0; } ///////////////////////////////////////////////////////////// static int saga_rmdir(const char *path) { std::ofstream log(saga_opts.log, std::ios::app); log << "rmdir" << std::endl; try { //Find parent directory call remove boost::filesystem::path cur_path(path, boost::filesystem::native); std::string parent(cur_path.branch_path().string()); parent = saga_opts.prefix + parent; saga::logical_directory saga_parent(parent); // WHAT IS DESIRED EFFECT // saga_parent.remove(path); } catch (const saga::exception &e) { log << e.what() << std::endl; } catch (const std::exception &e) { log << e.what() << std::endl; } catch (...) { log << "Unknown Error" << std::endl; } return 0; } ///////////////////////////////////////////////////////////// static int saga_unlink(const char *path) { std::ofstream log(saga_opts.log, std::ios::app); log << "unlink" << std::endl; log << "path " << std::endl; std::string npath(saga_opts.prefix); npath += path; try { //Find parent directory call remove boost::filesystem::path cur_path(path, boost::filesystem::native); std::string parent(cur_path.branch_path().string()); parent = saga_opts.prefix + parent; saga::logical_directory saga_parent(parent); // WHAT IS DESIRED EFFECT // saga_parent.remove(path); } catch (const saga::exception &e) { log << e.what() << std::endl; } catch (const std::exception &e) { log << e.what() << std::endl; } catch (...) { log << "Unknown Error" << std::endl; } return 0; } ///////////////////////////////////////////////////////////// static int saga_rename(const char *from, const char *to) { std::ofstream log(saga_opts.log, std::ios::app); log << "rename" << std::endl; return 0; } ///////////////////////////////////////////////////////////// static int saga_truncate(const char *path, off_t size) { std::ofstream log(saga_opts.log, std::ios::app); log << "truncate" << std::endl; int saga_mode = saga::file::ReadWrite; std::string npath(saga_opts.prefix); npath += path; try { /* if(size > 0) //Leaving some stuff in file { //Read size bytes from file char buffer[size]; saga::buffer saga_buf(buffer, size); { saga::file file(npath, saga_mode); file.read(size, saga_buf); } //Reopen with Truncate flag to zero out saga::file file(npath, saga_mode | saga::file::Truncate); file.write(size, saga_buf); } else //Just bring it to zero size { saga::file file(npath, saga_mode | saga::file::Truncate); } */ } catch (const saga::exception &e) { log << e.what() << std::endl; } catch (const std::exception &e) { log << e.what() << std::endl; } catch (...) { log << "Unknown Error" << std::endl; } return 0; } ///////////////////////////////////////////////////////////// static int saga_open(const char *path, struct fuse_file_info *fi) { std::ofstream log(saga_opts.log, std::ios::app); log << "open" << std::endl; return 0; } ///////////////////////////////////////////////////////////// static int saga_read(const char *path, char *buf, size_t size, off_t offset, struct fuse_file_info *fi) { std::ofstream log(saga_opts.log, std::ios::app); log << "read" << std::endl; std::string npath(saga_opts.prefix); npath += path; try { /* char *data; data = (char*)malloc(size); saga::buffer saga_buf(data, size); saga::logical_file logical_file(npath); std::vector loc = logical_file.list_locations(); saga::file file(...); file.seek(offset, saga::file::Start); ssize_t readbytes = file.read(size, saga_buf); memcpy(buf, saga_buf.get_data(), readbytes); return readbytes; */ } catch (const saga::exception &e) { log << e.what() << std::endl; } catch (const std::exception &e) { log << e.what() << std::endl; } catch (...) { log << "Unknown Error" << std::endl; } return 0; } ///////////////////////////////////////////////////////////// static int saga_write(const char *path, const char *buf, size_t size, off_t offset, struct fuse_file_info *fi) { std::ofstream log(saga_opts.log, std::ios::app); log << "write" << std::endl; int saga_mode = saga::file::ReadWrite; std::string npath(saga_opts.prefix); npath += path; try { /* saga::buffer saga_buf(const_cast(buf), size); saga::file file(npath, saga_mode); file.seek(offset, saga::file::Start); ssize_t writtenbytes = file.write(size, saga_buf); return writtenbytes; */ } catch (const saga::exception &e) { log << e.what() << std::endl; } catch (const std::exception &e) { log << e.what() << std::endl; } catch (...) { log << "Unknown Error" << std::endl; } return 0; } ///////////////////////////////////////////////////////////// static int saga_utimens(const char *path, const struct timespec ts[2]) { std::ofstream log(saga_opts.log, std::ios::app); log << "utimens" << std::endl; return 0; } ///////////////////////////////////////////////////////////// static int saga_readdir(const char *path, void *buf, fuse_fill_dir_t filler, off_t offset, struct fuse_file_info *fi) { std::ofstream log(saga_opts.log, std::ios::app); log << "readdir" << std::endl; std::string npath(saga_opts.prefix); npath += path; try { saga::logical_directory dir(npath); std::vector entries(dir.list()); std::vector::iterator it; for(it = entries.begin(); it != entries.end(); it++) { filler(buf, (*it).c_str(), NULL, 0); } } catch (const saga::exception &e) { log << e.what() << std::endl; } return 0; } ///////////////////////////////////////////////////////////// } //namespace file