Solved

absolute disk positiion of files

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

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Complete beginner needs help making a cron job 9 116
iSeries DB2 Query 2 95
Doc'in system (example?) BA 7 111
wordappend challenge 8 178
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
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.

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