Browse Source

remove FileInfo and keep only file descriptor

pull/57/head
Antonio SJ Musumeci 10 years ago
parent
commit
91671d7364
  1. 4
      src/create.cpp
  2. 6
      src/fallocate.cpp
  3. 6
      src/fgetattr.cpp
  4. 53
      src/fileinfo.hpp
  5. 4
      src/flush.cpp
  6. 6
      src/fsync.cpp
  7. 6
      src/ftruncate.cpp
  8. 5
      src/ioctl.cpp
  9. 1
      src/mkdir.cpp
  10. 4
      src/open.cpp
  11. 4
      src/read.cpp
  12. 4
      src/read_buf.cpp
  13. 10
      src/release.cpp
  14. 4
      src/write.cpp
  15. 3
      src/write_buf.cpp

4
src/create.cpp

@ -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;
} }

6
src/fallocate.cpp

@ -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(fileinfo->fd,
return _fallocate(ffi->fh,
mode, mode,
offset, offset,
len); len);

6
src/fgetattr.cpp

@ -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(fileinfo->fd,
return _fgetattr(ffi->fh,
*st); *st);
} }
} }

53
src/fileinfo.hpp

@ -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__ */

4
src/flush.cpp

@ -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);
} }
} }
} }

6
src/fsync.cpp

@ -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(fileinfo->fd,
return _fsync(ffi->fh,
isdatasync); isdatasync);
} }
} }

6
src/ftruncate.cpp

@ -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(fileinfo->fd,
return _ftruncate(ffi->fh,
size); size);
} }
} }

5
src/ioctl.cpp

@ -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,

1
src/mkdir.cpp

@ -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"

4
src/open.cpp

@ -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;
} }

4
src/read.cpp

@ -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);

4
src/read_buf.cpp

@ -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);

10
src/release.cpp

@ -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(fileinfo->fd);
delete fileinfo;
::close(fh);
fh = 0; fh = 0;

4
src/write.cpp

@ -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);

3
src/write_buf.cpp

@ -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…
Cancel
Save