Exemplo n.º 1
0
//*******************************************************************
// compare_files                                             PRIVATE
//-------------------------------------------------------------------
// Porownanie wszystkich przyslanych plikow.
// Kryterium porownywania jest czas ich ostatniej modyfikacji.
//*******************************************************************
void QBtCompareDirsDialog::compare_files( const FileMap& in_data1, const FileMap& in_data2 )
{
   QBtShared::idle();
   if( !continue_ ) return;

   AllItems data_all = AllItems();
   join_files( data_all, in_data1 );
   join_files( data_all, in_data2 );
   if( data_all.empty() ) return;

   RowData row_data;
   AllItems::const_iterator it = data_all.begin();
   const AllItems::const_iterator end = data_all.end();
   while( continue_ && ( it != end ) ) {
      const QString name = it.key();
      const FileMap::const_iterator it1 = in_data1.find( name );
      const FileMap::const_iterator it2 = in_data2.find( name );
      const bool is1 = ( it1 != in_data1.end() );
      const bool is2 = ( it2 != in_data2.end() );

      row_data.reset();
      if( is1 ) row_data.set_lft( name, it1.value().absoluteFilePath() );
      if( is2 ) row_data.set_rgt( name, it2.value().absoluteFilePath() );
      if( is1 && is2 ) {
         row_data.separator( check_files( row_data.path1(), row_data.path2() ) );
      }
      add_row( row_data );
      ++it;
   }
}
Exemplo n.º 2
0
FileMap*
FileMapBuffer::createMap(const char* filename)
{
	int fd;
	size_t length;

	fd = ::open(filename, O_RDONLY | O_BINARY);
	if (fd < 0) {
		LOGW("Unable to open file '%s': %s\n", filename, strerror(errno));
		return NULL;
	}

	length = lseek(fd, 0, SEEK_END);
	lseek(fd, 0, SEEK_SET);

	FileMap* map = new FileMap();
	if (!map) {
		LOGW("Unable to create file map for '%s': %s\n", filename, strerror(errno));
		return NULL;
	}

	if (!map->create(filename, fd, 0, length, true)) {
		map->release();
		LOGW("Unable to create file map for '%s': %s\n", filename, strerror(errno));
		return NULL;
	}

	close(fd);

	return map;
}
Exemplo n.º 3
0
void Memory::unmap(hostptr_t addr, size_t /*count*/)
{
	FileMapEntry entry = Files.find(addr);
	if(Files.remove(addr) == false) return;
	UnmapViewOfFile(entry.address());
	CloseHandle(entry.handle());
}
Exemplo n.º 4
0
extern "C" void
fssh_file_map_set_size(void* _map, fssh_off_t size)
{
	FileMap* map = (FileMap*)_map;
	if (map == NULL)
		return;

	map->SetSize(size);
}
Exemplo n.º 5
0
extern "C" fssh_status_t
fssh_file_map_set_mode(void* _map, uint32_t mode)
{
	FileMap* map = (FileMap*)_map;
	if (map == NULL)
		return FSSH_B_BAD_VALUE;

	return map->SetMode(mode);
}
Exemplo n.º 6
0
extern "C" void
fssh_file_map_invalidate(void* _map, fssh_off_t offset, fssh_off_t size)
{
	FileMap* map = (FileMap*)_map;
	if (map == NULL)
		return;

	map->Invalidate(offset, size);
}
Exemplo n.º 7
0
// Call instead of delete:
void DataFile::release ()
{
    if (--_ref_count <= 0)
    {
        FileMap::iterator i = open_data_files.find (_filename);
        LOG_ASSERT (i != open_data_files.end ());
        open_data_files.erase (i);
        delete this;
    }
}
Exemplo n.º 8
0
//*******************************************************************
// join_files                                                PRIVATE
//*******************************************************************
void QBtCompareDirsDialog::join_files( AllItems& out_set, const FileMap& in_map  ) const
{
   if( in_map.empty() ) return;
   
   FileMap::const_iterator it = in_map.begin();
   const FileMap::const_iterator end = in_map.end();
   while( continue_ && ( it != end ) ) {
      out_set.insert( it.key(), QString() );
      ++it;
   }
}
Exemplo n.º 9
0
extern "C" fssh_status_t
fssh_file_map_translate(void* _map, fssh_off_t offset, fssh_size_t size,
	fssh_file_io_vec* vecs, fssh_size_t* _count, fssh_size_t align)
{
	TRACE(("file_map_translate(map %p, offset %Ld, size %ld)\n",
		_map, offset, size));

	FileMap* map = (FileMap*)_map;
	if (map == NULL)
		return FSSH_B_BAD_VALUE;

	return map->Translate(offset, size, vecs, _count, align);
}
Exemplo n.º 10
0
status_t Tokenizer::open(const String8& filename, Tokenizer** outTokenizer) {
    *outTokenizer = NULL;

    int result = NO_ERROR;
    int fd = ::open(filename.string(), O_RDONLY);
    if (fd < 0) {
        result = -errno;
        ALOGE("Error opening file '%s', %s.", filename.string(), strerror(errno));
    } else {
        struct stat stat;
        if (fstat(fd, &stat)) {
            result = -errno;
            ALOGE("Error getting size of file '%s', %s.", filename.string(), strerror(errno));
        } else {
            size_t length = size_t(stat.st_size);

            FileMap* fileMap = new FileMap();
            bool ownBuffer = false;
            char* buffer;
            if (fileMap->create(NULL, fd, 0, length, true)) {
                fileMap->advise(FileMap::SEQUENTIAL);
                buffer = static_cast<char*>(fileMap->getDataPtr());
            } else {
                delete fileMap;
                fileMap = NULL;

                // Fall back to reading into a buffer since we can't mmap files in sysfs.
                // The length we obtained from stat is wrong too (it will always be 4096)
                // so we must trust that read will read the entire file.
                buffer = new char[length];
                ownBuffer = true;
                ssize_t nrd = read(fd, buffer, length);
                if (nrd < 0) {
                    result = -errno;
                    ALOGE("Error reading file '%s', %s.", filename.string(), strerror(errno));
                    delete[] buffer;
                    buffer = NULL;
                } else {
                    length = size_t(nrd);
                }
            }

            if (!result) {
                *outTokenizer = new Tokenizer(filename, fileMap, buffer, ownBuffer, length);
            }
        }
        close(fd);
    }
    return result;
}
Exemplo n.º 11
0
void daemon_pipe::exec()
{
    CHECK(!m_specs.empty(), "no procs to execute");

    SignalBlocker signals;

    // LockFile will be unlocked on destruction; don't do this until
    // after the ProcHarvester is destroyed
    LockFile lock;

    // ProcHarvester will wait for all children on destruction. Since we want
    // all the FDs to get closed before that happens, this must be instantiated
    // before the FileMap.
    ProcHarvester harvester(&signals.m_sigset);

    // build a map of all the files we're going to need to open, and whether
    // we need to read or write from them
    FileMap files;
    for(std::vector<daemon_proc_spec_ptr>::iterator i = m_specs.begin(), end = m_specs.end(); i != end; ++i)
    {
        Proc &proc(harvester.addProc(*i));

        if((*i)->m_stdin)
            proc.m_stdin = files.get((*i)->m_stdin, true, false);
        if((*i)->m_stdout)
            proc.m_stdout = files.get((*i)->m_stdout, false, true);
        if((*i)->m_stderr)
            proc.m_stderr = files.get((*i)->m_stderr, false, true);
    }

    if(!m_lockFile.empty())
        lock.open(m_lockFile);

    std::vector<File *>::const_iterator file = files.m_files.begin(),
                                        end = files.m_files.end();
    for(; file != end; ++file)
        (*file)->open();

    int pgid = 0;
    for(std::vector<ProcPtr>::iterator i = harvester.m_procs.begin(), end = harvester.m_procs.end(); i != end; ++i)
    {
        Proc &proc = **i;
        proc.m_blockedSignals = &signals;
        proc.m_newPGID = pgid;
        int pid = proc.safe_fork_exec();
        if(pgid == 0)
            pgid = pid;
    }
}
Exemplo n.º 12
0
int main()
{
    int fd;
 FileMap *pFile = FileMap::getInstance();
 for(;;)
    {
 fd = pFile->getFileFd("rr");
 if(fd<0)
 cout<<"fd:"<<strerror(errno)<<endl;
 else cout<<"fd:"<<fd<<endl;
    }
 pFile->traverse();
 pFile->close(fd);  
 return 0;
}
Exemplo n.º 13
0
File* File::Create(const CString& filename)
{
	// Check the map.
	File* file = g_globalFileMap.Get(filename);
	if (file)
		return file;

	// Create a new file.
	file = WNEW File;
	File::Create(*file, filename);

	// Add to map.
	g_globalFileMap.Add(file);

	return file;
}
Exemplo n.º 14
0
bool AdvancedMetaEngine::getFileProperties(const Common::FSNode &parent, const FileMap &allFiles, const ADGameDescription &game, const Common::String fname, ADFileProperties &fileProps) const {
	// FIXME/TODO: We don't handle the case that a file is listed as a regular
	// file and as one with resource fork.

	if (game.flags & ADGF_MACRESFORK) {
		Common::MacResManager macResMan;

		if (!macResMan.open(parent, fname))
			return false;

		fileProps.md5 = macResMan.computeResForkMD5AsString(_md5Bytes);
		fileProps.size = macResMan.getResForkDataSize();

		if (fileProps.size != 0)
			return true;
	}

	if (!allFiles.contains(fname))
		return false;

	Common::File testFile;

	if (!testFile.open(allFiles[fname]))
		return false;

	fileProps.size = (int32)testFile.size();
	fileProps.md5 = Common::computeStreamMD5AsString(testFile, _md5Bytes);
	return true;
}
Exemplo n.º 15
0
bool _dyld_find_unwind_sections(void* addr, struct dyld_unwind_sections* info)
{
	TRACE1(addr);
	const FileMap::ImageMap* map = g_file_map.imageMapForAddr(addr);

	if (!map) // in ELF
	{
		memset(info, 0, sizeof(*info));

		CBData data = { addr, info };

		dl_iterate_phdr(dlCallback, &data);
		std::cout << "Dwarf section at " << info->dwarf_section << std::endl;
		return info->dwarf_section != 0;
	}
	else // in Mach-O
	{
		info->mh = &map->header;
		info->dwarf_section = reinterpret_cast<const void*>(map->eh_frame.first + map->slide);
		info->dwarf_section_length = map->eh_frame.second;

		// FIXME: we would get "malformed __unwind_info" warnings otherwise
		// info->compact_unwind_section = reinterpret_cast<const void*>(map->unwind_info.first + map->slide);
		// info->compact_unwind_section_length = map->unwind_info.second;
		info->compact_unwind_section = 0;
		info->compact_unwind_section_length = 0;

		return true;
	}
}
Exemplo n.º 16
0
char* getsectdata(const struct mach_header* header, const char* segname, const char* sectname, unsigned long* size)
{
	FileMap::ImageMap* imageMap = 0;

	// Find the loaded image the header belongs to
	for (FileMap::ImageMap* entry : g_file_map.images())
	{
		if (&entry->header == header)
		{
			imageMap = entry;
			break;
		}
	}

	if (!imageMap)
		return 0; // Original dyld's man page indicates that it would still somehow proceed, but we don't bother
	
	for (const MachO::Section& sect : imageMap->sections)
	{
		if (sect.segment == segname && sect.section == sectname)
		{
			char* addr = reinterpret_cast<char*>(sect.addr);

			*size = sect.size;
			addr += imageMap->slide;

			return addr;
		}
	}
	return 0;
}
Exemplo n.º 17
0
 void registerFile( llvm::StringRef compilerPath, llvm::StringRef replacement )
 {
     FileStatus fileStatus;
     CompilerDescription desc = { compilerPath.str(), replacement.str() };
     if ( getFileStatus( compilerPath, fileStatus ) )
         files.insert( std::make_pair( fileStatus, desc ) );
 }
Exemplo n.º 18
0
hostptr_t Memory::shadow(hostptr_t addr, size_t count)
{
	TRACE(GLOBAL, "Getting shadow mapping for %p ("FMT_SIZE" bytes)", addr, count);
	FileMapEntry entry = Files.find(addr);
	if(entry.handle() == NULL) return NULL;
	off_t offset = off_t(addr - entry.address());
	hostptr_t ret = (hostptr_t)MapViewOfFile(entry.handle(), FILE_MAP_WRITE, 0, (DWORD)offset, (DWORD)count);
	return ret;
}
Exemplo n.º 19
0
int map_main(int argc, char* argv[]) {

    ContextMap *context = new ContextMap();
    if (!context->parseCmdArgs(argc, argv, 1) || context->getShowHelp() || !context->isValidState()) {
        if (!context->getErrorMsg().empty()) {
            cerr << context->getErrorMsg() << endl;
        }
        map_help();
        delete context;
        return 0;
    }
    FileMap *fileMap = new FileMap(context);

    bool retVal = fileMap->mapFiles();
    delete fileMap;
    delete context;
    return retVal ? 0 : 1;
}
Exemplo n.º 20
0
DataFile *DataFile::reference (const stdString &filename, bool for_write)
{
    DataFile *file;

    FileMap::iterator i = open_data_files.find (filename);
    if (i == open_data_files.end ())
    {
        file = new DataFile (filename, for_write);
        open_data_files.insert (FileMap::value_type (file->getFilename(), file));
    }
    else
    {
        file = i->second;
        file->reference ();
    }

    return file;
}
bool BootAnimation::readFile(const char* name, String8& outString)
{
    ZipEntryRO entry = mZip->findEntryByName(name);
    ALOGE_IF(!entry, "couldn't find %s", name);
    if (!entry) {
        return false;
    }

    FileMap* entryMap = mZip->createEntryFileMap(entry);
    mZip->releaseEntry(entry);
    ALOGE_IF(!entryMap, "entryMap is null");
    if (!entryMap) {
        return false;
    }

    outString.setTo((char const*)entryMap->getDataPtr(), entryMap->getDataLength());
    entryMap->release();
    return true;
}
Exemplo n.º 22
0
void
MediaAddonServer::_AddOnRemoved(ino_t fileNode)
{
	// TODO: locking?

	FileMap::iterator foundFile = fFileMap.find(fileNode);
	if (foundFile == fFileMap.end()) {
		ERROR("MediaAddonServer::_AddOnRemoved: inode %Ld removed, but no "
			"media add-on found\n", fileNode);
		return;
	}

	media_addon_id id = foundFile->second;
	fFileMap.erase(foundFile);

	int32 oldFlavorCount;
	InfoMap::iterator foundInfo = fInfoMap.find(id);

	if (foundInfo == fInfoMap.end()) {
		ERROR("MediaAddonServer::_AddOnRemoved: couldn't get addon info for "
			"add-on %ld\n", id);
		oldFlavorCount = 1000;
	} else {
		AddOnInfo& info = foundInfo->second;
		oldFlavorCount = info.flavor_count;

		_DestroyInstantiatedFlavors(info);
		_PutAddonIfPossible(info);

		if (info.addon) {
			ERROR("MediaAddonServer::_AddOnRemoved: couldn't unload addon "
				"%ld since flavors are in use\n", id);
		}

		fInfoMap.erase(foundInfo);
	}

	gDormantNodeManager->UnregisterAddOn(id);

	BPrivate::media::notifications::FlavorsChanged(id, 0, oldFlavorCount);
}
/*
 * Create a new FileMap object that spans the data in "entry".
 */
FileMap* ZipFileRO::createEntryFileMap(ZipEntryRO entry) const
{
    const _ZipEntryRO *zipEntry = reinterpret_cast<_ZipEntryRO*>(entry);
    const ZipEntry& ze = zipEntry->entry;
    int fd = GetFileDescriptor(mHandle);
    size_t actualLen = 0;

    if (ze.method == kCompressStored) {
        actualLen = ze.uncompressed_length;
    } else {
        actualLen = ze.compressed_length;
    }

    FileMap* newMap = new FileMap();
    if (!newMap->create(mFileName, fd, ze.offset, actualLen, true)) {
        newMap->release();
        return NULL;
    }

    return newMap;
}
Exemplo n.º 24
0
void CacheBase::FillReadDir(const char* path, void *buf, fuse_fill_dir_t filler,
			off_t offset, struct fuse_file_info *fi)
{
	BlockLockMutex lock(this);
	DirEntry* dir = dynamic_cast<DirEntry*>(Path2File(path));

	if(!dir)
		throw NoSuchFileOrDir();

	FileMap files = dir->GetFiles();
	for(FileMap::const_iterator it = files.begin(); it != files.end(); ++it)
	{
		if(it->second->IsRemoved())
			continue;

		struct stat st;
		memset(&st, 0, sizeof st);
		/*st.st_ino = de->d_ino;
		st.st_mode = de->d_type << 12;*/

		if(filler(buf, it->second->GetName().c_str(), &st, 0))
			break;
	}
}
Exemplo n.º 25
0
void ObjectCollection::SaveToStreams()
{
	typedef std::pair<String, Array<TypedCompoundPointer>>					FileEntry;
	typedef std::unordered_map<String, Array<TypedCompoundPointer>>			FileMap;
	FileMap map;

	for (TypedCompoundPointer& p : mObjects)
	{
		String* loc = p.GetCompoundMember<String>("!location");
		gAssert(loc != nullptr);
		FileMap::iterator i = map.find(*loc);
		if (i == map.end())
			map.insert(FileEntry(*loc, Array<TypedCompoundPointer>(&p, 1)));
		else
			i->second.Append(p);
	}

	for (const FileEntry& entry : map)
	{
		Path target_path(entry.first);
		StreamDevice* d = gDevices.FindDevice(target_path.GetDeviceName());
		gAssert(d != nullptr);
		Stream* s = d->CreateStream(target_path, smWrite);
		gAssert(s != nullptr);
		ObjectWriter wr(*s);
		std::cout << "Opened stream to " << target_path << std::endl;
		for (const TypedCompoundPointer& object : entry.second)
		{
			const String* name = object.GetCompoundMember<String>("!name");
			const String* loc = object.GetCompoundMember<String>("!location");
			std::cout << "   Writing: " << (loc != nullptr ? *loc : String("<noloc>")) << " : " << (name != nullptr ? *name : String("<noname>")) << std::endl;
			wr.WriteTypedCompoundPointer(object);
		}
		d->CloseStream(s);
	}
}
Exemplo n.º 26
0
void CMd5CalFile2Dlg::OnBnClickedButton1()
{
    // TODO: 在此添加控件通知处理程序代码
    m_showMd5Lower.SetWindowTextW(L"");
    m_showMd5Upper.SetWindowTextW(L"");
    LARGE_INTEGER liSize = { 0 };
    CString path;
    m_editPath.GetWindowTextW(path);
    FileMap fileMap;
    char* lpBuffer = (char*)fileMap.CreateFileMap(path.GetBuffer(), &liSize);
    std::wstring strRet = Md5Partially((unsigned char*)lpBuffer, 
        liSize.LowPart, 80*1024);
   
    m_showMd5Upper.SetWindowTextW(strRet.c_str());

    for (unsigned int i = 0; i < strRet.size(); ++i)
    {
        if ( strRet[i] >= L'A' && strRet[i] <= L'Z')
        {
            strRet[i] = strRet[i] - L'A' + L'a';
        }
    }
    m_showMd5Lower.SetWindowTextW(strRet.c_str());
}
Exemplo n.º 27
0
/**
 * Check for each ADFileBasedFallback record whether all files listed
 * in it are present. If multiple pass this test, we pick the one with
 * the maximal number of matching files. In case of a tie, the entry
 * coming first in the list is chosen.
 */
static ADGameDescList detectGameFilebased(const FileMap &allFiles, const ADParams &params) {
    const ADFileBasedFallback *ptr;
    const char* const* filenames;

    int maxNumMatchedFiles = 0;
    const ADGameDescription *matchedDesc = 0;

    for (ptr = params.fileBasedFallback; ptr->desc; ++ptr) {
        const ADGameDescription *agdesc = (const ADGameDescription *)ptr->desc;
        int numMatchedFiles = 0;
        bool fileMissing = false;

        for (filenames = ptr->filenames; *filenames; ++filenames) {
            debug(3, "++ %s", *filenames);
            if (!allFiles.contains(*filenames)) {
                fileMissing = true;
                break;
            }

            numMatchedFiles++;
        }

        if (!fileMissing) {
            debug(4, "Matched: %s", agdesc->gameid);

            if (numMatchedFiles > maxNumMatchedFiles) {
                matchedDesc = agdesc;
                maxNumMatchedFiles = numMatchedFiles;

                debug(4, "and overridden");
            }
        }
    }

    ADGameDescList matched;

    if (matchedDesc) { // We got a match
        matched.push_back(matchedDesc);
        if (params.flags & kADFlagPrintWarningOnFileBasedFallback) {
            printf("Your game version has been detected using filename matching as a\n");
            printf("variant of %s.\n", matchedDesc->gameid);
            printf("If this is an original and unmodified version, please report any\n");
            printf("information previously printed by ScummVM to the team.\n");
        }
    }

    return matched;
}
Exemplo n.º 28
0
// filePathListにあるファイルを一度にすべて読み込む
void Manager::Open( const vector<wstring> &filePathList, FileMap &files, 
				   bool cache, bool throwException )
{
	Core::PFileManager pFManager = Core::Manager::GetFileManager();
	list<wstring> notOpenedFileList;

	files.clear();

	foreach( const wstring &filePath, filePathList )
	{
		if( cache )
		{
			PFile pFile = Detail::Cache::Get( filePath );

			if( pFile )
			{
				files[ filePath ] = pFile;
				continue;
			}
		}
		else
		{
			Detail::Cache::Erase( filePath );
		}

		PFile pFile = 
			MakeIntrusivePtr( pFManager->OpenSyncFile( filePath.c_str() ) );

		if( throwException && !pFile )
		{
			notOpenedFileList.push_back( filePath );
		}
		else if( pFile )
		{
			files[ filePath ] = pFile;

			if( cache )
			{
				Detail::Cache::Put( filePath, pFile );
			}
		}
	}

	if( throwException && !notOpenedFileList.empty() )
	{
		THROW( Exception::NotFound( notOpenedFileList ) );
	}
}
Exemplo n.º 29
0
bool AdlMetaEngine::addFileProps(const FileMap &allFiles, Common::String fname, FilePropertiesMap &filePropsMap) const {
	if (filePropsMap.contains(fname))
		return true;

	if (!allFiles.contains(fname))
		return false;

	FileProperties fileProps;
	fileProps.size = computeMD5(allFiles[fname], fileProps.md5, 16384);

	if (fileProps.size != -1) {
		debug(3, "> '%s': '%s'", fname.c_str(), fileProps.md5.c_str());
		filePropsMap[fname] = fileProps;
	}

	return true;
}
Exemplo n.º 30
0
hostptr_t Memory::map(hostptr_t addr, size_t count, GmacProtection prot)
{
    hostptr_t cpuAddr = NULL;

	// Create anonymous file to be mapped
	HANDLE handle = CreateFileMapping(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, 0, (DWORD)count, NULL);
	if(handle == NULL) return NULL;
	
	// Create a view of the file in the previously allocated virtual memory range
	if((cpuAddr = (hostptr_t)MapViewOfFileEx(handle, FILE_MAP_WRITE, 0, 0, (DWORD)count, addr)) == NULL) {
		CloseHandle(handle);
		return NULL;
	}

	if(Files.insert(handle, cpuAddr, count) == false) {
		CloseHandle(handle);
		return NULL;
	}

	// Make sure that the range has the requested virtual protection bits
	protect(cpuAddr, count, prot);
    return cpuAddr;
}