Nico Huber | 0a9591e | 2023-11-27 16:59:11 +0100 | [diff] [blame] | 1 | with Interfaces.C; |
| 2 | with Interfaces.C.Strings; |
| 3 | |
| 4 | use Interfaces.C; |
| 5 | |
Thomas Heijligen | 5c43abc | 2023-12-11 15:24:36 +0000 | [diff] [blame] | 6 | package body FILO.FS.VFS |
Thomas Heijligen | d49cb12 | 2023-11-29 10:03:02 +0000 | [diff] [blame] | 7 | with |
Nico Huber | 691220d | 2023-12-04 14:54:01 +0100 | [diff] [blame] | 8 | SPARK_Mode => Off |
Thomas Heijligen | d49cb12 | 2023-11-29 10:03:02 +0000 | [diff] [blame] | 9 | is |
Nico Huber | 0a9591e | 2023-11-27 16:59:11 +0100 | [diff] [blame] | 10 | |
Nico Huber | 51f6041 | 2023-12-04 14:48:11 +0100 | [diff] [blame] | 11 | State : T := Initial; |
| 12 | |
Nico Huber | 0a9591e | 2023-11-27 16:59:11 +0100 | [diff] [blame] | 13 | function C_Mount return int |
| 14 | is |
| 15 | Success : Boolean; |
| 16 | begin |
Nico Huber | 51f6041 | 2023-12-04 14:48:11 +0100 | [diff] [blame] | 17 | if not Is_Mounted (State) then |
| 18 | State := Initial; -- Work around not having an unmount in FILO. |
| 19 | end if; |
| 20 | Mount (State, Part_Len, Success); |
Nico Huber | 0a9591e | 2023-11-27 16:59:11 +0100 | [diff] [blame] | 21 | return (if Success then 1 else 0); |
| 22 | end C_Mount; |
| 23 | |
| 24 | function C_Open (File_Path : Strings.chars_ptr) return int |
| 25 | is |
Nico Huber | 51f6041 | 2023-12-04 14:48:11 +0100 | [diff] [blame] | 26 | File_Len : File_Length; |
Nico Huber | 0a9591e | 2023-11-27 16:59:11 +0100 | [diff] [blame] | 27 | Success : Boolean; |
| 28 | begin |
Nico Huber | 51f6041 | 2023-12-04 14:48:11 +0100 | [diff] [blame] | 29 | if Is_Mounted (State) and not Is_Open (State) then |
| 30 | Open (State, File_Len, Strings.Value (File_Path), Success); |
| 31 | Set_File_Max (File_Len); |
| 32 | else |
| 33 | Success := False; |
| 34 | end if; |
Nico Huber | 0a9591e | 2023-11-27 16:59:11 +0100 | [diff] [blame] | 35 | return (if Success then 1 else 0); |
| 36 | end C_Open; |
Nico Huber | 51f6041 | 2023-12-04 14:48:11 +0100 | [diff] [blame] | 37 | |
| 38 | procedure C_Close is |
| 39 | begin |
| 40 | if Is_Open (State) then |
| 41 | Close (State); |
| 42 | end if; |
| 43 | end C_Close; |
Nico Huber | 0a9591e | 2023-11-27 16:59:11 +0100 | [diff] [blame] | 44 | |
| 45 | function C_Read (Buf : System.Address; Len : int) return int |
| 46 | is |
| 47 | subtype Buffer_Range is Natural range 0 .. Integer (Len) - 1; |
| 48 | Buffer : Buffer_Type (Buffer_Range) |
| 49 | with |
| 50 | Convention => C, |
| 51 | Address => Buf; |
| 52 | |
Thomas Heijligen | 5c43abc | 2023-12-11 15:24:36 +0000 | [diff] [blame] | 53 | File_Pos : File_Offset := FILO.FS.File_Pos; |
Nico Huber | 0a9591e | 2023-11-27 16:59:11 +0100 | [diff] [blame] | 54 | Read_Len : Natural; |
| 55 | begin |
Nico Huber | 51f6041 | 2023-12-04 14:48:11 +0100 | [diff] [blame] | 56 | if Is_Open (State) then |
Nico Huber | 549a1b8 | 2023-12-17 01:51:59 +0100 | [diff] [blame^] | 57 | Read (State, File_Pos, Buffer, Read_Len); |
Nico Huber | 51f6041 | 2023-12-04 14:48:11 +0100 | [diff] [blame] | 58 | Set_File_Pos (File_Pos); |
| 59 | else |
| 60 | Read_Len := 0; |
| 61 | end if; |
Nico Huber | 0a9591e | 2023-11-27 16:59:11 +0100 | [diff] [blame] | 62 | return int (Read_Len); |
| 63 | end C_Read; |
| 64 | |
Thomas Heijligen | 5c43abc | 2023-12-11 15:24:36 +0000 | [diff] [blame] | 65 | end FILO.FS.VFS; |