|
|
1.1 ! root 1: /* Copyright (C) 2004 TrueCrypt Team, truecrypt.org ! 2: This product uses components written by Paul Le Roux <[email protected]> */ ! 3: ! 4: #include "TCdefs.h" ! 5: ! 6: #include "crypto.h" ! 7: #include "fat.h" ! 8: #include "format.h" ! 9: #include "volumes.h" ! 10: #include "progress.h" ! 11: #include "apidrvr.h" ! 12: #include "dlgcode.h" ! 13: ! 14: int ! 15: FormatVolume (char *lpszFilename, ! 16: BOOL bDevice, ! 17: unsigned __int64 size, ! 18: char *lpszPassword, ! 19: int cipher, ! 20: int pkcs5, ! 21: fatparams * ft, ! 22: BOOL quickFormat, ! 23: HWND hwndDlg) ! 24: { ! 25: int nStatus; ! 26: PCRYPTO_INFO cryptoInfo; ! 27: void *dev = INVALID_HANDLE_VALUE; ! 28: OPEN_TEST_STRUCT driver; ! 29: DISKIO_STRUCT win9x_r0; ! 30: DWORD dwError; ! 31: diskio_f write; ! 32: ! 33: if (nCurrentOS == WIN_NT || bDevice == FALSE) ! 34: { ! 35: write = (diskio_f) _lwrite; ! 36: ! 37: if (bDevice == TRUE) ! 38: { ! 39: dev = CreateFile (lpszFilename, GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL); ! 40: } ! 41: else ! 42: { ! 43: /* We could support FILE_ATTRIBUTE_HIDDEN as an ! 44: option! */ ! 45: dev = CreateFile (lpszFilename, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL); ! 46: } ! 47: ! 48: if (dev == INVALID_HANDLE_VALUE) ! 49: { ! 50: return ERR_OS_ERROR; ! 51: } ! 52: } ! 53: else ! 54: { ! 55: write = (diskio_f) win9x_io; ! 56: ! 57: if (OpenDevice (lpszFilename, &driver) == FALSE) ! 58: { ! 59: return ERR_OS_ERROR; ! 60: } ! 61: ! 62: win9x_r0.devicenum = driver.device; ! 63: win9x_r0.sectorstart = driver.secstart; ! 64: win9x_r0.mode = 1; ! 65: ! 66: dev = &win9x_r0; ! 67: } ! 68: ! 69: size -= SECTOR_SIZE; // less the first TC sector ! 70: ! 71: ft->num_sectors = (int) (size / SECTOR_SIZE); ! 72: memcpy (ft->volume_name, " ", 11); ! 73: ! 74: { ! 75: // Avoid random init delay before time counters start ! 76: char tmp[1]; ! 77: RandgetBytes(&tmp, 1); ! 78: } ! 79: ! 80: InitProgressBar (ft->num_sectors); ! 81: ! 82: /* Calculate the fats, root dir etc, and update ft */ ! 83: GetFatParams (ft); ! 84: ! 85: /* Copies any header structures into ft->header, but does not do any ! 86: disk io */ ! 87: nStatus = VolumeWriteHeader (ft->header, ! 88: cipher, ! 89: lpszPassword, ! 90: pkcs5, ! 91: 0, ! 92: 0, ! 93: &cryptoInfo); ! 94: ! 95: if (nStatus != 0) ! 96: return nStatus; ! 97: ! 98: KillTimer (hwndDlg, 0xff); ! 99: ! 100: /* This does the disk io, both copying out the header, init the ! 101: sectors, and writing the FAT tables etc */ ! 102: nStatus = Format (ft, (HFILE) dev, cryptoInfo, 1000, write, bDevice==TRUE ? quickFormat:FALSE); ! 103: ! 104: dwError = GetLastError(); ! 105: ! 106: crypto_close (cryptoInfo); ! 107: ! 108: if (dev != &win9x_r0) ! 109: CloseHandle (dev); ! 110: ! 111: if (nStatus!=0) ! 112: SetLastError(dwError); ! 113: ! 114: return nStatus; ! 115: ! 116: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.