4 // Copyright (C) 2021 Christian Franke
6 // SPDX-License-Identifier: MIT
11 /* Not yet provided by w32api headers. */
12 #ifndef FSCTL_SET_EXTERNAL_BACKING
13 #define FSCTL_SET_EXTERNAL_BACKING \
14 CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 195, METHOD_BUFFERED, FILE_SPECIAL_ACCESS)
17 #ifndef WOF_CURRENT_VERSION
18 #define WOF_CURRENT_VERSION 1
20 typedef struct _WOF_EXTERNAL_INFO
{
27 #ifndef WOF_PROVIDER_FILE
28 #define WOF_PROVIDER_FILE 2
29 #define FILE_PROVIDER_CURRENT_VERSION 1
31 typedef struct _FILE_PROVIDER_EXTERNAL_INFO_V1
{
35 } FILE_PROVIDER_EXTERNAL_INFO_V1
;
39 #ifndef ERROR_COMPRESSION_NOT_BENEFICIAL
40 #define ERROR_COMPRESSION_NOT_BENEFICIAL 344
43 int CompactOsCompressFile(HANDLE h
, DWORD algorithm
)
46 WOF_EXTERNAL_INFO Wof
;
47 FILE_PROVIDER_EXTERNAL_INFO_V1 FileProvider
;
49 wfp
.Wof
.Version
= WOF_CURRENT_VERSION
;
50 wfp
.Wof
.Provider
= WOF_PROVIDER_FILE
;
51 wfp
.FileProvider
.Version
= FILE_PROVIDER_CURRENT_VERSION
;
52 wfp
.FileProvider
.Algorithm
= algorithm
;
53 wfp
.FileProvider
.Flags
= 0;
55 if (!DeviceIoControl(h
, FSCTL_SET_EXTERNAL_BACKING
, &wfp
, sizeof(wfp
), 0, 0, 0, 0))
57 if (GetLastError() != ERROR_COMPRESSION_NOT_BENEFICIAL
)