mirror of
https://github.com/trapexit/mergerfs.git
synced 2026-10-26 19:01:56 -04:00
Rework readlink to not depend on cstr nul termination
This commit is contained in:
parent
a86092b3c2
commit
b6d5da2330
8 changed files with 44 additions and 64 deletions
|
|
@ -32,34 +32,15 @@
|
|||
|
||||
|
||||
static
|
||||
int
|
||||
_readlink_core_standard(const fs::path &fullpath_,
|
||||
char *buf_,
|
||||
const size_t bufsize_)
|
||||
|
||||
{
|
||||
int rv;
|
||||
|
||||
rv = fs::readlink(fullpath_,buf_,(bufsize_ - 1));
|
||||
if(rv < 0)
|
||||
return rv;
|
||||
|
||||
buf_[rv] = '\0';
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static
|
||||
int
|
||||
ssize_t
|
||||
_readlink_core_symlinkify(const fs::path &fullpath_,
|
||||
char *buf_,
|
||||
const size_t bufsize_,
|
||||
const time_t symlinkify_timeout_)
|
||||
{
|
||||
int rv;
|
||||
size_t n;
|
||||
std::string fullpath_str;
|
||||
ssize_t rv;
|
||||
struct stat st;
|
||||
std::string fullpath_str;
|
||||
|
||||
fullpath_str = fullpath_.string();
|
||||
|
||||
|
|
@ -68,17 +49,16 @@ _readlink_core_symlinkify(const fs::path &fullpath_,
|
|||
return rv;
|
||||
|
||||
if(!symlinkify::can_be_symlink(st,symlinkify_timeout_))
|
||||
return ::_readlink_core_standard(fullpath_,buf_,bufsize_);
|
||||
return fs::readlink(fullpath_,buf_,bufsize_);
|
||||
|
||||
n = std::min(fullpath_str.size(),(bufsize_ - 1));
|
||||
memcpy(buf_,fullpath_str.c_str(),n);
|
||||
buf_[n] = '\0';
|
||||
rv = std::min(fullpath_str.size(),bufsize_);
|
||||
memcpy(buf_,fullpath_str.c_str(),rv);
|
||||
|
||||
return 0;
|
||||
return rv;
|
||||
}
|
||||
|
||||
static
|
||||
int
|
||||
ssize_t
|
||||
_readlink_core(const fs::path &basepath_,
|
||||
const fs::path &fusepath_,
|
||||
char *buf_,
|
||||
|
|
@ -93,11 +73,11 @@ _readlink_core(const fs::path &basepath_,
|
|||
if(symlinkify_)
|
||||
return ::_readlink_core_symlinkify(fullpath,buf_,bufsize_,symlinkify_timeout_);
|
||||
|
||||
return ::_readlink_core_standard(fullpath,buf_,bufsize_);
|
||||
return fs::readlink(fullpath,buf_,bufsize_);
|
||||
}
|
||||
|
||||
static
|
||||
int
|
||||
ssize_t
|
||||
_readlink(const Policy::Search &searchFunc_,
|
||||
const Branches::Ptr ibranches_,
|
||||
const fs::path &fusepath_,
|
||||
|
|
@ -106,7 +86,7 @@ _readlink(const Policy::Search &searchFunc_,
|
|||
const bool symlinkify_,
|
||||
const time_t symlinkify_timeout_)
|
||||
{
|
||||
int rv;
|
||||
ssize_t rv;
|
||||
std::vector<Branch*> obranches;
|
||||
|
||||
rv = searchFunc_(ibranches_,fusepath_,obranches);
|
||||
|
|
@ -123,16 +103,16 @@ _readlink(const Policy::Search &searchFunc_,
|
|||
symlinkify_timeout_);
|
||||
}
|
||||
|
||||
int
|
||||
ssize_t
|
||||
FUSE::readlink(const fuse_req_ctx_t *ctx_,
|
||||
const char *fusepath_,
|
||||
char *buf_,
|
||||
size_t bufsize_)
|
||||
{
|
||||
const fs::path fusepath{fusepath_};
|
||||
|
||||
if(bufsize_ == 0)
|
||||
return -EINVAL;
|
||||
return 0;
|
||||
|
||||
const fs::path fusepath{fusepath_};
|
||||
|
||||
return ::_readlink(cfg.func.readlink.policy,
|
||||
cfg.branches,
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@
|
|||
|
||||
namespace FUSE
|
||||
{
|
||||
int
|
||||
ssize_t
|
||||
readlink(const fuse_req_ctx_t *ctx,
|
||||
const char *fusepath,
|
||||
char *buf,
|
||||
|
|
|
|||
|
|
@ -43,7 +43,8 @@ void fuse_debug_entry_open_out(const uint64_t unique,
|
|||
const struct fuse_entry_out *earg,
|
||||
const struct fuse_open_out *oarg);
|
||||
void fuse_debug_readlink(const uint64_t unique,
|
||||
const char *linkname);
|
||||
const char *linkname,
|
||||
const size_t linkname_len);
|
||||
void fuse_debug_write_out(const uint64_t unique,
|
||||
const struct fuse_write_out *arg);
|
||||
void fuse_debug_statfs_out(const uint64_t unique,
|
||||
|
|
|
|||
|
|
@ -70,10 +70,10 @@ struct fuse_operations
|
|||
const char *,
|
||||
struct stat *,
|
||||
fuse_timeouts_t *);
|
||||
int (*readlink)(const fuse_req_ctx_t *,
|
||||
const char *,
|
||||
char *,
|
||||
size_t);
|
||||
ssize_t (*readlink)(const fuse_req_ctx_t *,
|
||||
const char *,
|
||||
char *,
|
||||
size_t);
|
||||
int (*mknod)(const fuse_req_ctx_t *,
|
||||
const char *,
|
||||
mode_t,
|
||||
|
|
|
|||
|
|
@ -241,7 +241,9 @@ int fuse_reply_statx(fuse_req_t *req,
|
|||
* @param link symbolic link contents
|
||||
* @return zero for success, -errno for failure to send reply
|
||||
*/
|
||||
int fuse_reply_readlink(fuse_req_t *req, const char *link);
|
||||
int fuse_reply_readlink(fuse_req_t *req,
|
||||
const char *linkname,
|
||||
const size_t linkname_len);
|
||||
|
||||
/**
|
||||
* Reply with open parameters
|
||||
|
|
|
|||
|
|
@ -1734,7 +1734,8 @@ fuse_debug_entry_open_out(const uint64_t unique_,
|
|||
|
||||
void
|
||||
fuse_debug_readlink(const uint64_t unique_,
|
||||
const char *linkname_)
|
||||
const char *linkname_,
|
||||
const size_t linkname_len_)
|
||||
{
|
||||
auto output = fuse_cfg.log_file();
|
||||
|
||||
|
|
@ -1748,8 +1749,8 @@ fuse_debug_readlink(const uint64_t unique_,
|
|||
"\n",
|
||||
_timestamp_ns(),
|
||||
unique_,
|
||||
(sizeof(struct fuse_out_header) + strlen(linkname_)),
|
||||
_quoted(linkname_));
|
||||
(sizeof(struct fuse_out_header) + linkname_len_),
|
||||
_quoted(linkname_,linkname_len_));
|
||||
}
|
||||
|
||||
void
|
||||
|
|
|
|||
|
|
@ -1729,29 +1729,24 @@ void
|
|||
fuse_lib_readlink(fuse_req_t *req_,
|
||||
struct fuse_in_header *hdr_)
|
||||
{
|
||||
int err;
|
||||
ssize_t rv;
|
||||
char *fusepath;
|
||||
char linkname[PATH_MAX + 1];
|
||||
|
||||
err = get_path(hdr_->nodeid,&fusepath);
|
||||
if(!err)
|
||||
rv = get_path(hdr_->nodeid,&fusepath);
|
||||
if(!rv)
|
||||
{
|
||||
err = f.ops.readlink(&req_->ctx,
|
||||
&fusepath[1],
|
||||
linkname,
|
||||
sizeof(linkname));
|
||||
rv = f.ops.readlink(&req_->ctx,
|
||||
&fusepath[1],
|
||||
linkname,
|
||||
sizeof(linkname));
|
||||
free_path(hdr_->nodeid,fusepath);
|
||||
}
|
||||
|
||||
if(!err)
|
||||
{
|
||||
linkname[PATH_MAX] = '\0';
|
||||
fuse_reply_readlink(req_,linkname);
|
||||
}
|
||||
if(rv >= 0)
|
||||
fuse_reply_readlink(req_,linkname,rv);
|
||||
else
|
||||
{
|
||||
fuse_reply_err(req_,err);
|
||||
}
|
||||
fuse_reply_err(req_,rv);
|
||||
}
|
||||
|
||||
static
|
||||
|
|
|
|||
|
|
@ -357,16 +357,17 @@ fuse_reply_statx(fuse_req_t *req_,
|
|||
}
|
||||
|
||||
int
|
||||
fuse_reply_readlink(fuse_req_t *req,
|
||||
const char *linkname)
|
||||
fuse_reply_readlink(fuse_req_t *req,
|
||||
const char *linkname,
|
||||
const size_t linkname_len)
|
||||
{
|
||||
if(not linkname)
|
||||
return fuse_reply_err(req,EIO);
|
||||
|
||||
if(fuse_cfg.debug)
|
||||
fuse_debug_readlink(req->ctx.unique,linkname);
|
||||
fuse_debug_readlink(req->ctx.unique,linkname,linkname_len);
|
||||
|
||||
return send_reply_ok(req, linkname, strlen(linkname));
|
||||
return send_reply_ok(req,linkname,linkname_len);
|
||||
}
|
||||
|
||||
int
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue