Commit b3eee164 authored by Ramon Nou's avatar Ramon Nou
Browse files

fcntl wip 2

parent 3c36c1b1
Loading
Loading
Loading
Loading
+37 −26
Original line number Diff line number Diff line
@@ -551,8 +551,10 @@ is_gkfs_fd(int fd) {

#define GKFS_OPERATION(name, ...)                                              \
    if(CTX->interception_enabled() && is_gkfs_fd(fd)) {                        \
        DEBUG_INFO("[GKFS] {}", fd);                                           \
        return gkfs::syscall::gkfs_##name(__VA_ARGS__);                        \
                                                                               \
        auto res = gkfs::syscall::gkfs_##name(__VA_ARGS__);                    \
        DEBUG_INFO("[GKFS] {} -> res {}", fd, res);                            \
        return res;                                                            \
}

#define GKFS_PATH_OPERATION(name, dirfd, path, ...)                            \
@@ -1273,6 +1275,19 @@ int
fcntl(int fd, int cmd, ...) // TODO
{
    initializeGekko();
    if(!real_fcntl) {
        real_fcntl = reinterpret_cast<int (*)(int fd, int cmd, ...)>(
                dlsym(((void*) -1l), "fcntl"));
        if(!real_fcntl) {
            fprintf(stderr, "dlsym failed for %s: %s\n", "fcntl", dlerror());
            (*__errno_location()) = 38;
            return (int) -1;
        }
    }
    va_list myargs;
    va_start(myargs, cmd);
    auto arg = va_arg(myargs, long);
    va_end(myargs);

    // is from gekkofs?
    if(is_gkfs_fd(fd)) {
@@ -1334,32 +1349,28 @@ fcntl(int fd, int cmd, ...) // TODO

            case F_GETLK:
                DEBUG_INFO("[GKFS] F_GETLK {}", fd);
                return 0;
                auto res = real_fcntl(fd, cmd, arg);
                return res;

            case F_SETLK:
                DEBUG_INFO("[GKFS] F_SETLK {}", fd);
                return 0;
                auto res = real_fcntl(fd, cmd, arg);
                return res;

            default:
            case F_SETLKW: // Used on S3D-IO
                DEBUG_INFO("[GKFS] F_SETLKW {}", fd);
                auto res = real_fcntl(fd, cmd, arg);
                return res;
                
            default:
                DEBUG_INFO("[GKFS] NOTSUPPORTED {}", fd);
                return -ENOTSUP;
        }
    }

   if(!real_fcntl) {
        real_fcntl = reinterpret_cast<int (*)(int fd, int cmd, ...)>(
                dlsym(((void*) -1l), "fcntl"));
        if(!real_fcntl) {
            fprintf(stderr, "dlsym failed for %s: %s\n", "fcntl", dlerror());
            (*__errno_location()) = 38;
            return (int) -1;
        }
    }
    log_arguments("fcntl", fd, cmd);
    va_list myargs;
    va_start(myargs, cmd);
    auto arg = va_arg(myargs, long);
    va_end(myargs);
    
    // log_arguments("fcntl", fd, cmd);
   
    auto res = real_fcntl(fd, cmd, arg);

    return res;