Пример #1
0
/** Let the intermediate write request fail. The write should be retried and
 *  finally succeed. */
TEST_F(AsyncWriteHandlerTest, IntermediateWriteFail) {
  size_t blocks = 5;
  size_t buffer_size = kBlockSize * blocks;
  size_t middle = blocks / 2;
  boost::scoped_array<char> write_buf(new char[buffer_size]());

  vector<WriteEntry> expected_front(middle);
  vector<WriteEntry> expected_tail(blocks - middle);
  for (size_t i = 0; i < middle; ++i) {
    expected_front[i] = WriteEntry(i, 0, kBlockSize);
  }

  for (size_t i = middle; i < blocks; ++i) {
    expected_tail[i - middle] = WriteEntry(i, 0, kBlockSize);
  }

  test_env.osds[0]->AddDropRule(
      new ProcIDFilterRule(xtreemfs::pbrpc::PROC_ID_WRITE,
                           new SkipMDropNRule(middle, 1)));

  ASSERT_NO_THROW(file->Write(write_buf.get(), buffer_size, 0));
  ASSERT_NO_THROW(file->Flush());

  EXPECT_TRUE(equal(expected_front.begin(),
                    expected_front.end(),
                    test_env.osds[0]->GetReceivedWrites().begin()));
  EXPECT_TRUE(equal(expected_tail.begin(),
                    expected_tail.end(),
                    test_env.osds[0]->GetReceivedWrites().end() -
                        expected_tail.size()));

  ASSERT_NO_THROW(file->Close());
}
Пример #2
0
//------------------------------------------------------------------
//
//	WriteWarning(..)
//
//	Params:
//	log			-	Text to log
//	bTimeStamp	-	To include time stamp in entry
//
//	Writes warning entry to text file
//
//------------------------------------------------------------------
void CDebugLog::WriteWarning(const std::string& log, bool bTimeStamp)
{
	if (bTimeStamp)
		WriteTimeStampEntry("Warning: " + log);
	else
		WriteEntry("Warning: " + log);
}
Пример #3
0
//------------------------------------------------------------------
//
//	WriteError(..)
//
//	Params:
//	log			-	Text to log
//	bTimeStamp	-	To include time stamp in entry
//
//	Writes error entry to text file
//
//------------------------------------------------------------------
void CDebugLog::WriteError(const std::string& log, bool bTimeStamp)
{
	if (bTimeStamp)
		WriteTimeStampEntry("Error: " + log);
	else
		WriteEntry("Error: " + log);
}
Пример #4
0
bool wxDatabaseConfig::DoWriteString(const wxString& key, const wxString& szValue) 
{ 
	wxString name = key.AfterLast(wxCONFIG_PATH_SEPARATOR);
	if (name.StartsWith(wxCONFIG_IMMUTABLE_PREFIX))
	{ 
		wxLogError("Immutable entries cannot be changed"); 
		return false; 
	} 

	dbentries entries;
	if (!FindEntries(key, entries))
	{ 
		wxConfigPathChanger path(this, key);
		//wxLogTrace(DBLCONF_TRACE_MASK, wxString::Format("Adding Entry '%s' = '%s' to Group '%s'", name, szValue, m_entry.path)); 
		AddEntry(m_entry, name, &szValue); 
	}
	else if (entries[0].isgroup)
	{
		wxLogError("Can't set value of a group!."); 
	}
	else
	{
		//wxLogTrace(DBLCONF_TRACE_MASK, wxString::Format("Writing Entry '%s' = '%s' in Group '%s'", name, szValue, entries[0].path)); 
		WriteEntry(entries[0], name, szValue); 
	}
	return true; 
} 
Пример #5
0
//------------------------------------------------------------------
//
//	WriteDebugInfo(..)
//
//	Params:
//	log			-	Text to log
//	bTimeStamp	-	To include time stamp in entry
//
//	Writes debug log entry (General purpose message)
//
//------------------------------------------------------------------
void CDebugLog::WriteDebugInfo(const std::string& log, bool bTimeStamp)
{
	if (bTimeStamp)
		WriteTimeStampEntry("Debug Info: " + log);
	else
		WriteEntry("Debug Info: " + log);
}
Пример #6
0
Файл: HDD.cpp Проект: ss23/rpcs3
bool vfsHDD::RemoveEntry(const std::string& name)
{
	u64 entry_block, parent_entry;
	if (!SearchEntry(name, entry_block, &parent_entry))
	{
		return false;
	}

	vfsHDD_Entry entry;
	ReadEntry(entry_block, entry);
	if (entry.type == vfsHDD_Entry_Dir)
	{
		RemoveBlocksDir(entry.data_block);
	}
	else if (entry.type == vfsHDD_Entry_File)
	{
		RemoveBlocksFile(entry.data_block);
	}

	if (parent_entry)
	{
		u64 next = entry.next_block;
		ReadEntry(parent_entry, entry);
		entry.next_block = next;
		WriteEntry(parent_entry, entry);
	}
	WriteBlock(entry_block, g_null_block);
	return true;
}
Пример #7
0
VXIlogResult OSBlog::ErrorLog(const VXIchar*   moduleName,
                              VXIunsigned      errorID,
                              const VXIchar*   format,
                              va_list          args)
{
    const VXIchar *finalModuleName =
        (moduleName && moduleName[0] ? moduleName : L"UNKNOWN");

    // Output the log message
    LogEntry entry;
    entry.AddEntrySep();
    entry += channelNum;
    entry.AddEntrySep();
    entry += finalModuleName;
    entry.AddEntrySep();
    entry += errorID;
    entry.AddEntrySep();
    VXIlogResult rc = entry.AppendKeyValueVa(format, args);
    entry.Terminate();

    VXIlogResult rc2 = WriteEntry(entry);
    if (rc2 != VXIlog_RESULT_SUCCESS)
        rc = rc2;

    // Want to warn the caller that NULL moduleName really isn't OK, but
    // logged it anyway
    if ((! moduleName) || (! moduleName[0]))
        rc = VXIlog_RESULT_INVALID_ARGUMENT;

    return rc;
}
Пример #8
0
int PRGinput(int len , char *buffer )
{
	extern PROGRAMM prg;
	extern BEZEICHNUNG bez;
	extern TEXTE txt;
	extern SAISON sai;
	extern int sprache;

	char *to_buffers[MAX_MENU_ITEMS];
	int status=(int)MPOK;

	status = UtilSplitMenubuffer(buffer, to_buffers, (char)NULL );
	if (status != (int)MPOK )
		{
		UtilMsg((int)MPE_CUTBUFFERIN, MSGTYP_ERROR, NULL);
		prg.prg_id = (int)_UNDEF;
		return((int)MPERROR);
		}

	if (ACTIONTYP == (unsigned char)INSERT)
		{
		prg.prg_id = (int)_UNDEF;
		prg.textid = (int)_UNDEF;
		txt.textid = (int)_UNDEF;
		}

	bez.s_id = (int)sprache;
	bez.typ = (int)_PROGRAMM;
	(void)copyTextTo( bez.bez, to_buffers[MPRG_BEZ], (int)_CHAR30 );
	if (*bez.bez != NULL )
		{
		if ( *to_buffers[MPRG_SAI] != NULL )
			prg.sai_id = (int)MPAPIselectEntry( (int)_SAISON, to_buffers[MPRG_SAI],
			   (char *)&sai, sizeof( SAISON ), sizeof( prg.sai_id ) );
		else
			prg.sai_id = (int)_UNDEF;

     	(void)copyTextTo(prg.code, to_buffers[MPRG_CODE], (int)_KRZLLEN);

		txt.typ = (int)_PROGRAMM;
		txt.s_id = (int)sprache;
		txt.textid = prg.textid;
		prg.textid = xTxtWrite( to_buffers[MPRG_TXT] );

		status = WriteEntry( (int)_PROGRAMM, (char *)&prg, &bez );
		if ( status == (int)MPERROR )
			prg.prg_id = (int)_UNDEF;
		else
			(void)WriteInfo((int)_PROGRAMM, (char *)&prg, buffer);
		}
	else
		{
		UtilMsg((int)MSG2, MSGTYP_ERROR, NULL);
		prg.prg_id = (int)_UNDEF;
		status = (int)MPERROR;
		}

	UtilSplitFreeMenubuffer( to_buffers );
	return( status );
}
Пример #9
0
int DLNTinput(int len, char *buffer)
{
	extern REISENDER_TYP reit;
	extern BEZEICHNUNG bez;
	extern TEXTE txt;
	extern int sprache;

	char *to_buffers[MAX_MENU_ITEMS];
	int status=(int)MPOK;

	status = UtilSplitMenubuffer(buffer, to_buffers, (char)NULL);
	if (status != MPOK)
		{
		UtilMsg((int)MPE_CUTBUFFERIN, MSGTYP_ERROR, NULL);
		reit.rkr_id = (int)_UNDEF;
		return((int)MPERROR);
		}

	if (ACTIONTYP == (int)INSERT)
		{
		reit.rkr_id=(int)_UNDEF;
		reit.textid=(int)_UNDEF;
		txt.textid=(int)_UNDEF;
		reit.vonalter = (int)_UNDEF;
		reit.bisalter = (int)_UNDEF;
		}

	bez.s_id=(int)sprache;
	bez.typ=(int)_REISENDER_TYP;
	(void)copyTextTo(bez.bez, to_buffers[MDLNT_BEZ], (int)_BEZLEN);
	if (*bez.bez != NULL)
		{
		(void)copyTextTo(reit.dlncode, to_buffers[MDLNT_CODE], (int)_CHAR10);

		status = readInteger(&reit.vonalter, to_buffers[MDLNT_VONALTER]);
		if (status == (int)MPERROR)
			reit.vonalter = (int)_UNDEF;

		status = readInteger(&reit.bisalter, to_buffers[MDLNT_BISALTER]);
		if (status == (int)MPERROR)
			reit.bisalter = (int)_UNDEF;

		txt.typ=(int)_REISENDER_TYP;
		txt.s_id=sprache;
		txt.textid=reit.textid;
		reit.textid=xTxtWrite(to_buffers[MDLNT_TXT]);

		status=WriteEntry((int)_REISENDER_TYP, (char *)&reit, &bez);
		if (status == (int)MPERROR)
			reit.rkr_id=(int)_UNDEF;
		/*!!! WriteInfo hier */
		}
	UtilSplitFreeMenubuffer(to_buffers);
	return(status);
}
Пример #10
0
bool wxDatabaseConfig::RenameEntry(const wxString& oldName, const wxString& newName) 
{ 
	wxASSERT_MSG(!wxStrchr(oldName, wxCONFIG_PATH_SEPARATOR), wxT("RenameEntry(): paths are not supported")); 

	dbentries entries;
	if ( FindEntries(newName, entries)) return false; 
	entries.clear();
	if (!FindEntries(oldName, entries)) return false; 

	return WriteEntry(entries[0], newName, entries[0].value); 
} 
Пример #11
0
int KOLTinput(int len, char *buffer)
{
	extern KOLLEKTIV_TYP kolt;
	extern BEZEICHNUNG bez;
	extern TEXTE txt;
	extern int sprache;

	char *to_buffers[MAX_MENU_ITEMS];
	int status=(int)MPOK;

	status = UtilSplitMenubuffer(buffer, to_buffers, (char)NULL);
	if (status != MPOK)
		{
		UtilMsg((int)MPE_CUTBUFFERIN, MSGTYP_ERROR, NULL);
		kolt.k_typ_id = (int)_UNDEF;
		return((int)MPERROR);
		}

	if (ACTIONTYP == (unsigned char)INSERT)
		{
		kolt.k_typ_id=(int)_UNDEF;
		kolt.textid=(int)_UNDEF;
		txt.textid=(int)_UNDEF;
		}

	bez.s_id=(int)sprache;
	bez.typ=(int)_KOLLEKTIV_TYP;
	(void)copyTextTo(bez.bez, to_buffers[MKOLT_BEZ], (int)_BEZLEN);
	if (*bez.bez != NULL)
		{
		(void)copyTextTo(kolt.kolcode, to_buffers[MKOLT_CODE], (int)_CHAR10);

		txt.typ=(int)_KOLLEKTIV_TYP;
		txt.s_id=sprache;
		txt.textid=kolt.textid;
		kolt.textid=xTxtWrite(to_buffers[MKOLT_TXT]);

		status=WriteEntry((int)_KOLLEKTIV_TYP, (char *)&kolt, &bez);
		if (status == (int)MPERROR)
			kolt.k_typ_id=(int)_UNDEF;
		else
			(void)WriteInfo((int)_KOLLEKTIV_TYP, (char *)&kolt, buffer);

		}
	else
		{
		UtilMsg((int)MSG2, MSGTYP_ERROR, NULL);
		kolt.k_typ_id=(int)_UNDEF;
		status=(int)MPERROR;
		}

	UtilSplitFreeMenubuffer(to_buffers);
	return(status);
}
Пример #12
0
void CLogDlg::RefreshLog()
{
	m_richLog.SetSel(0,m_richLog.LineLength(0)+1);
    m_richLog.SetSel(0,-1);

	m_richLog.SetReadOnly(false);
	m_richLog.Clear();
	m_richLog.SetReadOnly(true);
	for(int i = 0; i < (int)logEntry.size(); i++)
	{
		WriteEntry(i);
	}
}
Пример #13
0
Файл: HDD.cpp Проект: ss23/rpcs3
bool vfsHDD::Rename(const std::string& from, const std::string& to)
{
	u64 entry_block;
	if (!SearchEntry(from, entry_block))
	{
		return false;
	}

	vfsHDD_Entry entry;
	ReadEntry(entry_block, entry);
	WriteEntry(entry_block, entry, to);

	return true;
}
Пример #14
0
void DataArchive::Remove(const char* name)
{
   int index = FindEntry(name);

   if (index < 0) {
      printf("Could not remove '%s', not found\n", name);
      return;
   }

   RemoveEntry(index);
   WriteEntry(index, 0);

   if (verbose) printf("   Removed: %s\n", name);
}
Пример #15
0
void CLogDlg::WriteToLog(int warningLevel, int object, LPCTSTR strToWrite)
{
	CTime currentTime = CTime::GetCurrentTime();
	logEntry.push_back(LogEntry(currentTime.Format("%m/%d %H:%M:%S").GetString(),warningLevel,object, string(strToWrite)));
	if(logEntry.size() > MAX_LOG_SIZE)
	{
		logEntry.erase(&logEntry.front()); //pop the front if the log gets too big
		if(m_richLog.GetTextLength() > 1024*1024) // if text box gets too big
		{
			RefreshLog();
			return;
		}
	}
	WriteEntry((int)logEntry.size() - 1);
}
Пример #16
0
void IOAPIC::SetupIRQs() {
	struct IO_APIC_route_entry entry;
	bool first_notcon = true;
	printk("init IOAPIC IRQs\n");
	for(int apic = 0; apic < system->smp->nr_ioapics; apic++)
	for(int pin = 0; pin < nr_ioapic_registers[apic]; pin++) {
		memset(&entry, 0, sizeof(entry));
		entry.delivery_mode = dest_LowestPrio;
		entry.dest_mode = 1;
		entry.mask = 0;				/* enable IRQ */
		entry.dest.logical.logical_dest = 0;

		int idx = system->smp->FindIRQEntry(apic, pin, mp_INT);
		if(idx == -1) {
			if(first_notcon) {
				printk(" IO-APIC (apicid-pin) %d-%d", system->smp->mp_ioapics[apic].mpc_apicid, pin);
				first_notcon = false;
			} else
				printk(", %d-%d", system->smp->mp_ioapics[apic].mpc_apicid, pin);
			continue;
		}
		
		entry.trigger = system->smp->MPBIOS_trigger(idx);
		entry.polarity = system->smp->MPBIOS_polarity(idx);

		if (entry.trigger) {
			entry.trigger = 1;
			entry.mask = 1;
		}

		int irq = Pin2IRQ(idx, apic, pin);

		AddPinToIRQ(irq, apic, pin);

		if (apic == 0 && !IO_APIC_IRQ(irq))
			continue;

		if (IO_APIC_IRQ(irq)) {
			int vector = AssignIRQVector(irq);
			entry.vector = vector;
		
			if (apic == 0 && irq < 16)
				disable_8259A_irq(irq);
		}
		WriteEntry(apic, pin, entry);
	}

}
Пример #17
0
bool LogManager::AppendEntry(LogEntry* entry,std::string* save_err){
	abb::Mutex::Locker l(mtx_);
	if(this->log_entry_arr_.size() > 0){
		LogEntry* last_entry = this->log_entry_arr_.back();
		if(last_entry->term_ > entry->term_){
			LOG(DEBUG) << "Cannot Append entry with earlier term last:" << last_entry->term_ << "insert:" << entry->term_;
			if(save_err) *save_err = "Cannot Append entry with earlier term";
			return false;
		}else if(last_entry->term_ == entry->term_ && entry->index_ < last_entry->index_){
			LOG(DEBUG) << "Cannot Append entry with earlier index in same term last:" << last_entry->index_ << "insert:" << entry->index_;
			if(save_err) *save_err = "Cannot Append entry with earlier index";
			return false;
		}
	}
	WriteEntry(fd_,entry);
	this->log_entry_arr_.push_back(entry);
	return true;
}
Пример #18
0
bool LogManager::Compact(uint64_t index,uint64_t term){
	LOG(DEBUG) << "Compact.index" << index;
	LogEntryArray  arr;
	abb::Mutex::Locker l(mtx_);
	if(index == 0){
		return true;
	}
	if(index < this->InternalGetCurrentIndex()){
		for(unsigned i=index-start_index_;i<this->log_entry_arr_.size();i++){
			log_entry_arr_[i]->Ref();
			arr.push_back(log_entry_arr_[i]);
		}
	}
	std::string newpath = this->path_ + ".new";
	int fd =  open(newpath.c_str(),O_WRONLY|O_APPEND|O_CREAT,0600);
	if(fd < 0){
		LOG(WARN) << "Open Fial fail: path:" << newpath << "err:" << strerror(errno);
		return false;
	}
	fcntl(fd, F_SETFD, FD_CLOEXEC);
	for(unsigned i=0;i<arr.size();i++){
		if(!WriteEntry(fd,arr[i])){
			close(fd);
			remove(newpath.c_str());
			for(unsigned j=0;j<arr.size();j++){
				arr[j]->UnRef();
			}
			return false;
		}
	}
	fsync(fd);
	close(fd_);
	this->fd_ = fd;
	rename(newpath.c_str(),path_.c_str());
	for(unsigned i=0;i<this->log_entry_arr_.size();i++){
		log_entry_arr_[i]->UnRef();
	}
	this->log_entry_arr_ = arr;
	this->start_index_ = index;
	this->start_term_ = term;
	LOG(DEBUG) << "Compact.success.index = " << index <<".start_index = "<< this->start_index_ << ".entry_arr_size = " << log_entry_arr_.size();
	return true;

}
Пример #19
0
/** A normal async write with nothing special */
TEST_F(AsyncWriteHandlerTest, NormalWrite) {
  size_t blocks = 5;
  size_t buffer_size = kBlockSize * blocks;
  boost::scoped_array<char> write_buf(new char[buffer_size]());

  vector<WriteEntry> expected(blocks);
  for (size_t i = 0; i < blocks; ++i) {
    expected[i] = WriteEntry(i, 0, kBlockSize);
  }

  ASSERT_NO_THROW(file->Write(write_buf.get(), buffer_size, 0));
  ASSERT_NO_THROW(file->Flush());

  EXPECT_TRUE(equal(expected.begin(),
                    expected.end(),
                    test_env.osds[0]->GetReceivedWrites().end() - blocks));

  ASSERT_NO_THROW(file->Close());
}
Пример #20
0
VXIlogResult OSBlog::DiagnosticLog(VXIunsigned     tagID,
                                   const VXIchar*  subtag,
                                   const VXIchar*  format,
                                   va_list         args)
{
    VXIunsigned bindex, bpos;
    if (!Convert2Index(tagID, &bindex, &bpos))
        return VXIlog_RESULT_INVALID_ARGUMENT;

    if (! format)
        return VXIlog_RESULT_SUCCESS;

    // if this tag is not turned on, just return
    if (!testbit(TagIDs[bindex],bpos))
        return VXIlog_RESULT_SUCCESS;

    if (subtag == NULL)
        subtag = L"";

    // Output the log message
    LogEntry entry;
    entry.AddEntrySep();
    entry += channelNum;
    entry.AddEntrySep();
    entry += tagID;
    entry.AddEntrySep();
    entry += subtag;
    entry.AddEntrySep();
    VXIlogResult rc;
    if (args == 0)
        rc = entry.Append(format, wcslen(format));
    else
        rc = entry.AppendVa(format, args);
    entry.Terminate();

    VXIlogResult rc2 = WriteEntry(entry);
    if (rc2 != VXIlog_RESULT_SUCCESS)
        rc = rc2;

    return rc;
}
Пример #21
0
bool GOrgueArchiveIndex::WriteContent(const wxString& id, const std::vector<GOArchiveEntry>& entries)
{
	int magic = GRANDORGUE_INDEX_MAGIC;
	if (!Write(&magic, sizeof(magic)))
		return false;

	GOrgueHashType hash = GenerateHash();
	if (!Write(&hash, sizeof(hash)))
		return false;

	if (!WriteString(id))
		return false;

	unsigned cnt = entries.size();
	if (!Write(&cnt, sizeof(cnt)))
	    return false;
	for(unsigned i = 0; i < entries.size(); i++)
		if (!WriteEntry(entries[i]))
			return false;

	return true;
}
Пример #22
0
VXIlogResult OSBlog::EventLog(VXIunsigned      eventID,
                              const VXIchar*   format,
                              va_list          args)
{
    // Output the log message
    LogEntry entry;
    entry.AddEntrySep();
    entry += channelNum;
    entry.AddEntrySep();
    entry += L"EVENT";
    entry.AddEntrySep();
    entry += eventID;
    entry.AddEntrySep();
    VXIlogResult rc = entry.AppendKeyValueVa(format, args);
    entry.Terminate();

    // Don't write events to stdout
    VXIlogResult rc2 = WriteEntry(entry, false);
    if (rc2 != VXIlog_RESULT_SUCCESS)
        rc = rc2;

    return rc;
}
Пример #23
0
/** Let the first write request fail when there are more writes than
 *  writeahead allows.  The write should be retried and finally succeed. */
TEST_F(AsyncWriteHandlerTest, FirstWriteFailLong) {
  size_t blocks = 2 * test_env.options.async_writes_max_requests;
  size_t buffer_size = kBlockSize * blocks;
  boost::scoped_array<char> write_buf(new char[buffer_size]());

  vector<WriteEntry> expected_tail(blocks);
  for (size_t i = 0; i < blocks; ++i) {
    expected_tail[i] = WriteEntry(i, 0, kBlockSize);
  }

  test_env.osds[0]->AddDropRule(
      new ProcIDFilterRule(xtreemfs::pbrpc::PROC_ID_WRITE, new DropNRule(1)));

  ASSERT_NO_THROW(file->Write(write_buf.get(), buffer_size, 0));
  ASSERT_NO_THROW(file->Flush());

  EXPECT_TRUE(equal(expected_tail.begin(),
                    expected_tail.end(),
                    test_env.osds[0]->GetReceivedWrites().end() -
                        expected_tail.size()));

  ASSERT_NO_THROW(file->Close());
}
Пример #24
0
void MP4TableProperty::Write(MP4File* pFile, u_int32_t index)
{
	ASSERT(index == 0);

	if (m_implicit) {
		return;
	}

	u_int32_t numProperties = m_pProperties.Size();

	if (numProperties == 0) {
		WARNING(numProperties == 0);
		return;
	}

	u_int32_t numEntries = GetCount();

	ASSERT(m_pProperties[0]->GetCount() == numEntries);

	for (u_int32_t i = 0; i < numEntries; i++) {
		WriteEntry(pFile, i);
	}
}
Пример #25
0
int AKTinput(int len, char *buffer)
{
	extern AKTIONEN akt;
	extern AKTIONSGRP aktgrp;
	extern BEZEICHNUNG bez;
	extern TEXTE txt;
	extern AKTIONS_TYP aktt;
	extern STATUS_WERTE sta;
	extern int sprache;

	char *to_buffers[MAX_MENU_ITEMS];
	char tmp_buffer[RECLAENGE];
	char *buffer_ptr;
	int status=(int)MPOK;
	int buffersize;

	status = UtilSplitMenubuffer(buffer, to_buffers, (char)NULL);
	if (status != MPOK)
		{
		UtilMsg((int)MPE_CUTBUFFERIN, MSGTYP_ERROR, NULL);
		akt.akt_id=(int)_UNDEF;
		return((int)MPERROR);
		}

	if (ACTIONTYP == (unsigned char)INSERT)
		{
		akt.akt_id=(int)_UNDEF;
		akt.b_flag=(int)_UNDEF;
		akt.b2_flag=(int)_UNDEF;
		akt.textid=(int)_UNDEF;
		txt.textid=(int)_UNDEF;
		}

	/* AKTION */
	if (ACTIONTYP != INSERT && ACTIONTYP != UPDATE)
		{
		akt.akt_id=MPAPIselectEntry((int)_AKTIONEN, to_buffers[MAKT_BEZ],
		             (char *)&akt, sizeof(AKTIONEN), sizeof(akt.akt_id));
		if (akt.akt_id == (int)_UNDEF)
			{
			UtilMsg((int)MPE_NOENTRYFOUND, MSGTYP_ERROR, NULL);
			akt.akt_id=(int)_UNDEF;
			return((int)MPERROR);
			}
		}

	bez.s_id=(int)sprache;
	bez.typ=(int)_AKTIONEN;
	(void)copyTextTo(bez.bez, to_buffers[MAKT_BEZ], (int)_BEZLEN);
	if (*bez.bez != NULL)
		{
		if (*to_buffers[MAKT_AKTT] == NULL)
			akt.a_typ_id = (int)_UNDEF;
		else
			{
			akt.a_typ_id=(int)MPAPIselectEntry((int)_AKTIONS_TYP, to_buffers[MAKT_AKTT],
			          (char *)&aktt, sizeof(AKTIONS_TYP), sizeof(akt.a_typ_id));
			}

		if (*to_buffers[MAKT_STAAUS] == NULL)
			akt.a_flag = (int)_UNDEF;
		else
			{
			sta.typ = (int)_A_FLG;
			status = getAttribut((int)_A_FLG, to_buffers[MAKT_STAAUS]);
			if (status != (int)MPERROR)
				akt.a_flag=sta.sta_id;
			else
				{
				UtilMsg((int)MPE_NOSTA, MSGTYP_ERROR, NULL);
				akt.akt_id=(int)_UNDEF;
				UtilSplitFreeMenubuffer(to_buffers);
				return((int)MPERROR);
				}
			}

		if (*to_buffers[MAKT_STAINRES] == NULL)
			akt.b_flag = (int)_UNDEF;
		else
			{
			sta.typ = (int)_R_STA;
			status = getAttribut((int)_R_STA, to_buffers[MAKT_STAINRES]);
			if (status != (int)MPERROR)
				akt.b_flag=sta.sta_id;
			else
				{
				UtilMsg((int)MPE_NOSTA, MSGTYP_ERROR, NULL);
				akt.akt_id=(int)_UNDEF;
				UtilSplitFreeMenubuffer(to_buffers);
				return((int)MPERROR);
				}
			}

		if (*to_buffers[MAKT_STAOUTRES] == NULL)
			akt.b2_flag = (int)_UNDEF;
		else
			{
			sta.typ = (int)_R_STA;
			status = getAttribut((int)_R_STA, to_buffers[MAKT_STAOUTRES]);
			if (status != (int)MPERROR)
				akt.b2_flag=sta.sta_id;
			else
				{
				UtilMsg((int)MPE_NOSTA, MSGTYP_ERROR, NULL);
				akt.akt_id=(int)_UNDEF;
				UtilSplitFreeMenubuffer(to_buffers);
				return((int)MPERROR);
				}
			}

		if (*to_buffers[MAKT_STADEV] == NULL)
			akt.m_flag = (int)_UNDEF;
		else
			{
			sta.typ = (int)_DEVICE;
			status = getAttribut((int)_DEVICE, to_buffers[MAKT_STADEV]);
			if (status != (int)MPERROR)
				akt.m_flag=sta.sta_id;
			else
				{
				UtilMsg((int)MPE_NOSTA, MSGTYP_ERROR, NULL);
				akt.akt_id=(int)_UNDEF;
				UtilSplitFreeMenubuffer(to_buffers);
				return((int)MPERROR);
				}
			}

		txt.typ=(int)_AKTIONEN;
		txt.s_id=(int)sprache;
		txt.textid=akt.textid;
		akt.textid=xTxtWrite(to_buffers[MAKT_TXT]);

		status=WriteEntry((int)_AKTIONEN, (char *)&akt, &bez);
		if (status == (int)MPERROR)
			akt.akt_id=(int)_UNDEF;
		}
	else
		{
		UtilMsg((int)MPE_NOBEZ, MSGTYP_ERROR, NULL);
		akt.akt_id=(int)_UNDEF;
		status=(int)MPERROR;
		}

	UtilSplitFreeMenubuffer(to_buffers);
	return(status);
}
Пример #26
0
Файл: HDD.cpp Проект: ss23/rpcs3
bool vfsHDD::Create(vfsHDD_EntryType type, const std::string& name)
{
	if (HasEntry(name))
	{
		return false;
	}

	u64 new_block = FindFreeBlock();
	if (!new_block)
	{
		return false;
	}

	LOG_NOTICE(HLE, "CREATING ENTRY AT 0x%llx", new_block);
	WriteBlock(new_block, g_used_block);

	{
		vfsHDD_Entry new_entry;
		vfsHDDManager::CreateEntry(new_entry);
		new_entry.next_block = 0;
		new_entry.type = type;

		if (type == vfsHDD_Entry_Dir)
		{
			u64 block_cur = FindFreeBlock();

			if (!block_cur)
			{
				return false;
			}

			WriteBlock(block_cur, g_used_block);

			u64 block_last = FindFreeBlock();

			if (!block_last)
			{
				return false;
			}

			WriteBlock(block_last, g_used_block);

			vfsHDD_Entry entry_cur, entry_last;
			vfsHDDManager::CreateEntry(entry_cur);
			vfsHDDManager::CreateEntry(entry_last);

			entry_cur.type = vfsHDD_Entry_Dir;
			entry_cur.data_block = block_cur;
			entry_cur.next_block = block_last;

			entry_last.type = vfsHDD_Entry_Dir;
			entry_last.data_block = m_cur_dir_block;
			entry_last.next_block = 0;

			new_entry.data_block = block_cur;

			WriteEntry(block_cur, entry_cur, ".");
			WriteEntry(block_last, entry_last, "..");
		}

		WriteEntry(new_block, new_entry, name);
	}

	{
		u64 block = m_cur_dir_block;

		vfsHDD_Block tmp;
		while (block)
		{
			ReadBlock(block, tmp);

			if (!tmp.next_block)
				break;

			block = tmp.next_block;
		}

		tmp.next_block = new_block;
		WriteBlock(block, tmp);
	}

	return true;
}
Пример #27
0
ForceInline void main2(int argc, TCHAR **argv)
{
    if (argc < 2)
    {
        _tprintf(_T("%s input_dir\n"), findname(argv[0]));
        return;
    }

    TCHAR  szOutFile[MAX_PATH];
    HANDLE hOut, hHeap;
    DWORD  dwLength, dwEntryCount;
    PAZTYPE PazType;
    TMyPAZEntry *pEntry;

    hHeap = GetProcessHeap();
    ghHeap = hHeap;
    for (int i = 1; i != argc; ++i)
    {
        Char  (*pPazHeader)[sizeof(headers[0])];
        DWORD dwAttributes;

        dwAttributes = GetFileAttributes(argv[i]);
        if (dwAttributes == -1)
        {
            _tprintf(_T("\"%s\" doesn't exist.\n"), argv[i]);
            continue;
        }
        else if ((dwAttributes & FILE_ATTRIBUTE_DIRECTORY) == 0)
        {
            _tprintf(_T("%s isn't a directory.\n"), argv[i]);
            continue;
        }

        LPCSTR lpPath;

        lstrcpy(szOutFile, argv[i]);
        dwLength = lstrlen(szOutFile);
        if (szOutFile[dwLength - 1] == '\\')
            szOutFile[dwLength - 1] = 0;
        lstrcat(szOutFile, ".paz");

        lpPath = argv[i];
        PazType = NONE;
        if (i + 2 < argc)
        {
            int j = i + 1;
            if (argv[j][0] == '-' && ((argv[j][1] & 0xDF) == 'T'))
            {
                ++j;
                for (int k = 0; k != countof(szType); ++k)
                {
                    if (!lstrcmpi(szType[k], argv[j]))
                    {
                        i = j;
                        PazType = (PAZTYPE)k;
                        break;
                    }
                }
            }
        }
        else
        {
            PazType = GetPazTypeFromFileName(szOutFile);
        }

        if (PazType == NONE)
        {
            _tprintf(_T("Please specify one PAZ type by -t type or use a special file name.\n")
                _T("Following type is valid: \n\t")
                );
            for (int i = 0; i != countof(szType); ++i)
            {
                printf("%s ", szType[i]);
                if (i == countof(szType) / 2)
                    printf("\n\t");
            }

            break;
        }

        dwKeyIndex = GetKeyIndex(szType[PazType], &GameInfo[dwInfoIndex]);
        if (dwKeyIndex == -1)
        {
            printf("%s: don't know encryption key.\n", szOutFile);
            continue;
        }

        hOut = CreateFile(szOutFile,
                        GENERIC_READ|GENERIC_WRITE,
                        FILE_SHARE_READ|FILE_SHARE_WRITE,
                        NULL,
                        CREATE_ALWAYS,
                        FILE_ATTRIBUTE_NORMAL,
                        NULL);
        if (hOut == INVALID_HANDLE_VALUE)
        {
            _tprintf(_T("Can't create \"%s\"\n"), szOutFile);
            continue;
        }

        g_bIsMovie = IsMovie(szOutFile);
        bIsVoice = IsAudio(szOutFile);
        SetCurrentDirectory(lpPath);
        dwEntryCount = GenerateEntry(&pEntry);
        if (dwEntryCount == 0 || pEntry == NULL)
        {
            _tprintf(_T("There is no file in \"%s\"\n"), argv[i]);
            continue;
        }

        bNeedXor = strnicmp(szType[PazType], "pm", 2) != 0;
        _tprintf(_T("Packing %s ...\n"), szOutFile);
        if (bNeedXor)
        {
            pPazHeader = (Char (*)[32])headers[dwInfoIndex];
        }
        else
            pPazHeader = (Char (*)[32])headers[countof(headers) - 1];

        WriteFile(hOut, pPazHeader, sizeof(*pPazHeader), &dwLength, NULL);
        WriteEntry(hOut, pEntry, dwEntryCount, False);

        WriteFileToPaz(hOut, pEntry, dwEntryCount, PazType);
        WriteEntry(hOut, pEntry, dwEntryCount, True);

//        HeapFree(hHeap, 0, pEntry);
        FreeFileList(pEntry);
        CloseHandle(hOut);
    }
}
Пример #28
0
int KOLinput(int len, char *buffer )
{
	extern KOLLEKTIV kol;
	extern REISENDER rei;
	extern BEZEICHNUNG bez;
	extern KOLLEKTIV_TYP kolt;
	extern TEXTE txt;
	extern KOMMISSION kom;
	extern int sprache;
	
	REISENDER tmprei;
	KUNDEN rechnungsadr;
	KUNDEN buchungsstelle;
	char *to_buffers[MAX_MENU_ITEMS];
	int status=(int)MPOK;

	/* init */
	kol.kid    = (int)_UNDEF;
	kol.k_id   = (int)_UNDEF;
	kol.textid = (int)_UNDEF;
	kol.k_sta  = (int)_UNDEF;	/* Nicht gesetzt */
	bez.s_id   = sprache;
	bez.typ    = (int)_KOLLEKTIV;
	txt.textid = (int)_UNDEF;
	txt.typ    = (int)_KOLLEKTIV;
	txt.s_id   = sprache;
	
	/* get menu fields */
	status = UtilSplitMenubuffer(buffer, to_buffers, NULL);
	if (status != MPOK)
		{
		UtilMsg((int)MPE_CUTBUFFERIN, MSGTYP_ERROR, NULL);
		kol.k_id = (int)_UNDEF;
		return((int)MPERROR);
		}

	/* check MUST fields */
	if (*to_buffers[MKOL_BEZ] == NULL)
		{
		UtilSplitFreeMenubuffer(to_buffers);
		UtilMsg((int)MPE_NOBEZ, MSGTYP_ERROR, NULL);
		return((int)MPWARNING);
		}
	if (*to_buffers[MKOL_KOLT] == NULL)
		{
		UtilSplitFreeMenubuffer(to_buffers);
		UtilMsg((int)MPE_NOKOLT, MSGTYP_ERROR, NULL);
		return((int)MPWARNING);
		}
	if (*to_buffers[MKOL_KUNBCH] == NULL)
		{
		UtilSplitFreeMenubuffer(to_buffers);
		UtilMsg((int)MPE_NOBCHST, MSGTYP_ERROR, NULL);
		return((int)MPWARNING);
		}

	if (ACTIONTYP == UPDATE || ACTIONTYP == MPDELETE)
		{
		kol.k_id = MPAPIselectEntry((int)_KOLLEKTIV, to_buffers[MKOL_BEZ],
		     (char *)&kol, sizeof(KOLLEKTIV), sizeof(kol.k_id));
		}

	/* make action */
	switch (ACTIONTYP)
		{
		case MPDELETE:
			break;

		case UPDATE:
		case INSERT:
			/* BEZEICHNUNG only for INSERT */
			(void)copyTextTo(bez.bez, to_buffers[MKOL_BEZ], (int)_BEZLEN);

			/* KOLLEKTIV-TYP */
			kol.k_typ_id = MPAPIselectEntry((int)_KOLLEKTIV_TYP,
			        to_buffers[MKOL_KOLT], (char *)&kolt, sizeof(KOLLEKTIV_TYP),
			        sizeof(kol.k_typ_id));

			/* KUN BUCHUNGSSTELLE */
			kol.kbst = MPAPIselectEntry((int)_KUNDEN, to_buffers[MKOL_KUNBCH],
				(char *)&buchungsstelle, sizeof(KUNDEN), sizeof(kol.kbst));

			/* DLN as responsible */
			if ( *to_buffers[MKOL_VERANT] != NULL )
				{
				kol.hauptpers = MPAPIselectEntry( (int)_REISENDER, to_buffers[MKOL_VERANT], (char *)&tmprei,
											 sizeof( REISENDER ), sizeof( tmprei.pers_id ) );
				}
			else
				kol.hauptpers = (int)_UNDEF;
				
			/* KUN RECHNUNGSSTELLE */
			if (*to_buffers[MKOL_KUNRECH] != NULL)
				kol.kid = MPAPIselectEntry( (int)_KUNDEN, to_buffers[MKOL_KUNRECH],
				 (char *)&rechnungsadr, sizeof(KUNDEN), sizeof(kol.kid));

			/* KOL reference */
			if (*to_buffers[MKOL_REF] != NULL)
				(void)strcpy(kol.ref, to_buffers[MKOL_REF]);
			else
				*kol.ref = NULL;

			/* TEXTE */
			txt.textid = kol.textid;
			kol.textid = xTxtWrite(to_buffers[MKOL_TXT]);
			break;
		}

	/* ... and action */
	status = WriteEntry((int)_KOLLEKTIV, (char *)&kol, &bez);
	if (status != (int)MPOK)
		{
		kol.k_id = (int)_UNDEF;
		status   = (int)MPERROR;
		}

	UtilSplitFreeMenubuffer(to_buffers);
	return(status);
}
Пример #29
0
void DataArchive::Insert(const char* name)
{
   DWORD old_blocks = 0,     old_offset = 0,     new_blocks = 0;
   DWORD old_dir_blocks = 0, old_dir_offset = 0, new_dir_blocks = 0;
   int   added = 0;

   int index = FindEntry(name);
   
   if (index < 0) {
      old_dir_blocks = DirBlocks();
      old_dir_offset = header.dir_offset;
      
      index = InsertEntry(name);
      
      if (index >= (int) header.nfiles) {
         header.nfiles = index+1;
         added = 1;
      }

      new_dir_blocks = DirBlocks();
      
      if (new_dir_blocks > old_dir_blocks) {
         header.dir_offset = FindDataBlocks(new_dir_blocks);
         CreateBlockMap();
      }
   }
   else {
      old_blocks = FileBlocks(index);
      old_offset = directory[index].offset;
   }
   
   if (index >= 0) {
      DataEntry& e = directory[index];
      
      if (verbose) printf("   Inserting: %-48s ", e.name);

      BYTE* buf = CompressEntry(index);
      
      if (!buf) {
         // this is (almost) unrecoverable,
         // so we quit before screwing things up:
         printf("ERROR: Could not compress %d:%s\n", index, directory[index].name);
         exit(1);
      }

      new_blocks = FileBlocks(index);
      
      // the file is new, or got bigger,
      // need to find room for the data:
      if (new_blocks > old_blocks) {
         directory[index].offset = FindDataBlocks(new_blocks);
         CreateBlockMap();
      }

      WriteEntry(index, buf);
      delete [] buf;
      
      if (verbose) {
         int    ratio = (int) (100.0 * (double) e.size_comp / (double) e.size_orig);
         printf("%9d => %9d (%2d%%)\n", e.size_orig, e.size_comp, ratio); //-V576
      }
   }
   else if (added)
      header.nfiles--;
}
Пример #30
0
int TXTinput(int len, char *buffer )
{
	extern TEXTE txt;
	extern SPRACHEN spr;
	extern int sprache;

	int status=(int)MPOK;
	char *to_buffers[MAX_MENU_ITEMS];

	if (ACTIONTYP == (unsigned char)INSERT)
		{
		txt.s_id=(int)_UNDEF;
		txt.textid=(int)_UNDEF;
		}

	status = UtilSplitMenubuffer(buffer, to_buffers, (char)NULL);
	if (status != (int)MPOK)
		{
		UtilMsg((int)MPE_CUTBUFFERIN, MSGTYP_ERROR, NULL);
		txt.textid = (int)_UNDEF;
		return((int)MPERROR);
		}

	if (*to_buffers[MTXT_SPR] != NULL)
		txt.s_id=MPAPIselectEntry((int)_SPRACHEN, to_buffers[MTXT_SPR], (char *)&spr, sizeof(SPRACHEN), sizeof(txt.s_id));
	else
		txt.s_id=(int)_UNDEF;

	if (txt.s_id == (int)_UNDEF)
		txt.s_id=sprache;

	if (txt.s_id != (int)_UNDEF)
		{
		if (*to_buffers[MTXT_TXT] != NULL)
			{

			status=WriteEntry((int)_TEXTE, (char *)&txt, (BEZEICHNUNG *)NULL);

			if (status == (int)MPERROR)
				{
				txt.textid=(int)_UNDEF;
				}
			}
		else
			{
			UtilMsg((int)MSG2, MSGTYP_ERROR, NULL);
			txt.textid=(int)_UNDEF;
			status=(int)MPERROR;
			}
		}
	else
		{
		UtilMsg((int)MSG1, MSGTYP_ERROR, NULL);
		txt.textid=(int)_UNDEF;
		status=(int)MPERROR;
		}

	UtilSplitFreeMenubuffer(to_buffers);

	return(status);
}