-
Notifications
You must be signed in to change notification settings - Fork 0
/
fs-fs.ads
126 lines (107 loc) · 6.35 KB
/
fs-fs.ads
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
-------------------------------------------------------------------------
-- --
-- RTEMS FILE-SYSTEM SUPPORT --
-- --
-- F S . F S --
-- --
-- S p e c i f i c a t i o n --
-- --
-- $ Revision: 1.0 $ --
-- --
-- Alejandro Villanueva Uribarri (Universidad de Zaragoza) --
-- --
-------------------------------------------------------------------------
-------------------------------------------------------------------------
-- This package provides the Filesystem on top of the IDE driver. It's --
-- a simple filesystem that only support read operations on a FAT 16 --
-- partition. --
-- --
-- From here you get two protected types: --
-- (*) Path: with this you can create different Path Contexts that can --
-- be used by the File_Handler type to identify files on the disk. --
-- (*) File_Handler: variables of this type contain access information --
-- for the opened files in the system. --
-- We also get a default variable for each type: --
-- (*) Default_Path: Path; --
-- (*) Default_File: File_Handler; --
-- --
-- These types work as follows: To open a file in our FAT 16 system --
-- named "C:\alex\pfc\pfc.txt" we proceed this way... --
-- (1) We assign the Path variable Default_Path to "C:\alex\pfc" with --
-- the following operations: --
-- Default_Path.cd_partition (0); --
-- Default_Path.cd_absolute (Create_File_Name ("alex")); --
-- Default_Path.cd_relative (Create_File_Name ("pfc")); --
-- (2) Now we open the file "pfc.txt" by issuing this command: --
-- Default_File.Open (Create_File_Name ("pfc.txt"), --
-- Default_Path, --
-- Read_Only); --
-- Please note that the last two parameters are optional and --
-- that they default to Default_Path and Read_Only. --
-- (3) We could have defined our own Path and File_Handler variables. --
-- (4) If we want to print data from Default_File upon screen we use --
-- the Read_Sector operation like this: --
-- Data: fs.Data_Block; --
-- EOF, Final: Natural; --
-- Sector: fs.DWord := 0; --
-- loop --
-- Default_File.Read_Sector (Data, EOF, Sector); --
-- if EOF = 512 then Final := 511; --
-- else Final := EOF; --
-- end if; --
-- for I in 0 .. Final loop --
-- Ada.Text_IO.Put (Character'Val (Data (I))); --
-- end loop; --
-- exit when Final = EOF; --
-- Sector := Sector + 1; --
-- end loop; --
-- --
-- Please note that only the Read operation is currently implemented. --
-- Writing operation is not needed, so I won't implement it. Anyhow it --
-- is simple to implement in case you need to. --
-------------------------------------------------------------------------
with Ada.Strings.Bounded;
use Ada.Strings.Bounded;
package fs.fs is
package Bounded_12 is new Generic_Bounded_Length (12);
type File is new Bounded_12.Bounded_String;
type File_Type is (Regular, Directory, Not_Found);
type File_Mode is (Read_Only, Read_Write, Closed);
function Create_File_Name (File_Name: in String)
return File;
protected type Path is
function Get_First_Cluster_of_Dir
return Word;
function Get_Partition_Nr
return Natural;
procedure cd_absolute (New_Path: in File);
procedure cd_relative (New_Path: in File);
procedure cd_partition (New_Partition: in Natural);
private
Partition_Nr: Natural := 0;
First_Cluster_of_Dir: Word := 0;
end Path;
Default_Path: Path;
protected type File_Handler is
entry Open (File_Name: in File;
Path_Context: in Path := Default_Path;
Open_Mode: in File_Mode := Read_Only);
entry Read_Sector (Where: out Data_Block;
EOF_Mark_At: out Natural;
Sector: in DWord := 0);
entry Close;
function Is_Closed
return Boolean;
private
Partition_Nr: Natural := 0;
First_Cluster_of_File: Word := 0;
File_Size: DWord := 0;
Mode: File_Mode := Closed;
Cursor_Position: DWord := 0;
end File_Handler;
Default_File: File_Handler;
File_Not_Found_Exception: exception;
End_Of_File_Exception: exception;
Invalid_Partition_Exception: exception;
Bad_Cluster_Number_Exception: exception;
end fs.fs;