Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fuse_session_custom_io: Add a struct size field #930

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion example/hello_ll_uds.c
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ int main(int argc, char *argv[])
if (cfd == -1)
goto err_out3;

if (fuse_session_custom_io(se, &io, cfd) != 0)
if (fuse_session_custom_io(se, &io, sizeof(io), cfd) != 0)
goto err_out3;

/* Block until ctrl+c */
Expand Down
9 changes: 7 additions & 2 deletions include/fuse_lowlevel.h
Original file line number Diff line number Diff line change
Expand Up @@ -2043,15 +2043,20 @@ struct fuse_session *fuse_session_new(struct fuse_args *args,
* @param se session object
* @param io Custom io to use when retrieving/sending requests/responses
* @param fd file descriptor for the session
*
* @param custom_io_size the size of the struct the callers knows about.
* The struct might be extended in higher libfuse versions and in order
* to stay ABI compatible extended fields are zeroed - libuse needs to know
* the size the caller knows about.
* @return 0 on success
* @return -EINVAL if `io`, `io->read` or `ìo->writev` are NULL
* @return -EBADF if `fd` was smaller than 0
* @return -errno if failed to allocate memory to store `io`
*
**/
int fuse_session_custom_io(struct fuse_session *se,
const struct fuse_custom_io *io, int fd);
const struct fuse_custom_io *io,
size_t custom_io_size,
int fd);

/**
* Mount a FUSE file system.
Expand Down
20 changes: 17 additions & 3 deletions lib/fuse_lowlevel.c
Original file line number Diff line number Diff line change
Expand Up @@ -3117,8 +3117,17 @@ struct fuse_session *fuse_session_new(struct fuse_args *args,
}

int fuse_session_custom_io(struct fuse_session *se, const struct fuse_custom_io *io,
int fd)
size_t prog_custom_io_sz, int fd)
{
size_t lib_custom_io_sz = sizeof(*se->io);

if (prog_custom_io_sz > lib_custom_io_sz) {
fuse_log(FUSE_LOG_ERR,
"Provided 'fuse_custom_io_sz' (%zu) is larger than struct (%zu)\n",
prog_custom_io_sz, lib_custom_io_sz);
return -EINVAL;
}

if (fd < 0) {
fuse_log(FUSE_LOG_ERR, "Invalid file descriptor value %d passed to "
"fuse_session_custom_io()\n", fd);
Expand All @@ -3138,15 +3147,20 @@ int fuse_session_custom_io(struct fuse_session *se, const struct fuse_custom_io
return -EINVAL;
}

se->io = malloc(sizeof(struct fuse_custom_io));
se->io = calloc(1, lib_custom_io_sz);
if (se->io == NULL) {
fuse_log(FUSE_LOG_ERR, "Failed to allocate memory for custom io. "
"Error: %s\n", strerror(errno));
return -errno;
}

se->fd = fd;
*se->io = *io;

/* Above the struct was zeroed. For ABI compatibility we memcopy in
* what the caller knows about.
*/
memcpy(se->io, io, prog_custom_io_sz);

return 0;
}

Expand Down
Loading