Aaron Stainback
Aaron Stainback

Reputation: 3657

How to get Physical Sector Size in .NET without PInvoke or Admin elevation on Windows 8

I know in windows 8\server 2012 there is a new native API named FileFsSectorSizeInformation to get physical sector size from any file handle even over SMB2 without admain elevation. I'm looking for the .NET equivalent. Here is some more info on the native way.

http://msdn.microsoft.com/en-us/library/windows/desktop/hh848035(v=vs.85).aspx

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

I'm using .NET 4.5

Upvotes: 0

Views: 1061

Answers (1)

Hans Passant
Hans Passant

Reputation: 941455

No, that's not wrapped by .NET. It is not an api, it is a driver control code. You'll need to pinvoke DeviceIoControl() to use it. .NET in general avoids these low-level driver implementation details, too hard to keep them stable across Windows versions.

Do watch out here, what you contemplate doing doesn't make much sense in general. Calling FileStream.Flush() would be necessary to ensure that logging data gets written before your program crashes so you can be sure you have an up-to-date log. Passing true to the overload is extremely detrimental to perf, disk writes are very slow, it is only necessary if your program is in the habit of blue-screening the machine. You should then also be very un-interested in the drive sector size. Because the only way you can take advantage of that knowledge is to buffer log data. Buffering is the last thing you want to do if you also use Flush().

Upvotes: 3

Related Questions