Regenerate Japanese resources
[cygwin-setup.git] / compactos.cc
blob9ed2a731ae0f4996fe7ee7fa9f7c222a06dd4599
1 //
2 // compactos.cc
3 //
4 // Copyright (C) 2021 Christian Franke
5 //
6 // SPDX-License-Identifier: MIT
7 //
9 #include "compactos.h"
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)
15 #endif
17 #ifndef WOF_CURRENT_VERSION
18 #define WOF_CURRENT_VERSION 1
20 typedef struct _WOF_EXTERNAL_INFO {
21 DWORD Version;
22 DWORD Provider;
23 } WOF_EXTERNAL_INFO;
25 #endif
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 {
32 DWORD Version;
33 DWORD Algorithm;
34 DWORD Flags;
35 } FILE_PROVIDER_EXTERNAL_INFO_V1;
37 #endif
39 #ifndef ERROR_COMPRESSION_NOT_BENEFICIAL
40 #define ERROR_COMPRESSION_NOT_BENEFICIAL 344
41 #endif
43 int CompactOsCompressFile(HANDLE h, DWORD algorithm)
45 struct {
46 WOF_EXTERNAL_INFO Wof;
47 FILE_PROVIDER_EXTERNAL_INFO_V1 FileProvider;
48 } wfp;
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)
58 return -1;
59 return 0;
62 return 1;