Nico Huber | cc960f2 | 2024-01-29 01:13:45 +0100 | [diff] [blame^] | 1 | package FILO.FS.ISO9660 is |
| 2 | |
| 3 | type T is private; |
| 4 | |
| 5 | function Is_Mounted (State : T) return Boolean; |
| 6 | function Is_Open (State : T) return Boolean |
| 7 | with |
| 8 | Post => (if Is_Open'Result then Is_Mounted (State)); |
| 9 | |
| 10 | procedure Mount |
| 11 | (State : in out T; |
| 12 | Part_Len : in Partition_Length; |
| 13 | Success : out Boolean) |
| 14 | with |
| 15 | Pre => not Is_Mounted (State), |
| 16 | Post => Success = Is_Mounted (State); |
| 17 | |
| 18 | procedure Open |
| 19 | (State : in out T; |
| 20 | File_Len : out File_Length; |
| 21 | File_Type : out FS.File_Type; |
| 22 | File_Name : in String; |
| 23 | In_Root : in Boolean; |
| 24 | Success : out Boolean) |
| 25 | with |
| 26 | Pre => Is_Mounted (State), |
| 27 | Post => (if Success then Is_Open (State) else Is_Mounted (State)); |
| 28 | |
| 29 | procedure Close (State : in out T) |
| 30 | with |
| 31 | Pre => Is_Open (State), |
| 32 | Post => Is_Mounted (State); |
| 33 | |
| 34 | procedure Read |
| 35 | (State : in out T; |
| 36 | File_Pos : in out File_Offset; |
| 37 | Buf : out Buffer_Type; |
| 38 | Len : out Natural) |
| 39 | with |
| 40 | Pre => Is_Open (State) and Buf'Length > 0, |
| 41 | Post => Is_Open (State); |
| 42 | |
| 43 | private |
| 44 | type State is (Unmounted, Mounted, File_Opened); |
| 45 | |
| 46 | FSBlock_Size : constant := 2048; |
| 47 | subtype FSBlock_Index is Index_Type range 0 .. FSBlock_Size - 1; |
| 48 | |
| 49 | type FSBlock_Count is range 0 .. 2 ** 32 - 1; |
| 50 | subtype FSBlock is FSBlock_Count range 0 .. FSBlock_Count'Last - 1; |
| 51 | type FSBlock_Logical is new FSBlock; |
| 52 | |
| 53 | subtype Directory_Record_Range is Index_Type range 0 .. 32; |
| 54 | subtype Directory_Record is Buffer_Type (Directory_Record_Range); |
| 55 | |
| 56 | -- We'll use the absolute position of the dir record |
| 57 | type Inode_Index is record |
| 58 | Block : FSBlock := 0; |
| 59 | Offset : FSBlock_Index := 0; |
| 60 | end record; |
| 61 | type Inode_Length is range 0 .. FSBlock_Count'Last * FSBlock_Size; |
| 62 | |
| 63 | type Mount_State is record |
| 64 | Part_Len : Partition_Length := 0; |
| 65 | Root_Inode : Inode_Index := (others => <>); |
| 66 | end record; |
| 67 | |
| 68 | type Extent is record |
| 69 | Start : FSBlock := 0; |
| 70 | Count : FSBlock_Count := 0; |
| 71 | end record; |
| 72 | |
| 73 | type Extent_Range is range 0 .. 0; -- Linux allows 100 "file sections" |
| 74 | type Extents is array (Extent_Range) of Extent; |
| 75 | |
| 76 | type Inode_Info is record |
| 77 | I : Inode_Index := (others => <>); |
| 78 | Mode : File_Type := File_Type'First; |
| 79 | Size : Inode_Length := 0; |
| 80 | Extents : ISO9660.Extents := (Extent_Range => (others => <>)); |
| 81 | end record; |
| 82 | |
| 83 | type T is record |
| 84 | Static : Mount_State := (others => <>); |
| 85 | S : State; |
| 86 | Inode : Inode_Info := (others => <>); |
| 87 | Cur_Dir : Inode_Index := (others => <>); |
| 88 | end record; |
| 89 | |
| 90 | end FILO.FS.ISO9660; |