Line data Source code
1 : /* 2 : Copyright 2018-2022, Barcelona Supercomputing Center (BSC), Spain 3 : Copyright 2015-2022, Johannes Gutenberg Universitaet Mainz, Germany 4 : 5 : This software was partially supported by the 6 : EC H2020 funded project NEXTGenIO (Project ID: 671951, www.nextgenio.eu). 7 : 8 : This software was partially supported by the 9 : ADA-FS project under the SPPEXA project funded by the DFG. 10 : 11 : This file is part of GekkoFS. 12 : 13 : GekkoFS is free software: you can redistribute it and/or modify 14 : it under the terms of the GNU General Public License as published by 15 : the Free Software Foundation, either version 3 of the License, or 16 : (at your option) any later version. 17 : 18 : GekkoFS is distributed in the hope that it will be useful, 19 : but WITHOUT ANY WARRANTY; without even the implied warranty of 20 : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 21 : GNU General Public License for more details. 22 : 23 : You should have received a copy of the GNU General Public License 24 : along with GekkoFS. If not, see <https://www.gnu.org/licenses/>. 25 : 26 : SPDX-License-Identifier: GPL-3.0-or-later 27 : */ 28 : 29 : 30 : #include <cmath> 31 : #include <cstring> 32 : #include <getopt.h> 33 : #include <iostream> 34 : #include <queue> 35 : #include <regex.h> 36 : #include <stdio.h> 37 : #include <string> 38 : #include <sys/stat.h> 39 : #include <sys/types.h> 40 : #include <fcntl.h> 41 : #include <unistd.h> 42 : #include <limits> 43 : #include <cstdint> 44 : #include <client/user_functions.hpp> 45 : 46 : using namespace std; 47 : 48 : void 49 0 : write_file(std::string filename) { 50 : // Open File 51 0 : int fd = gkfs::syscall::gkfs_open(filename, S_IRWXU, O_RDWR | O_CREAT); 52 : 53 0 : cout << "FD open " << fd << endl; 54 : 55 0 : char* bufwrite = (char*) malloc(10); 56 0 : strncpy(bufwrite, "testing", 7); 57 : 58 : 59 0 : int size = gkfs::syscall::gkfs_write(fd, bufwrite, 7); 60 : 61 0 : cout << "Writting size " << size << endl; 62 : 63 0 : free(bufwrite); 64 0 : gkfs::syscall::gkfs_close(fd); 65 0 : } 66 : 67 : 68 : void 69 0 : read_file(std::string filename) { 70 0 : int fdread = gkfs::syscall::gkfs_open(filename, S_IRWXU, O_RDONLY); 71 0 : if(fdread == -1) 72 : return; 73 0 : char* bufread = (char*) malloc(10); 74 0 : int sizeread = gkfs::syscall::gkfs_read(fdread, bufread, 7); 75 : 76 0 : cout << "Reading Size: " << sizeread << " Content: " << bufread << endl; 77 : 78 0 : free(bufread); 79 0 : gkfs::syscall::gkfs_close(fdread); 80 : } 81 : 82 : int 83 0 : main(int argc, char** argv) { 84 0 : cout << "GekkoFS Client library test" << endl; 85 : 86 0 : auto res = gkfs_init(); 87 : 88 0 : cout << "Init result " << res << endl; 89 : 90 0 : write_file("/test.tmp"); 91 : 92 0 : read_file("/test.tmp"); 93 : 94 : 95 0 : write_file("/secondfile.tmp"); 96 : 97 0 : auto f_list = gkfs::syscall::gkfs_get_file_list("/"); 98 : 99 0 : for(auto f : f_list) { 100 0 : cout << "File: " << f << endl; 101 0 : struct stat buf; 102 0 : memset(&buf, 0, sizeof(struct stat)); 103 : 104 0 : gkfs::syscall::gkfs_stat("/" + f, &buf, true); 105 : 106 0 : cout << "Size: " << buf.st_size << " Mode: " << buf.st_mode << endl; 107 0 : cout << "Atime: " << buf.st_atime << " Mtime: " << buf.st_mtime 108 0 : << " Ctime: " << buf.st_ctime << endl 109 0 : << " ****** " << endl; 110 : } 111 : 112 0 : res = gkfs_end(); 113 : 114 0 : cout << "End result " << res << endl; 115 0 : }