static int fuse_operations_mount_ftruncate_size(struct MountsPublicInterface* this_, int fd, off_t length) {
    int ret;
    struct FuseOperationsMount* fs = (struct FuseOperationsMount*)this_;
    const struct OpenFileDescription* ofd = fs->handle_allocator->ofd(fd);
    if (ofd==NULL) {
        SET_ERRNO(ENOENT);
        return -1;
    }
    struct FuseFileOptionalData *fdata = (struct FuseFileOptionalData *)ofd->optional_data;
    struct stat st;

    CHECK_FUNC_ENSURE_EXIST(fs, ftruncate);
    GET_STAT_ENSURE_EXIST(fs, fdata->path, &st);

    if ( S_ISDIR(st.st_mode) ) {
        SET_ERRNO(EISDIR);
        return -1;
    }

    int flags = ofd->flags & O_ACCMODE;
    /*check if file was not opened for writing*/
    if ( flags!=O_WRONLY && flags!=O_RDWR ) {
        ZRT_LOG(L_ERROR, "file open flags=%s not allow truncate",
                STR_FILE_OPEN_FLAGS(flags));
        SET_ERRNO( EINVAL );
        return -1;
    }

    if ( (ret=fs->fuse_operations->ftruncate(fdata->path, length, fdata->finfo )) < 0 ) {
        SET_ERRNO(-ret);
        return -1;
    }

    return ret;
}
Exemple #2
0
int  zrt_zcall_enhanced_open(const char *name, int flags, mode_t mode, int *newfd){
    LOG_SYSCALL_START("name=%s flags=%d mode=%o(octal)", name, flags, mode );

    char* absolute_path;
    char temp_path[PATH_MAX];
    int ret=-1;
    errno=0;
    VALIDATE_SYSCALL_PTR(name);
    
    /*reset mode bits, that is not actual for permissions*/
    mode&=(S_IRWXU|S_IRWXG|S_IRWXO);
    APPLY_UMASK(&mode);

    if ( (absolute_path = zrealpath(name, temp_path)) != NULL ){
	ZRT_LOG(L_SHORT, "absolute_path=%s", absolute_path);
	if ( (ret = s_transparent_mount->open(s_transparent_mount, absolute_path, flags, mode )) >= 0 ){
	    /*get fd by pointer*/
	    *newfd  = ret;
	    ret =0;
	}
    }

    LOG_SHORT_SYSCALL_FINISH( ret, 
			      "*newfd=%d, name=%s, flags=%s, mode=%s", 
			      *newfd, name, 
			      STR_ALLOCA_COPY(STR_FILE_OPEN_FLAGS(flags)),
			      STR_ALLOCA_COPY(STR_STAT_ST_MODE(mode)));
    return ret;
}