Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygenntfs.c
Go to the documentation of this file.
00001 /* 00002 * COPYRIGHT: See COPYING in the top level directory 00003 * PROJECT: ReactOS File System Recognizer 00004 * FILE: drivers/filesystems/fs_rec/ntfs.c 00005 * PURPOSE: NTFS Recognizer 00006 * PROGRAMMER: Alex Ionescu (alex.ionescu@reactos.org) 00007 * Eric Kohl 00008 */ 00009 00010 /* INCLUDES *****************************************************************/ 00011 00012 #include "fs_rec.h" 00013 #define NDEBUG 00014 #include <debug.h> 00015 00016 /* FUNCTIONS ****************************************************************/ 00017 00018 BOOLEAN 00019 NTAPI 00020 FsRecIsNtfsVolume(IN PPACKED_BOOT_SECTOR BootSector, 00021 IN ULONG BytesPerSector, 00022 IN PLARGE_INTEGER NumberOfSectors) 00023 { 00024 /* Assume failure */ 00025 BOOLEAN Result = FALSE; 00026 00027 PAGED_CODE(); 00028 00029 if ((BootSector->Oem[0] == 'N') && 00030 (BootSector->Oem[1] == 'T') && 00031 (BootSector->Oem[2] == 'F') && 00032 (BootSector->Oem[3] == 'S') && 00033 (BootSector->Oem[4] == ' ') && 00034 (BootSector->Oem[5] == ' ') && 00035 (BootSector->Oem[6] == ' ') && 00036 (BootSector->Oem[7] == ' ')) 00037 { 00038 /* Success */ 00039 Result = TRUE; 00040 } 00041 00042 /* Return the result */ 00043 return Result; 00044 } 00045 00046 NTSTATUS 00047 NTAPI 00048 FsRecNtfsFsControl(IN PDEVICE_OBJECT DeviceObject, 00049 IN PIRP Irp) 00050 { 00051 PIO_STACK_LOCATION Stack; 00052 NTSTATUS Status; 00053 PDEVICE_OBJECT MountDevice; 00054 PPACKED_BOOT_SECTOR Bpb = NULL; 00055 ULONG SectorSize; 00056 LARGE_INTEGER Offset = {{0, 0}}, Offset2, Offset3, SectorCount; 00057 PAGED_CODE(); 00058 00059 /* Get the I/O Stack and check the function type */ 00060 Stack = IoGetCurrentIrpStackLocation(Irp); 00061 switch (Stack->MinorFunction) 00062 { 00063 case IRP_MN_MOUNT_VOLUME: 00064 00065 /* Assume failure */ 00066 Status = STATUS_UNRECOGNIZED_VOLUME; 00067 00068 /* Get the device object and request the sector size */ 00069 MountDevice = Stack->Parameters.MountVolume.DeviceObject; 00070 if ((FsRecGetDeviceSectorSize(MountDevice, &SectorSize)) && 00071 (FsRecGetDeviceSectors(MountDevice, SectorSize, &SectorCount))) 00072 { 00073 /* Setup other offsets to try */ 00074 Offset2.QuadPart = SectorCount.QuadPart >> 1; 00075 Offset2.QuadPart *= SectorSize; 00076 Offset3.QuadPart = (SectorCount.QuadPart - 1) * SectorSize; 00077 00078 /* Try to read the BPB */ 00079 if (FsRecReadBlock(MountDevice, 00080 &Offset, 00081 512, 00082 SectorSize, 00083 (PVOID)&Bpb, 00084 NULL)) 00085 { 00086 /* Check if it's an actual NTFS volume */ 00087 if (FsRecIsNtfsVolume(Bpb, SectorSize, &SectorCount)) 00088 { 00089 /* It is! */ 00090 Status = STATUS_FS_DRIVER_REQUIRED; 00091 } 00092 } 00093 else if (FsRecReadBlock(MountDevice, 00094 &Offset2, 00095 512, 00096 SectorSize, 00097 (PVOID)&Bpb, 00098 NULL)) 00099 { 00100 /* Check if it's an actual NTFS volume */ 00101 if (FsRecIsNtfsVolume(Bpb, SectorSize, &SectorCount)) 00102 { 00103 /* It is! */ 00104 Status = STATUS_FS_DRIVER_REQUIRED; 00105 } 00106 } 00107 else if (FsRecReadBlock(MountDevice, 00108 &Offset3, 00109 512, 00110 SectorSize, 00111 (PVOID)&Bpb, 00112 NULL)) 00113 { 00114 /* Check if it's an actual NTFS volume */ 00115 if (FsRecIsNtfsVolume(Bpb, SectorSize, &SectorCount)) 00116 { 00117 /* It is! */ 00118 Status = STATUS_FS_DRIVER_REQUIRED; 00119 } 00120 } 00121 00122 /* Free the boot sector if we have one */ 00123 ExFreePool(Bpb); 00124 } 00125 break; 00126 00127 case IRP_MN_LOAD_FILE_SYSTEM: 00128 00129 /* Load the file system */ 00130 Status = FsRecLoadFileSystem(DeviceObject, 00131 L"\\Registry\\Machine\\System\\CurrentControlSet\\Services\\Ntfs"); 00132 break; 00133 00134 default: 00135 00136 /* Invalid request */ 00137 Status = STATUS_INVALID_DEVICE_REQUEST; 00138 } 00139 00140 /* Return Status */ 00141 return Status; 00142 } 00143 00144 /* EOF */ Generated on Sat May 26 2012 04:17:58 for ReactOS by
1.7.6.1
|