?
Solved

get first cluster of a file

Posted on 2001-08-17
8
Medium Priority
?
245 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 22

Accepted Solution

by:
Mohammed Nasman earned 1200 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
 

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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Storage devices are generally used to save the data or sometime transfer the data from one computer system to another system. However, sometimes user accidentally erased their important data from the Storage devices. Users have to know how data reco…
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 walk an individual through the process of configuring basic necessities in order to use the 2010 version of Data Protection Manager. These include storage, agents, and protection jobs. Launch Data Protection Manager from the deskt…
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…
Suggested Courses

777 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