Cita:
Empezado por pcicom
bueno leyendo algo de lo que haces, me gustaria saber si conoces un metodo o la forma en como saber en que sector del disco esta grabado un archivo que yo eliga... posiscion, pista, sector y esas cosas...
|
Bueno, no exactamente el sector pero si se una forma de averiguar en que
clusters esta localizado el archivo. Aunque no entiendo muy bien para que necesitas esa información, si es para conocer lo fragmentado que esta un fichero esto es lo que buscas, si lo que quieres es hacer algún tipo de protección anticopia esto también te puede servir.
Código Delphi
[-]
program Cluster;
{$APPTYPE CONSOLE}
uses
Windows, SysUtils;
const
FSCTL_GET_RETRIEVAL_POINTERS = $90073;
type
Extent = record
Vcn: int64;
Lcn: int64;
end;
RETRIEVAL_POINTERS_BUFFER = record
ExtentCount: Cardinal;
StartingVcn: int64;
Extents: array[0..0] of Extent;
end;
PRETRIEVAL_POINTERS_BUFFER = ^RETRIEVAL_POINTERS_BUFFER ;
procedure OutString(Str: string);
begin
Writeln(Str);
end;
procedure DumpFile(Filename: string);
var
hFile: THandle;
Buffer: array[1..512+2] of int64;
StartVcn: Int64;
ClusterList: PRETRIEVAL_POINTERS_BUFFER;
Returned: Cardinal;
Success: BOOL;
LastError: Cardinal;
i: integer;
begin
hFile:= CreateFile(PChar(Filename),GENERIC_READ, FILE_SHARE_READ or
FILE_SHARE_WRITE ,nil, OPEN_EXISTING,FILE_FLAG_NO_BUFFERING,0);
if hFile <> INVALID_HANDLE_VALUE then
begin
StartVcn:= 0;
ClusterList:= @Buffer;
repeat
Success:= DeviceIOControl(hFile, FSCTL_GET_RETRIEVAL_POINTERS, @StartVcn,
Sizeof(StartVcn),@Buffer, Sizeof(Buffer), Returned, nil);
if Success then
LastError:= 0
else
LastError:= GetLastError;
if Success or (LastError = ERROR_MORE_DATA) then
begin
StartVcn:= ClusterList^.StartingVcn;
for i:= 0 to ClusterList^.ExtentCount - 1 do
begin
OutString(Format('VCN: %d LCN: %d LEN: %d',[StartVcn, ClusterList^.Extents[i].Lcn,
ClusterList^.Extents[i].Vcn - StartVcn]));
StartVcn := ClusterList^.Extents[i].Vcn;
end;
end else OutString(SysErrorMessage(LastError));
until LastError <> ERROR_MORE_DATA;
CloseHandle(hFile);
end else OutString(SysErrorMessage(GetLastError));
end;
begin
DumpFile(ParamStr(0));
readln;
end.
El programa anterior muestra una lista con los cluster que pertenecen al archivo. VCN -> Virtual cluster, LCN -> Logic Cluster (el numero de cluster real, posiblemente el que te interesa), LEN -> Es el numero de clusters contiguos en ese trozo. Lo normal, sobre todo si el archivo es pequeño, es que todos los cluster del archivo sean contiguos, así que la lista solo tendrá una entrada. Busca un archivo muy fragmentado para probar la función y veras como te devuelve la posición de cada trozo.
Aquí te dejo el programa compilado y con el código fuente, listo para usar: