MCPcopy Create free account
hub / github.com/Parchive/par2cmdline / ComputeRecoveryBlockCount

Method ComputeRecoveryBlockCount

src/commandline.cpp:1348–1435  ·  view source on GitHub ↗

Determine how many recovery blocks to create based on the source block count and the requested level of redundancy.

Source from the content-addressed store, hash-verified

1346// Determine how many recovery blocks to create based on the source block
1347// count and the requested level of redundancy.
1348bool CommandLine::ComputeRecoveryBlockCount(u32 *recoveryblockcount,
1349 u32 sourceblockcount,
1350 u64 blocksize,
1351 u32 firstblock,
1352 Scheme recoveryfilescheme,
1353 u32 recoveryfilecount,
1354 bool recoveryblockcountset,
1355 u32 redundancy,
1356 u64 redundancysize,
1357 u64 largestfilesize)
1358{
1359 if (recoveryblockcountset) {
1360 // no need to assign value.
1361 // pass through, so that value can be checked below.
1362 }
1363 else if (redundancy > 0)
1364 {
1365 // count is the number of input blocks
1366
1367 // Determine recoveryblockcount
1368 *recoveryblockcount = (sourceblockcount * redundancy + 50) / 100;
1369 }
1370 else if (redundancysize > 0)
1371 {
1372 const u64 overhead_per_recovery_file = sourceblockcount * (u64) 21;
1373 const u64 recovery_packet_size = blocksize + (u64) 70;
1374 if (recoveryfilecount == 0)
1375 {
1376 u32 estimatedFileCount = 15;
1377 u64 overhead = estimatedFileCount * overhead_per_recovery_file;
1378 u32 estimatedrecoveryblockcount;
1379 if (overhead > redundancysize)
1380 {
1381 estimatedrecoveryblockcount = 1; // at least 1
1382 }
1383 else
1384 {
1385 estimatedrecoveryblockcount = (u32)((redundancysize - overhead) / recovery_packet_size);
1386 }
1387
1388 // recoveryfilecount assigned below.
1389 bool success = ComputeRecoveryFileCount(std::cout,
1390 std::cerr,
1391 &recoveryfilecount,
1392 recoveryfilescheme,
1393 estimatedrecoveryblockcount,
1394 largestfilesize,
1395 blocksize);
1396 if (!success) {
1397 return false;
1398 }
1399 }
1400
1401 const u64 overhead = recoveryfilecount * overhead_per_recovery_file;
1402 if (overhead > redundancysize)
1403 {
1404 *recoveryblockcount = 1; // at least 1
1405 }

Callers

nothing calls this directly

Calls 1

ComputeRecoveryFileCountFunction · 0.85

Tested by

no test coverage detected