Share via


FSCTL_SET_COMPRESSION (Compact 2013)

3/26/2014

This I/O control sets the compression state of a file or directory on a volume whose file system supports per-file and per-directory compression. You can use this I/O control to compress or decompress a file or directory on such a volume.

Syntax

BOOL DeviceIoControl(
    HANDLE hDevice,           // handle to device
    DWORD dwIoControlCode,    // use FSCTL_SET_COMPRESSION
    LPVOID lpInBuffer,        // pointer to input buffer
    DWORD nInBufferSize,      // input buffer size
    LPVOID lpOutBuffer,       // pointer to output buffer
    DWORD nOutBufferSize,     // output buffer size
    LPDWORD lpBytesReturned,  // number of bytes returned
    OVERLAPPED lpOverlapped   // pointer to OVERLAPPED structure
);

Parameters

  • hDevice
    [in] Handle to the file, alternate stream, or directory to be compressed or decompressed. To retrieve a device handle, call the CreateFile function.
  • dwIoControlCode
    [in] Set to FSCTL_SET_COMPRESSION.
  • lpInBuf
    [in] Pointer to a buffer containing a USHORT value that specifies a new compression state for the file or directory. The following table shows possible values.

    Value

    Description

    COMPRESSION_FORMAT_DEFAULT

    Compress the file or directory, using the default compression format.

    COMPRESSION_FORMAT_LZNT1

    Compress the file or directory, using the LZNT1 compression format.

    COMPRESSION_FORMAT_NONE

    Decompress the file or directory.

  • nInBufSize
    [in] Size of the input buffer, in bytes. The buffer must be large enough to contain one USHORT value.
  • lpOutBuf
    Not used. Set to NULL.
  • nOutBufSize
    Not used. Set to NULL.
  • lpBytesReturned
    [out] Pointer to a variable that receives the size of the data stored in the output buffer, in bytes.
  • lpOverlapped
    Not used.

Return Values

If the operation succeeds, the DeviceIoControl function returns a nonzero value.

If the operation fails, DeviceIoControl returns zero. For extended error information, call GetLastError.

Remarks

LZNT1 is the only compression algorithm implemented.

If the file system of the volume that contains the specified file or directory does not support per-file or per-directory compression, the operation fails.

The compression state change of the file or directory occurs synchronously with calls to DeviceIoControl.

You can obtain the compression attribute of a file or directory with the GetFileAttributes function. The compression attribute indicates whether a file or directory is compressed. The compression state indicates whether a file or directory is compressed, and if it is, the format of the compressed data.

Directories are not compressed by this I/O control. Rather, this I/O control sets the default compression state for new files created in the directory.

Requirements

Header

fsioctl.h

See Also

Reference

FS I/O Controls
CreateFile
GetFileAttributes

Other Resources

DeviceIoControl