// ======================================================= bool CImageDisk::doesFileExists(char *szPath) // [Main-Thread] { //return ::doesFileExists2(szPath); BEGIN; //FILE *fStream; #ifdef HAVE_FSTAT64 struct stat64 fStat; #else struct stat fStat; #endif int nFd; int nRes; errno = 0; if ( strcmp(szPath, "stdin") ) { #ifdef HAVE_OPEN64 nFd = open64(szPath, O_RDONLY | O_NOFOLLOW | O_LARGEFILE); #else nFd = open(szPath, O_RDONLY | O_NOFOLLOW | O_LARGEFILE); #endif } else { // it's stdin nFd=0; return true; } showDebug(3, "doesFileExists(%s) =>%d\n",szPath,nFd); //fStream = fopen(szPath, "rb"); //if (!fStream) // error if (nFd == -1) { RETURN_int (errno != ENOENT); } else // success { #ifdef HAVE_FSTAT64 nRes = fstat64(nFd, &fStat); #else nRes = fstat(nFd, &fStat); #endif showDebug(3, "fstat() returned %d\n", nRes); if (nRes == -1) return true; // for large files //fclose(fStream); ::close(nFd); showDebug(3, "fStat.st_mode=%ld\n",(long)fStat.st_mode); RETURN_int(S_ISREG(fStat.st_mode)); } }
// ======================================================= int CRestoreOptWindow::create(char *szDevice, char *szImageFile, COptions options) { BEGIN; char szTemp[1024]; SNPRINTF(szTemp, i18n("restore partition from image file")); newtCenteredWindow(78, 20, szTemp); m_labelOptions = newtLabel(1, 1, i18n("Options")); m_checkEraseWithNull = newtCheckbox(1, 3, i18n("Erase free blocks with zero values"), (!!options.bEraseWithNull ? 'X' : ' '), " X", NULL); m_checkSimulateMode = newtCheckbox(1, 2, i18n("Simulation of the restoration (nothing is written)"), (!!options.bSimulateMode ? 'X' : ' '), " X", NULL); m_labelFinish = newtLabel(1, 5, i18n("If finished successfully:")); m_radioFinishWait = newtRadiobutton(1, 6, i18n("Wait"), options.dwFinish == FINISH_WAIT, NULL); m_radioFinishHalt = newtRadiobutton(1, 7, i18n("Halt"), options.dwFinish == FINISH_HALT, m_radioFinishWait); m_radioFinishReboot = newtRadiobutton(1, 8, i18n("Reboot"), options.dwFinish == FINISH_REBOOT, m_radioFinishHalt); m_radioFinishQuit = newtRadiobutton(1, 9, i18n("Quit"), options.dwFinish == FINISH_QUIT, m_radioFinishReboot); addButtons(); m_formMain = newtForm(NULL, NULL, 0); newtFormAddComponents(m_formMain, m_labelOptions, m_checkSimulateMode, m_checkEraseWithNull, NULL); newtFormAddComponents(m_formMain, m_labelFinish, m_radioFinishWait, m_radioFinishHalt, m_radioFinishReboot, m_radioFinishQuit, NULL); //newtFormAddComponents(m_formMain, m_btnRestore, m_btnExit, NULL); addHotKeys(); newtDrawForm(m_formMain); RETURN_int(0); }
// ======================================================= int CBlocksUseBitmap::readBitmap(DWORD dwPos, bool *bUsed, DWORD *dwBitsCount) { if (m_cBitmap == NULL) RETURN_int(-1); // is the next bit used or free ? *bUsed = isBitSet(dwPos++); *dwBitsCount = 1; // currently, 1 bit has been read // copy all the bits which are in the same state than the first one // TODO: use the real bits count in the bitmap insted of (8*m_dwBitmapSize) //showDebug(0, "m_dwMaxUsedBlocksCopiedPerOper=%lu\n",m_dwMaxUsedBlocksCopiedPerOper); //showDebug(0, "TTT: used=%d, state(+1)=%d,state(+2)=%d,state(+3)=%d\n",(int)*bUsed,(int)isBitSet(dwPos),isBitSet(dwPos+1),isBitSet(dwPos+2),isBitSet(dwPos+3)); // If we have used bits if (*bUsed) while ((dwPos < (8*m_dwBitmapSize)) && (*dwBitsCount < m_dwMaxUsedBlocksCopiedPerOper) && (isBitSet(dwPos) == true)) { (*dwBitsCount)++; dwPos++; } else // if free while ((dwPos < (8*m_dwBitmapSize)) && (*dwBitsCount < m_dwMaxFreeBlocksCopiedPerOper) && (isBitSet(dwPos) == false)) { (*dwBitsCount)++; dwPos++; } return 0; // success }
// ======================================================= int CBlocksUseBitmap::setBit(DWORD dwBit, bool bState) { if (m_cBitmap == NULL) RETURN_int(-1); DWORD dwLocalBit; DWORD dwByte; dwLocalBit = dwBit % 8; dwByte = (dwBit - dwLocalBit) / 8; //printf ("dwBit=%ld ==> (byte,bit)=(%ld,%ld)\n", dwByte, dwLocalBit); // if we must set the bit if (bState == true) { SET_BIT(m_cBitmap[dwByte], dwLocalBit, 1); //m_cBitmap[dwByte] |= g_dwBit[dwLocalBit]; } else // if we must unset the bit { SET_BIT(m_cBitmap[dwByte], dwLocalBit, 0); //m_cBitmap[dwByte] &= ~g_dwBit[dwLocalBit]; } return 0; }
// ======================================================= int CRestoreMbrWindow::create() { BEGIN; char szTemp[2048]; SNPRINTF(szTemp, "%s", i18n("Restore an MBR to the hard disk")); newtCenteredWindow(78, 20, szTemp); m_labelList1 = newtLabel(1, 1, i18n("Disk with the MBR to restore")); m_list1 = newtListbox(1, 2, 8, NEWT_FLAG_SCROLL); m_labelList2 = newtLabel(35, 1, i18n("Original MBR to use")); m_list2 = newtListbox(35, 2, 8, NEWT_FLAG_SCROLL); m_labelType = newtLabel(1, 12, i18n("What to restore:")); m_radioFull = newtRadiobutton(1, 13, i18n("The whole MBR"), true, NULL); m_radioBoot = newtRadiobutton(1, 14, "Only the boot loader", false, m_radioFull); m_radioTable = newtRadiobutton(1, 15, "Only the primary partitions table", false, m_radioBoot); addButtons(); m_formMain = newtForm(NULL, NULL, 0); newtFormAddComponents(m_formMain, m_labelList1, m_list1, m_labelList2, m_list2, m_labelType, m_radioFull, m_radioBoot, m_radioTable, NULL); //m_btnOkay, m_btnCancel, NULL); addHotKeys(); newtDrawForm(m_formMain); RETURN_int(0); }
// ======================================================= int CBlocksUseBitmap::fill(BYTE cValue) { BEGIN; DWORD i; DWORD dwMemSize; if (!m_cBitmap) // if memory was not allocated RETURN_int(-1); dwMemSize = m_dwBitmapSize / 8; for (i=0; i < dwMemSize; i++) m_cBitmap[i] = cValue; RETURN_int(0); }
// ======================================================= int CInterfaceNewt::askLogin(char *szLogin, char *szPasswd, WORD size) { newtComponent editLoginText; newtComponent editPasswdText; newtComponent labelLoginText; newtComponent labelPasswdText; newtComponent form; newtComponent btnOk; newtComponent btnCancel; newtComponent temp; int nOk = 0; while (!nOk) { newtCenteredWindow(65, 20, i18n("Password required")); labelLoginText = newtTextbox(1, 5, 60, 1, 0); newtTextboxSetText(labelLoginText, i18n("Enter your login")); editLoginText = newtEntry(1, 6, "", 55, NULL, NEWT_ENTRY_SCROLL); labelPasswdText = newtTextbox(1, 9, 60, 1, 0); newtTextboxSetText(labelPasswdText, i18n("Enter your password")); editPasswdText = newtEntry(1, 10, "", 55, NULL, NEWT_FLAG_HIDDEN); btnOk = newtButton(15, 14, i18n("Ok")); btnCancel = newtButton(40, 14, i18n("Cancel")); form = newtForm(NULL, NULL, 0); newtFormAddComponents(form, labelLoginText, editLoginText, labelPasswdText, editPasswdText, btnOk, btnCancel, NULL); temp = newtRunForm(form); newtPopWindow(); if (temp == btnCancel) { newtFormDestroy(form); RETURN_int(-1); } strncpy(szLogin, newtEntryGetValue(editLoginText), size-1); *(szLogin+size-1) = '\0'; strncpy(szPasswd, newtEntryGetValue(editPasswdText), size-1); *(szPasswd+size-1) = '\0'; if (!(*szLogin) || !(*szPasswd)) msgBoxError(i18n("Text cannot be empty")); else nOk = 1; newtFormDestroy(form); } return 0; }
// ======================================================= int CRestoringWindow::create(char *szDevice, char *szImageFile, QWORD qwCurPartSize, DWORD dwCompressionMode, char *szOriginalDevice, char *szFileSystem, tm dateCreate, QWORD qwOrigPartSize, COptions * options) { BEGIN; char szTemp[2048]; char szTemp2[2048]; if (options->bSimulateMode) SNPRINTF(szTemp, i18n("simulate partition restoration from image file")); else SNPRINTF(szTemp, i18n("restore partition from image file")); newtCenteredWindow(78, 20, szTemp); SNPRINTF(szTemp, i18n("Partition to restore:.............%s"), szDevice); m_labelPartition = newtLabel(1, 0, szTemp); SNPRINTF(szTemp, i18n("Size of partition to restore:.....%s = %llu bytes"), formatSize(qwCurPartSize, szTemp2), qwCurPartSize); m_labelPartitionSize = newtLabel(1, 1, szTemp); SNPRINTF(szTemp, i18n("Image file to use.................%s"), szImageFile); m_labelImageFile = newtLabel(1, 2, szTemp); SNPRINTF(szTemp, i18n("File system:......................%s"), szFileSystem); m_labelFS = newtLabel(1, 3, szTemp); m_labelCompression = newtLabel(1, 4, ""); SNPRINTF(szTemp, i18n("Partition was on device:..........%s\n"), szOriginalDevice); m_labelOldDevice = newtLabel(1, 5, szTemp); SNPRINTF(szTemp, i18n("Image created on:.................%s\n"), asctime(&dateCreate)); m_labelDate = newtLabel(1, 6, szTemp); SNPRINTF(szTemp, i18n("Size of the original partition:...%s = %llu bytes"), formatSize(qwOrigPartSize, szTemp2), qwOrigPartSize); m_labelOriginalPartitionSize = newtLabel(1, 7, szTemp); // stats m_labelStatsTime = newtLabel(1, 9, ""); m_labelStatsTimeRemaining = newtLabel(1, 10, ""); m_labelStatsSpeed = newtLabel(1, 11, ""); m_labelStatsSpace = newtLabel(1, 12, ""); m_progressRestoring = newtScale(1, 18, 70, 100); m_labelPercent = newtLabel(72, 18, ""); m_formMain = newtForm(NULL, NULL, 0); newtFormAddComponents(m_formMain, m_labelPartition, m_labelPartitionSize, m_labelImageFile, m_labelFS, m_labelCompression, NULL); newtFormAddComponents(m_formMain, m_labelOldDevice, m_labelDate, m_labelOriginalPartitionSize, NULL); newtFormAddComponents(m_formMain, m_labelStatsTime, m_labelStatsTimeRemaining, m_labelStatsSpeed, m_labelStatsSpace, NULL); newtFormAddComponents(m_formMain, m_progressRestoring, m_labelPercent, NULL); newtDrawForm(m_formMain); newtRefresh(); RETURN_int(0); }
// ======================================================= int CSaveOptWindow::getValues(COptions *options) { BEGIN; // get options options->bAskDesc = (newtCheckboxGetValue(m_checkAskDesc) == 'X'); options->bCheckBeforeSaving = (newtCheckboxGetValue(m_checkCheckBeforeSaving) == 'X'); options->bOverwrite = (newtCheckboxGetValue(m_checkOverwrite) == 'X'); options->bSplitWait = (newtCheckboxGetValue(m_checkSplitWait) == 'X'); // get compression level if (newtRadioGetCurrent(m_radioCompNone) == m_radioCompNone) options->dwCompression = COMPRESS_NONE; else if (newtRadioGetCurrent(m_radioCompNone) == m_radioCompGzip) options->dwCompression = COMPRESS_GZIP; else if (newtRadioGetCurrent(m_radioCompNone) == m_radioCompBzip2) options->dwCompression = COMPRESS_BZIP2; // get finish level if (newtRadioGetCurrent(m_radioFinishWait) == m_radioFinishWait) options->dwFinish = FINISH_WAIT; else if (newtRadioGetCurrent(m_radioFinishWait) == m_radioFinishHalt) options->dwFinish = FINISH_HALT; else if (newtRadioGetCurrent(m_radioFinishWait) == m_radioFinishReboot) options->dwFinish = FINISH_REBOOT; else if (newtRadioGetCurrent(m_radioFinishWait) == m_radioFinishQuit) options->dwFinish = FINISH_QUIT; else if (newtRadioGetCurrent(m_radioFinishWait) == m_radioFinishLast) options->dwFinish = FINISH_LAST; // get split mode if (newtRadioGetCurrent(m_radioSplitAuto) == m_radioSplitAuto) options->qwSplitSize = 0LL;//options->dwSplitMode = SPLIT_AUTO; else if (newtRadioGetCurrent(m_radioSplitAuto) == m_radioSplitSize) { //options->dwSplitMode = SPLIT_SIZE; #ifdef HAVE_ATOLL options->qwSplitSize = atoll(newtEntryGetValue(m_editSplitSize)) * 1024 * 1024; #else #ifdef HAVE_STRTOLL options->qwSplitSize = strtoll(newtEntryGetValue(m_editSplitSize), NULL, 10) * 1024 * 1024; #else #error "no function to convert string to long long int" #endif // HAVE_STRTOLL #endif // HAVE_ATOLL showDebug(1, "qwSplitSize = %llu\n", options->qwSplitSize); } /*else if (newtRadioGetCurrent(m_radioSplitNone) == m_radioSplitAuto) { options->dwSplitMode = SPLIT_AUTO; options->dwSplitSize = 0; }*/ RETURN_int(0); }
// ======================================================= int CBlocksUseBitmap::freeBitmap() { BEGIN; if (m_cBitmap) // if memory was allocated { delete m_cBitmap; m_cBitmap = NULL; } RETURN_int(0); }
// ======================================================= int CBlocksUseBitmap::init(DWORD dwBitmapSize) { BEGIN; // if memory already allocated if (m_cBitmap) RETURN_int(-1); m_dwBitmapSize = dwBitmapSize; m_cBitmap = new BYTE[dwBitmapSize+1]; if (m_cBitmap == NULL) { g_interface->msgBoxError(i18n("Out of memory")); RETURN_int(-1); } memset(m_cBitmap, 0, dwBitmapSize); RETURN_int(0); }
// ======================================================= // flag = LOCK_SH | LOCK_EX if called when restoring or saving int CImageDisk::lockImage(int flag, int nFd, char *szFilename) // [Main-Thread] { #ifndef DEVEL_SUPPORT int nRes; errno = 0; if (flag != LOCK_SH && flag != LOCK_EX) { showDebug(1, "LOCK flag is %d\n", flag); RETURN_int(-1); } nRes = flock(m_nImageFd, flag | LOCK_NB); if (nRes == -1) RETURN_int(-1); showDebug(4, "LOCK file %s\n", m_szImageFilename); #endif // DEVEL_SUPPORT return 0; }
// ======================================================= int COptionsWindow/*CSaveOptWindow*/::runForm() { BEGIN; newtComponent widgetTemp; newtExitStruct event; /*widgetTemp = */newtFormRun(m_formMain, &event); widgetTemp = newtFormGetCurrent(m_formMain); if (((event.reason == event.NEWT_EXIT_HOTKEY) && (event.u.key == KEY_EXIT)) || ((event.reason == event.NEWT_EXIT_COMPONENT) && (widgetTemp == m_btnExit))) RETURN_int(KEY_EXIT); if (((event.reason == event.NEWT_EXIT_HOTKEY) && (event.u.key == KEY_OKAY)) || ((event.reason == event.NEWT_EXIT_COMPONENT) && (widgetTemp == m_btnOkay))) RETURN_int(KEY_OKAY); if (((event.reason == event.NEWT_EXIT_HOTKEY) && (event.u.key == KEY_BACK)) || ((event.reason == event.NEWT_EXIT_COMPONENT) && (widgetTemp == m_btnBack)) ) RETURN_int(KEY_BACK); RETURN_int(-1); }
// ======================================================= int CSaveOptWindow::create(char *szImageFile, COptions options) { BEGIN; char szTemp[2048]; newtCenteredWindow(78, 20, i18n("save partition to image file")); m_labelCompression = newtLabel(1, 1, i18n("Compression level")); m_radioCompNone = newtRadiobutton(1, 2, i18n("None (very fast + very big file)"), options.dwCompression == COMPRESS_NONE, NULL); m_radioCompGzip = newtRadiobutton(1, 3, "Gzip (.gz: medium speed + small image file)", options.dwCompression == COMPRESS_GZIP, m_radioCompNone); m_radioCompBzip2 = newtRadiobutton(1, 4, "Bzip2 (.bz2: very slow + very small image file)", options.dwCompression == COMPRESS_BZIP2, m_radioCompGzip); m_labelOptions = newtLabel(1, 7, i18n("Options")); m_checkCheckBeforeSaving = newtCheckbox(1, 8, i18n("Check partition before saving"), (!!options.bCheckBeforeSaving ? 'X' : ' '), " X", NULL); m_checkAskDesc = newtCheckbox(1, 9, i18n("Enter description"), (!!options.bAskDesc ? 'X' : ' '), " X", NULL); m_checkOverwrite = newtCheckbox(1, 10, i18n("Overwrite without prompt"), (!!options.bOverwrite ? 'X' : ' '), " X", NULL); m_labelSplit = newtLabel(1, 12, i18n("Image split mode")); m_radioSplitAuto = newtRadiobutton(1, 13, i18n("Automatic split (when no space left)"), !options.qwSplitSize, NULL); m_radioSplitSize = newtRadiobutton(1, 14, i18n("Into files whose size is:............"), !!options.qwSplitSize, m_radioSplitAuto); SNPRINTF(szTemp, "%llu", (!!options.qwSplitSize) ? (options.qwSplitSize/1024/1024) : 2048); m_editSplitSize = newtEntry(43, 14, szTemp, 8, NULL, 0); m_labelSplitSizeKB = newtLabel(52, 14, i18n("MiB")); m_checkSplitWait = newtCheckbox(1, 15, i18n("Wait after each volume change"), (!!options.bSplitWait ? 'X' : ' '), " X", NULL); m_labelFinish = newtLabel(43, 7, i18n("If finished successfully:")); m_radioFinishWait = newtRadiobutton(43, 8, i18n("Wait"), options.dwFinish == FINISH_WAIT, NULL); m_radioFinishHalt = newtRadiobutton(43, 9, i18n("Halt"), options.dwFinish == FINISH_HALT, m_radioFinishWait); m_radioFinishReboot = newtRadiobutton(43, 10, i18n("Reboot"), options.dwFinish == FINISH_REBOOT, m_radioFinishHalt); m_radioFinishQuit = newtRadiobutton(43,11,i18n("Quit"), options.dwFinish == FINISH_QUIT, m_radioFinishReboot); m_radioFinishLast = newtRadiobutton(43,12,i18n("Last"), options.dwFinish == FINISH_LAST, m_radioFinishQuit); addButtons(); m_formMain = newtForm(NULL, NULL, 0); newtFormAddComponents(m_formMain, m_labelCompression, m_labelOptions, m_labelSplit, NULL); newtFormAddComponents(m_formMain, m_radioCompNone, m_radioCompGzip, m_radioCompBzip2, m_checkCheckBeforeSaving, m_checkAskDesc, m_checkOverwrite, NULL); newtFormAddComponents(m_formMain, m_labelFinish, m_radioFinishWait, m_radioFinishHalt, m_radioFinishReboot, m_radioFinishQuit, m_radioFinishLast, NULL); newtFormAddComponents(m_formMain, m_radioSplitAuto, m_radioSplitSize, m_labelSplitSizeKB, m_editSplitSize, m_checkSplitWait, NULL); addHotKeys(); newtDrawForm(m_formMain); RETURN_int(0); }
// ======================================================= int CInterfaceNewt::askText(char *szMessage, char *szTitle, char *szDestText, WORD size) { newtComponent editText; newtComponent labelText; newtComponent form; newtComponent btnOk; newtComponent btnCancel; newtComponent temp; *szDestText = 0; while (!*szDestText) { newtCenteredWindow(65, 20, szTitle); labelText = newtTextbox(1, 1, 60, 7, 0/*NEWT_TEXTBOX_SCROLL*/); newtTextboxSetText(labelText, szMessage); editText = newtEntry(1, 9, "", 55, NULL, NEWT_ENTRY_SCROLL); btnOk = newtButton(15, 14, i18n("Ok")); btnCancel = newtButton(40, 14, i18n("Cancel")); form = newtForm(NULL, NULL, 0); newtFormAddComponents(form, labelText, editText, btnOk, btnCancel, NULL); temp = newtRunForm(form); newtPopWindow(); if (temp == btnCancel) { newtFormDestroy(form); RETURN_int(-1); } strncpy(szDestText, newtEntryGetValue(editText), size-1); *(szDestText+size-1) = '\0'; if (*szDestText == 0) msgBoxError(i18n("Text cannot be empty")); newtFormDestroy(form); } return 0; }
// ======================================================= int CRestoreOptWindow::getValues(COptions *options) { BEGIN; // get options options->bEraseWithNull = (newtCheckboxGetValue(m_checkEraseWithNull) == 'X'); options->bSimulateMode = (newtCheckboxGetValue(m_checkSimulateMode) == 'X'); // get finish level if (newtRadioGetCurrent(m_radioFinishWait) == m_radioFinishWait) options->dwFinish = FINISH_WAIT; else if (newtRadioGetCurrent(m_radioFinishWait) == m_radioFinishHalt) options->dwFinish = FINISH_HALT; else if (newtRadioGetCurrent(m_radioFinishWait) == m_radioFinishReboot) options->dwFinish = FINISH_REBOOT; else if (newtRadioGetCurrent(m_radioFinishWait) == m_radioFinishQuit) options->dwFinish = FINISH_QUIT; RETURN_int(0); }
// ======================================================= int fillPartitionList(newtComponent editPartition) { BEGIN; FILE *fPart; int nMajor, nMinor, nBlocks; char szDevice[128]; char szFullDevice[128]; char cBuffer[32768]; char cFormat[1024]; char szTemp[1024]; char *cPtr; int nLines; unsigned int nSize; QWORD qwSize; int i; int nRes; char *szDeviceName; int nPartNum; errno = 0; fPart = fopen("/proc/partitions", "rb"); if (!fPart) { g_interface->msgBoxError(i18n("Cannot read \"/proc/partitions\" (%s). Then, you must use the " "command line to run Partition Image. Type \"partimage --help\" for help."), strerror(errno)); RETURN_int(-1); } nSize = 0; nLines = 0; memset(cBuffer, 0, sizeof(cBuffer)); showDebug(9, "Reading /proc/partitions file\n"); while (nSize < sizeof(cBuffer) && !feof(fPart)) { nRes = fgetc(fPart); if (nRes != -1) cBuffer[nSize] = nRes; else showDebug(9, "error in fgetc\n"); if (cBuffer[nSize] == '\n') { ++nLines; showDebug(9, "%d lines read\n", nLines); } ++nSize; } if (nSize < sizeof(cBuffer)) cBuffer[nSize] = '\0'; else cBuffer[sizeof(cBuffer)-1] = '\0'; fclose(fPart); showDebug(9, "/proc/partitions read -> \n%s\n", cBuffer); cPtr = cBuffer; // skip two first lines nLines -= 2; for (i=0; i < 2; i++) { while (*cPtr != '\n') cPtr++; cPtr++; } while (*(cPtr) && *(cPtr+1)&& *(cPtr+2)) //for (i=0; i < nLines; i++) // TO BE CHANGED { cPtr = decodePartitionEntry(cPtr, &nMajor, &nMinor, &nBlocks, &nPartNum, szDevice); // detect file system of the hard disk SNPRINTF(szFullDevice, "/dev/%s", szDevice); checkInodeForDevice(szFullDevice); nRes = detectFileSystem(szFullDevice, szTemp); showDebug(9, "device %s\n", szDevice); if (nRes != -1) // if a removable media { showDebug(9, "removable media found: %s\n", szTemp); // add media memset(cFormat, ' ', 50); memset(cFormat+50, 0, 50); memcpy(cFormat, szDevice, strlen(szDevice)); // Device memcpy(cFormat+37, szTemp, strlen(szTemp)); // File system qwSize = getPartitionSize(szFullDevice); formatSize(qwSize, szTemp); memcpy(cFormat+50, szTemp, strlen(szTemp)); // Size szDeviceName = strdup(szFullDevice); // TODO: never freed newtListboxAppendEntry(editPartition, cFormat, (void*)szDeviceName); showDebug(9, "inserted: %s\n", cFormat); // skip partitions cPtr = skipPartitionsEntries(cPtr); } else // if an hard disk { cPtr = processHardDrive(cPtr, editPartition); } } RETURN_int(0); }
// ======================================================= int CImageDisk::getCompressionLevelForImage(char *szFilename) // [Main-Thread] { //return(COMPRESS_LZO); BEGIN; if (!strcmp(szFilename, "stdin")) return COMPRESS_NONE; gzFile gzImageFile; FILE *fImageFile; BZFILE *bzImageFile; DWORD dwRes; CVolumeHeader headVolume; const char *szLabel = MAGIC_BEGIN_VOLUME; char cBuf[64]; showDebug(3, "TRACE_001\n"); // ------ 0. Check for LZO compression fImageFile = fopen(szFilename, "rb"); if (fImageFile == NULL) goto checkBzip2; dwRes = fread(cBuf, 1, 16, fImageFile); fclose(fImageFile); if (dwRes != 16) goto checkBzip2; if (strncmp(cBuf+1, "LZO", 3) == 0) RETURN_int(COMPRESS_LZO); showDebug(3, "TRACE_002\n"); // ------ 1. Check for a bzip2 compression checkBzip2: bzImageFile = BZ2_bzopen(szFilename, "rb"); if (bzImageFile == NULL) goto checkNone; dwRes = BZ2_bzread(bzImageFile, &headVolume, sizeof(CVolumeHeader)); BZ2_bzclose(bzImageFile); if (dwRes != sizeof(CVolumeHeader)) goto checkNone; if (strncmp(headVolume.szMagicString, szLabel, strlen(szLabel)) == 0) RETURN_int(COMPRESS_BZIP2); showDebug(3, "TRACE_003\n"); // ------ 2. Check for no compression checkNone: fImageFile = fopen(szFilename, "rb"); if (fImageFile == NULL) goto checkGzip; dwRes = fread(&headVolume, 1, sizeof(CVolumeHeader), fImageFile); fclose(fImageFile); if (dwRes != sizeof(CVolumeHeader)) goto checkGzip; if (strncmp(headVolume.szMagicString, szLabel, strlen(szLabel)) == 0) RETURN_int(COMPRESS_NONE); showDebug(3, "TRACE_004\n"); // ------ 3. Check for a gzip compression checkGzip: gzImageFile = gzopen(szFilename, "rb"); if (gzImageFile == NULL) RETURN_int(-1); // error dwRes = gzread(gzImageFile, &headVolume, sizeof(CVolumeHeader)); gzclose(gzImageFile); if (dwRes != sizeof(CVolumeHeader)) RETURN_int(-1); // error if (strncmp(headVolume.szMagicString, szLabel, strlen(szLabel)) == 0) //if (strcmp(headMain.szAppName, "PartImage") == 0) RETURN_int(COMPRESS_GZIP); showDebug(3, "TRACE_005\n"); RETURN_int(-1); // error }
// ======================================================= int CInterfaceNewt::guiInitMainWindow(char *szDevice, char *szImageFile, char *szNetworkIP, DWORD *dwServerPort, bool *bSsl) { newtComponent formMain, btnContinue, btnExit, btnAbout; newtComponent labelPartition, labelImage, editPartition, editImage, btnImage; newtComponent widgetTemp, labelAction, radioSave, radioRestore, radioMbr; newtComponent checkNetwork, labelNetwork, labelPort, editNetwork, editPort, checkSsl; newtExitStruct event; char szTemp[1024]; int nAction; int nRes; showDebug(8, "guiInitMainWindow\n"); SNPRINTF(szTemp, "Partition Image %s", PACKAGE_VERSION); newtCenteredWindow(67, 20, szTemp); labelPartition = newtLabel(1, 0, i18n("* Partition to save/restore")); editPartition = newtListbox(3, 1, 7, NEWT_FLAG_SCROLL); labelImage = newtLabel(1, 9, i18n("* Image file to create/use")); editImage = newtEntry(3, 10, szImageFile, 59, NULL, NEWT_FLAG_SCROLL); btnImage = newtCompactButton(62, 10, "*"); labelAction = newtLabel(1, 12, i18n("Action to be done:")); radioSave = newtRadiobutton(1, 13, i18n("Save partition into a new image file"), true, NULL); radioRestore = newtRadiobutton(1, 14, i18n("Restore partition from an image file"), false, radioSave); radioMbr = newtRadiobutton(1, 15, i18n("Restore an MBR from the image file"), false, radioRestore); checkNetwork = newtCheckbox(1, 17, i18n("Connect to server"), (!!(*szNetworkIP) ? 'X' : ' '), " X", NULL); #ifdef HAVE_SSL checkSsl = newtCheckbox(5, 19, i18n("Encrypt data on the network with SSL"), (*bSsl ? 'X' : ' '), " X", NULL); #else #ifdef MUST_LOGIN checkSsl = newtLabel(5, 19,i18n("SSL disabled at compile time")); #else checkSsl = newtLabel(5, 19,i18n("SSL&login disabled at compile time")); #endif #endif labelNetwork = newtLabel(5, 18, i18n("IP/name of the server:")); editNetwork = newtEntry(28, 18, szNetworkIP, 25, NULL, 0); labelPort = newtLabel(54, 18, i18n("Port:")); SNPRINTF(szTemp, "%u", *dwServerPort); editPort = newtEntry(60, 18, szTemp, 6, NULL, 0); btnContinue = newtCompactButton(50, 12, i18n("Next (F5)")); btnAbout = newtCompactButton(50, 14, i18n("About")); btnExit = newtCompactButton(50, 16, i18n("Exit (F6)")); nRes = fillPartitionList(editPartition); if (nRes == -1) RETURN_int(-1); formMain = newtForm(NULL, NULL, 0); newtFormAddComponents(formMain, labelPartition, labelImage, editPartition, editImage, btnImage, labelAction, radioSave, radioRestore, radioMbr, checkNetwork, labelNetwork, editNetwork, labelPort, editPort, checkSsl, btnContinue, btnAbout, btnExit, NULL); newtFormAddHotKey(formMain, KEY_EXIT); // Exit newtFormAddHotKey(formMain, KEY_OKAY); // Okay begin: /*widgetTemp = */newtFormRun(formMain, &event); widgetTemp = newtFormGetCurrent(formMain); if (((event.reason == event.NEWT_EXIT_HOTKEY) && (event.u.key == KEY_EXIT)) || ((event.reason == event.NEWT_EXIT_COMPONENT) && (widgetTemp == btnExit))) //if(widgetTemp == btnExit) return OPERATION_EXIT; if ((event.reason == event.NEWT_EXIT_COMPONENT) && (widgetTemp == btnAbout)) { showAboutDialog(); goto begin; } if ((event.reason == event.NEWT_EXIT_COMPONENT) && (widgetTemp == btnImage)) { char *fs_; fs_=filesel(newtEntryGetValue(editImage)); if(fs_) { newtEntrySet(editImage, fs_, 1); // free(fs_); } goto begin; } if (strcmp(newtEntryGetValue(editImage), "") == 0) // if "image" field empty { msgBoxError(i18n("The \"Image\" field is empty. Cannot continue")); goto begin; } if (newtCheckboxGetValue(checkNetwork) == 'X') { if (!(*newtEntryGetValue(editNetwork))) { msgBoxError(i18n("The \"Server IP/Name\" field is empty. Cannot continue")); goto begin; } if (!atoi((char*)newtEntryGetValue(editPort))) { msgBoxError(i18n("The \"Server Port\" field is not a valid integer. Cannot continue")); goto begin; } } // get device strcpy(szDevice, (char*)newtListboxGetCurrent(editPartition)); // image file strcpy(szImageFile, newtEntryGetValue(editImage)); // network if (newtCheckboxGetValue(checkNetwork) == 'X') // If network is activated { strcpy(szNetworkIP, (char*)newtEntryGetValue(editNetwork)); *dwServerPort = atoi((char*)newtEntryGetValue(editPort)); #ifdef HAVE_SSL *bSsl = (newtCheckboxGetValue(checkSsl) == 'X'); #endif } else // no network { *szNetworkIP = 0; *dwServerPort = OPTIONS_DEFAULT_SERVERPORT; } nAction = 0; if (newtRadioGetCurrent(radioRestore) == radioSave) { nAction = OPERATION_SAVE; } else if (newtRadioGetCurrent(radioRestore) == radioRestore) { nAction = OPERATION_RESTORE; } else if (newtRadioGetCurrent(radioRestore) == radioMbr) { nAction = OPERATION_RESTMBR; } newtFormDestroy(formMain); newtPopWindow(); return nAction; }
// ======================================================= int CRestoringWindow::runForm() { BEGIN; newtRefresh(); RETURN_int(0); }
// ======================================================= int CSavingWindow::create(const char *szDevice, const char *szImageFile, const char *szFilesystem, QWORD qwPartSize, COptions options) { BEGIN; char szTemp[1024]; char szTemp2[1024]; SNPRINTF(szTemp, i18n("save partition to image file")); newtCenteredWindow(78, 20, szTemp); SNPRINTF(szTemp, i18n("Partition to save:...........%s"), szDevice); m_labelPartition = newtLabel(1, 0, szTemp); SNPRINTF(szTemp, i18n("Size of the Partition:.......%s = %llu bytes"), formatSize(qwPartSize, szTemp2), qwPartSize); m_labelPartitionSize = newtLabel(1, 1, szTemp); SNPRINTF(szTemp, i18n("Image file to create.........%s"), szImageFile); m_labelImageFile = newtLabel(1, 2, szTemp); m_labelImageFileSize = newtLabel(1, 3, ""); m_labelFreeSpace = newtLabel(1, 4, ""); SNPRINTF(szTemp, i18n("Detected file system:........%s"), szFilesystem); m_labelFS = newtLabel(1, 5, szTemp); switch (options.dwCompression) { case COMPRESS_NONE: SNPRINTF(szTemp, i18n("Compression level:...........None")); break; case COMPRESS_GZIP: SNPRINTF(szTemp, i18n("Compression level:...........gzip")); break; case COMPRESS_BZIP2: SNPRINTF(szTemp, i18n("Compression level:...........bzip2")); break; case COMPRESS_LZO: SNPRINTF(szTemp, i18n("Compression level:...........lzo")); break; } m_labelCompression = newtLabel(1, 6, szTemp); // stats m_labelStatsTime = newtLabel(1, 9, ""); m_labelStatsTimeRemaining = newtLabel(1, 10, ""); m_labelStatsSpeed = newtLabel(1, 11, ""); m_labelStatsSpace = newtLabel(1, 12, ""); m_progressSaving = newtScale(1, 18, 70, 100); m_labelPercent = newtLabel(72, 18, ""); m_formMain = newtForm(NULL, NULL, 0); newtFormAddComponents(m_formMain, m_labelPartition, m_labelPartitionSize, m_labelImageFile, m_labelImageFileSize, m_labelFreeSpace, m_labelFS, m_labelCompression, NULL); newtFormAddComponents(m_formMain, m_labelStatsTime, m_labelStatsTimeRemaining, m_labelStatsSpeed, m_labelStatsSpace, NULL); newtFormAddComponents(m_formMain, m_progressSaving, m_labelPercent, NULL); newtRefresh(); newtDrawForm(m_formMain); RETURN_int(0); }