blob: e0c4ebb0efb36230f0d247798f8ce0a382dab18f [file] [log] [blame]
package body FILO.Blockdev is
procedure Read
(Buffer : in out Buffer_Type;
Offset : in Blockdev_Offset;
Success : out Boolean)
is
use Interfaces.C;
Sector : constant unsigned_long := unsigned_long (Offset / 512);
Byte_Offset : constant unsigned_long := unsigned_long (Offset rem 512);
Byte_Len : constant unsigned_long := unsigned_long (Buffer'Length);
Buf : constant System.Address := Buffer'Address;
-- NOTE: C_devread returns 1 on success
function To_Success (Item : Interfaces.C.int) return Boolean is
(if Item = 1 then True else False);
begin
-- With 32-bit longs, the current C interface
-- can't access more than 512 * 2 ** 32:
if Offset / 512 > Blockdev_Length (unsigned_long'last) then
Success := False;
return;
end if;
Success := To_Success (C_devread (Sector, Byte_Offset, Byte_Len, Buf));
end Read;
end FILO.Blockdev;