ReactOS 0.4.16-dev-258-g81860b4
ffs.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/ffs.c
5 * PURPOSE: FFS Recognizer
6 * PROGRAMMER: Peter Hater
7 * Pierre Schweitzer (pierre@reactos.org)
8 */
9
10/* INCLUDES *****************************************************************/
11
12#include "fs_rec.h"
13#include "ffs.h"
14
15#define NDEBUG
16#include <debug.h>
17
18/* FUNCTIONS ****************************************************************/
19
23{
24 return (dl->d_magic == DISKMAGIC);
25}
26
30{
31 return (sb->fs_magic == FS_UFS1_MAGIC);
32}
33
37{
38 return (sb->fs_magic == FS_UFS2_MAGIC);
39}
40
44 IN PIRP Irp)
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}
static PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(PIRP Irp)
#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
superblock * sb
Definition: btrfs.c:4261
#define ExFreePool(addr)
Definition: env_spec_w32.h:352
NTSTATUS NTAPI FsRecFfsFsControl(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: ffs.c:43
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 FS_UFS2_MAGIC
Definition: ffs.h:291
#define DISKMAGIC
Definition: ffs.h:293
#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 FS_UFS1_MAGIC
Definition: ffs.h:290
#define SBLOCK_UFS1
Definition: ffs.h:282
#define FS_BSDFFS
Definition: ffs.h:297
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
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
#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
Definition: ffs.h:183
Definition: ffs.h:70
#define NTAPI
Definition: typedefs.h:36
#define IN
Definition: typedefs.h:39
uint32_t ULONG
Definition: typedefs.h:59
uint64_t ULONGLONG
Definition: typedefs.h:67
#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
#define IRP_MN_LOAD_FILE_SYSTEM
Definition: iotypes.h:4406
#define IRP_MN_MOUNT_VOLUME
Definition: iotypes.h:4404