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

Definition at line 121 of file ramdisk.c.

Referenced by LoadAndBootWindows().

{
    ULONG RamFile;
    ULONG TotalRead, ChunkSize, Count;
    PCHAR MsgBuffer = "Loading ramdisk...";
    ULONG PercentPerChunk, Percent;
    FILEINFORMATION Information;
    LARGE_INTEGER Position;
    LONG ret;

    //
    // Display progress
    //
    UiDrawProgressBarCenter(1, 100, MsgBuffer);

    //
    // Try opening the ramdisk file
    //
    ret = ArcOpen(FileName, OpenReadOnly, &RamFile);
    if (ret == ESUCCESS)
    {
        //
        // Get the file size
        //
        ret = ArcGetFileInformation(RamFile, &Information);
        if (ret != ESUCCESS)
        {
            ArcClose(RamFile);
            return;
        }

        //
        // For now, limit RAM disks to 4GB
        //
        if (Information.EndingAddress.HighPart != 0)
        {
            UiMessageBox("RAM disk too big\n");
            ArcClose(RamFile);
            return;
        }
        gRamDiskSize = Information.EndingAddress.LowPart;

        //
        // Allocate memory for it
        //
        ChunkSize = 8 * 1024 * 1024;
        if (gRamDiskSize < ChunkSize)
            Percent = PercentPerChunk = 0;
        else
            Percent = PercentPerChunk = 100 / (gRamDiskSize / ChunkSize);
        gRamDiskBase = MmAllocateMemoryWithType(gRamDiskSize, LoaderXIPRom);
        if (!gRamDiskBase)
        {
            UiMessageBox("Failed to allocate memory for RAM disk\n");
            ArcClose(RamFile);
            return;
        }

        //
        // Read it in chunks
        //
        for (TotalRead = 0; TotalRead < gRamDiskSize; TotalRead += ChunkSize)
        {
            //
            // Check if we're at the last chunk
            //
            if ((gRamDiskSize - TotalRead) < ChunkSize)
            {
                //
                // Only need the actual data required
                //
                ChunkSize = gRamDiskSize - TotalRead;
            }

            //
            // Draw progress
            //
            UiDrawProgressBarCenter(Percent, 100, MsgBuffer);
            Percent += PercentPerChunk;

            //
            // Copy the contents
            //
            Position.HighPart = 0;
            Position.LowPart = TotalRead;
            ret = ArcSeek(RamFile, &Position, SeekAbsolute);
            if (ret == ESUCCESS)
            {
                ret = ArcRead(RamFile,
                              (PVOID)((ULONG_PTR)gRamDiskBase + TotalRead),
                              ChunkSize,
                              &Count);
            }

            //
            // Check for success
            //
            if (ret != ESUCCESS || Count != ChunkSize)
            {
                MmFreeMemory(gRamDiskBase);
                gRamDiskBase = NULL;
                gRamDiskSize = 0;
                ArcClose(RamFile);
                UiMessageBox("Failed to read ramdisk\n");
                return;
            }
        }

        ArcClose(RamFile);

        // Register a new device for the ramdisk
        FsRegisterDevice("ramdisk(0)", &RamDiskVtbl);
    }
}

Generated on Sat May 26 2012 04:47:11 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.