ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

BOOL BackupBootSector ( LPCTSTR  lpszVolumeName)

Definition at line 57 of file install.c.

Referenced by FatSwapFat32BootSector(), InstallFat32BootCodeToDisk(), and main().

{
    HANDLE  hBackupFile;
    TCHAR   szFileName[MAX_PATH];
    ULONG   Count;
    BYTE    BootSectorBuffer[512];
    DWORD   dwNumberOfBytesWritten;
    BOOL    bRetVal;

    //
    // Find the next unused filename and open it
    //
    for (Count=0; ; Count++)
    {
        //
        // Generate the next filename
        //
        _stprintf(szFileName, _T("%s\\bootsect.%03ld"), lpszVolumeName, Count);

        //
        // Try to create a new file, fail if exists
        //
        hBackupFile = CreateFile(szFileName, GENERIC_WRITE, 0, NULL, CREATE_NEW, /*FILE_ATTRIBUTE_SYSTEM*/0, NULL);

        //
        // Check to see if it worked
        //
        if (hBackupFile != INVALID_HANDLE_VALUE)
        {
            break;
        }

        //
        // Nope, didn't work
        // Check to see if it already existed
        //
        if (!(GetLastError() != ERROR_ALREADY_EXISTS))
        {
            _tprintf(_T("%s:%d: "), __FILE__, __LINE__);
            _tprintf(_T("Boot sector backup failed. Error code %ld.\n"), GetLastError());
            return FALSE;
        }
    }

    //
    // Try to read the boot sector
    //
    if (!ReadVolumeSector(0, BootSectorBuffer))
    {
        CloseHandle(hBackupFile);
        return FALSE;
    }

    //
    // Try to write the boot sector data to the file
    //
    bRetVal = WriteFile(hBackupFile, BootSectorBuffer, 512, &dwNumberOfBytesWritten, NULL);
    if (!bRetVal || (dwNumberOfBytesWritten != 512))
    {
        CloseHandle(hBackupFile);
        _tprintf(_T("%s:%d: "), __FILE__, __LINE__);
        _tprintf(_T("WriteFile() failed. Error code %ld.\n"), GetLastError());
        return FALSE;
    }

    _tprintf(_T("Boot sector backed up to file: %s\n"), szFileName);

    CloseHandle(hBackupFile);

    return TRUE;
}

Generated on Sun May 27 2012 04:48:34 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.