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
FSCTL_SET_COMPRESSION to compress or uncompress a file or directory on such a volume.
To perform this operation, call the
DeviceIoControl function with the following parameters.
|
BOOL DeviceIoControl(
(HANDLE) hDevice, // handle to file or directory
FSCTL_SET_COMPRESSION, // dwIoControlCode
(LPVOID) lpInBuffer, // input buffer
(DWORD) nInBufferSize, // size of input buffer
NULL, // lpOutBuffer
0, // nOutBufferSize
(LPDWORD) lpBytesReturned, // number of bytes returned
(LPOVERLAPPED) lpOverlapped // OVERLAPPED structure
); |
Parameters
- hDevice
A handle to the file, alternate stream, or directory to be compressed or decompressed. To retrieve a device handle, call the
CreateFile function.
The handle must have read-write access. For more information, see
File Security and Access Rights.
- dwIoControlCode
The control code for the operation. Use
FSCTL_SET_COMPRESSION for this operation.
- lpInBuffer
A pointer to a buffer containing a USHORT that specifies a new compression state for the file or directory.
This parameter can be one of the following values.
| Value | Meaning |
|
COMPRESSION_FORMAT_NONE
| Uncompress the file or directory.
|
|
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 algorithm.
|
|
all other values
| Reserved for future use.
|
- nInBufferSize
The size of the input buffer, in bytes. The buffer must be large enough to contain one USHORT value.
- lpOutBuffer
Not used with this operation; set to NULL.
- nOutBufferSize
Not used with this operation; set to zero (0).
- lpBytesReturned
A pointer to a variable that receives the size of the data stored in the output buffer, in bytes.
If lpOverlapped is NULL, lpBytesReturned cannot be NULL. Even when an operation returns no output data and lpOutBuffer is NULL,
DeviceIoControl makes use of lpBytesReturned. After such an operation, the value of lpBytesReturned is meaningless.
If lpOverlapped is not NULL, lpBytesReturned can be NULL. If this parameter is not NULL and the operation returns data, lpBytesReturned is meaningless until the overlapped operation has completed. To retrieve the number of bytes returned, call
GetOverlappedResult. If hDevice is associated with an I/O completion port, you can retrieve the number of bytes returned by calling
GetQueuedCompletionStatus.
- lpOverlapped
A pointer to an
OVERLAPPED structure.
If hDevice was opened without specifying FILE_FLAG_OVERLAPPED, lpOverlapped is ignored.
If hDevice was opened with the FILE_FLAG_OVERLAPPED flag, the operation is performed as an overlapped (asynchronous) operation. In this case, lpOverlapped must point to a valid OVERLAPPED structure that contains a handle to an event object.
Otherwise, the function fails in unpredictable ways.
For overlapped operations, DeviceIoControl returns immediately, and the event object is signaled when the operation has been completed. Otherwise, the function does not return until the operation has been completed or an error occurs.
Return Value
If the operation completes successfully,
DeviceIoControl returns a nonzero value.
If the operation fails or is pending, DeviceIoControl returns zero (0). To get extended error information, call
GetLastError.
Remarks
The LZNT1 compression algorithm is the only compression algorithm implemented. As a result, the LZNT1 compression algorithm is used as the DEFAULT compression method. Future releases may have additional compression methods which may be used as the DEFAULT.
If the file system of the volume containing 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 the call to
DeviceIoControl.
To retrieve the compression state of a file or directory, use the
FSCTL_GET_COMPRESSION control code.
To retrieve the compression attribute of a file or directory, use 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 actually compressed by this operation. Rather, the operation sets the default state for files created in the directory to be compressed.
Note that the time stamps may not be updated correctly for a remote file. To ensure consistent results, use unbuffered I/O.
File compression is supported for files of a maximum uncompressed size of 30 gigabytes.
Transacted Operations
You cannot change the compression state of a file opened with CreateFileTransacted.
For more information about transactions, see Transactional NTFS.
Requirements
| Client | Requires Windows Vista, Windows XP, or Windows 2000 Professional. |
| Server | Requires Windows Server 2008, Windows Server 2003, or Windows 2000 Server. |
|---|
| Header | Declared in WinIoCtl.h. |
See Also
DeviceIoControl
File Compression and Decompression
File Management Control Codes
FSCTL_GET_COMPRESSION
GetFileAttributes
Transactional NTFS
Send comments about this topic to Microsoft
Build date: 10/2/2008