Module:GetIDEMASectors: Difference between revisions
From Computing Classics Wiki
No edit summary |
m 8 revisions imported: All kinds of templates for CCW to emulate AEW's old hard drive stock |
||
| (5 intermediate revisions by the same user not shown) | |||
| Line 3: | Line 3: | ||
-- Returns the number of IDEMA sectors given a capacity in GB. | -- Returns the number of IDEMA sectors given a capacity in GB. | ||
function p.getIDEMASectors(gbCapacity, sectorSize) | function p.getIDEMASectors(gbCapacity, sectorSize) | ||
-- http://www.idema.org/wp-content/downloads/2169.pdf | -- If given one of the Advanced Format codes, convert it to a numerical sector size. | ||
if (sectorSize == "No" or sectorSize == "512n" or sectorSize == "512e") then | |||
sectorSize = 512 | |||
elseif (sectorSize == "4Kn" or sectorSize == "4,096") then | |||
sectorSize = 4096 | |||
else | |||
sectorSize = tonumber(sectorSize) | |||
end | |||
if (gbCapacity <= 8000) then | |||
-- http://www.idema.org/wp-content/downloads/2169.pdf | |||
gb50Less = gbCapacity - 50 | |||
if (sectorSize == 512) then | |||
return math.floor(97696368 + (1953504 * gb50Less)) | |||
elseif (sectorSize == 4096 or sectorSize == "4096" or sectorSize == "4,096") then | elseif (sectorSize == 4096) then | ||
return math.floor(12212046 + (244188 * gb50Less)) | |||
else | |||
error("getIDEMASectors: Sector size given was not 512 or 4096 (was " .. sectorSize .. ")") | |||
end | |||
else | |||
-- https://members.snia.org/document/dl/25903 | |||
gbCapacityInBytes = gbCapacity * 1000000000 | |||
if (sectorSize == 512 or sectorSize == "512") then | |||
return p.sffCeiling(gbCapacityInBytes / 512, 2^21) | |||
elseif (sectorSize == 4096 or sectorSize == "4096" or sectorSize == "4,096") then | |||
return p.sffCeiling(gbCapacityInBytes / 4096, 2^18) | |||
-- @todo: Add SCSI Protection Information and non-512 sector size compatibility | |||
else | |||
error("getIDEMASectors: Sector size given was not 512 or 4096 (was " .. sectorSize .. ")") | |||
end | |||
end | end | ||
end | |||
-- Implements the SFF's pseudocode ceiling function. | |||
-- https://stackoverflow.com/a/32106643 | |||
function p.sffCeiling(number, multiple) | |||
return (math.ceil(number / multiple) * multiple) | |||
end | |||
-- Implements the SFF's pseudocode floor function. | |||
function p.sffFloor(number, multiple) | |||
return (math.floor(number / multiple) * multiple) | |||
end | end | ||
Latest revision as of 06:15, 24 September 2024
Documentation for this module may be created at Module:GetIDEMASectors/doc
local p = {}
-- Returns the number of IDEMA sectors given a capacity in GB.
function p.getIDEMASectors(gbCapacity, sectorSize)
-- If given one of the Advanced Format codes, convert it to a numerical sector size.
if (sectorSize == "No" or sectorSize == "512n" or sectorSize == "512e") then
sectorSize = 512
elseif (sectorSize == "4Kn" or sectorSize == "4,096") then
sectorSize = 4096
else
sectorSize = tonumber(sectorSize)
end
if (gbCapacity <= 8000) then
-- http://www.idema.org/wp-content/downloads/2169.pdf
gb50Less = gbCapacity - 50
if (sectorSize == 512) then
return math.floor(97696368 + (1953504 * gb50Less))
elseif (sectorSize == 4096) then
return math.floor(12212046 + (244188 * gb50Less))
else
error("getIDEMASectors: Sector size given was not 512 or 4096 (was " .. sectorSize .. ")")
end
else
-- https://members.snia.org/document/dl/25903
gbCapacityInBytes = gbCapacity * 1000000000
if (sectorSize == 512 or sectorSize == "512") then
return p.sffCeiling(gbCapacityInBytes / 512, 2^21)
elseif (sectorSize == 4096 or sectorSize == "4096" or sectorSize == "4,096") then
return p.sffCeiling(gbCapacityInBytes / 4096, 2^18)
-- @todo: Add SCSI Protection Information and non-512 sector size compatibility
else
error("getIDEMASectors: Sector size given was not 512 or 4096 (was " .. sectorSize .. ")")
end
end
end
-- Implements the SFF's pseudocode ceiling function.
-- https://stackoverflow.com/a/32106643
function p.sffCeiling(number, multiple)
return (math.ceil(number / multiple) * multiple)
end
-- Implements the SFF's pseudocode floor function.
function p.sffFloor(number, multiple)
return (math.floor(number / multiple) * multiple)
end
-- Main entry point for this module.
function p.invokeMain(frame)
return p.getIDEMASectors(tonumber(frame.args[1]), frame.args[2])
end
return p