Solved

absolute disk positiion of files

Posted on 1998-07-06
4
220 Views
Last Modified: 2013-11-19
I'm looking for a pice of code to get the absolute disk position of a file in windows 95 using visual C++ 5.
0
Comment
Question by:pbranagan
  • 2
4 Comments
 
LVL 8

Expert Comment

by:trestan
ID: 1318750
The function "GetFileInformationByHandle" can serve your purpose.
The file information is contained in the structure "BY_HANDLE_FILE_INFORMATION" in which a data member "dwVolumeSerialNumber" specifies the serial number of the volume that contains the file. I think it is exactely what you want.
Please check the online help for more information.


0
 

Author Comment

by:pbranagan
ID: 1318751
dwVolumeSerialNumber is really not what i'm looking for.
I need a value that will identify a file. ie.. if the file is copied or moved to a different part of the pc then this number will have changed. (i'm thinking the absolute disk position)
0
 
LVL 8

Expert Comment

by:trestan
ID: 1318752
I think you need to read the FAT information of the disk. It is a big topic. Please refer to online help for more information:
Platform,DSK... -> Windows Base Services -> Windows 95 Features


0
 

Accepted Solution

by:
PeterM070698 earned 100 total points
ID: 1318753
I think that this is what you want. The following will give the physical start cluster of a file on FAT16 or FAT32 disk. Note this is for Windows95 ONLY! (NT does is a bit diferently - see help for DeviceIOControl)


#include "windows.h"

#define VWIN32_DIOC_DOS_IOCTL 1

typedef struct _DIOC_REGISTERS {
    DWORD reg_EBX;
    DWORD reg_EDX;
    DWORD reg_ECX;
    DWORD reg_EAX;
    DWORD reg_EDI;
    DWORD reg_ESI;
    DWORD reg_Flags;
} DIOC_REGISTERS, *PDIOC_REGISTERS;



void main()
{
      HANDLE hDevice;
      DIOC_REGISTERS reg;
      BOOL fResult;
      DWORD cb;

      
      hDevice = CreateFile("\\\\.\\vwin32", 0, 0, NULL, 0, FILE_FLAG_DELETE_ON_CLOSE, NULL);

      /*
      CharSet is the Character set of PathName.
      This parameter must be one of these values:

            BCS_WANSI (0)            Windows ANSI character set
            BCS_OEM (1)                  Current OEM character set
            BCS_UNICODE (2)            Unicode character set
       */

      DWORD dwCharSet = 0;
      char* szPathName = "c:\\foo.bar";

      reg.reg_EAX = 0x440D;                        // generic IOCTL
      reg.reg_EBX = dwCharSet;        
      reg.reg_ECX = 0x0871;                        /* device category - 0x08 = disk drive
                                                                  08h    disk drive
                                                                  48h    FAT32 disk drive
                                                                  00h-7Fh reserved for Microsoft
                                                                  80h-FFh reserved for OEM/user-defined
                                                            minor function code - Get First Cluster 0x71*/

      reg.reg_EDX = (DWORD) szPathName;      // see below

      fResult = DeviceIoControl(hDevice, VWIN32_DIOC_DOS_IOCTL, &reg, sizeof(reg), &reg, sizeof(reg), &cb, 0);

      if( !fResult )
            return;

      if( reg.reg_Flags & 0x0001 )
            return; // error if carry flag is set

      //////////////////////////////////////
      //
      //      This is the starting cluster of the file  foo.bar
      //

      DWORD dwStartingCluster = reg.reg_EDX;            

      //
      //
      //////////////////////////////////////

      CloseHandle(hDevice);
}


0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Unix / Linux grid computing 5 146
Expand macro to ask for filename column 8 37
matchUp  challenge 6 53
building a service to accessed via telnet client, want colors ? 4 81
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

911 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

23 Experts available now in Live!

Get 1:1 Help Now