2023-02-26 15:16:18 -05:00
|
|
|
/*
|
2026-02-23 13:22:21 -06:00
|
|
|
ISC License
|
|
|
|
|
|
|
|
|
|
Copyright (c) 2026, Antonio SJ Musumeci <trapexit@spawn.link>
|
2023-02-26 15:16:18 -05:00
|
|
|
|
|
|
|
|
Permission to use, copy, modify, and/or distribute this software for any
|
|
|
|
|
purpose with or without fee is hereby granted, provided that the above
|
|
|
|
|
copyright notice and this permission notice appear in all copies.
|
|
|
|
|
|
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
|
|
|
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
|
|
|
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
|
|
|
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
|
|
|
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
|
|
|
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
|
|
|
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
|
*/
|
|
|
|
|
|
2025-07-25 17:53:48 -05:00
|
|
|
#include "fuse_read.hpp"
|
|
|
|
|
|
2023-02-26 15:16:18 -05:00
|
|
|
#include "errno.hpp"
|
|
|
|
|
#include "fileinfo.hpp"
|
|
|
|
|
#include "fs_pread.hpp"
|
2025-09-26 12:36:56 -04:00
|
|
|
#include "ioprio.hpp"
|
2026-04-28 09:07:27 -05:00
|
|
|
#include "state.hpp"
|
2023-02-26 15:16:18 -05:00
|
|
|
|
|
|
|
|
#include "fuse.h"
|
|
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
|
|
|
2025-07-25 17:53:48 -05:00
|
|
|
static
|
|
|
|
|
int
|
|
|
|
|
_read_direct_io(const int fd_,
|
|
|
|
|
char *buf_,
|
|
|
|
|
const size_t size_,
|
|
|
|
|
const off_t offset_)
|
2023-02-26 15:16:18 -05:00
|
|
|
{
|
2025-07-25 17:53:48 -05:00
|
|
|
int rv;
|
|
|
|
|
|
|
|
|
|
rv = fs::pread(fd_,buf_,size_,offset_);
|
|
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static
|
|
|
|
|
int
|
|
|
|
|
_read_cached(const int fd_,
|
|
|
|
|
char *buf_,
|
|
|
|
|
const size_t size_,
|
|
|
|
|
const off_t offset_)
|
|
|
|
|
{
|
|
|
|
|
int rv;
|
|
|
|
|
|
|
|
|
|
rv = fs::pread(fd_,buf_,size_,offset_);
|
|
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int
|
2025-10-13 00:21:36 -04:00
|
|
|
FUSE::read(const fuse_req_ctx_t *ctx_,
|
|
|
|
|
const fuse_file_info_t *ffi_,
|
2025-07-25 17:53:48 -05:00
|
|
|
char *buf_,
|
|
|
|
|
size_t size_,
|
|
|
|
|
off_t offset_)
|
|
|
|
|
{
|
2025-10-13 00:21:36 -04:00
|
|
|
ioprio::SetFrom iop(ctx_->pid);
|
2026-04-28 09:07:27 -05:00
|
|
|
FileInfo *fi;
|
2025-07-25 17:53:48 -05:00
|
|
|
|
2026-04-28 09:07:27 -05:00
|
|
|
fi = state.get_fi(ctx_,ffi_->fh);
|
FUSE: require valid file/dir handle; drop open_files fallback
Several FUSE ops fell back to looking up a FileInfo via
state.open_files when the kernel-provided fh was zero, returning
-ENOENT if the lookup failed. This path papered over handle-tracking
bugs and added cost on every call. Use the handle directly and
return -EBADF when it is invalid - the kernel should always hand us
a valid fh for an open resource.
Also simplify FileInfo::from_fh / DirInfo::from_fh and their to_fh
helpers: callers now handle the null-pointer case explicitly so the
ASSERT_NOT_NULL checks are redundant.
Covers fallocate, fchmod, fchown, fgetattr, flock, ftruncate,
futimens, read, release, releasedir, write, statx, ioctl (file +
dir), readdir (sequential, concurrent-on-read,
concurrent-on-search), and the passthrough fast paths in
create/open.
2026-04-18 00:53:11 -04:00
|
|
|
if(not fi)
|
|
|
|
|
return -EBADF;
|
|
|
|
|
|
2025-07-25 17:53:48 -05:00
|
|
|
if(fi->direct_io)
|
|
|
|
|
return ::_read_direct_io(fi->fd,buf_,size_,offset_);
|
|
|
|
|
|
|
|
|
|
return ::_read_cached(fi->fd,buf_,size_,offset_);
|
2023-02-26 15:16:18 -05:00
|
|
|
}
|
|
|
|
|
|
2025-07-25 17:53:48 -05:00
|
|
|
int
|
2025-10-13 00:21:36 -04:00
|
|
|
FUSE::read_null(const fuse_req_ctx_t *ctx_,
|
|
|
|
|
const fuse_file_info_t *ffi_,
|
2025-07-25 17:53:48 -05:00
|
|
|
char *buf_,
|
|
|
|
|
size_t size_,
|
|
|
|
|
off_t offset_)
|
2023-02-26 15:16:18 -05:00
|
|
|
{
|
2025-07-25 17:53:48 -05:00
|
|
|
return size_;
|
2023-02-26 15:16:18 -05:00
|
|
|
}
|