Solved

absolute disk positiion of files

Posted on 1998-07-06
4
225 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Host to IP 7 80
Expand macro to ask for filename column 8 37
zeroFront challenge 7 112
Thin secure Windows 10 5 102
Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
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.

860 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