|
A function to compress a file by utilising NTFS's compression feature. Open CompressNTFS.c CompressNTFS.c:
#include <windows.h>
BOOL CompressFileNTFSEx (const TCHAR *tcFileName, USHORT usState)
{ // Compress or uncompress the given file.
//
// usState can be:
// 0 = COMPRESSION_FORMAT_NONE
// 1 = COMPRESSION_FORMAT_DEFAULT
// 2 = COMPRESSION_FORMAT_LZNT1
//
// Returns TRUE if successful, FALSE if an error occurred.
//
HANDLE hFile;
DWORD dwBytesReturned;
BOOL bResult;
//return FALSE;
hFile = CreateFile (tcFileName,
GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_DELETE + FILE_SHARE_READ + FILE_SHARE_WRITE,
NULL,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL + FILE_FLAG_SEQUENTIAL_SCAN,
NULL);
if (hFile == INVALID_HANDLE_VALUE)
return FALSE;
bResult = DeviceIoControl (hFile, // Handle to file or directory
FSCTL_SET_COMPRESSION, // dwIoControlCode
&usState, // Input buffer
sizeof (USHORT), // Size of input buffer
NULL, // lpOutBuffer
0, // nOutBufferSize
&dwBytesReturned, // Number of bytes returned
NULL // OVERLAPPED structure
);
if (!CloseHandle (hFile))
return FALSE;
return (bResult);
}
BOOL CompressFileNTFS (const TCHAR *tcFileName)
{
return (CompressFileNTFSEx (tcFileName, COMPRESSION_FORMAT_DEFAULT));
}
BOOL UnCompressFileNTFS (const TCHAR *tcFileName)
{
return (CompressFileNTFSEx (tcFileName, COMPRESSION_FORMAT_NONE));
}
Open CompressNTFS.c Open CompressNTFS.h CompressNTFS.h:
#ifndef __Compress_NTFS_included
#define __Compress_NTFS_included
BOOL CompressFileNTFSEx (const TCHAR *tcFileName, USHORT usState);
BOOL CompressFileNTFS (const TCHAR *tcFileName);
BOOL UnCompressFileNTFS (const TCHAR *tcFileName);
#endif
Open CompressNTFS.h
|