Verified Commit 965614f4 authored by Ramon Nou's avatar Ramon Nou Committed by Marc Vef
Browse files

Create an user_functions.hpp

parent 395e9329
Loading
Loading
Loading
Loading
+11 −18
Original line number Diff line number Diff line
@@ -41,35 +41,26 @@
#include <unistd.h>
#include <limits>
#include <cstdint>
#include <client/gkfs_functions.hpp>
#include <client/user_functions.hpp>

using namespace std;

/* Function exported from GekkoFS LD_PRELOAD, code needs to be compiled with
 * -fPIC */
extern "C" int
gkfs_init() __attribute__((weak));

extern "C" int
gkfs_end() __attribute__((weak));

void
init_preload(){};
void
destroy_preload(){};

void
write_file(std::string filename) {
    // Open File
    int fd = gkfs::syscall::gkfs_open(filename, S_IRWXU, O_RDWR | O_CREAT);

    cout << "FD open  " << fd << endl;
    char* buf = "testing";

    int size = gkfs::syscall::gkfs_write(fd, buf, 7);
    char* bufwrite = (char*) malloc(10);
    strncpy(bufwrite, "testing", 7);


    cout << "FD size" << size << endl;
    int size = gkfs::syscall::gkfs_write(fd, bufwrite, 7);

    cout << "Writting size " << size << endl;

    free(bufwrite);
    gkfs::syscall::gkfs_close(fd);
}

@@ -82,10 +73,12 @@ read_file(std::string filename) {
    char* bufread = (char*) malloc(10);
    int sizeread = gkfs::syscall::gkfs_read(fdread, bufread, 7);

    cout << "Reading : " << sizeread << " --> " << bufread << endl;
    cout << "Reading Size: " << sizeread << " Content: " << bufread << endl;

    free(bufread);
    gkfs::syscall::gkfs_close(fdread);
}

int
main(int argc, char** argv) {
    cout << "GekkoFS Client library test" << endl;
+1 −0
Original line number Diff line number Diff line
@@ -79,4 +79,5 @@ target_sources(
         syscalls/syscall.hpp
         syscalls/detail/syscall_info.h
         void_syscall_intercept.hpp
         user_functions.hpp
)
+1 −0
Original line number Diff line number Diff line
@@ -163,4 +163,5 @@ gkfs_rename(const std::string& old_path, const std::string& new_path);
extern "C" int
gkfs_getsingleserverdir(const char* path, struct dirent_extended* dirp,
                        unsigned int count, int server);

#endif // GEKKOFS_GKFS_FUNCTIONS_HPP
+2 −6
Original line number Diff line number Diff line
@@ -41,16 +41,12 @@ void
init_ld_env_if_needed();
} // namespace gkfs::preload

#ifndef BYPASS_SYSCALL
void
init_preload() __attribute__((constructor));

void
destroy_preload() __attribute__((destructor));

extern "C" int
gkfs_init();

extern "C" int
gkfs_end();
#endif

#endif // IOINTERCEPT_PRELOAD_HPP
+67 −0
Original line number Diff line number Diff line
/*
  Copyright 2018-2022, Barcelona Supercomputing Center (BSC), Spain
  Copyright 2015-2022, Johannes Gutenberg Universitaet Mainz, Germany

  This software was partially supported by the
  EC H2020 funded project NEXTGenIO (Project ID: 671951, www.nextgenio.eu).

  This software was partially supported by the
  ADA-FS project under the SPPEXA project funded by the DFG.

  This file is part of GekkoFS' POSIX interface.

  GekkoFS' POSIX interface is free software: you can redistribute it and/or
  modify it under the terms of the GNU Lesser General Public License as
  published by the Free Software Foundation, either version 3 of the License,
  or (at your option) any later version.

  GekkoFS' POSIX interface is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU Lesser General Public License for more details.

  You should have received a copy of the GNU Lesser General Public License
  along with GekkoFS' POSIX interface.  If not, see
  <https://www.gnu.org/licenses/>.

  SPDX-License-Identifier: LGPL-3.0-or-later
*/

#ifndef GEKKOFS_USER_FUNCTIONS_HPP
#define GEKKOFS_USER_FUNCTIONS_HPP
#include <sys/types.h>
#include <sys/stat.h>
#include <string>
#include <cstdint>

namespace gkfs::syscall {

int
gkfs_open(const std::string& path, mode_t mode, int flags);

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


ssize_t
gkfs_write(int fd, const void* buf, size_t count);


ssize_t
gkfs_read(int fd, void* buf, size_t count);


int
gkfs_close(unsigned int fd);


} // namespace gkfs::syscall


extern "C" int
gkfs_init();

extern "C" int
gkfs_end();

#endif // GEKKOFS_USER_FUNCTIONS_HPP
Loading