diff --git a/src/dirinfo.hpp b/src/dirinfo.hpp index 972e07c8..2355b4a5 100644 --- a/src/dirinfo.hpp +++ b/src/dirinfo.hpp @@ -27,6 +27,7 @@ class DirInfo : public FH { public: + static u64 to_fh(const DirInfo*); static DirInfo *from_fh(const u64 fh); public: @@ -39,23 +40,23 @@ public: } }; +inline +u64 +DirInfo::to_fh(const DirInfo *di_) +{ + return reinterpret_cast(di_); +} + inline u64 DirInfo::to_fh() const { - ASSERT_NOT_NULL(this); - return reinterpret_cast(this); + return to_fh(this); } inline DirInfo* DirInfo::from_fh(const u64 fh_) { - DirInfo *rv; - - rv = reinterpret_cast(fh_); - - ASSERT_NOT_NULL(rv); - - return rv; + return reinterpret_cast(fh_); } diff --git a/src/fileinfo.hpp b/src/fileinfo.hpp index e905007a..6a2866f7 100644 --- a/src/fileinfo.hpp +++ b/src/fileinfo.hpp @@ -104,7 +104,6 @@ inline u64 FileInfo::to_fh(const FileInfo *fi_) { - ASSERT_NOT_NULL(fi_); return reinterpret_cast(fi_); } @@ -112,19 +111,12 @@ inline u64 FileInfo::to_fh() const { - ASSERT_NOT_NULL(this); - return reinterpret_cast(this); + return to_fh(this); } inline FileInfo* FileInfo::from_fh(const u64 fh_) { - FileInfo *rv; - - rv = reinterpret_cast(fh_); - - ASSERT_NOT_NULL(rv); - - return rv; + return reinterpret_cast(fh_); } diff --git a/src/fuse_create.cpp b/src/fuse_create.cpp index a05e6210..40cd0ea8 100644 --- a/src/fuse_create.cpp +++ b/src/fuse_create.cpp @@ -292,6 +292,9 @@ _create(const fuse_req_ctx_t *ctx_, FileInfo *fi = FileInfo::from_fh(ffi_->fh); int backing_id = INVALID_BACKING_ID; + if(not fi) + return -EBADF; + switch(_(cfg.passthrough_io,ffi_->flags)) { case _(PassthroughIO::ENUM::RO,O_RDONLY): diff --git a/src/fuse_fallocate.cpp b/src/fuse_fallocate.cpp index abd4e90e..be11d40f 100644 --- a/src/fuse_fallocate.cpp +++ b/src/fuse_fallocate.cpp @@ -48,22 +48,10 @@ FUSE::fallocate(const fuse_req_ctx_t *ctx_, off_t offset_, off_t len_) { - u64 fh; + FileInfo *fi = FileInfo::from_fh(fh_); - fh = fh_; - if(fh == 0) - { - state.open_files.cvisit(ctx_->nodeid, - [&](auto &val_) - { - fh = val_.second.fi->to_fh(); - }); - } - - if(fh == 0) - return -ENOENT; - - FileInfo *fi = FileInfo::from_fh(fh); + if(not fi) + return -EBADF; return ::_fallocate(fi->fd, mode_, diff --git a/src/fuse_fchmod.cpp b/src/fuse_fchmod.cpp index cc5b0c5b..f70996d0 100644 --- a/src/fuse_fchmod.cpp +++ b/src/fuse_fchmod.cpp @@ -43,22 +43,10 @@ FUSE::fchmod(const fuse_req_ctx_t *ctx_, cu64 fh_, const mode_t mode_) { - u64 fh; + FileInfo *fi = FileInfo::from_fh(fh_); - fh = fh_; - if(fh == 0) - { - state.open_files.cvisit(ctx_->nodeid, - [&](auto &val_) - { - fh = val_.second.fi->to_fh(); - }); - } - - if(fh == 0) - return -ENOENT; - - FileInfo *fi = FileInfo::from_fh(fh); + if(not fi) + return -EBADF; return ::_fchmod(fi->fd,mode_); } diff --git a/src/fuse_fchown.cpp b/src/fuse_fchown.cpp index 91b799c9..e30ec9e0 100644 --- a/src/fuse_fchown.cpp +++ b/src/fuse_fchown.cpp @@ -47,22 +47,10 @@ FUSE::fchown(const fuse_req_ctx_t *ctx_, const uid_t uid_, const gid_t gid_) { - u64 fh; + FileInfo *fi = FileInfo::from_fh(fh_); - fh = fh_; - if(fh == 0) - { - state.open_files.cvisit(ctx_->nodeid, - [&](auto &val_) - { - fh = val_.second.fi->to_fh(); - }); - } - - if(fh == 0) - return -ENOENT; - - FileInfo *fi = FileInfo::from_fh(fh); + if(not fi) + return -EBADF; return ::_fchown(fi->fd,uid_,gid_); } diff --git a/src/fuse_fgetattr.cpp b/src/fuse_fgetattr.cpp index 94f20b11..4629bc0f 100644 --- a/src/fuse_fgetattr.cpp +++ b/src/fuse_fgetattr.cpp @@ -54,26 +54,14 @@ FUSE::fgetattr(const fuse_req_ctx_t *ctx_, fuse_timeouts_t *timeout_) { int rv; - u64 fh; + FileInfo *fi = FileInfo::from_fh(fh_); - fh = fh_; - if(fh == 0) - { - state.open_files.cvisit(ctx_->nodeid, - [&](const auto &val_) - { - fh = val_.second.fi->to_fh(); - }); - } - - if(fh == 0) + if(not fi) { timeout_->entry = cfg.cache_negative_entry; - return -ENOENT; + return -EBADF; } - FileInfo *fi = FileInfo::from_fh(fh); - rv = ::_fgetattr(fi,st_); timeout_->entry = ((rv >= 0) ? diff --git a/src/fuse_flock.cpp b/src/fuse_flock.cpp index 47b22f78..c2fde1e3 100644 --- a/src/fuse_flock.cpp +++ b/src/fuse_flock.cpp @@ -43,22 +43,10 @@ FUSE::flock(const fuse_req_ctx_t *ctx_, const fuse_file_info_t *ffi_, int op_) { - u64 fh; + FileInfo* fi = FileInfo::from_fh(ffi_->fh); - fh = ffi_->fh; - if(fh == 0) - { - state.open_files.cvisit(ctx_->nodeid, - [&](const auto &val_) - { - fh = val_.second.fi->to_fh(); - }); - } - - if(fh == 0) - return -ENOENT; - - FileInfo* fi = FileInfo::from_fh(fh); + if(not fi) + return -EBADF; return ::_flock(fi->fd,op_); } diff --git a/src/fuse_ftruncate.cpp b/src/fuse_ftruncate.cpp index cf967ca4..99aca0f5 100644 --- a/src/fuse_ftruncate.cpp +++ b/src/fuse_ftruncate.cpp @@ -43,22 +43,10 @@ FUSE::ftruncate(const fuse_req_ctx_t *ctx_, cu64 fh_, off_t size_) { - u64 fh; + FileInfo *fi = FileInfo::from_fh(fh_); - fh = fh_; - if(fh == 0) - { - state.open_files.cvisit(ctx_->nodeid, - [&](auto &val_) - { - fh = val_.second.fi->to_fh(); - }); - } - - if(fh == 0) - return -ENOENT; - - FileInfo *fi = FileInfo::from_fh(fh); + if(not fi) + return -EBADF; return ::_ftruncate(fi->fd,size_); } diff --git a/src/fuse_futimens.cpp b/src/fuse_futimens.cpp index 2b4a2a21..e6b9e012 100644 --- a/src/fuse_futimens.cpp +++ b/src/fuse_futimens.cpp @@ -45,22 +45,10 @@ FUSE::futimens(const fuse_req_ctx_t *ctx_, cu64 fh_, const struct timespec ts_[2]) { - u64 fh; + FileInfo *fi = FileInfo::from_fh(fh_); - fh = fh_; - if(fh == 0) - { - state.open_files.cvisit(ctx_->nodeid, - [&](const auto &val_) - { - fh = val_.second.fi->to_fh(); - }); - } - - if(fh == 0) - return -ENOENT; - - FileInfo *fi = FileInfo::from_fh(fh); + if(not fi) + return -EBADF; return ::_futimens(fi->fd,ts_); } diff --git a/src/fuse_ioctl.cpp b/src/fuse_ioctl.cpp index 51ce85a6..cdf1dbbf 100644 --- a/src/fuse_ioctl.cpp +++ b/src/fuse_ioctl.cpp @@ -115,6 +115,9 @@ _ioctl_file(const fuse_req_ctx_t *ctx_, { FileInfo *fi = FileInfo::from_fh(ffi_->fh); + if(not fi) + return -EBADF; + return ::_ioctl(fi->fd,cmd_,data_,out_bufsz_); } @@ -163,6 +166,9 @@ _ioctl_dir(const fuse_req_ctx_t *ctx_, { DirInfo *di = DirInfo::from_fh(ffi_->fh); + if(not di) + return -EBADF; + return ::_ioctl_dir_base(cfg.func.open.policy, cfg.branches, di->fusepath.c_str(), diff --git a/src/fuse_open.cpp b/src/fuse_open.cpp index 251decab..8513e39b 100644 --- a/src/fuse_open.cpp +++ b/src/fuse_open.cpp @@ -423,6 +423,8 @@ _open(const fuse_req_ctx_t *ctx_, return rv; fi = FileInfo::from_fh(ffi_->fh); + if(not fi) + return -EBADF; switch(_(cfg.passthrough_io,ffi_->flags)) { diff --git a/src/fuse_read.cpp b/src/fuse_read.cpp index 9847cfa6..3cd9ad35 100644 --- a/src/fuse_read.cpp +++ b/src/fuse_read.cpp @@ -67,6 +67,9 @@ FUSE::read(const fuse_req_ctx_t *ctx_, ioprio::SetFrom iop(ctx_->pid); FileInfo *fi = FileInfo::from_fh(ffi_->fh); + if(not fi) + return -EBADF; + if(fi->direct_io) return ::_read_direct_io(fi->fd,buf_,size_,offset_); diff --git a/src/fuse_readdir.cpp b/src/fuse_readdir.cpp index 614927d9..0c315fa0 100644 --- a/src/fuse_readdir.cpp +++ b/src/fuse_readdir.cpp @@ -84,6 +84,9 @@ _handle_ENOENT(const fuse_file_info_t *ffi_, dirent de; DirInfo *di = DirInfo::from_fh(ffi_->fh); + if(not di) + return -EBADF; + if(!di->fusepath.empty()) return -ENOENT; diff --git a/src/fuse_readdir_cor.cpp b/src/fuse_readdir_cor.cpp index e4f60eca..b0f5ba4a 100644 --- a/src/fuse_readdir_cor.cpp +++ b/src/fuse_readdir_cor.cpp @@ -89,6 +89,9 @@ FUSE::ReadDirCOR::operator()(const fuse_req_ctx_t *ctx_, { DirInfo *di = DirInfo::from_fh(ffi_->fh); + if(not di) + return -EBADF; + return ::_concurrent_readdir(_tp, cfg.branches, di->fusepath, diff --git a/src/fuse_readdir_cosr.cpp b/src/fuse_readdir_cosr.cpp index 4943061e..a916ba2e 100644 --- a/src/fuse_readdir_cosr.cpp +++ b/src/fuse_readdir_cosr.cpp @@ -67,6 +67,9 @@ FUSE::ReadDirCOSR::operator()(const fuse_req_ctx_t *ctx_, { DirInfo *di = DirInfo::from_fh(ffi_->fh); + if(not di) + return -EBADF; + return ::_readdir(_tp, cfg.branches, di->fusepath, diff --git a/src/fuse_readdir_seq.cpp b/src/fuse_readdir_seq.cpp index 11663d2d..3b8335d0 100644 --- a/src/fuse_readdir_seq.cpp +++ b/src/fuse_readdir_seq.cpp @@ -36,6 +36,9 @@ FUSE::ReadDirSeq::operator()(const fuse_req_ctx_t *ctx_, { DirInfo *di = DirInfo::from_fh(ffi_->fh); + if(not di) + return -EBADF; + return ::_readdir(cfg.branches, di->fusepath, dirents_); diff --git a/src/fuse_release.cpp b/src/fuse_release.cpp index c05f754c..17bbb0cd 100644 --- a/src/fuse_release.cpp +++ b/src/fuse_release.cpp @@ -119,6 +119,9 @@ FUSE::release(const fuse_req_ctx_t *ctx_, { FileInfo *fi = FileInfo::from_fh(ffi_->fh); + if(not fi) + return -EBADF; + return ::_release(ctx_->nodeid, fi, cfg.dropcacheonclose); diff --git a/src/fuse_releasedir.cpp b/src/fuse_releasedir.cpp index 7c755660..71226519 100644 --- a/src/fuse_releasedir.cpp +++ b/src/fuse_releasedir.cpp @@ -39,5 +39,8 @@ FUSE::releasedir(const fuse_req_ctx_t *ctx_, { DirInfo *di = DirInfo::from_fh(ffi_->fh); + if(not di) + return -EBADF; + return ::_releasedir(di); } diff --git a/src/fuse_statx_supported.icpp b/src/fuse_statx_supported.icpp index a49c75df..e16f792f 100644 --- a/src/fuse_statx_supported.icpp +++ b/src/fuse_statx_supported.icpp @@ -253,27 +253,15 @@ FUSE::statx_fh(const fuse_req_ctx_t *ctx_, fuse_timeouts_t *timeout_) { int rv; - uint64_t fh; + FileInfo *fi = FileInfo::from_fh(fh_); - fh = fh_; - if(fh == 0) - { - state.open_files.cvisit(ctx_->nodeid, - [&](auto &val_) - { - fh = val_.second.fi->to_fh(); - }); - } + if(not fi) + return -EBADF; - if(fh == 0) - return -ENOENT; - - FileInfo *fi = FileInfo::from_fh(fh); - - rv = ::_statx(fi, - flags_|AT_STATX_DONT_SYNC, - mask_, - st_); + rv = ::_statx(fi, + flags_|AT_STATX_DONT_SYNC, + mask_, + st_); timeout_->entry = ((rv >= 0) ? cfg.cache_entry : diff --git a/src/fuse_write.cpp b/src/fuse_write.cpp index 08403ebd..4db6c397 100644 --- a/src/fuse_write.cpp +++ b/src/fuse_write.cpp @@ -168,6 +168,8 @@ _write(const fuse_file_info_t *ffi_, FileInfo *fi; fi = FileInfo::from_fh(ffi_->fh); + if(not fi) + return -EBADF; // Concurrent writes can only happen if: // 1) writeback-cache is enabled and using page caching