示例#1
0
static bool ext4_sb_verify_csum(struct ext4_sblock *s)
{
	if (!ext4_sb_feature_ro_com(s, EXT4_FRO_COM_METADATA_CSUM))
		return true;

	if (s->checksum_type != to_le32(EXT4_CHECKSUM_CRC32C))
		return false;

	return s->checksum == to_le32(ext4_sb_csum(s));
}
示例#2
0
static void
ext4_dir_set_dx_checksum(struct ext4_inode_ref *inode_ref,
			struct ext4_directory_entry_ll *dirent)
{
	int count_offset, limit, count;
	struct ext4_sblock *sb = &inode_ref->fs->sb;

	if (ext4_sb_feature_ro_com(sb, EXT4_FRO_COM_METADATA_CSUM)) {
		struct ext4_directory_dx_countlimit *countlimit =
			ext4_dir_dx_get_countlimit(inode_ref, dirent, &count_offset);
		if (!countlimit) {
			/* Directory seems corrupted. */
			return;
		}
		struct ext4_directory_dx_tail *t;
		limit = ext4_dir_dx_countlimit_get_limit(countlimit);
		count = ext4_dir_dx_countlimit_get_count(countlimit);
		if (count_offset + (limit * sizeof(struct ext4_directory_dx_entry)) >
				ext4_sb_get_block_size(sb) -
				sizeof(struct ext4_directory_dx_tail)) {
			/* There is no space to hold the checksum */
			return;
		}
		t = (struct ext4_directory_dx_tail *)
			(((struct ext4_directory_dx_entry *)countlimit) + limit);

		t->checksum =
			to_le32(ext4_dir_dx_checksum(inode_ref, dirent, count_offset, count, t));
	}
}
示例#3
0
static void ext4_sb_set_csum(struct ext4_sblock *s)
{
	if (!ext4_sb_feature_ro_com(s, EXT4_FRO_COM_METADATA_CSUM))
		return;

	s->checksum = to_le32(ext4_sb_csum(s));
}
示例#4
0
文件: FileIo.cpp 项目: Marlinc/0ad
void CFilePacker::Write(const VfsPath& filename)
{
	const size_t payloadSize = m_writeBuffer.Size() - sizeof(FileHeader);
	const u32 payloadSize_le = to_le32(u32_from_larger(payloadSize));
	m_writeBuffer.Overwrite(&payloadSize_le, sizeof(payloadSize_le), 0+offsetof(FileHeader, payloadSize_le));

	// write out all data (including header)
	if(g_VFS->CreateFile(filename, m_writeBuffer.Data(), m_writeBuffer.Size()) < 0)
		throw PSERROR_File_WriteFailed();
}
示例#5
0
void IDeserializer::NumberI32(const char* name, int32_t& out, int32_t lower, int32_t upper)
{
	int32_t value;
	Get(name, (u8*)&value, sizeof(uint32_t));
	value = (i32)to_le32((u32)value);

	if (!(lower <= value && value <= upper))
		throw PSERROR_Deserialize_OutOfBounds(name);

	out = value;
}
示例#6
0
static uint32_t
ext4_dir_dx_checksum(struct ext4_inode_ref *inode_ref,
		 void *dirent,
		 int count_offset, int count, struct ext4_directory_dx_tail *t)
{
	uint32_t orig_checksum, checksum = 0;
	struct ext4_sblock *sb = &inode_ref->fs->sb;
	int size;

	/* Compute the checksum only if the filesystem supports it */
	if (ext4_sb_feature_ro_com(sb, EXT4_FRO_COM_METADATA_CSUM)) {
		uint32_t ino_index = to_le32(inode_ref->index);
		uint32_t ino_gen =
			to_le32(ext4_inode_get_generation(inode_ref->inode));

		size = count_offset +
			(count * sizeof(struct ext4_directory_dx_tail));
		orig_checksum = t->checksum;
		t->checksum = 0;
		/* First calculate crc32 checksum against fs uuid */
		checksum = ext4_crc32c(EXT4_CRC32_INIT, sb->uuid,
				sizeof(sb->uuid));
		/* Then calculate crc32 checksum against inode number
		 * and inode generation */
		checksum = ext4_crc32c(checksum, &ino_index,
				     sizeof(ino_index));
		checksum = ext4_crc32c(checksum, &ino_gen,
				     sizeof(ino_gen));
		/* After that calculate crc32 checksum against all the dx_entry */
		checksum = ext4_crc32c(checksum, dirent, size);
		/* Finally calculate crc32 checksum for dx_tail */
		checksum = ext4_crc32c(checksum, t,
				sizeof(struct ext4_directory_dx_tail));
		t->checksum = orig_checksum;
	}
	return checksum;
}
示例#7
0
void CNetClient::LoadFinished()
{
	JSContext* cx = GetScriptInterface().GetContext();
	JSAutoRequest rq(cx);

	if (!m_JoinSyncBuffer.empty())
	{
		// We're rejoining a game, and just finished loading the initial map,
		// so deserialize the saved game state now

		std::string state;
		DecompressZLib(m_JoinSyncBuffer, state, true);

		std::stringstream stream(state);

		u32 turn;
		stream.read((char*)&turn, sizeof(turn));
		turn = to_le32(turn);

		LOGMESSAGE("Rejoining client deserializing state at turn %u\n", turn);

		bool ok = m_Game->GetSimulation2()->DeserializeState(stream);
		ENSURE(ok);

		m_ClientTurnManager->ResetState(turn, turn);

		JS::RootedValue msg(cx);
		GetScriptInterface().Eval("({'type':'netstatus','status':'join_syncing'})", &msg);
		PushGuiMessage(msg);
	}
	else
	{
		// Connecting at the start of a game, so we'll wait for other players to finish loading
		JS::RootedValue msg(cx);
		GetScriptInterface().Eval("({'type':'netstatus','status':'waiting_for_players'})", &msg);
		PushGuiMessage(msg);
	}

	CLoadedGameMessage loaded;
	loaded.m_CurrentTurn = m_ClientTurnManager->GetCurrentTurn();
	SendMessage(&loaded);
}
示例#8
0
bool CNetClient::HandleMessage(CNetMessage* message)
{
	// Handle non-FSM messages first

	Status status = m_Session->GetFileTransferer().HandleMessageReceive(message);
	if (status == INFO::OK)
		return true;
	if (status != INFO::SKIPPED)
		return false;

	if (message->GetType() == NMT_FILE_TRANSFER_REQUEST)
	{
		CFileTransferRequestMessage* reqMessage = (CFileTransferRequestMessage*)message;

		// TODO: we should support different transfer request types, instead of assuming
		// it's always requesting the simulation state

		std::stringstream stream;

		LOGMESSAGERENDER("Serializing game at turn %u for rejoining player", m_ClientTurnManager->GetCurrentTurn());
		u32 turn = to_le32(m_ClientTurnManager->GetCurrentTurn());
		stream.write((char*)&turn, sizeof(turn));

		bool ok = m_Game->GetSimulation2()->SerializeState(stream);
		ENSURE(ok);

		// Compress the content with zlib to save bandwidth
		// (TODO: if this is still too large, compressing with e.g. LZMA works much better)
		std::string compressed;
		CompressZLib(stream.str(), compressed, true);

		m_Session->GetFileTransferer().StartResponse(reqMessage->m_RequestID, compressed);

		return true;
	}

	// Update FSM
	bool ok = Update(message->GetType(), message);
	if (!ok)
		LOGERROR("Net client: Error running FSM update (type=%d state=%d)", (int)message->GetType(), (int)GetCurrState());
	return ok;
}
示例#9
0
void IDeserializer::NumberI32_Unbounded(const char* name, int32_t& out)
{
	int32_t value;
	Get(name, (u8*)&value, sizeof(int32_t));
	out = (i32)to_le32((u32)value);
}
示例#10
0
void IDeserializer::NumberU32_Unbounded(const char* name, uint32_t& out)
{
	uint32_t value;
	Get(name, (u8*)&value, sizeof(uint32_t));
	out = to_le32(value);
}
示例#11
0
uint64_t ext4_extent_get_start(struct ext4_extent *extent)
{
    return ((uint64_t)to_le16(extent->start_hi)) << 32 |
           ((uint64_t)to_le32(extent->start_lo));
}
示例#12
0
void ext4_extent_set_first_block(struct ext4_extent *extent, uint32_t iblock)
{
    extent->first_block = to_le32(iblock);
}
示例#13
0
/**@brief Set block address where child node is located.
 * @param entry Pointer to index entry
 * @param block Block address of child node
 */
static inline void
ext4_dir_dx_entry_set_block(struct ext4_directory_dx_entry *entry,
			    uint32_t block)
{
	entry->block = to_le32(block);
}
示例#14
0
/**@brief Get block address where child node is located.
 * @param entry Pointer to index entry
 * @return Block address of child node
 */
static inline uint32_t
ext4_dir_dx_entry_get_block(struct ext4_directory_dx_entry *entry)
{
	return to_le32(entry->block);
}
示例#15
0
/**@brief Set hash value of index entry.
 * @param entry Pointer to index entry
 * @param hash  Hash value
 */
static inline void
ext4_dir_dx_entry_set_hash(struct ext4_directory_dx_entry *entry, uint32_t hash)
{
	entry->hash = to_le32(hash);
}
示例#16
0
/**@brief Get hash value of index entry.
 * @param entry Pointer to index entry
 * @return Hash value
 */
static inline uint32_t
ext4_dir_dx_entry_get_hash(struct ext4_directory_dx_entry *entry)
{
	return to_le32(entry->hash);
}
示例#17
0
文件: FileIo.cpp 项目: Marlinc/0ad
void CFilePacker::PackSize(size_t value)
{
	const u32 value_le32 = to_le32(u32_from_larger(value));
	PackRaw(&value_le32, sizeof(value_le32));
}
示例#18
0
uint32_t ext4_extent_get_first_block(struct ext4_extent *extent)
{
    return to_le32(extent->first_block);
}
示例#19
0
文件: FileIo.cpp 项目: Marlinc/0ad
size_t CFileUnpacker::UnpackSize()
{
	u32 value_le32;
	UnpackRaw(&value_le32, sizeof(value_le32));
	return (size_t)to_le32(value_le32);
}