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 ___________________________________________________________________
18 #include <afsconfig.h>
19 #include <afs/param.h>
24 #include "afscfg.h" // Main header for this application
27 #include <afs/afs_bosAdmin.h>
29 #include "admin_info_dlg.h"
33 * DEFINITIONS _________________________________________________________________
36 static const int DEFAULT_NUM_PROCESSES = 4;
37 static const char *DEFAULT_LOG_FILE = "";
38 static const int NUM_PROCS_BUF_SIZE = 5;
39 static const int MIN_NUM_PROCESSES = 1;
40 static const int MAX_NUM_PROCESSES = 32;
42 static HWND hDlg = 0; // HWND for this page's dialog
43 static BOOL bAdvanced;
44 static TCHAR szPartitionName[25];
45 static TCHAR szVolumeName[cchRESOURCE];
46 static TCHAR szNumProcesses[NUM_PROCS_BUF_SIZE];
47 static TCHAR szTempDir[_MAX_PATH];
48 static LPTSTR pszPartitionName;
49 static LPTSTR pszVolumeName;
50 static int nNumProcesses;
54 * PROTOTYPES _________________________________________________________________
57 static void OnInitDialog(HWND hwndDlg);
58 static void OnAdvanced();
59 static void UpdateControls();
60 static BOOL OnSalvage();
61 static DWORD WINAPI Salvage(LPVOID param);
63 BOOL CALLBACK SalvageDlgProc(HWND hDlg, UINT msg, WPARAM wp, LPARAM lp);
67 * EXPORTED FUNCTIONS _________________________________________________________
70 BOOL ShowSalvageDlg(HWND hParent, LPCTSTR pszPartitionName)
72 ASSERT(pszPartitionName);
74 lstrcpy(szPartitionName, pszPartitionName);
76 int nResult = ModalDialog(IDD_SALVAGE, hParent, (DLGPROC)SalvageDlgProc);
81 // Create a thread to perform the salvage
83 g_CfgData.hSalvageThread = CreateThread(0, 0, Salvage, 0, 0, &dwThreadID);
85 return (g_CfgData.hSalvageThread != 0);
90 * Dialog Proc _________________________________________________________________
93 BOOL CALLBACK SalvageDlgProc(HWND hwndDlg, UINT msg, WPARAM wp, LPARAM lp)
95 if (AfsAppLib_HandleHelp(IDD_SALVAGE, hwndDlg, msg, wp, lp))
100 OnInitDialog(hwndDlg);
104 switch (LOWORD(wp)) {
105 case IDC_VOLUME_NAME:
106 case IDC_NUM_PROCESSES:
109 if (HIWORD(wp) == EN_CHANGE)
116 case IDC_NUM_PROCESSES_CHECKBOX:
125 EndDialog(hDlg, IDCANCEL);
130 EndDialog(hDlg, IDOK);
141 * STATIC FUNCTIONS _________________________________________________________________
146 * Event Handler Functions _________________________________________________________________
149 static void OnInitDialog(HWND hwndDlg)
155 TCHAR szNumProcesses[32];
156 _itot(DEFAULT_NUM_PROCESSES, szNumProcesses, 10);
158 SetWndText(hDlg, IDC_NUM_PROCESSES, szNumProcesses);
159 SetCheck(hDlg, IDC_NUM_PROCESSES_CHECKBOX);
160 SetWndText(hDlg, IDC_LOG_FILE, A2S(DEFAULT_LOG_FILE));
162 // If a partition name isn't selected, then only allow the salvage server option
163 if (szPartitionName[0] == 0) {
164 SetEnable(hDlg, IDC_PARTITION, ES_DISABLE);
165 SetEnable(hDlg, IDC_VOLUME, ES_DISABLE);
166 SetCheck(hDlg, IDC_SERVER);
168 SetCheck(hDlg, IDC_PARTITION);
170 // Close the Advanced portion of the dialog
174 static void OnAdvanced()
176 static int nOffset = 0;
178 bAdvanced = !bAdvanced;
180 ShowAndEnable(hDlg, IDC_ADVANCED_FRAME, bAdvanced);
181 ShowAndEnable(hDlg, IDC_LOG_FILE, bAdvanced);
182 ShowAndEnable(hDlg, IDC_LOG_FILE_LABEL, bAdvanced);
183 ShowAndEnable(hDlg, IDC_NUM_PROCESSES, bAdvanced);
184 ShowAndEnable(hDlg, IDC_TEMP_DIR, bAdvanced);
185 ShowAndEnable(hDlg, IDC_TEMP_DIR_LABEL, bAdvanced);
186 ShowAndEnable(hDlg, IDC_NUM_PROCESSES_CHECKBOX, bAdvanced);
187 ShowAndEnable(hDlg, IDC_DAMAGED_VOLUMES, bAdvanced);
188 ShowAndEnable(hDlg, IDC_SMALL_BLOCK_READS, bAdvanced);
189 ShowAndEnable(hDlg, IDC_FORCE_SALVAGE, bAdvanced);
190 ShowAndEnable(hDlg, IDC_FORCE_REBUILD, bAdvanced);
191 ShowAndEnable(hDlg, IDC_LIST_DAMAGED_INODES, bAdvanced);
192 ShowAndEnable(hDlg, IDC_LIST_OWNED_INDOES, bAdvanced);
194 // To show or hide the advanced section, we have to resize the dialog
196 // Get current position of the dialog
198 GetWindowRect(hDlg, &rectDlg);
200 // Figure out offset between full dialog and short dialog
202 // Find the frame containing the things we will hide or show
203 HWND hFrame = GetDlgItem(hDlg, IDC_ADVANCED_FRAME);
205 // Get its dimensions
207 GetWindowRect(hFrame, &rectFrame);
209 // Find the distance between the bottom of the dialog and the top of the frame
210 nOffset = rectDlg.bottom - rectFrame.top - 3;
213 int nCurOffset = nOffset;
218 // Adjust dialog position
219 MoveWindow(hDlg, rectDlg.left, rectDlg.top, rectDlg.right - rectDlg.left, rectDlg.bottom - rectDlg.top + nCurOffset, TRUE);
221 SetWndText(hDlg, IDC_ADVANCED, bAdvanced ? IDS_ADVANCED_OPEN : IDS_ADVANCED_CLOSED);
224 static void UpdateControls()
226 // Update volume name controls
227 BOOL bVolume = IsButtonChecked(hDlg, IDC_VOLUME);
228 ENABLE_STATE es = bVolume ? ES_ENABLE : ES_DISABLE;
229 SetEnable(hDlg, IDC_VOLUME_NAME, es);
230 SetEnable(hDlg, IDC_VOLUME_NAME_LABEL, es);
231 GetWndText(hDlg, IDC_VOLUME_NAME, szVolumeName);
233 // Num processes edit control
234 BOOL bParallel = IsButtonChecked(hDlg, IDC_NUM_PROCESSES_CHECKBOX);
235 SetEnable(hDlg, IDC_NUM_PROCESSES, (ENABLE_STATE)bParallel);
236 GetWndText(hDlg, IDC_NUM_PROCESSES, szNumProcesses, NUM_PROCS_BUF_SIZE);
238 GetWndText(hDlg, IDC_LOG_FILE, g_CfgData.szSalvageLogFileName, _MAX_PATH);
239 GetWndText(hDlg, IDC_TEMP_DIR, szTempDir, _MAX_PATH);
241 // Should OK button be enabled or disabled?
245 bEnable = !!lstrlen(szVolumeName);
247 if (bEnable && bParallel)
248 bEnable = !!lstrlen(szNumProcesses);
250 SetEnable(hDlg, IDOK, (ENABLE_STATE)bEnable);
254 * Utility Functions _________________________________________________________________
257 static BOOL OnSalvage()
259 if (IsButtonChecked(hDlg, IDC_SERVER)) {
260 pszPartitionName = 0;
262 } else if (IsButtonChecked(hDlg, IDC_PARTITION)) {
263 pszPartitionName = szPartitionName;
265 } else if (IsButtonChecked(hDlg, IDC_VOLUME)) {
266 pszPartitionName = szPartitionName;
267 pszVolumeName = szVolumeName;
270 nNumProcesses = DEFAULT_NUM_PROCESSES;
271 if (IsButtonChecked(hDlg, IDC_NUM_PROCESSES_CHECKBOX)) {
272 nNumProcesses = _ttoi(szNumProcesses);
273 if ((nNumProcesses < MIN_NUM_PROCESSES) || (nNumProcesses > MAX_NUM_PROCESSES)) {
274 ShowError(hDlg, 0, IDS_INVALID_NUM_SALVAGE_PROCESSSES);
279 if (!g_CfgData.bReuseAdminInfo) {
280 if (!GetAdminInfo(hDlg, GAIO_LOGIN_ONLY))
283 if (!GetHandles(hDlg))
290 static DWORD WINAPI Salvage(LPVOID param)
292 afs_status_t nStatus;
296 nResult = bos_ServerOpen(g_hCell, GetHostnameA(), &hServer, &nStatus);
298 ShowError(hDlg, nStatus, IDS_BOS_OPEN_FAILED);
302 nResult = bos_Salvage(g_hCell, hServer, S2A(pszPartitionName), S2A(pszVolumeName), nNumProcesses, S2A(szTempDir), 0, VOS_NORMAL,
303 BOS_SALVAGE_DAMAGED_VOLUMES, BOS_SALVAGE_DONT_WRITE_INODES, BOS_SALVAGE_DONT_WRITE_ROOT_INODES,
304 BOS_SALVAGE_DONT_FORCE_DIRECTORIES, BOS_SALVAGE_DONT_FORCE_BLOCK_READS, &nStatus);
306 ShowError(hDlg, nStatus, IDS_SALVAGE_ERROR);
308 bos_ServerClose(hServer, &nStatus);
310 g_CfgData.bReuseAdminInfo = nResult;