1 ------------------------------------------------------------------------------
3 -- GNAT RUN-TIME COMPONENTS --
5 -- S Y S T E M . D I R E C T _ I O --
9 -- Copyright (C) 1992-2014, Free Software Foundation, Inc. --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. --
18 -- As a special exception under Section 7 of GPL version 3, you are granted --
19 -- additional permissions described in the GCC Runtime Library Exception, --
20 -- version 3.1, as published by the Free Software Foundation. --
22 -- You should have received a copy of the GNU General Public License and --
23 -- a copy of the GCC Runtime Library Exception along with this program; --
24 -- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
25 -- <http://www.gnu.org/licenses/>. --
27 -- GNAT was originally developed by the GNAT team at New York University. --
28 -- Extensive contributions were provided by Ada Core Technologies Inc. --
30 ------------------------------------------------------------------------------
32 -- This package contains the declaration of the control block used for
33 -- Direct_IO. This must be declared at the outer library level. It also
34 -- contains code that is shared between instances of Direct_IO.
36 with Interfaces
.C_Streams
;
38 with System
.File_Control_Block
;
39 with System
.Storage_Elements
;
41 package System
.Direct_IO
is
43 package FCB
renames System
.File_Control_Block
;
45 type Operation
is (Op_Read
, Op_Write
, Op_Other
);
46 -- Type used to record last operation (to optimize sequential operations)
48 subtype Count
is Interfaces
.C_Streams
.int64
;
49 -- The Count type in each instantiation is derived from this type
51 subtype Positive_Count
is Count
range 1 .. Count
'Last;
53 type Direct_AFCB
is new FCB
.AFCB
with record
55 -- Current Index value
57 Bytes
: Interfaces
.C_Streams
.size_t
;
58 -- Length of item in bytes (set from inside generic template)
60 Last_Op
: Operation
:= Op_Other
;
61 -- Last operation performed on file, used to avoid unnecessary
62 -- repositioning between successive read or write operations.
65 function AFCB_Allocate
(Control_Block
: Direct_AFCB
) return FCB
.AFCB_Ptr
;
67 procedure AFCB_Close
(File
: not null access Direct_AFCB
);
68 procedure AFCB_Free
(File
: not null access Direct_AFCB
);
71 (File
: in out Direct_AFCB
;
72 Item
: out Ada
.Streams
.Stream_Element_Array
;
73 Last
: out Ada
.Streams
.Stream_Element_Offset
);
74 -- Required overriding of Read, not actually used for Direct_IO
77 (File
: in out Direct_AFCB
;
78 Item
: Ada
.Streams
.Stream_Element_Array
);
79 -- Required overriding of Write, not actually used for Direct_IO
81 type File_Type
is access all Direct_AFCB
;
82 -- File_Type in individual instantiations is derived from this type
85 (File
: in out File_Type
;
86 Mode
: FCB
.File_Mode
:= FCB
.Inout_File
;
90 function End_Of_File
(File
: File_Type
) return Boolean;
92 function Index
(File
: File_Type
) return Positive_Count
;
95 (File
: in out File_Type
;
102 Item
: System
.Address
;
103 Size
: Interfaces
.C_Streams
.size_t
;
104 From
: Positive_Count
);
108 Item
: System
.Address
;
109 Size
: Interfaces
.C_Streams
.size_t
);
111 procedure Reset
(File
: in out File_Type
; Mode
: FCB
.File_Mode
);
112 procedure Reset
(File
: in out File_Type
);
114 procedure Set_Index
(File
: File_Type
; To
: Positive_Count
);
116 function Size
(File
: File_Type
) return Count
;
120 Item
: System
.Address
;
121 Size
: Interfaces
.C_Streams
.size_t
;
122 Zeroes
: System
.Storage_Elements
.Storage_Array
);
123 -- Note: Zeroes is the buffer of zeroes used to fill out partial records
125 -- The following procedures have a File_Type formal of mode IN OUT because
126 -- they may close the original file. The Close operation may raise an
127 -- exception, but in that case we want any assignment to the formal to
128 -- be effective anyway, so it must be passed by reference (or the caller
129 -- will be left with a dangling pointer).
131 pragma Export_Procedure
134 Parameter_Types
=> (File_Type
),
135 Mechanism
=> Reference
);
136 pragma Export_Procedure
139 Parameter_Types
=> (File_Type
, FCB
.File_Mode
),
140 Mechanism
=> (File
=> Reference
));
142 end System
.Direct_IO
;