本文整理汇总了C++中EncFS_Context::getRoot方法的典型用法代码示例。如果您正苦于以下问题:C++ EncFS_Context::getRoot方法的具体用法?C++ EncFS_Context::getRoot怎么用?C++ EncFS_Context::getRoot使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类EncFS_Context
的用法示例。
在下文中一共展示了EncFS_Context::getRoot方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: withCipherPath
// helper function -- apply a functor to a cipher path, given the plain path
static int withCipherPath(const char *opName, const char *path,
function<int(EncFS_Context *, const string &)> op,
bool passReturnCode = false) {
EncFS_Context *ctx = context();
int res = -EIO;
std::shared_ptr<DirNode> FSRoot = ctx->getRoot(&res);
if (!FSRoot) return res;
try {
string cyName = FSRoot->cipherPath(path);
VLOG(1) << "op: " << opName << " : " << cyName;
res = op(ctx, cyName);
if (res == -1) {
int eno = errno;
VLOG(1) << "op: " << opName << " error: " << strerror(eno);
res = -eno;
} else if (!passReturnCode) {
res = ESUCCESS;
}
} catch (encfs::Error &err) {
RLOG(ERROR) << "withCipherPath: error caught in " << opName << ": "
<< err.what();
}
return res;
}
示例2: withFileNode
static int withFileNode( const char *opName,
const char *path, struct fuse_file_info *fi,
int (*op)(FileNode *, T data ), T data )
{
EncFS_Context *ctx = context();
int res = -EIO;
shared_ptr<DirNode> FSRoot = ctx->getRoot(&res);
if(!FSRoot)
return res;
try
{
shared_ptr<FileNode> fnode;
if(fi != NULL)
fnode = GET_FN(ctx, fi);
else
fnode = FSRoot->lookupNode( path, opName );
rAssert(fnode != NULL);
rLog(Info, "%s %s", opName, fnode->cipherName());
res = op( fnode.get(), data );
if(res < 0)
rInfo("%s error: %s", opName, strerror(-res));
} catch( rlog::Error &err )
{
rError("error caught in %s", opName);
err.log( _RLWarningChannel );
}
return res;
}
示例3: _do_getattr
int _do_getattr(FileNode *fnode, struct stat *stbuf) {
int res = fnode->getAttr(stbuf);
if (res == ESUCCESS && S_ISLNK(stbuf->st_mode)) {
EncFS_Context *ctx = context();
std::shared_ptr<DirNode> FSRoot = ctx->getRoot(&res);
if (FSRoot) {
// determine plaintext link size.. Easiest to read and decrypt..
std::vector<char> buf(stbuf->st_size + 1, '\0');
res = ::readlink(fnode->cipherName(), buf.data(), stbuf->st_size);
if (res >= 0) {
// other functions expect c-strings to be null-terminated, which
// readlink doesn't provide
buf[res] = '\0';
stbuf->st_size = FSRoot->plainPath(buf.data()).length();
res = ESUCCESS;
} else {
res = -errno;
}
}
}
return res;
}
示例4: withCipherPath
static int withCipherPath( const char *opName, const char *path,
int (*op)(EncFS_Context *, const string &name, T data ), T data,
bool passReturnCode = false )
{
EncFS_Context *ctx = context();
int res = -EIO;
shared_ptr<DirNode> FSRoot = ctx->getRoot(&res);
if(!FSRoot)
return res;
try
{
string cyName = FSRoot->cipherPath( path );
VLOG(1) << opName << " " << cyName.c_str();
res = op( ctx, cyName, data );
if(res == -1)
{
res = -errno;
LOG(INFO) << opName << " error: " << strerror(-res);
} else if(!passReturnCode)
res = ESUCCESS;
} catch( Error &err )
{
LOG(ERROR) << "error caught in " << opName <<
":" << err.what();
}
return res;
}
示例5: withCipherPath
static int withCipherPath( const char *opName, const char *path,
int (*op)(EncFS_Context *, const string &name, T data ), T data,
bool passReturnCode = false )
{
EncFS_Context *ctx = context();
int res = -EIO;
shared_ptr<DirNode> FSRoot = ctx->getRoot(&res);
if(!FSRoot)
return res;
try
{
string cyName = FSRoot->cipherPath( path );
rLog(Info, "%s %s", opName, cyName.c_str());
res = op( ctx, cyName, data );
if(res == -1)
{
int eno = errno;
rInfo("%s error: %s", opName, strerror(eno));
res = -eno;
} else if(!passReturnCode)
res = ESUCCESS;
} catch( rlog::Error &err )
{
rError("error caught in %s", opName);
err.log( _RLWarningChannel );
}
return res;
}
示例6: encfs_mkdir
int encfs_mkdir(const char *path, mode_t mode) {
fuse_context *fctx = fuse_get_context();
EncFS_Context *ctx = context();
if (isReadOnly(ctx)) return -EROFS;
int res = -EIO;
std::shared_ptr<DirNode> FSRoot = ctx->getRoot(&res);
if (!FSRoot) return res;
try {
uid_t uid = 0;
gid_t gid = 0;
if (ctx->publicFilesystem) {
uid = fctx->uid;
gid = fctx->gid;
}
res = FSRoot->mkdir(path, mode, uid, gid);
// Is this error due to access problems?
if (ctx->publicFilesystem && -res == EACCES) {
// try again using the parent dir's group
string parent = parentDirectory(path);
std::shared_ptr<FileNode> dnode =
FSRoot->lookupNode(parent.c_str(), "mkdir");
struct stat st;
if (dnode->getAttr(&st) == 0)
res = FSRoot->mkdir(path, mode, uid, st.st_gid);
}
} catch (encfs::Error &err) {
RLOG(ERROR) << "error caught in mkdir: " << err.what();
}
return res;
}
示例7: withFileNode
static int withFileNode( const char *opName,
const char *path, struct fuse_file_info *fi,
int (*op)(FileNode *, T data ), T data )
{
EncFS_Context *ctx = context();
int res = -EIO;
shared_ptr<DirNode> FSRoot = ctx->getRoot(&res);
if(!FSRoot)
return res;
try
{
shared_ptr<FileNode> fnode;
if(fi != NULL)
fnode = GET_FN(ctx, fi);
else
fnode = FSRoot->lookupNode( path, opName );
rAssert(fnode != NULL);
VLOG(1) << opName << " " << fnode->cipherName();
res = op( fnode.get(), data );
LOG_IF(INFO, res < 0) << opName << " error: " << strerror(-res);
} catch( Error &err )
{
LOG(ERROR) << "error caught in " << opName <<
":" << err.what();
}
return res;
}
示例8: encfs_open
int encfs_open(const char *path, struct fuse_file_info *file)
{
EncFS_Context *ctx = context();
int res = -EIO;
shared_ptr<DirNode> FSRoot = ctx->getRoot(&res);
if(!FSRoot)
return res;
try
{
shared_ptr<FileNode> fnode =
FSRoot->openNode( path, "open", file->flags, &res );
if(fnode)
{
rLog(Info, "encfs_open for %s, flags %i", fnode->cipherName(),
file->flags);
if( res >= 0 )
{
file->fh = (uintptr_t)ctx->putNode(path, fnode);
res = ESUCCESS;
}
}
} catch( rlog::Error &err )
{
rError("error caught in open");
err.log( _RLWarningChannel );
}
return res;
}
示例9: encfs_open
int encfs_open(const char *path, struct fuse_file_info *file) {
EncFS_Context *ctx = context();
if (isReadOnly(ctx) && (file->flags & O_WRONLY || file->flags & O_RDWR))
return -EROFS;
int res = -EIO;
std::shared_ptr<DirNode> FSRoot = ctx->getRoot(&res);
if (!FSRoot) return res;
try {
std::shared_ptr<FileNode> fnode =
FSRoot->openNode(path, "open", file->flags, &res);
if (fnode) {
VLOG(1) << "encfs_open for " << fnode->cipherName() << ", flags "
<< file->flags;
if (res >= 0) {
file->fh =
reinterpret_cast<uintptr_t>(ctx->putNode(path, std::move(fnode)));
res = ESUCCESS;
}
}
} catch (encfs::Error &err) {
RLOG(ERROR) << "error caught in open: " << err.what();
}
return res;
}
示例10: encfs_open
int encfs_open(const char *path, struct fuse_file_info *file)
{
EncFS_Context *ctx = context();
int res = -EIO;
shared_ptr<DirNode> FSRoot = ctx->getRoot(&res);
if(!FSRoot)
return res;
try
{
shared_ptr<FileNode> fnode =
FSRoot->openNode( path, "open", file->flags, &res );
if(fnode)
{
VLOG(1) << "encfs_open for " << fnode->cipherName()
<< ", flags " << file->flags;
if( res >= 0 )
{
file->fh = (uintptr_t)ctx->putNode(path, fnode);
res = ESUCCESS;
}
}
} catch( Error &err )
{
LOG(ERROR) << "error caught in open: " << err.what();
}
return res;
}
示例11: GetFileAttributesW
static uint32_t encfs_win_get_attributes(const char *fn)
{
EncFS_Context *ctx = context();
int res = -EIO;
shared_ptr<DirNode> FSRoot = ctx->getRoot(&res);
if(!FSRoot)
return res;
std::wstring path = utf8_to_wfn(FSRoot->cipherPath(fn));
// TODO error
return GetFileAttributesW(path.c_str());
}
示例12: encfs_win_set_attributes
static int encfs_win_set_attributes(const char *fn, uint32_t attr)
{
EncFS_Context *ctx = context();
int res = -EIO;
shared_ptr<DirNode> FSRoot = ctx->getRoot(&res);
if(!FSRoot)
return res;
std::wstring path = utf8_to_wfn(FSRoot->cipherPath(fn));
if (SetFileAttributesW(path.c_str(), attr))
return 0;
return -win32_error_to_errno(GetLastError());
}
示例13: encfs_rename
int encfs_rename(const char *from, const char *to) {
EncFS_Context *ctx = context();
if (isReadOnly(ctx)) return -EROFS;
int res = -EIO;
std::shared_ptr<DirNode> FSRoot = ctx->getRoot(&res);
if (!FSRoot) return res;
try {
res = FSRoot->rename(from, to);
} catch (encfs::Error &err) {
RLOG(ERROR) << "error caught in rename: " << err.what();
}
return res;
}
示例14: encfs_symlink
int encfs_symlink(const char *from, const char *to)
{
EncFS_Context *ctx = context();
return -EIO;
#if 0
int res = -EIO;
shared_ptr<DirNode> FSRoot = ctx->getRoot(&res);
if(!FSRoot)
return res;
try
{
// allow fully qualified names in symbolic links.
string fromCName = FSRoot->relativeCipherPath( from );
string toCName = FSRoot->cipherPath( to );
rLog(Info, "symlink %s -> %s", fromCName.c_str(), toCName.c_str());
// use setfsuid / setfsgid so that the new link will be owned by the
// uid/gid provided by the fuse_context.
int olduid = -1;
int oldgid = -1;
if(ctx->publicFilesystem)
{
fuse_context *context = fuse_get_context();
olduid = setfsuid( context->uid );
oldgid = setfsgid( context->gid );
}
res = ::symlink( fromCName.c_str(), toCName.c_str() );
if(olduid >= 0)
setfsuid( olduid );
if(oldgid >= 0)
setfsgid( oldgid );
if(res == -1)
res = -errno;
else
res = ESUCCESS;
} catch( rlog::Error &err )
{
rError("error caught in symlink");
err.log( _RLWarningChannel );
}
return res;
#endif
}
示例15: encfs_mknod
int encfs_mknod(const char *path, mode_t mode, dev_t rdev)
{
EncFS_Context *ctx = context();
int res = -EIO;
shared_ptr<DirNode> FSRoot = ctx->getRoot(&res);
if(!FSRoot)
return res;
try
{
shared_ptr<FileNode> fnode = FSRoot->lookupNode( path, "mknod" );
VLOG(1) << "mknod on " << fnode->cipherName()
<< ", mode " << mode << ", dev " << rdev;
uid_t uid = 0;
gid_t gid = 0;
if(ctx->publicFilesystem)
{
fuse_context *context = fuse_get_context();
uid = context->uid;
gid = context->gid;
}
res = fnode->mknod( mode, rdev, uid, gid );
// Is this error due to access problems?
if(ctx->publicFilesystem && -res == EACCES)
{
// try again using the parent dir's group
string parent = fnode->plaintextParent();
LOG(INFO) << "attempting public filesystem workaround for "
<< parent.c_str();
shared_ptr<FileNode> dnode =
FSRoot->lookupNode( parent.c_str(), "mknod" );
struct stat st;
if(dnode->getAttr( &st ) == 0)
res = fnode->mknod( mode, rdev, uid, st.st_gid );
}
} catch( Error &err )
{
LOG(ERROR) << "error caught in mknod: " << err.what();
}
return res;
}