VCN to sector

Hello All!

Does anyone know how to properly convert VCNs taken from
FSCTL_GET_RETRIEVAL_POINTERS to the sector units? I just want to make sure I
do this translation correct.

Thanks in advance!

Mike

See http://www.wd-3.com/archive/luserland.htm


Don Burn (MVP, Windows DDK)
Windows Filesystem and Driver Consulting
Website: http://www.windrvr.com
Blog: http://msmvps.com/blogs/WinDrvr

“Mike Alekseev” wrote in message news:xxxxx@ntdev…
> Hello All!
>
>
>
> Does anyone know how to properly convert VCNs taken from
> FSCTL_GET_RETRIEVAL_POINTERS to the sector units? I just want to make sure
> I
> do this translation correct.
>
>
>
> Thanks in advance!
>
> Mike
>
>
>
>
>
>
> Information from ESET NOD32 Antivirus, version of virus
> signature database 4063 (20090508)

>
> The message was checked by ESET NOD32 Antivirus.
>
> http://www.eset.com
>
>

Information from ESET NOD32 Antivirus, version of virus signature database 4063 (20090508)

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com

Thanks Don!

This is a good article even if there are some strange assumptions about
FAT32 a “bug-feature”. Anyway I knew about this article and used it in my
experiments on NTFS but by some reason the sample does not work! I’m always
receiving STATUS_WAIT_1 (0x00000001) either in Kernel or in User modes.
Could you please examine the simple code below and say what is wrong there:

STARTING_VCN_INPUT_BUFFER inputVcn;
RETRIEVAL_POINTERS_BUFFER rpBuf;
VOLUME_LOGICAL_OFFSET lOffset;
VOLUME_PHYSICAL_OFFSETS pOffset;

GetDiskFreeSpace( L"Y:\“, &SectorsPerCluster, &BytesPerSector,
&NumOfFreeClusters, &TotalClusters );
printf(”%d %d %d %d\n", SectorsPerCluster, BytesPerSector,
NumOfFreeClusters, TotalClusters );

4 512 777918 783152

if( (hFile = CreateFileA( “Y:\test.dat”, FILE_ALL_ACCESS, 0, NULL,
OPEN_EXISTING, 0, NULL ) ) == INVALID_HANDLE_VALUE ) {
printf(“Failed to create "%s" file, error %d\n”, argv[1], GetLastError()
);
return -1;
}

inputVcn.StartingVcn.QuadPart = 0;
bRet = DeviceIoControl( hFile, FSCTL_GET_RETRIEVAL_POINTERS, &inputVcn,
sizeof(STARTING_VCN_INPUT_BUFFER), &rpBuf,
sizeof(RETRIEVAL_POINTERS_BUFFER), &dwBytesReturned, NULL );
if( bRet == FALSE )
printf(“DeviceIoControl error 0x%08X\n”, GetLastError() );

lOffset.LogicalOffset = rpBuf.Extents[0].Lcn.QuadPart * SectorsPerCluster *
BytesPerSector;
// rpBuf.Extents[0].Lcn.QuadPart = 0x000000000005F9A4
// lOffset.LogicalOffset = 0x000000002FCD2000
bRet = DeviceIoControl( hFile, IOCTL_VOLUME_LOGICAL_TO_PHYSICAL, &lOffset,
sizeof(VOLUME_LOGICAL_OFFSET), &pOffset, sizeof(VOLUME_PHYSICAL_OFFSETS),
&dwBytesReturned, NULL );
if( bRet == FALSE )
printf(“DeviceIoControl error 0x%08X\n”, GetLastError() );

DeviceIoControl error 0x00000001

The NTFS volume I’m working with has no compression and is a regular simple
volume on a single disk.

Thanks, regards,
Mike

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Don Burn
Sent: Sunday, May 10, 2009 1:45 AM
To: Windows System Software Devs Interest List
Subject: Re:[ntdev] VCN to sector

See http://www.wd-3.com/archive/luserland.htm


Don Burn (MVP, Windows DDK)
Windows Filesystem and Driver Consulting
Website: http://www.windrvr.com
Blog: http://msmvps.com/blogs/WinDrvr

“Mike Alekseev” wrote in message news:xxxxx@ntdev…
> Hello All!
>
>
>
> Does anyone know how to properly convert VCNs taken from
> FSCTL_GET_RETRIEVAL_POINTERS to the sector units? I just want to make sure

> I
> do this translation correct.
>
>
>
> Thanks in advance!
>
> Mike
>
>
>
>
>
>
> Information from ESET NOD32 Antivirus, version of virus
> signature database 4063 (20090508)

>
> The message was checked by ESET NOD32 Antivirus.
>
> http://www.eset.com
>
>

Information from ESET NOD32 Antivirus, version of virus signature
database 4063 (20090508)


The message was checked by ESET NOD32 Antivirus.

http://www.eset.com


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer

On Sun, May 10, 2009 at 3:55 AM, Mike Alekseev wrote:
>> DeviceIoControl error 0x00000001

ERROR_INVALID_FUNCTION

You have to do IOCTL_VOLUME_LOGICAL_TO_PHYSICAL on the volume handle
not the file handle.

Mark Roddy

Thanks Mark!

You are absolutely right! I have already found&fixed this stupid mistake in
my head and code but anyway I would like to thank you for the article you
created!

Best wishes!
Mike

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Mark Roddy
Sent: Sunday, May 10, 2009 5:19 PM
To: Windows System Software Devs Interest List
Subject: Re: [ntdev] VCN to sector

On Sun, May 10, 2009 at 3:55 AM, Mike Alekseev wrote:
>> DeviceIoControl error 0x00000001

ERROR_INVALID_FUNCTION

You have to do IOCTL_VOLUME_LOGICAL_TO_PHYSICAL on the volume handle
not the file handle.

Mark Roddy


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer

> bRet = DeviceIoControl( hFile, IOCTL_VOLUME_LOGICAL_TO_PHYSICAL, &lOffset,

Are you sure this is about FS cluster number to volume offset conversion? I think this is about converting the partition offset to physical disk offset.


Maxim S. Shatskih
Windows DDK MVP
xxxxx@storagecraft.com
http://www.storagecraft.com

I think It returns physical disk specific offsets after doing raid
mapping from logical offset.

You can get two physical offsets for the same logical offset for a
mirrored volume. The
Two physical offsets are offsets into disk.

http://msdn.microsoft.com/en-us/library/ms804515.aspx

Harish

-----Original Message-----
From: Maxim S. Shatskih [mailto:xxxxx@storagecraft.com]
Sent: Monday, May 11, 2009 12:59 PM
To: Windows System Software Devs Interest List
Subject: Re:[ntdev] VCN to sector

bRet = DeviceIoControl( hFile, IOCTL_VOLUME_LOGICAL_TO_PHYSICAL,
&lOffset,

Are you sure this is about FS cluster number to volume offset
conversion? I think this is about converting the partition offset to
physical disk offset.


Maxim S. Shatskih
Windows DDK MVP
xxxxx@storagecraft.com
http://www.storagecraft.com


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer