ReactOS  0.4.15-dev-506-ga3ec01c
ntfs.c
Go to the documentation of this file.
1 /*
2  * COPYRIGHT: See COPYING in the top level directory
3  * PROJECT: ReactOS File System Recognizer
4  * FILE: drivers/filesystems/fs_rec/ntfs.c
5  * PURPOSE: NTFS Recognizer
6  * PROGRAMMER: Alex Ionescu (alex.ionescu@reactos.org)
7  * Eric Kohl
8  */
9 
10 /* INCLUDES *****************************************************************/
11 
12 #include "fs_rec.h"
13 
14 #define NDEBUG
15 #include <debug.h>
16 
17 /* FUNCTIONS ****************************************************************/
18 
19 BOOLEAN
20 NTAPI
22  IN ULONG BytesPerSector,
23  IN PLARGE_INTEGER NumberOfSectors)
24 {
25  /* Assume failure */
27 
28  UNREFERENCED_PARAMETER(BytesPerSector);
29  UNREFERENCED_PARAMETER(NumberOfSectors);
30 
31  PAGED_CODE();
32 
33  if ((BootSector->Oem[0] == 'N') &&
34  (BootSector->Oem[1] == 'T') &&
35  (BootSector->Oem[2] == 'F') &&
36  (BootSector->Oem[3] == 'S') &&
37  (BootSector->Oem[4] == ' ') &&
38  (BootSector->Oem[5] == ' ') &&
39  (BootSector->Oem[6] == ' ') &&
40  (BootSector->Oem[7] == ' '))
41  {
42  /* Success */
43  Result = TRUE;
44  }
45 
46  /* Return the result */
47  return Result;
48 }
49 
51 NTAPI
53  IN PIRP Irp)
54 {
55  PIO_STACK_LOCATION Stack;
57  PDEVICE_OBJECT MountDevice;
60  LARGE_INTEGER Offset = {{0, 0}}, Offset2, Offset3, SectorCount;
61  PAGED_CODE();
62 
63  /* Get the I/O Stack and check the function type */
65  switch (Stack->MinorFunction)
66  {
68 
69  /* Assume failure */
71 
72  /* Get the device object and request the sector size */
73  MountDevice = Stack->Parameters.MountVolume.DeviceObject;
74  if ((FsRecGetDeviceSectorSize(MountDevice, &SectorSize)) &&
76  {
77  /* Setup other offsets to try */
78  Offset2.QuadPart = SectorCount.QuadPart >> 1;
79  Offset2.QuadPart *= SectorSize;
80  Offset3.QuadPart = (SectorCount.QuadPart - 1) * SectorSize;
81 
82  /* Try to read the BPB */
83  if (FsRecReadBlock(MountDevice,
84  &Offset,
85  512,
86  SectorSize,
87  (PVOID)&Bpb,
88  NULL))
89  {
90  /* Check if it's an actual NTFS volume */
92  {
93  /* It is! */
95  }
96  }
97  else if (FsRecReadBlock(MountDevice,
98  &Offset2,
99  512,
100  SectorSize,
101  (PVOID)&Bpb,
102  NULL))
103  {
104  /* Check if it's an actual NTFS volume */
106  {
107  /* It is! */
109  }
110  }
111  else if (FsRecReadBlock(MountDevice,
112  &Offset3,
113  512,
114  SectorSize,
115  (PVOID)&Bpb,
116  NULL))
117  {
118  /* Check if it's an actual NTFS volume */
120  {
121  /* It is! */
123  }
124  }
125 
126  /* Free the boot sector if we have one */
127  ExFreePool(Bpb);
128  }
129  break;
130 
132 
133  /* Load the file system */
135  L"\\Registry\\Machine\\System\\CurrentControlSet\\Services\\Ntfs");
136  break;
137 
138  default:
139 
140  /* Invalid request */
142  }
143 
144  /* Return Status */
145  return Status;
146 }
147 
148 /* EOF */
#define IN
Definition: typedefs.h:39
#define TRUE
Definition: types.h:120
_In_ PIRP Irp
Definition: csq.h:116
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:323
BOOLEAN NTAPI FsRecGetDeviceSectorSize(IN PDEVICE_OBJECT DeviceObject, OUT PULONG SectorSize)
Definition: blockdev.c:80
LONG NTSTATUS
Definition: precomp.h:26
#define IRP_MN_LOAD_FILE_SYSTEM
Definition: iotypes.h:4052
#define STATUS_INVALID_DEVICE_REQUEST
Definition: udferr_usr.h:138
BOOLEAN NTAPI FsRecIsNtfsVolume(IN PPACKED_BOOT_SECTOR BootSector, IN ULONG BytesPerSector, IN PLARGE_INTEGER NumberOfSectors)
Definition: ntfs.c:21
#define STATUS_FS_DRIVER_REQUIRED
Definition: ntstatus.h:631
NTSTATUS(* NTAPI)(IN PFILE_FULL_EA_INFORMATION EaBuffer, IN ULONG EaLength, OUT PULONG ErrorOffset)
Definition: IoEaTest.cpp:117
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
#define STATUS_UNRECOGNIZED_VOLUME
Definition: udferr_usr.h:173
unsigned char BOOLEAN
smooth NULL
Definition: ftsmooth.c:416
_At_(*)(_In_ PWSK_CLIENT Client, _In_opt_ PUNICODE_STRING NodeName, _In_opt_ PUNICODE_STRING ServiceName, _In_opt_ ULONG NameSpace, _In_opt_ GUID *Provider, _In_opt_ PADDRINFOEXW Hints, _Outptr_ PADDRINFOEXW *Result, _In_opt_ PEPROCESS OwningProcess, _In_opt_ PETHREAD OwningThread, _Inout_ PIRP Irp Result)(Mem)) NTSTATUS(WSKAPI *PFN_WSK_GET_ADDRESS_INFO
Definition: wsk.h:426
#define IRP_MN_MOUNT_VOLUME
Definition: iotypes.h:4050
BOOLEAN NTAPI FsRecGetDeviceSectors(IN PDEVICE_OBJECT DeviceObject, IN ULONG SectorSize, OUT PLARGE_INTEGER SectorCount)
Definition: blockdev.c:24
static const WCHAR L[]
Definition: oid.c:1250
NTSTATUS NTAPI FsRecNtfsFsControl(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: ntfs.c:52
ULONG SectorCount
Definition: part_xbox.c:31
Status
Definition: gdiplustypes.h:24
BOOLEAN NTAPI FsRecReadBlock(IN PDEVICE_OBJECT DeviceObject, IN PLARGE_INTEGER Offset, IN ULONG Length, IN ULONG SectorSize, IN OUT PVOID *Buffer, OUT PBOOLEAN DeviceError OPTIONAL)
Definition: blockdev.c:152
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1569
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2745
NTSTATUS NTAPI FsRecLoadFileSystem(IN PDEVICE_OBJECT DeviceObject, IN PWCHAR DriverServiceName)
Definition: fs_rec.c:23
unsigned int ULONG
Definition: retypes.h:1
_In_ ULONG SectorSize
Definition: halfuncs.h:291
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:2774
INT Offset2
Definition: FsRtlDissect.c:14
#define ExFreePool(addr)
Definition: env_spec_w32.h:352
#define PAGED_CODE()