Lines Matching refs:params

552 static void PrintHashForCorruptedSourceBlocks(const CommandParameters& params,  in PrintHashForCorruptedSourceBlocks()  argument
554 LOG(INFO) << "unexpected contents of source blocks in cmd:\n" << params.cmdline; in PrintHashForCorruptedSourceBlocks()
555 CHECK(params.tokens[0] == "move" || params.tokens[0] == "bsdiff" || in PrintHashForCorruptedSourceBlocks()
556 params.tokens[0] == "imgdiff"); in PrintHashForCorruptedSourceBlocks()
563 if (params.tokens[0] == "move") { in PrintHashForCorruptedSourceBlocks()
565 if (params.tokens.size() < 5) { in PrintHashForCorruptedSourceBlocks()
566 LOG(ERROR) << "failed to parse source range in cmd:\n" << params.cmdline; in PrintHashForCorruptedSourceBlocks()
572 if (params.tokens.size() < 8) { in PrintHashForCorruptedSourceBlocks()
573 LOG(ERROR) << "failed to parse source range in cmd:\n" << params.cmdline; in PrintHashForCorruptedSourceBlocks()
580 if (params.tokens[pos] == "-") { in PrintHashForCorruptedSourceBlocks()
584 RangeSet src = RangeSet::Parse(params.tokens[pos++]); in PrintHashForCorruptedSourceBlocks()
586 LOG(ERROR) << "Failed to parse range in " << params.cmdline; in PrintHashForCorruptedSourceBlocks()
593 if (pos == params.tokens.size()) { in PrintHashForCorruptedSourceBlocks()
600 locs = RangeSet::Parse(params.tokens[pos++]); in PrintHashForCorruptedSourceBlocks()
735 static int LoadStash(const CommandParameters& params, const std::string& id, bool verify, in LoadStash() argument
739 if (!params.canwrite) { in LoadStash()
744 if (ReadBlocks(src, buffer, params.fd) == -1) { in LoadStash()
759 std::string fn = GetStashFileName(params.stashbase, id, ""); in LoadStash()
765 PrintHashForMissingStashedBlocks(id, params.fd); in LoadStash()
797 << " when executing command: " << params.cmdname; in LoadStash()
993 static int LoadSourceBlocks(CommandParameters& params, const RangeSet& tgt, size_t* src_blocks, in LoadSourceBlocks() argument
999 const std::string& token = params.tokens[params.cpos++]; in LoadSourceBlocks()
1005 allocate(*src_blocks * BLOCKSIZE, &params.buffer); in LoadSourceBlocks()
1008 if (params.tokens[params.cpos] == "-") { in LoadSourceBlocks()
1010 params.cpos++; in LoadSourceBlocks()
1012 RangeSet src = RangeSet::Parse(params.tokens[params.cpos++]); in LoadSourceBlocks()
1016 if (ReadBlocks(src, &params.buffer, params.fd) == -1) { in LoadSourceBlocks()
1020 if (params.cpos >= params.tokens.size()) { in LoadSourceBlocks()
1025 RangeSet locs = RangeSet::Parse(params.tokens[params.cpos++]); in LoadSourceBlocks()
1027 MoveRange(params.buffer, locs, params.buffer); in LoadSourceBlocks()
1031 while (params.cpos < params.tokens.size()) { in LoadSourceBlocks()
1034 std::vector<std::string> tokens = android::base::Split(params.tokens[params.cpos++], ":"); in LoadSourceBlocks()
1041 if (LoadStash(params, tokens[0], false, &stash, true) == -1) { in LoadSourceBlocks()
1050 MoveRange(params.buffer, locs, stash); in LoadSourceBlocks()
1082 static int LoadSrcTgtVersion3(CommandParameters& params, RangeSet* tgt, size_t* src_blocks, in LoadSrcTgtVersion3() argument
1086 if (params.cpos >= params.tokens.size()) { in LoadSrcTgtVersion3()
1091 std::string srchash = params.tokens[params.cpos++]; in LoadSrcTgtVersion3()
1097 if (params.cpos >= params.tokens.size()) { in LoadSrcTgtVersion3()
1101 tgthash = params.tokens[params.cpos++]; in LoadSrcTgtVersion3()
1106 if (params.cpos + 2 >= params.tokens.size()) { in LoadSrcTgtVersion3()
1112 *tgt = RangeSet::Parse(params.tokens[params.cpos++]); in LoadSrcTgtVersion3()
1116 if (ReadBlocks(*tgt, &tgtbuffer, params.fd) == -1) { in LoadSrcTgtVersion3()
1127 if (LoadSourceBlocks(params, *tgt, src_blocks, &overlap) == -1) { in LoadSrcTgtVersion3()
1131 if (VerifyBlocks(srchash, params.buffer, *src_blocks, true) == 0) { in LoadSrcTgtVersion3()
1135 if (overlap && params.canwrite) { in LoadSrcTgtVersion3()
1139 if (WriteStash(params.stashbase, srchash, *src_blocks, params.buffer, true, in LoadSrcTgtVersion3()
1145 params.stashed += *src_blocks; in LoadSrcTgtVersion3()
1148 params.freestash = srchash; in LoadSrcTgtVersion3()
1156 if (overlap && LoadStash(params, srchash, true, &params.buffer, true) == 0) { in LoadSrcTgtVersion3()
1165 PrintHashForCorruptedSourceBlocks(params, params.buffer); in LoadSrcTgtVersion3()
1167 params.isunresumable = true; in LoadSrcTgtVersion3()
1172 static int PerformCommandMove(CommandParameters& params) { in PerformCommandMove() argument
1175 int status = LoadSrcTgtVersion3(params, &tgt, &blocks, true); in PerformCommandMove()
1183 params.foundwrites = true; in PerformCommandMove()
1185 params.target_verified = true; in PerformCommandMove()
1186 if (params.foundwrites) { in PerformCommandMove()
1187 LOG(WARNING) << "warning: commands executed out of order [" << params.cmdname << "]"; in PerformCommandMove()
1191 if (params.canwrite) { in PerformCommandMove()
1195 if (WriteBlocks(tgt, params.buffer, params.fd) == -1) { in PerformCommandMove()
1203 if (!params.freestash.empty()) { in PerformCommandMove()
1204 FreeStash(params.stashbase, params.freestash); in PerformCommandMove()
1205 params.freestash.clear(); in PerformCommandMove()
1208 params.written += tgt.blocks(); in PerformCommandMove()
1213 static int PerformCommandStash(CommandParameters& params) { in PerformCommandStash() argument
1215 if (params.cpos + 1 >= params.tokens.size()) { in PerformCommandStash()
1220 const std::string& id = params.tokens[params.cpos++]; in PerformCommandStash()
1221 if (LoadStash(params, id, true, &params.buffer, false) == 0) { in PerformCommandStash()
1227 RangeSet src = RangeSet::Parse(params.tokens[params.cpos++]); in PerformCommandStash()
1231 allocate(blocks * BLOCKSIZE, &params.buffer); in PerformCommandStash()
1232 if (ReadBlocks(src, &params.buffer, params.fd) == -1) { in PerformCommandStash()
1237 if (VerifyBlocks(id, params.buffer, blocks, true) != 0) { in PerformCommandStash()
1246 if (!params.canwrite) { in PerformCommandStash()
1251 int result = WriteStash(params.stashbase, id, blocks, params.buffer, false, nullptr); in PerformCommandStash()
1253 params.stashed += blocks; in PerformCommandStash()
1258 static int PerformCommandFree(CommandParameters& params) { in PerformCommandFree() argument
1260 if (params.cpos >= params.tokens.size()) { in PerformCommandFree()
1265 const std::string& id = params.tokens[params.cpos++]; in PerformCommandFree()
1268 if (params.createdstash || params.canwrite) { in PerformCommandFree()
1269 return FreeStash(params.stashbase, id); in PerformCommandFree()
1275 static int PerformCommandZero(CommandParameters& params) { in PerformCommandZero() argument
1276 if (params.cpos >= params.tokens.size()) { in PerformCommandZero()
1281 RangeSet tgt = RangeSet::Parse(params.tokens[params.cpos++]); in PerformCommandZero()
1286 allocate(BLOCKSIZE, &params.buffer); in PerformCommandZero()
1287 memset(params.buffer.data(), 0, BLOCKSIZE); in PerformCommandZero()
1289 if (params.canwrite) { in PerformCommandZero()
1293 if (!discard_blocks(params.fd, offset, size)) { in PerformCommandZero()
1297 if (!check_lseek(params.fd, offset, SEEK_SET)) { in PerformCommandZero()
1302 if (!android::base::WriteFully(params.fd, params.buffer.data(), BLOCKSIZE)) { in PerformCommandZero()
1311 if (params.cmdname[0] == 'z') { in PerformCommandZero()
1314 params.written += tgt.blocks(); in PerformCommandZero()
1320 static int PerformCommandNew(CommandParameters& params) { in PerformCommandNew() argument
1321 if (params.cpos >= params.tokens.size()) { in PerformCommandNew()
1326 RangeSet tgt = RangeSet::Parse(params.tokens[params.cpos++]); in PerformCommandNew()
1329 if (params.canwrite) { in PerformCommandNew()
1332 pthread_mutex_lock(&params.nti.mu); in PerformCommandNew()
1333 params.nti.writer = std::make_unique<RangeSinkWriter>(params.fd, tgt); in PerformCommandNew()
1334 pthread_cond_broadcast(&params.nti.cv); in PerformCommandNew()
1336 while (params.nti.writer != nullptr) { in PerformCommandNew()
1337 if (!params.nti.receiver_available) { in PerformCommandNew()
1338 LOG(ERROR) << "missing " << (tgt.blocks() * BLOCKSIZE - params.nti.writer->BytesWritten()) in PerformCommandNew()
1340 pthread_mutex_unlock(&params.nti.mu); in PerformCommandNew()
1343 pthread_cond_wait(&params.nti.cv, &params.nti.mu); in PerformCommandNew()
1346 pthread_mutex_unlock(&params.nti.mu); in PerformCommandNew()
1349 params.written += tgt.blocks(); in PerformCommandNew()
1354 static int PerformCommandDiff(CommandParameters& params) { in PerformCommandDiff() argument
1356 if (params.cpos + 1 >= params.tokens.size()) { in PerformCommandDiff()
1357 LOG(ERROR) << "missing patch offset or length for " << params.cmdname; in PerformCommandDiff()
1362 if (!android::base::ParseUint(params.tokens[params.cpos++], &offset)) { in PerformCommandDiff()
1368 if (!android::base::ParseUint(params.tokens[params.cpos++], &len)) { in PerformCommandDiff()
1375 int status = LoadSrcTgtVersion3(params, &tgt, &blocks, false); in PerformCommandDiff()
1383 params.foundwrites = true; in PerformCommandDiff()
1385 params.target_verified = true; in PerformCommandDiff()
1386 if (params.foundwrites) { in PerformCommandDiff()
1387 LOG(WARNING) << "warning: commands executed out of order [" << params.cmdname << "]"; in PerformCommandDiff()
1391 if (params.canwrite) { in PerformCommandDiff()
1396 std::string(reinterpret_cast<const char*>(params.patch_start + offset), len)); in PerformCommandDiff()
1398 RangeSinkWriter writer(params.fd, tgt); in PerformCommandDiff()
1399 if (params.cmdname[0] == 'i') { // imgdiff in PerformCommandDiff()
1400 if (ApplyImagePatch(params.buffer.data(), blocks * BLOCKSIZE, patch_value, in PerformCommandDiff()
1409 if (ApplyBSDiffPatch(params.buffer.data(), blocks * BLOCKSIZE, patch_value, 0, in PerformCommandDiff()
1427 << params.cmdline << "]"; in PerformCommandDiff()
1431 if (!params.freestash.empty()) { in PerformCommandDiff()
1432 FreeStash(params.stashbase, params.freestash); in PerformCommandDiff()
1433 params.freestash.clear(); in PerformCommandDiff()
1436 params.written += tgt.blocks(); in PerformCommandDiff()
1441 static int PerformCommandErase(CommandParameters& params) { in PerformCommandErase() argument
1443 return PerformCommandZero(params); in PerformCommandErase()
1447 if (fstat(params.fd, &sb) == -1) { in PerformCommandErase()
1457 if (params.cpos >= params.tokens.size()) { in PerformCommandErase()
1462 RangeSet tgt = RangeSet::Parse(params.tokens[params.cpos++]); in PerformCommandErase()
1465 if (params.canwrite) { in PerformCommandErase()
1471 if (!discard_blocks(params.fd, offset, size, true /* force */)) { in PerformCommandErase()
1493 static int PerformCommandComputeHashTree(CommandParameters& params) { in PerformCommandComputeHashTree() argument
1494 if (params.cpos + 5 != params.tokens.size()) { in PerformCommandComputeHashTree()
1495 LOG(ERROR) << "Invaild arguments count in hash computation " << params.cmdline; in PerformCommandComputeHashTree()
1500 RangeSet hash_tree_ranges = RangeSet::Parse(params.tokens[params.cpos++]); in PerformCommandComputeHashTree()
1502 LOG(ERROR) << "Invalid hash tree ranges in " << params.cmdline; in PerformCommandComputeHashTree()
1506 RangeSet source_ranges = RangeSet::Parse(params.tokens[params.cpos++]); in PerformCommandComputeHashTree()
1508 LOG(ERROR) << "Invalid source ranges in " << params.cmdline; in PerformCommandComputeHashTree()
1512 auto hash_function = HashTreeBuilder::HashFunction(params.tokens[params.cpos++]); in PerformCommandComputeHashTree()
1514 LOG(ERROR) << "Invalid hash algorithm in " << params.cmdline; in PerformCommandComputeHashTree()
1519 std::string salt_hex = params.tokens[params.cpos++]; in PerformCommandComputeHashTree()
1521 LOG(ERROR) << "Failed to parse salt in " << params.cmdline; in PerformCommandComputeHashTree()
1525 std::string expected_root_hash = params.tokens[params.cpos++]; in PerformCommandComputeHashTree()
1527 LOG(ERROR) << "Invalid root hash in " << params.cmdline; in PerformCommandComputeHashTree()
1543 if (!check_lseek(params.fd, static_cast<off64_t>(begin) * BLOCKSIZE, SEEK_SET)) { in PerformCommandComputeHashTree()
1549 if (!android::base::ReadFully(params.fd, buffer, BLOCKSIZE)) { in PerformCommandComputeHashTree()
1575 if (params.canwrite && !builder.WriteHashTreeToFd(params.fd, write_offset)) { in PerformCommandComputeHashTree()
1629 CommandParameters params = {}; in PerformBlockImageUpdate() local
1631 params.canwrite = !dryrun; in PerformBlockImageUpdate()
1695 params.patch_start = updater->GetMappedPackageAddress() + patch_entry.offset; in PerformBlockImageUpdate()
1704 params.fd.reset(TEMP_FAILURE_RETRY(open(block_device_path.c_str(), O_RDWR))); in PerformBlockImageUpdate()
1705 if (params.fd == -1) { in PerformBlockImageUpdate()
1715 params.stashbase = print_sha1(digest); in PerformBlockImageUpdate()
1720 std::string updated_marker = GetStashFileName(params.stashbase + ".UPDATED", "", ""); in PerformBlockImageUpdate()
1746 if (!android::base::ParseInt(lines[0], &params.version, 3, 4)) { in PerformBlockImageUpdate()
1751 LOG(INFO) << "blockimg version is " << params.version; in PerformBlockImageUpdate()
1775 int res = CreateStash(state, stash_max_blocks, params.stashbase); in PerformBlockImageUpdate()
1779 params.createdstash = res; in PerformBlockImageUpdate()
1782 if (params.canwrite) { in PerformBlockImageUpdate()
1783 params.nti.za = za; in PerformBlockImageUpdate()
1784 params.nti.entry = new_entry; in PerformBlockImageUpdate()
1785 params.nti.brotli_compressed = android::base::EndsWith(new_data_fn->data, ".br"); in PerformBlockImageUpdate()
1786 if (params.nti.brotli_compressed) { in PerformBlockImageUpdate()
1788 params.nti.brotli_decoder_state = BrotliDecoderCreateInstance(nullptr, nullptr, nullptr); in PerformBlockImageUpdate()
1790 params.nti.receiver_available = true; in PerformBlockImageUpdate()
1792 pthread_mutex_init(&params.nti.mu, nullptr); in PerformBlockImageUpdate()
1793 pthread_cond_init(&params.nti.cv, nullptr); in PerformBlockImageUpdate()
1798 int error = pthread_create(&params.thread, &attr, unzip_new_data, &params.nti); in PerformBlockImageUpdate()
1831 params.tokens = android::base::Split(line, " "); in PerformBlockImageUpdate()
1832 params.cpos = 0; in PerformBlockImageUpdate()
1833 params.cmdname = params.tokens[params.cpos++]; in PerformBlockImageUpdate()
1834 params.cmdline = line; in PerformBlockImageUpdate()
1835 params.target_verified = false; in PerformBlockImageUpdate()
1837 Command::Type cmd_type = Command::ParseType(params.cmdname); in PerformBlockImageUpdate()
1839 LOG(ERROR) << "unexpected command [" << params.cmdname << "]"; in PerformBlockImageUpdate()
1854 if (params.canwrite && skip_executed_command && cmdindex <= saved_last_command_index && in PerformBlockImageUpdate()
1861 if (performer(params) == -1) { in PerformBlockImageUpdate()
1872 if (!params.canwrite && skip_executed_command && cmdindex <= saved_last_command_index) { in PerformBlockImageUpdate()
1876 !params.target_verified) { in PerformBlockImageUpdate()
1878 << params.cmdline << " doesn't produce expected target blocks."; in PerformBlockImageUpdate()
1884 if (params.canwrite) { in PerformBlockImageUpdate()
1885 if (fsync(params.fd) == -1) { in PerformBlockImageUpdate()
1891 if (!UpdateLastCommandIndex(cmdindex, params.cmdline)) { in PerformBlockImageUpdate()
1897 static_cast<double>(params.written) / total_blocks), in PerformBlockImageUpdate()
1905 if (params.canwrite) { in PerformBlockImageUpdate()
1906 pthread_mutex_lock(&params.nti.mu); in PerformBlockImageUpdate()
1907 if (params.nti.receiver_available) { in PerformBlockImageUpdate()
1910 params.nti.receiver_available = false; in PerformBlockImageUpdate()
1911 pthread_cond_broadcast(&params.nti.cv); in PerformBlockImageUpdate()
1912 pthread_mutex_unlock(&params.nti.mu); in PerformBlockImageUpdate()
1913 int ret = pthread_join(params.thread, nullptr); in PerformBlockImageUpdate()
1919 LOG(INFO) << "wrote " << params.written << " blocks; expected " << total_blocks; in PerformBlockImageUpdate()
1920 LOG(INFO) << "stashed " << params.stashed << " blocks"; in PerformBlockImageUpdate()
1921 LOG(INFO) << "max alloc needed was " << params.buffer.size(); in PerformBlockImageUpdate()
1927 static_cast<uint64_t>(params.written) * BLOCKSIZE)); in PerformBlockImageUpdate()
1930 static_cast<uint64_t>(params.stashed) * BLOCKSIZE), in PerformBlockImageUpdate()
1935 DeleteStash(params.stashbase); in PerformBlockImageUpdate()
1946 pthread_mutex_destroy(&params.nti.mu); in PerformBlockImageUpdate()
1947 pthread_cond_destroy(&params.nti.cv); in PerformBlockImageUpdate()
1952 if (fsync(params.fd) == -1) { in PerformBlockImageUpdate()
1958 if (params.nti.brotli_decoder_state != nullptr) { in PerformBlockImageUpdate()
1959 BrotliDecoderDestroyInstance(params.nti.brotli_decoder_state); in PerformBlockImageUpdate()
1963 if (params.isunresumable) { in PerformBlockImageUpdate()
1969 if (params.isunresumable || (!params.canwrite && params.createdstash)) { in PerformBlockImageUpdate()
1970 DeleteStash(params.stashbase); in PerformBlockImageUpdate()