[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

get first cluster of a file

Posted on 2001-08-17
8
Medium Priority
?
247 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
 
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
Industry Leaders: 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

VM backup deduplication is a method of reducing the amount of storage space needed to save VM backups. In most organizations, VMs contain many duplicate copies of data, such as VMs deployed from the same template, VMs with the same OS, or VMs that h…
Are you looking to recover an email message or a contact you just deleted mistakenly? Or you are searching for a contact that you erased from your MS Outlook ‘Contacts’ folder and now realized that it was important.
This tutorial will walk an individual through the steps necessary to enable the VMware\Hyper-V licensed feature of Backup Exec 2012. In addition, how to add a VMware server and configure a backup job. The first step is to acquire the necessary licen…
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…

649 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