2014-05-12 12:41:46 -04:00
|
|
|
/*
|
2016-01-14 16:50:22 -05: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.
|
2014-05-12 12:41:46 -04:00
|
|
|
*/
|
|
|
|
|
|
2016-09-14 08:36:06 -04:00
|
|
|
#include "errno.hpp"
|
2015-09-15 18:49:18 -04:00
|
|
|
#include "fileinfo.hpp"
|
2020-08-17 16:29:22 -04:00
|
|
|
#include "fs_read.hpp"
|
2015-09-15 18:49:18 -04:00
|
|
|
|
2019-01-09 00:01:52 -05:00
|
|
|
#include <fuse.h>
|
|
|
|
|
|
2019-01-25 07:03:46 -05:00
|
|
|
namespace l
|
2014-05-12 12:41:46 -04:00
|
|
|
{
|
2019-01-09 00:01:52 -05:00
|
|
|
static
|
|
|
|
|
inline
|
|
|
|
|
int
|
|
|
|
|
read_regular(const int fd_,
|
|
|
|
|
void *buf_,
|
|
|
|
|
const size_t count_,
|
|
|
|
|
const off_t offset_)
|
|
|
|
|
{
|
|
|
|
|
int rv;
|
2014-05-12 12:41:46 -04:00
|
|
|
|
2019-01-09 00:01:52 -05:00
|
|
|
rv = fs::pread(fd_,buf_,count_,offset_);
|
|
|
|
|
if(rv == -1)
|
|
|
|
|
return -errno;
|
|
|
|
|
if(rv == 0)
|
|
|
|
|
return 0;
|
2014-05-12 12:41:46 -04:00
|
|
|
|
2019-01-09 00:01:52 -05:00
|
|
|
return count_;
|
|
|
|
|
}
|
2016-12-20 17:06:34 -05:00
|
|
|
|
2019-01-09 00:01:52 -05:00
|
|
|
static
|
|
|
|
|
inline
|
|
|
|
|
int
|
|
|
|
|
read_direct_io(const int fd_,
|
|
|
|
|
void *buf_,
|
|
|
|
|
const size_t count_,
|
|
|
|
|
const off_t offset_)
|
|
|
|
|
{
|
|
|
|
|
int rv;
|
2016-12-20 17:06:34 -05:00
|
|
|
|
2019-01-09 00:01:52 -05:00
|
|
|
rv = fs::pread(fd_,buf_,count_,offset_);
|
|
|
|
|
if(rv == -1)
|
|
|
|
|
return -errno;
|
2016-12-20 17:06:34 -05:00
|
|
|
|
2019-01-09 00:01:52 -05:00
|
|
|
return rv;
|
|
|
|
|
}
|
2014-05-12 12:41:46 -04:00
|
|
|
}
|
|
|
|
|
|
2019-01-25 07:03:46 -05:00
|
|
|
namespace FUSE
|
2014-05-12 12:41:46 -04:00
|
|
|
{
|
2019-01-25 07:03:46 -05:00
|
|
|
int
|
2020-11-15 19:12:33 -05:00
|
|
|
read(const fuse_file_info_t *ffi_,
|
|
|
|
|
char *buf_,
|
|
|
|
|
size_t count_,
|
|
|
|
|
off_t offset_)
|
2014-05-12 12:41:46 -04:00
|
|
|
{
|
2019-01-25 07:03:46 -05:00
|
|
|
FileInfo *fi;
|
2015-09-15 18:49:18 -04:00
|
|
|
|
2019-01-25 07:03:46 -05:00
|
|
|
fi = reinterpret_cast<FileInfo*>(ffi_->fh);
|
2016-12-20 17:06:34 -05:00
|
|
|
|
2019-01-25 07:03:46 -05:00
|
|
|
if(ffi_->direct_io)
|
|
|
|
|
return l::read_direct_io(fi->fd,buf_,count_,offset_);
|
|
|
|
|
return l::read_regular(fi->fd,buf_,count_,offset_);
|
|
|
|
|
}
|
2017-05-26 16:51:30 -04:00
|
|
|
|
2019-01-25 07:03:46 -05:00
|
|
|
int
|
2020-11-15 19:12:33 -05:00
|
|
|
read_null(const fuse_file_info_t *ffi_,
|
|
|
|
|
char *buf_,
|
|
|
|
|
size_t count_,
|
|
|
|
|
off_t offset_)
|
2019-01-25 07:03:46 -05:00
|
|
|
{
|
|
|
|
|
return count_;
|
2014-05-12 12:41:46 -04:00
|
|
|
}
|
|
|
|
|
}
|