Thomas Heijligen | 5c43abc | 2023-12-11 15:24:36 +0000 | [diff] [blame] | 1 | package body FILO.Blockdev is |
Thomas Heijligen | d1e0457 | 2023-11-27 14:28:55 +0000 | [diff] [blame] | 2 | |
| 3 | procedure Read |
Thomas Heijligen | 62268ee | 2023-11-27 15:10:41 +0000 | [diff] [blame] | 4 | (Buffer : in out Buffer_Type; |
Nico Huber | 9c04187 | 2023-12-12 13:24:55 +0100 | [diff] [blame] | 5 | Offset : in Blockdev_Offset; |
Thomas Heijligen | 62268ee | 2023-11-27 15:10:41 +0000 | [diff] [blame] | 6 | Success : out Boolean) |
Thomas Heijligen | d1e0457 | 2023-11-27 14:28:55 +0000 | [diff] [blame] | 7 | is |
Thomas Heijligen | a968f6f | 2023-12-11 09:40:06 +0000 | [diff] [blame] | 8 | use Interfaces.C; |
| 9 | |
Nico Huber | a529660 | 2023-12-12 13:30:31 +0100 | [diff] [blame^] | 10 | Sector : constant unsigned_long := unsigned_long (Offset / 512); |
| 11 | Byte_Offset : constant unsigned_long := unsigned_long (Offset rem 512); |
Thomas Heijligen | a968f6f | 2023-12-11 09:40:06 +0000 | [diff] [blame] | 12 | Byte_Len : constant unsigned_long := unsigned_long (Buffer'Length); |
| 13 | Buf : constant System.Address := Buffer'Address; |
| 14 | |
| 15 | -- NOTE: C_devread returns 1 on success |
| 16 | function To_Success (Item : Interfaces.C.int) return Boolean is |
| 17 | (if Item = 1 then True else False); |
| 18 | |
Thomas Heijligen | d1e0457 | 2023-11-27 14:28:55 +0000 | [diff] [blame] | 19 | begin |
Nico Huber | a529660 | 2023-12-12 13:30:31 +0100 | [diff] [blame^] | 20 | -- With 32-bit longs, the current C interface |
| 21 | -- can't access more than 512 * 2 ** 32: |
| 22 | if Offset / 512 > Blockdev_Length (unsigned_long'last) then |
| 23 | Success := False; |
| 24 | return; |
| 25 | end if; |
Thomas Heijligen | a968f6f | 2023-12-11 09:40:06 +0000 | [diff] [blame] | 26 | Success := To_Success (C_devread (Sector, Byte_Offset, Byte_Len, Buf)); |
Thomas Heijligen | d1e0457 | 2023-11-27 14:28:55 +0000 | [diff] [blame] | 27 | end Read; |
| 28 | |
Thomas Heijligen | 5c43abc | 2023-12-11 15:24:36 +0000 | [diff] [blame] | 29 | end FILO.Blockdev; |