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 OnAdvanced();
54 static void UpdateControls();
55 static BOOL OnSalvage();
56 static DWORD WINAPI Salvage(LPVOID param);
58 BOOL CALLBACK SalvageDlgProc(HWND hDlg, UINT msg, WPARAM wp, LPARAM lp);
62 * EXPORTED FUNCTIONS _________________________________________________________
65 BOOL ShowSalvageDlg(HWND hParent, LPCTSTR pszPartitionName)
67 ASSERT(pszPartitionName);
69 lstrcpy(szPartitionName, pszPartitionName);
71 int nResult = ModalDialog(IDD_SALVAGE, hParent, (DLGPROC)SalvageDlgProc);
76 // Create a thread to perform the salvage
78 g_CfgData.hSalvageThread = CreateThread(0, 0, Salvage, 0, 0, &dwThreadID);
80 return (g_CfgData.hSalvageThread != 0);
85 * Dialog Proc _________________________________________________________________
88 BOOL CALLBACK SalvageDlgProc(HWND hwndDlg, UINT msg, WPARAM wp, LPARAM lp)
90 if (AfsAppLib_HandleHelp(IDD_SALVAGE, hwndDlg, msg, wp, lp))
95 OnInitDialog(hwndDlg);
100 case IDC_VOLUME_NAME:
101 case IDC_NUM_PROCESSES:
104 if (HIWORD(wp) == EN_CHANGE)
111 case IDC_NUM_PROCESSES_CHECKBOX:
120 EndDialog(hDlg, IDCANCEL);
125 EndDialog(hDlg, IDOK);
136 * STATIC FUNCTIONS _________________________________________________________________
141 * Event Handler Functions _________________________________________________________________
144 static void OnInitDialog(HWND hwndDlg)
150 TCHAR szNumProcesses[32];
151 _itot(DEFAULT_NUM_PROCESSES, szNumProcesses, 10);
153 SetWndText(hDlg, IDC_NUM_PROCESSES, szNumProcesses);
154 SetCheck(hDlg, IDC_NUM_PROCESSES_CHECKBOX);
155 SetWndText(hDlg, IDC_LOG_FILE, A2S(DEFAULT_LOG_FILE));
157 // If a partition name isn't selected, then only allow the salvage server option
158 if (szPartitionName[0] == 0) {
159 SetEnable(hDlg, IDC_PARTITION, ES_DISABLE);
160 SetEnable(hDlg, IDC_VOLUME, ES_DISABLE);
161 SetCheck(hDlg, IDC_SERVER);
163 SetCheck(hDlg, IDC_PARTITION);
165 // Close the Advanced portion of the dialog
169 static void OnAdvanced()
171 static int nOffset = 0;
173 bAdvanced = !bAdvanced;
175 ShowAndEnable(hDlg, IDC_ADVANCED_FRAME, bAdvanced);
176 ShowAndEnable(hDlg, IDC_LOG_FILE, bAdvanced);
177 ShowAndEnable(hDlg, IDC_LOG_FILE_LABEL, bAdvanced);
178 ShowAndEnable(hDlg, IDC_NUM_PROCESSES, bAdvanced);
179 ShowAndEnable(hDlg, IDC_TEMP_DIR, bAdvanced);
180 ShowAndEnable(hDlg, IDC_TEMP_DIR_LABEL, bAdvanced);
181 ShowAndEnable(hDlg, IDC_NUM_PROCESSES_CHECKBOX, bAdvanced);
182 ShowAndEnable(hDlg, IDC_DAMAGED_VOLUMES, bAdvanced);
183 ShowAndEnable(hDlg, IDC_SMALL_BLOCK_READS, bAdvanced);
184 ShowAndEnable(hDlg, IDC_FORCE_SALVAGE, bAdvanced);
185 ShowAndEnable(hDlg, IDC_FORCE_REBUILD, bAdvanced);
186 ShowAndEnable(hDlg, IDC_LIST_DAMAGED_INODES, bAdvanced);
187 ShowAndEnable(hDlg, IDC_LIST_OWNED_INDOES, bAdvanced);
189 // To show or hide the advanced section, we have to resize the dialog
191 // Get current position of the dialog
193 GetWindowRect(hDlg, &rectDlg);
195 // Figure out offset between full dialog and short dialog
197 // Find the frame containing the things we will hide or show
198 HWND hFrame = GetDlgItem(hDlg, IDC_ADVANCED_FRAME);
200 // Get its dimensions
202 GetWindowRect(hFrame, &rectFrame);
204 // Find the distance between the bottom of the dialog and the top of the frame
205 nOffset = rectDlg.bottom - rectFrame.top - 3;
208 int nCurOffset = nOffset;
213 // Adjust dialog position
214 MoveWindow(hDlg, rectDlg.left, rectDlg.top, rectDlg.right - rectDlg.left, rectDlg.bottom - rectDlg.top + nCurOffset, TRUE);
216 SetWndText(hDlg, IDC_ADVANCED, bAdvanced ? IDS_ADVANCED_OPEN : IDS_ADVANCED_CLOSED);
219 static void UpdateControls()
221 // Update volume name controls
222 BOOL bVolume = IsButtonChecked(hDlg, IDC_VOLUME);
223 ENABLE_STATE es = bVolume ? ES_ENABLE : ES_DISABLE;
224 SetEnable(hDlg, IDC_VOLUME_NAME, es);
225 SetEnable(hDlg, IDC_VOLUME_NAME_LABEL, es);
226 GetWndText(hDlg, IDC_VOLUME_NAME, szVolumeName);
228 // Num processes edit control
229 BOOL bParallel = IsButtonChecked(hDlg, IDC_NUM_PROCESSES_CHECKBOX);
230 SetEnable(hDlg, IDC_NUM_PROCESSES, (ENABLE_STATE)bParallel);
231 GetWndText(hDlg, IDC_NUM_PROCESSES, szNumProcesses, NUM_PROCS_BUF_SIZE);
233 GetWndText(hDlg, IDC_LOG_FILE, g_CfgData.szSalvageLogFileName, _MAX_PATH);
234 GetWndText(hDlg, IDC_TEMP_DIR, szTempDir, _MAX_PATH);
236 // Should OK button be enabled or disabled?
240 bEnable = !!lstrlen(szVolumeName);
242 if (bEnable && bParallel)
243 bEnable = !!lstrlen(szNumProcesses);
245 SetEnable(hDlg, IDOK, (ENABLE_STATE)bEnable);
249 * Utility Functions _________________________________________________________________
252 static BOOL OnSalvage()
254 if (IsButtonChecked(hDlg, IDC_SERVER)) {
255 pszPartitionName = 0;
257 } else if (IsButtonChecked(hDlg, IDC_PARTITION)) {
258 pszPartitionName = szPartitionName;
260 } else if (IsButtonChecked(hDlg, IDC_VOLUME)) {
261 pszPartitionName = szPartitionName;
262 pszVolumeName = szVolumeName;
265 nNumProcesses = DEFAULT_NUM_PROCESSES;
266 if (IsButtonChecked(hDlg, IDC_NUM_PROCESSES_CHECKBOX)) {
267 nNumProcesses = _ttoi(szNumProcesses);
268 if ((nNumProcesses < MIN_NUM_PROCESSES) || (nNumProcesses > MAX_NUM_PROCESSES)) {
269 ShowError(hDlg, 0, IDS_INVALID_NUM_SALVAGE_PROCESSSES);
274 if (!g_CfgData.bReuseAdminInfo) {
275 if (!GetAdminInfo(hDlg, GAIO_LOGIN_ONLY))
278 if (!GetHandles(hDlg))
285 static DWORD WINAPI Salvage(LPVOID param)
287 afs_status_t nStatus;
291 nResult = bos_ServerOpen(g_hCell, GetHostnameA(), &hServer, &nStatus);
293 ShowError(hDlg, nStatus, IDS_BOS_OPEN_FAILED);
297 nResult = bos_Salvage(g_hCell, hServer, S2A(pszPartitionName), S2A(pszVolumeName), nNumProcesses, S2A(szTempDir), 0, VOS_NORMAL,
298 BOS_SALVAGE_DAMAGED_VOLUMES, BOS_SALVAGE_DONT_WRITE_INODES, BOS_SALVAGE_DONT_WRITE_ROOT_INODES,
299 BOS_SALVAGE_DONT_FORCE_DIRECTORIES, BOS_SALVAGE_DONT_FORCE_BLOCK_READS, &nStatus);
301 ShowError(hDlg, nStatus, IDS_SALVAGE_ERROR);
303 bos_ServerClose(hServer, &nStatus);
305 g_CfgData.bReuseAdminInfo = nResult;