Commit c0c0711f authored by Julius Athenstaedt's avatar Julius Athenstaedt
Browse files

small working set of functions

parent 06d65a49
Loading
Loading
Loading
Loading
+38 −15
Original line number Diff line number Diff line
#include <pybind11/pybind11.h>
#include <pybind11/stl.h>
#include <client/open_file_map.hpp>
#include <common/metadata.hpp>
#include <client/intercept.hpp>
#include <sys/stat.h>
#include <sys/vfs.h>
#include <client/user_functions.hpp>

namespace py = pybind11;
@@ -15,20 +10,48 @@ PYBIND11_MODULE(gkfs_python, m) {
    m.def("gkfs_open", &gkfs::syscall::gkfs_open);
    m.def("gkfs_create", &gkfs::syscall::gkfs_create);
    m.def("gkfs_remove", &gkfs::syscall::gkfs_remove);
    m.def("gkfs_access", &gkfs::syscall::gkfs_access,
          py::arg("path"), py::arg("mask"), py::arg("follow_links") = true);
    m.def("gkfs_access", &gkfs::syscall::gkfs_access, py::arg("path"),
          py::arg("mask"), py::arg("follow_links") = true);

    // Wrap gkfs_stat manually (complex signature)
    m.def("gkfs_stat", [](const std::string& path, bool follow_links, bool bypass_rename) {
    m.def("gkfs_stat",
          [](const std::string& path, bool follow_links, bool bypass_rename) {
              struct stat buf;
        int res = gkfs::syscall::gkfs_stat(path, &buf, follow_links, bypass_rename);
        return std::make_tuple(res, buf);
              int res = gkfs::syscall::gkfs_stat(path, &buf, follow_links,
                                                 bypass_rename);
              // TODO check if syscall was successful
              py::dict stat_result;
              stat_result["st_dev"] = buf.st_dev;
              stat_result["st_ino"] = buf.st_ino;
              stat_result["st_mode"] = buf.st_mode;
              stat_result["st_nlink"] = buf.st_nlink;
              stat_result["st_uid"] = buf.st_uid;
              stat_result["st_gid"] = buf.st_gid;
              stat_result["st_rdev"] = buf.st_rdev;
              stat_result["st_size"] = buf.st_size;
              stat_result["st_blksize"] = buf.st_blksize;
              stat_result["st_blocks"] = buf.st_blocks;
              stat_result["st_atime"] = buf.st_atime;
              stat_result["st_mtime"] = buf.st_mtime;
              stat_result["st_ctime"] = buf.st_ctime;

              return std::make_tuple(res, stat_result);
          });

    // Example vector-returning function
    m.def("gkfs_get_file_list", &gkfs::syscall::gkfs_get_file_list);

    // Example: wrap close
    m.def("gkfs_close", &gkfs::syscall::gkfs_close);
}


    m.def(
            "init",
            []() {
                int result = gkfs_init();
                if(result != 0) {
                    throw std::runtime_error("gkfs_init() failed with code " +
                                             std::to_string(result));
                }
                return result;
            },
            "Initialize GekkoFS");
}