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