Solved

get first cluster of a file

Posted on 2001-08-17
8
237 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:
mnasman earned 300 total points
Comment Utility

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:mnasman
Comment Utility
0
 

Author Comment

by:yegor
Comment Utility

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
 
LVL 5

Expert Comment

by:Gwena
Comment Utility
listening :-)
0
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 1

Expert Comment

by:Fraction
Comment Utility
listening too ;-)
0
 

Author Comment

by:yegor
Comment Utility

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
Comment Utility

Mnasman,

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

Yegor
0
 
LVL 17

Expert Comment

by:geobul
Comment Utility
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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

A Bare Metal Image backup allows for the restore of an entire system to a similar or dissimilar hardware. They are highly useful for migrations and disaster recovery. Bare Metal Image backups support Full and Incremental backups. Differential backup…
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
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…

763 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

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now