Commit 0ad6100f authored by Ramon Nou's avatar Ramon Nou
Browse files

feat: add fchownat wrapper and syscall coverage test

Expose the fchownat libc wrapper and validate its behavior in the metadata permission syscall coverage tests, including expected unsupported and permission errors.
parent 205333c0
Loading
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -253,6 +253,9 @@ int
chown(const char* path, uid_t owner, gid_t group) throw();
int
fchown(int fd, uid_t owner, gid_t group) throw();
int
fchownat(int dfd, const char* path, uid_t owner, gid_t group,
         int flags) throw();

//------------------------- Process and Descriptor Management
//------------------//
+3 −0
Original line number Diff line number Diff line
@@ -724,6 +724,9 @@ DLSYM_WRAPPER(int, fchown, (int fd, uid_t owner, gid_t group),
              (fd, owner, group), "fchown")
DLSYM_WRAPPER(int, lchown, (const char* path, uid_t owner, gid_t group),
              (path, owner, group), "lchown")
DLSYM_WRAPPER(int, fchownat,
              (int dfd, const char* path, uid_t owner, gid_t group, int flags),
              (dfd, path, owner, group, flags), "fchownat")

// Process and Descriptor Management
DLSYM_WRAPPER(int, dup, (int fd), (fd), "dup")
+14 −1
Original line number Diff line number Diff line
@@ -832,7 +832,7 @@ test_traversal_uncovered(const std::string& base_dir) {
    rmdir(subdir_path.c_str());
}

// Test Metadata/Permissions (chmod, chown, fchown, utimes, futimes)
// Test Metadata/Permissions (chmod, chown, fchown, fchownat, utimes, futimes)
void
test_metadata_perms_uncovered(const std::string& base_dir) {
    std::string filepath = make_path(base_dir, "test_metadata_uncovered.txt");
@@ -895,6 +895,18 @@ test_metadata_perms_uncovered(const std::string& base_dir) {
        ;
    }

    // Test fchownat
    errno = 0;
    if(fchownat(AT_FDCWD, filepath.c_str(), getuid(), getgid(), 0) != 0) {
        if(errno == ENOTSUP || errno == EPERM || errno == ENOENT) {
            ;
        } else {
            perror("fchownat failed unexpectedly");
        }
    } else {
        ;
    }

    // Test futimes
    errno = 0;
    if(futimes(fd, times) != 0) {
@@ -968,6 +980,7 @@ test_misc_file_ops_uncovered(const std::string& base_dir) {
    } else {
        flock(fd, LOCK_UN); // Release
    }

    close(fd); // Close GekkoFS FD before testing fallbacks