blob: 3cdeca5cbdabc99244d0b92ba4ee7d66c748b337 [file] [log] [blame]
Nico Huber26f71832023-12-05 16:26:56 +01001-- Derived from GRUB -- GRand Unified Bootloader
2-- Copyright (C) 1999, 2001, 2003 Free Software Foundation, Inc.
3-- Copyright (C) 2023 secunet Security Networks AG
4--
5-- This program is free software; you can redistribute it and/or modify
6-- it under the terms of the GNU General Public License as published by
7-- the Free Software Foundation; either version 2 of the License, or
8-- (at your option) any later version.
9
Nico Huber33f6d952023-12-13 23:16:42 +010010with Ada.Unchecked_Conversion;
Nico Huber8ec45a12023-12-04 17:11:08 +010011with System;
Nico Huber1d7727f2023-11-30 15:58:46 +010012with Interfaces;
Nico Huber8ec45a12023-12-04 17:11:08 +010013with Interfaces.C;
Nico Huber1d7727f2023-11-30 15:58:46 +010014
Thomas Heijligen5c43abc2023-12-11 15:24:36 +000015with FILO.Blockdev;
16with FILO.FS.VFS;
Nico Huber8ec45a12023-12-04 17:11:08 +010017
18use Interfaces.C;
Nico Huber1d7727f2023-11-30 15:58:46 +010019
Thomas Heijligen5c43abc2023-12-11 15:24:36 +000020package body FILO.FS.Ext2 is
Nico Huber1d7727f2023-11-30 15:58:46 +010021
Nico Huber57d3a852023-12-04 15:42:40 +010022 function Is_Mounted (State : T) return Boolean is (State.S >= Mounted);
23 function Is_Open (State : T) return Boolean is (State.S = File_Opened);
24
Nico Huber26f71832023-12-05 16:26:56 +010025 --------------------------------------------------------------------------
26
27 SUPERBLOCK_SIZE : constant := 1024;
Nico Huber26f71832023-12-05 16:26:56 +010028 SUPERBLOCK_MAGIC : constant := 16#ef53#;
29 OLD_REV : constant := 0;
30 DYNAMIC_REV : constant := 1;
Nico Huber700a4112024-01-08 15:50:09 +010031
Nico Huber26f71832023-12-05 16:26:56 +010032 FEATURE_INCOMPAT_EXTENTS : constant := 16#0040#;
33 FEATURE_INCOMPAT_64BIT : constant := 16#0080#;
34
Nico Hubercdc03512023-12-13 23:32:54 +010035 EXT4_EXTENTS_FL : constant := 16#8_0000#;
36
Nico Huber57d3a852023-12-04 15:42:40 +010037 procedure Mount
38 (State : in out T;
39 Part_Len : in Partition_Length;
40 Success : out Boolean)
Nico Huber1d7727f2023-11-30 15:58:46 +010041 is
Nico Huber26f71832023-12-05 16:26:56 +010042 Super_Block : Buffer_Type (0 .. SUPERBLOCK_SIZE - 1) := (others => 0);
Nico Huber1d7727f2023-11-30 15:58:46 +010043 begin
Nico Huber26f71832023-12-05 16:26:56 +010044 if Part_Len < 2 * SUPERBLOCK_SIZE then
45 Success := False;
46 return;
47 end if;
48
Thomas Heijligen5c43abc2023-12-11 15:24:36 +000049 Blockdev.Read (Super_Block, 1 * SUPERBLOCK_SIZE, Success);
Nico Huber26f71832023-12-05 16:26:56 +010050 if not Success then
51 return;
52 end if;
53
54 if Read_LE16 (Super_Block, 14 * 4) /= 16#ef53# then
55 Success := False;
56 return;
57 end if;
58
59 State.Part_Len := Part_Len;
Nico Hubercd1d5f72023-12-13 16:01:43 +010060 State.First_Data_Block := FSBlock_Offset (Read_LE32 (Super_Block, 5 * 4));
Nico Huber26f71832023-12-05 16:26:56 +010061
62 declare
63 S_Log_Block_Size : constant Unsigned_32 := Read_LE32 (Super_Block, 6 * 4);
64 begin
65 if S_Log_Block_Size <= Unsigned_32 (Log_Block_Size'Last - 10) then
66 State.Block_Size_Bits := Log_Block_Size (S_Log_Block_Size + 10);
Nico Huber700a4112024-01-08 15:50:09 +010067 State.Block_Size := 2 ** Log_Block_Size (S_Log_Block_Size + 10);
Nico Huber26f71832023-12-05 16:26:56 +010068 else
69 Success := False;
70 return;
71 end if;
72 end;
73
74 declare
75 S_Inodes_Per_Group : constant Unsigned_32 := Read_LE32 (Super_Block, 10 * 4);
76 begin
Nico Huber21d42022023-12-16 02:50:22 +010077 if S_Inodes_Per_Group in 2 .. Unsigned_32'Last then
Nico Hubercdc03512023-12-13 23:32:54 +010078 State.Inodes_Per_Group := Inode_Index (S_Inodes_Per_Group);
Nico Huber26f71832023-12-05 16:26:56 +010079 else
80 Success := False;
81 return;
82 end if;
83 end;
84
85 declare
86 S_Rev_Level : constant Unsigned_32 := Read_LE32 (Super_Block, 19 * 4);
87 begin
88 if S_Rev_Level >= DYNAMIC_REV then
89 declare
90 S_Inode_Size : constant Unsigned_16 := Read_LE16 (Super_Block, 22 * 4);
91 begin
Nico Huber5a042fd2024-01-08 15:54:57 +010092 if Natural (S_Inode_Size) in Inode_Size then
Nico Huber26f71832023-12-05 16:26:56 +010093 State.Inode_Size := Inode_Size (S_Inode_Size);
94 else
95 Success := False;
96 return;
97 end if;
98 end;
99 else
100 State.Inode_Size := Inode_Size'First;
101 end if;
102 end;
103
104 declare
105 S_Feature_Incompat : constant Unsigned_32 := Read_LE32 (Super_Block, 24 * 4);
106 begin
107 State.Feature_Extents := (S_Feature_Incompat and FEATURE_INCOMPAT_EXTENTS) /= 0;
108 State.Feature_64Bit := (S_Feature_Incompat and FEATURE_INCOMPAT_64BIT) /= 0;
109 if State.Feature_64Bit then
110 declare
111 S_Desc_Size : constant Unsigned_16 := Read_LE16 (Super_Block, 63 * 4 + 2);
112 begin
Nico Huber700a4112024-01-08 15:50:09 +0100113 if Natural (S_Desc_Size) in Desc_Size and
114 Natural (S_Desc_Size) <= State.Block_Size and
115 Is_Power_Of_2 (S_Desc_Size)
Nico Huber26f71832023-12-05 16:26:56 +0100116 then
117 State.Desc_Size := Desc_Size (S_Desc_Size);
118 else
119 Success := False;
120 return;
121 end if;
122 end;
Nico Huber77a04d72023-12-13 23:11:40 +0100123 State.Feature_64Bit := State.Feature_64Bit and State.Desc_Size >= 64;
Nico Huber26f71832023-12-05 16:26:56 +0100124 else
125 State.Desc_Size := Desc_Size'First;
126 end if;
127 end;
128
129 State.S := Mounted;
Nico Huber1d7727f2023-11-30 15:58:46 +0100130 end Mount;
131
Nico Huberf5d99d02023-12-12 13:42:55 +0100132 procedure Read_FSBlock
Nico Huber700a4112024-01-08 15:50:09 +0100133 (Buf : in out Buffer_Type;
Nico Huberf5d99d02023-12-12 13:42:55 +0100134 FSBlock : in FSBlock_Offset;
Nico Huber700a4112024-01-08 15:50:09 +0100135 Part_Len : in Partition_Length;
Nico Huberf5d99d02023-12-12 13:42:55 +0100136 Success : out Boolean)
137 with
Nico Huber700a4112024-01-08 15:50:09 +0100138 Pre => Buf'Length in Block_Size
Nico Huberf5d99d02023-12-12 13:42:55 +0100139 is
Nico Huber700a4112024-01-08 15:50:09 +0100140 FSBlock_64 : constant Integer_64 := Integer_64 (FSBlock);
141 Block_Size : constant Integer_64 := Integer_64 (Buf'Length);
142 Max_Block_Offset : constant Integer_64 := Integer_64 (Part_Len) / Block_Size - 1;
Nico Huberf5d99d02023-12-12 13:42:55 +0100143 begin
Nico Huber700a4112024-01-08 15:50:09 +0100144 if FSBlock_64 > Max_Block_Offset then
Nico Huberf5d99d02023-12-12 13:42:55 +0100145 Success := False;
146 return;
147 end if;
Nico Huber700a4112024-01-08 15:50:09 +0100148 Blockdev.Read (Buf, Blockdev_Length (FSBlock_64 * Block_Size), Success);
Nico Huberf5d99d02023-12-12 13:42:55 +0100149 end Read_FSBlock;
150
Nico Huber68c86932023-12-13 11:03:11 +0100151 procedure Cache_FSBlock
152 (State : in out T;
153 Phys : in FSBlock_Offset;
154 Level : in Block_Cache_Index;
Nico Huber57dfbfb2023-12-13 23:24:16 +0100155 Label : in Cache_Label;
156 Logical : in Boolean := True;
Nico Huber68c86932023-12-13 11:03:11 +0100157 Cache_Start : out Max_Block_Index;
158 Cache_End : out Max_Block_Index;
159 Success : out Boolean)
160 with
Nico Huber700a4112024-01-08 15:50:09 +0100161 Post => Cache_End = Cache_Start + State.Block_Size - 1
Nico Huber68c86932023-12-13 11:03:11 +0100162 is
Nico Huber68c86932023-12-13 11:03:11 +0100163 -- Limit cache usage depending on block size:
Nico Huber700a4112024-01-08 15:50:09 +0100164 Max_Level : constant Block_Cache_Index := Block_Size'Last / State.Block_Size - 1;
165 Cache_Level : constant Block_Cache_Index := Block_Cache_Index'Min (Level, Max_Level);
Nico Huber68c86932023-12-13 11:03:11 +0100166 begin
Nico Huber700a4112024-01-08 15:50:09 +0100167 Cache_Start := Cache_Level * State.Block_Size;
168 Cache_End := Cache_Start + State.Block_Size - 1;
Nico Huber57dfbfb2023-12-13 23:24:16 +0100169 if State.Block_Cache_Logical (Cache_Level) = Logical and
170 State.Block_Cache_Label (Cache_Level) = Label
171 then
Nico Huber68c86932023-12-13 11:03:11 +0100172 Success := True;
173 else
174 Read_FSBlock
Nico Huber700a4112024-01-08 15:50:09 +0100175 (Buf => State.Block_Cache (Cache_Start .. Cache_End),
Nico Huber68c86932023-12-13 11:03:11 +0100176 FSBlock => Phys,
Nico Huber700a4112024-01-08 15:50:09 +0100177 Part_Len => State.Part_Len,
Nico Huber68c86932023-12-13 11:03:11 +0100178 Success => Success);
Nico Huber57dfbfb2023-12-13 23:24:16 +0100179 State.Block_Cache_Logical (Cache_Level) := Logical;
180 State.Block_Cache_Label (Cache_Level) := Label;
Nico Huber68c86932023-12-13 11:03:11 +0100181 end if;
182 end Cache_FSBlock;
183
Nico Huber57dfbfb2023-12-13 23:24:16 +0100184 procedure Cache_FSBlock
185 (State : in out T;
186 Phys : in FSBlock_Offset;
187 Level : in Block_Cache_Index;
188 Cache_Start : out Max_Block_Index;
189 Cache_End : out Max_Block_Index;
190 Success : out Boolean)
191 with
Nico Huber700a4112024-01-08 15:50:09 +0100192 Post => Cache_End = Cache_Start + State.Block_Size - 1
Nico Huber57dfbfb2023-12-13 23:24:16 +0100193 is
194 begin
195 Cache_FSBlock (State, Phys, Level, Cache_Label (Phys),
196 False, Cache_Start, Cache_End, Success);
197 end Cache_FSBlock;
198
199 procedure Reset_Cache_Logical (State : in out T) is
200 begin
201 for I in Block_Cache_Index loop
202 if State.Block_Cache_Logical (I) then
203 State.Block_Cache_Logical (I) := False;
204 State.Block_Cache_Label (I) := 0;
205 end if;
206 end loop;
207 end Reset_Cache_Logical;
208
Nico Huber6623c982023-12-12 16:35:46 +0100209 procedure Ext2_Block_Map
210 (State : in out T;
211 Logical : in FSBlock_Logical;
212 Physical : out FSBlock_Offset;
213 Success : out Boolean)
214 is
Nico Huber33f6d952023-12-13 23:16:42 +0100215 Direct_Blocks : constant := 12;
216 type Direct_Blocks_Array is array (Natural range 0 .. Direct_Blocks - 1) of Unsigned_32;
217 type Inode_Blocks is record
218 Direct_Blocks : Direct_Blocks_Array;
219 Indirect_Block : Unsigned_32;
220 Double_Indirect : Unsigned_32;
221 Triple_Indirect : Unsigned_32;
222 end record
Nico Huber5a042fd2024-01-08 15:54:57 +0100223 with Object_Size => Inode_Extents'Length * 8;
Nico Huber33f6d952023-12-13 23:16:42 +0100224
225 function I_Blocks is new Ada.Unchecked_Conversion (Inode_Extents, Inode_Blocks);
Nico Huber7403a542023-12-15 23:13:47 +0100226 function I_Blocks (State : T) return Inode_Blocks is (I_Blocks (State.Inode.Inline));
Nico Huber33f6d952023-12-13 23:16:42 +0100227
Nico Huber700a4112024-01-08 15:50:09 +0100228 Addr_Per_Block : constant FSBlock_Logical := FSBlock_Logical (State.Block_Size / 4);
229 Max_Addr_Per_Block : constant FSBlock_Logical := FSBlock_Logical (Block_Size'Last / 4);
Nico Huber6623c982023-12-12 16:35:46 +0100230 type Addr_In_Block_Range is range 0 .. Max_Addr_Per_Block - 1;
231
232 procedure Indirect_Block_Lookup
233 (Indirect_Block_Phys : in FSBlock_Offset;
234 Addr_In_Block : in Addr_In_Block_Range;
235 Level : in Block_Cache_Index;
236 Logical_Off : in FSBlock_Logical;
237 Next_Physical : out FSBlock_Offset;
238 Success : out Boolean)
239 with
Nico Huber5a042fd2024-01-08 15:54:57 +0100240 Pre =>
241 Addr_Per_Block = FSBlock_Logical (State.Block_Size / 4) and
242 FSBlock_Logical (Addr_In_Block) < Addr_Per_Block
Nico Huber6623c982023-12-12 16:35:46 +0100243 is
Nico Huber68c86932023-12-13 11:03:11 +0100244 Cache_Start, Cache_End : Max_Block_Index;
Nico Huber6623c982023-12-12 16:35:46 +0100245 begin
Nico Huber68c86932023-12-13 11:03:11 +0100246 Cache_FSBlock
247 (State => State,
248 Phys => Indirect_Block_Phys,
249 Level => Level,
Nico Huber57dfbfb2023-12-13 23:24:16 +0100250 Label => Cache_Label (Logical_Off),
Nico Huber68c86932023-12-13 11:03:11 +0100251 Cache_Start => Cache_Start,
252 Cache_End => Cache_End,
253 Success => Success);
Nico Huber6623c982023-12-12 16:35:46 +0100254 Next_Physical := FSBlock_Offset (Read_LE32
Nico Huberfe897122023-12-12 21:33:36 +0100255 (Buf => State.Block_Cache (Cache_Start .. Cache_End),
Nico Huber6623c982023-12-12 16:35:46 +0100256 Off => Natural (Addr_In_Block) * 4));
Nico Huber6623c982023-12-12 16:35:46 +0100257 end Indirect_Block_Lookup;
258
259 Logical_Rest : FSBlock_Logical := Logical;
Nico Huber5a042fd2024-01-08 15:54:57 +0100260
261 pragma Assert (Addr_Per_Block <= 2 ** 14);
Nico Huber6623c982023-12-12 16:35:46 +0100262 begin
263 if Logical_Rest < Direct_Blocks then
Nico Huber33f6d952023-12-13 23:16:42 +0100264 Physical := FSBlock_Offset (I_Blocks (State).Direct_Blocks (Natural (Logical)));
Nico Huber6623c982023-12-12 16:35:46 +0100265 Success := True;
266 return;
267 end if;
268
269 Logical_Rest := Logical_Rest - Direct_Blocks;
270 if Logical_Rest < Addr_Per_Block then
271 Indirect_Block_Lookup
Nico Huber33f6d952023-12-13 23:16:42 +0100272 (Indirect_Block_Phys => FSBlock_Offset (I_Blocks (State).Indirect_Block),
Nico Huber6623c982023-12-12 16:35:46 +0100273 Addr_In_Block => Addr_In_Block_Range (Logical_Rest),
Nico Huberfe897122023-12-12 21:33:36 +0100274 Level => 0,
Nico Huber6623c982023-12-12 16:35:46 +0100275 Logical_Off => Logical - Logical_Rest,
276 Next_Physical => Physical,
277 Success => Success);
278 return;
279 end if;
280
281 Logical_Rest := Logical_Rest - Addr_Per_Block;
282 if Logical_Rest < Addr_Per_Block ** 2 then
283 Indirect_Block_Lookup
Nico Huber33f6d952023-12-13 23:16:42 +0100284 (Indirect_Block_Phys => FSBlock_Offset (I_Blocks (State).Double_Indirect),
Nico Huber5a042fd2024-01-08 15:54:57 +0100285 Addr_In_Block => Addr_In_Block_Range ((Logical_Rest / Addr_Per_Block) mod Addr_Per_Block),
Nico Huberfe897122023-12-12 21:33:36 +0100286 Level => 1,
Nico Huber6623c982023-12-12 16:35:46 +0100287 Logical_Off => Logical - Logical_Rest,
288 Next_Physical => Physical,
289 Success => Success);
290 if not Success then
291 return;
292 end if;
293
294 Indirect_Block_Lookup
295 (Indirect_Block_Phys => Physical,
296 Addr_In_Block => Addr_In_Block_Range (Logical_Rest mod Addr_Per_Block),
Nico Huberfe897122023-12-12 21:33:36 +0100297 Level => 0,
Nico Huber6623c982023-12-12 16:35:46 +0100298 Logical_Off => Logical - (Logical_Rest mod Addr_Per_Block),
299 Next_Physical => Physical,
300 Success => Success);
301 return;
302 end if;
303
304 Logical_Rest := Logical_Rest - Addr_Per_Block ** 2;
305 if Logical_Rest < Addr_Per_Block ** 3 then
306 Indirect_Block_Lookup
Nico Huber33f6d952023-12-13 23:16:42 +0100307 (Indirect_Block_Phys => FSBlock_Offset (I_Blocks (State).Triple_Indirect),
Nico Huber5a042fd2024-01-08 15:54:57 +0100308 Addr_In_Block => Addr_In_Block_Range ((Logical_Rest / Addr_Per_Block ** 2) mod Addr_Per_Block),
Nico Huberfe897122023-12-12 21:33:36 +0100309 Level => 2,
Nico Huber6623c982023-12-12 16:35:46 +0100310 Logical_Off => Logical - Logical_Rest,
311 Next_Physical => Physical,
312 Success => Success);
313 if not Success then
314 return;
315 end if;
316
317 Indirect_Block_Lookup
318 (Indirect_Block_Phys => Physical,
Nico Huber5a042fd2024-01-08 15:54:57 +0100319 Addr_In_Block => Addr_In_Block_Range ((Logical_Rest / Addr_Per_Block) mod Addr_Per_Block),
Nico Huberfe897122023-12-12 21:33:36 +0100320 Level => 1,
Nico Huber6623c982023-12-12 16:35:46 +0100321 Logical_Off => Logical - (Logical_Rest mod Addr_Per_Block ** 2),
322 Next_Physical => Physical,
323 Success => Success);
324 if not Success then
325 return;
326 end if;
327
328 Indirect_Block_Lookup
329 (Indirect_Block_Phys => Physical,
330 Addr_In_Block => Addr_In_Block_Range (Logical_Rest mod Addr_Per_Block),
Nico Huberfe897122023-12-12 21:33:36 +0100331 Level => 0,
Nico Huber6623c982023-12-12 16:35:46 +0100332 Logical_Off => Logical - (Logical_Rest mod Addr_Per_Block),
333 Next_Physical => Physical,
334 Success => Success);
335 return;
336 end if;
337
338 -- Logical address was just too high.
Nico Huber5a042fd2024-01-08 15:54:57 +0100339 Physical := 0;
Nico Huber6623c982023-12-12 16:35:46 +0100340 Success := False;
341 end Ext2_Block_Map;
342
Nico Huberfffc8c12023-12-13 12:44:12 +0100343 procedure Extent_Block_Map
344 (State : in out T;
345 Logical : in FSBlock_Logical;
346 Physical : out FSBlock_Offset;
347 Success : out Boolean)
348 is
349 -- Extent blocks always start with a 12B header and contain 12B entries.
350 -- Every entry starts with the number of the first logical block it
351 -- covers. Entries are sorted by this number.
352 -- Depth > 0 blocks have index entries, referencing further extent blocks.
353 -- Depth = 0 blocks have extent entries, referencing a contiguous range
354 -- of data blocks.
355 --
356 -- +-----------------+
357 -- .-> | Hdr depth=0 |
358 -- | +-----------------+
359 -- | | Extent 0.. 12 |
360 -- +-------------+ | +-----------------+
361 -- | Hdr depth=1 | | | Extent 13.. 13 |
362 -- +-------------+ | +-----------------+
363 -- | Index 0 | --' | Extent 14..122 |
364 -- +-------------+ +-----------------+
365 -- | Index 123 | --.
366 -- +-------------+ | +-----------------+
367 -- `-> | Hdr depth=0 |
368 -- +-----------------+
369 -- | Extent 123..125 |
370 -- +-----------------+
371 -- | Extent 126..234 |
372 -- +-----------------+
373 --
374
375 Extent_Header_Size : constant := 12;
376 Extent_Header_Magic : constant := 16#f03a#;
377 subtype Extent_Off is Natural range 0 .. Extent_Header_Size;
378 subtype Extent_Idx is Natural range 1 .. (Max_Block_Index'Last + 1) / Extent_Header_Size - 1;
Nico Huber700a4112024-01-08 15:50:09 +0100379 Dynamic_Max_Index : constant Extent_Idx := State.Block_Size / Extent_Header_Size - 1;
Nico Huberfffc8c12023-12-13 12:44:12 +0100380
381 function Extent_Byte_Offset (Idx : Extent_Idx; Off : Extent_Off) return Natural
382 is
383 (Idx * Extent_Header_Size + Off);
384
385 function Header_Magic (Buf : Buffer_Type) return Unsigned_16
386 is
387 (Read_LE16 (Buf, 0))
388 with
389 Pre => Buf'Length >= 2;
390
391 function Header_Entries (Buf : Buffer_Type) return Natural
392 is
393 (Natural (Read_LE16 (Buf, 2)))
394 with
395 Pre => Buf'Length >= 4;
396
397 function Header_Depth (Buf : Buffer_Type) return Natural
398 is
399 (Natural (Read_LE16 (Buf, 6)))
400 with
401 Pre => Buf'Length >= 8;
402
403 function Index_Logical (Buf : Buffer_Type; Idx : Extent_Idx) return FSBlock_Logical
404 is
405 (FSBlock_Logical (Read_LE32 (Buf, Extent_Byte_Offset (Idx, 0))))
406 with
407 Pre => Buf'Length >= Extent_Byte_Offset (Idx, 4);
408
409 function Index_Physical (Buf : Buffer_Type; Idx : Extent_Idx) return FSBlock_Offset
410 is
411 (FSBlock_Offset
412 (Shift_Left (Unsigned_64 (Read_LE16 (Buf, Extent_Byte_Offset (Idx, 8))), 32) or
413 Unsigned_64 (Read_LE32 (Buf, Extent_Byte_Offset (Idx, 4)))))
414 with
415 Pre => Buf'Length >= Extent_Byte_Offset (Idx, 10);
416
417 function Extent_Logical (Buf : Buffer_Type; Idx : Extent_Idx) return FSBlock_Logical
418 renames Index_Logical;
419
420 function Extent_Length (Buf : Buffer_Type; Idx : Extent_Idx) return FSBlock_Logical
421 is
422 (FSBlock_Logical (Read_LE16 (Buf, Extent_Byte_Offset (Idx, 4))))
423 with
424 Pre => Buf'Length >= Extent_Byte_Offset (Idx, 6);
425
426 function Extent_Physical (Buf : Buffer_Type; Idx : Extent_Idx) return FSBlock_Offset
427 is
428 (FSBlock_Offset
429 (Shift_Left (Unsigned_64 (Read_LE16 (Buf, Extent_Byte_Offset (Idx, 6))), 32) or
430 Unsigned_64 (Read_LE32 (Buf, Extent_Byte_Offset (Idx, 8)))))
431 with
432 Pre => Buf'Length >= Extent_Byte_Offset (Idx, 12);
433
434 function Bin_Search (Buf : Buffer_Type; Refs : Extent_Idx) return Extent_Idx
435 with
Nico Huber6710c0e2024-01-08 15:56:24 +0100436 Pre =>
437 Buf'Length in 2 * Extent_Header_Size .. Max_Block_Index'Last and then
438 Refs in 1 .. Extent_Idx (Buf'Length / Extent_Header_Size - 1) and then
439 Extent_Logical (Buf, 1) <= Logical,
440 Post =>
441 Bin_Search'Result in 1 .. Refs and
442 Extent_Logical (Buf, Bin_Search'Result) <= Logical
Nico Huberfffc8c12023-12-13 12:44:12 +0100443 is
Nico Huber6710c0e2024-01-08 15:56:24 +0100444 Left : Positive := 2;
Nico Huberfffc8c12023-12-13 12:44:12 +0100445 Right : Extent_Idx := Refs;
446 begin
447 while Left <= Right loop
448 declare
449 Mid : constant Extent_Idx := (Left + Right) / 2;
450 Ext_Logical : constant FSBlock_Logical := Extent_Logical (Buf, Mid);
451 begin
452 if Logical < Ext_Logical then
453 Right := Mid - 1;
454 else
455 Left := Mid + 1;
456 end if;
Nico Huber6710c0e2024-01-08 15:56:24 +0100457 pragma Loop_Invariant
458 (Right <= Refs and then
459 Left in 2 .. Refs + 1 and then
460 Extent_Logical (Buf, Left - 1) <= Logical);
Nico Huberfffc8c12023-12-13 12:44:12 +0100461 end;
462 end loop;
463 return Left - 1;
464 end Bin_Search;
465
466 procedure Next_Ref
467 (Current : in FSBlock_Offset;
468 Logical_Off : in FSBlock_Logical;
469 Depth : in Natural;
470 Next : out Extent_Idx;
471 Cache_Start : out Max_Block_Index;
472 Cache_End : out Max_Block_Index;
473 Success : out Boolean)
474 with
475 Pre => Logical_Off <= Logical,
476 Post => (if Success then
Nico Huber700a4112024-01-08 15:50:09 +0100477 Cache_End = Cache_Start + State.Block_Size - 1 and then
Nico Huberfffc8c12023-12-13 12:44:12 +0100478 Extent_Logical (State.Block_Cache (Cache_Start .. Cache_End), Next) <= Logical)
479 is
Nico Huberfffc8c12023-12-13 12:44:12 +0100480 begin
481 Cache_FSBlock
482 (State => State,
483 Phys => Current,
484 Level => Depth,
Nico Huber57dfbfb2023-12-13 23:24:16 +0100485 Label => Cache_Label (Logical_Off),
Nico Huberfffc8c12023-12-13 12:44:12 +0100486 Cache_Start => Cache_Start,
487 Cache_End => Cache_End,
488 Success => Success);
489 if not Success then
490 Next := 1;
491 return;
492 end if;
493
494 declare
495 Hdr_Magic : constant Unsigned_16 :=
496 Header_Magic (State.Block_Cache (Cache_Start .. Cache_End));
497 Hdr_Entries : constant Natural :=
498 Header_Entries (State.Block_Cache (Cache_Start .. Cache_End));
499 Hdr_Depth : constant Natural :=
500 Header_Depth (State.Block_Cache (Cache_Start .. Cache_End));
501 First_Logical : constant FSBlock_Logical :=
502 Extent_Logical (State.Block_Cache (Cache_Start .. Cache_End), 1);
503 begin
504 Success := Success and then
505 Hdr_Magic = Extent_Header_Magic and then
506 Hdr_Depth = Depth and then
507 Hdr_Entries <= Dynamic_Max_Index and then
508 First_Logical = Logical_Off;
509 if not Success then
510 Next := 1;
511 else
512 Next := Bin_Search (State.Block_Cache (Cache_Start .. Cache_End), Hdr_Entries);
513 end if;
514 end;
515 end Next_Ref;
516
Nico Huber7403a542023-12-15 23:13:47 +0100517 Inline_Extents : Ext2.Inode_Extents renames State.Inode.Inline;
518 Inode_Magic : constant Unsigned_16 := Header_Magic (Inline_Extents);
519 Inode_Entries : constant Natural := Header_Entries (Inline_Extents);
520 First_Logical : constant FSBlock_Logical := Extent_Logical (Inline_Extents, 1);
521 Depth : Natural := Header_Depth (Inline_Extents);
Nico Huberfffc8c12023-12-13 12:44:12 +0100522
523 Cache_Start, Cache_End : Max_Block_Index;
524 Logical_Off, Length : FSBlock_Logical;
525 Idx : Extent_Idx;
526 begin
527 Success :=
528 Inode_Magic = Extent_Header_Magic and then
529 Inode_Entries > 0 and then
Nico Huber7403a542023-12-15 23:13:47 +0100530 Inode_Entries < Inline_Extents'Length / Extent_Header_Size and then
Nico Huberfffc8c12023-12-13 12:44:12 +0100531 First_Logical <= Logical;
532 if not Success then
533 Physical := 0;
534 return;
535 end if;
536
Nico Huber7403a542023-12-15 23:13:47 +0100537 Idx := Bin_Search (Inline_Extents, Inode_Entries);
Nico Huberfffc8c12023-12-13 12:44:12 +0100538 if Depth = 0 then
Nico Huber7403a542023-12-15 23:13:47 +0100539 Physical := Extent_Physical (Inline_Extents, Idx);
540 Logical_Off := Extent_Logical (Inline_Extents, Idx);
541 Length := Extent_Length (Inline_Extents, Idx);
Nico Huberfffc8c12023-12-13 12:44:12 +0100542 else
Nico Huber7403a542023-12-15 23:13:47 +0100543 Physical := Index_Physical (Inline_Extents, Idx);
544 Logical_Off := Index_Logical (Inline_Extents, Idx);
Nico Huberfffc8c12023-12-13 12:44:12 +0100545 loop
546 Depth := Depth - 1;
547 Next_Ref
548 (Current => Physical,
549 Logical_Off => Logical_Off,
550 Depth => Depth,
551 Next => Idx,
552 Cache_Start => Cache_Start,
553 Cache_End => Cache_End,
554 Success => Success);
555 if not Success then
556 return;
557 end if;
558
559 exit when Depth = 0;
560 Physical := Index_Physical (State.Block_Cache (Cache_Start .. Cache_End), Idx);
561 Logical_Off := Index_Logical (State.Block_Cache (Cache_Start .. Cache_End), Idx);
562 end loop;
563
564 Physical := Extent_Physical (State.Block_Cache (Cache_Start .. Cache_End), Idx);
565 Logical_Off := Extent_Logical (State.Block_Cache (Cache_Start .. Cache_End), Idx);
566 Length := Extent_Length (State.Block_Cache (Cache_Start .. Cache_End), Idx);
567 end if;
568
569 Success :=
570 Length > 0 and then
Nico Huberc4c7a5e2023-12-14 00:08:56 +0100571 Logical_Off <= FSBlock_Logical'Last - Length and then
Nico Huberfffc8c12023-12-13 12:44:12 +0100572 Logical < Logical_Off + Length;
573 if Success then
574 Physical := Physical + FSBlock_Offset (Logical - Logical_Off);
575 end if;
576 end Extent_Block_Map;
577
Nico Huber57d3a852023-12-04 15:42:40 +0100578 procedure Open
Nico Hubercdc03512023-12-13 23:32:54 +0100579 (State : in out T;
580 Inode : in Inode_Index;
581 Success : out Boolean)
582 with
583 Pre => Is_Mounted (State) and not Is_Open (State),
584 Post => Success = Is_Open (State)
585 is
586 type Group_Index is new Natural;
587 subtype Desc_In_Block_Index is Group_Index
588 range 0 .. Group_Index (2 ** Log_Block_Size'Last / Desc_Size'First - 1);
589
Nico Huber700a4112024-01-08 15:50:09 +0100590 Inodes_Per_Block : constant Inode_Index := Inode_Index (State.Block_Size / State.Inode_Size);
591 Desc_Per_Block : constant Group_Index := Group_Index (State.Block_Size / State.Desc_Size);
Nico Hubercdc03512023-12-13 23:32:54 +0100592
Nico Huber022e2262023-12-15 23:15:17 +0100593 ------------------------
594 -- Group deserialization
595
Nico Hubercdc03512023-12-13 23:32:54 +0100596 subtype Group_Off is Natural range 0 .. Desc_Size'Last;
597 function Group_Byte_Offset (Idx : Group_Index; Off : Group_Off) return Natural
598 is
599 (Natural (Idx) * State.Desc_Size + Off);
600
601 function Group_Inode_Table (Buf : Buffer_Type; Idx : Group_Index) return FSBlock_Offset
602 is
603 (FSBlock_Offset (
604 (if State.Feature_64Bit
605 then Shift_Left (Unsigned_64 (Read_LE32 (Buf, Group_Byte_Offset (Idx, 40))), 32)
606 else 0)
607 or
608 Unsigned_64 (Read_LE32 (Buf, Group_Byte_Offset (Idx, 8)))))
609 with
610 Pre => Buf'Length >= Group_Byte_Offset (Idx, 44);
611
Nico Huber022e2262023-12-15 23:15:17 +0100612 ------------------------
613 -- Inode deserialization
614
Nico Hubercdc03512023-12-13 23:32:54 +0100615 subtype Inode_Off is Natural range 0 .. Inode_Size'Last;
616 function Inode_Byte_Offset (Idx : Inode_Index; Off : Inode_Off) return Natural
617 is
618 (Natural (Idx) * State.Inode_Size + Off);
619
Nico Huber022e2262023-12-15 23:15:17 +0100620 function Inode_Mode (Buf : Buffer_Type; Idx : Inode_Index) return Unsigned_16
621 is
622 (Read_LE16 (Buf, Inode_Byte_Offset (Idx, 0)))
623 with
624 Pre => Buf'Length >= Inode_Byte_Offset (Idx, 2);
625
626 function Inode_Size (Buf : Buffer_Type; Idx : Inode_Index; Mode : Inode_Type) return Unsigned_64
627 is
628 ((if Mode = Regular
629 then Shift_Left (Unsigned_64 (Read_LE32 (Buf, Inode_Byte_Offset (Idx, 108))), 32)
630 else 0) or
631 Unsigned_64 (Read_LE32 (Buf, Inode_Byte_Offset (Idx, 4))))
632 with
633 Pre => Buf'Length >= Inode_Byte_Offset (Idx, 112);
634
635 function Inode_Blocks (Buf : Buffer_Type; Idx : Inode_Index) return Unsigned_32
636 is
637 (Read_LE32 (Buf, Inode_Byte_Offset (Idx, 28)))
638 with
639 Pre => Buf'Length >= Inode_Byte_Offset (Idx, 32);
640
Nico Hubercdc03512023-12-13 23:32:54 +0100641 function Inode_Flags (Buf : Buffer_Type; Idx : Inode_Index) return Unsigned_32
642 is
643 (Read_LE32 (Buf, Inode_Byte_Offset (Idx, 32)))
644 with
645 Pre => Buf'Length >= Inode_Byte_Offset (Idx, 36);
646
Nico Huber022e2262023-12-15 23:15:17 +0100647 function Inode_File_ACL (Buf : Buffer_Type; Idx : Inode_Index) return Unsigned_32
648 is
649 (Read_LE32 (Buf, Inode_Byte_Offset (Idx, 104)))
650 with
651 Pre => Buf'Length >= Inode_Byte_Offset (Idx, 108);
652
Nico Hubercdc03512023-12-13 23:32:54 +0100653 Group : constant Group_Index := Group_Index ((Inode - 1) / State.Inodes_Per_Group);
654 Desc_Block : constant FSBlock_Offset :=
655 1 + State.First_Data_Block + FSBlock_Offset (Group / Desc_Per_Block);
656 Cache_Start, Cache_End : Max_Block_Index;
657 begin
658 Cache_FSBlock
659 (State => State,
660 Phys => Desc_Block,
661 Level => Natural'Min (Natural (Group / Desc_Per_Block), Block_Cache_Index'Last),
662 Cache_Start => Cache_Start,
663 Cache_End => Cache_End,
664 Success => Success);
665 if not Success then
666 return;
667 end if;
668
669 declare
670 Desc : constant Desc_In_Block_Index := Group mod Desc_Per_Block;
671 Inode_In_Group : constant Inode_Index := (Inode - 1) mod State.Inodes_Per_Group;
672 Inode_Block : constant FSBlock_Offset :=
673 Group_Inode_Table (State.Block_Cache (Cache_Start .. Cache_End), Group) +
674 FSBlock_Offset (Inode_In_Group / Inodes_Per_Block);
675 begin
676 Cache_FSBlock
677 (State => State,
678 Phys => Inode_Block,
679 Level => Block_Cache_Index'Last,
680 Cache_Start => Cache_Start,
681 Cache_End => Cache_End,
682 Success => Success);
683 if not Success then
684 return;
685 end if;
686
687 declare
Nico Huber022e2262023-12-15 23:15:17 +0100688 S_IFMT : constant := 8#170000#;
689 S_IFDIR : constant := 8#040000#;
690 S_IFREG : constant := 8#100000#;
691 S_IFLNK : constant := 8#120000#;
692
Nico Hubercdc03512023-12-13 23:32:54 +0100693 Inode_In_Block : constant Inode_Index := Inode_In_Group mod Inodes_Per_Block;
Nico Huber022e2262023-12-15 23:15:17 +0100694 I_Mode : constant Unsigned_16 :=
695 Inode_Mode (State.Block_Cache (Cache_Start .. Cache_End), Inode_In_Block);
Nico Hubercdc03512023-12-13 23:32:54 +0100696 I_Flags : constant Unsigned_32 :=
697 Inode_Flags (State.Block_Cache (Cache_Start .. Cache_End), Inode_In_Block);
698 begin
Nico Huber022e2262023-12-15 23:15:17 +0100699 case I_Mode and S_IFMT is
700 when S_IFDIR => State.Inode.Mode := Dir;
701 when S_IFREG => State.Inode.Mode := Regular;
702 when S_IFLNK => State.Inode.Mode := Link;
703 when others => Success := False; return;
704 end case;
705 if State.Inode.Mode = Link then
706 declare
707 I_File_ACL : constant Unsigned_32 := Inode_File_ACL (
708 State.Block_Cache (Cache_Start .. Cache_End), Inode_In_Block);
709 I_Blocks : constant Unsigned_32 := Inode_Blocks (
710 State.Block_Cache (Cache_Start .. Cache_End), Inode_In_Block);
711 begin
712 if (I_File_ACL = 0 and I_Blocks = 0) or
713 (I_File_ACL /= 0 and I_Blocks = 2 ** (State.Block_Size_Bits - 9))
714 then
715 State.Inode.Mode := Fast_Link;
716 end if;
717 end;
718 end if;
719 declare
720 I_Size : constant Unsigned_64 := Inode_Size (
721 State.Block_Cache (Cache_Start .. Cache_End), Inode_In_Block, State.Inode.Mode);
722 begin
723 if I_Size <= Unsigned_64 (Inode_Length'Last) then
724 State.Inode.Size := Inode_Length (I_Size);
725 else
726 Success := False;
727 end if;
728 end;
Nico Hubercdc03512023-12-13 23:32:54 +0100729 State.Inode.Use_Extents := State.Feature_Extents and (I_Flags and EXT4_EXTENTS_FL) /= 0;
Nico Huber7403a542023-12-15 23:13:47 +0100730 State.Inode.Inline := State.Block_Cache (Cache_Start + 40 .. Cache_Start + 100 - 1);
Nico Huber21d42022023-12-16 02:50:22 +0100731 State.Inode.I := Inode;
Nico Hubercdc03512023-12-13 23:32:54 +0100732 Reset_Cache_Logical (State);
733 State.S := File_Opened;
734 end;
735 end;
736 end Open;
737
738 procedure Open
Nico Huber57d3a852023-12-04 15:42:40 +0100739 (State : in out T;
740 File_Len : out File_Length;
Nico Huberb1cb2d32023-12-17 01:45:47 +0100741 File_Type : out FS.File_Type;
742 File_Name : in String;
743 In_Root : in Boolean;
Nico Huber57d3a852023-12-04 15:42:40 +0100744 Success : out Boolean)
Nico Huber1d7727f2023-11-30 15:58:46 +0100745 is
Nico Huber21d42022023-12-16 02:50:22 +0100746 File_Name_Max : constant := 255;
747 Root_Inode : constant := 2;
748
749 function Str_Buf_Equal (Str : String; Buf : Buffer_Type) return Boolean is
750 begin
751 for I in Str'Range loop
752 if Character'Pos (Str (I)) /= Buf (Buf'First + (I - Str'First)) then
753 return False;
754 end if;
755 end loop;
756 return True;
757 end Str_Buf_Equal;
758
759 File_Inode : Inode_Index;
760 File_Pos : File_Length;
Nico Huber1d7727f2023-11-30 15:58:46 +0100761 begin
Nico Huber57d3a852023-12-04 15:42:40 +0100762 File_Len := 0;
Nico Huber21d42022023-12-16 02:50:22 +0100763 File_Type := FS.File_Type'First;
764
765 if File_Name'Length > File_Name_Max then
766 Success := False;
767 return;
768 end if;
769
770 -- Ensure dir is opened:
771 --
772 if State.S = File_Opened then
773 if State.Cur_Dir /= State.Inode.I then
774 Success := False;
775 return;
776 end if;
777 else
778 if In_Root then
779 State.Cur_Dir := Root_Inode;
780 end if;
781 Open (State, State.Cur_Dir, Success);
782 if not Success then
783 return;
784 end if;
785 end if;
786
787 -- Lookup file in opened dir:
788 --
789 File_Pos := 0;
Nico Huber1d7727f2023-11-30 15:58:46 +0100790 Success := False;
Nico Huber21d42022023-12-16 02:50:22 +0100791 while Unsigned_64 (File_Pos) < Unsigned_64 (State.Inode.Size) loop
792 declare
793 Dir_Entry_Header_Length : constant := 4 + 2 + 1 + 1;
794 subtype Dir_Entry_Index is Natural
795 range 0 .. Dir_Entry_Header_Length + File_Name_Max - 1;
796 Dir_Entry : Buffer_Type (Dir_Entry_Index);
797 Entry_File_Pos : File_Offset := File_Pos;
798 Len : Natural;
799 begin
800 Read
801 (State => State,
802 File_Pos => Entry_File_Pos,
803 Buf => Dir_Entry (0 .. 7),
804 Len => Len);
805 if Len < Dir_Entry_Header_Length then
806 return;
807 end if;
808
809 -- Only check filenames of exact same length
810 if Read_LE32 (Dir_Entry, 0) > Root_Inode and then
811 File_Name'Length = Natural (Dir_Entry (6))
812 then
813 Read
814 (State => State,
815 File_Pos => Entry_File_Pos,
816 Buf => Dir_Entry (8 .. 8 + File_Name'Length - 1),
817 Len => Len);
818 if Len < File_Name'Length then
819 return;
820 end if;
821
822 File_Inode := Inode_Index (Read_LE32 (Dir_Entry, 0));
823 Success := Str_Buf_Equal (File_Name, Dir_Entry (8 .. 8 + File_Name'Length - 1));
824 exit when Success;
825 end if;
826
827 File_Pos := File_Pos + File_Length (Read_LE16 (Dir_Entry, 4));
828 end;
829 end loop;
830
831 if Success then
832 Open (State, File_Inode, Success);
833 if not Success then
834 return;
835 end if;
836
837 if State.Inode.Mode = Dir then
838 State.Cur_Dir := File_Inode;
839 end if;
840 end if;
841
842 Success := Unsigned_64 (State.Inode.Size) <= Unsigned_64 (File_Length'Last);
843 if Success then
844 File_Len := File_Length (State.Inode.Size);
845 File_Type := (case State.Inode.Mode is
846 when Dir => FS.Dir,
847 when Regular => FS.Regular,
848 when Link .. Fast_Link => FS.Link);
849 else
850 Close (State);
851 end if;
Nico Huber1d7727f2023-11-30 15:58:46 +0100852 end Open;
853
Nico Huber57d3a852023-12-04 15:42:40 +0100854 procedure Close (State : in out T) is
855 begin
856 State.S := Mounted;
857 end Close;
Nico Huber1d7727f2023-11-30 15:58:46 +0100858
Nico Huber57d3a852023-12-04 15:42:40 +0100859 procedure Read
860 (State : in out T;
Nico Huber57d3a852023-12-04 15:42:40 +0100861 File_Pos : in out File_Offset;
862 Buf : out Buffer_Type;
863 Len : out Natural)
Nico Huber1d7727f2023-11-30 15:58:46 +0100864 is
Nico Huberd3644be2023-12-16 01:43:00 +0100865 Pos : Natural;
Nico Huber1d7727f2023-11-30 15:58:46 +0100866 begin
Nico Huberd3644be2023-12-16 01:43:00 +0100867 if State.Inode.Mode = Fast_Link then
Nico Huber549a1b82023-12-17 01:51:59 +0100868 if State.Inode.Size > Inode_Length (State.Inode.Inline'Length) or
869 Inode_Length (File_Pos) >= State.Inode.Size then
Nico Huberd3644be2023-12-16 01:43:00 +0100870 Len := 0;
871 else
Nico Huber549a1b82023-12-17 01:51:59 +0100872 Len := Natural'Min (Buf'Length, Natural (State.Inode.Size) - Natural (File_Pos));
Nico Huberd3644be2023-12-16 01:43:00 +0100873 end if;
874 Buf (Buf'First .. Buf'First + Len - 1) :=
875 State.Inode.Inline (Natural (File_Pos) .. Natural (File_Pos) + Len - 1);
876 Buf (Buf'First + Len .. Buf'Last) := (others => 16#00#);
877 File_Pos := File_Pos + File_Length (Len);
878 return;
879 end if;
880
Nico Huber1d7727f2023-11-30 15:58:46 +0100881 Len := 0;
Nico Huberd3644be2023-12-16 01:43:00 +0100882 Pos := Buf'First;
883 while Pos <= Buf'Last and Inode_Length (File_Pos) < State.Inode.Size loop
884 declare
Nico Huber700a4112024-01-08 15:50:09 +0100885 In_Block : constant Max_Block_Index := Natural (File_Pos) mod State.Block_Size;
886 Logical : constant FSBlock_Logical := FSBlock_Logical (File_Pos / File_Offset (State.Block_Size));
887 In_Block_Space : constant Natural := Natural (State.Block_Size) - In_Block;
Nico Huber549a1b82023-12-17 01:51:59 +0100888 In_File_Space : constant Inode_Length := State.Inode.Size - Inode_Length (File_Pos);
Nico Huberd3644be2023-12-16 01:43:00 +0100889 In_Buf_Space : constant Natural := Buf'Last - Pos + 1;
890 Len_Here : Natural;
891 begin
892 Len_Here := In_Block_Space;
Nico Huber549a1b82023-12-17 01:51:59 +0100893 if In_File_Space < Inode_Length (Len_Here) then
894 Len_Here := Natural (In_File_Space);
Nico Huberd3644be2023-12-16 01:43:00 +0100895 end if;
896 if In_Buf_Space < Len_Here then
897 Len_Here := In_Buf_Space;
898 end if;
899
900 declare
901 Last : constant Index_Type := Pos + Len_Here - 1;
902 Cache_Start, Cache_End : Max_Block_Index;
903 Physical : FSBlock_Offset;
904 Success : Boolean;
905 begin
906 if State.Inode.Use_Extents then
907 Extent_Block_Map (State, Logical, Physical, Success);
908 else
909 Ext2_Block_Map (State, Logical, Physical, Success);
910 end if;
911 if Success then
912 Cache_FSBlock
913 (State => State,
914 Phys => Physical,
915 Level => Block_Cache_Index'Last,
916 Cache_Start => Cache_Start,
917 Cache_End => Cache_End,
918 Success => Success);
919 end if;
920 exit when not Success;
921
922 Buf (Pos .. Last) := State.Block_Cache (
923 Cache_Start + In_Block .. Cache_Start + In_Block + Len_Here - 1);
924 File_Pos := File_Pos + File_Length (Len_Here);
925 Pos := Pos + Len_Here;
926 Len := Len + Len_Here;
927 end;
928 end;
929 end loop;
930 Buf (Pos .. Buf'Last) := (others => 16#00#);
Nico Huber1d7727f2023-11-30 15:58:46 +0100931 end Read;
932
Nico Huber26f71832023-12-05 16:26:56 +0100933 --------------------------------------------------------------------------
934
935 package C is new VFS (T => T, Initial => (S => Unmounted, others => <>));
Nico Huber8ec45a12023-12-04 17:11:08 +0100936
937 function C_Mount return int
938 with
939 Export,
940 Convention => C,
941 External_Name => "ext2fs_mount";
942 function C_Mount return int
943 with
944 SPARK_Mode => Off
945 is
946 begin
947 return C.C_Mount;
948 end C_Mount;
949
Nico Huber3da21472023-12-18 15:43:35 +0100950 function C_Open (File_Path : System.Address) return int
Nico Huber8ec45a12023-12-04 17:11:08 +0100951 with
952 Export,
953 Convention => C,
954 External_Name => "ext2fs_dir";
Nico Huber3da21472023-12-18 15:43:35 +0100955 function C_Open (File_Path : System.Address) return int
Nico Huber8ec45a12023-12-04 17:11:08 +0100956 with
957 SPARK_Mode => Off
958 is
959 begin
960 return C.C_Open (File_Path);
961 end C_Open;
962
963 function C_Read (Buf : System.Address; Len : int) return int
964 with
965 Export,
966 Convention => C,
967 External_Name => "ext2fs_read";
968 function C_Read (Buf : System.Address; Len : int) return int
969 with
970 SPARK_Mode => Off
971 is
972 begin
973 return C.C_Read (Buf, Len);
974 end C_Read;
975
Thomas Heijligen5c43abc2023-12-11 15:24:36 +0000976end FILO.FS.Ext2;