ReactOS  0.4.13-dev-259-g5ca9c9c
fs_rec.h File Reference
#include <ntifs.h>
#include <pshpack1.h>
#include <poppack.h>
Include dependency graph for fs_rec.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

union  _UCHAR1
 
union  _UCHAR2
 
union  _UCHAR4
 
struct  _PACKED_BIOS_PARAMETER_BLOCK
 
struct  _PACKED_BOOT_SECTOR
 
struct  BIOS_PARAMETER_BLOCK
 
struct  _TAG
 
struct  _EXTENT
 
struct  _AVDP
 
struct  _DEVICE_EXTENSION
 

Macros

#define FSREC_TAG   'cRsF'
 
#define UDFS_VRS_START_OFFSET   32768
 
#define UDFS_AVDP_SECTOR   256
 
#define ROUND_UP(n, align)   ROUND_DOWN(((ULONG)n) + (align) - 1, (align))
 
#define ROUND_DOWN(n, align)   (((ULONG)n) & ~((align) - 1l))
 
#define CopyUchar1(Dst, Src)
 
#define CopyUchar2(Dst, Src)
 
#define CopyUchar4(Dst, Src)
 
#define FatUnpackBios(Bios, Pbios)
 

Typedefs

typedef union _UCHAR1 UCHAR1
 
typedef union _UCHAR1PUCHAR1
 
typedef union _UCHAR2 UCHAR2
 
typedef union _UCHAR2PUCHAR2
 
typedef union _UCHAR4 UCHAR4
 
typedef union _UCHAR4PUCHAR4
 
typedef struct _PACKED_BIOS_PARAMETER_BLOCK PACKED_BIOS_PARAMETER_BLOCK
 
typedef struct _PACKED_BIOS_PARAMETER_BLOCKPPACKED_BIOS_PARAMETER_BLOCK
 
typedef struct _PACKED_BOOT_SECTOR PACKED_BOOT_SECTOR
 
typedef struct _PACKED_BOOT_SECTORPPACKED_BOOT_SECTOR
 
typedef struct BIOS_PARAMETER_BLOCK BIOS_PARAMETER_BLOCK
 
typedef struct BIOS_PARAMETER_BLOCKPBIOS_PARAMETER_BLOCK
 
typedef struct _TAG TAG
 
typedef struct _TAGPTAG
 
typedef struct _EXTENT EXTENT
 
typedef struct _EXTENTPEXTENT
 
typedef struct _AVDP AVDP
 
typedef struct _AVDPPAVDP
 
typedef enum _FILE_SYSTEM_TYPE FILE_SYSTEM_TYPE
 
typedef enum _FILE_SYSTEM_TYPEPFILE_SYSTEM_TYPE
 
typedef enum _FS_REC_STATE FS_REC_STATE
 
typedef enum _FS_REC_STATEPFS_REC_STATE
 
typedef struct _DEVICE_EXTENSION DEVICE_EXTENSION
 
typedef struct _DEVICE_EXTENSIONPDEVICE_EXTENSION
 

Enumerations

enum  _FILE_SYSTEM_TYPE {
  FS_TYPE_UNUSED, FS_TYPE_VFAT, FS_TYPE_NTFS, FS_TYPE_CDFS,
  FS_TYPE_UDFS, FS_TYPE_EXT2, FS_TYPE_BTRFS, FS_TYPE_REISERFS,
  FS_TYPE_FFS
}
 
enum  _FS_REC_STATE { Pending, Loaded, Unloading }
 

Functions

NTSTATUS NTAPI FsRecCdfsFsControl (IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
 
NTSTATUS NTAPI FsRecVfatFsControl (IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
 
NTSTATUS NTAPI FsRecNtfsFsControl (IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
 
NTSTATUS NTAPI FsRecUdfsFsControl (IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
 
NTSTATUS NTAPI FsRecExt2FsControl (IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
 
NTSTATUS NTAPI FsRecBtrfsFsControl (IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
 
NTSTATUS NTAPI FsRecReiserfsFsControl (IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
 
NTSTATUS NTAPI FsRecFfsFsControl (IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
 
BOOLEAN NTAPI FsRecGetDeviceSectors (IN PDEVICE_OBJECT DeviceObject, IN ULONG SectorSize, OUT PLARGE_INTEGER SectorCount)
 
BOOLEAN NTAPI FsRecGetDeviceSectorSize (IN PDEVICE_OBJECT DeviceObject, OUT PULONG SectorSize)
 
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)
 
NTSTATUS NTAPI FsRecLoadFileSystem (IN PDEVICE_OBJECT DeviceObject, IN PWCHAR DriverServiceName)
 

Macro Definition Documentation

◆ CopyUchar1

#define CopyUchar1 (   Dst,
  Src 
)
Value:
{ \
*((UCHAR1 *)(Dst)) = *((UNALIGNED UCHAR1 *)(Src)); \
}
#define UNALIGNED
Definition: crtdefs.h:132
#define Dst
Definition: mesh.h:153

Definition at line 50 of file fs_rec.h.

◆ CopyUchar2

#define CopyUchar2 (   Dst,
  Src 
)
Value:
{ \
*((UCHAR2 *)(Dst)) = *((UNALIGNED UCHAR2 *)(Src)); \
}
#define UNALIGNED
Definition: crtdefs.h:132
#define Dst
Definition: mesh.h:153

Definition at line 54 of file fs_rec.h.

◆ CopyUchar4

#define CopyUchar4 (   Dst,
  Src 
)
Value:
{ \
*((UCHAR4 *)(Dst)) = *((UNALIGNED UCHAR4 *)(Src)); \
}
#define UNALIGNED
Definition: crtdefs.h:132
#define Dst
Definition: mesh.h:153

Definition at line 58 of file fs_rec.h.

◆ FatUnpackBios

#define FatUnpackBios (   Bios,
  Pbios 
)
Value:
{ \
CopyUchar2(&(Bios)->BytesPerSector, &(Pbios)->BytesPerSector[0] ); \
CopyUchar1(&(Bios)->SectorsPerCluster, &(Pbios)->SectorsPerCluster[0]); \
CopyUchar2(&(Bios)->ReservedSectors, &(Pbios)->ReservedSectors[0] ); \
CopyUchar1(&(Bios)->Fats, &(Pbios)->Fats[0] ); \
CopyUchar2(&(Bios)->RootEntries, &(Pbios)->RootEntries[0] ); \
CopyUchar2(&(Bios)->Sectors, &(Pbios)->Sectors[0] ); \
CopyUchar1(&(Bios)->Media, &(Pbios)->Media[0] ); \
CopyUchar2(&(Bios)->SectorsPerFat, &(Pbios)->SectorsPerFat[0] ); \
CopyUchar2(&(Bios)->SectorsPerTrack, &(Pbios)->SectorsPerTrack[0] ); \
CopyUchar2(&(Bios)->Heads, &(Pbios)->Heads[0] ); \
CopyUchar4(&(Bios)->HiddenSectors, &(Pbios)->HiddenSectors[0] ); \
CopyUchar4(&(Bios)->LargeSectors, &(Pbios)->LargeSectors[0] ); \
}
_In_ ULONG _In_ ULONG SectorsPerTrack
Definition: iofuncs.h:2066

Definition at line 62 of file fs_rec.h.

◆ FSREC_TAG

#define FSREC_TAG   'cRsF'

Definition at line 16 of file fs_rec.h.

◆ ROUND_DOWN

#define ROUND_DOWN (   n,
  align 
)    (((ULONG)n) & ~((align) - 1l))

Definition at line 27 of file fs_rec.h.

◆ ROUND_UP

#define ROUND_UP (   n,
  align 
)    ROUND_DOWN(((ULONG)n) + (align) - 1, (align))

Definition at line 24 of file fs_rec.h.

◆ UDFS_AVDP_SECTOR

#define UDFS_AVDP_SECTOR   256

Definition at line 20 of file fs_rec.h.

◆ UDFS_VRS_START_OFFSET

#define UDFS_VRS_START_OFFSET   32768

Definition at line 19 of file fs_rec.h.

Typedef Documentation

◆ AVDP

typedef struct _AVDP AVDP

◆ BIOS_PARAMETER_BLOCK

◆ DEVICE_EXTENSION

◆ EXTENT

◆ FILE_SYSTEM_TYPE

◆ FS_REC_STATE

◆ PACKED_BIOS_PARAMETER_BLOCK

◆ PACKED_BOOT_SECTOR

◆ PAVDP

typedef struct _AVDP * PAVDP

◆ PBIOS_PARAMETER_BLOCK

◆ PDEVICE_EXTENSION

◆ PEXTENT

typedef struct _EXTENT * PEXTENT

◆ PFILE_SYSTEM_TYPE

◆ PFS_REC_STATE

◆ PPACKED_BIOS_PARAMETER_BLOCK

◆ PPACKED_BOOT_SECTOR

◆ PTAG

typedef struct _TAG * PTAG

◆ PUCHAR1

typedef union _UCHAR1 * PUCHAR1

◆ PUCHAR2

typedef union _UCHAR2 * PUCHAR2

◆ PUCHAR4

typedef union _UCHAR4 * PUCHAR4

◆ TAG

static TAG

Definition at line 143 of file db.cpp.

◆ UCHAR1

typedef union _UCHAR1 UCHAR1

◆ UCHAR2

typedef union _UCHAR2 UCHAR2

◆ UCHAR4

typedef union _UCHAR4 UCHAR4

Enumeration Type Documentation

◆ _FILE_SYSTEM_TYPE

Enumerator
FS_TYPE_UNUSED 
FS_TYPE_VFAT 
FS_TYPE_NTFS 
FS_TYPE_CDFS 
FS_TYPE_UDFS 
FS_TYPE_EXT2 
FS_TYPE_BTRFS 
FS_TYPE_REISERFS 
FS_TYPE_FFS 

Definition at line 169 of file fs_rec.h.

170 {
172  FS_TYPE_VFAT,
173  FS_TYPE_NTFS,
174  FS_TYPE_CDFS,
175  FS_TYPE_UDFS,
176  FS_TYPE_EXT2,
179  FS_TYPE_FFS,
enum _FILE_SYSTEM_TYPE * PFILE_SYSTEM_TYPE
enum _FILE_SYSTEM_TYPE FILE_SYSTEM_TYPE

◆ _FS_REC_STATE

Enumerator
Pending 
Loaded 
Unloading 

Definition at line 183 of file fs_rec.h.

184 {
185  Pending,
186  Loaded,
187  Unloading
enum _FS_REC_STATE FS_REC_STATE
enum _FS_REC_STATE * PFS_REC_STATE
Definition: fs_rec.h:186

Function Documentation

◆ FsRecBtrfsFsControl()

NTSTATUS NTAPI FsRecBtrfsFsControl ( IN PDEVICE_OBJECT  DeviceObject,
IN PIRP  Irp 
)

Definition at line 30 of file btrfs.c.

32 {
33  PIO_STACK_LOCATION Stack;
35  PDEVICE_OBJECT MountDevice;
39  BOOLEAN DeviceError = FALSE;
40  PAGED_CODE();
41 
42  /* Get the I/O Stack and check the function type */
44  switch (Stack->MinorFunction)
45  {
47 
48  /* Assume failure */
50 
51  /* Get the device object and request the sector size */
52  MountDevice = Stack->Parameters.MountVolume.DeviceObject;
53  if (FsRecGetDeviceSectorSize(MountDevice, &SectorSize))
54  {
55  /* Try to read the superblock */
56  Offset.QuadPart = BTRFS_SB_OFFSET;
57  if (FsRecReadBlock(MountDevice,
58  &Offset,
60  SectorSize,
61  (PVOID)&Spb,
62  &DeviceError))
63  {
64  /* Check if it's an actual BTRFS volume */
65  if (FsRecIsBtrfsVolume(Spb))
66  {
67  /* It is! */
69  }
70  }
71 
72  /* Free the boot sector if we have one */
73  ExFreePool(Spb);
74  }
75  else
76  {
77  /* We have some sort of failure in the storage stack */
78  DeviceError = TRUE;
79  }
80 
81  /* Check if we have an error on the stack */
82  if (DeviceError)
83  {
84  /* Was this because of a floppy? */
85  if (MountDevice->Characteristics & FILE_FLOPPY_DISKETTE)
86  {
87  /* Let the FS try anyway */
89  }
90  }
91 
92  break;
93 
95 
96  /* Load the file system */
98  L"\\Registry\\Machine\\System\\CurrentControlSet\\Services\\btrfs");
99  break;
100 
101  default:
102 
103  /* Invalid request */
105  }
106 
107  /* Return Status */
108  return Status;
109 }
#define TRUE
Definition: types.h:120
_In_ PIRP Irp
Definition: csq.h:116
BOOLEAN NTAPI FsRecGetDeviceSectorSize(IN PDEVICE_OBJECT DeviceObject, OUT PULONG SectorSize)
Definition: blockdev.c:80
LONG NTSTATUS
Definition: precomp.h:26
Status
Definition: btrfs.c:3909
#define IRP_MN_LOAD_FILE_SYSTEM
Definition: iotypes.h:4049
#define STATUS_INVALID_DEVICE_REQUEST
Definition: udferr_usr.h:138
#define STATUS_FS_DRIVER_REQUIRED
Definition: ntstatus.h:631
#define PAGED_CODE()
Definition: video.h:57
_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
BOOLEAN NTAPI FsRecIsBtrfsVolume(IN PBTRFS_SUPER_BLOCK SuperBlock)
Definition: btrfs.c:22
#define IRP_MN_MOUNT_VOLUME
Definition: iotypes.h:4047
static const WCHAR L[]
Definition: oid.c:1250
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:1560
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2745
#define BTRFS_SB_SIZE
Definition: btrfs.h:31
#define BTRFS_SB_OFFSET
Definition: btrfs.h:30
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:2771
#define FILE_FLOPPY_DISKETTE
Definition: nt_native.h:809
#define ExFreePool(addr)
Definition: env_spec_w32.h:352

Referenced by FsRecFsControl().

◆ FsRecCdfsFsControl()

NTSTATUS NTAPI FsRecCdfsFsControl ( IN PDEVICE_OBJECT  DeviceObject,
IN PIRP  Irp 
)

Definition at line 66 of file cdfs.c.

68 {
69  PDEVICE_OBJECT MountDevice;
71  PIO_STACK_LOCATION Stack;
73  PAGED_CODE();
74 
75  /* Get the I/O Stack and check the function type */
77  switch (Stack->MinorFunction)
78  {
80 
81  /* Assume failure */
83 
84  /* Get the device object and request the sector size */
85  MountDevice = Stack->Parameters.MountVolume.DeviceObject;
86  if (FsRecGetDeviceSectorSize(MountDevice, &SectorSize))
87  {
88  /* Check if it's an actual CDFS (ISO-9660) volume */
89  if (FsRecIsCdfsVolume(MountDevice, SectorSize))
90  {
91  /* It is! */
93  }
94  }
95 
96  break;
97 
99 
100  /* Load the file system */
102  L"\\Registry\\Machine\\System\\CurrentControlSet\\Services\\Cdfs");
103  break;
104 
105  default:
106 
107  /* Invalid request */
109  }
110 
111  /* Return Status */
112  return Status;
113 }
_In_ PIRP Irp
Definition: csq.h:116
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:4049
#define STATUS_INVALID_DEVICE_REQUEST
Definition: udferr_usr.h:138
#define STATUS_FS_DRIVER_REQUIRED
Definition: ntstatus.h:631
#define PAGED_CODE()
Definition: video.h:57
#define STATUS_UNRECOGNIZED_VOLUME
Definition: udferr_usr.h:173
#define IRP_MN_MOUNT_VOLUME
Definition: iotypes.h:4047
static const WCHAR L[]
Definition: oid.c:1250
Status
Definition: gdiplustypes.h:24
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2745
BOOLEAN NTAPI FsRecIsCdfsVolume(IN PDEVICE_OBJECT DeviceObject, IN ULONG SectorSize)
Definition: cdfs.c:23
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:2771

Referenced by FsRecFsControl().

◆ FsRecExt2FsControl()

NTSTATUS NTAPI FsRecExt2FsControl ( IN PDEVICE_OBJECT  DeviceObject,
IN PIRP  Irp 
)

Definition at line 30 of file ext2.c.

32 {
33  PIO_STACK_LOCATION Stack;
35  PDEVICE_OBJECT MountDevice;
36  PEXT2_SUPER_BLOCK Spb = NULL;
39  BOOLEAN DeviceError = FALSE;
40  PAGED_CODE();
41 
42  /* Get the I/O Stack and check the function type */
44  switch (Stack->MinorFunction)
45  {
47 
48  /* Assume failure */
50 
51  /* Get the device object and request the sector size */
52  MountDevice = Stack->Parameters.MountVolume.DeviceObject;
53  if (FsRecGetDeviceSectorSize(MountDevice, &SectorSize))
54  {
55  /* Try to read the superblock */
56  Offset.QuadPart = EXT2_SB_OFFSET;
57  if (FsRecReadBlock(MountDevice,
58  &Offset,
60  SectorSize,
61  (PVOID)&Spb,
62  &DeviceError))
63  {
64  /* Check if it's an actual EXT2 volume */
65  if (FsRecIsExt2Volume(Spb))
66  {
67  /* It is! */
69  }
70  }
71 
72  /* Free the boot sector if we have one */
73  ExFreePool(Spb);
74  }
75  else
76  {
77  /* We have some sort of failure in the storage stack */
78  DeviceError = TRUE;
79  }
80 
81  /* Check if we have an error on the stack */
82  if (DeviceError)
83  {
84  /* Was this because of a floppy? */
85  if (MountDevice->Characteristics & FILE_FLOPPY_DISKETTE)
86  {
87  /* Let the FS try anyway */
89  }
90  }
91 
92  break;
93 
95 
96  /* Load the file system */
98  L"\\Registry\\Machine\\System\\CurrentControlSet\\Services\\Ext2fs");
99  break;
100 
101  default:
102 
103  /* Invalid request */
105  }
106 
107  /* Return Status */
108  return Status;
109 }
#define TRUE
Definition: types.h:120
_In_ PIRP Irp
Definition: csq.h:116
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:4049
#define STATUS_INVALID_DEVICE_REQUEST
Definition: udferr_usr.h:138
#define STATUS_FS_DRIVER_REQUIRED
Definition: ntstatus.h:631
#define PAGED_CODE()
Definition: video.h:57
_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
#define IRP_MN_MOUNT_VOLUME
Definition: iotypes.h:4047
BOOLEAN NTAPI FsRecIsExt2Volume(IN PEXT2_SUPER_BLOCK SuperBlock)
Definition: ext2.c:22
static const WCHAR L[]
Definition: oid.c:1250
#define EXT2_SB_OFFSET
Definition: ext2.h:47
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:1560
__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
#define EXT2_SB_SIZE
Definition: ext2.h:48
_In_ ULONG SectorSize
Definition: halfuncs.h:291
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:2771
#define FILE_FLOPPY_DISKETTE
Definition: nt_native.h:809
#define ExFreePool(addr)
Definition: env_spec_w32.h:352

Referenced by FsRecFsControl().

◆ FsRecFfsFsControl()

NTSTATUS NTAPI FsRecFfsFsControl ( IN PDEVICE_OBJECT  DeviceObject,
IN PIRP  Irp 
)

Definition at line 43 of file ffs.c.

45 {
46  PIO_STACK_LOCATION Stack;
48  PDEVICE_OBJECT MountDevice;
49  PFFSD_SUPER_BLOCK Spb = NULL;
50  PFFSD_DISKLABEL DiskLabel = NULL;
51  ULONGLONG FSOffset = 0;
52  int i;
55  BOOLEAN DeviceError = FALSE;
56  PAGED_CODE();
57 
58  /* Get the I/O Stack and check the function type */
60  switch (Stack->MinorFunction)
61  {
63 
64  /* Assume failure */
66 
67  /* Get the device object and request the sector size */
68  MountDevice = Stack->Parameters.MountVolume.DeviceObject;
69  if (FsRecGetDeviceSectorSize(MountDevice, &SectorSize))
70  {
71  /* Try to read the disklabel */
72  Offset.QuadPart = LABELSECTOR*SectorSize;
73  if (FsRecReadBlock(MountDevice,
74  &Offset,
75  SectorSize,
76  SectorSize,
77  (PVOID)&DiskLabel,
78  &DeviceError))
79  {
80  /* Check if it's an actual FFS disk label */
81  if (FsRecIsFfsDiskLabel(DiskLabel))
82  {
83  /* It is! */
84  for (i = 0; i < MAXPARTITIONS; i++)
85  {
86  if (DiskLabel->d_partitions[i].p_fstype == FS_BSDFFS)
87  {
88  /* Important */
89  FSOffset = DiskLabel->d_partitions[i].p_offset;
90  FSOffset = FSOffset * SectorSize;
91  /* Try to read the superblock */
92  Offset.QuadPart = FSOffset+SBLOCK_UFS1;
93  if (FsRecReadBlock(MountDevice,
94  &Offset,
95  SBLOCKSIZE,
96  SectorSize,
97  (PVOID)&Spb,
98  &DeviceError))
99  {
100  /* Check if it's an actual FFS volume */
101  if (FsRecIsFfs1Volume(Spb))
102  {
103  /* It is! */
105  }
106  else
107  {
108  /* Free the boot sector if we have one */
109  ExFreePool(Spb);
110  Spb = NULL;
111 
112  Offset.QuadPart = FSOffset+SBLOCK_UFS2;
113  if (FsRecReadBlock(MountDevice,
114  &Offset,
115  SBLOCKSIZE,
116  SectorSize,
117  (PVOID)&Spb,
118  &DeviceError))
119  {
120  /* Check if it's an actual FFS volume */
121  if (FsRecIsFfs2Volume(Spb))
122  {
123  /* It is! */
125  }
126  }
127  }
128  }
129 
130  /* Free the boot sector if we have one */
131  ExFreePool(Spb);
132  Spb = NULL;
133  }
134  }
135  }
136  else
137  {
138  /* Try to read the superblock */
139  Offset.QuadPart = FSOffset+SBLOCK_UFS1;
140  if (FsRecReadBlock(MountDevice,
141  &Offset,
142  SBLOCKSIZE,
143  SectorSize,
144  (PVOID)&Spb,
145  &DeviceError))
146  {
147  /* Check if it's an actual FFS volume */
148  if (FsRecIsFfs1Volume(Spb))
149  {
150  /* It is! */
152  }
153  else
154  {
155  /* Free the boot sector if we have one */
156  ExFreePool(Spb);
157  Spb = NULL;
158 
159  Offset.QuadPart = FSOffset+SBLOCK_UFS2;
160  if (FsRecReadBlock(MountDevice,
161  &Offset,
162  SBLOCKSIZE,
163  SectorSize,
164  (PVOID)&Spb,
165  &DeviceError))
166  {
167  /* Check if it's an actual FFS volume */
168  if (FsRecIsFfs2Volume(Spb))
169  {
170  /* It is! */
172  }
173  }
174  }
175  }
176 
177  /* Free the boot sector if we have one */
178  ExFreePool(Spb);
179  Spb = NULL;
180  }
181  }
182 
183  /* Free the boot sector if we have one */
184  ExFreePool(DiskLabel);
185  }
186  else
187  {
188  /* We have some sort of failure in the storage stack */
189  DeviceError = TRUE;
190  }
191 
192  /* Check if we have an error on the stack */
193  if (DeviceError)
194  {
195  /* Was this because of a floppy? */
196  if (MountDevice->Characteristics & FILE_FLOPPY_DISKETTE)
197  {
198  /* Let the FS try anyway */
200  }
201  }
202 
203  break;
204 
206 
207  /* Load the file system */
209  L"\\Registry\\Machine\\System\\CurrentControlSet\\Services\\ffs");
210  break;
211 
212  default:
213 
214  /* Invalid request */
216  }
217 
218  /* Return Status */
219  return Status;
220 }
BOOLEAN NTAPI FsRecIsFfs1Volume(IN PFFSD_SUPER_BLOCK sb)
Definition: ffs.c:29
BOOLEAN NTAPI FsRecIsFfsDiskLabel(IN PFFSD_DISKLABEL dl)
Definition: ffs.c:22
#define TRUE
Definition: types.h:120
BOOLEAN NTAPI FsRecIsFfs2Volume(IN PFFSD_SUPER_BLOCK sb)
Definition: ffs.c:36
_In_ PIRP Irp
Definition: csq.h:116
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:4049
#define STATUS_INVALID_DEVICE_REQUEST
Definition: udferr_usr.h:138
#define STATUS_FS_DRIVER_REQUIRED
Definition: ntstatus.h:631
Definition: fs.h:235
#define PAGED_CODE()
Definition: video.h:57
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
_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
#define IRP_MN_MOUNT_VOLUME
Definition: iotypes.h:4047
uint64_t ULONGLONG
Definition: typedefs.h:65
#define MAXPARTITIONS
Definition: disklabel.h:65
#define FS_BSDFFS
Definition: disklabel.h:360
static const WCHAR L[]
Definition: oid.c:1250
#define LABELSECTOR
Definition: disklabel.h:63
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:1560
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2745
#define SBLOCKSIZE
Definition: fs.h:95
NTSTATUS NTAPI FsRecLoadFileSystem(IN PDEVICE_OBJECT DeviceObject, IN PWCHAR DriverServiceName)
Definition: fs_rec.c:23
#define SBLOCK_UFS2
Definition: fs.h:93
unsigned int ULONG
Definition: retypes.h:1
_In_ ULONG SectorSize
Definition: halfuncs.h:291
#define SBLOCK_UFS1
Definition: fs.h:92
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:2771
#define FILE_FLOPPY_DISKETTE
Definition: nt_native.h:809
#define ExFreePool(addr)
Definition: env_spec_w32.h:352

Referenced by FsRecFsControl().

◆ FsRecGetDeviceSectors()

BOOLEAN NTAPI FsRecGetDeviceSectors ( IN PDEVICE_OBJECT  DeviceObject,
IN ULONG  SectorSize,
OUT PLARGE_INTEGER  SectorCount 
)

Definition at line 24 of file blockdev.c.

27 {
30  KEVENT Event;
31  PIRP Irp;
34  PAGED_CODE();
35 
36  /* Only needed for disks */
37  if (DeviceObject->DeviceType != FILE_DEVICE_DISK) return FALSE;
38 
39  /* Build the information IRP */
43  NULL,
44  0,
46  sizeof(PARTITION_INFORMATION),
47  FALSE,
48  &Event,
49  &IoStatusBlock);
50  if (!Irp) return FALSE;
51 
52  /* Override verification */
54 
55  /* Do the request */
57  if (Status == STATUS_PENDING)
58  {
59  /* Wait for completion */
61  Executive,
62  KernelMode,
63  FALSE,
64  NULL);
66  }
67 
68  /* Fail if we couldn't get the data */
69  if (!NT_SUCCESS(Status)) return FALSE;
70 
71  /* Otherwise, return the number of sectors */
73  SectorSize,
74  &Remainder);
75  return TRUE;
76 }
#define FILE_DEVICE_DISK
Definition: winioctl.h:112
#define TRUE
Definition: types.h:120
_In_ PIRP Irp
Definition: csq.h:116
LONG NTSTATUS
Definition: precomp.h:26
NTSTATUS NTAPI KeWaitForSingleObject(IN PVOID Object, IN KWAIT_REASON WaitReason, IN KPROCESSOR_MODE WaitMode, IN BOOLEAN Alertable, IN PLARGE_INTEGER Timeout OPTIONAL)
Definition: wait.c:416
#define PAGED_CODE()
Definition: video.h:57
_In_ PVOID _In_ ULONG Event
Definition: iotypes.h:434
smooth NULL
Definition: ftsmooth.c:416
#define SL_OVERRIDE_VERIFY_VOLUME
Definition: iotypes.h:1779
NTSYSAPI LONGLONG WINAPI RtlExtendedLargeIntegerDivide(LONGLONG, INT, INT *)
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define STATUS_PENDING
Definition: ntstatus.h:82
_In_ ULONG _In_ struct _SET_PARTITION_INFORMATION_EX * PartitionInfo
Definition: iofuncs.h:2101
#define IOCTL_DISK_GET_PARTITION_INFO
Definition: ntdddisk.h:88
ULONG SectorCount
Definition: part_xbox.c:32
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetNextIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2647
Status
Definition: gdiplustypes.h:24
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
static OUT PIO_STATUS_BLOCK IoStatusBlock
Definition: pipe.c:75
NTSTATUS NTAPI IoCallDriver(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: irp.c:1218
PIRP NTAPI IoBuildDeviceIoControlRequest(IN ULONG IoControlCode, IN PDEVICE_OBJECT DeviceObject, IN PVOID InputBuffer, IN ULONG InputBufferLength, IN PVOID OutputBuffer, IN ULONG OutputBufferLength, IN BOOLEAN InternalDeviceIoControl, IN PKEVENT Event, IN PIO_STATUS_BLOCK IoStatusBlock)
Definition: irp.c:881
unsigned int ULONG
Definition: retypes.h:1
_In_ ULONG SectorSize
Definition: halfuncs.h:291
_In_ LARGE_INTEGER _Out_opt_ PLARGE_INTEGER Remainder
Definition: rtlfuncs.h:3046

Referenced by FsRecNtfsFsControl().

◆ FsRecGetDeviceSectorSize()

BOOLEAN NTAPI FsRecGetDeviceSectorSize ( IN PDEVICE_OBJECT  DeviceObject,
OUT PULONG  SectorSize 
)

Definition at line 80 of file blockdev.c.

82 {
83  DISK_GEOMETRY DiskGeometry;
85  KEVENT Event;
86  PIRP Irp;
89  PAGED_CODE();
90 
91  /* Check what device we have */
92  switch (DeviceObject->DeviceType)
93  {
94  case FILE_DEVICE_CD_ROM:
95 
96  /* Use the CD IOCTL */
98  break;
99 
100  case FILE_DEVICE_DISK:
101 
102  /* Use the Disk IOCTL */
104  break;
105 
106  default:
107 
108  /* Invalid device type */
109  return FALSE;
110  }
111 
112  /* Build the information IRP */
115  DeviceObject,
116  NULL,
117  0,
118  &DiskGeometry,
119  sizeof(DISK_GEOMETRY),
120  FALSE,
121  &Event,
122  &IoStatusBlock);
123  if (!Irp) return FALSE;
124 
125  /* Override verification */
127 
128  /* Do the request */
130  if (Status == STATUS_PENDING)
131  {
132  /* Wait for completion */
134  Executive,
135  KernelMode,
136  FALSE,
137  NULL);
139  }
140 
141  /* Fail if we couldn't get the data */
142  if (!NT_SUCCESS(Status)) return FALSE;
143 
144  /* Return the sector size if it's valid */
145  if (!DiskGeometry.BytesPerSector) return FALSE;
146  *SectorSize = DiskGeometry.BytesPerSector;
147  return TRUE;
148 }
#define FILE_DEVICE_DISK
Definition: winioctl.h:112
#define TRUE
Definition: types.h:120
_In_ PIRP Irp
Definition: csq.h:116
LONG NTSTATUS
Definition: precomp.h:26
ULONG BytesPerSector
Definition: ntdddisk.h:376
NTSTATUS NTAPI KeWaitForSingleObject(IN PVOID Object, IN KWAIT_REASON WaitReason, IN KPROCESSOR_MODE WaitMode, IN BOOLEAN Alertable, IN PLARGE_INTEGER Timeout OPTIONAL)
Definition: wait.c:416
#define PAGED_CODE()
Definition: video.h:57
#define FILE_DEVICE_CD_ROM
Definition: winioctl.h:107
_In_ PVOID _In_ ULONG Event
Definition: iotypes.h:434
smooth NULL
Definition: ftsmooth.c:416
#define SL_OVERRIDE_VERIFY_VOLUME
Definition: iotypes.h:1779
_IRQL_requires_same_ typedef _In_ ULONG ControlCode
Definition: wmitypes.h:55
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define STATUS_PENDING
Definition: ntstatus.h:82
#define IOCTL_CDROM_GET_DRIVE_GEOMETRY
Definition: ntddcdrm.h:46
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetNextIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2647
Status
Definition: gdiplustypes.h:24
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
static OUT PIO_STATUS_BLOCK IoStatusBlock
Definition: pipe.c:75
NTSTATUS NTAPI IoCallDriver(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: irp.c:1218
PIRP NTAPI IoBuildDeviceIoControlRequest(IN ULONG IoControlCode, IN PDEVICE_OBJECT DeviceObject, IN PVOID InputBuffer, IN ULONG InputBufferLength, IN PVOID OutputBuffer, IN ULONG OutputBufferLength, IN BOOLEAN InternalDeviceIoControl, IN PKEVENT Event, IN PIO_STATUS_BLOCK IoStatusBlock)
Definition: irp.c:881
unsigned int ULONG
Definition: retypes.h:1
_In_ ULONG SectorSize
Definition: halfuncs.h:291
#define IOCTL_DISK_GET_DRIVE_GEOMETRY
Definition: cdrw_usr.h:169

Referenced by FsRecBtrfsFsControl(), FsRecCdfsFsControl(), FsRecExt2FsControl(), FsRecFfsFsControl(), FsRecNtfsFsControl(), FsRecReiserfsFsControl(), FsRecUdfsFsControl(), and FsRecVfatFsControl().

◆ FsRecLoadFileSystem()

NTSTATUS NTAPI FsRecLoadFileSystem ( IN PDEVICE_OBJECT  DeviceObject,
IN PWCHAR  DriverServiceName 
)

Definition at line 23 of file fs_rec.c.

25 {
26  UNICODE_STRING DriverName;
29  PAGED_CODE();
30 
31  /* Make sure we haven't already been called */
32  if (DeviceExtension->State != Loaded)
33  {
34  /* Acquire the load lock */
36  Executive,
37  KernelMode,
38  FALSE,
39  NULL);
41 
42  /* Make sure we're active */
43  if (DeviceExtension->State == Pending)
44  {
45  /* Load the FS driver */
46  RtlInitUnicodeString(&DriverName, DriverServiceName);
47  Status = ZwLoadDriver(&DriverName);
48 
49  /* Loop all the linked recognizer objects */
50  while (DeviceExtension->State != Unloading)
51  {
52  /* Set them to the unload state */
53  DeviceExtension->State = Unloading;
54 
55  /* Go to the next one */
56  DeviceObject = DeviceExtension->Alternate;
57  DeviceExtension = DeviceObject->DeviceExtension;
58  }
59  }
60 
61  /* Make sure that we haven't already loaded the FS */
62  if (DeviceExtension->State != Loaded)
63  {
64  /* Unregister us, and set us as loaded */
66  DeviceExtension->State = Loaded;
67  }
68 
69  /* Release the lock */
72  }
73 
74  /* Return */
75  return Status;
76 }
VOID NTAPI IoUnregisterFileSystem(IN PDEVICE_OBJECT DeviceObject)
Definition: volume.c:1053
LONG NTSTATUS
Definition: precomp.h:26
LONG NTAPI KeSetEvent(IN PKEVENT Event, IN KPRIORITY Increment, IN BOOLEAN Wait)
Definition: eventobj.c:159
NTSTATUS NTAPI KeWaitForSingleObject(IN PVOID Object, IN KWAIT_REASON WaitReason, IN KPROCESSOR_MODE WaitMode, IN BOOLEAN Alertable, IN PLARGE_INTEGER Timeout OPTIONAL)
Definition: wait.c:416
#define PAGED_CODE()
Definition: video.h:57
Definition: fs_rec.h:186
PKEVENT FsRecLoadSync
Definition: fs_rec.c:17
PVOID DeviceExtension
Definition: env_spec_w32.h:418
smooth NULL
Definition: ftsmooth.c:416
#define KeEnterCriticalRegion()
Definition: ke_x.h:83
Status
Definition: gdiplustypes.h:24
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
#define KeLeaveCriticalRegion()
Definition: ke_x.h:114
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define STATUS_IMAGE_ALREADY_LOADED
Definition: ntstatus.h:492

Referenced by FsRecBtrfsFsControl(), FsRecCdfsFsControl(), FsRecExt2FsControl(), FsRecFfsFsControl(), FsRecNtfsFsControl(), FsRecReiserfsFsControl(), FsRecUdfsFsControl(), and FsRecVfatFsControl().

◆ FsRecNtfsFsControl()

NTSTATUS NTAPI FsRecNtfsFsControl ( IN PDEVICE_OBJECT  DeviceObject,
IN PIRP  Irp 
)

Definition at line 52 of file ntfs.c.

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 }
_In_ PIRP Irp
Definition: csq.h:116
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:4049
#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
#define PAGED_CODE()
Definition: video.h:57
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
#define STATUS_UNRECOGNIZED_VOLUME
Definition: udferr_usr.h:173
smooth NULL
Definition: ftsmooth.c:416
#define IRP_MN_MOUNT_VOLUME
Definition: iotypes.h:4047
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
ULONG SectorCount
Definition: part_xbox.c:32
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:1560
__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:2771
INT Offset2
Definition: FsRtlDissect.c:14
#define ExFreePool(addr)
Definition: env_spec_w32.h:352

Referenced by FsRecFsControl().

◆ FsRecReadBlock()

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 at line 152 of file blockdev.c.

158 {
160  KEVENT Event;
161  PIRP Irp;
163  PAGED_CODE();
164 
165  /* Assume failure */
166  if (DeviceError) *DeviceError = FALSE;
167 
168  /* Check if the caller requested too little */
169  if (Length < SectorSize)
170  {
171  /* Read at least the sector size */
172  Length = SectorSize;
173  }
174  else
175  {
176  /* Otherwise, just round up the request to sector size */
178  }
179 
180  /* Check if the caller gave us a buffer */
181  if (!*Buffer)
182  {
183  /* He didn't, allocate one */
186  FSREC_TAG);
187  if (!*Buffer) return FALSE;
188  }
189 
190  /* Build the IRP */
193  DeviceObject,
194  *Buffer,
195  Length,
196  Offset,
197  &Event,
198  &IoStatusBlock);
199  if (!Irp) return FALSE;
200 
201  /* Override verification */
203 
204  /* Do the request */
206  if (Status == STATUS_PENDING)
207  {
208  /* Wait for completion */
210  Executive,
211  KernelMode,
212  FALSE,
213  NULL);
215  }
216 
217  /* Check if we couldn't get the data */
218  if (!NT_SUCCESS(Status))
219  {
220  /* Check if caller wanted to know about the device and fail */
221  if (DeviceError) *DeviceError = TRUE;
222  return FALSE;
223  }
224 
225  /* All went well */
226  return TRUE;
227 }
#define TRUE
Definition: types.h:120
#define ROUND_UP(n, align)
Definition: eventvwr.h:31
PIRP NTAPI IoBuildSynchronousFsdRequest(IN ULONG MajorFunction, IN PDEVICE_OBJECT DeviceObject, IN PVOID Buffer, IN ULONG Length, IN PLARGE_INTEGER StartingOffset, IN PKEVENT Event, IN PIO_STATUS_BLOCK IoStatusBlock)
Definition: irp.c:1069
_In_ PIRP Irp
Definition: csq.h:116
LONG NTSTATUS
Definition: precomp.h:26
NTSTATUS NTAPI KeWaitForSingleObject(IN PVOID Object, IN KWAIT_REASON WaitReason, IN KPROCESSOR_MODE WaitMode, IN BOOLEAN Alertable, IN PLARGE_INTEGER Timeout OPTIONAL)
Definition: wait.c:416
#define PAGED_CODE()
Definition: video.h:57
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
_In_ PVOID _In_ ULONG Event
Definition: iotypes.h:434
smooth NULL
Definition: ftsmooth.c:416
#define SL_OVERRIDE_VERIFY_VOLUME
Definition: iotypes.h:1779
Definition: bufpool.h:45
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define STATUS_PENDING
Definition: ntstatus.h:82
#define FSREC_TAG
Definition: fs_rec.h:16
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetNextIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2647
Status
Definition: gdiplustypes.h:24
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
#define ROUND_TO_PAGES(Size)
static OUT PIO_STATUS_BLOCK IoStatusBlock
Definition: pipe.c:75
NTSTATUS NTAPI IoCallDriver(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: irp.c:1218
#define IRP_MJ_READ
Definition: rdpdr.c:46
_In_ ULONG SectorSize
Definition: halfuncs.h:291

Referenced by FsRecBtrfsFsControl(), FsRecExt2FsControl(), FsRecFfsFsControl(), FsRecIsCdfsVolume(), FsRecIsUdfsVolume(), FsRecNtfsFsControl(), FsRecReiserfsFsControl(), and FsRecVfatFsControl().

◆ FsRecReiserfsFsControl()

NTSTATUS NTAPI FsRecReiserfsFsControl ( IN PDEVICE_OBJECT  DeviceObject,
IN PIRP  Irp 
)

Definition at line 43 of file reiserfs.c.

45 {
46  PIO_STACK_LOCATION Stack;
48  PDEVICE_OBJECT MountDevice;
49  PRFSD_SUPER_BLOCK Spb = NULL;
52  BOOLEAN DeviceError = FALSE;
53  PAGED_CODE();
54 
55  /* Get the I/O Stack and check the function type */
57  switch (Stack->MinorFunction)
58  {
60 
61  /* Assume failure */
63 
64  /* Get the device object and request the sector size */
65  MountDevice = Stack->Parameters.MountVolume.DeviceObject;
66  if (FsRecGetDeviceSectorSize(MountDevice, &SectorSize))
67  {
68  /* Try to read the superblock */
70  if (FsRecReadBlock(MountDevice,
71  &Offset,
72  SectorSize,
73  SectorSize,
74  (PVOID)&Spb,
75  &DeviceError))
76  {
77  /* Check if it's an actual BTRFS volume */
78  if (FsRecIsReiserfsVolume(Spb))
79  {
80  /* It is! */
82  }
83  }
84 
85  /* Free the boot sector if we have one */
86  ExFreePool(Spb);
87  }
88  else
89  {
90  /* We have some sort of failure in the storage stack */
91  DeviceError = TRUE;
92  }
93 
94  /* Check if we have an error on the stack */
95  if (DeviceError)
96  {
97  /* Was this because of a floppy? */
98  if (MountDevice->Characteristics & FILE_FLOPPY_DISKETTE)
99  {
100  /* Let the FS try anyway */
102  }
103  }
104 
105  break;
106 
108 
109  /* Load the file system */
111  L"\\Registry\\Machine\\System\\CurrentControlSet\\Services\\reiserfs");
112  break;
113 
114  default:
115 
116  /* Invalid request */
118  }
119 
120  /* Return Status */
121  return Status;
122 }
#define TRUE
Definition: types.h:120
_In_ PIRP Irp
Definition: csq.h:116
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:4049
#define STATUS_INVALID_DEVICE_REQUEST
Definition: udferr_usr.h:138
#define STATUS_FS_DRIVER_REQUIRED
Definition: ntstatus.h:631
#define PAGED_CODE()
Definition: video.h:57
_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
#define IRP_MN_MOUNT_VOLUME
Definition: iotypes.h:4047
#define REISERFS_DISK_OFFSET_IN_BYTES
Definition: reiserfs.h:72
static const WCHAR L[]
Definition: oid.c:1250
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:1560
__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:2771
#define FILE_FLOPPY_DISKETTE
Definition: nt_native.h:809
BOOLEAN NTAPI FsRecIsReiserfsVolume(IN PRFSD_SUPER_BLOCK sb)
Definition: reiserfs.c:22
#define ExFreePool(addr)
Definition: env_spec_w32.h:352

Referenced by FsRecFsControl().

◆ FsRecUdfsFsControl()

NTSTATUS NTAPI FsRecUdfsFsControl ( IN PDEVICE_OBJECT  DeviceObject,
IN PIRP  Irp 
)

Definition at line 106 of file udfs.c.

108 {
109  PIO_STACK_LOCATION Stack;
111  PDEVICE_OBJECT MountDevice;
113  PAGED_CODE();
114 
115  /* Get the I/O Stack and check the function type */
117  switch (Stack->MinorFunction)
118  {
119  case IRP_MN_MOUNT_VOLUME:
120 
121  /* Assume failure */
123 
124  /* Get the device object and request the sector size */
125  MountDevice = Stack->Parameters.MountVolume.DeviceObject;
126  if (FsRecGetDeviceSectorSize(MountDevice, &SectorSize))
127  {
128  /* Check if it's an actual UDF volume */
129  if (FsRecIsUdfsVolume(MountDevice, SectorSize))
130  {
131  /* It is! */
133  }
134  }
135 
136  break;
137 
139 
140  /* Load the file system */
142  L"\\Registry\\Machine\\System\\CurrentControlSet\\Services\\Udfs");
143  break;
144 
145  default:
146 
147  /* Invalid request */
149  }
150 
151  /* Return Status */
152  return Status;
153 }
_In_ PIRP Irp
Definition: csq.h:116
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:4049
#define STATUS_INVALID_DEVICE_REQUEST
Definition: udferr_usr.h:138
#define STATUS_FS_DRIVER_REQUIRED
Definition: ntstatus.h:631
#define PAGED_CODE()
Definition: video.h:57
#define STATUS_UNRECOGNIZED_VOLUME
Definition: udferr_usr.h:173
#define IRP_MN_MOUNT_VOLUME
Definition: iotypes.h:4047
static const WCHAR L[]
Definition: oid.c:1250
Status
Definition: gdiplustypes.h:24
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
__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
BOOLEAN NTAPI FsRecIsUdfsVolume(IN PDEVICE_OBJECT DeviceObject, IN ULONG SectorSize)
Definition: udfs.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:2771

Referenced by FsRecFsControl().

◆ FsRecVfatFsControl()

NTSTATUS NTAPI FsRecVfatFsControl ( IN PDEVICE_OBJECT  DeviceObject,
IN PIRP  Irp 
)

Definition at line 100 of file fat.c.

102 {
103  PIO_STACK_LOCATION Stack;
105  PDEVICE_OBJECT MountDevice;
108  LARGE_INTEGER Offset = {{0, 0}};
109  BOOLEAN DeviceError = FALSE;
110  PAGED_CODE();
111 
112  /* Get the I/O Stack and check the function type */
114  switch (Stack->MinorFunction)
115  {
116  case IRP_MN_MOUNT_VOLUME:
117 
118  /* Assume failure */
120 
121  /* Get the device object and request the sector size */
122  MountDevice = Stack->Parameters.MountVolume.DeviceObject;
123  if (FsRecGetDeviceSectorSize(MountDevice, &SectorSize))
124  {
125  /* Try to read the BPB */
126  if (FsRecReadBlock(MountDevice,
127  &Offset,
128  512,
129  SectorSize,
130  (PVOID)&Bpb,
131  &DeviceError))
132  {
133  /* Check if it's an actual FAT volume */
134  if (FsRecIsFatVolume(Bpb))
135  {
136  /* It is! */
138  }
139  }
140 
141  /* Free the boot sector if we have one */
142  ExFreePool(Bpb);
143  }
144  else
145  {
146  /* We have some sort of failure in the storage stack */
147  DeviceError = TRUE;
148  }
149 
150  /* Check if we have an error on the stack */
151  if (DeviceError)
152  {
153  /* Was this because of a floppy? */
154  if (MountDevice->Characteristics & FILE_FLOPPY_DISKETTE)
155  {
156  /* Let the FS try anyway */
158  }
159  }
160 
161  break;
162 
164 
165  /* Load the file system */
167  L"\\Registry\\Machine\\System\\CurrentControlSet\\Services\\fastfat");
168  break;
169 
170  default:
171 
172  /* Invalid request */
174  }
175 
176  /* Return Status */
177  return Status;
178 }
#define TRUE
Definition: types.h:120
_In_ PIRP Irp
Definition: csq.h:116
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:4049
#define STATUS_INVALID_DEVICE_REQUEST
Definition: udferr_usr.h:138
#define STATUS_FS_DRIVER_REQUIRED
Definition: ntstatus.h:631
#define PAGED_CODE()
Definition: video.h:57
_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
#define IRP_MN_MOUNT_VOLUME
Definition: iotypes.h:4047
static const WCHAR L[]
Definition: oid.c:1250
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:1560
__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:2771
#define FILE_FLOPPY_DISKETTE
Definition: nt_native.h:809
#define ExFreePool(addr)
Definition: env_spec_w32.h:352
BOOLEAN NTAPI FsRecIsFatVolume(IN PPACKED_BOOT_SECTOR PackedBootSector)
Definition: fat.c:21

Referenced by FsRecFsControl().