Added delete files and directory functions to flatfs
This commit is contained in:
parent
27177979a2
commit
b601080960
@ -572,6 +572,138 @@ begin
|
|||||||
kfree(buffer);
|
kfree(buffer);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure delete_file(volume : PStorage_Volume; fileName : pchar; status : PuInt32);
|
||||||
|
var
|
||||||
|
directories : PLinkedListBase;
|
||||||
|
i : uint32;
|
||||||
|
p : uint32;
|
||||||
|
|
||||||
|
fileEntries : PFile_Entry;
|
||||||
|
fileEntry : PFile_Entry;
|
||||||
|
zeroBuffer : PuInt32;
|
||||||
|
|
||||||
|
position : uint32;
|
||||||
|
offset : uint32;
|
||||||
|
|
||||||
|
fileCount : uint32 = 1000;
|
||||||
|
|
||||||
|
exsists : boolean;
|
||||||
|
begin
|
||||||
|
|
||||||
|
//load file table
|
||||||
|
fileEntries := PFile_Entry(Kalloc(sizeof(TFile_Entry) * fileCount + 512));
|
||||||
|
memset(uint32(fileEntries), 0, sizeof(TFile_Entry) * fileCount);
|
||||||
|
|
||||||
|
volume^.device^.readCallback(volume^.device, volume^.sectorStart + 1, sizeof(TFile_Entry) * fileCount div 512, puint32(fileEntries));
|
||||||
|
|
||||||
|
//check if file exists else exit
|
||||||
|
for i := 0 to fileCount - 1 do begin
|
||||||
|
|
||||||
|
if stringEquals(fileEntries[i].name, fileName) then begin
|
||||||
|
exsists := true;
|
||||||
|
p:= i;
|
||||||
|
break;
|
||||||
|
end;
|
||||||
|
|
||||||
|
end;
|
||||||
|
|
||||||
|
//set position of entry
|
||||||
|
position := (p * sizeof(TFile_Entry)) div 512;
|
||||||
|
|
||||||
|
//if entry is directory then exit
|
||||||
|
if fileEntries[p].attribues and $10 = $10 then begin
|
||||||
|
status^ := 1;
|
||||||
|
exit;
|
||||||
|
end;
|
||||||
|
|
||||||
|
//if entry is not found exit
|
||||||
|
if fileEntries[i].attribues = 0 then begin
|
||||||
|
exsists := false;
|
||||||
|
p:= i;
|
||||||
|
exit;
|
||||||
|
end;
|
||||||
|
|
||||||
|
//zero out file
|
||||||
|
zeroBuffer := Kalloc(fileEntries[p].size);
|
||||||
|
memset(uint32(zeroBuffer), 0, fileEntries[p].size);
|
||||||
|
|
||||||
|
//write file
|
||||||
|
volume^.device^.writeCallback(volume^.device, fileEntries[p].start, fileEntries[p].size, zeroBuffer);
|
||||||
|
|
||||||
|
//free buffer
|
||||||
|
Kfree(puint32(zeroBuffer));
|
||||||
|
|
||||||
|
//zero out file table
|
||||||
|
memset(uint32(@fileEntries[p]), 0, sizeof(TFile_Entry));
|
||||||
|
|
||||||
|
//write file table
|
||||||
|
volume^.device^.writeCallback(volume^.device, volume^.sectorStart + 1 , 1, puint32(@fileEntries[position]));
|
||||||
|
|
||||||
|
//free buffer
|
||||||
|
Kfree(puint32(fileEntries));
|
||||||
|
|
||||||
|
status^ := 0;
|
||||||
|
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure delete_directory(volume : PStorage_Volume; directoryName : pchar; status : PuInt32);
|
||||||
|
var
|
||||||
|
directories : PLinkedListBase;
|
||||||
|
i : uint32;
|
||||||
|
p : uint32;
|
||||||
|
|
||||||
|
fileEntries : PFile_Entry;
|
||||||
|
fileEntry : PFile_Entry;
|
||||||
|
zeroBuffer : PuInt32;
|
||||||
|
|
||||||
|
position : uint32;
|
||||||
|
offset : uint32;
|
||||||
|
|
||||||
|
fileCount : uint32 = 1000;
|
||||||
|
|
||||||
|
exsists : boolean;
|
||||||
|
begin
|
||||||
|
|
||||||
|
//load file table
|
||||||
|
fileEntries := PFile_Entry(Kalloc(sizeof(TFile_Entry) * fileCount + 512));
|
||||||
|
memset(uint32(fileEntries), 0, sizeof(TFile_Entry) * fileCount);
|
||||||
|
|
||||||
|
volume^.device^.readCallback(volume^.device, volume^.sectorStart + 1, sizeof(TFile_Entry) * fileCount div 512, puint32(fileEntries));
|
||||||
|
|
||||||
|
//check if file exists else exit
|
||||||
|
|
||||||
|
for i := 0 to fileCount - 1 do begin
|
||||||
|
|
||||||
|
if stringEquals(fileEntries[i].name, directoryName) then begin
|
||||||
|
exsists := true;
|
||||||
|
p:= i;
|
||||||
|
break;
|
||||||
|
end;
|
||||||
|
|
||||||
|
end;
|
||||||
|
|
||||||
|
//if entry is not directory then exit
|
||||||
|
if fileEntries[i].attribues and $10 <> $10 then begin
|
||||||
|
status^ := 1;
|
||||||
|
exit;
|
||||||
|
end;
|
||||||
|
|
||||||
|
//calculate position of directory in file table
|
||||||
|
position := (p * sizeof(TFile_Entry)) div 512;
|
||||||
|
|
||||||
|
//zero file table
|
||||||
|
memset(uint32(@fileEntries[p]), 0, sizeof(TFile_Entry));
|
||||||
|
|
||||||
|
//write file table
|
||||||
|
volume^.device^.writeCallback(volume^.device, volume^.sectorStart + 1 , 1, puint32(@fileEntries[position]));
|
||||||
|
|
||||||
|
//free buffer
|
||||||
|
Kfree(puint32(fileEntries));
|
||||||
|
|
||||||
|
status^ := 0;
|
||||||
|
|
||||||
|
end;
|
||||||
|
|
||||||
|
|
||||||
procedure init();
|
procedure init();
|
||||||
begin
|
begin
|
||||||
|
Loading…
x
Reference in New Issue
Block a user