2016-10-19 11:58:44 -04:00
|
|
|
/*
|
|
|
|
|
Copyright (c) 2016, Antonio SJ Musumeci <trapexit@spawn.link>
|
|
|
|
|
|
|
|
|
|
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_flock.hpp"
|
|
|
|
|
|
2016-10-19 11:58:44 -04:00
|
|
|
#include "errno.hpp"
|
|
|
|
|
#include "fileinfo.hpp"
|
2020-08-17 16:29:22 -04:00
|
|
|
#include "fs_flock.hpp"
|
2025-09-17 23:51:16 -04:00
|
|
|
#include "state.hpp"
|
2016-10-19 11:58:44 -04:00
|
|
|
|
2020-12-19 15:06:08 -05:00
|
|
|
#include "fuse.h"
|
|
|
|
|
|
2019-01-25 07:03:46 -05:00
|
|
|
|
2025-07-25 17:53:48 -05:00
|
|
|
static
|
|
|
|
|
int
|
|
|
|
|
_flock(const int fd_,
|
|
|
|
|
const int operation_)
|
2016-10-19 11:58:44 -04:00
|
|
|
{
|
2025-07-25 17:53:48 -05:00
|
|
|
int rv;
|
2016-10-19 11:58:44 -04:00
|
|
|
|
2025-07-25 17:53:48 -05:00
|
|
|
rv = fs::flock(fd_,operation_);
|
2016-10-19 11:58:44 -04:00
|
|
|
|
2025-07-25 17:53:48 -05:00
|
|
|
return rv;
|
2016-10-19 11:58:44 -04:00
|
|
|
}
|
|
|
|
|
|
2025-07-25 17:53:48 -05:00
|
|
|
int
|
|
|
|
|
FUSE::flock(const fuse_file_info_t *ffi_,
|
|
|
|
|
int op_)
|
2016-10-19 11:58:44 -04:00
|
|
|
{
|
2025-09-17 23:51:16 -04:00
|
|
|
uint64_t fh;
|
|
|
|
|
const fuse_context *fc = fuse_get_context();
|
|
|
|
|
|
|
|
|
|
fh = ffi_->fh;
|
|
|
|
|
if(fh == 0)
|
|
|
|
|
{
|
|
|
|
|
state.open_files.cvisit(fc->nodeid,
|
|
|
|
|
[&](const auto &val_)
|
|
|
|
|
{
|
|
|
|
|
fh = val_.second.fi->to_fh();
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(fh == 0)
|
|
|
|
|
return -ENOENT;
|
|
|
|
|
|
|
|
|
|
FileInfo* fi = FileInfo::from_fh(fh);
|
2025-07-25 17:53:48 -05:00
|
|
|
|
|
|
|
|
return ::_flock(fi->fd,op_);
|
2016-10-19 11:58:44 -04:00
|
|
|
}
|