Commit 59b5ea2a authored by Marc Vef's avatar Marc Vef
Browse files

Code maintenance: Reformatting code, removed dead code, rearranged imports

Reformatted code w.r.t. unifying code styles as of the official
CPPCoreGuidelines by Stroustrup and Sutter
parent 053cd9a5
Loading
Loading
Loading
Loading
Loading
+48 −18
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@


int hook_openat(int dirfd, const char* cpath, int flags, mode_t mode);

int hook_close(int fd);

int hook_stat(const char* path, struct stat* buf);
@@ -28,36 +29,65 @@ int hook_lstat(const char* path, struct stat* buf);
int hook_fstat(unsigned int fd, struct stat* buf);

int hook_fstatat(int dirfd, const char* cpath, struct stat* buf, int flags);

int hook_read(unsigned int fd, void* buf, size_t count);

int hook_pread(unsigned int fd, char* buf, size_t count, loff_t pos);

int hook_write(unsigned int fd, const char* buf, size_t count);

int hook_pwrite(unsigned int fd, const char* buf, size_t count, loff_t pos);

int hook_writev(unsigned long fd, const struct iovec* iov, unsigned long iovcnt);

int hook_pwritev(unsigned long fd, const struct iovec* iov, unsigned long iovcnt,
                 unsigned long pos_l, unsigned long pos_h);

int hook_unlinkat(int dirfd, const char* cpath, int flags);

int hook_symlinkat(const char* oldname, int newdfd, const char* newname);

int hook_access(const char* path, int mask);

int hook_faccessat(int dirfd, const char* cpath, int mode);

off_t hook_lseek(unsigned int fd, off_t offset, unsigned int whence);

int hook_truncate(const char* path, long length);

int hook_ftruncate(unsigned int fd, unsigned long length);

int hook_dup(unsigned int fd);

int hook_dup2(unsigned int oldfd, unsigned int newfd);

int hook_dup3(unsigned int oldfd, unsigned int newfd, int flags);

int hook_getdents(unsigned int fd, struct linux_dirent* dirp, unsigned int count);

int hook_getdents64(unsigned int fd, struct linux_dirent64* dirp, unsigned int count);

int hook_mkdirat(int dirfd, const char* cpath, mode_t mode);

int hook_fchmodat(int dirfd, const char* path, mode_t mode);

int hook_fchmod(unsigned int dirfd, mode_t mode);

int hook_chdir(const char* path);

int hook_fchdir(unsigned int fd);

int hook_getcwd(char* buf, unsigned long size);

int hook_readlinkat(int dirfd, const char* cpath, char* buf, int bufsiz);

int hook_fcntl(unsigned int fd, unsigned int cmd, unsigned long arg);

int hook_renameat(int olddfd, const char* oldname, int newdfd, const char* newname,
                  unsigned int flags);

int hook_statfs(const char* path, struct statfs* buf);

int hook_fstatfs(unsigned int fd, struct statfs* buf);


+0 −80
Original line number Diff line number Diff line
/*
  Copyright 2018-2019, Barcelona Supercomputing Center (BSC), Spain
  Copyright 2015-2019, 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.

  SPDX-License-Identifier: MIT
*/

#ifndef GEKKOFS_INTCP_FUNCTIONS_HPP
#define GEKKOFS_INTCP_FUNCTIONS_HPP

#include <dirent.h>

extern "C" {

# define weak_alias(name, aliasname) \
  extern __typeof (name) aliasname __attribute__ ((weak, alias (#name)));

# define strong_alias(name, aliasname) \
  extern __typeof (name) aliasname __attribute__ ((alias (#name)));

/**
 * In the glibc headers the following two functions (readdir & opendir)
 * marks the @dirp parameter with a non-null attribute.
 * If we try to implement them directly instead of the weak aliased function,
 * the compiler will assume  that the parameter is actually null and
 * will optimized expression like `(dirp == nullptr)`.
*/

struct dirent* intcp_readdir(DIR* dirp);
weak_alias(intcp_readdir, readdir)

int intcp_dirfd(DIR* dirp);
weak_alias(intcp_dirfd, dirfd)

int intcp_closedir(DIR* dirp);
weak_alias(intcp_closedir, closedir)

size_t intcp_fread(void *ptr, size_t size, size_t nmemb, FILE *stream);
strong_alias(intcp_fread, fread)
strong_alias(intcp_fread, fread_unlocked)
size_t intcp_fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream);
strong_alias(intcp_fwrite, fwrite)
strong_alias(intcp_fwrite, fwrite_unlocked)

int intcp_open(const char* path, int flags, ...);
strong_alias(intcp_open, open)
strong_alias(intcp_open, __open_2)
int intcp_open64(const char* path, int flags, ...);
strong_alias(intcp_open64, open64)
strong_alias(intcp_open64, __open64_2)
int intcp_openat(int dirfd, const char *cpath, int flags, ...);
strong_alias(intcp_openat, openat)
strong_alias(intcp_openat, __openat_2)
int intcp_openat64(int dirfd, const char *path, int flags, ...);
strong_alias(intcp_openat64, openat64)
strong_alias(intcp_openat64, __openat64_2)
int intcp_symlink(const char* oldname, const char* newname) noexcept;
strong_alias(intcp_symlink, symlink)
strong_alias(intcp_symlink, __symlink)
int intcp_symlinkat(const char* oldname, int newfd, const char* newname) noexcept;
strong_alias(intcp_symlinkat, symlinkat)
ssize_t intcp_readlink(const char * cpath, char * buf, size_t bufsize) noexcept;
strong_alias(intcp_readlink, readlink)
ssize_t intcp_readlinkat(int dirfd, const char * cpath, char * buf, size_t bufsize) noexcept;
strong_alias(intcp_readlinkat, readlinkat)

int intcp_statvfs(const char *path, struct statvfs *buf) noexcept;
strong_alias(intcp_statvfs, statvfs)
int intcp_fstatvfs(int fd, struct statvfs *buf) noexcept;
strong_alias(intcp_fstatvfs, fstatvfs)

#endif // GEKKOFS_INTCP_FUNCTIONS_HPP

} // extern C
+3 −1
Original line number Diff line number Diff line
@@ -27,7 +27,9 @@ hook_guard_wrapper(long syscall_number,
                   long* syscall_return_value);

void start_self_interception();

void start_interception();

void stop_interception();

#endif
+20 −15
Original line number Diff line number Diff line
@@ -28,8 +28,10 @@ class DirEntry {
    std::string name_;
    FileType type_;
public:
        DirEntry(const std::string& name, const FileType type);
    DirEntry(const std::string& name, FileType type);

    const std::string& name();

    FileType type();
};

@@ -39,9 +41,12 @@ class OpenDir: public OpenFile {


public:
        OpenDir(const std::string& path);
    explicit OpenDir(const std::string& path);

    void add(const std::string& name, const FileType& type);

    const DirEntry& getdent(unsigned int pos);

    size_t size();
};

+2 −1
Original line number Diff line number Diff line
@@ -54,7 +54,7 @@ public:

    OpenFile(const std::string& path, int flags, FileType type = FileType::regular);

    ~OpenFile();
    ~OpenFile() = default;

    // getter/setter
    std::string path() const;
@@ -111,6 +111,7 @@ public:
    int dup2(int oldfd, int newfd);

    int generate_fd_idx();

    int get_fd_idx();
};

Loading