xref: /reactos/dll/shellext/shellbtrfs/devices.h (revision 40462c92)
1 /* Copyright (c) Mark Harmstone 2016-17
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 #pragma once
19 
20 #ifndef __REACTOS__
21 #include <windows.h>
22 #include <winternl.h>
23 #else
24 #define WIN32_NO_STATUS
25 #include <windef.h>
26 #include <winbase.h>
27 #include <ndk/iofuncs.h>
28 #include <ndk/iotypes.h>
29 #endif
30 #include <shlobj.h>
31 #ifndef __REACTOS__
32 #include "../btrfsioctl.h"
33 #else
34 #include "btrfsioctl.h"
35 #endif
36 
37 typedef struct {
38     wstring pnp_name;
39     wstring friendly_name;
40     wstring drive;
41     wstring fstype;
42     ULONG disk_num;
43     ULONG part_num;
44     uint64_t size;
45     bool has_parts;
46     BTRFS_UUID fs_uuid;
47     BTRFS_UUID dev_uuid;
48     bool ignore;
49     bool multi_device;
50     bool is_disk;
51 } device;
52 
53 typedef struct {
54     const WCHAR* name;
55     const char* magic;
56     ULONG magiclen;
57     uint32_t sboff;
58     uint32_t kboff;
59 } fs_identifier;
60 
61 // This list is compiled from information in libblkid, part of util-linux
62 // and likewise under the LGPL. Thanks!
63 
64 const static fs_identifier fs_ident[] = {
65     { L"BeFS", "BFS1", 4, 0x20, 0 },
66     { L"BeFS", "1SFB", 4, 0x20, 0 },
67     { L"BeFS", "BFS1", 4, 0x220, 0 },
68     { L"BeFS", "1SFB", 4, 0x220, 0 },
69     { L"BFS", "\xce\xfa\xad\x1b", 4, 0, 0 },
70     { L"RomFS", "-rom1fs-", 8, 0, 0 },
71     { L"SquashFS", "hsqs", 4, 0, 0 },
72     { L"SquashFS", "sqsh", 4, 0, 0 },
73     { L"SquashFS", "hsqs", 4, 0, 0 },
74     { L"UBIFS", "\x31\x18\x10\x06", 4, 0, 0 },
75     { L"XFS", "XFSB", 4, 0, 0 },
76     { L"ext2", "\123\357", 2, 0x38, 1 },
77     { L"F2FS", "\x10\x20\xF5\xF2", 4, 0, 1 },
78     { L"HFS", "BD", 2, 0, 1 },
79     { L"HFS", "BD", 2, 0, 1 },
80     { L"HFS", "H+", 2, 0, 1 },
81     { L"HFS", "HX", 2, 0, 1 },
82     { L"Minix", "\177\023", 2, 0x10, 1 },
83     { L"Minix", "\217\023", 2, 0x10, 1 },
84     { L"Minix", "\023\177", 2, 0x10, 1 },
85     { L"Minix", "\023\217", 2, 0x10, 1 },
86     { L"Minix", "\150\044", 2, 0x10, 1 },
87     { L"Minix", "\170\044", 2, 0x10, 1 },
88     { L"Minix", "\044\150", 2, 0x10, 1 },
89     { L"Minix", "\044\170", 2, 0x10, 1 },
90     { L"Minix", "\132\115", 2, 0x10, 1 },
91     { L"Minix", "\115\132", 2, 0x10, 1 },
92     { L"OCFS", "OCFSV2", 6, 0, 1 },
93     { L"SysV", "\x2b\x55\x44", 3, 0x400, 1 },
94     { L"SysV", "\x44\x55\x2b", 3, 0x400, 1 },
95     { L"VXFS", "\365\374\001\245", 4, 0, 1 },
96     { L"OCFS", "OCFSV2", 6, 0, 2 },
97     { L"ExFAT", "EXFAT   ", 8, 3 },
98     { L"NTFS", "NTFS    ", 8, 3 },
99     { L"NetWare", "SPB5", 4, 0, 4 },
100     { L"OCFS", "OCFSV2", 6, 0, 4 },
101     { L"HPFS", "\x49\xe8\x95\xf9", 4, 0, 8 },
102     { L"OCFS", "OracleCFS", 9, 0, 8 },
103     { L"OCFS", "OCFSV2", 6, 0, 8 },
104     { L"ReFS", "\000\000\000ReFS\000", 8 },
105     { L"ReiserFS", "ReIsErFs",  8, 0x34, 8 },
106     { L"ReiserFS", "ReIsErFs",  8, 20,  8 },
107     { L"ISO9660", "CD001", 5, 1, 32, },
108     { L"ISO9660", "CDROM", 5, 9, 32, },
109     { L"JFS", "JFS1", 4, 0, 32 },
110     { L"OCFS", "ORCLDISK", 8, 32 },
111     { L"UDF", "BEA01", 5, 1, 32 },
112     { L"UDF", "BOOT2", 5, 1, 32 },
113     { L"UDF", "CD001", 5, 1, 32 },
114     { L"UDF", "CDW02", 5, 1, 32 },
115     { L"UDF", "NSR02", 5, 1, 32 },
116     { L"UDF", "NSR03", 5, 1, 32 },
117     { L"UDF", "TEA01", 5, 1, 32 },
118     { L"Btrfs", "_BHRfS_M", 8, 0x40, 64 },
119     { L"GFS", "\x01\x16\x19\x70", 4, 0, 64 },
120     { L"GFS", "\x01\x16\x19\x70", 4, 0, 64 },
121     { L"ReiserFS", "ReIsEr2Fs", 9, 0x34, 64 },
122     { L"ReiserFS", "ReIsEr3Fs", 9, 0x34, 64 },
123     { L"ReiserFS", "ReIsErFs",  8, 0x34, 64 },
124     { L"ReiserFS", "ReIsEr4", 7, 0, 64 },
125     { L"VMFS", "\x0d\xd0\x01\xc0", 4, 0, 1024 },
126     { L"VMFS", "\x5e\xf1\xab\x2f", 4, 0, 2048 },
127     { L"FAT", "MSWIN",    5, 0x52, 0 },
128     { L"FAT", "FAT32   ", 8, 0x52, 0 },
129     { L"FAT", "MSDOS",    5, 0x36, 0 },
130     { L"FAT", "FAT16   ", 8, 0x36, 0 },
131     { L"FAT", "FAT12   ", 8, 0x36, 0 },
132     { L"FAT", "FAT     ", 8, 0x36, 0 },
133     { L"FAT", "\353",     1, 0, 0 },
134     { L"FAT", "\351",     1, 0, 0},
135     { L"FAT", "\125\252", 2, 0x1fe, 0 },
136     { nullptr, 0, 0, 0 }
137 };
138 
139 class BtrfsDeviceAdd {
140 public:
141     INT_PTR CALLBACK DeviceAddDlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
142     void ShowDialog();
143     void AddDevice(HWND hwndDlg);
144     BtrfsDeviceAdd(HINSTANCE hinst, HWND hwnd, WCHAR* cmdline);
145 
146 private:
147     void populate_device_tree(HWND tree);
148 
149     HINSTANCE hinst;
150     HWND hwnd;
151     WCHAR* cmdline;
152     device* sel;
153     vector<device> device_list;
154 };
155 
156 class BtrfsDeviceResize {
157 public:
158     INT_PTR CALLBACK DeviceResizeDlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
159     void ShowDialog(HWND hwnd, const wstring& fn, uint64_t dev_id);
160 
161 private:
162     void do_resize(HWND hwndDlg);
163 
164     uint64_t dev_id, new_size;
165     wstring fn;
166     WCHAR new_size_text[255];
167     btrfs_device dev_info;
168 };
169