Please consider the following diagram of a RAID-5 array (Ignore the gray background): enter image description here

Now, given a logical address, how can one return the device number (0-3)?

For example, DeviceByLogicalSector(50) = 0, DeviceByLogicalSector(31)=2.

I've need to implement DeviceByLogicalSector method. I can use space if that's required.

Now, I've noticed the following:
Let's observe only the first $4$ rows; If we have a sector which is above the $P$-diagonal then the formula is: $\frac{(\text{logical_addr} \mod 12)}{4}$. And if the sector is below the diagonal then we need to add $1$.



1 Answer 1


Extracted from: HERE

// Assume all indexes are zero-based.
// Algorithm = Left-Asym

ChunkIndex = LogicalSector / SectorsPerChunk
StripeIndex = ChunkIndex / (DiskCount - 1)

ParityDisk = (DiskCount - 1) - ((StripeIndex / ParityDelay) % DiskCount)

DataDisk = (LogicalSector % (SectorsPerChunk * (DiskCount - 1))) / SectorsPerChunk
If ParityDisk <= DataDisk:
    DataDisk = DataDisk + 1

PhysicalSector = (LogicalSector / SectorsPerChunk) * (DiskCount - 1)
PhysicalSector = PhysicalSector * SectorsPerChunk
PhysicalSector = PhysicalSector + (LogicalSector % SectorsPerChunk)
  • 1
    $\begingroup$ Thanks but we're looking for explanatory answers, not lumps of code. $\endgroup$ Commented Apr 15, 2016 at 14:57
  • $\begingroup$ David - that lump of code breaks down the problem by solving key values (ChunkIndex, StripeIndex, ParityDisk, DataDisk and PhysicalSector) and then showing how they are used to solve the issue. Basically, I can't particlarly explain any further - it's just simple math with a splash of logic to tie it all together... Which is by definition what I've written in the first place as an explanation. $\endgroup$
    – Litch
    Commented Apr 16, 2016 at 19:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.