当前位置: 首页>>代码示例>>C++>>正文


C++ EncFS_Context类代码示例

本文整理汇总了C++中EncFS_Context的典型用法代码示例。如果您正苦于以下问题:C++ EncFS_Context类的具体用法?C++ EncFS_Context怎么用?C++ EncFS_Context使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了EncFS_Context类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: 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;
}
开发者ID:tarruda,项目名称:encfs,代码行数:32,代码来源:encfs.cpp

示例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);
    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;
}
开发者ID:tarruda,项目名称:encfs,代码行数:32,代码来源:encfs.cpp

示例3: 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;
}
开发者ID:HirasawaRUS,项目名称:encfs4win,代码行数:32,代码来源:encfs.cpp

示例4: 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;
}
开发者ID:HirasawaRUS,项目名称:encfs4win,代码行数:33,代码来源:encfs.cpp

示例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 );
    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;
}
开发者ID:tarruda,项目名称:encfs,代码行数:31,代码来源:encfs.cpp

示例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;
}
开发者ID:aidan-fitz,项目名称:encfs,代码行数:34,代码来源:encfs.cpp

示例7: _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;
}
开发者ID:aidan-fitz,项目名称:encfs,代码行数:26,代码来源:encfs.cpp

示例8: 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;
}
开发者ID:aidan-fitz,项目名称:encfs,代码行数:30,代码来源:encfs.cpp

示例9: 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;
}
开发者ID:aidan-fitz,项目名称:encfs,代码行数:29,代码来源:encfs.cpp

示例10: 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;
}
开发者ID:HirasawaRUS,项目名称:encfs4win,代码行数:33,代码来源:encfs.cpp

示例11: idleMonitor

static
void * idleMonitor(void *_arg)
{
  EncFS_Context *ctx = (EncFS_Context*)_arg;
  shared_ptr<EncFS_Args> arg = ctx->args;

  const int timeoutCycles = 60 * arg->idleTimeout / ActivityCheckInterval;
  int idleCycles = 0;

  ctx->wakeupMutex.lock();

  while(ctx->running)
  {
    int usage = ctx->getAndResetUsageCounter();

    if(usage == 0 && ctx->isMounted())
      ++idleCycles;
    else
      idleCycles = 0;

    if(idleCycles >= timeoutCycles)
    {
      int openCount = ctx->openFileCount();
      if( openCount == 0 && unmountFS( ctx ) )
      {
#ifdef CMAKE_USE_PTHREADS_INIT
        // wait for main thread to wake us up
        pthread_cond_wait( &ctx->wakeupCond, &ctx->wakeupMutex._mutex );
#endif
        break;
      }

      VLOG(1) << "num open files: " << openCount;
    }

    VLOG(1) << "idle cycle count: " << idleCycles 
      << ", timeout after " << timeoutCycles;

    struct timeval currentTime;
    gettimeofday( &currentTime, 0 );
    struct timespec wakeupTime;
    wakeupTime.tv_sec = currentTime.tv_sec + ActivityCheckInterval;
    wakeupTime.tv_nsec = currentTime.tv_usec * 1000;
#ifdef CMAKE_USE_PTHREADS_INIT
    pthread_cond_timedwait( &ctx->wakeupCond, 
        &ctx->wakeupMutex._mutex, &wakeupTime );
#endif
  }

  ctx->wakeupMutex.unlock();

  VLOG(1) << "Idle monitoring thread exiting";

  return 0;
}
开发者ID:bentolor,项目名称:encfs,代码行数:55,代码来源:main.cpp

示例12: encfs_release

/*
Note: This is advisory -- it might benefit us to keep file nodes around for a
bit after they are released just in case they are reopened soon.  But that
requires a cache layer.
 */
int encfs_release(const char *path, struct fuse_file_info *finfo) {
  EncFS_Context *ctx = context();

  try {
    ctx->eraseNode(path, reinterpret_cast<FileNode *>(finfo->fh));
    return ESUCCESS;
  } catch (encfs::Error &err) {
    RLOG(ERROR) << "error caught in release: " << err.what();
    return -EIO;
  }
}
开发者ID:aidan-fitz,项目名称:encfs,代码行数:16,代码来源:encfs.cpp

示例13: encfs_win_get_attributes

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());
}
开发者ID:HirasawaRUS,项目名称:encfs4win,代码行数:13,代码来源:encfs.cpp

示例14: idleMonitor

static
void * idleMonitor(void *_arg)
{
    EncFS_Context *ctx = (EncFS_Context*)_arg;
    shared_ptr<EncFS_Args> arg = ctx->args;

    const int timeoutCycles = 60 * arg->idleTimeout / ActivityCheckInterval;
    int idleCycles = 0;

    pthread_mutex_lock( &ctx->wakeupMutex );
    
    while(ctx->running)
    {
	int usage = ctx->getAndResetUsageCounter();

	if(usage == 0 && ctx->isMounted())
	    ++idleCycles;
	else
	    idleCycles = 0;
	
	if(idleCycles >= timeoutCycles)
	{
	    int openCount = ctx->openFileCount();
	    if( openCount == 0 && unmountFS( ctx ) )
	    {
		// wait for main thread to wake us up
		pthread_cond_wait( &ctx->wakeupCond, &ctx->wakeupMutex );
		break;
	    }
		
	    rDebug("num open files: %i", openCount );
	}
	    
	rDebug("idle cycle count: %i, timeout after %i", idleCycles,
		timeoutCycles);

	struct timeval currentTime;
	gettimeofday( &currentTime, 0 );
	struct timespec wakeupTime;
	wakeupTime.tv_sec = currentTime.tv_sec + ActivityCheckInterval;
	wakeupTime.tv_nsec = currentTime.tv_usec * 1000;
	pthread_cond_timedwait( &ctx->wakeupCond, 
		&ctx->wakeupMutex, &wakeupTime );
    }
    
    pthread_mutex_unlock( &ctx->wakeupMutex );

    rDebug("Idle monitoring thread exiting");

    return 0;
}
开发者ID:ghostbar,项目名称:encfs.deb,代码行数:51,代码来源:main.cpp

示例15: encfs_release

/*
Note: This is advisory -- it might benefit us to keep file nodes around for a
bit after they are released just in case they are reopened soon.  But that
requires a cache layer.
 */
int encfs_release(const char *path, struct fuse_file_info *finfo)
{
  EncFS_Context *ctx = context();

  try
  {
    ctx->eraseNode( path, (void*)(uintptr_t)finfo->fh );
    return ESUCCESS;
  } catch( Error &err )
  {
    LOG(ERROR) << "error caught in release: " << err.what();
    return -EIO;
  }
}
开发者ID:tarruda,项目名称:encfs,代码行数:19,代码来源:encfs.cpp


注:本文中的EncFS_Context类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。