ummgr print client address and bug found
[brdnet.git] / Store1.pas
bloba479db5192097e3f65bb04c8511245ab4bae9f34
1 UNIT Store1;
2 {Take tracks of files in store}
3 {just simple, no cleaning, etc}
4 INTERFACE
5 uses SysUtils;
7 type
8 tfid=array [0..19] of byte;
9 tStoreObjectInfo=object
10 final:boolean; {hash matched}
11 rc:Word; {0=no error 1=not found, other}
12 length:LongWord; {the whole file}
13 seglen:longword; {from cur to end of segment}
15 procedure Open(const fid:tfid);
16 procedure Close;
17 procedure SegSeek(ofs:LongWord); unimplemented;
18 procedure ReadAhead(cnt:Word; into:pointer);
19 procedure WaitRead; {wait for read to finish, rc}
20 private
21 dh:tHandle; {handle to the data file}
22 filename:string[80];
23 procedure mkfilen(var d:string; flag:char; const fid:tfid);
24 end;
26 IMPLEMENTATION
27 const prefix='object';
29 procedure tStoreObjectInfo.mkfilen(var d:string; flag:char; const fid:tfid);
30 function hc(b:byte):char;
31 begin
32 if b<10 then hc:=char(ord('0')+b)
33 else hc:=char(ord('A')-10+b);
34 end;
35 var b,i:byte;
36 begin
37 d:=prefix+flag+'/';
38 b:=system.length(d);
39 SetLength(d,b+40);
40 inc(b);
41 for i:=0 to 19 do begin
42 filename[b+(i*2)]:=hc(fid[i] shr 4);
43 filename[b+(i*2)+1]:=hc(fid[i] and $F);
44 end;
45 end;
46 procedure tStoreObjectInfo.Open(const fid:tfid);
47 begin
48 mkfilen(filename,'f',fid);
49 dh:=FileOpen(filename,fmOpenRead or fmShareDenyWrite);
50 if dh<>-1 then begin
51 rc:=0;
52 final:=true;
53 length:=FileSeek(dh,0,fsFromEnd);
54 FileSeek(dh,0,fsFromBeginning);
55 end else begin
56 Writeln('Store1: open failed for file ',filename,', ioresult=',IOResult);
57 rc:=2;
58 end;
59 end;
60 procedure tStoreObjectInfo.ReadAhead(cnt:Word; into:pointer);
61 var red:LongWord;
62 begin
63 //todo, do real async read
64 red:=FileRead(dh,into^,cnt);
65 if red=cnt then rc:=0 else begin
66 //todo
67 writeln('Store1: read ',red,' out of ',cnt,' requested bytes');
68 rc:=2;
69 end;
70 end;
71 procedure tStoreObjectInfo.WaitRead; {wait for read to finish, rc}
72 begin
73 //todo
74 end;
75 procedure tStoreObjectInfo.Close;
76 begin
77 FileClose(dh);
78 end;
79 procedure tStoreObjectInfo.SegSeek(ofs:longword);
80 begin
81 if ofs=0 then begin
82 rc:=0;
83 seglen:=length;
84 end else rc:=7;
85 end;
87 END.