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

ramdisk.c
Go to the documentation of this file.
00001 /*
00002  * PROJECT:         ReactOS Kernel
00003  * LICENSE:         BSD - See COPYING.ARM in the top level directory
00004  * FILE:            ntoskrnl/io/iomgr/ramdisk.c
00005  * PURPOSE:         Allows booting from RAM disk
00006  * PROGRAMMERS:     ReactOS Portable Systems Group
00007  */
00008 
00009 /* INCLUDES *******************************************************************/
00010 
00011 #include <ntoskrnl.h>
00012 #include <initguid.h>
00013 #include <ntddrdsk.h>
00014 #define NDEBUG
00015 #include <debug.h>
00016 
00017 /* DATA ***********************************************************************/
00018 
00019 #if defined (ALLOC_PRAGMA)
00020 #pragma alloc_text(INIT, IopStartRamdisk)
00021 #endif
00022 
00023 /* FUNCTIONS ******************************************************************/
00024 
00025 NTSTATUS
00026 NTAPI
00027 INIT_FUNCTION
00028 IopStartRamdisk(IN PLOADER_PARAMETER_BLOCK LoaderBlock)
00029 {
00030     PMEMORY_ALLOCATION_DESCRIPTOR MemoryDescriptor;
00031     NTSTATUS Status;
00032     PCHAR CommandLine, Offset, OffsetValue, Length, LengthValue;
00033     HANDLE DriverHandle;
00034     RAMDISK_CREATE_INPUT RamdiskCreate;
00035     IO_STATUS_BLOCK IoStatusBlock;
00036     UNICODE_STRING GuidString, SymbolicLinkName, ObjectName, DeviceString;
00037     PLIST_ENTRY ListHead, NextEntry;
00038     OBJECT_ATTRIBUTES ObjectAttributes;
00039     WCHAR SourceString[54];
00040     
00041     //
00042     // Scan memory descriptors
00043     //
00044     MemoryDescriptor = NULL;
00045     ListHead = &LoaderBlock->MemoryDescriptorListHead;
00046     NextEntry = ListHead->Flink;
00047     while (NextEntry != ListHead)
00048     {
00049         //
00050         // Get the descriptor
00051         //
00052         MemoryDescriptor = CONTAINING_RECORD(NextEntry,
00053                                              MEMORY_ALLOCATION_DESCRIPTOR,
00054                                              ListEntry);
00055         
00056         //
00057         // Needs to be a ROM/RAM descriptor
00058         //
00059         if (MemoryDescriptor->MemoryType == LoaderXIPRom) break;
00060 
00061         //
00062         // Keep trying
00063         //
00064         NextEntry = NextEntry->Flink;
00065     }
00066     
00067     //
00068     // Nothing found?
00069     //
00070     if (NextEntry == ListHead)
00071     {
00072         //
00073         // Bugcheck -- no data
00074         //
00075         KeBugCheckEx(RAMDISK_BOOT_INITIALIZATION_FAILED,
00076                      RD_NO_XIPROM_DESCRIPTOR,
00077                      STATUS_INVALID_PARAMETER,
00078                      0,
00079                      0);
00080     }
00081     
00082     //
00083     // Setup the input buffer
00084     //
00085     RtlZeroMemory(&RamdiskCreate, sizeof(RamdiskCreate));
00086     RamdiskCreate.Version = sizeof(RamdiskCreate);
00087     RamdiskCreate.DiskType = RAMDISK_BOOT_DISK;
00088     RamdiskCreate.BasePage = MemoryDescriptor->BasePage;
00089     RamdiskCreate.DiskOffset = 0;
00090     RamdiskCreate.DiskLength.QuadPart = MemoryDescriptor->PageCount << PAGE_SHIFT;
00091     RamdiskCreate.DiskGuid = RAMDISK_BOOTDISK_GUID;
00092     RamdiskCreate.DriveLetter = L'C';
00093     RamdiskCreate.Options.Fixed = TRUE;
00094     
00095     //
00096     // Check for commandline parameters
00097     //
00098     CommandLine = LoaderBlock->LoadOptions;
00099     if (CommandLine)
00100     {
00101         //
00102         // Make everything upper case
00103         //
00104         _strupr(CommandLine);
00105         
00106         //
00107         // Check for offset parameter
00108         //
00109         Offset = strstr(CommandLine, "RDIMAGEOFFSET");
00110         if (Offset)
00111         {
00112             //
00113             // Get to the actual value
00114             //
00115             OffsetValue = strstr(Offset, "=");
00116             if (OffsetValue)
00117             {
00118                 //
00119                 // Set the offset
00120                 //
00121                 RamdiskCreate.DiskOffset = atol(OffsetValue + 1);
00122             }
00123         }
00124         
00125         //
00126         // Reduce the disk length
00127         //
00128         RamdiskCreate.DiskLength.QuadPart -= RamdiskCreate.DiskOffset;
00129         
00130         //
00131         // Check for length parameter
00132         //
00133         Length = strstr(CommandLine, "RDIMAGELENGTH");
00134         if (Length)
00135         {
00136             //
00137             // Get to the actual value
00138             //
00139             LengthValue = strstr(Length, "=");
00140             if (LengthValue)
00141             {
00142                 //
00143                 // Set the offset
00144                 //
00145                 RamdiskCreate.DiskLength.QuadPart = _atoi64(LengthValue + 1);
00146             }
00147         }
00148     }
00149     
00150     //
00151     // Setup object attributes
00152     //
00153     RtlInitUnicodeString(&ObjectName, L"\\Device\\Ramdisk");
00154     InitializeObjectAttributes(&ObjectAttributes,
00155                                &ObjectName,
00156                                OBJ_KERNEL_HANDLE | OBJ_CASE_INSENSITIVE,
00157                                NULL,
00158                                NULL);
00159     
00160     //
00161     // Open a handle to the driver
00162     //
00163     Status = ZwOpenFile(&DriverHandle,
00164                         GENERIC_ALL,
00165                         &ObjectAttributes,
00166                         &IoStatusBlock,
00167                         FILE_SHARE_READ | FILE_SHARE_WRITE,
00168                         FILE_SYNCHRONOUS_IO_NONALERT);
00169     if (!(NT_SUCCESS(Status)) || !(NT_SUCCESS(IoStatusBlock.Status)))
00170     {
00171         //
00172         // Bugcheck -- no driver
00173         //
00174         KeBugCheckEx(RAMDISK_BOOT_INITIALIZATION_FAILED,
00175                      RD_NO_RAMDISK_DRIVER,
00176                      IoStatusBlock.Status,
00177                      0,
00178                      0);
00179     }
00180     
00181     //
00182     // Send create command
00183     //
00184     Status = ZwDeviceIoControlFile(DriverHandle,
00185                                    NULL,
00186                                    NULL,
00187                                    NULL,
00188                                    &IoStatusBlock,
00189                                    FSCTL_CREATE_RAM_DISK,
00190                                    &RamdiskCreate,
00191                                    sizeof(RamdiskCreate),
00192                                    NULL,
00193                                    0);
00194     ZwClose(DriverHandle);
00195     if (!(NT_SUCCESS(Status)) || !(NT_SUCCESS(IoStatusBlock.Status)))
00196     {
00197         //
00198         // Bugcheck -- driver failed
00199         //
00200         KeBugCheckEx(RAMDISK_BOOT_INITIALIZATION_FAILED,
00201                      RD_FSCTL_FAILED,
00202                      IoStatusBlock.Status,
00203                      0,
00204                      0);
00205     }
00206     
00207     //
00208     // Convert the GUID
00209     //
00210     Status = RtlStringFromGUID(&RamdiskCreate.DiskGuid, &GuidString);
00211     if (!NT_SUCCESS(Status))
00212     {
00213         //
00214         // Bugcheck -- GUID convert failed
00215         //
00216         KeBugCheckEx(RAMDISK_BOOT_INITIALIZATION_FAILED,
00217                      RD_GUID_CONVERT_FAILED,
00218                      Status,
00219                      0,
00220                      0);
00221     }
00222     
00223     //
00224     // Build the symbolic link name and target
00225     //
00226     _snwprintf(SourceString,
00227                sizeof(SourceString),
00228                L"\\Device\\Ramdisk%wZ",
00229                &GuidString);
00230     SymbolicLinkName.Length = 38;
00231     SymbolicLinkName.MaximumLength = 38 + sizeof(UNICODE_NULL);
00232     SymbolicLinkName.Buffer = L"\\ArcName\\ramdisk(0)";
00233     
00234     //
00235     // Create the symbolic link
00236     //
00237     RtlInitUnicodeString(&DeviceString, SourceString);
00238     Status = IoCreateSymbolicLink(&SymbolicLinkName, &DeviceString);
00239     RtlFreeUnicodeString(&GuidString);
00240     if (!NT_SUCCESS(Status))
00241     {
00242         //
00243         // Bugcheck -- symlink create failed
00244         //
00245         KeBugCheckEx(RAMDISK_BOOT_INITIALIZATION_FAILED,
00246                      RD_SYMLINK_CREATE_FAILED,
00247                      Status,
00248                      0,
00249                      0);
00250     }
00251     
00252     //
00253     // We made it
00254     //
00255     return STATUS_SUCCESS;
00256 }

Generated on Sun May 27 2012 04:19: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.