Error 0x32 (ERROR_NOT_SUPPORTED) from FSCTL_FILE_LEVEL_TRIM

I am trying this via DeviceIoControl() to a file and I am getting ERROR_NOT_SUPPORTED error from the API. I am using Windows 8 Developer Build. Any idea how to debug/solve this issue ?. I know the device on which the NTFS volume was created does support UNMAP. Is this supposed to work for DeveloperPreview builds ?. I did see similar post earlier but, there was no resolution for the issue in the thread. Appreciate if someone could throw some light on this.

Here is my code:

/*
#define FSCTL_FILE_LEVEL_TRIM CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 130, METHOD_BUFFERED, FILE_WRITE_DATA)

typedef struct _FILE_LEVEL_TRIM_OUTPUT {
DWORD NumRangesProccessed;
} FILE_LEVEL_TRIM_OUTPUT, *PFILE_LEVEL_TRIM_OUTPUT;

typedef struct _FILE_LEVEL_TRIM_RANGE {
DWORDLONG Offset;
DWORDLONG Length;
} FILE_LEVEL_TRIM_RANGE, *PFILE_LEVEL_TRIM_RANGE;

typedef struct _FILE_LEVEL_TRIM {
DWORD Key;
DWORD NumRanges;
FILE_LEVEL_TRIM_RANGE Ranges[1];
} FILE_LEVEL_TRIM, *PFILE_LEVEL_TRIM;
*/

FILE_LEVEL_TRIM fltIn;
FILE_LEVEL_TRIM_OUTPUT fltOut;
DWORD retVal;

ULONG lengthIn, lengthOut, bytesReturn;

lengthIn = sizeof(FILE_LEVEL_TRIM);
ZeroMemory(&fltIn,sizeof(FILE_LEVEL_TRIM));
fltIn.Key =0;
fltIn.NumRanges = 1;
fltIn.Ranges[0].Length = (DWORDLONG) length;
fltIn.Ranges[0].Offset = 0;

lengthOut = sizeof(FILE_LEVEL_TRIM_OUTPUT);
ZeroMemory(&fltOut, sizeof(FILE_LEVEL_TRIM_OUTPUT));

retVal = DeviceIoControl(hFileHandle,
FSCTL_FILE_LEVEL_TRIM,
&fltIn,
lengthIn,
&fltOut,
lengthOut,
&bytesReturn,
NULL);
if (retVal == FALSE) {
retVal = GetLastError();
return retVal;
} else {
return ERROR_SUCCESS;
}

Not all devices/adapters/drivers support TRIM. You have to either know
what is below you or allow for ‘not supported’.

Mark Roddy

On Fri, Jun 22, 2012 at 6:49 AM, wrote:
> I am trying this via DeviceIoControl() to a file and I am getting ERROR_NOT_SUPPORTED error from the API. I am using Windows 8 Developer Build. Any idea how to debug/solve this issue ?. I know the device on which the NTFS volume was created does support UNMAP. Is this supposed to work for DeveloperPreview builds ?. I did see similar post earlier but, there was no resolution for the issue in the thread. Appreciate if someone could throw some light on this.
>
> Here is my code:
>
> /*
> ? ? ? ?#define FSCTL_FILE_LEVEL_TRIM CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 130, METHOD_BUFFERED, FILE_WRITE_DATA)
>
> ? ? ? ?typedef struct _FILE_LEVEL_TRIM_OUTPUT {
> ? ? ? ? ? ? ? ?DWORD NumRangesProccessed;
> ? ? ? ?} FILE_LEVEL_TRIM_OUTPUT, *PFILE_LEVEL_TRIM_OUTPUT;
>
> ? ? ? ?typedef struct _FILE_LEVEL_TRIM_RANGE {
> ? ? ? ? ? ? ? ?DWORDLONG Offset;
> ? ? ? ? ? ? ? ?DWORDLONG Length;
> ? ? ? ?} FILE_LEVEL_TRIM_RANGE, *PFILE_LEVEL_TRIM_RANGE;
>
> ? ? ? ?typedef struct _FILE_LEVEL_TRIM {
> ? ? ? ? ? ? ? ?DWORD ? ? ? ? ? ? ? ? Key;
> ? ? ? ? ? ? ? ?DWORD ? ? ? ? ? ? ? ? NumRanges;
> ? ? ? ? ? ? ? ?FILE_LEVEL_TRIM_RANGE Ranges[1];
> ? ? ? ?} FILE_LEVEL_TRIM, *PFILE_LEVEL_TRIM;
> */
>
> ? ? ? ?FILE_LEVEL_TRIM fltIn;
> ? ? ? ?FILE_LEVEL_TRIM_OUTPUT fltOut;
> ? ? ? ?DWORD retVal;
>
> ? ? ? ?ULONG lengthIn, lengthOut, bytesReturn;
>
> ? ? ? ?lengthIn = sizeof(FILE_LEVEL_TRIM);
> ? ? ? ?ZeroMemory(&fltIn,sizeof(FILE_LEVEL_TRIM));
> ? ? ? ?fltIn.Key =0;
> ? ? ? ?fltIn.NumRanges = 1;
> ? ? ? ?fltIn.Ranges[0].Length = (DWORDLONG) length;
> ? ? ? ?fltIn.Ranges[0].Offset = 0;
>
> ? ? ? ?lengthOut = sizeof(FILE_LEVEL_TRIM_OUTPUT);
> ? ? ? ?ZeroMemory(&fltOut, sizeof(FILE_LEVEL_TRIM_OUTPUT));
>
> ? ? ? ?retVal = DeviceIoControl(hFileHandle,
> ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? FSCTL_FILE_LEVEL_TRIM,
> ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? &fltIn,
> ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? lengthIn,
> ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? &fltOut,
> ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? lengthOut,
> ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? &bytesReturn,
> ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? NULL);
> ? ? ? ?if (retVal == FALSE) {
> ? ? ? ? ? ? ? ?retVal = GetLastError();
> ? ? ? ? ? ? ? ?return retVal;
> ? ? ? ?} else {
> ? ? ? ? ? ? ? ?return ERROR_SUCCESS;
> ? ? ? ?}
>
> —
> 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

xxxxx@yahoo.com wrote:

I am trying this via DeviceIoControl() to a file and I am getting ERROR_NOT_SUPPORTED error from the API. I am using Windows 8 Developer Build. Any idea how to debug/solve this issue ?. I know the device on which the NTFS volume was created does support UNMAP. Is this supposed to work for DeveloperPreview builds ?. I did see similar post earlier but, there was no resolution for the issue in the thread.

I thought the result of the previous thread was that
FSCTL_FILE_LEVEL_TRIM was only supported on SSDs.


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