2013-05-28 05:54:09 +00:00
|
|
|
#ifndef FD_CACHE_H_
|
|
|
|
#define FD_CACHE_H_
|
|
|
|
|
|
|
|
#include "common.h"
|
|
|
|
|
|
|
|
//
|
|
|
|
// Struct for fuse file handle cache
|
|
|
|
//
|
|
|
|
struct fd_cache_entry {
|
2013-06-21 06:07:22 +00:00
|
|
|
int refcnt;
|
2013-05-28 05:54:09 +00:00
|
|
|
int fd;
|
|
|
|
int flags;
|
|
|
|
|
2013-06-21 06:07:22 +00:00
|
|
|
fd_cache_entry() : refcnt(0), fd(0), flags(0) {}
|
2013-05-28 05:54:09 +00:00
|
|
|
};
|
|
|
|
|
2013-06-21 06:07:22 +00:00
|
|
|
typedef std::list<int> fd_list_t;
|
|
|
|
typedef std::list<struct fd_cache_entry> fd_cache_entlist_t;
|
|
|
|
typedef std::map<std::string, fd_cache_entlist_t*> fd_cache_t; // key=path, value=<list>*
|
|
|
|
typedef std::map<int, int> fd_flags_t; // key=file discriptor, value=flags
|
2013-05-28 05:54:09 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// Class for fuse file handle cache
|
|
|
|
//
|
|
|
|
class FdCache
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
static FdCache singleton;
|
|
|
|
static pthread_mutex_t fd_cache_lock;
|
|
|
|
fd_cache_t fd_cache;
|
|
|
|
fd_flags_t fd_flags;
|
|
|
|
|
|
|
|
public:
|
|
|
|
FdCache();
|
|
|
|
~FdCache();
|
|
|
|
|
|
|
|
// Reference singleton
|
|
|
|
static FdCache* getFdCacheData(void) {
|
|
|
|
return &singleton;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Add(const char* path, int fd, int flags);
|
|
|
|
bool Del(const char* path, int fd);
|
|
|
|
bool Del(const char* path);
|
|
|
|
bool Del(int fd);
|
|
|
|
bool Get(const char* path, int* pfd = NULL, int* pflags = NULL) const;
|
|
|
|
bool Get(int fd, int* pflags = NULL) const;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // FD_CACHE_H_
|