ReactOS  0.4.11-dev-721-g95bc44e
recv.cpp
Go to the documentation of this file.
1 /* Copyright (c) Mark Harmstone 2017
2  *
3  * This file is part of WinBtrfs.
4  *
5  * WinBtrfs is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU Lesser General Public Licence as published by
7  * the Free Software Foundation, either version 3 of the Licence, or
8  * (at your option) any later version.
9  *
10  * WinBtrfs is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU Lesser General Public Licence for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public Licence
16  * along with WinBtrfs. If not, see <http://www.gnu.org/licenses/>. */
17 
18 #include "shellext.h"
19 #include <windows.h>
20 #include <strsafe.h>
21 #include <stddef.h>
22 #include <sys/stat.h>
23 #include <string>
24 #include "recv.h"
25 #include "resource.h"
26 
27 #ifndef __REACTOS__
28 #ifndef _MSC_VER
29 #include <cpuid.h>
30 #else
31 #include <intrin.h>
32 #endif
33 
34 #include <smmintrin.h>
35 #endif
36 
37 #define EA_NTACL "security.NTACL"
38 #define EA_DOSATTRIB "user.DOSATTRIB"
39 #define EA_REPARSE "user.reparse"
40 #define EA_EA "user.EA"
41 #define XATTR_USER "user."
42 
43 #ifndef __REACTOS__
45 #endif
46 
47 static const UINT32 crctable[] = {
48  0x00000000, 0xf26b8303, 0xe13b70f7, 0x1350f3f4, 0xc79a971f, 0x35f1141c, 0x26a1e7e8, 0xd4ca64eb,
49  0x8ad958cf, 0x78b2dbcc, 0x6be22838, 0x9989ab3b, 0x4d43cfd0, 0xbf284cd3, 0xac78bf27, 0x5e133c24,
50  0x105ec76f, 0xe235446c, 0xf165b798, 0x030e349b, 0xd7c45070, 0x25afd373, 0x36ff2087, 0xc494a384,
51  0x9a879fa0, 0x68ec1ca3, 0x7bbcef57, 0x89d76c54, 0x5d1d08bf, 0xaf768bbc, 0xbc267848, 0x4e4dfb4b,
52  0x20bd8ede, 0xd2d60ddd, 0xc186fe29, 0x33ed7d2a, 0xe72719c1, 0x154c9ac2, 0x061c6936, 0xf477ea35,
53  0xaa64d611, 0x580f5512, 0x4b5fa6e6, 0xb93425e5, 0x6dfe410e, 0x9f95c20d, 0x8cc531f9, 0x7eaeb2fa,
54  0x30e349b1, 0xc288cab2, 0xd1d83946, 0x23b3ba45, 0xf779deae, 0x05125dad, 0x1642ae59, 0xe4292d5a,
55  0xba3a117e, 0x4851927d, 0x5b016189, 0xa96ae28a, 0x7da08661, 0x8fcb0562, 0x9c9bf696, 0x6ef07595,
56  0x417b1dbc, 0xb3109ebf, 0xa0406d4b, 0x522bee48, 0x86e18aa3, 0x748a09a0, 0x67dafa54, 0x95b17957,
57  0xcba24573, 0x39c9c670, 0x2a993584, 0xd8f2b687, 0x0c38d26c, 0xfe53516f, 0xed03a29b, 0x1f682198,
58  0x5125dad3, 0xa34e59d0, 0xb01eaa24, 0x42752927, 0x96bf4dcc, 0x64d4cecf, 0x77843d3b, 0x85efbe38,
59  0xdbfc821c, 0x2997011f, 0x3ac7f2eb, 0xc8ac71e8, 0x1c661503, 0xee0d9600, 0xfd5d65f4, 0x0f36e6f7,
60  0x61c69362, 0x93ad1061, 0x80fde395, 0x72966096, 0xa65c047d, 0x5437877e, 0x4767748a, 0xb50cf789,
61  0xeb1fcbad, 0x197448ae, 0x0a24bb5a, 0xf84f3859, 0x2c855cb2, 0xdeeedfb1, 0xcdbe2c45, 0x3fd5af46,
62  0x7198540d, 0x83f3d70e, 0x90a324fa, 0x62c8a7f9, 0xb602c312, 0x44694011, 0x5739b3e5, 0xa55230e6,
63  0xfb410cc2, 0x092a8fc1, 0x1a7a7c35, 0xe811ff36, 0x3cdb9bdd, 0xceb018de, 0xdde0eb2a, 0x2f8b6829,
64  0x82f63b78, 0x709db87b, 0x63cd4b8f, 0x91a6c88c, 0x456cac67, 0xb7072f64, 0xa457dc90, 0x563c5f93,
65  0x082f63b7, 0xfa44e0b4, 0xe9141340, 0x1b7f9043, 0xcfb5f4a8, 0x3dde77ab, 0x2e8e845f, 0xdce5075c,
66  0x92a8fc17, 0x60c37f14, 0x73938ce0, 0x81f80fe3, 0x55326b08, 0xa759e80b, 0xb4091bff, 0x466298fc,
67  0x1871a4d8, 0xea1a27db, 0xf94ad42f, 0x0b21572c, 0xdfeb33c7, 0x2d80b0c4, 0x3ed04330, 0xccbbc033,
68  0xa24bb5a6, 0x502036a5, 0x4370c551, 0xb11b4652, 0x65d122b9, 0x97baa1ba, 0x84ea524e, 0x7681d14d,
69  0x2892ed69, 0xdaf96e6a, 0xc9a99d9e, 0x3bc21e9d, 0xef087a76, 0x1d63f975, 0x0e330a81, 0xfc588982,
70  0xb21572c9, 0x407ef1ca, 0x532e023e, 0xa145813d, 0x758fe5d6, 0x87e466d5, 0x94b49521, 0x66df1622,
71  0x38cc2a06, 0xcaa7a905, 0xd9f75af1, 0x2b9cd9f2, 0xff56bd19, 0x0d3d3e1a, 0x1e6dcdee, 0xec064eed,
72  0xc38d26c4, 0x31e6a5c7, 0x22b65633, 0xd0ddd530, 0x0417b1db, 0xf67c32d8, 0xe52cc12c, 0x1747422f,
73  0x49547e0b, 0xbb3ffd08, 0xa86f0efc, 0x5a048dff, 0x8ecee914, 0x7ca56a17, 0x6ff599e3, 0x9d9e1ae0,
74  0xd3d3e1ab, 0x21b862a8, 0x32e8915c, 0xc083125f, 0x144976b4, 0xe622f5b7, 0xf5720643, 0x07198540,
75  0x590ab964, 0xab613a67, 0xb831c993, 0x4a5a4a90, 0x9e902e7b, 0x6cfbad78, 0x7fab5e8c, 0x8dc0dd8f,
76  0xe330a81a, 0x115b2b19, 0x020bd8ed, 0xf0605bee, 0x24aa3f05, 0xd6c1bc06, 0xc5914ff2, 0x37faccf1,
77  0x69e9f0d5, 0x9b8273d6, 0x88d28022, 0x7ab90321, 0xae7367ca, 0x5c18e4c9, 0x4f48173d, 0xbd23943e,
78  0xf36e6f75, 0x0105ec76, 0x12551f82, 0xe03e9c81, 0x34f4f86a, 0xc69f7b69, 0xd5cf889d, 0x27a40b9e,
79  0x79b737ba, 0x8bdcb4b9, 0x988c474d, 0x6ae7c44e, 0xbe2da0a5, 0x4c4623a6, 0x5f16d052, 0xad7d5351,
80 };
81 
82 // HW code taken from https://github.com/rurban/smhasher/blob/master/crc32_hw.c
83 #define ALIGN_SIZE 0x08UL
84 #define ALIGN_MASK (ALIGN_SIZE - 1)
85 #define CALC_CRC(op, crc, type, buf, len) \
86 do { \
87  for (; (len) >= sizeof (type); (len) -= sizeof(type), buf += sizeof (type)) { \
88  (crc) = op((crc), *(type *) (buf)); \
89  } \
90 } while(0)
91 
92 #ifndef __REACTOS__
93 static UINT32 crc32c_hw(const void *input, ULONG len, UINT32 crc) {
94  const char* buf = (const char*)input;
95 
96  // Annoyingly, the CRC32 intrinsics don't work properly in modern versions of MSVC -
97  // it compiles _mm_crc32_u8 as if it was _mm_crc32_u32. And because we're apparently
98  // not allowed to use inline asm on amd64, there's no easy way to fix this!
99 
100  for (; (len > 0) && ((size_t)buf & ALIGN_MASK); len--, buf++) {
101 #ifdef _MSC_VER
102  crc = crctable[(crc ^ *buf) & 0xff] ^ (crc >> 8);
103 #else
104  crc = _mm_crc32_u8(crc, *buf);
105 #endif
106  }
107 
108 #ifdef _AMD64_
109 #ifdef _MSC_VER
110 #pragma warning(push)
111 #pragma warning(disable:4244) // _mm_crc32_u64 wants to return UINT64(!)
112 #pragma warning(disable:4242)
113 #endif
114  CALC_CRC(_mm_crc32_u64, crc, UINT64, buf, len);
115 #ifdef _MSC_VER
116 #pragma warning(pop)
117 #endif
118 #endif
119  CALC_CRC(_mm_crc32_u32, crc, UINT32, buf, len);
120 
121 #ifdef _MSC_VER
122  for (; len > 0; len--, buf++) {
123  crc = crctable[(crc ^ *buf) & 0xff] ^ (crc >> 8);
124  }
125 #else
126  CALC_CRC(_mm_crc32_u16, crc, UINT16, buf, len);
127  CALC_CRC(_mm_crc32_u8, crc, UINT8, buf, len);
128 #endif
129 
130  return crc;
131 }
132 #endif
133 
134 static UINT32 calc_crc32c(UINT32 seed, UINT8* msg, ULONG msglen) {
135 #ifndef __REACTOS__
136  if (have_sse42)
137  return crc32c_hw(msg, msglen, seed);
138  else {
139 #endif
140  UINT32 rem;
141  ULONG i;
142 
143  rem = seed;
144 
145  for (i = 0; i < msglen; i++) {
146  rem = crctable[(rem ^ msg[i]) & 0xff] ^ (rem >> 8);
147  }
148 
149  return rem;
150 #ifndef __REACTOS__
151  }
152 #endif
153 }
154 
156  ULONG off = 0;
157 
158  while (off < datalen) {
159  btrfs_send_tlv* tlv = (btrfs_send_tlv*)(data + off);
160  UINT8* payload = data + off + sizeof(btrfs_send_tlv);
161 
162  if (off + sizeof(btrfs_send_tlv) + tlv->length > datalen) // file is truncated
163  return FALSE;
164 
165  if (tlv->type == type) {
166  *value = payload;
167  *len = tlv->length;
168  return TRUE;
169  }
170 
171  off += sizeof(btrfs_send_tlv) + tlv->length;
172  }
173 
174  return FALSE;
175 }
176 
177 BOOL BtrfsRecv::utf8_to_utf16(HWND hwnd, char* utf8, ULONG utf8len, std::wstring* utf16) {
179  ULONG utf16len;
180  WCHAR* buf;
181 
182  Status = RtlUTF8ToUnicodeN(NULL, 0, &utf16len, utf8, utf8len);
183  if (!NT_SUCCESS(Status)) {
185  return FALSE;
186  }
187 
188  buf = (WCHAR*)malloc(utf16len + sizeof(WCHAR));
189 
190  if (!buf) {
192  return FALSE;
193  }
194 
195  Status = RtlUTF8ToUnicodeN(buf, utf16len, &utf16len, utf8, utf8len);
196  if (!NT_SUCCESS(Status)) {
198  free(buf);
199  return FALSE;
200  }
201 
202  buf[utf16len / sizeof(WCHAR)] = 0;
203 
204  *utf16 = buf;
205 
206  free(buf);
207 
208  return TRUE;
209 }
210 
212  char* name;
213  BTRFS_UUID* uuid;
214  UINT64* gen;
215  ULONG namelen, uuidlen, genlen, bcslen;
216  btrfs_create_subvol* bcs;
219  std::wstring nameu;
220 
221  if (!find_tlv(data, cmd->length, BTRFS_SEND_TLV_PATH, (void**)&name, &namelen)) {
223  return FALSE;
224  }
225 
226  if (!find_tlv(data, cmd->length, BTRFS_SEND_TLV_UUID, (void**)&uuid, &uuidlen)) {
228  return FALSE;
229  }
230 
231  if (uuidlen < sizeof(BTRFS_UUID)) {
232  ShowRecvError(IDS_RECV_SHORT_PARAM, funcname, L"uuid", uuidlen, sizeof(BTRFS_UUID));
233  return FALSE;
234  }
235 
236  if (!find_tlv(data, cmd->length, BTRFS_SEND_TLV_TRANSID, (void**)&gen, &genlen)) {
238  return FALSE;
239  }
240 
241  if (genlen < sizeof(UINT64)) {
242  ShowRecvError(IDS_RECV_SHORT_PARAM, funcname, L"transid", genlen, sizeof(UINT64));
243  return FALSE;
244  }
245 
246  this->subvol_uuid = *uuid;
247  this->stransid = *gen;
248 
249  if (!utf8_to_utf16(hwnd, name, namelen, &nameu))
250  return FALSE;
251 
252  bcslen = offsetof(btrfs_create_subvol, name[0]) + (nameu.length() * sizeof(WCHAR));
253  bcs = (btrfs_create_subvol*)malloc(bcslen);
254 
255  bcs->readonly = TRUE;
256  bcs->posix = TRUE;
257  bcs->namelen = nameu.length() * sizeof(WCHAR);
258  memcpy(bcs->name, nameu.c_str(), bcs->namelen);
259 
260  Status = NtFsControlFile(parent, NULL, NULL, NULL, &iosb, FSCTL_BTRFS_CREATE_SUBVOL, bcs, bcslen, NULL, 0);
261  if (!NT_SUCCESS(Status)) {
263  return FALSE;
264  }
265 
267  subvolpath += L"\\";
268  subvolpath += nameu;
269 
270  if (dir != INVALID_HANDLE_VALUE)
271  CloseHandle(dir);
272 
275 
278  if (master == INVALID_HANDLE_VALUE) {
280  return FALSE;
281  }
282 
283  Status = NtFsControlFile(master, NULL, NULL, NULL, &iosb, FSCTL_BTRFS_RESERVE_SUBVOL, bcs, bcslen, NULL, 0);
284  if (!NT_SUCCESS(Status)) {
286  return FALSE;
287  }
288 
292  if (dir == INVALID_HANDLE_VALUE) {
294  return FALSE;
295  }
296 
297  subvolpath += L"\\";
298 
300 
301  num_received++;
302 
303  return TRUE;
304 }
305 
306 void BtrfsRecv::add_cache_entry(BTRFS_UUID* uuid, UINT64 transid, std::wstring path) {
307  subvol_cache sc;
308 
309  sc.uuid = *uuid;
310  sc.transid = transid;
311  sc.path = path;
312 
313  cache.push_back(sc);
314 }
315 
317  char* name;
318  BTRFS_UUID *uuid, *parent_uuid;
319  UINT64 *gen, *parent_transid;
320  ULONG namelen, uuidlen, genlen, paruuidlen, partransidlen, bcslen;
324  std::wstring nameu, parpath;
325  btrfs_find_subvol bfs;
326  WCHAR parpathw[MAX_PATH], volpathw[MAX_PATH];
327  HANDLE subvol;
328 
329  if (!find_tlv(data, cmd->length, BTRFS_SEND_TLV_PATH, (void**)&name, &namelen)) {
331  return FALSE;
332  }
333 
334  if (!find_tlv(data, cmd->length, BTRFS_SEND_TLV_UUID, (void**)&uuid, &uuidlen)) {
336  return FALSE;
337  }
338 
339  if (uuidlen < sizeof(BTRFS_UUID)) {
340  ShowRecvError(IDS_RECV_SHORT_PARAM, funcname, L"uuid", uuidlen, sizeof(BTRFS_UUID));
341  return FALSE;
342  }
343 
344  if (!find_tlv(data, cmd->length, BTRFS_SEND_TLV_TRANSID, (void**)&gen, &genlen)) {
346  return FALSE;
347  }
348 
349  if (genlen < sizeof(UINT64)) {
350  ShowRecvError(IDS_RECV_SHORT_PARAM, funcname, L"transid", genlen, sizeof(UINT64));
351  return FALSE;
352  }
353 
354  if (!find_tlv(data, cmd->length, BTRFS_SEND_TLV_CLONE_UUID, (void**)&parent_uuid, &paruuidlen)) {
356  return FALSE;
357  }
358 
359  if (paruuidlen < sizeof(BTRFS_UUID)) {
360  ShowRecvError(IDS_RECV_SHORT_PARAM, funcname, L"clone_uuid", paruuidlen, sizeof(BTRFS_UUID));
361  return FALSE;
362  }
363 
364  if (!find_tlv(data, cmd->length, BTRFS_SEND_TLV_CLONE_CTRANSID, (void**)&parent_transid, &partransidlen)) {
365  ShowRecvError(IDS_RECV_MISSING_PARAM, funcname, L"clone_ctransid");
366  return FALSE;
367  }
368 
369  if (partransidlen < sizeof(UINT64)) {
370  ShowRecvError(IDS_RECV_SHORT_PARAM, funcname, L"clone_ctransid", partransidlen, sizeof(UINT64));
371  return FALSE;
372  }
373 
374  this->subvol_uuid = *uuid;
375  this->stransid = *gen;
376 
377  if (!utf8_to_utf16(hwnd, name, namelen, &nameu))
378  return FALSE;
379 
380  bfs.uuid = *parent_uuid;
381  bfs.ctransid = *parent_transid;
382 
383  Status = NtFsControlFile(parent, NULL, NULL, NULL, &iosb, FSCTL_BTRFS_FIND_SUBVOL, &bfs, sizeof(btrfs_find_subvol),
384  parpathw, sizeof(parpathw));
385  if (Status == STATUS_NOT_FOUND) {
387  return FALSE;
388  } else if (!NT_SUCCESS(Status)) {
390  return FALSE;
391  }
392 
393  if (!GetVolumePathNameW(dirpath.c_str(), volpathw, (sizeof(volpathw) / sizeof(WCHAR)) - 1)) {
395  return FALSE;
396  }
397 
398  parpath = volpathw;
399  if (parpath.substr(parpath.length() - 1) == L"\\")
400  parpath = parpath.substr(0, parpath.length() - 1);
401 
402  parpath += parpathw;
403 
406  if (subvol == INVALID_HANDLE_VALUE) {
408  return FALSE;
409  }
410 
411  bcslen = offsetof(btrfs_create_snapshot, name[0]) + (nameu.length() * sizeof(WCHAR));
412  bcs = (btrfs_create_snapshot*)malloc(bcslen);
413 
414  bcs->readonly = TRUE;
415  bcs->posix = TRUE;
416  bcs->subvol = subvol;
417  bcs->namelen = nameu.length() * sizeof(WCHAR);
418  memcpy(bcs->name, nameu.c_str(), bcs->namelen);
419 
420  Status = NtFsControlFile(parent, NULL, NULL, NULL, &iosb, FSCTL_BTRFS_CREATE_SNAPSHOT, bcs, bcslen, NULL, 0);
421  if (!NT_SUCCESS(Status)) {
423  return FALSE;
424  }
425 
427  subvolpath += L"\\";
428  subvolpath += nameu;
429 
430  if (dir != INVALID_HANDLE_VALUE)
431  CloseHandle(dir);
432 
435 
437  NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS | FILE_FLAG_POSIX_SEMANTICS, NULL);
438  if (master == INVALID_HANDLE_VALUE) {
440  return FALSE;
441  }
442 
443  Status = NtFsControlFile(master, NULL, NULL, NULL, &iosb, FSCTL_BTRFS_RESERVE_SUBVOL, bcs, bcslen, NULL, 0);
444  if (!NT_SUCCESS(Status)) {
446  return FALSE;
447  }
448 
451  NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS | FILE_FLAG_POSIX_SEMANTICS, NULL);
452  if (dir == INVALID_HANDLE_VALUE) {
454  return FALSE;
455  }
456 
457  subvolpath += L"\\";
458 
460 
461  num_received++;
462 
463  return TRUE;
464 }
465 
467  char *name, *pathlink;
468  UINT64 *inode, *rdev = NULL, *mode = NULL;
469  ULONG namelen, inodelen, bmnsize;
472  btrfs_mknod* bmn;
473  std::wstring nameu, pathlinku;
474 
475  if (!find_tlv(data, cmd->length, BTRFS_SEND_TLV_PATH, (void**)&name, &namelen)) {
477  return FALSE;
478  }
479 
480  if (!find_tlv(data, cmd->length, BTRFS_SEND_TLV_INODE, (void**)&inode, &inodelen)) {
482  return FALSE;
483  }
484 
485  if (inodelen < sizeof(UINT64)) {
486  ShowRecvError(IDS_RECV_SHORT_PARAM, funcname, L"inode", inodelen, sizeof(UINT64));
487  return FALSE;
488  }
489 
490  if (cmd->cmd == BTRFS_SEND_CMD_MKNOD || cmd->cmd == BTRFS_SEND_CMD_MKFIFO || cmd->cmd == BTRFS_SEND_CMD_MKSOCK) {
491  ULONG rdevlen, modelen;
492 
493  if (!find_tlv(data, cmd->length, BTRFS_SEND_TLV_RDEV, (void**)&rdev, &rdevlen)) {
495  return FALSE;
496  }
497 
498  if (rdevlen < sizeof(UINT64)) {
499  ShowRecvError(IDS_RECV_SHORT_PARAM, funcname, L"rdev", rdev, sizeof(UINT64));
500  return FALSE;
501  }
502 
503  if (!find_tlv(data, cmd->length, BTRFS_SEND_TLV_MODE, (void**)&mode, &modelen)) {
505  return FALSE;
506  }
507 
508  if (modelen < sizeof(UINT64)) {
509  ShowRecvError(IDS_RECV_SHORT_PARAM, funcname, L"mode", modelen, sizeof(UINT64));
510  return FALSE;
511  }
512  } else if (cmd->cmd == BTRFS_SEND_CMD_SYMLINK) {
513  ULONG pathlinklen;
514 
515  if (!find_tlv(data, cmd->length, BTRFS_SEND_TLV_PATH_LINK, (void**)&pathlink, &pathlinklen)) {
517  return FALSE;
518  }
519 
520  if (!utf8_to_utf16(hwnd, pathlink, pathlinklen, &pathlinku))
521  return FALSE;
522  }
523 
524  if (!utf8_to_utf16(hwnd, name, namelen, &nameu))
525  return FALSE;
526 
527  bmnsize = sizeof(btrfs_mknod) - sizeof(WCHAR) + (nameu.length() * sizeof(WCHAR));
528  bmn = (btrfs_mknod*)malloc(bmnsize);
529 
530  bmn->inode = *inode;
531 
532  if (cmd->cmd == BTRFS_SEND_CMD_MKDIR)
533  bmn->type = BTRFS_TYPE_DIRECTORY;
534  else if (cmd->cmd == BTRFS_SEND_CMD_MKNOD)
536  else if (cmd->cmd == BTRFS_SEND_CMD_MKFIFO)
537  bmn->type = BTRFS_TYPE_FIFO;
538  else if (cmd->cmd == BTRFS_SEND_CMD_MKSOCK)
539  bmn->type = BTRFS_TYPE_SOCKET;
540  else
541  bmn->type = BTRFS_TYPE_FILE;
542 
543  bmn->st_rdev = rdev ? *rdev : 0;
544  bmn->namelen = nameu.length() * sizeof(WCHAR);
545  memcpy(bmn->name, nameu.c_str(), bmn->namelen);
546 
547  Status = NtFsControlFile(dir, NULL, NULL, NULL, &iosb, FSCTL_BTRFS_MKNOD, bmn, bmnsize, NULL, 0);
548  if (!NT_SUCCESS(Status)) {
549  ShowRecvError(IDS_RECV_MKNOD_FAILED, Status, format_ntstatus(Status).c_str());
550  free(bmn);
551  return FALSE;
552  }
553 
554  free(bmn);
555 
556  if (cmd->cmd == BTRFS_SEND_CMD_SYMLINK) {
557  HANDLE h;
558  REPARSE_DATA_BUFFER* rdb;
559  ULONG rdblen;
561 
562  rdblen = offsetof(REPARSE_DATA_BUFFER, SymbolicLinkReparseBuffer.PathBuffer[0]) + (2 * pathlinku.length() * sizeof(WCHAR));
563 
564  rdb = (REPARSE_DATA_BUFFER*)malloc(rdblen);
565 
567  rdb->ReparseDataLength = rdblen - offsetof(REPARSE_DATA_BUFFER, SymbolicLinkReparseBuffer);
568  rdb->Reserved = 0;
569  rdb->SymbolicLinkReparseBuffer.SubstituteNameOffset = 0;
570  rdb->SymbolicLinkReparseBuffer.SubstituteNameLength = pathlinku.length() * sizeof(WCHAR);
571  rdb->SymbolicLinkReparseBuffer.PrintNameOffset = pathlinku.length() * sizeof(WCHAR);
572  rdb->SymbolicLinkReparseBuffer.PrintNameLength = pathlinku.length() * sizeof(WCHAR);
574 
575  memcpy(rdb->SymbolicLinkReparseBuffer.PathBuffer, pathlinku.c_str(), rdb->SymbolicLinkReparseBuffer.SubstituteNameLength);
576  memcpy(rdb->SymbolicLinkReparseBuffer.PathBuffer + (rdb->SymbolicLinkReparseBuffer.SubstituteNameLength / sizeof(WCHAR)),
577  pathlinku.c_str(), rdb->SymbolicLinkReparseBuffer.PrintNameLength);
578 
581  if (h == INVALID_HANDLE_VALUE) {
583  free(rdb);
584  return FALSE;
585  }
586 
587  Status = NtFsControlFile(h, NULL, NULL, NULL, &iosb, FSCTL_SET_REPARSE_POINT, rdb, rdblen, NULL, 0);
588  if (!NT_SUCCESS(Status)) {
590  free(rdb);
591  CloseHandle(h);
592  return FALSE;
593  }
594 
595  free(rdb);
596 
597  memset(&bsii, 0, sizeof(btrfs_set_inode_info));
598 
599  bsii.mode_changed = TRUE;
600  bsii.st_mode = 0777;
601 
602  Status = NtFsControlFile(h, NULL, NULL, NULL, &iosb, FSCTL_BTRFS_SET_INODE_INFO, &bsii, sizeof(btrfs_set_inode_info), NULL, 0);
603  if (!NT_SUCCESS(Status)) {
605  CloseHandle(h);
606  return FALSE;
607  }
608 
609  CloseHandle(h);
610  } else if (cmd->cmd == BTRFS_SEND_CMD_MKNOD || cmd->cmd == BTRFS_SEND_CMD_MKFIFO || cmd->cmd == BTRFS_SEND_CMD_MKSOCK) {
611  UINT64* mode;
612  ULONG modelen;
613 
614  if (find_tlv(data, cmd->length, BTRFS_SEND_TLV_MODE, (void**)&mode, &modelen)) {
615  HANDLE h;
617 
618  if (modelen < sizeof(UINT64)) {
619  ShowRecvError(IDS_RECV_SHORT_PARAM, funcname, L"mode", modelen, sizeof(UINT64));
620  return FALSE;
621  }
622 
625  if (h == INVALID_HANDLE_VALUE) {
627  return FALSE;
628  }
629 
630  memset(&bsii, 0, sizeof(btrfs_set_inode_info));
631 
632  bsii.mode_changed = TRUE;
633  bsii.st_mode = *mode;
634 
635  Status = NtFsControlFile(h, NULL, NULL, NULL, &iosb, FSCTL_BTRFS_SET_INODE_INFO, &bsii, sizeof(btrfs_set_inode_info), NULL, 0);
636  if (!NT_SUCCESS(Status)) {
638  CloseHandle(h);
639  return FALSE;
640  }
641 
642  CloseHandle(h);
643  }
644  }
645 
646  return TRUE;
647 }
648 
650  char *path, *path_to;
651  ULONG path_len, path_to_len;
652  std::wstring pathu, path_tou;
653 
654  if (!find_tlv(data, cmd->length, BTRFS_SEND_TLV_PATH, (void**)&path, &path_len)) {
656  return FALSE;
657  }
658 
659  if (!find_tlv(data, cmd->length, BTRFS_SEND_TLV_PATH_TO, (void**)&path_to, &path_to_len)) {
661  return FALSE;
662  }
663 
664  if (!utf8_to_utf16(hwnd, path, path_len, &pathu))
665  return FALSE;
666 
667  if (!utf8_to_utf16(hwnd, path_to, path_to_len, &path_tou))
668  return FALSE;
669 
670  if (!MoveFileW((subvolpath + pathu).c_str(), (subvolpath + path_tou).c_str())) {
671  ShowRecvError(IDS_RECV_MOVEFILE_FAILED, pathu.c_str(), path_tou.c_str(), GetLastError(), format_message(GetLastError()).c_str());
672  return FALSE;
673  }
674 
675  return TRUE;
676 }
677 
679  char *path, *path_link;
680  ULONG path_len, path_link_len;
681  std::wstring pathu, path_linku;
682 
683  if (!find_tlv(data, cmd->length, BTRFS_SEND_TLV_PATH, (void**)&path, &path_len)) {
685  return FALSE;
686  }
687 
688  if (!find_tlv(data, cmd->length, BTRFS_SEND_TLV_PATH_LINK, (void**)&path_link, &path_link_len)) {
690  return FALSE;
691  }
692 
693  if (!utf8_to_utf16(hwnd, path, path_len, &pathu))
694  return FALSE;
695 
696  if (!utf8_to_utf16(hwnd, path_link, path_link_len, &path_linku))
697  return FALSE;
698 
699  if (!CreateHardLinkW((subvolpath + pathu).c_str(), (subvolpath + path_linku).c_str(), NULL)) {
700  ShowRecvError(IDS_RECV_CREATEHARDLINK_FAILED, pathu.c_str(), path_linku.c_str(), GetLastError(), format_message(GetLastError()).c_str());
701  return FALSE;
702  }
703 
704  return TRUE;
705 }
706 
708  char* path;
709  ULONG pathlen;
710  std::wstring pathu;
711  ULONG att;
712 
713  if (!find_tlv(data, cmd->length, BTRFS_SEND_TLV_PATH, (void**)&path, &pathlen)) {
715  return FALSE;
716  }
717 
718  if (!utf8_to_utf16(hwnd, path, pathlen, &pathu))
719  return FALSE;
720 
721  att = GetFileAttributesW((subvolpath + pathu).c_str());
722  if (att == INVALID_FILE_ATTRIBUTES) {
724  return FALSE;
725  }
726 
727  if (att & FILE_ATTRIBUTE_READONLY) {
728  if (!SetFileAttributesW((subvolpath + pathu).c_str(), att & ~FILE_ATTRIBUTE_READONLY)) {
730  return FALSE;
731  }
732  }
733 
734  if (!DeleteFileW((subvolpath + pathu).c_str())) {
736  return FALSE;
737  }
738 
739  return TRUE;
740 }
741 
743  char* path;
744  ULONG pathlen;
745  std::wstring pathu;
746  ULONG att;
747 
748  if (!find_tlv(data, cmd->length, BTRFS_SEND_TLV_PATH, (void**)&path, &pathlen)) {
750  return FALSE;
751  }
752 
753  if (!utf8_to_utf16(hwnd, path, pathlen, &pathu))
754  return FALSE;
755 
756  att = GetFileAttributesW((subvolpath + pathu).c_str());
757  if (att == INVALID_FILE_ATTRIBUTES) {
759  return FALSE;
760  }
761 
762  if (att & FILE_ATTRIBUTE_READONLY) {
763  if (!SetFileAttributesW((subvolpath + pathu).c_str(), att & ~FILE_ATTRIBUTE_READONLY)) {
765  return FALSE;
766  }
767  }
768 
769  if (!RemoveDirectoryW((subvolpath + pathu).c_str())) {
771  return FALSE;
772  }
773 
774  return TRUE;
775 }
776 
778  char *path, *xattrname;
779  UINT8* xattrdata;
780  ULONG pathlen, xattrnamelen, xattrdatalen;
781  std::wstring pathu;
782 
783  if (!find_tlv(data, cmd->length, BTRFS_SEND_TLV_PATH, (void**)&path, &pathlen)) {
785  return FALSE;
786  }
787 
788  if (!find_tlv(data, cmd->length, BTRFS_SEND_TLV_XATTR_NAME, (void**)&xattrname, &xattrnamelen)) {
790  return FALSE;
791  }
792 
793  if (!find_tlv(data, cmd->length, BTRFS_SEND_TLV_XATTR_DATA, (void**)&xattrdata, &xattrdatalen)) {
795  return FALSE;
796  }
797 
798  if (!utf8_to_utf16(hwnd, path, pathlen, &pathu))
799  return FALSE;
800 
801  if (xattrnamelen > strlen(XATTR_USER) && !memcmp(xattrname, XATTR_USER, strlen(XATTR_USER)) &&
802  (xattrnamelen != strlen(EA_DOSATTRIB) || memcmp(xattrname, EA_DOSATTRIB, xattrnamelen)) &&
803  (xattrnamelen != strlen(EA_EA) || memcmp(xattrname, EA_EA, xattrnamelen)) &&
804  (xattrnamelen != strlen(EA_REPARSE) || memcmp(xattrname, EA_REPARSE, xattrnamelen))) {
805  HANDLE h;
806  std::wstring streamname;
807  ULONG att;
808 
809  if (!utf8_to_utf16(hwnd, xattrname, xattrnamelen, &streamname))
810  return FALSE;
811 
812  att = GetFileAttributesW((subvolpath + pathu).c_str());
813  if (att == INVALID_FILE_ATTRIBUTES) {
815  return FALSE;
816  }
817 
818  if (att & FILE_ATTRIBUTE_READONLY) {
819  if (!SetFileAttributesW((subvolpath + pathu).c_str(), att & ~FILE_ATTRIBUTE_READONLY)) {
821  return FALSE;
822  }
823  }
824 
825  streamname = streamname.substr(strlen(XATTR_USER));
826 
827  h = CreateFileW((subvolpath + pathu + L":" + streamname).c_str(), GENERIC_WRITE, 0,
829  if (h == INVALID_HANDLE_VALUE) {
830  ShowRecvError(IDS_RECV_CANT_CREATE_FILE, (pathu + L":" + streamname).c_str(), GetLastError(), format_message(GetLastError()).c_str());
831  return FALSE;
832  }
833 
834  if (xattrdatalen > 0) {
835  if (!WriteFile(h, xattrdata, xattrdatalen, NULL, NULL)) {
837  CloseHandle(h);
838  return FALSE;
839  }
840  }
841 
842  CloseHandle(h);
843 
844  if (att & FILE_ATTRIBUTE_READONLY) {
845  if (!SetFileAttributesW((subvolpath + pathu).c_str(), att)) {
847  return FALSE;
848  }
849  }
850  } else {
851  HANDLE h;
854  ULONG bsxalen, perms = FILE_WRITE_ATTRIBUTES;
855  btrfs_set_xattr* bsxa;
856 
857  if (xattrnamelen == strlen(EA_NTACL) && !memcmp(xattrname, EA_NTACL, xattrnamelen))
858  perms |= WRITE_DAC | WRITE_OWNER;
859  else if (xattrnamelen == strlen(EA_EA) && !memcmp(xattrname, EA_EA, xattrnamelen))
860  perms |= FILE_WRITE_EA;
861 
862  h = CreateFileW((subvolpath + pathu).c_str(), perms, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
864  if (h == INVALID_HANDLE_VALUE) {
866  return FALSE;
867  }
868 
869  bsxalen = offsetof(btrfs_set_xattr, data[0]) + xattrnamelen + xattrdatalen;
870  bsxa = (btrfs_set_xattr*)malloc(bsxalen);
871  if (!bsxa) {
873  CloseHandle(h);
874  return FALSE;
875  }
876 
877  bsxa->namelen = xattrnamelen;
878  bsxa->valuelen = xattrdatalen;
879  memcpy(bsxa->data, xattrname, xattrnamelen);
880  memcpy(&bsxa->data[xattrnamelen], xattrdata, xattrdatalen);
881 
882  Status = NtFsControlFile(h, NULL, NULL, NULL, &iosb, FSCTL_BTRFS_SET_XATTR, bsxa, bsxalen, NULL, 0);
883  if (!NT_SUCCESS(Status)) {
884  ShowRecvError(IDS_RECV_SETXATTR_FAILED, Status, format_ntstatus(Status).c_str());
885  free(bsxa);
886  CloseHandle(h);
887  return FALSE;
888  }
889 
890  free(bsxa);
891  CloseHandle(h);
892  }
893 
894  return TRUE;
895 }
896 
898  char *path, *xattrname;
899  ULONG pathlen, xattrnamelen;
900  std::wstring pathu;
901 
902  if (!find_tlv(data, cmd->length, BTRFS_SEND_TLV_PATH, (void**)&path, &pathlen)) {
904  return FALSE;
905  }
906 
907  if (!find_tlv(data, cmd->length, BTRFS_SEND_TLV_XATTR_NAME, (void**)&xattrname, &xattrnamelen)) {
909  return FALSE;
910  }
911 
912  if (!utf8_to_utf16(hwnd, path, pathlen, &pathu))
913  return FALSE;
914 
915  if (xattrnamelen > strlen(XATTR_USER) && !memcmp(xattrname, XATTR_USER, strlen(XATTR_USER)) &&
916  (xattrnamelen != strlen(EA_DOSATTRIB) || memcmp(xattrname, EA_DOSATTRIB, xattrnamelen)) &&
917  (xattrnamelen != strlen(EA_EA) || memcmp(xattrname, EA_EA, xattrnamelen))) { // deleting stream
918  ULONG att;
919  std::wstring streamname;
920 
921  if (!utf8_to_utf16(hwnd, xattrname, xattrnamelen, &streamname))
922  return FALSE;
923 
924  streamname = streamname.substr(strlen(XATTR_USER));
925 
926  att = GetFileAttributesW((subvolpath + pathu).c_str());
927  if (att == INVALID_FILE_ATTRIBUTES) {
929  return FALSE;
930  }
931 
932  if (att & FILE_ATTRIBUTE_READONLY) {
933  if (!SetFileAttributesW((subvolpath + pathu).c_str(), att & ~FILE_ATTRIBUTE_READONLY)) {
935  return FALSE;
936  }
937  }
938 
939  if (!DeleteFileW((subvolpath + pathu + L":" + streamname).c_str())) {
940  ShowRecvError(IDS_RECV_DELETEFILE_FAILED, (pathu + L":" + streamname).c_str(), GetLastError(), format_message(GetLastError()).c_str());
941  return FALSE;
942  }
943 
944  if (att & FILE_ATTRIBUTE_READONLY) {
945  if (!SetFileAttributesW((subvolpath + pathu).c_str(), att)) {
947  return FALSE;
948  }
949  }
950  } else {
951  HANDLE h;
954  ULONG bsxalen, perms = FILE_WRITE_ATTRIBUTES;
955  btrfs_set_xattr* bsxa;
956 
957  if (xattrnamelen == strlen(EA_NTACL) && !memcmp(xattrname, EA_NTACL, xattrnamelen))
958  perms |= WRITE_DAC | WRITE_OWNER;
959  else if (xattrnamelen == strlen(EA_EA) && !memcmp(xattrname, EA_EA, xattrnamelen))
960  perms |= FILE_WRITE_EA;
961 
962  h = CreateFileW((subvolpath + pathu).c_str(), perms, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
964  if (h == INVALID_HANDLE_VALUE) {
966  return FALSE;
967  }
968 
969  bsxalen = offsetof(btrfs_set_xattr, data[0]) + xattrnamelen;
970  bsxa = (btrfs_set_xattr*)malloc(bsxalen);
971  if (!bsxa) {
973  CloseHandle(h);
974  return FALSE;
975  }
976 
977  bsxa->namelen = xattrnamelen;
978  bsxa->valuelen = 0;
979  memcpy(bsxa->data, xattrname, xattrnamelen);
980 
981  Status = NtFsControlFile(h, NULL, NULL, NULL, &iosb, FSCTL_BTRFS_SET_XATTR, bsxa, bsxalen, NULL, 0);
982  if (!NT_SUCCESS(Status)) {
983  ShowRecvError(IDS_RECV_SETXATTR_FAILED, Status, format_ntstatus(Status).c_str());
984  free(bsxa);
985  CloseHandle(h);
986  return FALSE;
987  }
988 
989  free(bsxa);
990  CloseHandle(h);
991  }
992 
993  return TRUE;
994 }
995 
997  char* path;
998  UINT64* offset;
999  UINT8* writedata;
1000  ULONG pathlen, offsetlen, datalen;
1001  std::wstring pathu;
1002  HANDLE h;
1003  LARGE_INTEGER offli;
1004 
1005  if (!find_tlv(data, cmd->length, BTRFS_SEND_TLV_PATH, (void**)&path, &pathlen)) {
1007  return FALSE;
1008  }
1009 
1010  if (!find_tlv(data, cmd->length, BTRFS_SEND_TLV_OFFSET, (void**)&offset, &offsetlen)) {
1012  return FALSE;
1013  }
1014 
1015  if (offsetlen < sizeof(UINT64)) {
1016  ShowRecvError(IDS_RECV_SHORT_PARAM, funcname, L"offset", offsetlen, sizeof(UINT64));
1017  return FALSE;
1018  }
1019 
1020  if (!find_tlv(data, cmd->length, BTRFS_SEND_TLV_DATA, (void**)&writedata, &datalen)) {
1022  return FALSE;
1023  }
1024 
1025  if (!utf8_to_utf16(hwnd, path, pathlen, &pathu))
1026  return FALSE;
1027 
1028  if (lastwritepath != pathu) {
1029  FILE_BASIC_INFO fbi;
1030 
1034  return FALSE;
1035  }
1036  }
1037 
1039 
1040  lastwriteatt = GetFileAttributesW((subvolpath + pathu).c_str());
1043  return FALSE;
1044  }
1045 
1046  if (lastwriteatt & FILE_ATTRIBUTE_READONLY) {
1047  if (!SetFileAttributesW((subvolpath + pathu).c_str(), lastwriteatt & ~FILE_ATTRIBUTE_READONLY)) {
1049  return FALSE;
1050  }
1051  }
1052 
1055  if (h == INVALID_HANDLE_VALUE) {
1057  return FALSE;
1058  }
1059 
1060  lastwritepath = pathu;
1061  lastwritefile = h;
1062 
1063  memset(&fbi, 0, sizeof(FILE_BASIC_INFO));
1064 
1065  fbi.LastWriteTime.QuadPart = -1;
1066 
1067  if (!SetFileInformationByHandle(h, FileBasicInfo, &fbi, sizeof(FILE_BASIC_INFO))) {
1069  return FALSE;
1070  }
1071  } else
1072  h = lastwritefile;
1073 
1074  offli.QuadPart = *offset;
1075 
1078  return FALSE;
1079  }
1080 
1081  if (!WriteFile(h, writedata, datalen, NULL, NULL)) {
1083  return FALSE;
1084  }
1085 
1086  return TRUE;
1087 }
1088 
1090  char *path, *clonepath;
1091  UINT64 *offset, *cloneoffset, *clonetransid, *clonelen;
1092  BTRFS_UUID* cloneuuid;
1093  ULONG i, offsetlen, pathlen, clonepathlen, cloneoffsetlen, cloneuuidlen, clonetransidlen, clonelenlen;
1094  std::wstring pathu, clonepathu, clonepar;
1095  btrfs_find_subvol bfs;
1096  NTSTATUS Status;
1098  WCHAR cloneparw[MAX_PATH];
1099  HANDLE src, dest;
1101  LARGE_INTEGER filesize;
1102  BOOL found = FALSE;
1103 
1104  if (!find_tlv(data, cmd->length, BTRFS_SEND_TLV_OFFSET, (void**)&offset, &offsetlen)) {
1106  return FALSE;
1107  }
1108 
1109  if (offsetlen < sizeof(UINT64)) {
1110  ShowRecvError(IDS_RECV_SHORT_PARAM, funcname, L"offset", offsetlen, sizeof(UINT64));
1111  return FALSE;
1112  }
1113 
1114  if (!find_tlv(data, cmd->length, BTRFS_SEND_TLV_CLONE_LENGTH, (void**)&clonelen, &clonelenlen)) {
1116  return FALSE;
1117  }
1118 
1119  if (clonelenlen < sizeof(UINT64)) {
1120  ShowRecvError(IDS_RECV_SHORT_PARAM, funcname, L"clone_len", clonelenlen, sizeof(UINT64));
1121  return FALSE;
1122  }
1123 
1124  if (!find_tlv(data, cmd->length, BTRFS_SEND_TLV_PATH, (void**)&path, &pathlen)) {
1126  return FALSE;
1127  }
1128 
1129  if (!utf8_to_utf16(hwnd, path, pathlen, &pathu))
1130  return FALSE;
1131 
1132  if (!find_tlv(data, cmd->length, BTRFS_SEND_TLV_CLONE_UUID, (void**)&cloneuuid, &cloneuuidlen)) {
1134  return FALSE;
1135  }
1136 
1137  if (cloneuuidlen < sizeof(BTRFS_UUID)) {
1138  ShowRecvError(IDS_RECV_SHORT_PARAM, funcname, L"clone_uuid", cloneuuidlen, sizeof(BTRFS_UUID));
1139  return FALSE;
1140  }
1141 
1142  if (!find_tlv(data, cmd->length, BTRFS_SEND_TLV_CLONE_CTRANSID, (void**)&clonetransid, &clonetransidlen)) {
1143  ShowRecvError(IDS_RECV_MISSING_PARAM, funcname, L"clone_ctransid");
1144  return FALSE;
1145  }
1146 
1147  if (clonetransidlen < sizeof(UINT64)) {
1148  ShowRecvError(IDS_RECV_SHORT_PARAM, funcname, L"clone_ctransid", clonetransidlen, sizeof(UINT64));
1149  return FALSE;
1150  }
1151 
1152  if (!find_tlv(data, cmd->length, BTRFS_SEND_TLV_CLONE_PATH, (void**)&clonepath, &clonepathlen)) {
1154  return FALSE;
1155  }
1156 
1157  if (!utf8_to_utf16(hwnd, clonepath, clonepathlen, &clonepathu))
1158  return FALSE;
1159 
1160  if (!find_tlv(data, cmd->length, BTRFS_SEND_TLV_CLONE_OFFSET, (void**)&cloneoffset, &cloneoffsetlen)) {
1162  return FALSE;
1163  }
1164 
1165  if (cloneoffsetlen < sizeof(UINT64)) {
1166  ShowRecvError(IDS_RECV_SHORT_PARAM, funcname, L"clone_offset", cloneoffsetlen, sizeof(UINT64));
1167  return FALSE;
1168  }
1169 
1170  for (i = 0; i < cache.size(); i++) {
1171  if (!memcmp(cloneuuid, &cache[i].uuid, sizeof(BTRFS_UUID)) && *clonetransid == cache[i].transid) {
1172  clonepar = cache[i].path;
1173  found = TRUE;
1174  break;
1175  }
1176  }
1177 
1178  if (!found) {
1179  WCHAR volpathw[MAX_PATH];
1180 
1181  bfs.uuid = *cloneuuid;
1182  bfs.ctransid = *clonetransid;
1183 
1184  Status = NtFsControlFile(dir, NULL, NULL, NULL, &iosb, FSCTL_BTRFS_FIND_SUBVOL, &bfs, sizeof(btrfs_find_subvol),
1185  cloneparw, sizeof(cloneparw));
1186  if (Status == STATUS_NOT_FOUND) {
1188  return FALSE;
1189  } else if (!NT_SUCCESS(Status)) {
1190  ShowRecvError(IDS_RECV_FIND_SUBVOL_FAILED, Status, format_ntstatus(Status).c_str());
1191  return FALSE;
1192  }
1193 
1194  if (!GetVolumePathNameW(dirpath.c_str(), volpathw, (sizeof(volpathw) / sizeof(WCHAR)) - 1)) {
1196  return FALSE;
1197  }
1198 
1199  clonepar = volpathw;
1200  if (clonepar.substr(clonepar.length() - 1) == L"\\")
1201  clonepar = clonepar.substr(0, clonepar.length() - 1);
1202 
1203  clonepar += cloneparw;
1204  clonepar += L"\\";
1205 
1206  add_cache_entry(cloneuuid, *clonetransid, clonepar);
1207  }
1208 
1209  src = CreateFileW((clonepar + clonepathu).c_str(), FILE_READ_DATA, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
1211  if (src == INVALID_HANDLE_VALUE) {
1212  ShowRecvError(IDS_RECV_CANT_OPEN_FILE, funcname, (clonepar + clonepathu).c_str(), GetLastError(), format_message(GetLastError()).c_str());
1213  return FALSE;
1214  }
1215 
1218  if (dest == INVALID_HANDLE_VALUE) {
1220  CloseHandle(src);
1221  return FALSE;
1222  }
1223 
1224  if (!GetFileSizeEx(dest, &filesize)) {
1226  CloseHandle(dest);
1227  CloseHandle(src);
1228  return FALSE;
1229  }
1230 
1231  if ((UINT64)filesize.QuadPart < *offset + *clonelen) {
1232  LARGE_INTEGER sizeli;
1233 
1234  sizeli.QuadPart = *offset + *clonelen;
1235 
1236  if (SetFilePointer(dest, sizeli.LowPart, &sizeli.HighPart, FILE_BEGIN) == INVALID_SET_FILE_POINTER) {
1238  CloseHandle(dest);
1239  CloseHandle(src);
1240  return FALSE;
1241  }
1242 
1243  if (!SetEndOfFile(dest)) {
1245  CloseHandle(dest);
1246  CloseHandle(src);
1247  return FALSE;
1248  }
1249  }
1250 
1251  ded.FileHandle = src;
1252  ded.SourceFileOffset.QuadPart = *cloneoffset;
1254  ded.ByteCount.QuadPart = *clonelen;
1255 
1256  Status = NtFsControlFile(dest, NULL, NULL, NULL, &iosb, FSCTL_DUPLICATE_EXTENTS_TO_FILE, &ded, sizeof(DUPLICATE_EXTENTS_DATA),
1257  NULL, 0);
1258  if (!NT_SUCCESS(Status)) {
1260  CloseHandle(dest);
1261  CloseHandle(src);
1262  return FALSE;
1263  }
1264 
1265  CloseHandle(dest);
1266  CloseHandle(src);
1267 
1268  return TRUE;
1269 }
1270 
1272  char* path;
1273  UINT64* size;
1274  ULONG pathlen, sizelen;
1275  std::wstring pathu;
1276  HANDLE h;
1277  LARGE_INTEGER sizeli;
1278  DWORD att;
1279 
1280  if (!find_tlv(data, cmd->length, BTRFS_SEND_TLV_PATH, (void**)&path, &pathlen)) {
1282  return FALSE;
1283  }
1284 
1285  if (!find_tlv(data, cmd->length, BTRFS_SEND_TLV_SIZE, (void**)&size, &sizelen)) {
1287  return FALSE;
1288  }
1289 
1290  if (sizelen < sizeof(UINT64)) {
1291  ShowRecvError(IDS_RECV_SHORT_PARAM, funcname, L"size", sizelen, sizeof(UINT64));
1292  return FALSE;
1293  }
1294 
1295  if (!utf8_to_utf16(hwnd, path, pathlen, &pathu))
1296  return FALSE;
1297 
1298  att = GetFileAttributesW((subvolpath + pathu).c_str());
1299  if (att == INVALID_FILE_ATTRIBUTES) {
1301  return FALSE;
1302  }
1303 
1304  if (att & FILE_ATTRIBUTE_READONLY) {
1305  if (!SetFileAttributesW((subvolpath + pathu).c_str(), att & ~FILE_ATTRIBUTE_READONLY)) {
1307  return FALSE;
1308  }
1309  }
1310 
1311  h = CreateFileW((subvolpath + pathu).c_str(), FILE_WRITE_DATA, 0, NULL, OPEN_EXISTING,
1313  if (h == INVALID_HANDLE_VALUE) {
1315  return FALSE;
1316  }
1317 
1318  sizeli.QuadPart = *size;
1319 
1320  if (SetFilePointer(h, sizeli.LowPart, &sizeli.HighPart, FILE_BEGIN) == INVALID_SET_FILE_POINTER) {
1322  CloseHandle(h);
1323  return FALSE;
1324  }
1325 
1326  if (!SetEndOfFile(h)) {
1328  CloseHandle(h);
1329  return FALSE;
1330  }
1331 
1332  CloseHandle(h);
1333 
1334  if (att & FILE_ATTRIBUTE_READONLY) {
1335  if (!SetFileAttributesW((subvolpath + pathu).c_str(), att)) {
1337  return FALSE;
1338  }
1339  }
1340 
1341  return TRUE;
1342 }
1343 
1345  HANDLE h;
1346  char* path;
1347  UINT32* mode;
1348  ULONG pathlen, modelen;
1349  std::wstring pathu;
1350  btrfs_set_inode_info bsii;
1351  NTSTATUS Status;
1353 
1354  if (!find_tlv(data, cmd->length, BTRFS_SEND_TLV_PATH, (void**)&path, &pathlen)) {
1356  return FALSE;
1357  }
1358 
1359  if (!find_tlv(data, cmd->length, BTRFS_SEND_TLV_MODE, (void**)&mode, &modelen)) {
1361  return FALSE;
1362  }
1363 
1364  if (modelen < sizeof(UINT32)) {
1365  ShowRecvError(IDS_RECV_SHORT_PARAM, funcname, L"mode", modelen, sizeof(UINT32));
1366  return FALSE;
1367  }
1368 
1369  if (!utf8_to_utf16(hwnd, path, pathlen, &pathu))
1370  return FALSE;
1371 
1372  h = CreateFileW((subvolpath + pathu).c_str(), WRITE_DAC, 0, NULL, OPEN_EXISTING,
1374  if (h == INVALID_HANDLE_VALUE) {
1376  return FALSE;
1377  }
1378 
1379  memset(&bsii, 0, sizeof(btrfs_set_inode_info));
1380 
1381  bsii.mode_changed = TRUE;
1382  bsii.st_mode = *mode;
1383 
1384  Status = NtFsControlFile(h, NULL, NULL, NULL, &iosb, FSCTL_BTRFS_SET_INODE_INFO, &bsii, sizeof(btrfs_set_inode_info), NULL, 0);
1385  if (!NT_SUCCESS(Status)) {
1387  CloseHandle(h);
1388  return FALSE;
1389  }
1390 
1391  CloseHandle(h);
1392 
1393  return TRUE;
1394 }
1395 
1397  HANDLE h;
1398  char* path;
1399  UINT32 *uid, *gid;
1400  ULONG pathlen, uidlen, gidlen;
1401  std::wstring pathu;
1402  btrfs_set_inode_info bsii;
1403 
1404  if (!find_tlv(data, cmd->length, BTRFS_SEND_TLV_PATH, (void**)&path, &pathlen)) {
1406  return FALSE;
1407  }
1408 
1409  if (!utf8_to_utf16(hwnd, path, pathlen, &pathu))
1410  return FALSE;
1411 
1414  if (h == INVALID_HANDLE_VALUE) {
1416  return FALSE;
1417  }
1418 
1419  memset(&bsii, 0, sizeof(btrfs_set_inode_info));
1420 
1421  if (find_tlv(data, cmd->length, BTRFS_SEND_TLV_UID, (void**)&uid, &uidlen)) {
1422  if (uidlen < sizeof(UINT32)) {
1423  ShowRecvError(IDS_RECV_SHORT_PARAM, funcname, L"uid", uidlen, sizeof(UINT32));
1424  CloseHandle(h);
1425  return FALSE;
1426  }
1427 
1428  bsii.uid_changed = TRUE;
1429  bsii.st_uid = *uid;
1430  }
1431 
1432  if (find_tlv(data, cmd->length, BTRFS_SEND_TLV_GID, (void**)&gid, &gidlen)) {
1433  if (gidlen < sizeof(UINT32)) {
1434  ShowRecvError(IDS_RECV_SHORT_PARAM, funcname, L"gid", gidlen, sizeof(UINT32));
1435  CloseHandle(h);
1436  return FALSE;
1437  }
1438 
1439  bsii.gid_changed = TRUE;
1440  bsii.st_gid = *gid;
1441  }
1442 
1443  if (bsii.uid_changed || bsii.gid_changed) {
1444  NTSTATUS Status;
1446 
1447  Status = NtFsControlFile(h, NULL, NULL, NULL, &iosb, FSCTL_BTRFS_SET_INODE_INFO, &bsii, sizeof(btrfs_set_inode_info), NULL, 0);
1448  if (!NT_SUCCESS(Status)) {
1450  CloseHandle(h);
1451  return FALSE;
1452  }
1453  }
1454 
1455  CloseHandle(h);
1456 
1457  return TRUE;
1458 }
1459 
1461  return (t->seconds * 10000000) + (t->nanoseconds / 100) + 116444736000000000;
1462 }
1463 
1465  char* path;
1466  ULONG pathlen;
1467  std::wstring pathu;
1468  HANDLE h;
1469  FILE_BASIC_INFO fbi;
1470  BTRFS_TIME* time;
1471  ULONG timelen;
1472 
1473  if (!find_tlv(data, cmd->length, BTRFS_SEND_TLV_PATH, (void**)&path, &pathlen)) {
1475  return FALSE;
1476  }
1477 
1478  if (!utf8_to_utf16(hwnd, path, pathlen, &pathu))
1479  return FALSE;
1480 
1481  h = CreateFileW((subvolpath + pathu).c_str(), FILE_WRITE_ATTRIBUTES, 0, NULL, OPEN_EXISTING,
1483  if (h == INVALID_HANDLE_VALUE) {
1485  return FALSE;
1486  }
1487 
1488  memset(&fbi, 0, sizeof(FILE_BASIC_INFO));
1489 
1490  if (find_tlv(data, cmd->length, BTRFS_SEND_TLV_OTIME, (void**)&time, &timelen) && timelen >= sizeof(BTRFS_TIME))
1491  fbi.CreationTime.QuadPart = unix_time_to_win(time);
1492 
1493  if (find_tlv(data, cmd->length, BTRFS_SEND_TLV_ATIME, (void**)&time, &timelen) && timelen >= sizeof(BTRFS_TIME))
1494  fbi.LastAccessTime.QuadPart = unix_time_to_win(time);
1495 
1496  if (find_tlv(data, cmd->length, BTRFS_SEND_TLV_MTIME, (void**)&time, &timelen) && timelen >= sizeof(BTRFS_TIME))
1497  fbi.LastWriteTime.QuadPart = unix_time_to_win(time);
1498 
1499  if (find_tlv(data, cmd->length, BTRFS_SEND_TLV_CTIME, (void**)&time, &timelen) && timelen >= sizeof(BTRFS_TIME))
1500  fbi.ChangeTime.QuadPart = unix_time_to_win(time);
1501 
1502  if (!SetFileInformationByHandle(h, FileBasicInfo, &fbi, sizeof(FILE_BASIC_INFO))) {
1504  CloseHandle(h);
1505  return FALSE;
1506  }
1507 
1508  CloseHandle(h);
1509 
1510  return TRUE;
1511 }
1512 
1513 void BtrfsRecv::ShowRecvError(int resid, ...) {
1514  WCHAR s[1024], t[1024];
1515  va_list ap;
1516 
1517  if (!hwnd)
1518  return;
1519 
1520  if (!LoadStringW(module, resid, s, sizeof(s) / sizeof(WCHAR))) {
1522  return;
1523  }
1524 
1525  va_start(ap, resid);
1526 #ifndef __REACTOS__
1527  vswprintf(t, sizeof(t) / sizeof(WCHAR), s, ap);
1528 #else
1529  vsnwprintf(t, sizeof(t) / sizeof(WCHAR), s, ap);
1530 #endif
1531 
1533 
1534  va_end(ap);
1535 
1536  SendMessageW(GetDlgItem(hwnd, IDC_RECV_PROGRESS), PBM_SETSTATE, PBST_ERROR, 0);
1537 }
1538 
1539 static void delete_directory(std::wstring dir) {
1540  HANDLE h;
1541  WIN32_FIND_DATAW fff;
1542 
1543  h = FindFirstFileW((dir + L"*").c_str(), &fff);
1544 
1545  if (h == INVALID_HANDLE_VALUE)
1546  return;
1547 
1548  do {
1549  std::wstring file;
1550 
1551  file = fff.cFileName;
1552 
1553  if (file != L"." && file != L"..") {
1554  if (fff.dwFileAttributes & FILE_ATTRIBUTE_READONLY)
1555  SetFileAttributesW((dir + file).c_str(), fff.dwFileAttributes & ~FILE_ATTRIBUTE_READONLY);
1556 
1557  if (fff.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
1558  if (!(fff.dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT))
1559  delete_directory(dir + file + L"\\");
1560  else
1561  RemoveDirectoryW((dir + file).c_str());
1562  } else
1563  DeleteFileW((dir + file).c_str());
1564  }
1565  } while (FindNextFileW(h, &fff));
1566 
1567  FindClose(h);
1568 
1569  RemoveDirectoryW(dir.c_str());
1570 }
1571 
1573  UINT32 crc32 = cmd->csum, calc;
1574 
1575  cmd->csum = 0;
1576 
1577  calc = calc_crc32c(0, (UINT8*)cmd, sizeof(btrfs_send_command));
1578 
1579  if (cmd->length > 0)
1580  calc = calc_crc32c(calc, data, cmd->length);
1581 
1582  return calc == crc32 ? TRUE : FALSE;
1583 }
1584 
1587  BOOL b = TRUE, ended = FALSE;
1588 
1589  if (!ReadFile(f, &header, sizeof(btrfs_send_header), NULL, NULL)) {
1591  return FALSE;
1592  }
1593 
1594  *pos += sizeof(btrfs_send_header);
1595 
1596  if (memcmp(header.magic, BTRFS_SEND_MAGIC, sizeof(header.magic))) {
1598  return FALSE;
1599  }
1600 
1601  if (header.version > 1) {
1603  return FALSE;
1604  }
1605 
1607 
1609  lastwritepath = L"";
1610  lastwriteatt = 0;
1611 
1612  while (TRUE) {
1614  UINT8* data;
1615  ULONG progress;
1616 
1617  if (cancelling) {
1618  b = FALSE;
1619  break;
1620  }
1621 
1622  progress = (ULONG)((float)*pos * 65536.0f / (float)size);
1624 
1625  if (!ReadFile(f, &cmd, sizeof(btrfs_send_command), NULL, NULL)) {
1626  if (GetLastError() != ERROR_HANDLE_EOF) {
1628  break;
1629  }
1630 
1631  break;
1632  }
1633 
1634  *pos += sizeof(btrfs_send_command);
1635 
1636  if (cmd.length > 0) {
1637  if (*pos + cmd.length > size) {
1639  b = FALSE;
1640  break;
1641  }
1642 
1643  data = (UINT8*)malloc(cmd.length);
1644  if (!data) {
1646  b = FALSE;
1647  break;
1648  }
1649 
1650  if (!ReadFile(f, data, cmd.length, NULL, NULL)) {
1652  free(data);
1653  b = FALSE;
1654  break;
1655  }
1656 
1657  *pos += cmd.length;
1658  } else
1659  data = NULL;
1660 
1661  if (!check_csum(&cmd, data)) {
1663  if (data) free(data);
1664  b = FALSE;
1665  break;
1666  }
1667 
1668  if (cmd.cmd == BTRFS_SEND_CMD_END) {
1669  if (data) free(data);
1670  ended = TRUE;
1671  break;
1672  }
1673 
1678  return FALSE;
1679  }
1680  }
1681 
1683 
1685  lastwritepath = L"";
1686  lastwriteatt = 0;
1687  }
1688 
1689  switch (cmd.cmd) {
1690  case BTRFS_SEND_CMD_SUBVOL:
1691  b = cmd_subvol(hwnd, &cmd, data);
1692  break;
1693 
1695  b = cmd_snapshot(hwnd, &cmd, data);
1696  break;
1697 
1698  case BTRFS_SEND_CMD_MKFILE:
1699  case BTRFS_SEND_CMD_MKDIR:
1700  case BTRFS_SEND_CMD_MKNOD:
1701  case BTRFS_SEND_CMD_MKFIFO:
1702  case BTRFS_SEND_CMD_MKSOCK:
1704  b = cmd_mkfile(hwnd, &cmd, data);
1705  break;
1706 
1707  case BTRFS_SEND_CMD_RENAME:
1708  b = cmd_rename(hwnd, &cmd, data);
1709  break;
1710 
1711  case BTRFS_SEND_CMD_LINK:
1712  b = cmd_link(hwnd, &cmd, data);
1713  break;
1714 
1715  case BTRFS_SEND_CMD_UNLINK:
1716  b = cmd_unlink(hwnd, &cmd, data);
1717  break;
1718 
1719  case BTRFS_SEND_CMD_RMDIR:
1720  b = cmd_rmdir(hwnd, &cmd, data);
1721  break;
1722 
1724  b = cmd_setxattr(hwnd, &cmd, data);
1725  break;
1726 
1728  b = cmd_removexattr(hwnd, &cmd, data);
1729  break;
1730 
1731  case BTRFS_SEND_CMD_WRITE:
1732  b = cmd_write(hwnd, &cmd, data);
1733  break;
1734 
1735  case BTRFS_SEND_CMD_CLONE:
1736  b = cmd_clone(hwnd, &cmd, data);
1737  break;
1738 
1740  b = cmd_truncate(hwnd, &cmd, data);
1741  break;
1742 
1743  case BTRFS_SEND_CMD_CHMOD:
1744  b = cmd_chmod(hwnd, &cmd, data);
1745  break;
1746 
1747  case BTRFS_SEND_CMD_CHOWN:
1748  b = cmd_chown(hwnd, &cmd, data);
1749  break;
1750 
1751  case BTRFS_SEND_CMD_UTIMES:
1752  b = cmd_utimes(hwnd, &cmd, data);
1753  break;
1754 
1756  // does nothing
1757  break;
1758 
1759  default:
1761  b = FALSE;
1762  break;
1763  }
1764 
1765  if (data) free(data);
1766 
1767  if (!b)
1768  break;
1769  }
1770 
1775  return FALSE;
1776  }
1777  }
1778 
1780  }
1781 
1782  if (b && !ended) {
1784  b = FALSE;
1785  }
1786 
1787  if (b) {
1788  NTSTATUS Status;
1791 
1792  brs.generation = stransid;
1793  brs.uuid = subvol_uuid;
1794 
1796  NULL, 0);
1797  if (!NT_SUCCESS(Status)) {
1799  b = FALSE;
1800  }
1801  }
1802 
1803  CloseHandle(dir);
1804 
1807 
1808  if (!b && subvolpath != L"") {
1809  ULONG attrib;
1810 
1811  attrib = GetFileAttributesW(subvolpath.c_str());
1812  attrib &= ~FILE_ATTRIBUTE_READONLY;
1813 
1814  if (!SetFileAttributesW(subvolpath.c_str(), attrib))
1816  else
1818  }
1819 
1820  return b;
1821 }
1822 
1824  HANDLE f;
1826  UINT64 pos = 0;
1827  BOOL b;
1828 
1829  running = TRUE;
1830 
1831  f = CreateFileW(streamfile.c_str(), GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, NULL);
1832  if (f == INVALID_HANDLE_VALUE) {
1834  goto end;
1835  }
1836 
1837  if (!GetFileSizeEx(f, &size)) {
1839  goto end;
1840  }
1841 
1844  if (parent == INVALID_HANDLE_VALUE) {
1846  CloseHandle(f);
1847  goto end;
1848  }
1849 
1850  do {
1851  b = do_recv(f, &pos, size.QuadPart);
1852  } while (b && pos < (UINT64)size.QuadPart);
1853 
1855  CloseHandle(f);
1856 
1857  if (b && hwnd) {
1858  WCHAR s[255];
1859 
1861 
1862  if (num_received == 1) {
1863  if (!LoadStringW(module, IDS_RECV_SUCCESS, s, sizeof(s) / sizeof(WCHAR)))
1865  else
1867  } else {
1868  if (!LoadStringW(module, IDS_RECV_SUCCESS_PLURAL, s, sizeof(s) / sizeof(WCHAR)))
1870  else {
1871  WCHAR t[255];
1872 
1873  if (StringCchPrintfW(t, sizeof(t) / sizeof(WCHAR), s, num_received) == STRSAFE_E_INSUFFICIENT_BUFFER)
1875  else
1877  }
1878  }
1879 
1880  if (!LoadStringW(module, IDS_RECV_BUTTON_OK, s, sizeof(s) / sizeof(WCHAR)))
1882  else
1884  }
1885 
1886 end:
1887  thread = NULL;
1888  running = FALSE;
1889 
1890  return 0;
1891 }
1892 
1894  BtrfsRecv* br = (BtrfsRecv*)lpParameter;
1895 
1896  return br->recv_thread();
1897 }
1898 
1900  switch (uMsg) {
1901  case WM_INITDIALOG:
1902  this->hwnd = hwndDlg;
1903  thread = CreateThread(NULL, 0, global_recv_thread, this, 0, NULL);
1904 
1905  if (!thread)
1907  break;
1908 
1909  case WM_COMMAND:
1910  switch (HIWORD(wParam)) {
1911  case BN_CLICKED:
1912  switch (LOWORD(wParam)) {
1913  case IDOK:
1914  case IDCANCEL:
1915  if (running) {
1916  WCHAR s[255];
1917 
1918  cancelling = TRUE;
1919 
1920  if (!LoadStringW(module, IDS_RECV_CANCELLED, s, sizeof(s) / sizeof(WCHAR))) {
1921  ShowError(hwndDlg, GetLastError());
1922  return FALSE;
1923  }
1924 
1927 
1928  if (!LoadStringW(module, IDS_RECV_BUTTON_OK, s, sizeof(s) / sizeof(WCHAR))) {
1929  ShowError(hwndDlg, GetLastError());
1930  return FALSE;
1931  }
1932 
1934  } else
1935  EndDialog(hwndDlg, 1);
1936 
1937  return TRUE;
1938  }
1939  break;
1940  }
1941  break;
1942  }
1943 
1944  return FALSE;
1945 }
1946 
1948  BtrfsRecv* br;
1949 
1950  if (uMsg == WM_INITDIALOG) {
1951  SetWindowLongPtr(hwndDlg, GWLP_USERDATA, (LONG_PTR)lParam);
1952  br = (BtrfsRecv*)lParam;
1953  } else {
1954  br = (BtrfsRecv*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA);
1955  }
1956 
1957  if (br)
1958  return br->RecvProgressDlgProc(hwndDlg, uMsg, wParam, lParam);
1959  else
1960  return FALSE;
1961 }
1962 
1964 #ifndef __REACTOS__
1965  UINT32 cpuInfo[4];
1966 #endif
1967 
1968  streamfile = file;
1969  dirpath = path;
1970  subvolpath = L"";
1971 
1972 #ifndef __REACTOS__
1973 #ifndef _MSC_VER
1974  __get_cpuid(1, &cpuInfo[0], &cpuInfo[1], &cpuInfo[2], &cpuInfo[3]);
1975  have_sse42 = cpuInfo[2] & bit_SSE4_2;
1976 #else
1977  __cpuid((int*)cpuInfo, 1);
1978  have_sse42 = cpuInfo[2] & (1 << 20);
1979 #endif
1980 #endif
1981 
1982  if (quiet)
1983  recv_thread();
1984  else {
1986  ShowError(hwnd, GetLastError());
1987  }
1988 }
1989 
1990 #ifdef __REACTOS__
1991 extern "C" {
1992 #endif
1993 
1994 void CALLBACK RecvSubvolGUIW(HWND hwnd, HINSTANCE hinst, LPWSTR lpszCmdLine, int nCmdShow) {
1996  WCHAR file[MAX_PATH];
1997  BtrfsRecv* recv;
1998  HANDLE token;
2000  LUID luid;
2001  ULONG tplen;
2002 
2003  set_dpi_aware();
2004 
2006  ShowError(hwnd, GetLastError());
2007  return;
2008  }
2009 
2010  tplen = offsetof(TOKEN_PRIVILEGES, Privileges[0]) + (3 * sizeof(LUID_AND_ATTRIBUTES));
2011  tp = (TOKEN_PRIVILEGES*)malloc(tplen);
2012  if (!tp) {
2014  CloseHandle(token);
2015  return;
2016  }
2017 
2018  tp->PrivilegeCount = 3;
2019 
2020  if (!LookupPrivilegeValueW(NULL, L"SeManageVolumePrivilege", &luid)) {
2021  ShowError(hwnd, GetLastError());
2022  free(tp);
2023  CloseHandle(token);
2024  return;
2025  }
2026 
2027  tp->Privileges[0].Luid = luid;
2029 
2030  if (!LookupPrivilegeValueW(NULL, L"SeSecurityPrivilege", &luid)) {
2031  ShowError(hwnd, GetLastError());
2032  free(tp);
2033  CloseHandle(token);
2034  return;
2035  }
2036 
2037  tp->Privileges[1].Luid = luid;
2039 
2040  if (!LookupPrivilegeValueW(NULL, L"SeRestorePrivilege", &luid)) {
2041  ShowError(hwnd, GetLastError());
2042  free(tp);
2043  CloseHandle(token);
2044  return;
2045  }
2046 
2047  tp->Privileges[2].Luid = luid;
2049 
2050  if (!AdjustTokenPrivileges(token, FALSE, tp, tplen, NULL, NULL)) {
2051  ShowError(hwnd, GetLastError());
2052  free(tp);
2053  CloseHandle(token);
2054  return;
2055  }
2056 
2057  file[0] = 0;
2058 
2059  memset(&ofn, 0, sizeof(OPENFILENAMEW));
2060  ofn.lStructSize = sizeof(OPENFILENAMEW);
2061  ofn.hwndOwner = hwnd;
2062  ofn.hInstance = module;
2063  ofn.lpstrFile = file;
2064  ofn.nMaxFile = sizeof(file) / sizeof(WCHAR);
2066 
2067  if (GetOpenFileNameW(&ofn)) {
2068  recv = new BtrfsRecv;
2069 
2070  recv->Open(hwnd, file, lpszCmdLine, FALSE);
2071 
2072  delete recv;
2073  }
2074 
2075  free(tp);
2076  CloseHandle(token);
2077 }
2078 
2079 void CALLBACK RecvSubvolW(HWND hwnd, HINSTANCE hinst, LPWSTR lpszCmdLine, int nCmdShow) {
2080  LPWSTR* args;
2081  int num_args;
2082 
2083  args = CommandLineToArgvW(lpszCmdLine, &num_args);
2084 
2085  if (!args)
2086  return;
2087 
2088  if (num_args >= 2) {
2089  BtrfsRecv* br;
2090  HANDLE token;
2092  ULONG tplen;
2093  LUID luid;
2094 
2096  goto end;
2097 
2098  tplen = offsetof(TOKEN_PRIVILEGES, Privileges[0]) + (3 * sizeof(LUID_AND_ATTRIBUTES));
2099  tp = (TOKEN_PRIVILEGES*)malloc(tplen);
2100  if (!tp) {
2101  CloseHandle(token);
2102  goto end;
2103  }
2104 
2105  tp->PrivilegeCount = 3;
2106 
2107  if (!LookupPrivilegeValueW(NULL, L"SeManageVolumePrivilege", &luid)) {
2108  free(tp);
2109  CloseHandle(token);
2110  goto end;
2111  }
2112 
2113  tp->Privileges[0].Luid = luid;
2115 
2116  if (!LookupPrivilegeValueW(NULL, L"SeSecurityPrivilege", &luid)) {
2117  free(tp);
2118  CloseHandle(token);
2119  goto end;
2120  }
2121 
2122  tp->Privileges[1].Luid = luid;
2124 
2125  if (!LookupPrivilegeValueW(NULL, L"SeRestorePrivilege", &luid)) {
2126  free(tp);
2127  CloseHandle(token);
2128  goto end;
2129  }
2130 
2131  tp->Privileges[2].Luid = luid;
2133 
2134  if (!AdjustTokenPrivileges(token, FALSE, tp, tplen, NULL, NULL)) {
2135  free(tp);
2136  CloseHandle(token);
2137  goto end;
2138  }
2139 
2140  free(tp);
2141  CloseHandle(token);
2142 
2143  br = new BtrfsRecv;
2144  br->Open(NULL, args[0], args[1], TRUE);
2145 
2146  delete br;
2147  }
2148 
2149 end:
2150  LocalFree(args);
2151 }
2152 
2153 #ifdef __REACTOS__
2154 } /* extern "C" */
2155 #endif
#define IDS_RECV_MKNOD_FAILED
Definition: resource.h:140
BOOL WINAPI SetFileAttributesW(LPCWSTR lpFileName, DWORD dwFileAttributes)
Definition: fileinfo.c:944
#define BTRFS_SEND_TLV_OFFSET
Definition: btrfs.h:557
#define OFN_FILEMUSTEXIST
Definition: commdlg.h:106
Definition: cache.c:46
HINSTANCE hInstance
Definition: commdlg.h:362
BOOL WINAPI FindNextFileW(IN HANDLE hFindFile, OUT LPWIN32_FIND_DATAW lpFindFileData)
Definition: find.c:382
BOOL running
Definition: recv.h:88
static PIO_STATUS_BLOCK iosb
Definition: file.c:98
const DOCKBAR PVOID HWND HWND * hwnd
Definition: tooldock.h:22
#define BTRFS_SEND_CMD_LINK
Definition: btrfs.h:526
#define FILE_WRITE_EA
Definition: nt_native.h:640
DWORD Flags
Definition: commdlg.h:373
BOOL cmd_chown(HWND hwnd, btrfs_send_command *cmd, UINT8 *data)
Definition: recv.cpp:1396
ULONG num_received
Definition: recv.h:85
#define IDS_RECV_CANT_FIND_PARENT_SUBVOL
Definition: resource.h:165
#define PBM_SETRANGE32
Definition: commctrl.h:2158
Definition: get.c:139
#define IDS_RECV_FILE_TRUNCATED
Definition: resource.h:162
#define TRUE
Definition: types.h:120
BOOL cmd_chmod(HWND hwnd, btrfs_send_command *cmd, UINT8 *data)
Definition: recv.cpp:1344
std::wstring format_ntstatus(NTSTATUS Status)
Definition: main.cpp:260
#define IDOK
Definition: winuser.h:824
#define CloseHandle
Definition: compat.h:398
BOOL cmd_truncate(HWND hwnd, btrfs_send_command *cmd, UINT8 *data)
Definition: recv.cpp:1271
HMODULE module
Definition: main.cpp:46
#define INVALID_SET_FILE_POINTER
Definition: winbase.h:115
BOOL WINAPI LookupPrivilegeValueW(LPCWSTR lpSystemName, LPCWSTR lpPrivilegeName, PLUID lpLuid)
Definition: misc.c:782
void add_cache_entry(BTRFS_UUID *uuid, UINT64 transid, std::wstring path)
Definition: recv.cpp:306
#define BTRFS_SEND_TLV_UID
Definition: btrfs.h:545
INT_PTR WINAPI DialogBoxParamW(_In_opt_ HINSTANCE, _In_ LPCWSTR, _In_opt_ HWND, _In_opt_ DLGPROC, _In_ LPARAM)
#define IDS_RECV_GETFILESIZEEX_FAILED
Definition: resource.h:172
#define BTRFS_SEND_TLV_GID
Definition: btrfs.h:546
int memcmp(void *Buffer1, void *Buffer2, ACPI_SIZE Count)
Definition: utclib.c:112
BTRFS_UUID uuid
Definition: recv.h:32
UINT64 transid
Definition: recv.h:33
static BOOL check_csum(btrfs_send_command *cmd, UINT8 *data)
Definition: recv.cpp:1572
#define BTRFS_TYPE_SOCKET
Definition: shellext.h:73
Definition: recv.h:37
void CALLBACK RecvSubvolW(HWND hwnd, HINSTANCE hinst, LPWSTR lpszCmdLine, int nCmdShow)
Definition: recv.cpp:2079
#define BTRFS_SEND_TLV_PATH_TO
Definition: btrfs.h:555
#define BTRFS_SEND_TLV_DATA
Definition: btrfs.h:558
#define IDS_RECV_CANCELLED
Definition: resource.h:164
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
Definition: ftp_var.h:139
__wchar_t WCHAR
Definition: xmlstorage.h:180
GLsizei const GLchar ** path
Definition: glext.h:7234
#define BTRFS_TYPE_BLOCKDEV
Definition: shellext.h:71
#define IDS_RECV_RECEIVED_SUBVOL_FAILED
Definition: resource.h:158
#define FILE_FLAG_POSIX_SEMANTICS
Definition: disk.h:40
#define XATTR_USER
Definition: recv.cpp:41
UINT32 nanoseconds
Definition: btrfs.h:260
#define free
Definition: debug_ros.c:5
BOOL WINAPI SetEndOfFile(HANDLE hFile)
Definition: fileinfo.c:1154
#define IDS_RECV_CSUM_ERROR
Definition: resource.h:154
static void delete_directory(std::wstring dir)
Definition: recv.cpp:1539
BOOL cmd_setxattr(HWND hwnd, btrfs_send_command *cmd, UINT8 *data)
Definition: recv.cpp:777
LPWSTR lpstrFile
Definition: commdlg.h:367
UINT64 st_rdev
Definition: btrfsioctl.h:232
#define BTRFS_TYPE_FIFO
Definition: shellext.h:72
#define ALIGN_MASK
Definition: recv.cpp:84
GLintptr offset
Definition: glext.h:5920
#define CALLBACK
Definition: compat.h:27
#define IDS_RECV_SUCCESS_PLURAL
Definition: resource.h:174
struct _LUID_AND_ATTRIBUTES LUID_AND_ATTRIBUTES
UINT uMsg
Definition: precomp.h:45
#define IDS_RECV_READFILE_FAILED
Definition: resource.h:132
GLdouble GLdouble t
Definition: gl.h:2047
HANDLE HWND
Definition: compat.h:13
OPENFILENAME ofn
Definition: main.cpp:37
$ULONG PrivilegeCount
Definition: setypes.h:969
#define BTRFS_SEND_CMD_SET_XATTR
Definition: btrfs.h:529
#define IDS_RECV_SETINODEINFO_FAILED
Definition: resource.h:149
GLuint GLuint GLsizei GLenum type
Definition: gl.h:1545
#define INVALID_HANDLE_VALUE
Definition: compat.h:391
#define EA_DOSATTRIB
Definition: recv.cpp:38
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
NTSTATUS WINAPI RtlUTF8ToUnicodeN(PWSTR uni_dest, ULONG uni_bytes_max, PULONG uni_bytes_written, PCCH utf8_src, ULONG utf8_bytes)
Definition: reactos.cpp:21
#define PBM_SETPOS
Definition: commctrl.h:2154
#define IDS_RECV_CANT_FIND_CLONE_SUBVOL
Definition: resource.h:171
char * cmd
Definition: vfdcmd.c:85
#define IDS_OUT_OF_MEMORY
Definition: resource.h:63
UINT64 stransid
Definition: recv.h:86
NTSYSCALLAPI NTSTATUS NTAPI NtFsControlFile(HANDLE FileHandle, HANDLE Event, PIO_APC_ROUTINE ApcRoutine, PVOID ApcContext, PIO_STATUS_BLOCK IoStatusBlock, ULONG FsControlCode, PVOID InputBuffer, ULONG InputBufferLength, PVOID OutputBuffer, ULONG OutputBufferLength)
UINT32 crc32
Definition: btrfs.c:3862
#define BTRFS_SEND_TLV_XATTR_NAME
Definition: btrfs.h:552
BOOL WINAPI GetVolumePathNameW(IN LPCWSTR lpszFileName, IN LPWSTR lpszVolumePathName, IN DWORD cchBufferLength)
Definition: volume.c:815
GLuint GLuint end
Definition: gl.h:1545
_In_ UINT64 _In_ UINT64 _In_ UINT64 _In_opt_ traverse_ptr * tp
Definition: btrfs.c:2630
#define BTRFS_SEND_TLV_MTIME
Definition: btrfs.h:549
#define BTRFS_SEND_CMD_UPDATE_EXTENT
Definition: btrfs.h:538
__u16 time
Definition: mkdosfs.c:366
#define WRITE_OWNER
Definition: nt_native.h:60
#define FILE_SHARE_WRITE
Definition: nt_native.h:681
void ShowError(HWND hwnd, ULONG err)
Definition: main.cpp:49
#define BTRFS_TYPE_CHARDEV
Definition: shellext.h:70
int32_t INT_PTR
Definition: typedefs.h:62
BOOL cmd_snapshot(HWND hwnd, btrfs_send_command *cmd, UINT8 *data)
Definition: recv.cpp:316
#define IDS_RECV_UNKNOWN_COMMAND
Definition: resource.h:134
UINT16 type
Definition: btrfs.h:579
#define BTRFS_SEND_TLV_XATTR_DATA
Definition: btrfs.h:553
int const JOCTET unsigned int datalen
Definition: jpeglib.h:1027
#define WCHAR
Definition: msvc.h:43
GLint namelen
Definition: glext.h:7232
#define BTRFS_SEND_TLV_INODE
Definition: btrfs.h:542
BOOL cmd_rename(HWND hwnd, btrfs_send_command *cmd, UINT8 *data)
Definition: recv.cpp:649
static DWORD WINAPI global_recv_thread(LPVOID lpParameter)
Definition: recv.cpp:1893
int WINAPI LoadStringW(_In_opt_ HINSTANCE hInstance, _In_ UINT uID, _Out_writes_to_(cchBufferMax, return+1) LPWSTR lpBuffer, _In_ int cchBufferMax)
#define STRSAFE_E_INSUFFICIENT_BUFFER
Definition: strsafe.h:103
#define IDS_RECV_RTLUTF8TOUNICODEN_FAILED
Definition: resource.h:136
#define SetWindowLongPtr
Definition: treelist.c:70
BOOL WINAPI EndDialog(_In_ HWND, _In_ INT_PTR)
DWORD DWORD
Definition: winlogon.h:84
#define FILE_WRITE_ATTRIBUTES
Definition: nt_native.h:649
#define FILE_SHARE_READ
Definition: compat.h:125
DWORD lStructSize
Definition: commdlg.h:360
GLfloat GLfloat GLfloat GLfloat h
Definition: glext.h:7723
DWORD WINAPI DECLSPEC_HOTPATCH SetFilePointer(HANDLE hFile, LONG lDistanceToMove, PLONG lpDistanceToMoveHigh, DWORD dwMoveMethod)
Definition: fileinfo.c:204
UINT_PTR WPARAM
Definition: windef.h:207
void Open(HWND hwnd, WCHAR *file, WCHAR *path, BOOL quiet)
Definition: recv.cpp:1963
#define BTRFS_SEND_CMD_UTIMES
Definition: btrfs.h:536
BOOL cmd_removexattr(HWND hwnd, btrfs_send_command *cmd, UINT8 *data)
Definition: recv.cpp:897
UINT16 namelen
Definition: btrfsioctl.h:233
UINT8 type
Definition: btrfsioctl.h:231
BOOL WINAPI SetDlgItemTextW(_In_ HWND, _In_ int, _In_ LPCWSTR)
Definition: fs.h:78
#define IDS_RECV_SHORT_PARAM
Definition: resource.h:139
GLuint const GLchar * name
Definition: glext.h:6031
void ShowStringError(HWND hwndDlg, int num,...)
Definition: main.cpp:63
#define BTRFS_SEND_CMD_MKFIFO
Definition: btrfs.h:522
GLuint const GLubyte GLvoid * src
Definition: s_context.h:57
#define FILE_TRAVERSE
Definition: nt_native.h:643
WCHAR PathBuffer[1]
Definition: shellext.h:132
#define IDC_RECV_PROGRESS
Definition: resource.h:251
BOOL cancelling
Definition: recv.h:88
#define SE_PRIVILEGE_ENABLED
Definition: setypes.h:63
GLenum GLclampf GLint i
Definition: glfuncs.h:14
BTRFS_UUID subvol_uuid
Definition: recv.h:87
#define IDS_RECV_CREATETHREAD_FAILED
Definition: resource.h:161
#define va_end(ap)
Definition: acmsvcex.h:90
#define FILE_ADD_FILE
Definition: nt_native.h:632
#define EA_EA
Definition: recv.cpp:40
#define BTRFS_SEND_TLV_TRANSID
Definition: btrfs.h:541
#define FALSE
Definition: types.h:117
unsigned int UINT32
#define FSCTL_BTRFS_CREATE_SNAPSHOT
Definition: btrfsioctl.h:10
static UINT32 calc_crc32c(UINT32 seed, UINT8 *msg, ULONG msglen)
Definition: recv.cpp:134
#define IDS_RECV_UNSUPPORTED_VERSION
Definition: resource.h:156
void ShowRecvError(int resid,...)
Definition: recv.cpp:1513
#define BTRFS_SEND_CMD_SUBVOL
Definition: btrfs.h:517
LONG_PTR LPARAM
Definition: windef.h:208
DWORD WINAPI GetFileAttributesW(LPCWSTR lpFileName)
Definition: fileinfo.c:802
#define BTRFS_SEND_TLV_CLONE_PATH
Definition: btrfs.h:561
#define FILE_READ_DATA
Definition: nt_native.h:628
#define GENERIC_WRITE
Definition: nt_native.h:90
#define IDS_RECV_GETFILEATTRIBUTES_FAILED
Definition: resource.h:153
BOOL WINAPI GetOpenFileNameW(OPENFILENAMEW *ofn)
Definition: filedlg.c:4221
BOOL WINAPI MoveFileW(IN LPCWSTR lpExistingFileName, IN LPCWSTR lpNewFileName)
Definition: move.c:1044
#define BTRFS_SEND_CMD_TRUNCATE
Definition: btrfs.h:533
PIN_DIRECTION dir
Definition: strmbase.h:230
BOOL WINAPI DeleteFileW(IN LPCWSTR lpFileName)
Definition: delete.c:39
BOOL find_tlv(UINT8 *data, ULONG datalen, UINT16 type, void **value, ULONG *len)
Definition: recv.cpp:155
#define GWLP_USERDATA
Definition: treelist.c:63
LPWSTR *WINAPI CommandLineToArgvW(LPCWSTR lpCmdline, int *numargs)
Definition: shell32_main.c:76
#define BTRFS_SEND_TLV_OTIME
Definition: btrfs.h:551
#define BTRFS_TYPE_DIRECTORY
Definition: shellext.h:69
BTRFS_UUID uuid
Definition: btrfsioctl.h:256
HANDLE WINAPI DECLSPEC_HOTPATCH CreateThread(IN LPSECURITY_ATTRIBUTES lpThreadAttributes, IN DWORD dwStackSize, IN LPTHREAD_START_ROUTINE lpStartAddress, IN LPVOID lpParameter, IN DWORD dwCreationFlags, OUT LPDWORD lpThreadId)
Definition: thread.c:112
#define IDS_RECV_REMOVEDIRECTORY_FAILED
Definition: resource.h:170
smooth NULL
Definition: ftsmooth.c:416
#define offsetof(TYPE, MEMBER)
std::wstring path
Definition: recv.h:34
DWORD recv_thread()
Definition: recv.cpp:1823
char * va_list
Definition: acmsvcex.h:78
#define BTRFS_SEND_CMD_MKSOCK
Definition: btrfs.h:523
#define BTRFS_SEND_CMD_CHOWN
Definition: btrfs.h:535
std::wstring streamfile
Definition: recv.h:83
#define IDD_RECV_PROGRESS
Definition: resource.h:86
BOOL have_sse42
Definition: recv.cpp:44
BOOL WINAPI RemoveDirectoryW(IN LPCWSTR lpPathName)
Definition: dir.c:732
#define IDS_RECV_BUTTON_OK
Definition: resource.h:151
#define FILE_ATTRIBUTE_REPARSE_POINT
Definition: ntifs_ex.h:381
#define FILE_WRITE_DATA
Definition: nt_native.h:631
#define OPEN_EXISTING
Definition: compat.h:426
BOOL cmd_mkfile(HWND hwnd, btrfs_send_command *cmd, UINT8 *data)
Definition: recv.cpp:466
#define b
Definition: ke_i.h:79
#define FSCTL_BTRFS_CREATE_SUBVOL
Definition: btrfsioctl.h:9
#define FILE_ATTRIBUTE_DIRECTORY
Definition: nt_native.h:705
UINT32 length
Definition: btrfs.h:573
#define IDS_RECV_SETXATTR_FAILED
Definition: resource.h:160
#define BTRFS_SEND_TLV_SIZE
Definition: btrfs.h:543
#define IDS_RECV_SUCCESS
Definition: resource.h:150
#define BTRFS_SEND_TLV_PATH_LINK
Definition: btrfs.h:556
BOOL WINAPI WriteFile(IN HANDLE hFile, IN LPCVOID lpBuffer, IN DWORD nNumberOfBytesToWrite OPTIONAL, OUT LPDWORD lpNumberOfBytesWritten OPTIONAL, IN LPOVERLAPPED lpOverlapped OPTIONAL)
Definition: rw.c:24
#define IDS_RECV_WRITEFILE_FAILED
Definition: resource.h:144
LARGE_INTEGER SourceFileOffset
Definition: shellext.h:156
int token
Definition: lex.c:71
#define STATUS_NOT_FOUND
Definition: shellext.h:55
GLfloat f
Definition: glext.h:7540
GLboolean GLboolean GLboolean b
Definition: glext.h:6204
BOOL cmd_link(HWND hwnd, btrfs_send_command *cmd, UINT8 *data)
Definition: recv.cpp:678
unsigned int BOOL
Definition: ntddk_ex.h:94
GLsizeiptr size
Definition: glext.h:5919
LONG NTSTATUS
Definition: precomp.h:26
BOOL cmd_unlink(HWND hwnd, btrfs_send_command *cmd, UINT8 *data)
Definition: recv.cpp:707
#define IDS_RECV_SET_REPARSE_POINT_FAILED
Definition: resource.h:141
#define IDS_RECV_FIND_SUBVOL_FAILED
Definition: resource.h:166
static UINT32 crc32c_hw(const void *input, ULONG len, UINT32 crc)
Definition: recv.cpp:93
#define TOKEN_QUERY
Definition: setypes.h:874
#define BTRFS_SEND_CMD_REMOVE_XATTR
Definition: btrfs.h:530
HWND WINAPI GetDlgItem(_In_opt_ HWND, _In_ int)
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:24
#define IDS_RECV_NOT_A_SEND_STREAM
Definition: resource.h:155
HANDLE thread
Definition: recv.h:81
BOOL do_recv(HANDLE f, UINT64 *pos, UINT64 size)
Definition: recv.cpp:1585
UINT WPARAM wParam
Definition: precomp.h:45
#define EA_REPARSE
Definition: recv.cpp:39
__CRT_INLINE int __cdecl vsnwprintf(wchar_t *s, size_t n, const wchar_t *format, va_list arg)
Definition: stdio.h:930
#define FSCTL_BTRFS_RESERVE_SUBVOL
Definition: btrfsioctl.h:35
#define BTRFS_SEND_TLV_CLONE_LENGTH
Definition: btrfs.h:563
#define funcname
Definition: shellext.h:79
HANDLE WINAPI GetCurrentProcess(VOID)
Definition: proc.c:1168
#define MAX_PATH
Definition: compat.h:26
const char file[]
Definition: icontest.c:11
GLfloat CONST GLvector4f CONST GLfloat GLvector4f * dest
Definition: m_xform.h:122
static __inline UINT64 unix_time_to_win(BTRFS_TIME *t)
Definition: recv.cpp:1460
#define FILE_ATTRIBUTE_READONLY
Definition: nt_native.h:702
#define BN_CLICKED
Definition: winuser.h:1886
DWORD nMaxFile
Definition: commdlg.h:368
#define WRITE_DAC
Definition: nt_native.h:59
BOOL cmd_utimes(HWND hwnd, btrfs_send_command *cmd, UINT8 *data)
Definition: recv.cpp:1464
HANDLE lastwritefile
Definition: recv.h:81
std::wstring dirpath
Definition: recv.h:83
UINT32 version
Definition: btrfs.h:569
#define INVALID_FILE_ATTRIBUTES
Definition: vfdcmd.c:23
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
#define IDS_RECV_CREATE_SUBVOL_FAILED
Definition: resource.h:137
UINT64 inode
Definition: btrfsioctl.h:230
_In_ PSECURITY_SUBJECT_CONTEXT _In_ BOOLEAN _In_ ACCESS_MASK _In_ ACCESS_MASK _Outptr_opt_ PPRIVILEGE_SET * Privileges
Definition: sefuncs.h:13
#define IDS_RECV_DELETEFILE_FAILED
Definition: resource.h:169
HANDLE HINSTANCE
Definition: typedefs.h:75
#define BTRFS_SEND_CMD_WRITE
Definition: btrfs.h:531
#define BTRFS_SEND_TLV_PATH
Definition: btrfs.h:554
#define FSCTL_BTRFS_FIND_SUBVOL
Definition: btrfsioctl.h:36
#define GetFileSizeEx
Definition: compat.h:414
static INT_PTR CALLBACK stub_RecvProgressDlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
Definition: recv.cpp:1947
HWND hwndOwner
Definition: commdlg.h:361
#define BTRFS_SEND_TLV_RDEV
Definition: btrfs.h:547
USHORT ReparseDataLength
Definition: shellext.h:122
#define FILE_SHARE_DELETE
Definition: nt_native.h:682
#define BTRFS_SEND_CMD_CLONE
Definition: btrfs.h:532
static const WCHAR L[]
Definition: oid.c:1087
#define IDS_RECV_SETFILEPOINTER_FAILED
Definition: resource.h:143
struct tagOFNW OPENFILENAMEW
#define BTRFS_SEND_CMD_MKNOD
Definition: btrfs.h:521
#define FSCTL_BTRFS_MKNOD
Definition: btrfsioctl.h:31
#define BTRFS_SEND_TLV_CTIME
Definition: btrfs.h:548
void CALLBACK RecvSubvolGUIW(HWND hwnd, HINSTANCE hinst, LPWSTR lpszCmdLine, int nCmdShow)
Definition: recv.cpp:1994
LPVOID lpParameter
Definition: kernel32.h:232
#define FILE_ADD_SUBDIRECTORY
Definition: nt_native.h:635
ULONG LowPart
Definition: typedefs.h:104
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
#define OFN_HIDEREADONLY
Definition: commdlg.h:107
format_message(j_common_ptr cinfo, char *buffer)
Definition: jerror.c:158
GLdouble s
Definition: gl.h:2039
GLenum GLsizei len
Definition: glext.h:6722
#define GENERIC_READ
Definition: compat.h:124
struct _REPARSE_DATA_BUFFER::@308::@310 SymbolicLinkReparseBuffer
#define WM_COMMAND
Definition: winuser.h:1716
HANDLE master
Definition: recv.h:81
#define BTRFS_SEND_CMD_END
Definition: btrfs.h:537
#define FSCTL_BTRFS_SET_INODE_INFO
Definition: btrfsioctl.h:12
GLenum mode
Definition: glext.h:6217
#define BTRFS_SEND_CMD_CHMOD
Definition: btrfs.h:534
#define IDS_RECV_MISSING_PARAM
Definition: resource.h:138
#define WINAPI
Definition: msvc.h:20
#define SYMLINK_FLAG_RELATIVE
Definition: shellext.h:149
#define BTRFS_SEND_CMD_RENAME
Definition: btrfs.h:525
BOOL WINAPI AdjustTokenPrivileges(HANDLE TokenHandle, BOOL DisableAllPrivileges, PTOKEN_PRIVILEGES NewState, DWORD BufferLength, PTOKEN_PRIVILEGES PreviousState, PDWORD ReturnLength)
Definition: security.c:372
static const UINT32 crctable[]
Definition: recv.cpp:47
Status
Definition: gdiplustypes.h:24
#define BTRFS_SEND_MAGIC
Definition: btrfs.h:565
#define S_IFCHR
Definition: ext2fs.h:359
#define IDS_RECV_SETFILEINFO_FAILED
Definition: resource.h:148
INT_PTR CALLBACK RecvProgressDlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
Definition: recv.cpp:1899
#define BTRFS_SEND_TLV_CLONE_UUID
Definition: btrfs.h:559
#define IDS_RECV_CANT_CREATE_FILE
Definition: resource.h:147
#define BTRFS_SEND_TLV_MODE
Definition: btrfs.h:544
#define CREATE_ALWAYS
Definition: disk.h:72
#define FILE_BEGIN
Definition: winbase.h:112
DWORD *typedef HANDLE
Definition: winlogon.h:61
PPC_QUAL void __cpuid(int CPUInfo[], const int InfoType)
Definition: intrin_ppc.h:682
static DWORD path_len
Definition: batch.c:31
GLenum GLenum GLenum input
Definition: glext.h:9031
BOOL cmd_write(HWND hwnd, btrfs_send_command *cmd, UINT8 *data)
Definition: recv.cpp:996
DWORD lastwriteatt
Definition: recv.h:84
HLOCAL NTAPI LocalFree(HLOCAL hMem)
Definition: heapmem.c:1577
#define f
Definition: ke_i.h:83
#define IDS_RECV_DUPLICATE_EXTENTS_FAILED
Definition: resource.h:173
LRESULT WINAPI SendMessageW(_In_ HWND, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
BOOL cmd_clone(HWND hwnd, btrfs_send_command *cmd, UINT8 *data)
Definition: recv.cpp:1089
STRSAFEAPI StringCchPrintfW(STRSAFE_LPWSTR pszDest, size_t cchDest, STRSAFE_LPCWSTR pszFormat,...)
Definition: strsafe.h:530
Definition: services.c:325
#define IDS_RECV_CREATE_SNAPSHOT_FAILED
Definition: resource.h:167
__int3264 LONG_PTR
Definition: mstsclib_h.h:276
UINT WPARAM LPARAM lParam
Definition: precomp.h:45
unsigned short UINT16
#define va_start(ap, A)
Definition: acmsvcex.h:91
#define BTRFS_SEND_CMD_MKFILE
Definition: btrfs.h:519
unsigned int UINT
Definition: ndis.h:50
BOOL WINAPI OpenProcessToken(HANDLE ProcessHandle, DWORD DesiredAccess, PHANDLE TokenHandle)
Definition: security.c:292
#define BTRFS_SEND_CMD_RMDIR
Definition: btrfs.h:528
LARGE_INTEGER TargetFileOffset
Definition: shellext.h:157
#define EA_NTACL
Definition: recv.cpp:37
cd_progress_ptr progress
Definition: cdjpeg.h:150
LUID_AND_ATTRIBUTES Privileges[ANYSIZE_ARRAY]
Definition: setypes.h:970
#define CreateFileW
Definition: compat.h:400
UINT64 seconds
Definition: btrfs.h:259
#define BTRFS_TYPE_FILE
Definition: shellext.h:68
#define IDS_RECV_SETFILEATTRIBUTES_FAILED
Definition: resource.h:152
BOOL WINAPI SetFileInformationByHandle(HANDLE hFile, FILE_INFO_BY_HANDLE_CLASS FileInformationClass, LPVOID lpFileInformation, DWORD dwBufferSize)
Definition: reactos.cpp:177
#define IDS_RECV_CANT_OPEN_PATH
Definition: resource.h:135
#define FSCTL_BTRFS_RECEIVED_SUBVOL
Definition: btrfsioctl.h:32
void int int ULONGLONG int va_list * ap
Definition: winesup.h:32
#define FILE_FLAG_BACKUP_SEMANTICS
Definition: disk.h:41
WCHAR name[1]
Definition: btrfsioctl.h:234
HANDLE parent
Definition: recv.h:81
BOOL cmd_rmdir(HWND hwnd, btrfs_send_command *cmd, UINT8 *data)
Definition: recv.cpp:742
#define IDS_RECV_MOVEFILE_FAILED
Definition: resource.h:142
UINT msg
Definition: msvc.h:92
#define FSCTL_BTRFS_SET_XATTR
Definition: btrfsioctl.h:34
#define HIWORD(l)
Definition: typedefs.h:246
Definition: msctf.idl:510
#define BTRFS_SEND_CMD_MKDIR
Definition: btrfs.h:520
unsigned int ULONG
Definition: retypes.h:1
static HINSTANCE hinst
Definition: edit.c:551
#define ERROR_HANDLE_EOF
Definition: winerror.h:140
BOOL utf8_to_utf16(HWND hwnd, char *utf8, ULONG utf8len, std::wstring *utf16)
Definition: recv.cpp:177
#define malloc
Definition: debug_ros.c:4
#define BTRFS_SEND_TLV_CLONE_CTRANSID
Definition: btrfs.h:560
#define IDS_RECV_CANT_OPEN_FILE
Definition: resource.h:131
#define BTRFS_SEND_CMD_SNAPSHOT
Definition: btrfs.h:518
#define MAKEINTRESOURCEW(i)
Definition: winuser.h:582
#define FSCTL_SET_REPARSE_POINT
Definition: winioctl.h:98
std::wstring subvolpath
Definition: recv.h:83
#define GetWindowLongPtr
Definition: treelist.c:73
#define IDS_RECV_RESERVE_SUBVOL_FAILED
Definition: resource.h:163
unsigned long long UINT64
#define BTRFS_SEND_TLV_UUID
Definition: btrfs.h:540
#define IDCANCEL
Definition: winuser.h:825
#define BTRFS_SEND_CMD_UNLINK
Definition: btrfs.h:527
#define IDS_RECV_SETENDOFFILE_FAILED
Definition: resource.h:146
BOOL WINAPI ReadFile(IN HANDLE hFile, IN LPVOID lpBuffer, IN DWORD nNumberOfBytesToRead, OUT LPDWORD lpNumberOfBytesRead OPTIONAL, IN LPOVERLAPPED lpOverlapped OPTIONAL)
Definition: rw.c:123
unsigned char UINT8
calc_t calc
Definition: winmain.c:226
UINT8 magic[13]
Definition: btrfs.h:568
std::wstring lastwritepath
Definition: recv.h:83
#define memset(x, y, z)
Definition: compat.h:39
WCHAR * LPWSTR
Definition: xmlstorage.h:184
#define TOKEN_ADJUST_PRIVILEGES
Definition: setypes.h:876
#define args
Definition: format.c:66
_CRTIMP int __cdecl vswprintf(_Out_ wchar_t *, const wchar_t *, va_list)
#define IDC_RECV_MSG
Definition: resource.h:310
void set_dpi_aware()
Definition: main.cpp:111
#define FILE_OPEN_REPARSE_POINT
Definition: from_kernel.h:46
#define WM_INITDIALOG
Definition: winuser.h:1715
#define IO_REPARSE_TAG_SYMLINK
Definition: iotypes.h:6883
#define LOWORD(l)
Definition: pedump.c:82
LARGE_INTEGER ByteCount
Definition: shellext.h:158
INT WSAAPI recv(IN SOCKET s, OUT CHAR FAR *buf, IN INT len, IN INT flags)
Definition: recv.c:23
struct CFHEADER header
Definition: fdi.c:109
BOOL cmd_subvol(HWND hwnd, btrfs_send_command *cmd, UINT8 *data)
Definition: recv.cpp:211
#define BTRFS_SEND_TLV_CLONE_OFFSET
Definition: btrfs.h:562
UINT16 length
Definition: btrfs.h:580
LONGLONG QuadPart
Definition: typedefs.h:112
#define BTRFS_SEND_CMD_SYMLINK
Definition: btrfs.h:524
#define FSCTL_DUPLICATE_EXTENTS_TO_FILE
Definition: shellext.h:161
HANDLE WINAPI FindFirstFileW(IN LPCWSTR lpFileName, OUT LPWIN32_FIND_DATAW lpFindFileData)
Definition: find.c:320
#define BTRFS_SEND_TLV_ATIME
Definition: btrfs.h:550
#define IDS_RECV_CREATEHARDLINK_FAILED
Definition: resource.h:145
off
Definition: i386-dis.c:3909
Definition: fci.c:126
#define ERROR_INSUFFICIENT_BUFFER
Definition: dderror.h:10
BOOL WINAPI FindClose(HANDLE hFindFile)
Definition: find.c:502
#define IDS_RECV_GETVOLUMEPATHNAME_FAILED
Definition: resource.h:168
#define CALC_CRC(op, crc, type, buf, len)
Definition: recv.cpp:85