Verified Commit 751bceaa authored by Ramon Nou's avatar Ramon Nou Committed by Marc Vef
Browse files

Add file_list function, remove and expand gkfs_lib example

parent 649df72d
Loading
Loading
Loading
Loading
+18 −0
Original line number Diff line number Diff line
@@ -91,6 +91,24 @@ main(int argc, char** argv) {

    read_file("/test.tmp");


    write_file("/secondfile.tmp");

    auto f_list = gkfs::syscall::gkfs_get_file_list("/");

    for(auto f : f_list) {
        cout << "File: " << f << endl;
        struct stat buf;
        memset(&buf, 0, sizeof(struct stat));

        gkfs::syscall::gkfs_stat("/" + f, &buf, true);

        cout << "Size: " << buf.st_size << " Mode: " << buf.st_mode << endl;
        cout << "Atime: " << buf.st_atime << " Mtime: " << buf.st_mtime
             << " Ctime: " << buf.st_ctime << endl
             << " ****** " << endl;
    }

    res = gkfs_end();

    cout << "End result " << res << endl;
+3 −0
Original line number Diff line number Diff line
@@ -152,6 +152,9 @@ gkfs_rmdir(const std::string& path);
int
gkfs_close(unsigned int fd);

std::vector<std::string>
gkfs_get_file_list(const std::string& path);

#ifdef HAS_RENAME
int
gkfs_rename(const std::string& old_path, const std::string& new_path);
+5 −0
Original line number Diff line number Diff line
@@ -68,6 +68,11 @@ gkfs_pread_ws(int fd, void* buf, size_t count, off64_t offset);
int
gkfs_stat(const std::string& path, struct stat* buf, bool follow_links = true);

int
gkfs_remove(const std::string& path);

std::vector<std::string>
gkfs_get_file_list(const std::string& path);
} // namespace gkfs::syscall


+22 −0
Original line number Diff line number Diff line
@@ -1504,6 +1504,28 @@ gkfs_readlink(const std::string& path, char* buf, int bufsize) {
#endif
#endif


std::vector<std::string>
gkfs_get_file_list(const std::string& path) {
    auto ret = gkfs::rpc::forward_get_dirents(path);
    auto err = ret.first;
    if(err) {
        errno = err;
        return {};
    }

    auto open_dir = ret.second;

    std::vector<std::string> file_list;
    unsigned int pos = 0;

    while(pos < open_dir->size()) {
        auto de = open_dir->getdent(pos++);
        file_list.push_back(de.name());
    }
    return file_list;
}

} // namespace gkfs::syscall