Solved

absolute disk positiion of files

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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 …
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

759 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

18 Experts available now in Live!

Get 1:1 Help Now