示例#1
0
int impl_fuse_context::get_file_information(
    LPCWSTR file_name, LPBY_HANDLE_FILE_INFORMATION handle_file_information,
    PDOKAN_FILE_INFO dokan_file_info) {
  std::string fname = unixify(wchar_to_utf8_cstr(file_name));

  if (!ops_.getattr)
    return -EINVAL;

  struct FUSE_STAT st = {0};
  CHECKED(ops_.getattr(fname.c_str(), &st));
  if (S_ISLNK(st.st_mode)) {
    std::string resolved;
    CHECKED(resolve_symlink(fname, &resolved));
    CHECKED(ops_.getattr(resolved.c_str(), &st));
  }

  handle_file_information->nNumberOfLinks = st.st_nlink;
  if ((st.st_mode & S_IFDIR) == S_IFDIR)
    dokan_file_info->IsDirectory = TRUE;
  convertStatlikeBuf(&st, fname, handle_file_information);

  uint32_t attrs = 0xFFFFFFFFu;
  if (ops_.win_get_attributes)
    attrs = ops_.win_get_attributes(fname.c_str());
  if (attrs != 0xFFFFFFFFu)
    handle_file_information->dwFileAttributes = attrs;

  return 0;
}
示例#2
0
int impl_fuse_context::walk_directory(void *buf, const char *name,
									  const struct stat *stbuf, FUSE_OFF_T off)
{
	walk_data *wd=(walk_data*)buf;
	WIN32_FIND_DATAW find_data={0};

	utf8_to_wchar_buf(name,find_data.cFileName,MAX_PATH);
	GetShortPathNameW(find_data.cFileName,find_data.cAlternateFileName,MAX_PATH);

	struct FUSE_STAT stat={0};

	if (stbuf!=NULL)
		stat=*stbuf;
	else
	{
		//No stat buffer - use 'getattr'.
		//TODO: fill directory params here!!!
		if (strcmp(name,".")==0 || strcmp(name,"..")==0) //Special entries
			stat.st_mode|=S_IFDIR;
		else
			CHECKED(wd->ctx->ops_.getattr((wd->dirname+name).c_str(),&stat));
	}

	if (S_ISLNK(stat.st_mode))
	{
		std::string resolved;
		CHECKED(wd->ctx->resolve_symlink(wd->dirname+name,&resolved));
		CHECKED(wd->ctx->ops_.getattr(resolved.c_str(),&stat));
	}

	convertStatlikeBuf(&stat,name,&find_data);
	return wd->delegate(&find_data,wd->DokanFileInfo);
}
示例#3
0
win_error impl_fuse_context::create_file(LPCWSTR file_name, DWORD access_mode, 
								   DWORD share_mode, DWORD creation_disposition, 
								   DWORD flags_and_attributes, 
								   PDOKAN_FILE_INFO dokan_file_info)
{
	std::string fname=unixify(wchar_to_utf8_cstr(file_name));
	dokan_file_info->Context=0;

	if (!ops_.getattr)
		return -EINVAL;

	struct FUSE_STAT stbuf={0};
	//Check if the target file/directory exists
	if (ops_.getattr(fname.c_str(),&stbuf)<0)
	{
		//Nope.		
		if (dokan_file_info->IsDirectory) 
			return -EINVAL; //We can't create directories using CreateFile
		return do_create_file(file_name, creation_disposition, share_mode, access_mode,
			dokan_file_info);
	} else
	{		
		if (S_ISLNK(stbuf.st_mode))
		{
			//Get link's target
			CHECKED(resolve_symlink(fname,&fname));
			CHECKED(ops_.getattr(fname.c_str(),&stbuf));
		}

		if ((stbuf.st_mode&S_IFDIR)==S_IFDIR)
		{
			//Existing directory
			//TODO: add access control
			dokan_file_info->IsDirectory=TRUE;
			return do_open_dir(file_name,dokan_file_info);
		} else
		{
			//Existing file
			//Check if we'll be able to truncate or delete the opened file
			//TODO: race condition here?
			if (creation_disposition==CREATE_ALWAYS)
			{
				if (!ops_.unlink) return -EINVAL;
				CHECKED(ops_.unlink(fname.c_str())); //Delete file
				//And create it!
				return do_create_file(file_name,creation_disposition, share_mode,
					access_mode,dokan_file_info);
			} else if (creation_disposition==TRUNCATE_EXISTING)
			{
				if (!ops_.truncate) return -EINVAL;
				CHECKED(ops_.truncate(fname.c_str(),0));
			} else if (creation_disposition==CREATE_NEW)
			{
				return win_error(ERROR_FILE_EXISTS, true);
			}

			return do_open_file(file_name, share_mode, access_mode, dokan_file_info);
		}
	}
}
示例#4
0
文件: vm.cpp 项目: osprey-lang/ovum
int VM::New(VMStartParams &params, Box<VM> &result)
{
	int status__;
	{
		if (!vmKey.IsValid())
			CHECKED_MEM(vmKey.Alloc());

		Box<VM> vm(new(std::nothrow) VM(params));
		CHECKED_MEM(vm.get());

		// Most things rely on static strings, so initialize them first.
		CHECKED_MEM(vm->strings = StaticStrings::New());

		CHECKED_MEM(vm->mainThread = Thread::New(vm.get()));
		CHECKED_MEM(vm->gc = GC::New(vm.get()));
		CHECKED_MEM(vm->standardTypeCollection = StandardTypeCollection::New(vm.get()));
		CHECKED_MEM(vm->modules = ModulePool::New(10));
		CHECKED_MEM(vm->refSignatures = Box<RefSignaturePool>(new(std::nothrow) RefSignaturePool()));

		CHECKED(vm->LoadModules(params));
		CHECKED(vm->InitArgs(params.argc, params.argv));

		result = std::move(vm);
	}

	status__ = OVUM_SUCCESS;
retStatus__:
	return status__;
}
示例#5
0
int impl_fuse_context::open_directory(LPCWSTR file_name, 
									  PDOKAN_FILE_INFO dokan_file_info)
{
	std::string fname=unixify(wchar_to_utf8_cstr(file_name));	

	if (ops_.opendir)
		return do_open_dir(file_name,dokan_file_info);

	//We don't have opendir(), so the most we can do is make sure
	//that the target is indeed a directory
	struct FUSE_STAT st={0};
	CHECKED(ops_.getattr(fname.c_str(),&st));
	if (S_ISLNK(st.st_mode))
	{
		std::string resolved;
		CHECKED(resolve_symlink(fname,&resolved));	
		CHECKED(ops_.getattr(resolved.c_str(),&st));
	}

	//Not a directory
	if ((st.st_mode&S_IFDIR)!=S_IFDIR)
		return -ENOTDIR;
	
	dokan_file_info->Context=(ULONG64)NULL; //Do not want to attach anything
	return 0; //Use readdir here?
}
示例#6
0
int impl_fuse_context::do_create_file(LPCWSTR FileName, DWORD Disposition, DWORD share_mode, DWORD Flags,
									PDOKAN_FILE_INFO DokanFileInfo)
{
	std::string fname=unixify(wchar_to_utf8_cstr(FileName));

	//Create file?
	if (Disposition!=CREATE_NEW && Disposition!=CREATE_ALWAYS && Disposition!=OPEN_ALWAYS)		
		return -ENOENT; //No, we're trying to open an existing file!

	if (!ops_.create)
	{
		//Use mknod+open.
		if (!ops_.mknod || !ops_.open) return -EINVAL;
		CHECKED(ops_.mknod(fname.c_str(),filemask_,0));
		return do_open_file(FileName, share_mode, Flags, DokanFileInfo);
	}

	std::auto_ptr<impl_file_handle> file;
	CHECKED(file_locks.get_file(fname,false,Flags,share_mode,file));

	fuse_file_info finfo={0};
	finfo.flags=O_CREAT | O_EXCL | convert_flags(Flags); //TODO: these flags should be OK for new files?	
	
	CHECKED(ops_.create(fname.c_str(),filemask_,&finfo));

	DokanFileInfo->Context=reinterpret_cast<ULONG64>(file.release());
	return 0;
}
示例#7
0
int impl_fuse_context::move_file(LPCWSTR file_name, LPCWSTR new_file_name,
                                 BOOL replace_existing,
                                 PDOKAN_FILE_INFO dokan_file_info) {
  if (!ops_.rename || !ops_.getattr)
    return -EINVAL;

  std::string name = unixify(wchar_to_utf8_cstr(file_name));
  std::string new_name = unixify(wchar_to_utf8_cstr(new_file_name));

  struct FUSE_STAT stbuf = {0};
  if (ops_.getattr(new_name.c_str(), &stbuf) != -ENOENT) {
    if (!replace_existing)
      return -EEXIST;

    // Cannot delete directory
    if ((stbuf.st_mode & S_IFDIR) != 0)
      return -EISDIR;
    if (!ops_.unlink)
      return -EINVAL;
    CHECKED(ops_.unlink(new_name.c_str()));
  }

  // this can happen cause DeleteFile in Windows can return success even if
  // file is still in the file system
  if (ops_.getattr(new_name.c_str(), &stbuf) != -ENOENT) {
    return -EEXIST;
  }

  CHECKED(ops_.rename(name.c_str(), new_name.c_str()));
  file_locks.renamed_file(name, new_name);
  return 0;
}
示例#8
0
int impl_fuse_context::check_and_resolve(std::string *name) {
  if (!ops_.getattr)
    return -EINVAL;

  struct FUSE_STAT stat = {0};
  CHECKED(ops_.getattr(name->c_str(), &stat));
  if (S_ISLNK(stat.st_mode))
    CHECKED(resolve_symlink(*name, name));

  return 0;
}
示例#9
0
	~mmio_stream_raii() {

				data_info.dwFlags |= MMIO_DIRTY;
				CHECKED(mmioSetInfo( mmio, &data_info, 0 ));

			CHECKED(mmioAscend( mmio, &data_chunk, 0 ));

		CHECKED(mmioAscend( mmio, &WAVE_chunk, 0 ));

		CHECKED(mmioClose( mmio, 0 ));
		mmio = NULL;

	}
示例#10
0
int impl_fuse_context::walk_directory(void *buf, const char *name, 
									  const struct FUSE_STAT *stbuf, FUSE_OFF_T off)
{
	walk_data *wd=(walk_data*)buf;
	WIN32_FIND_DATAW find_data={0};	

	utf8_to_wchar_buf(name,find_data.cFileName,MAX_PATH);
	// fix name if wrong encoding
	if (!find_data.cFileName[0]) {
		struct FUSE_STAT stbuf={0};
		utf8_to_wchar_buf_old(name,find_data.cFileName,MAX_PATH);
		std::string new_name = wchar_to_utf8_cstr(find_data.cFileName);
		if (wd->ctx->ops_.getattr && wd->ctx->ops_.rename && new_name.length() && wd->ctx->ops_.getattr(new_name.c_str(),&stbuf) == -ENOENT)
			wd->ctx->ops_.rename(name, new_name.c_str());
	}
	memset(find_data.cAlternateFileName, 0, sizeof(find_data.cAlternateFileName));

	struct FUSE_STAT stat={0};

	if (stbuf!=NULL)
		stat=*stbuf;		
	else
	{
		//No stat buffer - use 'getattr'.
		//TODO: fill directory params here!!!
		if (strcmp(name,".")==0 || strcmp(name,"..")==0) //Special entries
			stat.st_mode|=S_IFDIR;
		else
			CHECKED(wd->ctx->ops_.getattr((wd->dirname+name).c_str(),&stat));
	}

	if (S_ISLNK(stat.st_mode))
	{
		std::string resolved;
		CHECKED(wd->ctx->resolve_symlink(wd->dirname+name,&resolved));		
		CHECKED(wd->ctx->ops_.getattr(resolved.c_str(),&stat));		
	}
	
	convertStatlikeBuf(&stat,name,&find_data);

	uint32_t attrs = 0xFFFFFFFFu;
	if (wd->ctx->ops_.win_get_attributes)
		attrs = wd->ctx->ops_.win_get_attributes((wd->dirname+name).c_str());
	if (attrs != 0xFFFFFFFFu)
		find_data.dwFileAttributes = attrs;
	
	return wd->delegate(&find_data,wd->DokanFileInfo);
}
示例#11
0
int impl_fuse_context::move_file(LPCWSTR file_name, LPCWSTR new_file_name,
			  BOOL replace_existing, PDOKAN_FILE_INFO dokan_file_info)
{
	if (!ops_.rename || !ops_.getattr) return -EINVAL;

	std::string name=unixify(wchar_to_utf8_cstr(file_name));
	std::string new_name=unixify(wchar_to_utf8_cstr(new_file_name));

	struct FUSE_STAT stbuf={0};
	if (ops_.getattr(new_name.c_str(),&stbuf)!=-ENOENT)
	{
		//Cannot delete directory
		if ((stbuf.st_mode&S_IFDIR)==0 && ops_.unlink)
        {
            if (replace_existing)
            {
                CHECKED(ops_.unlink(new_name.c_str()));
            }
            else
            {
                return -EEXIST;
            }
		}
	}

	return ops_.rename(name.c_str(),new_name.c_str());
}
示例#12
0
int impl_fuse_context::do_open_file(LPCWSTR FileName, DWORD Flags,
									PDOKAN_FILE_INFO DokanFileInfo)
{
	if (!ops_.open) return -EINVAL;
	std::string fname=unixify(wchar_to_utf8_cstr(FileName));
	CHECKED(check_and_resolve(&fname));

	fuse_file_info finfo={0};
	//if ((ShareMode & FILE_SHARE_READ) || (ShareMode & FILE_SHARE_DELETE))
	//TODO: add sharing support?
	finfo.flags=convert_flags(Flags);

	CHECKED(ops_.open(fname.c_str(),&finfo));
	DokanFileInfo->Context=reinterpret_cast<ULONG64>(new impl_file_handle(fname,false,&finfo));
	return 0;
}
示例#13
0
int impl_fuse_context::write_file(LPCWSTR /*file_name*/, LPCVOID buffer,
			   DWORD num_bytes_to_write,LPDWORD num_bytes_written,
			   LONGLONG offset, PDOKAN_FILE_INFO dokan_file_info)
{
	//Please note, that we ifnore file_name here, because it might
	//have been retargeted by a symlink.

	*num_bytes_written=0; //Conform to ReadFile semantics

	if (!ops_.write) return -EINVAL;

	impl_file_handle *hndl=reinterpret_cast<impl_file_handle*>(dokan_file_info->Context);
	if (!hndl)
		return -EINVAL;
	if (hndl->is_dir())
		return -EACCES;

	//Clip the maximum write size
	if (num_bytes_to_write>conn_info_.max_write)
		num_bytes_to_write=conn_info_.max_write;

	FUSE_OFF_T off;
	CHECKED(cast_from_longlong(offset,&off));

	fuse_file_info finfo(hndl->make_finfo());
	int res=ops_.write(hndl->get_name().c_str(),(const char*)buffer,
		num_bytes_to_write, off,&finfo);
	if (res<0) return res; //Error

	//OK!
	*num_bytes_written=res;
	return 0;
}
示例#14
0
int impl_fuse_context::unlock_file(LPCWSTR file_name, LONGLONG byte_offset,
                                   LONGLONG length,
                                   PDOKAN_FILE_INFO dokan_file_info) {
  impl_file_handle *hndl =
      reinterpret_cast<impl_file_handle *>(dokan_file_info->Context);
  if (!hndl)
    return -EINVAL;
  if (hndl->is_dir())
    return -EACCES;

  FUSE_OFF_T off;
  CHECKED(cast_from_longlong(byte_offset, &off));

  if (ops_.lock) {
    fuse_file_info finfo(hndl->make_finfo());

    struct flock lock;
    lock.l_type = F_UNLCK;
    lock.l_whence = SEEK_SET;
    lock.l_start = off;
    lock.l_len = length;

    return ops_.lock(hndl->get_name().c_str(), &finfo, F_SETLK, &lock);
  }

  return hndl->unlock(byte_offset, length);
}
示例#15
0
void DesktopDuplication::init()
{
	IDXGIFactory1* dxgiFactory = nullptr;
	CHECKED(hr, CreateDXGIFactory1(__uuidof(IDXGIFactory1), reinterpret_cast<void**>(&dxgiFactory)));

	IDXGIAdapter1* dxgiAdapter = nullptr;
	CHECKED(hr, dxgiFactory->EnumAdapters1(adapter, &dxgiAdapter));
	dxgiFactory->Release();

	CHECKED(hr, D3D11CreateDevice(dxgiAdapter,
		D3D_DRIVER_TYPE_UNKNOWN,
		NULL,
		NULL,
		NULL,
		NULL,
		D3D11_SDK_VERSION,
		&d3dDevice,
		NULL,
		&d3dContext));

	IDXGIOutput* dxgiOutput = nullptr;
	CHECKED(hr, dxgiAdapter->EnumOutputs(output, &dxgiOutput));
	dxgiAdapter->Release();

	IDXGIOutput1* dxgiOutput1 = nullptr;
	CHECKED(hr, dxgiOutput->QueryInterface(__uuidof(dxgiOutput1), reinterpret_cast<void**>(&dxgiOutput1)));
	dxgiOutput->Release();

	IDXGIDevice* dxgiDevice = nullptr;
	CHECKED(hr, d3dDevice->QueryInterface(__uuidof(IDXGIDevice), reinterpret_cast<void**>(&dxgiDevice)));

	CHECKED(hr, dxgiOutput1->DuplicateOutput(dxgiDevice, &outputDuplication));
	dxgiOutput1->Release();
	dxgiDevice->Release();
}
示例#16
0
	mmio_stream_raii( const std::string & filename, const commandlineflags & flags_ ) : flags(flags_), mmio(NULL) {

		ZeroMemory( &waveformatex, sizeof( WAVEFORMATEX ) );
		waveformatex.cbSize = 0;
		waveformatex.wFormatTag = flags.use_float ? WAVE_FORMAT_IEEE_FLOAT : WAVE_FORMAT_PCM;
		waveformatex.nChannels = flags.channels;
		waveformatex.nSamplesPerSec = flags.samplerate;
		waveformatex.wBitsPerSample = flags.use_float ? 32 : 16;
		waveformatex.nBlockAlign = flags.channels * ( waveformatex.wBitsPerSample / 8 );
		waveformatex.nAvgBytesPerSec = waveformatex.nSamplesPerSec * waveformatex.nBlockAlign;

		#if defined(WIN32) && defined(UNICODE)
			wchar_t * tmp = wcsdup( utf8_to_wstring( filename ).c_str() );
			mmio = mmioOpen( tmp, NULL, MMIO_ALLOCBUF | MMIO_READWRITE | MMIO_CREATE );
			free( tmp );
			tmp = 0;
		#else
			char * tmp = strdup( filename.c_str() );
			mmio = mmioOpen( tmp, NULL, MMIO_ALLOCBUF | MMIO_READWRITE | MMIO_CREATE );
			free( tmp );
			tmp = 0;
		#endif
		
		ZeroMemory( &WAVE_chunk, sizeof( MMCKINFO ) );
		WAVE_chunk.fccType = mmioFOURCC('W', 'A', 'V', 'E');
		CHECKED(mmioCreateChunk( mmio, &WAVE_chunk, MMIO_CREATERIFF ));

			ZeroMemory( &fmt__chunk, sizeof( MMCKINFO ) );
			fmt__chunk.ckid = mmioFOURCC('f', 'm', 't', ' ');
			fmt__chunk.cksize = sizeof( WAVEFORMATEX );
			CHECKED(mmioCreateChunk( mmio, &fmt__chunk, 0 ));

				mmioWrite( mmio, (const char*)&waveformatex, sizeof( WAVEFORMATEX ) );

			CHECKED(mmioAscend( mmio, &fmt__chunk, 0 ));

			ZeroMemory( &data_chunk, sizeof( MMCKINFO ) );
			data_chunk.ckid = mmioFOURCC('d', 'a', 't', 'a');
			data_chunk.cksize = 0;
			CHECKED(mmioCreateChunk( mmio, &data_chunk, 0 ));

				ZeroMemory( &data_info, sizeof( MMIOINFO ) );
				CHECKED(mmioGetInfo( mmio, &data_info, 0 ));

	}
示例#17
0
int impl_fuse_context::set_end_of_file(LPCWSTR file_name, LONGLONG byte_offset,
                                       PDOKAN_FILE_INFO dokan_file_info) {
  FUSE_OFF_T off;
  CHECKED(cast_from_longlong(byte_offset, &off));
  std::string fname = unixify(wchar_to_utf8_cstr(file_name));
  CHECKED(check_and_resolve(&fname));

  impl_file_handle *hndl =
      reinterpret_cast<impl_file_handle *>(dokan_file_info->Context);
  if (hndl && ops_.ftruncate) {
    fuse_file_info finfo(hndl->make_finfo());
    return ops_.ftruncate(hndl->get_name().c_str(), off, &finfo);
  }

  if (!ops_.truncate)
    return -EINVAL;
  return ops_.truncate(fname.c_str(), off);
}
示例#18
0
文件: path.c 项目: Dazdin9o/DECAF
ABool
path_exists( const char*  path )
{
    int  ret;
    if (path == NULL)
        return 0;
    CHECKED(ret, access(path, F_OK));
    return (ret == 0) || (errno != ENOENT);
}
示例#19
0
文件: path.c 项目: Dazdin9o/DECAF
ABool
path_can_exec( const char* path )
{
    int  ret;
    if (path == NULL)
        return 0;
    CHECKED(ret, access(path, X_OK));
    return (ret == 0);
}
示例#20
0
int impl_fuse_context::set_file_time(PCWSTR file_name,
                                     const FILETIME *creation_time,
                                     const FILETIME *last_access_time,
                                     const FILETIME *last_write_time,
                                     PDOKAN_FILE_INFO dokan_file_info) {
  if (!ops_.utimens && !ops_.utime && !ops_.win_set_times)
    return -EINVAL;

  if (ops_.win_set_times) {
    std::string fname = unixify(wchar_to_utf8_cstr(file_name));
    CHECKED(check_and_resolve(&fname));

    impl_file_handle *hndl =
        reinterpret_cast<impl_file_handle *>(dokan_file_info->Context);
    if (!hndl)
      return ops_.win_set_times(fname.c_str(), NULL, creation_time,
                                last_access_time, last_write_time);

    if (hndl->is_dir())
      return -EACCES;

    fuse_file_info finfo(hndl->make_finfo());

    return ops_.win_set_times(fname.c_str(), &finfo, creation_time,
                              last_access_time, last_write_time);
  }

  if (!ops_.getattr)
    return -EINVAL;

  std::string fname = unixify(wchar_to_utf8_cstr(file_name));
  CHECKED(check_and_resolve(&fname));

  struct FUSE_STAT st = {0};
  CHECKED(ops_.getattr(fname.c_str(), &st));

  if (ops_.utimens) {
    struct timespec tv[2] = {0};
    // TODO: support nanosecond resolution
    // Access time
    CHECKED(helper_set_time_struct(last_access_time, st.st_atim.tv_sec,
                                   &(tv[0].tv_sec)));
    // Modification time
    CHECKED(helper_set_time_struct(last_write_time, st.st_mtim.tv_sec,
                                   &(tv[1].tv_sec)));

    return ops_.utimens(fname.c_str(), tv);
  } else {
    struct utimbuf ut = {0};
    // Access time
    CHECKED(helper_set_time_struct(last_access_time, st.st_atim.tv_sec,
                                   &(ut.actime)));
    // Modification time
    CHECKED(helper_set_time_struct(last_write_time, st.st_mtim.tv_sec,
                                   &(ut.modtime)));

    return ops_.utime(fname.c_str(), &ut);
  }
}
示例#21
0
int impl_fuse_context::find_files(LPCWSTR file_name,
                                  PFillFindData fill_find_data,
                                  PDOKAN_FILE_INFO dokan_file_info) {
  if ((!ops_.readdir && !ops_.getdir) || !ops_.getattr)
    return -EINVAL;

  std::string fname = unixify(wchar_to_utf8_cstr(file_name));
  CHECKED(check_and_resolve(&fname));

  walk_data wd;
  wd.ctx = this;
  wd.dirname = fname;
  if (*fname.rbegin() != '/')
    wd.dirname.append("/");
  wd.delegate = fill_find_data;
  wd.DokanFileInfo = dokan_file_info;

  if (ops_.readdir) {
    impl_file_handle *hndl =
        reinterpret_cast<impl_file_handle *>(dokan_file_info->Context);
    if (hndl != NULL) {
      fuse_file_info finfo(hndl->make_finfo());
      return ops_.readdir(fname.c_str(), &wd, &walk_directory, 0, &finfo);
    } else
      return ops_.readdir(fname.c_str(), &wd, &walk_directory, 0, NULL);
  } else {
    CHECKED(
        ops_.getdir(fname.c_str(), (fuse_dirh_t)&wd, &walk_directory_getdir));
    // Convert returned data The getdir_data array will be filled during
    // getdir() call.
    // We emulate FUSE behavior and do not pass information directly to Dokan
    // in walk_directory_getdir callback. This can cause excessive network
    // traffic
    // in sshfs because it populates stat buffer cache AFTER calling our
    // callback.
    // See: cache.c file, function cache_dirfill() in SSHFS 2.2
    for (std::vector<std::string>::const_iterator f = wd.getdir_data.begin();
         f != wd.getdir_data.end(); ++f)
      CHECKED(walk_directory(&wd, f->c_str(), 0, 0));
  }

  return 0;
}
示例#22
0
int impl_fuse_context::do_open_file(LPCWSTR FileName, DWORD share_mode, DWORD Flags,
									PDOKAN_FILE_INFO DokanFileInfo)
{
	if (!ops_.open) return -EINVAL;
	std::string fname=unixify(wchar_to_utf8_cstr(FileName));
	CHECKED(check_and_resolve(&fname));

	std::auto_ptr<impl_file_handle> file;
	CHECKED(file_locks.get_file(fname,false,Flags,share_mode,file));

	fuse_file_info finfo={0};
	finfo.flags=convert_flags(Flags);

	CHECKED(ops_.open(fname.c_str(),&finfo));

	file->set_finfo(finfo);
	DokanFileInfo->Context=reinterpret_cast<ULONG64>(file.release());
	return 0;
}
示例#23
0
int impl_fuse_context::do_open_dir(LPCWSTR FileName, PDOKAN_FILE_INFO DokanFileInfo)
{
	if (ops_.opendir)
	{
		std::string fname=unixify(wchar_to_utf8_cstr(FileName));
		std::auto_ptr<impl_file_handle> file;
		// TODO access_mode
		CHECKED(file_locks.get_file(fname,true,0,FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,file));

		fuse_file_info finfo={0};
		CHECKED(ops_.opendir(fname.c_str(),&finfo));

		file->set_finfo(finfo);
		DokanFileInfo->Context=reinterpret_cast<ULONG64>(file.release());
		return 0;
	}

	DokanFileInfo->Context=0;
	return 0;
}
示例#24
0
int impl_fuse_context::do_create_file(LPCWSTR FileName, DWORD Disposition,
                                      DWORD share_mode, DWORD Flags,
                                      PDOKAN_FILE_INFO DokanFileInfo)
// Kernel mappsings:
// Disposition = CreateDisposition
// Flags = DesiredAccess
// share_mode = ShareAccess
{
  std::string fname = unixify(wchar_to_utf8_cstr(FileName));

  // Create file?
  if (Disposition != FILE_CREATE && Disposition != FILE_SUPERSEDE &&
      Disposition != FILE_OPEN_IF && Disposition != FILE_OVERWRITE_IF) {
    SetLastError(ERROR_FILE_NOT_FOUND);
    return -ENOENT; // No, we're trying to open an existing file!
  }

  if (!ops_.create) {
    // Use mknod+open.
    if (!ops_.mknod || !ops_.open)
      return -EINVAL;

    CHECKED(ops_.mknod(fname.c_str(), filemask_, 0));

    return do_open_file(FileName, share_mode, Flags, DokanFileInfo);
  }

  std::unique_ptr<impl_file_handle> file;
  CHECKED(file_locks.get_file(fname, false, Flags, share_mode, file));

  fuse_file_info finfo = {0};
  finfo.flags =
      O_CREAT | O_EXCL |
      convert_flags(Flags); // TODO: these flags should be OK for new files?

  CHECKED(ops_.create(fname.c_str(), filemask_, &finfo));

  file->set_finfo(finfo);
  DokanFileInfo->Context = reinterpret_cast<ULONG64>(file.release());
  return 0;
}
示例#25
0
AVES_API BEGIN_NATIVE_FUNCTION(aves_Utf16Encoding_getByteCount)
{
	// getByteCount(str)
	CHECKED(StringFromValue(thread, args + 1));

	Utf16Encoding *encoding = THISV.Get<Utf16Encoding>();

	Utf16Encoder enc(encoding->bigEndian);
	ssize_t byteCount = enc.GetByteCount(thread, args[1].v.string, true);

	VM_PushInt(thread, byteCount);
}
示例#26
0
	void write( const std::vector<std::int16_t*> buffers, std::size_t frames ) {
		for ( std::size_t frame = 0; frame < frames; frame++ ) {
			for ( std::size_t channel = 0; channel < buffers.size(); channel++ ) {
				if ( data_info.pchEndWrite - data_info.pchNext < static_cast<long>( sizeof( std::int16_t ) ) ) {
					data_info.dwFlags |= MMIO_DIRTY;
					CHECKED(mmioAdvance( mmio, &data_info, MMIO_WRITE ));
				}
				std::memcpy( data_info.pchNext, &( buffers[channel][frame] ), sizeof( std::int16_t ) );
				data_info.pchNext += sizeof( std::int16_t );
			}
		}
	}
示例#27
0
文件: path.c 项目: Dazdin9o/DECAF
/* try to make a directory. returns 0 on success, -1 on failure
 * (error code in errno) */
APosixStatus
path_mkdir( const char*  path, int  mode )
{
#ifdef _WIN32
    (void)mode;
    return _mkdir(path);
#else
    int  ret;
    CHECKED(ret, mkdir(path, mode));
    return ret;
#endif
}
示例#28
0
int impl_fuse_context::set_file_time(PCWSTR file_name, const FILETIME* creation_time,
				  const FILETIME* last_access_time, const FILETIME* last_write_time,
				  PDOKAN_FILE_INFO dokan_file_info)
{
	if (!ops_.utimens && !ops_.utime) return -EINVAL;
	if (!ops_.getattr) return -EINVAL;

	std::string fname=unixify(wchar_to_utf8_cstr(file_name));
	CHECKED(check_and_resolve(&fname));

	struct FUSE_STAT st={0};
	CHECKED(ops_.getattr(fname.c_str(),&st));

	if (ops_.utimens)
	{
		struct timespec tv[2]={{0,},};
		//TODO: support nanosecond resolution
		//Access time
		CHECKED(helper_set_time_struct(last_access_time,st.st_atime,&(tv[0].tv_sec)));
		//Modification time
		CHECKED(helper_set_time_struct(last_write_time,st.st_mtime,&(tv[1].tv_sec)));

		return ops_.utimens(fname.c_str(),tv);
	} else
	{
		struct utimbuf ut={0};
		//Access time
		CHECKED(helper_set_time_struct(last_access_time,st.st_atime,&(ut.actime)));
		//Modification time
		CHECKED(helper_set_time_struct(last_write_time,st.st_mtime,&(ut.modtime)));

		return ops_.utime(fname.c_str(),&ut);
	}
}
示例#29
0
文件: path.c 项目: Dazdin9o/DECAF
/* checks that a path points to a directory */
ABool
path_is_dir( const char*  path )
{
    int          ret;
    struct stat  st;

    if (path == NULL)
        return 0;
    CHECKED(ret, stat(path, &st));
    if (ret < 0)
        return 0;

    return S_ISDIR(st.st_mode);
}
示例#30
0
ID3D11Texture2D* DesktopDuplication::copyToStaging(ID3D11Texture2D* tex)
{
	D3D11_TEXTURE2D_DESC texDesc;
	tex->GetDesc(&texDesc);

	stagingTexDesc = getStagingTexDesc(texDesc);

	ID3D11Texture2D* stagingTex;
	CHECKED(hr, d3dDevice->CreateTexture2D(&stagingTexDesc, nullptr, &stagingTex));

	d3dContext->CopyResource(stagingTex, tex);

	return stagingTex;
}