Unverified Commit 94ace34f authored by Tommaso Tocci's avatar Tommaso Tocci
Browse files

Correctly set file type

Since POSIX.1-2001 the S_IFMT (0170000) bitmask of the file mode must
contain the file type.

At the moment we correctly support
 - [S_IFREG] regular file
 - [S_IFDIR] directory
parent fe7e5ee3
Loading
Loading
Loading
Loading
+7 −1
Original line number Diff line number Diff line
@@ -12,7 +12,7 @@ int adafs_open(const std::string& path, mode_t mode, int flags) {
    // TODO look up if file exists configurable
    if (flags & O_CREAT)
        // no access check required here. If one is using our FS they have the permissions.
        err = rpc_send_mk_node(path, mode);
        err = adafs_mk_node(path, mode | S_IFREG);
    else {
        auto mask = F_OK; // F_OK == 0
#if defined(CHECK_ACCESS_DURING_OPEN)
@@ -41,6 +41,12 @@ int adafs_open(const std::string& path, mode_t mode, int flags) {

int adafs_mk_node(const std::string& path, const mode_t mode) {
    init_ld_env_if_needed();

    //file type must be set
    assert((mode & S_IFMT) != 0);
    //file type must be either regular file or directory
    assert(S_ISREG(mode) || S_ISDIR(mode));

    return rpc_send_mk_node(path, mode);
}

+1 −1
Original line number Diff line number Diff line
@@ -74,7 +74,7 @@ int mkdir(const char* path, mode_t mode) __THROW {
    init_passthrough_if_needed();
    ld_logger->trace("{}() called with path {} with mode {}", __func__, path, mode);
    if (ld_is_aux_loaded() && is_fs_path(path)) {
        return adafs_mk_node(path, mode);
        return adafs_mk_node(path, mode | S_IFDIR);
    }
    return (reinterpret_cast<decltype(&mkdir)>(libc_mkdir))(path, mode);
}