Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

absolute disk positiion of files

Posted on 1998-07-06
4
Medium Priority
?
230 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 200 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: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

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

In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
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.
Loops Section Overview

927 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