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 #include <shlobj.h> 21 #include <deque> 22 #ifndef __REACTOS__ 23 #include "../btrfsioctl.h" 24 #else 25 #include "btrfsioctl.h" 26 #endif 27 28 #ifndef S_IRUSR 29 #define S_IRUSR 0000400 30 #endif 31 32 #ifndef S_IWUSR 33 #define S_IWUSR 0000200 34 #endif 35 36 #ifndef S_IXUSR 37 #define S_IXUSR 0000100 38 #endif 39 40 #ifndef S_IRGRP 41 #define S_IRGRP (S_IRUSR >> 3) 42 #endif 43 44 #ifndef S_IWGRP 45 #define S_IWGRP (S_IWUSR >> 3) 46 #endif 47 48 #ifndef S_IXGRP 49 #define S_IXGRP (S_IXUSR >> 3) 50 #endif 51 52 #ifndef S_IROTH 53 #define S_IROTH (S_IRGRP >> 3) 54 #endif 55 56 #ifndef S_IWOTH 57 #define S_IWOTH (S_IWGRP >> 3) 58 #endif 59 60 #ifndef S_IXOTH 61 #define S_IXOTH (S_IXGRP >> 3) 62 #endif 63 64 #ifndef S_ISUID 65 #define S_ISUID 0004000 66 #endif 67 68 #ifndef S_ISGID 69 #define S_ISGID 0002000 70 #endif 71 72 #ifndef S_ISVTX 73 #define S_ISVTX 0001000 74 #endif 75 76 #define BTRFS_INODE_NODATASUM 0x001 77 #define BTRFS_INODE_NODATACOW 0x002 78 #define BTRFS_INODE_READONLY 0x004 79 #define BTRFS_INODE_NOCOMPRESS 0x008 80 #define BTRFS_INODE_PREALLOC 0x010 81 #define BTRFS_INODE_SYNC 0x020 82 #define BTRFS_INODE_IMMUTABLE 0x040 83 #define BTRFS_INODE_APPEND 0x080 84 #define BTRFS_INODE_NODUMP 0x100 85 #define BTRFS_INODE_NOATIME 0x200 86 #define BTRFS_INODE_DIRSYNC 0x400 87 #define BTRFS_INODE_COMPRESS 0x800 88 89 extern LONG objs_loaded; 90 91 class BtrfsPropSheet : public IShellExtInit, IShellPropSheetExt { 92 public: 93 BtrfsPropSheet() { 94 refcount = 0; 95 ignore = true; 96 stgm_set = false; 97 readonly = false; 98 flags_changed = false; 99 perms_changed = false; 100 uid_changed = false; 101 gid_changed = false; 102 compress_type_changed = false; 103 ro_changed = false; 104 can_change_perms = false; 105 show_admin_button = false; 106 thread = nullptr; 107 mode = mode_set = 0; 108 flags = flags_set = 0; 109 has_subvols = false; 110 filename = L""; 111 112 sizes[0] = sizes[1] = sizes[2] = sizes[3] = sizes[4] = 0; 113 totalsize = allocsize = sparsesize = 0; 114 num_extents = 0; 115 sector_size = 0; 116 size_format[0] = 0; 117 cr_format[0] = 0; 118 frag_format[0] = 0; 119 120 InterlockedIncrement(&objs_loaded); 121 } 122 123 virtual ~BtrfsPropSheet() { 124 if (stgm_set) { 125 GlobalUnlock(stgm.hGlobal); 126 ReleaseStgMedium(&stgm); 127 } 128 129 InterlockedDecrement(&objs_loaded); 130 } 131 132 // IUnknown 133 134 HRESULT __stdcall QueryInterface(REFIID riid, void **ppObj); 135 136 ULONG __stdcall AddRef() { 137 return InterlockedIncrement(&refcount); 138 } 139 140 ULONG __stdcall Release() { 141 LONG rc = InterlockedDecrement(&refcount); 142 143 if (rc == 0) 144 delete this; 145 146 return rc; 147 } 148 149 // IShellExtInit 150 151 virtual HRESULT __stdcall Initialize(PCIDLIST_ABSOLUTE pidlFolder, IDataObject* pdtobj, HKEY hkeyProgID); 152 153 // IShellPropSheetExt 154 155 virtual HRESULT __stdcall AddPages(LPFNADDPROPSHEETPAGE pfnAddPage, LPARAM lParam); 156 virtual HRESULT __stdcall ReplacePage(UINT uPageID, LPFNADDPROPSHEETPAGE pfnReplacePage, LPARAM lParam); 157 158 void init_propsheet(HWND hwndDlg); 159 void change_inode_flag(HWND hDlg, uint64_t flag, UINT state); 160 void change_perm_flag(HWND hDlg, ULONG perm, UINT state); 161 void change_uid(HWND hDlg, uint32_t uid); 162 void change_gid(HWND hDlg, uint32_t gid); 163 void apply_changes(HWND hDlg); 164 void set_size_on_disk(HWND hwndDlg); 165 DWORD search_list_thread(); 166 void do_search(const wstring& fn); 167 void update_size_details_dialog(HWND hDlg); 168 void open_as_admin(HWND hwndDlg); 169 void set_cmdline(const wstring& cmdline); 170 171 bool readonly; 172 bool can_change_perms; 173 bool can_change_nocow; 174 WCHAR size_format[255], cr_format[255], frag_format[255]; 175 HANDLE thread; 176 uint32_t min_mode, max_mode, mode, mode_set; 177 uint64_t min_flags, max_flags, flags, flags_set; 178 uint64_t subvol, inode, rdev; 179 uint8_t type, min_compression_type, max_compression_type, compress_type; 180 uint32_t uid, gid; 181 bool various_subvols, various_inodes, various_types, various_uids, various_gids, compress_type_changed, has_subvols, 182 ro_subvol, various_ro, ro_changed, show_admin_button; 183 184 private: 185 LONG refcount; 186 bool ignore; 187 STGMEDIUM stgm; 188 bool stgm_set; 189 bool flags_changed, perms_changed, uid_changed, gid_changed; 190 uint64_t sizes[5], totalsize, allocsize, sparsesize, num_extents; 191 deque<wstring> search_list; 192 wstring filename; 193 uint32_t sector_size; 194 195 void apply_changes_file(HWND hDlg, const wstring& fn); 196 HRESULT check_file(const wstring& fn, UINT i, UINT num_files, UINT* sv); 197 HRESULT load_file_list(); 198 }; 199