Solved

get first cluster of a file

Posted on 2001-08-17
8
238 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
 
LVL 5

Expert Comment

by:Gwena
ID: 6399464
listening :-)
0
NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

 
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

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

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

Suggested Solutions

This article is an update and follow-up of my previous article:   Storage 101: common concepts in the IT enterprise storage This time, I expand on more frequently used storage concepts.
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 walk an individual through the steps necessary to install and configure the Windows Server Backup Utility. Directly connect an external storage device such as a USB drive, or CD\DVD burner: If the device is a USB drive, ensure i…
This tutorial will walk an individual through the process of installing of Data Protection Manager on a server running Windows Server 2012 R2, including the prerequisites. Microsoft .Net 3.5 is required. To install this feature, go to Server Manager…

914 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

12 Experts available now in Live!

Get 1:1 Help Now