1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
/* Copyright (c) Mark Harmstone 2016-17
 *
 * This file is part of WinBtrfs.
 *
 * WinBtrfs is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public Licence as published by
 * the Free Software Foundation, either version 3 of the Licence, or
 * (at your option) any later version.
 *
 * WinBtrfs is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public Licence for more details.
 *
 * You should have received a copy of the GNU Lesser General Public Licence
 * along with WinBtrfs.  If not, see <http://www.gnu.org/licenses/>. */

#pragma once

#ifndef __REACTOS__
#include <windows.h>
#include <winternl.h>
#else
#define WIN32_NO_STATUS
#include <windef.h>
#include <winbase.h>
#include <ndk/iofuncs.h>
#include <ndk/iotypes.h>
#endif
#include <shlobj.h>
#ifndef __REACTOS__
#include "../btrfsioctl.h"
#else
#include "btrfsioctl.h"
#endif

typedef struct {
    wstring pnp_name;
    wstring friendly_name;
    wstring drive;
    wstring fstype;
    ULONG disk_num;
    ULONG part_num;
    uint64_t size;
    bool has_parts;
    BTRFS_UUID fs_uuid;
    BTRFS_UUID dev_uuid;
    bool ignore;
    bool multi_device;
    bool is_disk;
} device;

typedef struct {
    const WCHAR* name;
    const char* magic;
    ULONG magiclen;
    uint32_t sboff;
    uint32_t kboff;
} fs_identifier;

// This list is compiled from information in libblkid, part of util-linux
// and likewise under the LGPL. Thanks!

const static fs_identifier fs_ident[] = {
    { L"BeFS", "BFS1", 4, 0x20, 0 },
    { L"BeFS", "1SFB", 4, 0x20, 0 },
    { L"BeFS", "BFS1", 4, 0x220, 0 },
    { L"BeFS", "1SFB", 4, 0x220, 0 },
    { L"BFS", "\xce\xfa\xad\x1b", 4, 0, 0 },
    { L"RomFS", "-rom1fs-", 8, 0, 0 },
    { L"SquashFS", "hsqs", 4, 0, 0 },
    { L"SquashFS", "sqsh", 4, 0, 0 },
    { L"SquashFS", "hsqs", 4, 0, 0 },
    { L"UBIFS", "\x31\x18\x10\x06", 4, 0, 0 },
    { L"XFS", "XFSB", 4, 0, 0 },
    { L"ext2", "\123\357", 2, 0x38, 1 },
    { L"F2FS", "\x10\x20\xF5\xF2", 4, 0, 1 },
    { L"HFS", "BD", 2, 0, 1 },
    { L"HFS", "BD", 2, 0, 1 },
    { L"HFS", "H+", 2, 0, 1 },
    { L"HFS", "HX", 2, 0, 1 },
    { L"Minix", "\177\023", 2, 0x10, 1 },
    { L"Minix", "\217\023", 2, 0x10, 1 },
    { L"Minix", "\023\177", 2, 0x10, 1 },
    { L"Minix", "\023\217", 2, 0x10, 1 },
    { L"Minix", "\150\044", 2, 0x10, 1 },
    { L"Minix", "\170\044", 2, 0x10, 1 },
    { L"Minix", "\044\150", 2, 0x10, 1 },
    { L"Minix", "\044\170", 2, 0x10, 1 },
    { L"Minix", "\132\115", 2, 0x10, 1 },
    { L"Minix", "\115\132", 2, 0x10, 1 },
    { L"OCFS", "OCFSV2", 6, 0, 1 },
    { L"SysV", "\x2b\x55\x44", 3, 0x400, 1 },
    { L"SysV", "\x44\x55\x2b", 3, 0x400, 1 },
    { L"VXFS", "\365\374\001\245", 4, 0, 1 },
    { L"OCFS", "OCFSV2", 6, 0, 2 },
    { L"ExFAT", "EXFAT   ", 8, 3 },
    { L"NTFS", "NTFS    ", 8, 3 },
    { L"NetWare", "SPB5", 4, 0, 4 },
    { L"OCFS", "OCFSV2", 6, 0, 4 },
    { L"HPFS", "\x49\xe8\x95\xf9", 4, 0, 8 },
    { L"OCFS", "OracleCFS", 9, 0, 8 },
    { L"OCFS", "OCFSV2", 6, 0, 8 },
    { L"ReFS", "\000\000\000ReFS\000", 8 },
    { L"ReiserFS", "ReIsErFs",  8, 0x34, 8 },
    { L"ReiserFS", "ReIsErFs",  8, 20,  8 },
    { L"ISO9660", "CD001", 5, 1, 32, },
    { L"ISO9660", "CDROM", 5, 9, 32, },
    { L"JFS", "JFS1", 4, 0, 32 },
    { L"OCFS", "ORCLDISK", 8, 32 },
    { L"UDF", "BEA01", 5, 1, 32 },
    { L"UDF", "BOOT2", 5, 1, 32 },
    { L"UDF", "CD001", 5, 1, 32 },
    { L"UDF", "CDW02", 5, 1, 32 },
    { L"UDF", "NSR02", 5, 1, 32 },
    { L"UDF", "NSR03", 5, 1, 32 },
    { L"UDF", "TEA01", 5, 1, 32 },
    { L"Btrfs", "_BHRfS_M", 8, 0x40, 64 },
    { L"GFS", "\x01\x16\x19\x70", 4, 0, 64 },
    { L"GFS", "\x01\x16\x19\x70", 4, 0, 64 },
    { L"ReiserFS", "ReIsEr2Fs", 9, 0x34, 64 },
    { L"ReiserFS", "ReIsEr3Fs", 9, 0x34, 64 },
    { L"ReiserFS", "ReIsErFs",  8, 0x34, 64 },
    { L"ReiserFS", "ReIsEr4", 7, 0, 64 },
    { L"VMFS", "\x0d\xd0\x01\xc0", 4, 0, 1024 },
    { L"VMFS", "\x5e\xf1\xab\x2f", 4, 0, 2048 },
    { L"FAT", "MSWIN",    5, 0x52, 0 },
    { L"FAT", "FAT32   ", 8, 0x52, 0 },
    { L"FAT", "MSDOS",    5, 0x36, 0 },
    { L"FAT", "FAT16   ", 8, 0x36, 0 },
    { L"FAT", "FAT12   ", 8, 0x36, 0 },
    { L"FAT", "FAT     ", 8, 0x36, 0 },
    { L"FAT", "\353",     1, 0, 0 },
    { L"FAT", "\351",     1, 0, 0},
    { L"FAT", "\125\252", 2, 0x1fe, 0 },
    { nullptr, 0, 0, 0 }
};

class BtrfsDeviceAdd {
public:
    INT_PTR CALLBACK DeviceAddDlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
    void ShowDialog();
    void AddDevice(HWND hwndDlg);
    BtrfsDeviceAdd(HINSTANCE hinst, HWND hwnd, WCHAR* cmdline);

private:
    void populate_device_tree(HWND tree);

    HINSTANCE hinst;
    HWND hwnd;
    WCHAR* cmdline;
    device* sel;
    vector<device> device_list;
};

class BtrfsDeviceResize {
public:
    INT_PTR CALLBACK DeviceResizeDlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
    void ShowDialog(HWND hwnd, const wstring& fn, uint64_t dev_id);

private:
    void do_resize(HWND hwndDlg);

    uint64_t dev_id, new_size;
    wstring fn;
    WCHAR new_size_text[255];
    btrfs_device dev_info;
};