mirror of
https://github.com/s3fs-fuse/s3fs-fuse.git
synced 2024-06-01 16:40:52 +00:00
99 lines
2.3 KiB
C++
99 lines
2.3 KiB
C++
|
/*
|
||
|
* s3fs - FUSE-based file system backed by Amazon S3
|
||
|
*
|
||
|
* Copyright(C) 2007 Takeshi Nakatani <ggtakec.com>
|
||
|
*
|
||
|
* This program is free software; you can redistribute it and/or
|
||
|
* modify it under the terms of the GNU General Public License
|
||
|
* as published by the Free Software Foundation; either version 2
|
||
|
* of the License, or (at your option) any later version.
|
||
|
*
|
||
|
* This program is distributed in the hope that it will be useful,
|
||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
|
* GNU General Public License for more details.
|
||
|
*
|
||
|
* You should have received a copy of the GNU General Public License
|
||
|
* along with this program; if not, write to the Free Software
|
||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||
|
*/
|
||
|
|
||
|
#include <cstdio>
|
||
|
#include <cstdlib>
|
||
|
#include <algorithm>
|
||
|
|
||
|
#include "common.h"
|
||
|
#include "s3fs.h"
|
||
|
#include "fdcache_fdinfo.h"
|
||
|
#include "fdcache_pseudofd.h"
|
||
|
#include "autolock.h"
|
||
|
|
||
|
//------------------------------------------------
|
||
|
// PseudoFdInfo methods
|
||
|
//------------------------------------------------
|
||
|
PseudoFdInfo::PseudoFdInfo(int fd, int open_flags) : pseudo_fd(-1), physical_fd(fd), flags(0) //, is_lock_init(false)
|
||
|
{
|
||
|
if(-1 != physical_fd){
|
||
|
pseudo_fd = PseudoFdManager::Get();
|
||
|
flags = open_flags;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
PseudoFdInfo::~PseudoFdInfo()
|
||
|
{
|
||
|
Clear();
|
||
|
}
|
||
|
|
||
|
bool PseudoFdInfo::Clear()
|
||
|
{
|
||
|
if(-1 != pseudo_fd){
|
||
|
PseudoFdManager::Release(pseudo_fd);
|
||
|
}
|
||
|
pseudo_fd = -1;
|
||
|
physical_fd = -1;
|
||
|
|
||
|
return true;
|
||
|
}
|
||
|
|
||
|
bool PseudoFdInfo::Set(int fd, int open_flags)
|
||
|
{
|
||
|
if(-1 == fd){
|
||
|
return false;
|
||
|
}
|
||
|
Clear();
|
||
|
physical_fd = fd;
|
||
|
pseudo_fd = PseudoFdManager::Get();
|
||
|
flags = open_flags;
|
||
|
|
||
|
return true;
|
||
|
}
|
||
|
|
||
|
bool PseudoFdInfo::Writable() const
|
||
|
{
|
||
|
if(-1 == pseudo_fd){
|
||
|
return false;
|
||
|
}
|
||
|
if(0 == (flags & (O_WRONLY | O_RDWR))){
|
||
|
return false;
|
||
|
}
|
||
|
return true;
|
||
|
}
|
||
|
|
||
|
bool PseudoFdInfo::Readable() const
|
||
|
{
|
||
|
if(-1 == pseudo_fd){
|
||
|
return false;
|
||
|
}
|
||
|
// O_RDONLY is 0x00, it means any pattern is readable.
|
||
|
return true;
|
||
|
}
|
||
|
|
||
|
/*
|
||
|
* Local variables:
|
||
|
* tab-width: 4
|
||
|
* c-basic-offset: 4
|
||
|
* End:
|
||
|
* vim600: expandtab sw=4 ts=4 fdm=marker
|
||
|
* vim<600: expandtab sw=4 ts=4
|
||
|
*/
|