ReactOS 0.4.15-dev-8339-g4028de8
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 <iostream>
24#include "recv.h"
25#include "resource.h"
26#include "crc32c.h"
27
28
29#ifndef _MSC_VER
30#ifdef __REACTOS__
31#define __cpuidex __cpuidex_ // prevent redeclaration
32#endif
33#include <cpuid.h>
34#else
35#include <intrin.h>
36#endif
37
38
39const string EA_NTACL = "security.NTACL";
40const string EA_DOSATTRIB = "user.DOSATTRIB";
41const string EA_REPARSE = "user.reparse";
42const string EA_EA = "user.EA";
43const string XATTR_USER = "user.";
44
46 size_t off = 0;
47
48 while (off < datalen) {
49 btrfs_send_tlv* tlv = (btrfs_send_tlv*)(data + off);
50 uint8_t* payload = data + off + sizeof(btrfs_send_tlv);
51
52 if (off + sizeof(btrfs_send_tlv) + tlv->length > datalen) // file is truncated
53 return false;
54
55 if (tlv->type == type) {
56 *value = payload;
57 *len = tlv->length;
58 return true;
59 }
60
61 off += sizeof(btrfs_send_tlv) + tlv->length;
62 }
63
64 return false;
65}
66
68 string name;
70 uint64_t* gen;
71 ULONG uuidlen, genlen;
75
76 {
77 char* namebuf;
79
80 if (!find_tlv(data, cmd->length, BTRFS_SEND_TLV_PATH, (void**)&namebuf, &namelen))
82
83 name = string(namebuf, namelen);
84 }
85
86 if (!find_tlv(data, cmd->length, BTRFS_SEND_TLV_UUID, (void**)&uuid, &uuidlen))
88
89 if (uuidlen < sizeof(BTRFS_UUID))
90 throw string_error(IDS_RECV_SHORT_PARAM, funcname, L"uuid", uuidlen, sizeof(BTRFS_UUID));
91
92 if (!find_tlv(data, cmd->length, BTRFS_SEND_TLV_TRANSID, (void**)&gen, &genlen))
94
95 if (genlen < sizeof(uint64_t))
96 throw string_error(IDS_RECV_SHORT_PARAM, funcname, L"transid", genlen, sizeof(uint64_t));
97
98 this->subvol_uuid = *uuid;
99 this->stransid = *gen;
100
101 auto nameu = utf8_to_utf16(name);
102
103 size_t bcslen = offsetof(btrfs_create_subvol, name[0]) + (nameu.length() * sizeof(WCHAR));
104 bcs = (btrfs_create_subvol*)malloc(bcslen);
105
106 bcs->readonly = true;
107 bcs->posix = true;
108 bcs->namelen = (uint16_t)(nameu.length() * sizeof(WCHAR));
109 memcpy(bcs->name, nameu.c_str(), bcs->namelen);
110
111 Status = NtFsControlFile(parent, nullptr, nullptr, nullptr, &iosb, FSCTL_BTRFS_CREATE_SUBVOL, bcs, (ULONG)bcslen, nullptr, 0);
112 if (!NT_SUCCESS(Status))
114
116 subvolpath += L"\\";
117 subvolpath += nameu;
118
121
124
129
130 Status = NtFsControlFile(master, nullptr, nullptr, nullptr, &iosb, FSCTL_BTRFS_RESERVE_SUBVOL, bcs, (ULONG)bcslen, nullptr, 0);
131 if (!NT_SUCCESS(Status))
133
139
140 subvolpath += L"\\";
141
143
144 num_received++;
145}
146
147void BtrfsRecv::add_cache_entry(BTRFS_UUID* uuid, uint64_t transid, const wstring& path) {
148 subvol_cache sc;
149
150 sc.uuid = *uuid;
151 sc.transid = transid;
152 sc.path = path;
153
154 cache.push_back(sc);
155}
156
158 string name;
159 BTRFS_UUID *uuid, *parent_uuid;
160 uint64_t *gen, *parent_transid;
161 ULONG uuidlen, genlen, paruuidlen, partransidlen;
165 wstring parpath;
167 WCHAR parpathw[MAX_PATH], volpathw[MAX_PATH];
168 size_t bcslen;
169
170 {
171 char* namebuf;
173
174 if (!find_tlv(data, cmd->length, BTRFS_SEND_TLV_PATH, (void**)&namebuf, &namelen))
176
177 name = string(namebuf, namelen);
178 }
179
180 if (!find_tlv(data, cmd->length, BTRFS_SEND_TLV_UUID, (void**)&uuid, &uuidlen))
182
183 if (uuidlen < sizeof(BTRFS_UUID))
184 throw string_error(IDS_RECV_SHORT_PARAM, funcname, L"uuid", uuidlen, sizeof(BTRFS_UUID));
185
186 if (!find_tlv(data, cmd->length, BTRFS_SEND_TLV_TRANSID, (void**)&gen, &genlen))
188
189 if (genlen < sizeof(uint64_t))
190 throw string_error(IDS_RECV_SHORT_PARAM, funcname, L"transid", genlen, sizeof(uint64_t));
191
192 if (!find_tlv(data, cmd->length, BTRFS_SEND_TLV_CLONE_UUID, (void**)&parent_uuid, &paruuidlen))
193 throw string_error(IDS_RECV_MISSING_PARAM, funcname, L"clone_uuid");
194
195 if (paruuidlen < sizeof(BTRFS_UUID))
196 throw string_error(IDS_RECV_SHORT_PARAM, funcname, L"clone_uuid", paruuidlen, sizeof(BTRFS_UUID));
197
198 if (!find_tlv(data, cmd->length, BTRFS_SEND_TLV_CLONE_CTRANSID, (void**)&parent_transid, &partransidlen))
199 throw string_error(IDS_RECV_MISSING_PARAM, funcname, L"clone_ctransid");
200
201 if (partransidlen < sizeof(uint64_t))
202 throw string_error(IDS_RECV_SHORT_PARAM, funcname, L"clone_ctransid", partransidlen, sizeof(uint64_t));
203
204 this->subvol_uuid = *uuid;
205 this->stransid = *gen;
206
207 auto nameu = utf8_to_utf16(name);
208
209 bfs.uuid = *parent_uuid;
210 bfs.ctransid = *parent_transid;
211
212 Status = NtFsControlFile(parent, nullptr, nullptr, nullptr, &iosb, FSCTL_BTRFS_FIND_SUBVOL, &bfs, sizeof(btrfs_find_subvol),
213 parpathw, sizeof(parpathw));
216 else if (!NT_SUCCESS(Status))
218
219 if (!GetVolumePathNameW(dirpath.c_str(), volpathw, (sizeof(volpathw) / sizeof(WCHAR)) - 1))
221
222 parpath = volpathw;
223 if (parpath.substr(parpath.length() - 1) == L"\\")
224 parpath = parpath.substr(0, parpath.length() - 1);
225
226 parpath += parpathw;
227
228 {
230 nullptr, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, nullptr);
231 if (subvol == INVALID_HANDLE_VALUE)
232 throw string_error(IDS_RECV_CANT_OPEN_PATH, parpath.c_str(), GetLastError(), format_message(GetLastError()).c_str());
233
234 bcslen = offsetof(btrfs_create_snapshot, name[0]) + (nameu.length() * sizeof(WCHAR));
235 bcs = (btrfs_create_snapshot*)malloc(bcslen);
236
237 bcs->readonly = true;
238 bcs->posix = true;
239 bcs->subvol = subvol;
240 bcs->namelen = (uint16_t)(nameu.length() * sizeof(WCHAR));
241 memcpy(bcs->name, nameu.c_str(), bcs->namelen);
242
243 Status = NtFsControlFile(parent, nullptr, nullptr, nullptr, &iosb, FSCTL_BTRFS_CREATE_SNAPSHOT, bcs, (ULONG)bcslen, nullptr, 0);
244 if (!NT_SUCCESS(Status))
246 }
247
249 subvolpath += L"\\";
250 subvolpath += nameu;
251
254
257
262
263 Status = NtFsControlFile(master, nullptr, nullptr, nullptr, &iosb, FSCTL_BTRFS_RESERVE_SUBVOL, bcs, (ULONG)bcslen, nullptr, 0);
264 if (!NT_SUCCESS(Status))
266
272
273 subvolpath += L"\\";
274
276
277 num_received++;
278}
279
281 uint64_t *inode, *rdev = nullptr, *mode = nullptr;
282 ULONG inodelen;
285 btrfs_mknod* bmn;
286 wstring nameu, pathlinku;
287
288 {
289 char* name;
291
292 if (!find_tlv(data, cmd->length, BTRFS_SEND_TLV_PATH, (void**)&name, &namelen))
294
295 nameu = utf8_to_utf16(string(name, namelen));
296 }
297
298 if (!find_tlv(data, cmd->length, BTRFS_SEND_TLV_INODE, (void**)&inode, &inodelen))
300
301 if (inodelen < sizeof(uint64_t))
302 throw string_error(IDS_RECV_SHORT_PARAM, funcname, L"inode", inodelen, sizeof(uint64_t));
303
305 ULONG rdevlen, modelen;
306
307 if (!find_tlv(data, cmd->length, BTRFS_SEND_TLV_RDEV, (void**)&rdev, &rdevlen))
309
310 if (rdevlen < sizeof(uint64_t))
311 throw string_error(IDS_RECV_SHORT_PARAM, funcname, L"rdev", rdev, sizeof(uint64_t));
312
313 if (!find_tlv(data, cmd->length, BTRFS_SEND_TLV_MODE, (void**)&mode, &modelen))
315
316 if (modelen < sizeof(uint64_t))
317 throw string_error(IDS_RECV_SHORT_PARAM, funcname, L"mode", modelen, sizeof(uint64_t));
318 } else if (cmd->cmd == BTRFS_SEND_CMD_SYMLINK) {
319 char* pathlink;
320 ULONG pathlinklen;
321
322 if (!find_tlv(data, cmd->length, BTRFS_SEND_TLV_PATH_LINK, (void**)&pathlink, &pathlinklen))
323 throw string_error(IDS_RECV_MISSING_PARAM, funcname, L"path_link");
324
325 pathlinku = utf8_to_utf16(string(pathlink, pathlinklen));
326 }
327
328 size_t bmnsize = sizeof(btrfs_mknod) - sizeof(WCHAR) + (nameu.length() * sizeof(WCHAR));
329 bmn = (btrfs_mknod*)malloc(bmnsize);
330
331 bmn->inode = *inode;
332
333 if (cmd->cmd == BTRFS_SEND_CMD_MKDIR)
335 else if (cmd->cmd == BTRFS_SEND_CMD_MKNOD)
337 else if (cmd->cmd == BTRFS_SEND_CMD_MKFIFO)
338 bmn->type = BTRFS_TYPE_FIFO;
339 else if (cmd->cmd == BTRFS_SEND_CMD_MKSOCK)
340 bmn->type = BTRFS_TYPE_SOCKET;
341 else
342 bmn->type = BTRFS_TYPE_FILE;
343
344 bmn->st_rdev = rdev ? *rdev : 0;
345 bmn->namelen = (uint16_t)(nameu.length() * sizeof(WCHAR));
346 memcpy(bmn->name, nameu.c_str(), bmn->namelen);
347
348 Status = NtFsControlFile(dir, nullptr, nullptr, nullptr, &iosb, FSCTL_BTRFS_MKNOD, bmn, (ULONG)bmnsize, nullptr, 0);
349 if (!NT_SUCCESS(Status)) {
350 free(bmn);
352 }
353
354 free(bmn);
355
356 if (cmd->cmd == BTRFS_SEND_CMD_SYMLINK) {
359
360 size_t rdblen = offsetof(REPARSE_DATA_BUFFER, SymbolicLinkReparseBuffer.PathBuffer[0]) + (2 * pathlinku.length() * sizeof(WCHAR));
361
362 if (rdblen >= 0x10000)
364
365 rdb = (REPARSE_DATA_BUFFER*)malloc(rdblen);
366
368 rdb->ReparseDataLength = (uint16_t)(rdblen - offsetof(REPARSE_DATA_BUFFER, SymbolicLinkReparseBuffer));
369 rdb->Reserved = 0;
370 rdb->SymbolicLinkReparseBuffer.SubstituteNameOffset = 0;
371 rdb->SymbolicLinkReparseBuffer.SubstituteNameLength = (uint16_t)(pathlinku.length() * sizeof(WCHAR));
372 rdb->SymbolicLinkReparseBuffer.PrintNameOffset = (uint16_t)(pathlinku.length() * sizeof(WCHAR));
373 rdb->SymbolicLinkReparseBuffer.PrintNameLength = (uint16_t)(pathlinku.length() * sizeof(WCHAR));
375
376 memcpy(rdb->SymbolicLinkReparseBuffer.PathBuffer, pathlinku.c_str(), rdb->SymbolicLinkReparseBuffer.SubstituteNameLength);
377 memcpy(rdb->SymbolicLinkReparseBuffer.PathBuffer + (rdb->SymbolicLinkReparseBuffer.SubstituteNameLength / sizeof(WCHAR)),
378 pathlinku.c_str(), rdb->SymbolicLinkReparseBuffer.PrintNameLength);
379
382 if (h == INVALID_HANDLE_VALUE) {
383 free(rdb);
385 }
386
387 Status = NtFsControlFile(h, nullptr, nullptr, nullptr, &iosb, FSCTL_SET_REPARSE_POINT, rdb, (ULONG)rdblen, nullptr, 0);
388 if (!NT_SUCCESS(Status)) {
389 free(rdb);
391 }
392
393 free(rdb);
394
395 memset(&bsii, 0, sizeof(btrfs_set_inode_info));
396
397 bsii.mode_changed = true;
398 bsii.st_mode = 0777;
399
400 Status = NtFsControlFile(h, nullptr, nullptr, nullptr, &iosb, FSCTL_BTRFS_SET_INODE_INFO, &bsii, sizeof(btrfs_set_inode_info), nullptr, 0);
401 if (!NT_SUCCESS(Status))
403 } else if (cmd->cmd == BTRFS_SEND_CMD_MKNOD || cmd->cmd == BTRFS_SEND_CMD_MKFIFO || cmd->cmd == BTRFS_SEND_CMD_MKSOCK) {
404 uint64_t* mode;
405 ULONG modelen;
406
407 if (find_tlv(data, cmd->length, BTRFS_SEND_TLV_MODE, (void**)&mode, &modelen)) {
409
410 if (modelen < sizeof(uint64_t))
411 throw string_error(IDS_RECV_SHORT_PARAM, funcname, L"mode", modelen, sizeof(uint64_t));
412
415 if (h == INVALID_HANDLE_VALUE)
417
418 memset(&bsii, 0, sizeof(btrfs_set_inode_info));
419
420 bsii.mode_changed = true;
421 bsii.st_mode = (uint32_t)*mode;
422
423 Status = NtFsControlFile(h, nullptr, nullptr, nullptr, &iosb, FSCTL_BTRFS_SET_INODE_INFO, &bsii, sizeof(btrfs_set_inode_info), nullptr, 0);
424 if (!NT_SUCCESS(Status))
426 }
427 }
428}
429
431 wstring pathu, path_tou;
432
433 {
434 char* path;
436
437 if (!find_tlv(data, cmd->length, BTRFS_SEND_TLV_PATH, (void**)&path, &path_len))
439
440 pathu = utf8_to_utf16(string(path, path_len));
441 }
442
443 {
444 char* path_to;
445 ULONG path_to_len;
446
447 if (!find_tlv(data, cmd->length, BTRFS_SEND_TLV_PATH_TO, (void**)&path_to, &path_to_len))
449
450 path_tou = utf8_to_utf16(string(path_to, path_to_len));
451 }
452
453 if (!MoveFileW((subvolpath + pathu).c_str(), (subvolpath + path_tou).c_str()))
454 throw string_error(IDS_RECV_MOVEFILE_FAILED, pathu.c_str(), path_tou.c_str(), GetLastError(), format_message(GetLastError()).c_str());
455}
456
458 wstring pathu, path_linku;
459
460 {
461 char* path;
463
464 if (!find_tlv(data, cmd->length, BTRFS_SEND_TLV_PATH, (void**)&path, &path_len))
466
467 pathu = utf8_to_utf16(string(path, path_len));
468 }
469
470 {
471 char* path_link;
472 ULONG path_link_len;
473
474 if (!find_tlv(data, cmd->length, BTRFS_SEND_TLV_PATH_LINK, (void**)&path_link, &path_link_len))
475 throw string_error(IDS_RECV_MISSING_PARAM, funcname, L"path_link");
476
477 path_linku = utf8_to_utf16(string(path_link, path_link_len));
478 }
479
480 if (!CreateHardLinkW((subvolpath + pathu).c_str(), (subvolpath + path_linku).c_str(), nullptr))
481 throw string_error(IDS_RECV_CREATEHARDLINK_FAILED, pathu.c_str(), path_linku.c_str(), GetLastError(), format_message(GetLastError()).c_str());
482}
483
485 wstring pathu;
486 ULONG att;
487
488 {
489 char* path;
490 ULONG pathlen;
491
492 if (!find_tlv(data, cmd->length, BTRFS_SEND_TLV_PATH, (void**)&path, &pathlen))
494
495 pathu = utf8_to_utf16(string(path, pathlen));
496 }
497
498 att = GetFileAttributesW((subvolpath + pathu).c_str());
499 if (att == INVALID_FILE_ATTRIBUTES)
501
502 if (att & FILE_ATTRIBUTE_READONLY) {
503 if (!SetFileAttributesW((subvolpath + pathu).c_str(), att & ~FILE_ATTRIBUTE_READONLY))
505 }
506
507 if (!DeleteFileW((subvolpath + pathu).c_str()))
509}
510
512 wstring pathu;
513 ULONG att;
514
515 {
516 char* path;
517 ULONG pathlen;
518
519 if (!find_tlv(data, cmd->length, BTRFS_SEND_TLV_PATH, (void**)&path, &pathlen))
521
522 pathu = utf8_to_utf16(string(path, pathlen));
523 }
524
525 att = GetFileAttributesW((subvolpath + pathu).c_str());
526 if (att == INVALID_FILE_ATTRIBUTES)
528
529 if (att & FILE_ATTRIBUTE_READONLY) {
530 if (!SetFileAttributesW((subvolpath + pathu).c_str(), att & ~FILE_ATTRIBUTE_READONLY))
532 }
533
534 if (!RemoveDirectoryW((subvolpath + pathu).c_str()))
536}
537
539 string xattrname;
540 uint8_t* xattrdata;
541 ULONG xattrdatalen;
542 wstring pathu;
543
544 {
545 char* path;
546 ULONG pathlen;
547
548 if (!find_tlv(data, cmd->length, BTRFS_SEND_TLV_PATH, (void**)&path, &pathlen))
550
551 pathu = utf8_to_utf16(string(path, pathlen));
552 }
553
554 {
555 char* xattrnamebuf;
556 ULONG xattrnamelen;
557
558 if (!find_tlv(data, cmd->length, BTRFS_SEND_TLV_XATTR_NAME, (void**)&xattrnamebuf, &xattrnamelen))
559 throw string_error(IDS_RECV_MISSING_PARAM, funcname, L"xattr_name");
560
561 xattrname = string(xattrnamebuf, xattrnamelen);
562 }
563
564 if (!find_tlv(data, cmd->length, BTRFS_SEND_TLV_XATTR_DATA, (void**)&xattrdata, &xattrdatalen))
565 throw string_error(IDS_RECV_MISSING_PARAM, funcname, L"xattr_data");
566
567 if (xattrname.length() > XATTR_USER.length() && xattrname.substr(0, XATTR_USER.length()) == XATTR_USER &&
568 xattrname != EA_DOSATTRIB && xattrname != EA_EA && xattrname != EA_REPARSE) {
569 ULONG att;
570
571 auto streamname = utf8_to_utf16(xattrname);
572
573 att = GetFileAttributesW((subvolpath + pathu).c_str());
574 if (att == INVALID_FILE_ATTRIBUTES)
576
577 if (att & FILE_ATTRIBUTE_READONLY) {
578 if (!SetFileAttributesW((subvolpath + pathu).c_str(), att & ~FILE_ATTRIBUTE_READONLY))
580 }
581
582 streamname = streamname.substr(XATTR_USER.length());
583
584 win_handle h = CreateFileW((subvolpath + pathu + L":" + streamname).c_str(), GENERIC_WRITE, 0,
585 nullptr, CREATE_ALWAYS, FILE_FLAG_POSIX_SEMANTICS, nullptr);
586 if (h == INVALID_HANDLE_VALUE)
587 throw string_error(IDS_RECV_CANT_CREATE_FILE, (pathu + L":" + streamname).c_str(), GetLastError(), format_message(GetLastError()).c_str());
588
589 if (xattrdatalen > 0) {
590 if (!WriteFile(h, xattrdata, xattrdatalen, nullptr, nullptr))
592 }
593
594 if (att & FILE_ATTRIBUTE_READONLY) {
595 if (!SetFileAttributesW((subvolpath + pathu).c_str(), att))
597 }
598 } else {
602 btrfs_set_xattr* bsxa;
603
604 if (xattrname == EA_NTACL)
605 perms |= WRITE_DAC | WRITE_OWNER;
606 else if (xattrname == EA_EA)
607 perms |= FILE_WRITE_EA;
608
611 if (h == INVALID_HANDLE_VALUE)
613
614 size_t bsxalen = offsetof(btrfs_set_xattr, data[0]) + xattrname.length() + xattrdatalen;
615 bsxa = (btrfs_set_xattr*)malloc(bsxalen);
616 if (!bsxa)
618
619 bsxa->namelen = (uint16_t)xattrname.length();
620 bsxa->valuelen = (uint16_t)xattrdatalen;
621 memcpy(bsxa->data, xattrname.c_str(), xattrname.length());
622 memcpy(&bsxa->data[xattrname.length()], xattrdata, xattrdatalen);
623
624 Status = NtFsControlFile(h, nullptr, nullptr, nullptr, &iosb, FSCTL_BTRFS_SET_XATTR, bsxa, (ULONG)bsxalen, nullptr, 0);
625 if (!NT_SUCCESS(Status)) {
626 free(bsxa);
628 }
629
630 free(bsxa);
631 }
632}
633
635 wstring pathu;
636 string xattrname;
637
638 {
639 char* path;
640 ULONG pathlen;
641
642 if (!find_tlv(data, cmd->length, BTRFS_SEND_TLV_PATH, (void**)&path, &pathlen))
644
645 pathu = utf8_to_utf16(string(path, pathlen));
646 }
647
648 {
649 char* xattrnamebuf;
650 ULONG xattrnamelen;
651
652 if (!find_tlv(data, cmd->length, BTRFS_SEND_TLV_XATTR_NAME, (void**)&xattrnamebuf, &xattrnamelen))
653 throw string_error(IDS_RECV_MISSING_PARAM, funcname, L"xattr_name");
654
655 xattrname = string(xattrnamebuf, xattrnamelen);
656 }
657
658 if (xattrname.length() > XATTR_USER.length() && xattrname.substr(0, XATTR_USER.length()) == XATTR_USER && xattrname != EA_DOSATTRIB && xattrname != EA_EA) { // deleting stream
659 ULONG att;
660
661 auto streamname = utf8_to_utf16(xattrname);
662
663 streamname = streamname.substr(XATTR_USER.length());
664
665 att = GetFileAttributesW((subvolpath + pathu).c_str());
666 if (att == INVALID_FILE_ATTRIBUTES)
668
669 if (att & FILE_ATTRIBUTE_READONLY) {
670 if (!SetFileAttributesW((subvolpath + pathu).c_str(), att & ~FILE_ATTRIBUTE_READONLY))
672 }
673
674 if (!DeleteFileW((subvolpath + pathu + L":" + streamname).c_str()))
675 throw string_error(IDS_RECV_DELETEFILE_FAILED, (pathu + L":" + streamname).c_str(), GetLastError(), format_message(GetLastError()).c_str());
676
677 if (att & FILE_ATTRIBUTE_READONLY) {
678 if (!SetFileAttributesW((subvolpath + pathu).c_str(), att))
680 }
681 } else {
685 btrfs_set_xattr* bsxa;
686
687 if (xattrname == EA_NTACL)
688 perms |= WRITE_DAC | WRITE_OWNER;
689 else if (xattrname == EA_EA)
690 perms |= FILE_WRITE_EA;
691
694 if (h == INVALID_HANDLE_VALUE)
696
697 size_t bsxalen = offsetof(btrfs_set_xattr, data[0]) + xattrname.length();
698 bsxa = (btrfs_set_xattr*)malloc(bsxalen);
699 if (!bsxa)
701
702 bsxa->namelen = (uint16_t)(xattrname.length());
703 bsxa->valuelen = 0;
704 memcpy(bsxa->data, xattrname.c_str(), xattrname.length());
705
706 Status = NtFsControlFile(h, nullptr, nullptr, nullptr, &iosb, FSCTL_BTRFS_SET_XATTR, bsxa, (ULONG)bsxalen, nullptr, 0);
707 if (!NT_SUCCESS(Status)) {
708 free(bsxa);
710 }
711
712 free(bsxa);
713 }
714}
715
718 uint8_t* writedata;
719 ULONG offsetlen, datalen;
720 wstring pathu;
721 HANDLE h;
722 LARGE_INTEGER offli;
725
726 {
727 char* path;
728 ULONG pathlen;
729
730 if (!find_tlv(data, cmd->length, BTRFS_SEND_TLV_PATH, (void**)&path, &pathlen))
732
733 pathu = utf8_to_utf16(string(path, pathlen));
734 }
735
736 if (!find_tlv(data, cmd->length, BTRFS_SEND_TLV_OFFSET, (void**)&offset, &offsetlen))
738
739 if (offsetlen < sizeof(uint64_t))
740 throw string_error(IDS_RECV_SHORT_PARAM, funcname, L"offset", offsetlen, sizeof(uint64_t));
741
742 if (!find_tlv(data, cmd->length, BTRFS_SEND_TLV_DATA, (void**)&writedata, &datalen))
744
745 if (lastwritepath != pathu) {
746 FILE_BASIC_INFO fbi;
747
751 }
752
754
755 lastwriteatt = GetFileAttributesW((subvolpath + pathu).c_str());
758
762 }
763
766 if (h == INVALID_HANDLE_VALUE)
768
769 lastwritepath = pathu;
771
772 memset(&fbi, 0, sizeof(FILE_BASIC_INFO));
773
774 fbi.LastWriteTime.QuadPart = -1;
775
776 Status = NtSetInformationFile(h, &iosb, &fbi, sizeof(FILE_BASIC_INFO), FileBasicInformation);
777 if (!NT_SUCCESS(Status))
778 throw ntstatus_error(Status);
779 } else
781
782 offli.QuadPart = *offset;
783
786
787 if (!WriteFile(h, writedata, datalen, nullptr, nullptr))
789}
790
792 uint64_t *offset, *cloneoffset, *clonetransid, *clonelen;
793 BTRFS_UUID* cloneuuid;
794 ULONG i, offsetlen, cloneoffsetlen, cloneuuidlen, clonetransidlen, clonelenlen;
795 wstring pathu, clonepathu, clonepar;
799 WCHAR cloneparw[MAX_PATH];
801 LARGE_INTEGER filesize;
802 bool found = false;
803
804 if (!find_tlv(data, cmd->length, BTRFS_SEND_TLV_OFFSET, (void**)&offset, &offsetlen))
806
807 if (offsetlen < sizeof(uint64_t))
808 throw string_error(IDS_RECV_SHORT_PARAM, funcname, L"offset", offsetlen, sizeof(uint64_t));
809
810 if (!find_tlv(data, cmd->length, BTRFS_SEND_TLV_CLONE_LENGTH, (void**)&clonelen, &clonelenlen))
811 throw string_error(IDS_RECV_MISSING_PARAM, funcname, L"clone_len");
812
813 if (clonelenlen < sizeof(uint64_t))
814 throw string_error(IDS_RECV_SHORT_PARAM, funcname, L"clone_len", clonelenlen, sizeof(uint64_t));
815
816 {
817 char* path;
818 ULONG pathlen;
819
820 if (!find_tlv(data, cmd->length, BTRFS_SEND_TLV_PATH, (void**)&path, &pathlen))
822
823 pathu = utf8_to_utf16(string(path, pathlen));
824 }
825
826 if (!find_tlv(data, cmd->length, BTRFS_SEND_TLV_CLONE_UUID, (void**)&cloneuuid, &cloneuuidlen))
827 throw string_error(IDS_RECV_MISSING_PARAM, funcname, L"clone_uuid");
828
829 if (cloneuuidlen < sizeof(BTRFS_UUID))
830 throw string_error(IDS_RECV_SHORT_PARAM, funcname, L"clone_uuid", cloneuuidlen, sizeof(BTRFS_UUID));
831
832 if (!find_tlv(data, cmd->length, BTRFS_SEND_TLV_CLONE_CTRANSID, (void**)&clonetransid, &clonetransidlen))
833 throw string_error(IDS_RECV_MISSING_PARAM, funcname, L"clone_ctransid");
834
835 if (clonetransidlen < sizeof(uint64_t))
836 throw string_error(IDS_RECV_SHORT_PARAM, funcname, L"clone_ctransid", clonetransidlen, sizeof(uint64_t));
837
838 {
839 char* clonepath;
840 ULONG clonepathlen;
841
842 if (!find_tlv(data, cmd->length, BTRFS_SEND_TLV_CLONE_PATH, (void**)&clonepath, &clonepathlen))
843 throw string_error(IDS_RECV_MISSING_PARAM, funcname, L"clone_path");
844
845 clonepathu = utf8_to_utf16(string(clonepath, clonepathlen));
846 }
847
848 if (!find_tlv(data, cmd->length, BTRFS_SEND_TLV_CLONE_OFFSET, (void**)&cloneoffset, &cloneoffsetlen))
849 throw string_error(IDS_RECV_MISSING_PARAM, funcname, L"clone_offset");
850
851 if (cloneoffsetlen < sizeof(uint64_t))
852 throw string_error(IDS_RECV_SHORT_PARAM, funcname, L"clone_offset", cloneoffsetlen, sizeof(uint64_t));
853
854 for (i = 0; i < cache.size(); i++) {
855 if (!memcmp(cloneuuid, &cache[i].uuid, sizeof(BTRFS_UUID)) && *clonetransid == cache[i].transid) {
856 clonepar = cache[i].path;
857 found = true;
858 break;
859 }
860 }
861
862 if (!found) {
863 WCHAR volpathw[MAX_PATH];
864
865 bfs.uuid = *cloneuuid;
866 bfs.ctransid = *clonetransid;
867
868 Status = NtFsControlFile(dir, nullptr, nullptr, nullptr, &iosb, FSCTL_BTRFS_FIND_SUBVOL, &bfs, sizeof(btrfs_find_subvol),
869 cloneparw, sizeof(cloneparw));
872 else if (!NT_SUCCESS(Status))
874
875 if (!GetVolumePathNameW(dirpath.c_str(), volpathw, (sizeof(volpathw) / sizeof(WCHAR)) - 1))
877
878 clonepar = volpathw;
879 if (clonepar.substr(clonepar.length() - 1) == L"\\")
880 clonepar = clonepar.substr(0, clonepar.length() - 1);
881
882 clonepar += cloneparw;
883 clonepar += L"\\";
884
885 add_cache_entry(cloneuuid, *clonetransid, clonepar);
886 }
887
888 {
892 throw string_error(IDS_RECV_CANT_OPEN_FILE, funcname, (clonepar + clonepathu).c_str(), GetLastError(), format_message(GetLastError()).c_str());
893
898
899 if (!GetFileSizeEx(dest, &filesize))
901
902 if ((uint64_t)filesize.QuadPart < *offset + *clonelen) {
903 LARGE_INTEGER sizeli;
904
905 sizeli.QuadPart = *offset + *clonelen;
906
909
910 if (!SetEndOfFile(dest))
912 }
913
914 ded.FileHandle = src;
915 ded.SourceFileOffset.QuadPart = *cloneoffset;
917 ded.ByteCount.QuadPart = *clonelen;
918
919 Status = NtFsControlFile(dest, nullptr, nullptr, nullptr, &iosb, FSCTL_DUPLICATE_EXTENTS_TO_FILE, &ded, sizeof(DUPLICATE_EXTENTS_DATA),
920 nullptr, 0);
921 if (!NT_SUCCESS(Status))
923 }
924}
925
927 uint64_t* size;
928 ULONG sizelen;
929 wstring pathu;
930 LARGE_INTEGER sizeli;
931 DWORD att;
932
933 {
934 char* path;
935 ULONG pathlen;
936
937 if (!find_tlv(data, cmd->length, BTRFS_SEND_TLV_PATH, (void**)&path, &pathlen))
939
940 pathu = utf8_to_utf16(string(path, pathlen));
941 }
942
943 if (!find_tlv(data, cmd->length, BTRFS_SEND_TLV_SIZE, (void**)&size, &sizelen))
945
946 if (sizelen < sizeof(uint64_t))
947 throw string_error(IDS_RECV_SHORT_PARAM, funcname, L"size", sizelen, sizeof(uint64_t));
948
949 att = GetFileAttributesW((subvolpath + pathu).c_str());
950 if (att == INVALID_FILE_ATTRIBUTES)
952
953 if (att & FILE_ATTRIBUTE_READONLY) {
954 if (!SetFileAttributesW((subvolpath + pathu).c_str(), att & ~FILE_ATTRIBUTE_READONLY))
956 }
957
958 {
959 win_handle h = CreateFileW((subvolpath + pathu).c_str(), FILE_WRITE_DATA, 0, nullptr, OPEN_EXISTING,
961
962 if (h == INVALID_HANDLE_VALUE)
964
965 sizeli.QuadPart = *size;
966
969
970 if (!SetEndOfFile(h))
972 }
973
974 if (att & FILE_ATTRIBUTE_READONLY) {
975 if (!SetFileAttributesW((subvolpath + pathu).c_str(), att))
977 }
978}
979
982 uint32_t* mode;
983 ULONG modelen;
984 wstring pathu;
988
989 {
990 char* path;
991 ULONG pathlen;
992
993 if (!find_tlv(data, cmd->length, BTRFS_SEND_TLV_PATH, (void**)&path, &pathlen))
995
996 pathu = utf8_to_utf16(string(path, pathlen));
997 }
998
999 if (!find_tlv(data, cmd->length, BTRFS_SEND_TLV_MODE, (void**)&mode, &modelen))
1001
1002 if (modelen < sizeof(uint32_t))
1003 throw string_error(IDS_RECV_SHORT_PARAM, funcname, L"mode", modelen, sizeof(uint32_t));
1004
1005 h = CreateFileW((subvolpath + pathu).c_str(), WRITE_DAC, 0, nullptr, OPEN_EXISTING,
1007 if (h == INVALID_HANDLE_VALUE)
1009
1010 memset(&bsii, 0, sizeof(btrfs_set_inode_info));
1011
1012 bsii.mode_changed = true;
1013 bsii.st_mode = *mode;
1014
1015 Status = NtFsControlFile(h, nullptr, nullptr, nullptr, &iosb, FSCTL_BTRFS_SET_INODE_INFO, &bsii, sizeof(btrfs_set_inode_info), nullptr, 0);
1016 if (!NT_SUCCESS(Status))
1018}
1019
1021 win_handle h;
1022 uint32_t *uid, *gid;
1023 ULONG uidlen, gidlen;
1024 wstring pathu;
1026
1027 {
1028 char* path;
1029 ULONG pathlen;
1030
1031 if (!find_tlv(data, cmd->length, BTRFS_SEND_TLV_PATH, (void**)&path, &pathlen))
1033
1034 pathu = utf8_to_utf16(string(path, pathlen));
1035 }
1036
1037 h = CreateFileW((subvolpath + pathu).c_str(), FILE_WRITE_ATTRIBUTES | WRITE_OWNER | WRITE_DAC, 0, nullptr, OPEN_EXISTING,
1039 if (h == INVALID_HANDLE_VALUE)
1041
1042 memset(&bsii, 0, sizeof(btrfs_set_inode_info));
1043
1044 if (find_tlv(data, cmd->length, BTRFS_SEND_TLV_UID, (void**)&uid, &uidlen)) {
1045 if (uidlen < sizeof(uint32_t))
1046 throw string_error(IDS_RECV_SHORT_PARAM, funcname, L"uid", uidlen, sizeof(uint32_t));
1047
1048 bsii.uid_changed = true;
1049 bsii.st_uid = *uid;
1050 }
1051
1052 if (find_tlv(data, cmd->length, BTRFS_SEND_TLV_GID, (void**)&gid, &gidlen)) {
1053 if (gidlen < sizeof(uint32_t))
1054 throw string_error(IDS_RECV_SHORT_PARAM, funcname, L"gid", gidlen, sizeof(uint32_t));
1055
1056 bsii.gid_changed = true;
1057 bsii.st_gid = *gid;
1058 }
1059
1060 if (bsii.uid_changed || bsii.gid_changed) {
1063
1064 Status = NtFsControlFile(h, nullptr, nullptr, nullptr, &iosb, FSCTL_BTRFS_SET_INODE_INFO, &bsii, sizeof(btrfs_set_inode_info), nullptr, 0);
1065 if (!NT_SUCCESS(Status))
1067 }
1068}
1069
1071 return (t->seconds * 10000000) + (t->nanoseconds / 100) + 116444736000000000;
1072}
1073
1075 wstring pathu;
1076 win_handle h;
1077 FILE_BASIC_INFO fbi;
1079 ULONG timelen;
1082
1083 {
1084 char* path;
1085 ULONG pathlen;
1086
1087 if (!find_tlv(data, cmd->length, BTRFS_SEND_TLV_PATH, (void**)&path, &pathlen))
1089
1090 pathu = utf8_to_utf16(string(path, pathlen));
1091 }
1092
1093 h = CreateFileW((subvolpath + pathu).c_str(), FILE_WRITE_ATTRIBUTES, 0, nullptr, OPEN_EXISTING,
1095 if (h == INVALID_HANDLE_VALUE)
1097
1098 memset(&fbi, 0, sizeof(FILE_BASIC_INFO));
1099
1100 if (find_tlv(data, cmd->length, BTRFS_SEND_TLV_OTIME, (void**)&time, &timelen) && timelen >= sizeof(BTRFS_TIME))
1101 fbi.CreationTime.QuadPart = unix_time_to_win(time);
1102
1103 if (find_tlv(data, cmd->length, BTRFS_SEND_TLV_ATIME, (void**)&time, &timelen) && timelen >= sizeof(BTRFS_TIME))
1104 fbi.LastAccessTime.QuadPart = unix_time_to_win(time);
1105
1106 if (find_tlv(data, cmd->length, BTRFS_SEND_TLV_MTIME, (void**)&time, &timelen) && timelen >= sizeof(BTRFS_TIME))
1107 fbi.LastWriteTime.QuadPart = unix_time_to_win(time);
1108
1109 if (find_tlv(data, cmd->length, BTRFS_SEND_TLV_CTIME, (void**)&time, &timelen) && timelen >= sizeof(BTRFS_TIME))
1110 fbi.ChangeTime.QuadPart = unix_time_to_win(time);
1111
1112 Status = NtSetInformationFile(h, &iosb, &fbi, sizeof(FILE_BASIC_INFO), FileBasicInformation);
1113 if (!NT_SUCCESS(Status))
1114 throw ntstatus_error(Status);
1115}
1116
1117static void delete_directory(const wstring& dir) {
1118 WIN32_FIND_DATAW fff;
1119
1120 fff_handle h = FindFirstFileW((dir + L"*").c_str(), &fff);
1121
1122 if (h == INVALID_HANDLE_VALUE)
1123 return;
1124
1125 do {
1126 wstring file;
1127
1128 file = fff.cFileName;
1129
1130 if (file != L"." && file != L"..") {
1131 if (fff.dwFileAttributes & FILE_ATTRIBUTE_READONLY)
1132 SetFileAttributesW((dir + file).c_str(), fff.dwFileAttributes & ~FILE_ATTRIBUTE_READONLY);
1133
1134 if (fff.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
1135 if (!(fff.dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT))
1136 delete_directory(dir + file + L"\\");
1137 else
1138 RemoveDirectoryW((dir + file).c_str());
1139 } else
1140 DeleteFileW((dir + file).c_str());
1141 }
1142 } while (FindNextFileW(h, &fff));
1143
1144 RemoveDirectoryW(dir.c_str());
1145}
1146
1148 uint32_t crc32 = cmd->csum, calc;
1149
1150 cmd->csum = 0;
1151
1153
1154 if (cmd->length > 0)
1155 calc = calc_crc32c(calc, data, cmd->length);
1156
1157 return calc == crc32 ? true : false;
1158}
1159
1161 try {
1163 bool ended = false;
1164
1165 if (!ReadFile(f, &header, sizeof(btrfs_send_header), nullptr, nullptr))
1167
1168 *pos += sizeof(btrfs_send_header);
1169
1170 if (memcmp(header.magic, BTRFS_SEND_MAGIC, sizeof(header.magic)))
1172
1173 if (header.version > 1)
1175
1177
1179 lastwritepath = L"";
1180 lastwriteatt = 0;
1181
1182 while (true) {
1184 uint8_t* data = nullptr;
1186
1187 if (cancelling)
1188 break;
1189
1190 progress = (ULONG)((float)*pos * 65536.0f / (float)size);
1192
1193 if (!ReadFile(f, &cmd, sizeof(btrfs_send_command), nullptr, nullptr)) {
1196
1197 break;
1198 }
1199
1200 *pos += sizeof(btrfs_send_command);
1201
1202 if (cmd.length > 0) {
1203 if (*pos + cmd.length > size)
1205
1206 data = (uint8_t*)malloc(cmd.length);
1207 if (!data)
1209 }
1210
1211 try {
1212 if (data) {
1213 if (!ReadFile(f, data, cmd.length, nullptr, nullptr))
1215
1216 *pos += cmd.length;
1217 }
1218
1219 if (!check_csum(&cmd, data))
1221
1222 if (cmd.cmd == BTRFS_SEND_CMD_END) {
1223 ended = true;
1224 break;
1225 }
1226
1231 }
1232
1234
1236 lastwritepath = L"";
1237 lastwriteatt = 0;
1238 }
1239
1240 switch (cmd.cmd) {
1243 break;
1244
1247 break;
1248
1255 cmd_mkfile(hwnd, &cmd, data);
1256 break;
1257
1259 cmd_rename(hwnd, &cmd, data);
1260 break;
1261
1263 cmd_link(hwnd, &cmd, data);
1264 break;
1265
1267 cmd_unlink(hwnd, &cmd, data);
1268 break;
1269
1271 cmd_rmdir(hwnd, &cmd, data);
1272 break;
1273
1276 break;
1277
1280 break;
1281
1283 cmd_write(hwnd, &cmd, data);
1284 break;
1285
1287 cmd_clone(hwnd, &cmd, data);
1288 break;
1289
1292 break;
1293
1295 cmd_chmod(hwnd, &cmd, data);
1296 break;
1297
1299 cmd_chown(hwnd, &cmd, data);
1300 break;
1301
1303 cmd_utimes(hwnd, &cmd, data);
1304 break;
1305
1307 // does nothing
1308 break;
1309
1310 default:
1312 }
1313 } catch (...) {
1314 if (data) free(data);
1315 throw;
1316 }
1317
1318 if (data) free(data);
1319 }
1320
1325 }
1326
1328 }
1329
1330 if (!ended && !cancelling)
1332
1333 if (!cancelling) {
1337
1338 brs.generation = stransid;
1339 brs.uuid = subvol_uuid;
1340
1341 Status = NtFsControlFile(dir, nullptr, nullptr, nullptr, &iosb, FSCTL_BTRFS_RECEIVED_SUBVOL, &brs, sizeof(btrfs_received_subvol),
1342 nullptr, 0);
1343 if (!NT_SUCCESS(Status))
1345 }
1346
1348
1351 } catch (...) {
1352 if (subvolpath != L"") {
1353 ULONG attrib;
1354
1355 attrib = GetFileAttributesW(subvolpath.c_str());
1356 attrib &= ~FILE_ATTRIBUTE_READONLY;
1357
1358 if (SetFileAttributesW(subvolpath.c_str(), attrib))
1360 }
1361
1362 throw;
1363 }
1364}
1365
1366#if defined(_X86_) || defined(_AMD64_)
1367static void check_cpu() {
1368 bool have_sse42 = false;
1369
1370#ifndef _MSC_VER
1371 {
1372 uint32_t eax, ebx, ecx, edx;
1373
1374 __cpuid(1, eax, ebx, ecx, edx);
1375
1376 if (__get_cpuid(1, &eax, &ebx, &ecx, &edx))
1377 have_sse42 = ecx & bit_SSE4_2;
1378 }
1379#else
1380 {
1381 int cpu_info[4];
1382
1383 __cpuid(cpu_info, 1);
1384 have_sse42 = (unsigned int)cpu_info[2] & (1 << 20);
1385 }
1386#endif
1387
1388 if (have_sse42)
1389 calc_crc32c = calc_crc32c_hw;
1390}
1391#endif
1392
1395 uint64_t pos = 0;
1396 bool b = true;
1397
1398 running = true;
1399
1400 try {
1401 win_handle f = CreateFileW(streamfile.c_str(), GENERIC_READ, 0, nullptr, OPEN_EXISTING, 0, nullptr);
1402 if (f == INVALID_HANDLE_VALUE)
1404
1405 if (!GetFileSizeEx(f, &size))
1407
1408 {
1413
1414 do {
1415 do_recv(f, &pos, size.QuadPart, parent);
1416 } while (pos < (uint64_t)size.QuadPart);
1417 }
1418 } catch (const exception& e) {
1419 auto msg = utf8_to_utf16(e.what());
1420
1422
1423 SendMessageW(GetDlgItem(hwnd, IDC_RECV_PROGRESS), PBM_SETSTATE, PBST_ERROR, 0);
1424
1425 b = false;
1426 }
1427
1428 if (b && hwnd) {
1429 wstring s;
1430
1432
1433 if (num_received == 1) {
1436 } else {
1437 wstring t;
1438
1440
1442
1444 }
1445
1447
1448 SetDlgItemTextW(hwnd, IDCANCEL, s.c_str());
1449 }
1450
1451 thread = nullptr;
1452 running = false;
1453
1454 return 0;
1455}
1456
1458 BtrfsRecv* br = (BtrfsRecv*)lpParameter;
1459
1460 return br->recv_thread();
1461}
1462
1464 switch (uMsg) {
1465 case WM_INITDIALOG:
1466 try {
1467 this->hwnd = hwndDlg;
1468 thread = CreateThread(nullptr, 0, global_recv_thread, this, 0, nullptr);
1469
1470 if (!thread)
1472 } catch (const exception& e) {
1473 auto msg = utf8_to_utf16(e.what());
1474
1476
1477 SendMessageW(GetDlgItem(hwnd, IDC_RECV_PROGRESS), PBM_SETSTATE, PBST_ERROR, 0);
1478 }
1479 break;
1480
1481 case WM_COMMAND:
1482 switch (HIWORD(wParam)) {
1483 case BN_CLICKED:
1484 switch (LOWORD(wParam)) {
1485 case IDOK:
1486 case IDCANCEL:
1487 if (running) {
1488 wstring s;
1489
1490 cancelling = true;
1491
1493 throw last_error(GetLastError());
1494
1497
1499 throw last_error(GetLastError());
1500
1501 SetDlgItemTextW(hwnd, IDCANCEL, s.c_str());
1502 } else
1503 EndDialog(hwndDlg, 1);
1504
1505 return true;
1506 }
1507 break;
1508 }
1509 break;
1510 }
1511
1512 return false;
1513}
1514
1516 BtrfsRecv* br;
1517
1518 if (uMsg == WM_INITDIALOG) {
1520 br = (BtrfsRecv*)lParam;
1521 } else {
1522 br = (BtrfsRecv*)GetWindowLongPtrW(hwndDlg, GWLP_USERDATA);
1523 }
1524
1525 if (br)
1526 return br->RecvProgressDlgProc(hwndDlg, uMsg, wParam, lParam);
1527 else
1528 return false;
1529}
1530
1531void BtrfsRecv::Open(HWND hwnd, const wstring& file, const wstring& path, bool quiet) {
1532 streamfile = file;
1533 dirpath = path;
1534 subvolpath = L"";
1535
1536#if defined(_X86_) || defined(_AMD64_)
1537 check_cpu();
1538#endif
1539
1540 if (quiet)
1541 recv_thread();
1542 else {
1544 throw last_error(GetLastError());
1545 }
1546}
1547
1548extern "C" void CALLBACK RecvSubvolGUIW(HWND hwnd, HINSTANCE hinst, LPWSTR lpszCmdLine, int nCmdShow) {
1549 try {
1554 LUID luid;
1555 ULONG tplen;
1556
1557 set_dpi_aware();
1558
1560 throw last_error(GetLastError());
1561
1562 tplen = offsetof(TOKEN_PRIVILEGES, Privileges[0]) + (3 * sizeof(LUID_AND_ATTRIBUTES));
1563 tp = (TOKEN_PRIVILEGES*)malloc(tplen);
1564 if (!tp)
1566
1567 tp->PrivilegeCount = 3;
1568
1569#ifdef __clang__
1570#pragma clang diagnostic push
1571#pragma clang diagnostic ignored "-Warray-bounds"
1572#endif // __clang__
1573
1574 if (!LookupPrivilegeValueW(nullptr, L"SeManageVolumePrivilege", &luid)) {
1575 free(tp);
1576 throw last_error(GetLastError());
1577 }
1578
1579 tp->Privileges[0].Luid = luid;
1580 tp->Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
1581
1582 if (!LookupPrivilegeValueW(nullptr, L"SeSecurityPrivilege", &luid)) {
1583 free(tp);
1584 throw last_error(GetLastError());
1585 }
1586
1587 tp->Privileges[1].Luid = luid;
1588 tp->Privileges[1].Attributes = SE_PRIVILEGE_ENABLED;
1589
1590 if (!LookupPrivilegeValueW(nullptr, L"SeRestorePrivilege", &luid)) {
1591 free(tp);
1592 throw last_error(GetLastError());
1593 }
1594
1595 tp->Privileges[2].Luid = luid;
1596 tp->Privileges[2].Attributes = SE_PRIVILEGE_ENABLED;
1597
1598 if (!AdjustTokenPrivileges(token, false, tp, tplen, nullptr, nullptr)) {
1599 free(tp);
1600 throw last_error(GetLastError());
1601 }
1602
1603#ifdef __clang__
1604 #pragma clang diagnostic pop
1605#endif // __clang__
1606
1607 file[0] = 0;
1608
1609 memset(&ofn, 0, sizeof(OPENFILENAMEW));
1610 ofn.lStructSize = sizeof(OPENFILENAMEW);
1611 ofn.hwndOwner = hwnd;
1613 ofn.lpstrFile = file;
1614 ofn.nMaxFile = sizeof(file) / sizeof(WCHAR);
1616
1617 if (GetOpenFileNameW(&ofn)) {
1619
1620 recv.Open(hwnd, file, lpszCmdLine, false);
1621 }
1622
1623 free(tp);
1624 } catch (const exception& e) {
1625 error_message(hwnd, e.what());
1626 }
1627}
1628
1629extern "C" void CALLBACK RecvSubvolW(HWND hwnd, HINSTANCE hinst, LPWSTR lpszCmdLine, int nCmdShow) {
1630 try {
1632
1633 command_line_to_args(lpszCmdLine, args);
1634
1635 if (args.size() >= 2) {
1638 ULONG tplen;
1639 LUID luid;
1640
1642 return;
1643
1644 tplen = offsetof(TOKEN_PRIVILEGES, Privileges[0]) + (3 * sizeof(LUID_AND_ATTRIBUTES));
1645 tp = (TOKEN_PRIVILEGES*)malloc(tplen);
1646 if (!tp)
1647 return;
1648
1649 tp->PrivilegeCount = 3;
1650
1651#ifdef __clang__
1652#pragma clang diagnostic push
1653#pragma clang diagnostic ignored "-Warray-bounds"
1654#endif // __clang__
1655
1656 if (!LookupPrivilegeValueW(nullptr, L"SeManageVolumePrivilege", &luid)) {
1657 free(tp);
1658 return;
1659 }
1660
1661 tp->Privileges[0].Luid = luid;
1662 tp->Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
1663
1664 if (!LookupPrivilegeValueW(nullptr, L"SeSecurityPrivilege", &luid)) {
1665 free(tp);
1666 return;
1667 }
1668
1669 tp->Privileges[1].Luid = luid;
1670 tp->Privileges[1].Attributes = SE_PRIVILEGE_ENABLED;
1671
1672 if (!LookupPrivilegeValueW(nullptr, L"SeRestorePrivilege", &luid)) {
1673 free(tp);
1674 return;
1675 }
1676
1677 tp->Privileges[2].Luid = luid;
1678 tp->Privileges[2].Attributes = SE_PRIVILEGE_ENABLED;
1679
1680#ifdef __clang__
1681#pragma clang diagnostic pop
1682#endif // __clang__
1683
1684 if (!AdjustTokenPrivileges(token, false, tp, tplen, nullptr, nullptr)) {
1685 free(tp);
1686 return;
1687 }
1688
1689 free(tp);
1690
1691 BtrfsRecv br;
1692 br.Open(nullptr, args[0], args[1], true);
1693 }
1694 } catch (const exception& e) {
1695 cerr << "Error: " << e.what() << endl;
1696 }
1697}
basic_ostream< _CharT, _Traits > &_STLP_CALL endl(basic_ostream< _CharT, _Traits > &__os)
Definition: _ostream.h:357
int memcmp(void *Buffer1, void *Buffer2, ACPI_SIZE Count)
Definition: utclib.c:112
unsigned short int uint16_t
Definition: acefiex.h:54
unsigned int dir
Definition: maze.c:112
#define msg(x)
Definition: auth_time.c:54
#define IDS_OUT_OF_MEMORY
Definition: resource.h:5
LONG NTSTATUS
Definition: precomp.h:26
#define EA_EA
Definition: btrfs_drv.h:102
#define EA_NTACL
Definition: btrfs_drv.h:93
#define EA_REPARSE
Definition: btrfs_drv.h:99
#define EA_DOSATTRIB
Definition: btrfs_drv.h:96
#define FSCTL_BTRFS_CREATE_SNAPSHOT
Definition: btrfsioctl.h:9
#define FSCTL_BTRFS_SET_INODE_INFO
Definition: btrfsioctl.h:11
#define FSCTL_BTRFS_SET_XATTR
Definition: btrfsioctl.h:33
#define FSCTL_BTRFS_RESERVE_SUBVOL
Definition: btrfsioctl.h:34
#define FSCTL_BTRFS_MKNOD
Definition: btrfsioctl.h:30
#define FSCTL_BTRFS_FIND_SUBVOL
Definition: btrfsioctl.h:35
#define FSCTL_BTRFS_RECEIVED_SUBVOL
Definition: btrfsioctl.h:31
#define FSCTL_BTRFS_CREATE_SUBVOL
Definition: btrfsioctl.h:8
calc_t calc
Definition: winmain.c:247
cd_progress_ptr progress
Definition: cdjpeg.h:152
Definition: recv.h:35
void cmd_removexattr(HWND hwnd, btrfs_send_command *cmd, uint8_t *data)
Definition: recv.cpp:634
DWORD lastwriteatt
Definition: recv.h:80
void cmd_chmod(HWND hwnd, btrfs_send_command *cmd, uint8_t *data)
Definition: recv.cpp:980
void cmd_subvol(HWND hwnd, btrfs_send_command *cmd, uint8_t *data, const win_handle &parent)
Definition: recv.cpp:67
void cmd_write(HWND hwnd, btrfs_send_command *cmd, uint8_t *data)
Definition: recv.cpp:716
wstring lastwritepath
Definition: recv.h:79
DWORD recv_thread()
Definition: recv.cpp:1393
void cmd_rmdir(HWND hwnd, btrfs_send_command *cmd, uint8_t *data)
Definition: recv.cpp:511
void cmd_snapshot(HWND hwnd, btrfs_send_command *cmd, uint8_t *data, const win_handle &parent)
Definition: recv.cpp:157
void cmd_clone(HWND hwnd, btrfs_send_command *cmd, uint8_t *data)
Definition: recv.cpp:791
bool find_tlv(uint8_t *data, ULONG datalen, uint16_t type, void **value, ULONG *len)
Definition: recv.cpp:45
void cmd_setxattr(HWND hwnd, btrfs_send_command *cmd, uint8_t *data)
Definition: recv.cpp:538
uint64_t stransid
Definition: recv.h:82
void Open(HWND hwnd, const wstring &file, const wstring &path, bool quiet)
Definition: recv.cpp:1531
HANDLE dir
Definition: recv.h:77
void cmd_mkfile(HWND hwnd, btrfs_send_command *cmd, uint8_t *data)
Definition: recv.cpp:280
bool running
Definition: recv.h:84
void add_cache_entry(BTRFS_UUID *uuid, uint64_t transid, const wstring &path)
Definition: recv.cpp:147
wstring subvolpath
Definition: recv.h:79
void cmd_link(HWND hwnd, btrfs_send_command *cmd, uint8_t *data)
Definition: recv.cpp:457
void cmd_unlink(HWND hwnd, btrfs_send_command *cmd, uint8_t *data)
Definition: recv.cpp:484
void cmd_rename(HWND hwnd, btrfs_send_command *cmd, uint8_t *data)
Definition: recv.cpp:430
HANDLE thread
Definition: recv.h:77
INT_PTR CALLBACK RecvProgressDlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
Definition: recv.cpp:1463
void cmd_truncate(HWND hwnd, btrfs_send_command *cmd, uint8_t *data)
Definition: recv.cpp:926
HANDLE master
Definition: recv.h:77
wstring dirpath
Definition: recv.h:79
void cmd_chown(HWND hwnd, btrfs_send_command *cmd, uint8_t *data)
Definition: recv.cpp:1020
ULONG num_received
Definition: recv.h:81
void cmd_utimes(HWND hwnd, btrfs_send_command *cmd, uint8_t *data)
Definition: recv.cpp:1074
HANDLE lastwritefile
Definition: recv.h:77
wstring streamfile
Definition: recv.h:79
void do_recv(const win_handle &f, uint64_t *pos, uint64_t size, const win_handle &parent)
Definition: recv.cpp:1160
bool cancelling
Definition: recv.h:84
BTRFS_UUID subvol_uuid
Definition: recv.h:83
size_type length() const
Definition: _string.h:401
WPARAM wParam
Definition: combotst.c:138
LPARAM lParam
Definition: combotst.c:139
#define OFN_EXPLORER
Definition: commdlg.h:104
#define OFN_HIDEREADONLY
Definition: commdlg.h:107
#define OFN_FILEMUSTEXIST
Definition: commdlg.h:106
struct tagOFNW OPENFILENAMEW
crc_func calc_crc32c
Definition: crc32c.c:23
#define free
Definition: debug_ros.c:5
#define malloc
Definition: debug_ros.c:4
UINT32 uint32_t
Definition: types.h:75
UINT64 uint64_t
Definition: types.h:77
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
void set_dpi_aware()
Definition: main.cpp:50
void error_message(HWND hwnd, const char *msg)
Definition: main.cpp:783
wstring format_ntstatus(NTSTATUS Status)
Definition: main.cpp:184
void wstring_sprintf(wstring &s, wstring fmt,...)
Definition: main.cpp:225
void command_line_to_args(LPWSTR cmdline, vector< wstring > &args)
Definition: main.cpp:645
wstring utf8_to_utf16(const string_view &utf8)
Definition: main.cpp:734
#define IDS_RECV_CSUM_ERROR
Definition: resource.h:155
#define IDS_RECV_DUPLICATE_EXTENTS_FAILED
Definition: resource.h:174
#define IDS_RECV_CANT_CREATE_FILE
Definition: resource.h:148
#define IDD_RECV_PROGRESS
Definition: resource.h:86
#define IDS_RECV_SETXATTR_FAILED
Definition: resource.h:161
#define IDS_RECV_SETFILEPOINTER_FAILED
Definition: resource.h:144
#define IDS_RECV_FILE_TRUNCATED
Definition: resource.h:163
#define IDS_RECV_CANT_FIND_CLONE_SUBVOL
Definition: resource.h:172
#define IDS_RECV_NOT_A_SEND_STREAM
Definition: resource.h:156
#define IDS_RECV_RECEIVED_SUBVOL_FAILED
Definition: resource.h:159
#define IDS_RECV_REMOVEDIRECTORY_FAILED
Definition: resource.h:171
#define IDS_RECV_GETFILEATTRIBUTES_FAILED
Definition: resource.h:154
#define IDS_RECV_RESERVE_SUBVOL_FAILED
Definition: resource.h:164
#define IDS_RECV_SETINODEINFO_FAILED
Definition: resource.h:150
#define IDC_RECV_MSG
Definition: resource.h:325
#define IDS_RECV_SETENDOFFILE_FAILED
Definition: resource.h:147
#define IDS_RECV_WRITEFILE_FAILED
Definition: resource.h:145
#define IDS_RECV_CREATE_SNAPSHOT_FAILED
Definition: resource.h:168
#define IDS_RECV_UNKNOWN_COMMAND
Definition: resource.h:135
#define IDS_RECV_CANT_OPEN_PATH
Definition: resource.h:136
#define IDS_RECV_CANT_OPEN_FILE
Definition: resource.h:132
#define IDS_RECV_CREATETHREAD_FAILED
Definition: resource.h:162
#define IDS_RECV_READFILE_FAILED
Definition: resource.h:133
#define IDS_RECV_GETVOLUMEPATHNAME_FAILED
Definition: resource.h:169
#define IDS_RECV_MOVEFILE_FAILED
Definition: resource.h:143
#define IDS_RECV_FIND_SUBVOL_FAILED
Definition: resource.h:167
#define IDS_RECV_SET_REPARSE_POINT_FAILED
Definition: resource.h:142
#define IDS_RECV_UNSUPPORTED_VERSION
Definition: resource.h:157
#define IDS_RECV_SETFILEATTRIBUTES_FAILED
Definition: resource.h:153
#define IDC_RECV_PROGRESS
Definition: resource.h:264
#define IDS_RECV_SUCCESS
Definition: resource.h:151
#define IDS_RECV_MKNOD_FAILED
Definition: resource.h:141
#define IDS_RECV_SHORT_PARAM
Definition: resource.h:140
#define IDS_RECV_BUTTON_OK
Definition: resource.h:152
#define IDS_RECV_CANCELLED
Definition: resource.h:165
#define IDS_RECV_CREATEHARDLINK_FAILED
Definition: resource.h:146
#define IDS_RECV_SUCCESS_PLURAL
Definition: resource.h:175
#define IDS_RECV_GETFILESIZEEX_FAILED
Definition: resource.h:173
#define IDS_RECV_MISSING_PARAM
Definition: resource.h:139
#define IDS_RECV_DELETEFILE_FAILED
Definition: resource.h:170
#define IDS_RECV_CREATE_SUBVOL_FAILED
Definition: resource.h:138
#define IDS_RECV_CANT_FIND_PARENT_SUBVOL
Definition: resource.h:166
#define IDS_RECV_PATH_TOO_LONG
Definition: resource.h:208
BOOL WINAPI LookupPrivilegeValueW(LPCWSTR lpSystemName, LPCWSTR lpPrivilegeName, PLUID lpLuid)
Definition: misc.c:782
BOOL WINAPI AdjustTokenPrivileges(HANDLE TokenHandle, BOOL DisableAllPrivileges, PTOKEN_PRIVILEGES NewState, DWORD BufferLength, PTOKEN_PRIVILEGES PreviousState, PDWORD ReturnLength)
Definition: security.c:374
BOOL WINAPI OpenProcessToken(HANDLE ProcessHandle, DWORD DesiredAccess, PHANDLE TokenHandle)
Definition: security.c:294
BOOL WINAPI GetOpenFileNameW(OPENFILENAMEW *ofn)
Definition: filedlg.c:4736
#define CloseHandle
Definition: compat.h:739
#define FILE_BEGIN
Definition: compat.h:761
#define INVALID_SET_FILE_POINTER
Definition: compat.h:732
#define OPEN_EXISTING
Definition: compat.h:775
#define ReadFile(a, b, c, d, e)
Definition: compat.h:742
#define SetFilePointer
Definition: compat.h:743
#define INVALID_HANDLE_VALUE
Definition: compat.h:731
#define GetCurrentProcess()
Definition: compat.h:759
#define GENERIC_READ
Definition: compat.h:135
#define MAX_PATH
Definition: compat.h:34
#define CreateFileW
Definition: compat.h:741
#define GetFileSizeEx
Definition: compat.h:757
#define CALLBACK
Definition: compat.h:35
#define FILE_SHARE_READ
Definition: compat.h:136
#define crc32(crc, buf, len)
Definition: inflate.c:1081
BOOL WINAPI DeleteFileW(IN LPCWSTR lpFileName)
Definition: delete.c:39
BOOL WINAPI RemoveDirectoryW(IN LPCWSTR lpPathName)
Definition: dir.c:732
DWORD WINAPI GetFileAttributesW(LPCWSTR lpFileName)
Definition: fileinfo.c:652
BOOL WINAPI SetFileAttributesW(LPCWSTR lpFileName, DWORD dwFileAttributes)
Definition: fileinfo.c:794
BOOL WINAPI SetEndOfFile(HANDLE hFile)
Definition: fileinfo.c:1004
HANDLE WINAPI FindFirstFileW(IN LPCWSTR lpFileName, OUT LPWIN32_FIND_DATAW lpFindFileData)
Definition: find.c:320
BOOL WINAPI FindNextFileW(IN HANDLE hFindFile, OUT LPWIN32_FIND_DATAW lpFindFileData)
Definition: find.c:382
BOOL WINAPI MoveFileW(IN LPCWSTR lpExistingFileName, IN LPCWSTR lpNewFileName)
Definition: move.c:1104
BOOL WINAPI WriteFile(IN HANDLE hFile, IN LPCVOID lpBuffer, IN DWORD nNumberOfBytesToWrite OPTIONAL, OUT LPDWORD lpNumberOfBytesWritten, IN LPOVERLAPPED lpOverlapped OPTIONAL)
Definition: rw.c:24
BOOL WINAPI GetVolumePathNameW(IN LPCWSTR lpszFileName, IN LPWSTR lpszVolumePathName, IN DWORD cchBufferLength)
Definition: volume.c:815
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:137
unsigned int(__cdecl typeof(jpeg_read_scanlines))(struct jpeg_decompress_struct *
Definition: typeof.h:31
INT WSAAPI recv(IN SOCKET s, OUT CHAR FAR *buf, IN INT len, IN INT flags)
Definition: recv.c:23
_In_ uint64_t _In_ uint64_t _In_ uint64_t _In_opt_ traverse_ptr * tp
Definition: btrfs.c:2996
r parent
Definition: btrfs.c:3010
#define BTRFS_SEND_CMD_RMDIR
Definition: btrfs.h:556
#define BTRFS_SEND_TLV_PATH
Definition: btrfs.h:582
#define BTRFS_SEND_TLV_CLONE_UUID
Definition: btrfs.h:587
#define BTRFS_SEND_CMD_SET_XATTR
Definition: btrfs.h:557
#define BTRFS_SEND_CMD_MKFILE
Definition: btrfs.h:547
#define BTRFS_SEND_TLV_CLONE_OFFSET
Definition: btrfs.h:590
#define BTRFS_SEND_TLV_XATTR_DATA
Definition: btrfs.h:581
#define BTRFS_SEND_CMD_UPDATE_EXTENT
Definition: btrfs.h:566
#define BTRFS_SEND_CMD_WRITE
Definition: btrfs.h:559
#define BTRFS_SEND_CMD_UTIMES
Definition: btrfs.h:564
#define BTRFS_SEND_CMD_CHMOD
Definition: btrfs.h:562
#define BTRFS_SEND_CMD_LINK
Definition: btrfs.h:554
#define BTRFS_SEND_CMD_RENAME
Definition: btrfs.h:553
#define BTRFS_SEND_TLV_TRANSID
Definition: btrfs.h:569
#define BTRFS_SEND_TLV_UUID
Definition: btrfs.h:568
#define BTRFS_SEND_TLV_GID
Definition: btrfs.h:574
#define BTRFS_SEND_TLV_DATA
Definition: btrfs.h:586
#define BTRFS_SEND_CMD_MKFIFO
Definition: btrfs.h:550
#define BTRFS_SEND_CMD_SUBVOL
Definition: btrfs.h:545
#define BTRFS_SEND_TLV_MODE
Definition: btrfs.h:572
#define BTRFS_SEND_CMD_SNAPSHOT
Definition: btrfs.h:546
#define BTRFS_SEND_TLV_UID
Definition: btrfs.h:573
#define BTRFS_SEND_CMD_TRUNCATE
Definition: btrfs.h:561
#define BTRFS_SEND_TLV_XATTR_NAME
Definition: btrfs.h:580
#define BTRFS_SEND_TLV_MTIME
Definition: btrfs.h:577
#define BTRFS_SEND_TLV_CLONE_PATH
Definition: btrfs.h:589
#define BTRFS_SEND_TLV_CLONE_LENGTH
Definition: btrfs.h:591
#define BTRFS_SEND_TLV_OFFSET
Definition: btrfs.h:585
#define BTRFS_SEND_CMD_CHOWN
Definition: btrfs.h:563
#define BTRFS_SEND_TLV_CLONE_CTRANSID
Definition: btrfs.h:588
#define BTRFS_SEND_CMD_MKNOD
Definition: btrfs.h:549
#define BTRFS_SEND_TLV_SIZE
Definition: btrfs.h:571
#define BTRFS_SEND_CMD_END
Definition: btrfs.h:565
#define BTRFS_SEND_CMD_UNLINK
Definition: btrfs.h:555
#define BTRFS_SEND_CMD_REMOVE_XATTR
Definition: btrfs.h:558
#define BTRFS_SEND_CMD_SYMLINK
Definition: btrfs.h:552
#define BTRFS_SEND_CMD_CLONE
Definition: btrfs.h:560
#define BTRFS_SEND_CMD_MKSOCK
Definition: btrfs.h:551
#define BTRFS_SEND_TLV_PATH_LINK
Definition: btrfs.h:584
#define BTRFS_SEND_MAGIC
Definition: btrfs.h:593
#define BTRFS_SEND_TLV_INODE
Definition: btrfs.h:570
#define BTRFS_SEND_TLV_ATIME
Definition: btrfs.h:578
#define BTRFS_SEND_TLV_CTIME
Definition: btrfs.h:576
#define BTRFS_SEND_TLV_OTIME
Definition: btrfs.h:579
#define BTRFS_SEND_TLV_RDEV
Definition: btrfs.h:575
#define BTRFS_SEND_TLV_PATH_TO
Definition: btrfs.h:583
#define BTRFS_SEND_CMD_MKDIR
Definition: btrfs.h:548
#define S_IFCHR
Definition: ext2fs.h:364
unsigned long DWORD
Definition: ntddk_ex.h:95
@ FileBasicInformation
Definition: from_kernel.h:65
#define FILE_OPEN_REPARSE_POINT
Definition: from_kernel.h:46
Status
Definition: gdiplustypes.h:25
GLuint GLuint GLsizei GLenum type
Definition: gl.h:1545
GLdouble s
Definition: gl.h:2039
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
GLdouble GLdouble t
Definition: gl.h:2047
GLsizeiptr size
Definition: glext.h:5919
GLenum src
Definition: glext.h:6340
GLint namelen
Definition: glext.h:7232
GLfloat f
Definition: glext.h:7540
GLboolean GLboolean GLboolean b
Definition: glext.h:6204
GLenum mode
Definition: glext.h:6217
GLenum GLsizei len
Definition: glext.h:6722
GLintptr offset
Definition: glext.h:5920
GLfloat GLfloat GLfloat GLfloat h
Definition: glext.h:7723
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat token
Definition: glfuncs.h:210
Definition: msctf.idl:550
PPC_QUAL void __cpuid(int CPUInfo[], const int InfoType)
Definition: intrin_ppc.h:682
#define cerr
Definition: iostream.cpp:39
format_message(j_common_ptr cinfo, char *buffer)
Definition: jerror.c:158
int const JOCTET unsigned int datalen
Definition: jpeglib.h:1031
#define e
Definition: ke_i.h:82
__u16 time
Definition: mkdosfs.c:8
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
char string[160]
Definition: util.h:11
#define CREATE_ALWAYS
Definition: disk.h:72
#define FILE_FLAG_POSIX_SEMANTICS
Definition: disk.h:40
#define FILE_FLAG_BACKUP_SEMANTICS
Definition: disk.h:41
static DWORD path_len
Definition: batch.c:31
static HINSTANCE hinst
Definition: edit.c:551
static PIO_STATUS_BLOCK iosb
Definition: file.c:98
static char * dest
Definition: rtl.c:135
static float(__cdecl *square_half_float)(float x
__int3264 LONG_PTR
Definition: mstsclib_h.h:276
BYTE uint8_t
Definition: msvideo1.c:66
static int load_string(HINSTANCE hModule, UINT resId, LPWSTR pwszBuffer, INT cMaxChars)
Definition: muireg.c:10
unsigned int UINT
Definition: ndis.h:50
#define uint32_t
Definition: nsiface.idl:61
#define uint16_t
Definition: nsiface.idl:60
#define FILE_SHARE_WRITE
Definition: nt_native.h:681
#define FILE_WRITE_DATA
Definition: nt_native.h:631
#define WRITE_DAC
Definition: nt_native.h:59
#define FILE_READ_DATA
Definition: nt_native.h:628
#define FILE_ATTRIBUTE_READONLY
Definition: nt_native.h:702
NTSYSAPI NTSTATUS NTAPI NtSetInformationFile(IN HANDLE hFile, OUT PIO_STATUS_BLOCK pIoStatusBlock, IN PVOID FileInformationBuffer, IN ULONG FileInformationBufferLength, IN FILE_INFORMATION_CLASS FileInfoClass)
Definition: iofunc.c:3096
#define FILE_SHARE_DELETE
Definition: nt_native.h:682
#define FILE_TRAVERSE
Definition: nt_native.h:643
#define FILE_WRITE_ATTRIBUTES
Definition: nt_native.h:649
#define FILE_ATTRIBUTE_DIRECTORY
Definition: nt_native.h:705
#define WRITE_OWNER
Definition: nt_native.h:60
#define FILE_ADD_SUBDIRECTORY
Definition: nt_native.h:635
#define GENERIC_WRITE
Definition: nt_native.h:90
#define FILE_ADD_FILE
Definition: nt_native.h:632
NTSYSAPI NTSTATUS NTAPI NtFsControlFile(IN HANDLE hFile, IN HANDLE hEvent OPTIONAL, IN PIO_APC_ROUTINE IoApcRoutine OPTIONAL, IN PVOID IoApcContext OPTIONAL, OUT PIO_STATUS_BLOCK pIoStatusBlock, IN ULONG DeviceIoControlCode, IN PVOID InBuffer OPTIONAL, IN ULONG InBufferLength, OUT PVOID OutBuffer OPTIONAL, IN ULONG OutBufferLength)
#define FILE_WRITE_EA
Definition: nt_native.h:640
#define FILE_ATTRIBUTE_REPARSE_POINT
Definition: ntifs_ex.h:381
#define L(x)
Definition: ntvdm.h:50
#define LOWORD(l)
Definition: pedump.c:82
#define PBM_SETRANGE32
Definition: commctrl.h:2188
#define PBM_SETPOS
Definition: commctrl.h:2184
#define FSCTL_SET_REPARSE_POINT
Definition: winioctl.h:747
const string EA_DOSATTRIB
Definition: recv.cpp:40
static DWORD WINAPI global_recv_thread(LPVOID lpParameter)
Definition: recv.cpp:1457
void CALLBACK RecvSubvolGUIW(HWND hwnd, HINSTANCE hinst, LPWSTR lpszCmdLine, int nCmdShow)
Definition: recv.cpp:1548
static __inline uint64_t unix_time_to_win(BTRFS_TIME *t)
Definition: recv.cpp:1070
const string EA_NTACL
Definition: recv.cpp:39
const string XATTR_USER
Definition: recv.cpp:43
static INT_PTR CALLBACK stub_RecvProgressDlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
Definition: recv.cpp:1515
void CALLBACK RecvSubvolW(HWND hwnd, HINSTANCE hinst, LPWSTR lpszCmdLine, int nCmdShow)
Definition: recv.cpp:1629
const string EA_EA
Definition: recv.cpp:42
static void delete_directory(const wstring &dir)
Definition: recv.cpp:1117
const string EA_REPARSE
Definition: recv.cpp:41
static bool check_csum(btrfs_send_command *cmd, uint8_t *data)
Definition: recv.cpp:1147
#define offsetof(TYPE, MEMBER)
#define memset(x, y, z)
Definition: compat.h:39
#define BTRFS_TYPE_FILE
Definition: shellext.h:85
#define FSCTL_DUPLICATE_EXTENTS_TO_FILE
Definition: shellext.h:205
#define SYMLINK_FLAG_RELATIVE
Definition: shellext.h:193
#define BTRFS_TYPE_DIRECTORY
Definition: shellext.h:86
#define BTRFS_TYPE_SOCKET
Definition: shellext.h:90
#define funcname
Definition: shellext.h:96
#define BTRFS_TYPE_FIFO
Definition: shellext.h:89
#define STATUS_NOT_FOUND
Definition: shellext.h:72
#define BTRFS_TYPE_CHARDEV
Definition: shellext.h:87
#define BTRFS_TYPE_BLOCKDEV
Definition: shellext.h:88
OPENFILENAME ofn
Definition: sndrec32.cpp:56
#define true
Definition: stdbool.h:36
LARGE_INTEGER ByteCount
Definition: shellext.h:202
LARGE_INTEGER SourceFileOffset
Definition: shellext.h:200
LARGE_INTEGER TargetFileOffset
Definition: shellext.h:201
WCHAR PathBuffer[1]
Definition: shellext.h:176
struct _REPARSE_DATA_BUFFER::@321::@323 SymbolicLinkReparseBuffer
USHORT ReparseDataLength
Definition: shellext.h:166
Definition: match.c:390
BTRFS_UUID uuid
Definition: btrfsioctl.h:263
uint64_t ctransid
Definition: btrfsioctl.h:264
uint64_t inode
Definition: btrfsioctl.h:237
WCHAR name[1]
Definition: btrfsioctl.h:241
uint16_t namelen
Definition: btrfsioctl.h:240
uint64_t st_rdev
Definition: btrfsioctl.h:239
uint8_t type
Definition: btrfsioctl.h:238
uint16_t type
Definition: btrfs.h:607
uint16_t length
Definition: btrfs.h:608
Definition: cache.c:49
Definition: ftp_var.h:139
Definition: fci.c:127
Definition: fs.h:78
Definition: name.c:39
BTRFS_UUID uuid
Definition: recv.h:30
uint64_t transid
Definition: recv.h:31
wstring path
Definition: recv.h:32
HWND hwndOwner
Definition: commdlg.h:330
HINSTANCE hInstance
Definition: commdlg.h:331
LPSTR lpstrFile
Definition: commdlg.h:336
DWORD Flags
Definition: commdlg.h:342
DWORD lStructSize
Definition: commdlg.h:329
DWORD nMaxFile
Definition: commdlg.h:337
ecx edi movl ebx edx edi decl ecx esi eax jecxz decl eax andl ebx
Definition: synth_sse3d.h:83
ecx edi movl ebx edx edi decl ecx esi eax jecxz decl eax andl eax esi movl eax
Definition: synth_sse3d.h:85
ecx edi movl ebx edx edi decl ecx esi eax jecxz decl eax andl eax esi movl edx
Definition: synth_sse3d.h:87
#define GWLP_USERDATA
Definition: treelist.c:63
int32_t INT_PTR
Definition: typedefs.h:64
uint32_t ULONG
Definition: typedefs.h:59
#define HIWORD(l)
Definition: typedefs.h:247
LONGLONG QuadPart
Definition: typedefs.h:114
ULONG LowPart
Definition: typedefs.h:106
Definition: pdh_main.c:94
#define INVALID_FILE_ATTRIBUTES
Definition: vfdcmd.c:23
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
_In_ LONG _In_ HWND hwnd
Definition: winddi.h:4023
LONG_PTR LPARAM
Definition: windef.h:208
UINT_PTR WPARAM
Definition: windef.h:207
#define WINAPI
Definition: msvc.h:6
#define ERROR_HANDLE_EOF
Definition: winerror.h:140
#define GetWindowLongPtrW
Definition: winuser.h:4829
#define IDCANCEL
Definition: winuser.h:831
#define WM_COMMAND
Definition: winuser.h:1740
BOOL WINAPI SetDlgItemTextW(_In_ HWND, _In_ int, _In_ LPCWSTR)
#define WM_INITDIALOG
Definition: winuser.h:1739
HWND WINAPI GetDlgItem(_In_opt_ HWND, _In_ int)
#define IDOK
Definition: winuser.h:830
#define BN_CLICKED
Definition: winuser.h:1925
#define MAKEINTRESOURCEW(i)
Definition: winuser.h:582
#define SetWindowLongPtrW
Definition: winuser.h:5355
LRESULT WINAPI SendMessageW(_In_ HWND, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
INT_PTR WINAPI DialogBoxParamW(_In_opt_ HINSTANCE, _In_ LPCWSTR, _In_opt_ HWND, _In_opt_ DLGPROC, _In_ LPARAM)
BOOL WINAPI EndDialog(_In_ HWND, _In_ INT_PTR)
#define IO_REPARSE_TAG_SYMLINK
Definition: iotypes.h:7240
_In_ PSECURITY_SUBJECT_CONTEXT _In_ BOOLEAN _In_ ACCESS_MASK _In_ ACCESS_MASK _Outptr_opt_ PPRIVILEGE_SET * Privileges
Definition: sefuncs.h:17
#define TOKEN_ADJUST_PRIVILEGES
Definition: setypes.h:930
#define TOKEN_QUERY
Definition: setypes.h:928
struct _LUID_AND_ATTRIBUTES LUID_AND_ATTRIBUTES
#define SE_PRIVILEGE_ENABLED
Definition: setypes.h:63
static int quiet
Definition: xmllint.c:162
__wchar_t WCHAR
Definition: xmlstorage.h:180
WCHAR * LPWSTR
Definition: xmlstorage.h:184