ReactOS 0.4.15-dev-5666-gc548b97
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 , FS_TYPE_FATX
}
 
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)
 
NTSTATUS NTAPI FsRecFatxFsControl (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:144
#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)); \
}

Definition at line 54 of file fs_rec.h.

◆ CopyUchar4

#define CopyUchar4 (   Dst,
  Src 
)
Value:
{ \
*((UCHAR4 *)(Dst)) = *((UNALIGNED UCHAR4 *)(Src)); \
}

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:2071

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 145 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 
FS_TYPE_FATX 

Definition at line 169 of file fs_rec.h.

170{
enum _FILE_SYSTEM_TYPE * PFILE_SYSTEM_TYPE
@ FS_TYPE_UDFS
Definition: fs_rec.h:175
@ FS_TYPE_BTRFS
Definition: fs_rec.h:177
@ FS_TYPE_NTFS
Definition: fs_rec.h:173
@ FS_TYPE_FFS
Definition: fs_rec.h:179
@ FS_TYPE_CDFS
Definition: fs_rec.h:174
@ FS_TYPE_FATX
Definition: fs_rec.h:180
@ FS_TYPE_UNUSED
Definition: fs_rec.h:171
@ FS_TYPE_EXT2
Definition: fs_rec.h:176
@ FS_TYPE_REISERFS
Definition: fs_rec.h:178
@ FS_TYPE_VFAT
Definition: fs_rec.h:172
enum _FILE_SYSTEM_TYPE FILE_SYSTEM_TYPE

◆ _FS_REC_STATE

Enumerator
Pending 
Loaded 
Unloading 

Definition at line 184 of file fs_rec.h.

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

Function Documentation

◆ FsRecBtrfsFsControl()

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

Definition at line 30 of file btrfs.c.

32{
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,
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 PAGED_CODE()
unsigned char BOOLEAN
LONG NTSTATUS
Definition: precomp.h:26
_In_ PIRP Irp
Definition: csq.h:116
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
BOOLEAN NTAPI FsRecIsBtrfsVolume(IN PBTRFS_SUPER_BLOCK SuperBlock)
Definition: btrfs.c:22
#define BTRFS_SB_SIZE
Definition: btrfs.h:31
#define BTRFS_SB_OFFSET
Definition: btrfs.h:30
#define ExFreePool(addr)
Definition: env_spec_w32.h:352
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
BOOLEAN NTAPI FsRecGetDeviceSectorSize(IN PDEVICE_OBJECT DeviceObject, OUT PULONG SectorSize)
Definition: blockdev.c:80
NTSTATUS NTAPI FsRecLoadFileSystem(IN PDEVICE_OBJECT DeviceObject, IN PWCHAR DriverServiceName)
Definition: fs_rec.c:23
Status
Definition: gdiplustypes.h:25
unsigned int ULONG
Definition: retypes.h:1
#define FILE_FLOPPY_DISKETTE
Definition: nt_native.h:809
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
#define STATUS_FS_DRIVER_REQUIRED
Definition: ntstatus.h:645
#define L(x)
Definition: ntvdm.h:50
#define STATUS_INVALID_DEVICE_REQUEST
Definition: udferr_usr.h:138
#define STATUS_UNRECOGNIZED_VOLUME
Definition: udferr_usr.h:173
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
_In_ WDFREQUEST _In_ PIO_STACK_LOCATION Stack
Definition: wdfrequest.h:639
_In_ ULONG SectorSize
Definition: halfuncs.h:291
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2793
#define IRP_MN_LOAD_FILE_SYSTEM
Definition: iotypes.h:4406
#define IRP_MN_MOUNT_VOLUME
Definition: iotypes.h:4404

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;
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}
BOOLEAN NTAPI FsRecIsCdfsVolume(IN PDEVICE_OBJECT DeviceObject, IN ULONG SectorSize)
Definition: cdfs.c:23

Referenced by FsRecFsControl().

◆ FsRecExt2FsControl()

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

Definition at line 30 of file ext2.c.

32{
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 = EXT2_SB_OFFSET;
57 if (FsRecReadBlock(MountDevice,
58 &Offset,
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}
BOOLEAN NTAPI FsRecIsExt2Volume(IN PEXT2_SUPER_BLOCK SuperBlock)
Definition: ext2.c:22
#define EXT2_SB_OFFSET
Definition: ext2.h:47
#define EXT2_SB_SIZE
Definition: ext2.h:48

Referenced by FsRecFsControl().

◆ FsRecFatxFsControl()

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

Definition at line 66 of file fatx.c.

68{
71 PDEVICE_OBJECT MountDevice;
74 LARGE_INTEGER Offset = {{0, 0}};
75 BOOLEAN DeviceError = FALSE;
76 PAGED_CODE();
77
78 /* Get the I/O Stack and check the function type */
80 switch (Stack->MinorFunction)
81 {
83
84 /* Assume failure */
86
87 /* Get the device object and request the sector size */
88 MountDevice = Stack->Parameters.MountVolume.DeviceObject;
89 if (FsRecGetDeviceSectorSize(MountDevice, &SectorSize))
90 {
91 /* Try to read the BPB */
92 if (FsRecReadBlock(MountDevice,
93 &Offset,
94 512,
96 (PVOID)&Bpb,
97 &DeviceError))
98 {
99 /* Check if it's an actual FAT volume */
100 if (FsRecIsFatxVolume(Bpb))
101 {
102 /* It is! */
104 }
105 }
106
107 /* Free the boot sector if we have one */
108 ExFreePool(Bpb);
109 }
110
111 break;
112
114
115 /* Load the file system */
117 L"\\Registry\\Machine\\System\\CurrentControlSet\\Services\\vfatfs");
118 break;
119
120 default:
121
122 /* Invalid request */
124 }
125
126 /* Return Status */
127 return Status;
128}
BOOLEAN NTAPI FsRecIsFatxVolume(IN PFATX_BOOT_SECTOR BootSector)
Definition: fatx.c:33

Referenced by FsRecFsControl().

◆ FsRecFfsFsControl()

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

Definition at line 43 of file ffs.c.

45{
48 PDEVICE_OBJECT MountDevice;
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,
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,
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,
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,
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,
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 FsRecIsFfs2Volume(IN PFFSD_SUPER_BLOCK sb)
Definition: ffs.c:36
BOOLEAN NTAPI FsRecIsFfsDiskLabel(IN PFFSD_DISKLABEL dl)
Definition: ffs.c:22
#define LABELSECTOR
Definition: ffs.h:295
#define SBLOCK_UFS2
Definition: ffs.h:283
#define MAXPARTITIONS
Definition: ffs.h:179
#define SBLOCKSIZE
Definition: ffs.h:285
#define SBLOCK_UFS1
Definition: ffs.h:282
#define FS_BSDFFS
Definition: ffs.h:297
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
Definition: ffs.h:183
Definition: ffs.h:70
uint64_t ULONGLONG
Definition: typedefs.h:67

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{
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,
47 FALSE,
48 &Event,
50 if (!Irp) return FALSE;
51
52 /* Override verification */
54
55 /* Do the request */
58 {
59 /* Wait for completion */
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 */
74 &Remainder);
75 return TRUE;
76}
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define KeWaitForSingleObject(pEvt, foo, a, b, c)
Definition: env_spec_w32.h:478
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
NTSYSAPI LONGLONG WINAPI RtlExtendedLargeIntegerDivide(LONGLONG, INT, INT *)
static OUT PIO_STATUS_BLOCK IoStatusBlock
Definition: pipe.c:75
#define KernelMode
Definition: asm.h:34
#define IOCTL_DISK_GET_PARTITION_INFO
Definition: ntdddisk.h:106
@ SynchronizationEvent
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
#define IoCallDriver
Definition: irp.c:1225
#define STATUS_PENDING
Definition: ntstatus.h:82
ULONG SectorCount
Definition: part_xbox.c:31
#define FILE_DEVICE_DISK
Definition: winioctl.h:113
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetNextIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2695
_In_ ULONG _In_ struct _SET_PARTITION_INFORMATION_EX * PartitionInfo
Definition: iofuncs.h:2105
#define SL_OVERRIDE_VERIFY_VOLUME
Definition: iotypes.h:1823
@ Executive
Definition: ketypes.h:403
_In_ LARGE_INTEGER _Out_opt_ PLARGE_INTEGER Remainder
Definition: rtlfuncs.h:3045

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;
86 PIRP Irp;
89 PAGED_CODE();
90
91 /* Check what device we have */
92 switch (DeviceObject->DeviceType)
93 {
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 */
116 NULL,
117 0,
118 &DiskGeometry,
119 sizeof(DISK_GEOMETRY),
120 FALSE,
121 &Event,
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,
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 IOCTL_DISK_GET_DRIVE_GEOMETRY
Definition: cdrw_usr.h:169
#define IOCTL_CDROM_GET_DRIVE_GEOMETRY
Definition: ntddcdrm.h:73
#define FILE_DEVICE_CD_ROM
Definition: winioctl.h:108
ULONG BytesPerSector
Definition: ntdddisk.h:409
_IRQL_requires_same_ typedef _In_ ULONG ControlCode
Definition: wmitypes.h:55

Referenced by FsRecBtrfsFsControl(), FsRecCdfsFsControl(), FsRecExt2FsControl(), FsRecFatxFsControl(), 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{
27 PDEVICE_EXTENSION DeviceExtension = DeviceObject->DeviceExtension;
28 UNICODE_STRING DriverName;
29
30 PAGED_CODE();
31
32 /* Make sure we haven't already been called */
33 if (DeviceExtension->State != Loaded)
34 {
35 /* Acquire the load lock */
40 FALSE,
41 NULL);
42
43 /* Make sure we're active */
44 if (DeviceExtension->State == Pending)
45 {
46 /* Load the FS driver */
47 RtlInitUnicodeString(&DriverName, DriverServiceName);
48 Status = ZwLoadDriver(&DriverName);
49
50 /* Loop all the linked recognizer objects */
51 while (DeviceExtension->State != Unloading)
52 {
53 /* Set them to the unload state */
54 DeviceExtension->State = Unloading;
55
56 /* Go to the next one */
57 DeviceObject = DeviceExtension->Alternate;
58 DeviceExtension = DeviceObject->DeviceExtension;
59 }
60 }
61
62 /* Make sure that we haven't already loaded the FS */
63 if (DeviceExtension->State != Loaded)
64 {
65 /* Unregister us, and set us as loaded */
67 DeviceExtension->State = Loaded;
68 }
69
70 /* Release the lock */
73 }
74
75 return Status;
76}
#define KeSetEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:476
PKEVENT FsRecLoadSync
Definition: fs_rec.c:17
#define KeLeaveCriticalRegion()
Definition: ke_x.h:119
#define KeEnterCriticalRegion()
Definition: ke_x.h:88
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
VOID NTAPI IoUnregisterFileSystem(IN PDEVICE_OBJECT DeviceObject)
Definition: volume.c:1056
#define STATUS_IMAGE_ALREADY_LOADED
Definition: ntstatus.h:506
#define IO_NO_INCREMENT
Definition: iotypes.h:598

Referenced by FsRecBtrfsFsControl(), FsRecCdfsFsControl(), FsRecExt2FsControl(), FsRecFatxFsControl(), 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{
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,
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,
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,
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}
INT Offset2
Definition: FsRtlDissect.c:14
BOOLEAN NTAPI FsRecIsNtfsVolume(IN PPACKED_BOOT_SECTOR BootSector, IN ULONG BytesPerSector, IN PLARGE_INTEGER NumberOfSectors)
Definition: ntfs.c:21
BOOLEAN NTAPI FsRecGetDeviceSectors(IN PDEVICE_OBJECT DeviceObject, IN ULONG SectorSize, OUT PLARGE_INTEGER SectorCount)
Definition: blockdev.c:24

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{
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 */
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 */
194 *Buffer,
195 Length,
196 Offset,
197 &Event,
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,
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}
Definition: bufpool.h:45
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
#define NonPagedPool
Definition: env_spec_w32.h:307
#define ROUND_UP(n, align)
Definition: eventvwr.h:34
#define FSREC_TAG
Definition: fs_rec.h:16
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:102
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
#define IRP_MJ_READ
Definition: rdpdr.c:46
#define ROUND_TO_PAGES(Size)

Referenced by FsRecBtrfsFsControl(), FsRecExt2FsControl(), FsRecFatxFsControl(), 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{
48 PDEVICE_OBJECT MountDevice;
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,
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}
BOOLEAN NTAPI FsRecIsReiserfsVolume(IN PRFSD_SUPER_BLOCK sb)
Definition: reiserfs.c:22
#define REISERFS_DISK_OFFSET_IN_BYTES
Definition: reiserfs.h:72

Referenced by FsRecFsControl().

◆ FsRecUdfsFsControl()

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

Definition at line 106 of file udfs.c.

108{
111 PDEVICE_OBJECT MountDevice;
113 PAGED_CODE();
114
115 /* Get the I/O Stack and check the function type */
117 switch (Stack->MinorFunction)
118 {
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}
BOOLEAN NTAPI FsRecIsUdfsVolume(IN PDEVICE_OBJECT DeviceObject, IN ULONG SectorSize)
Definition: udfs.c:23

Referenced by FsRecFsControl().

◆ FsRecVfatFsControl()

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

Definition at line 100 of file fat.c.

102{
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 {
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,
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}
BOOLEAN NTAPI FsRecIsFatVolume(IN PPACKED_BOOT_SECTOR PackedBootSector)
Definition: fat.c:21

Referenced by FsRecFsControl().