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

Function ComputeRecoveryFileCount

src/libpar2.cpp:129–201  ·  view source on GitHub ↗

Determine how many recovery files to create.

Source from the content-addressed store, hash-verified

127
128// Determine how many recovery files to create.
129bool ComputeRecoveryFileCount(std::ostream &sout,
130 std::ostream &serr,
131 u32 *recoveryfilecount,
132 Scheme recoveryfilescheme,
133 u32 recoveryblockcount,
134 u64 largestfilesize,
135 u64 blocksize)
136{
137 // Are we computing any recovery blocks
138 if (recoveryblockcount == 0)
139 {
140 *recoveryfilecount = 0;
141 return true;
142 }
143
144 switch (recoveryfilescheme)
145 {
146 case scUnknown:
147 {
148 //assert(false);
149 serr << "Scheme unspecified (create, verify, or repair)." << std::endl;
150 return false;
151 }
152 break;
153 case scVariable:
154 case scUniform:
155 {
156 if (*recoveryfilecount == 0)
157 {
158 // If none specified then then filecount is roughly log2(blockcount)
159 // This prevents you getting excessively large numbers of files
160 // when the block count is high and also allows the files to have
161 // sizes which vary exponentially.
162
163 for (u32 blocks=recoveryblockcount; blocks>0; blocks>>=1)
164 {
165 (*recoveryfilecount)++;
166 }
167 }
168
169 if (*recoveryfilecount > recoveryblockcount)
170 {
171 // You cannot have more recovery files than there are recovery blocks
172 // to put in them.
173 serr << "Too many recovery files specified." << std::endl;
174 return false;
175 }
176 }
177 break;
178
179 case scLimited:
180 {
181 // No recovery file will contain more recovery blocks than would
182 // be required to reconstruct the largest source file if it
183 // were missing. Other recovery files will have recovery blocks
184 // distributed in an exponential scheme.
185
186 u32 largest = (u32)((largestfilesize + blocksize-1) / blocksize);

Callers 7

test1Function · 0.85
test2Function · 0.85
test3Function · 0.85
test4Function · 0.85
test8_helperFunction · 0.85
ProcessMethod · 0.85

Calls

no outgoing calls

Tested by 5

test1Function · 0.68
test2Function · 0.68
test3Function · 0.68
test4Function · 0.68
test8_helperFunction · 0.68