mirror of
https://github.com/trapexit/mergerfs.git
synced 2025-02-22 08:41:55 +08:00
remove FileInfo and keep only file descriptor
This commit is contained in:
parent
15b2c8be1b
commit
91671d7364
@ -34,13 +34,11 @@
|
|||||||
|
|
||||||
#include "config.hpp"
|
#include "config.hpp"
|
||||||
#include "ugid.hpp"
|
#include "ugid.hpp"
|
||||||
#include "fileinfo.hpp"
|
|
||||||
#include "fs.hpp"
|
#include "fs.hpp"
|
||||||
#include "rwlock.hpp"
|
#include "rwlock.hpp"
|
||||||
|
|
||||||
using std::string;
|
using std::string;
|
||||||
using std::vector;
|
using std::vector;
|
||||||
using mergerfs::FileInfo;
|
|
||||||
using mergerfs::Policy;
|
using mergerfs::Policy;
|
||||||
|
|
||||||
static
|
static
|
||||||
@ -81,7 +79,7 @@ _create(const fs::find::Func searchFunc,
|
|||||||
if(fd == -1)
|
if(fd == -1)
|
||||||
return -errno;
|
return -errno;
|
||||||
|
|
||||||
fh = (uint64_t)new FileInfo(fd,flags,path);
|
fh = fd;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -33,8 +33,6 @@
|
|||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
|
|
||||||
#include "fileinfo.hpp"
|
|
||||||
|
|
||||||
static
|
static
|
||||||
int
|
int
|
||||||
_fallocate(const int fd,
|
_fallocate(const int fd,
|
||||||
@ -75,9 +73,7 @@ namespace mergerfs
|
|||||||
off_t len,
|
off_t len,
|
||||||
struct fuse_file_info *ffi)
|
struct fuse_file_info *ffi)
|
||||||
{
|
{
|
||||||
const FileInfo *fileinfo = (FileInfo*)ffi->fh;
|
return _fallocate(ffi->fh,
|
||||||
|
|
||||||
return _fallocate(fileinfo->fd,
|
|
||||||
mode,
|
mode,
|
||||||
offset,
|
offset,
|
||||||
len);
|
len);
|
||||||
|
@ -29,8 +29,6 @@
|
|||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
|
||||||
#include "fileinfo.hpp"
|
|
||||||
|
|
||||||
static
|
static
|
||||||
int
|
int
|
||||||
_fgetattr(const int fd,
|
_fgetattr(const int fd,
|
||||||
@ -52,9 +50,7 @@ namespace mergerfs
|
|||||||
struct stat *st,
|
struct stat *st,
|
||||||
struct fuse_file_info *ffi)
|
struct fuse_file_info *ffi)
|
||||||
{
|
{
|
||||||
const FileInfo *fileinfo = (FileInfo*)ffi->fh;
|
return _fgetattr(ffi->fh,
|
||||||
|
|
||||||
return _fgetattr(fileinfo->fd,
|
|
||||||
*st);
|
*st);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,53 +0,0 @@
|
|||||||
/*
|
|
||||||
The MIT License (MIT)
|
|
||||||
|
|
||||||
Copyright (c) 2014 Antonio SJ Musumeci <trapexit@spawn.link>
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in
|
|
||||||
all copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
||||||
THE SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef __FILEINFO_H__
|
|
||||||
#define __FILEINFO_H__
|
|
||||||
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
namespace mergerfs
|
|
||||||
{
|
|
||||||
struct FileInfo
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
FileInfo(int fd_,
|
|
||||||
int flags_,
|
|
||||||
std::string realpath_) :
|
|
||||||
fd(fd_),
|
|
||||||
flags(flags_),
|
|
||||||
realpath(realpath_)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
int fd;
|
|
||||||
int flags;
|
|
||||||
std::string realpath;
|
|
||||||
|
|
||||||
private:
|
|
||||||
FileInfo() {}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif /* __FILEINFO_H__ */
|
|
@ -27,8 +27,6 @@
|
|||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
|
||||||
#include "fileinfo.hpp"
|
|
||||||
|
|
||||||
static
|
static
|
||||||
int
|
int
|
||||||
_flush(const int fd)
|
_flush(const int fd)
|
||||||
@ -52,7 +50,7 @@ namespace mergerfs
|
|||||||
flush(const char *fusepath,
|
flush(const char *fusepath,
|
||||||
struct fuse_file_info *ffi)
|
struct fuse_file_info *ffi)
|
||||||
{
|
{
|
||||||
return _flush(((FileInfo*)ffi->fh)->fd);
|
return _flush(ffi->fh);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -34,8 +34,6 @@
|
|||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
|
||||||
#include "fileinfo.hpp"
|
|
||||||
|
|
||||||
static
|
static
|
||||||
int
|
int
|
||||||
_fsync(const int fd,
|
_fsync(const int fd,
|
||||||
@ -59,9 +57,7 @@ namespace mergerfs
|
|||||||
int isdatasync,
|
int isdatasync,
|
||||||
struct fuse_file_info *ffi)
|
struct fuse_file_info *ffi)
|
||||||
{
|
{
|
||||||
const FileInfo *fileinfo = (FileInfo*)ffi->fh;
|
return _fsync(ffi->fh,
|
||||||
|
|
||||||
return _fsync(fileinfo->fd,
|
|
||||||
isdatasync);
|
isdatasync);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -28,8 +28,6 @@
|
|||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
|
||||||
#include "fileinfo.hpp"
|
|
||||||
|
|
||||||
static
|
static
|
||||||
int
|
int
|
||||||
_ftruncate(const int fd,
|
_ftruncate(const int fd,
|
||||||
@ -51,9 +49,7 @@ namespace mergerfs
|
|||||||
off_t size,
|
off_t size,
|
||||||
struct fuse_file_info *ffi)
|
struct fuse_file_info *ffi)
|
||||||
{
|
{
|
||||||
const FileInfo *fileinfo = (FileInfo*)ffi->fh;
|
return _ftruncate(ffi->fh,
|
||||||
|
|
||||||
return _ftruncate(fileinfo->fd,
|
|
||||||
size);
|
size);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -32,7 +32,6 @@
|
|||||||
#include <linux/fs.h>
|
#include <linux/fs.h>
|
||||||
|
|
||||||
#include "config.hpp"
|
#include "config.hpp"
|
||||||
#include "fileinfo.hpp"
|
|
||||||
#include "ugid.hpp"
|
#include "ugid.hpp"
|
||||||
#include "rwlock.hpp"
|
#include "rwlock.hpp"
|
||||||
|
|
||||||
@ -145,8 +144,6 @@ namespace mergerfs
|
|||||||
unsigned int flags,
|
unsigned int flags,
|
||||||
void *data)
|
void *data)
|
||||||
{
|
{
|
||||||
const FileInfo *fileinfo = (FileInfo*)ffi->fh;
|
|
||||||
|
|
||||||
#ifdef FUSE_IOCTL_DIR
|
#ifdef FUSE_IOCTL_DIR
|
||||||
if(flags & FUSE_IOCTL_DIR)
|
if(flags & FUSE_IOCTL_DIR)
|
||||||
return _ioctl_dir(fusepath,
|
return _ioctl_dir(fusepath,
|
||||||
@ -156,7 +153,7 @@ namespace mergerfs
|
|||||||
data);
|
data);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return _ioctl(fileinfo->fd,
|
return _ioctl(ffi->fh,
|
||||||
cmd,
|
cmd,
|
||||||
arg,
|
arg,
|
||||||
flags,
|
flags,
|
||||||
|
@ -32,7 +32,6 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "ugid.hpp"
|
#include "ugid.hpp"
|
||||||
#include "fileinfo.hpp"
|
|
||||||
#include "fs.hpp"
|
#include "fs.hpp"
|
||||||
#include "config.hpp"
|
#include "config.hpp"
|
||||||
#include "rwlock.hpp"
|
#include "rwlock.hpp"
|
||||||
|
@ -32,14 +32,12 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "ugid.hpp"
|
#include "ugid.hpp"
|
||||||
#include "fileinfo.hpp"
|
|
||||||
#include "fs.hpp"
|
#include "fs.hpp"
|
||||||
#include "config.hpp"
|
#include "config.hpp"
|
||||||
#include "rwlock.hpp"
|
#include "rwlock.hpp"
|
||||||
|
|
||||||
using std::string;
|
using std::string;
|
||||||
using std::vector;
|
using std::vector;
|
||||||
using mergerfs::FileInfo;
|
|
||||||
|
|
||||||
static
|
static
|
||||||
int
|
int
|
||||||
@ -61,7 +59,7 @@ _open(const fs::find::Func searchFunc,
|
|||||||
if(fd == -1)
|
if(fd == -1)
|
||||||
return -errno;
|
return -errno;
|
||||||
|
|
||||||
fh = (uint64_t)new FileInfo(fd,flags,path[0].full);
|
fh = fd;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -30,8 +30,6 @@
|
|||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include "fileinfo.hpp"
|
|
||||||
|
|
||||||
static
|
static
|
||||||
int
|
int
|
||||||
_read(const int fd,
|
_read(const int fd,
|
||||||
@ -57,7 +55,7 @@ namespace mergerfs
|
|||||||
off_t offset,
|
off_t offset,
|
||||||
struct fuse_file_info *ffi)
|
struct fuse_file_info *ffi)
|
||||||
{
|
{
|
||||||
return _read(((FileInfo*)ffi->fh)->fd,
|
return _read(ffi->fh,
|
||||||
buf,
|
buf,
|
||||||
count,
|
count,
|
||||||
offset);
|
offset);
|
||||||
|
@ -30,8 +30,6 @@
|
|||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include "fileinfo.hpp"
|
|
||||||
|
|
||||||
static
|
static
|
||||||
int
|
int
|
||||||
_read_buf(const int fd,
|
_read_buf(const int fd,
|
||||||
@ -67,7 +65,7 @@ namespace mergerfs
|
|||||||
off_t offset,
|
off_t offset,
|
||||||
struct fuse_file_info *ffi)
|
struct fuse_file_info *ffi)
|
||||||
{
|
{
|
||||||
return _read_buf(((FileInfo*)ffi->fh)->fd,
|
return _read_buf(ffi->fh,
|
||||||
bufp,
|
bufp,
|
||||||
size,
|
size,
|
||||||
offset);
|
offset);
|
||||||
|
@ -29,19 +29,11 @@
|
|||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include "fileinfo.hpp"
|
|
||||||
|
|
||||||
using mergerfs::FileInfo;
|
|
||||||
|
|
||||||
static
|
static
|
||||||
int
|
int
|
||||||
_release(uint64_t &fh)
|
_release(uint64_t &fh)
|
||||||
{
|
{
|
||||||
const FileInfo *fileinfo = (FileInfo*)fh;
|
::close(fh);
|
||||||
|
|
||||||
::close(fileinfo->fd);
|
|
||||||
|
|
||||||
delete fileinfo;
|
|
||||||
|
|
||||||
fh = 0;
|
fh = 0;
|
||||||
|
|
||||||
|
@ -27,8 +27,6 @@
|
|||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
#include "fileinfo.hpp"
|
|
||||||
|
|
||||||
static
|
static
|
||||||
int
|
int
|
||||||
_write(const int fd,
|
_write(const int fd,
|
||||||
@ -54,7 +52,7 @@ namespace mergerfs
|
|||||||
off_t offset,
|
off_t offset,
|
||||||
struct fuse_file_info *ffi)
|
struct fuse_file_info *ffi)
|
||||||
{
|
{
|
||||||
return _write(((FileInfo*)ffi->fh)->fd,
|
return _write(ffi->fh,
|
||||||
buf,
|
buf,
|
||||||
count,
|
count,
|
||||||
offset);
|
offset);
|
||||||
|
@ -28,7 +28,6 @@
|
|||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
#include "fileinfo.hpp"
|
|
||||||
#include "write.hpp"
|
#include "write.hpp"
|
||||||
|
|
||||||
static
|
static
|
||||||
@ -59,7 +58,7 @@ namespace mergerfs
|
|||||||
off_t offset,
|
off_t offset,
|
||||||
struct fuse_file_info *ffi)
|
struct fuse_file_info *ffi)
|
||||||
{
|
{
|
||||||
return _write_buf(((FileInfo*)ffi->fh)->fd,
|
return _write_buf(ffi->fh,
|
||||||
*src,
|
*src,
|
||||||
offset);
|
offset);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user