Solved

get first cluster of a file

Posted on 2001-08-17
8
240 Views
Last Modified: 2013-11-15
Hi all!

Since there has been no info on this topic, I am going to try to ask it as a separate question:

is there a way to know the number of the first cluster where a file's contents are kept? to read the whole cluster chain? to read the file's FAT entry?

An ideal answer would be something like:

function GetFirstCluster(Filename: String): Integer;
function GetFATEntry(FileName: String): whatever it is...

yegor
0
Comment
Question by:yegor
8 Comments
 
LVL 22

Accepted Solution

by:
Mohammed Nasman earned 300 total points
ID: 6399153

function GetCluster(PathName : PChar; CharSet : Integer) : LongInt;
type DIOCRegs=record
reg_EBX:DWORD;
reg_EDX:DWORD;
reg_ECX:DWORD;
reg_EAX:DWORD;
reg_EDI:DWORD;
reg_ESI:DWORD;
reg_Flags:DWORD;
end;
var Regs:DIOCregs;
    h:integer;
    i:dword;
begin
  h:=CreateFile('\\.\VWIN32',GENERIC_READ,FILE_SHARE_READ OR
FILE_SHARE_WRITE,nil,OPEN_EXISTING,0,0);
  if h=INVALID_HANDLE_VALUE then begin Result:=0;exit;end;

  // Lock volume
  Regs.reg_EAX := $0D;
  Regs.reg_ECX := $084a;
  Regs.reg_EBX :=$0103;
  Regs.reg_EDX :=0;
  DeviceIoControl(h, 1,@Regs, SIZEOF(Regs),@Regs, SIZEOF(Regs),i,nil);

  // DOS GENERIC IOCTL - GET FIRST CLUSTER
  Regs.reg_EAX := $0D;
  Regs.reg_ECX := $0871;
  Regs.reg_EBX :=CharSet;
  Regs.reg_EDX :=DWORD(PathName);
  DeviceIoControl(h, 1,@Regs, SIZEOF(Regs),@Regs, SIZEOF(Regs),i,nil);

  Result:=Regs.reg_EAX;

  //Unlock volume
  Regs.reg_EAX := $0D;
  Regs.reg_ECX := $086a;
  Regs.reg_EBX :=3;
  DeviceIoControl(h, 1,@Regs, SIZEOF(Regs),@Regs, SIZEOF(Regs),i,nil);

  CloseHandle(h);
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
 ShowMessage(IntToStr(GetCluster('c:\boot.ini',1)));
end;
0
 
LVL 22

Expert Comment

by:Mohammed Nasman
ID: 6399238
0
 

Author Comment

by:yegor
ID: 6399349

Thank you, mnasman, this seems to work all right, but... there is a thing I cannot understand: there are 64 sectors per cluster on my disk. When I get the first cluster using your function, I then multiply the result by 64 and hope to get the number of the corresponding sector -- but it is in fact ALWAYS bigger by 311... What on earth may this mean???

yegor
0
Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

 
LVL 5

Expert Comment

by:Gwena
ID: 6399464
listening :-)
0
 
LVL 1

Expert Comment

by:Fraction
ID: 6399502
listening too ;-)
0
 

Author Comment

by:yegor
ID: 6399533

I have discovered why this happens -- the correct way to get the number of the sector is

(FirstCluster - 2) * SectorsperCluster + SectorOfTheSecondCluster

yegor
0
 

Author Comment

by:yegor
ID: 6399689

Mnasman,

it seems your function works only on the drive C... I wonder why.

Yegor
0
 
LVL 17

Expert Comment

by:geobul
ID: 9286216
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

accept mnasman's comment as answer

Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

Thanks,

geobul
EE Cleanup Volunteer
0

Featured Post

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
In this article we will learn how to backup a VMware farm using Nakivo Backup & Replication. In this tutorial we will install the software on a Windows 2012 R2 Server.
This tutorial will show how to configure a new Backup Exec 2012 server and move an existing database to that server with the use of the BEUtility. Install Backup Exec 2012 on the new server and apply all of the latest hotfixes and service packs. The…
This tutorial will walk an individual through the process of installing the necessary services and then configuring a Windows Server 2012 system as an iSCSI target. To install the necessary roles, go to Server Manager, and select Add Roles and Featu…

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question