1 (* The implementation *)
6 mutable filename
: string option;
7 mutable next
: chunk
option;
13 mutable chunks
: chunk
;
16 let create filename size
=
17 let dirname = Printf.sprintf
"%s.chunks" filename
in
30 let chunk_min_size = ref 65000
32 let split_chunk c pos
=
41 let rec extend_chunk c size
=
44 lprintf
"Cannot extend last chunk\n";
47 if cc.created
<> None
then
52 c
.len
<- (cc.pos
++ cc.len
) -- c
.pos
;
55 if cc.len
>= size
++ !chunk_min_size then
57 split_chunk cc (cc.pos
++ size
);
63 c
.len
<- (cc.pos
++ cc.len
) -- c
.pos
;
64 ftruncate_chunk c
(c
.len
++ cc.len
);
68 let create_chunk c
= ()
70 let get_chunk t pos len
=
74 if c.created
<> None
&& c.pos
<= pos
&& c.pos
++ c.len
>= pos
++ len
then
75 (open_chunk c, pos
-- c.pos
)
77 if c.created
<> None
&& pos
<= c.pos
++ c.len
++ !chunk_min_size then
79 extend_chunk c (maxi
!chunk_min_size (pos
++ len
-- c.pos
-- c.len
++ !chunk_min_size));
83 if c.pos
++ c.len
<= pos
then
86 lprintf
"Invalid access in file pos %Ld is after last chunk\n" pos
;
90 if c.pos
++ !chunk_min_size < pos
then
96 if c.pos
++ c.len
> pos
++ (maxi len
!chunk_min_size) ++ !chunk_min_size then
98 split_chunk c (pos
++ (maxi len
!chunk_min_size) ++ !chunk_min_size);
110 if t
.chunks
.created
= None
then create_chunk c;
111 while t
.chunks
.next
<> None
do
112 extend_chunk c t
.size