FILE_ALIGNMENT_INFO

I have used the user mode API GetFileInformationByHandleEx FileAlignmentInfo for several years. on every system except one it has always either failed (older OS), or returned 0 or 1 as the AlignmentRequirement

I have encountered a system with a disk where AlignmentRequirement comes back as 3. This seems strange to me as I expected the AlignmentRequirement to always be a power of 2, but either I am doing something wrong or my expectations are fallacious

has anyone seen behaviour like this before?

the disk in question is a Cisco UCS-PCI25-40010= - 400GB 2.5IN SFF PCIE NVMESTOR INTL P3700 HGH ENDURANCE

and the OS is Server 2012 R2

I subsequently use the alignment in this code to align a pointer

UINT_PTR Remainder;

Remainder = ((UINT_PTR)pRecord + sizeof(DISK_LOG_RECORD)) % pDiskLog->fai.AlignmentRequirement;

if(Remainder == 0)
{
pRecord->szBuf = (char*)((UINT_PTR)pRecord + sizeof(DISK_LOG_RECORD));
}
else
{
pRecord->szBuf = (char*)((UINT_PTR)pRecord + sizeof(DISK_LOG_RECORD) + pDiskLog->fai.AlignmentRequirement - Remainder);
}

but the “aligned” pointer causes WriteFile to fail with 87 as I am doing unbuffered IO

pLogFile->hFile = CreateFileW( pLogFile->wzPath,
GENERIC_WRITE,
FILE_SHARE_READ|FILE_SHARE_DELETE,
NULL,
CREATE_ALWAYS,
FILE_FLAG_OVERLAPPED|
FILE_ATTRIBUTE_NOT_CONTENT_INDEXED|
FILE_FLAG_WRITE_THROUGH|
FILE_FLAG_SEQUENTIAL_SCAN|
(FILE_FLAG_NO_BUFFERING),
0);

xxxxx@hotmail.com xxxxx@lists.osr.com wrote:

I have used the user mode API GetFileInformationByHandleEx FileAlignmentInfo for several years. on every system except one it has always either failed (older OS), or returned 0 or 1 as the AlignmentRequirement

I have encountered a system with a disk where AlignmentRequirement comes back as 3. This seems strange to me as I expected the AlignmentRequirement to always be a power of 2, but either I am doing something wrong or my expectations are fallacious

has anyone seen behaviour like this before?

Interesting.  My SATA hard disks return 1, a network drive returns 0, a
USB memory stick returns 0, but a USB-attached SATA drive returns 3.

So, that value is either a bitmask, or log 2 of the actual value.  I’d
be more likely to guess a bitmask, which means the value YOU want is N+1.


Tim Roberts, xxxxx@probo.com
Providenza & Boekelheide, Inc.

Correct…The value returned is from the AlignmentRequirement field of the
device object:

https://msdn.microsoft.com/en-us/library/windows/hardware/ff543147(v=vs.85).aspx

Some defines are provided in WDM.H for common values:

//
// Define alignment requirement values
//

#define FILE_BYTE_ALIGNMENT 0x00000000
#define FILE_WORD_ALIGNMENT 0x00000001
#define FILE_LONG_ALIGNMENT 0x00000003
#define FILE_QUAD_ALIGNMENT 0x00000007
#define FILE_OCTA_ALIGNMENT 0x0000000f

-scott
OSR
@OSRDrivers

wrote in message news:xxxxx@ntdev…

xxxxx@hotmail.com xxxxx@lists.osr.com wrote:

I have used the user mode API GetFileInformationByHandleEx
FileAlignmentInfo for several years. on every system except one it has
always either failed (older OS), or returned 0 or 1 as the
AlignmentRequirement

I have encountered a system with a disk where AlignmentRequirement comes
back as 3. This seems strange to me as I expected the
AlignmentRequirement to always be a power of 2, but either I am doing
something wrong or my expectations are fallacious

has anyone seen behaviour like this before?

Interesting. My SATA hard disks return 1, a network drive returns 0, a
USB memory stick returns 0, but a USB-attached SATA drive returns 3.

So, that value is either a bitmask, or log 2 of the actual value. I’d
be more likely to guess a bitmask, which means the value YOU want is N+1.


Tim Roberts, xxxxx@probo.com
Providenza & Boekelheide, Inc.

Thanks!

Sent from Mailhttps: for Windows 10

From: Scott Noonemailto:xxxxx
Sent: August 25, 2017 8:59 AM
To: Windows System Software Devs Interest Listmailto:xxxxx
Subject: Re:[ntdev] FILE_ALIGNMENT_INFO

Correct…The value returned is from the AlignmentRequirement field of the
device object:

https://msdn.microsoft.com/en-us/library/windows/hardware/ff543147(v=vs.85).aspx

Some defines are provided in WDM.H for common values:

//
// Define alignment requirement values
//

#define FILE_BYTE_ALIGNMENT 0x00000000
#define FILE_WORD_ALIGNMENT 0x00000001
#define FILE_LONG_ALIGNMENT 0x00000003
#define FILE_QUAD_ALIGNMENT 0x00000007
#define FILE_OCTA_ALIGNMENT 0x0000000f


-scott
OSR
@OSRDrivers

wrote in message news:xxxxx@ntdev…

xxxxx@hotmail.com xxxxx@lists.osr.com wrote:
> I have used the user mode API GetFileInformationByHandleEx
> FileAlignmentInfo for several years. on every system except one it has
> always either failed (older OS), or returned 0 or 1 as the
> AlignmentRequirement
>
> I have encountered a system with a disk where AlignmentRequirement comes
> back as 3. This seems strange to me as I expected the
> AlignmentRequirement to always be a power of 2, but either I am doing
> something wrong or my expectations are fallacious
>
> has anyone seen behaviour like this before?

Interesting. My SATA hard disks return 1, a network drive returns 0, a
USB memory stick returns 0, but a USB-attached SATA drive returns 3.

So, that value is either a bitmask, or log 2 of the actual value. I’d
be more likely to guess a bitmask, which means the value YOU want is N+1.


Tim Roberts, xxxxx@probo.com
Providenza & Boekelheide, Inc.


NTDEV is sponsored by OSR

Visit the list online at: http:

MONTHLY seminars on crash dump analysis, WDF, Windows internals and software drivers!
Details at http:

To unsubscribe, visit the List Server section of OSR Online at http:</http:></http:></http:></mailto:xxxxx></mailto:xxxxx></https:>

Scott Noone wrote:

Correct…The value returned is from the AlignmentRequirement field of the
device object:

https://msdn.microsoft.com/en-us/library/windows/hardware/ff543147(v=vs.85).aspx

Good spotting.  I submitted doc feedback on the FILE_ALIGNMENT_INFO page.


Tim Roberts, xxxxx@probo.com
Providenza & Boekelheide, Inc.