5 ms·
Define hash(x) that takes an integer and returns a sector-sized hash. Define S = claimed total number of sectors. for(i=0; i<S; ++i) { write_sector(i, h
by 10000truths 2y ago
Define hash(x) that takes an integer and returns a sector-sized hash.
Define S = claimed total number of sectors.
for(i=0; i<S; ++i) {
write_sector(i, hash(i))
for(j=0; j<=i; ++j) {
if(hash(j) != read_sector(j)) {
return i
}
}
}
return S
The above pseudo code will return the number of sectors the flash drive actually has.
- sroussey 2y agoWrite everything before read or you will just get back cached results.
- 10000truths 2y agoCache can only mask performance. It can't mask fraudulent reporting of storage capacity. At worst, the test above will return (size of write cache + size of actual storage), but a bargain-bin flash drive is going to have a very small (if any) write cache, so it's not going to overestimate by much.
- geocar 2y agoWhy would they only have a small write cache? You can map a lot of memory from pcie
- bagels 2y agoSure, so if the drive is genuine, or even one sector short (I recognize it's more typically a much larger fraction for the fraudulent drives), you'd still have to write to nearly the full stated capacity to verify. This approach though, seems to require reading the first sector many times.
- nullc 2y agoaccidentally quadratic. you just want two non-nested loops.
- 10000truths 2y agoIt's not accidental. It's optimized to minimize the number of writes necessary to determine whether the reported storage capacity is genuine.
- nullc 2y agoIf it is genuine your quadratic version will perform the same number of writes as the linear time solution. If it is non-genuine what do you care how many writes it will perform? In that case the media is trash anyways. The quadratic test will take an eternity due to the n^2 hashing operations and reads unless it terminates extremely early. If you really have a need to terminate writing early, you could at least perform only a few reads randomly after each write (which will terminate early with high probably not long after you reached the maximum).