Annotation of truecrypt/common/format.c, revision 1.1.1.2

1.1.1.2 ! root        1: /* Copyright (C) 2004 TrueCrypt Foundation
1.1       root        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:        /* Calculate the fats, root dir etc, and update ft */
                     75:        GetFatParams (ft);
                     76: 
                     77:        /* Copies any header structures into ft->header, but does not do any
                     78:           disk io */
1.1.1.2 ! root       79:        VirtualLock (&ft->header, sizeof (ft->header));
        !            80: 
1.1       root       81:        nStatus = VolumeWriteHeader (ft->header,
                     82:                                     cipher,
                     83:                                     lpszPassword,
                     84:                                     pkcs5,
                     85:                                         0,
                     86:                                         0,
                     87:                                     &cryptoInfo);
                     88: 
1.1.1.2 ! root       89:        VirtualUnlock (&ft->header, sizeof (ft->header));
        !            90: 
1.1       root       91:        if (nStatus != 0)
                     92:                return nStatus;
                     93: 
                     94:        KillTimer (hwndDlg, 0xff);
                     95: 
1.1.1.2 ! root       96:        InitProgressBar (ft->num_sectors);
        !            97: 
1.1       root       98:        /* This does the disk io, both copying out the header, init the
                     99:           sectors, and writing the FAT tables etc */
                    100:        nStatus = Format (ft, (HFILE) dev, cryptoInfo, 1000, write, bDevice==TRUE ? quickFormat:FALSE);
                    101: 
                    102:        dwError = GetLastError();
                    103: 
                    104:        crypto_close (cryptoInfo);
                    105: 
                    106:        if (dev != &win9x_r0)
                    107:                CloseHandle (dev);
                    108: 
                    109:        if (nStatus!=0)
                    110:                SetLastError(dwError);
                    111:        
                    112:        return nStatus;
                    113: 
                    114: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.