2 * Copyright 2000, International Business Machines Corporation and others.
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
11 * INCLUDES ___________________________________________________________________
15 #include <afs/param.h>
19 #include "afscfg.h" // Main header for this application
22 #include "afs_bosAdmin.h"
24 #include "admin_info_dlg.h"
28 * DEFINITIONS _________________________________________________________________
31 static const int DEFAULT_NUM_PROCESSES = 4;
32 static const char *DEFAULT_LOG_FILE = "";
33 static const int NUM_PROCS_BUF_SIZE = 5;
34 static const int MIN_NUM_PROCESSES = 1;
35 static const int MAX_NUM_PROCESSES = 32;
37 static HWND hDlg = 0; // HWND for this page's dialog
38 static BOOL bAdvanced;
39 static TCHAR szPartitionName[25];
40 static TCHAR szVolumeName[cchRESOURCE];
41 static TCHAR szNumProcesses[NUM_PROCS_BUF_SIZE];
42 static TCHAR szTempDir[_MAX_PATH];
43 static LPTSTR pszPartitionName;
44 static LPTSTR pszVolumeName;
45 static int nNumProcesses;
49 * PROTOTYPES _________________________________________________________________
52 static void OnInitDialog(HWND hwndDlg);
53 static void CheckEnableButtons();
54 static void OnAdvanced();
55 static void UpdateControls();
56 static BOOL OnSalvage();
57 static DWORD WINAPI Salvage(LPVOID param);
59 BOOL CALLBACK SalvageDlgProc(HWND hDlg, UINT msg, WPARAM wp, LPARAM lp);
63 * EXPORTED FUNCTIONS _________________________________________________________
66 BOOL ShowSalvageDlg(HWND hParent, LPCTSTR pszPartitionName)
68 ASSERT(pszPartitionName);
70 lstrcpy(szPartitionName, pszPartitionName);
72 int nResult = ModalDialog(IDD_SALVAGE, hParent, (DLGPROC)SalvageDlgProc);
77 // Create a thread to perform the salvage
79 g_CfgData.hSalvageThread = CreateThread(0, 0, Salvage, 0, 0, &dwThreadID);
81 return (g_CfgData.hSalvageThread != 0);
86 * Dialog Proc _________________________________________________________________
89 BOOL CALLBACK SalvageDlgProc(HWND hwndDlg, UINT msg, WPARAM wp, LPARAM lp)
91 if (AfsAppLib_HandleHelp(IDD_SALVAGE, hwndDlg, msg, wp, lp))
96 OnInitDialog(hwndDlg);
100 switch (LOWORD(wp)) {
101 case IDC_VOLUME_NAME:
102 case IDC_NUM_PROCESSES:
105 if (HIWORD(wp) == EN_CHANGE)
112 case IDC_NUM_PROCESSES_CHECKBOX:
121 EndDialog(hDlg, IDCANCEL);
126 EndDialog(hDlg, IDOK);
137 * STATIC FUNCTIONS _________________________________________________________________
142 * Event Handler Functions _________________________________________________________________
145 static void OnInitDialog(HWND hwndDlg)
151 TCHAR szNumProcesses[32];
152 _itot(DEFAULT_NUM_PROCESSES, szNumProcesses, 10);
154 SetWndText(hDlg, IDC_NUM_PROCESSES, szNumProcesses);
155 SetCheck(hDlg, IDC_NUM_PROCESSES_CHECKBOX);
156 SetWndText(hDlg, IDC_LOG_FILE, A2S(DEFAULT_LOG_FILE));
158 // If a partition name isn't selected, then only allow the salvage server option
159 if (szPartitionName[0] == 0) {
160 SetEnable(hDlg, IDC_PARTITION, ES_DISABLE);
161 SetEnable(hDlg, IDC_VOLUME, ES_DISABLE);
162 SetCheck(hDlg, IDC_SERVER);
164 SetCheck(hDlg, IDC_PARTITION);
166 // Close the Advanced portion of the dialog
170 static void OnAdvanced()
172 static int nOffset = 0;
174 bAdvanced = !bAdvanced;
176 ShowAndEnable(hDlg, IDC_ADVANCED_FRAME, bAdvanced);
177 ShowAndEnable(hDlg, IDC_LOG_FILE, bAdvanced);
178 ShowAndEnable(hDlg, IDC_LOG_FILE_LABEL, bAdvanced);
179 ShowAndEnable(hDlg, IDC_NUM_PROCESSES, bAdvanced);
180 ShowAndEnable(hDlg, IDC_TEMP_DIR, bAdvanced);
181 ShowAndEnable(hDlg, IDC_TEMP_DIR_LABEL, bAdvanced);
182 ShowAndEnable(hDlg, IDC_NUM_PROCESSES_CHECKBOX, bAdvanced);
183 ShowAndEnable(hDlg, IDC_DAMAGED_VOLUMES, bAdvanced);
184 ShowAndEnable(hDlg, IDC_SMALL_BLOCK_READS, bAdvanced);
185 ShowAndEnable(hDlg, IDC_FORCE_SALVAGE, bAdvanced);
186 ShowAndEnable(hDlg, IDC_FORCE_REBUILD, bAdvanced);
187 ShowAndEnable(hDlg, IDC_LIST_DAMAGED_INODES, bAdvanced);
188 ShowAndEnable(hDlg, IDC_LIST_OWNED_INDOES, bAdvanced);
190 // To show or hide the advanced section, we have to resize the dialog
192 // Get current position of the dialog
194 GetWindowRect(hDlg, &rectDlg);
196 // Figure out offset between full dialog and short dialog
198 // Find the frame containing the things we will hide or show
199 HWND hFrame = GetDlgItem(hDlg, IDC_ADVANCED_FRAME);
201 // Get its dimensions
203 GetWindowRect(hFrame, &rectFrame);
205 // Find the distance between the bottom of the dialog and the top of the frame
206 nOffset = rectDlg.bottom - rectFrame.top - 3;
209 int nCurOffset = nOffset;
214 // Adjust dialog position
215 MoveWindow(hDlg, rectDlg.left, rectDlg.top, rectDlg.right - rectDlg.left, rectDlg.bottom - rectDlg.top + nCurOffset, TRUE);
217 SetWndText(hDlg, IDC_ADVANCED, bAdvanced ? IDS_ADVANCED_OPEN : IDS_ADVANCED_CLOSED);
220 static void UpdateControls()
222 // Update volume name controls
223 BOOL bVolume = IsButtonChecked(hDlg, IDC_VOLUME);
224 ENABLE_STATE es = bVolume ? ES_ENABLE : ES_DISABLE;
225 SetEnable(hDlg, IDC_VOLUME_NAME, es);
226 SetEnable(hDlg, IDC_VOLUME_NAME_LABEL, es);
227 GetWndText(hDlg, IDC_VOLUME_NAME, szVolumeName);
229 // Num processes edit control
230 BOOL bParallel = IsButtonChecked(hDlg, IDC_NUM_PROCESSES_CHECKBOX);
231 SetEnable(hDlg, IDC_NUM_PROCESSES, (ENABLE_STATE)bParallel);
232 GetWndText(hDlg, IDC_NUM_PROCESSES, szNumProcesses, NUM_PROCS_BUF_SIZE);
234 GetWndText(hDlg, IDC_LOG_FILE, g_CfgData.szSalvageLogFileName, _MAX_PATH);
235 GetWndText(hDlg, IDC_TEMP_DIR, szTempDir, _MAX_PATH);
237 // Should OK button be enabled or disabled?
241 bEnable = !!lstrlen(szVolumeName);
243 if (bEnable && bParallel)
244 bEnable = !!lstrlen(szNumProcesses);
246 SetEnable(hDlg, IDOK, (ENABLE_STATE)bEnable);
250 * Utility Functions _________________________________________________________________
253 static BOOL OnSalvage()
255 if (IsButtonChecked(hDlg, IDC_SERVER)) {
256 pszPartitionName = 0;
258 } else if (IsButtonChecked(hDlg, IDC_PARTITION)) {
259 pszPartitionName = szPartitionName;
261 } else if (IsButtonChecked(hDlg, IDC_VOLUME)) {
262 pszPartitionName = szPartitionName;
263 pszVolumeName = szVolumeName;
266 nNumProcesses = DEFAULT_NUM_PROCESSES;
267 if (IsButtonChecked(hDlg, IDC_NUM_PROCESSES_CHECKBOX)) {
268 nNumProcesses = _ttoi(szNumProcesses);
269 if ((nNumProcesses < MIN_NUM_PROCESSES) || (nNumProcesses > MAX_NUM_PROCESSES)) {
270 ShowError(hDlg, 0, IDS_INVALID_NUM_SALVAGE_PROCESSSES);
275 if (!g_CfgData.bReuseAdminInfo) {
276 if (!GetAdminInfo(hDlg, GAIO_LOGIN_ONLY))
279 if (!GetHandles(hDlg))
286 static DWORD WINAPI Salvage(LPVOID param)
288 afs_status_t nStatus;
292 nResult = bos_ServerOpen(g_hCell, GetHostnameA(), &hServer, &nStatus);
294 ShowError(hDlg, nStatus, IDS_BOS_OPEN_FAILED);
298 nResult = bos_Salvage(g_hCell, hServer, S2A(pszPartitionName), S2A(pszVolumeName), nNumProcesses, S2A(szTempDir), 0, VOS_NORMAL,
299 BOS_SALVAGE_DAMAGED_VOLUMES, BOS_SALVAGE_DONT_WRITE_INODES, BOS_SALVAGE_DONT_WRITE_ROOT_INODES,
300 BOS_SALVAGE_DONT_FORCE_DIRECTORIES, BOS_SALVAGE_DONT_FORCE_BLOCK_READS, &nStatus);
302 ShowError(hDlg, nStatus, IDS_SALVAGE_ERROR);
304 bos_ServerClose(hServer, &nStatus);
306 g_CfgData.bReuseAdminInfo = nResult;