ReactOS  0.4.14-dev-297-g23e575c
ffs.c File Reference
#include "fs_rec.h"
#include "ffs.h"
#include <debug.h>
Include dependency graph for ffs.c:

Go to the source code of this file.

Macros

#define NDEBUG
 

Functions

BOOLEAN NTAPI FsRecIsFfsDiskLabel (IN PFFSD_DISKLABEL dl)
 
BOOLEAN NTAPI FsRecIsFfs1Volume (IN PFFSD_SUPER_BLOCK sb)
 
BOOLEAN NTAPI FsRecIsFfs2Volume (IN PFFSD_SUPER_BLOCK sb)
 
NTSTATUS NTAPI FsRecFfsFsControl (IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 15 of file ffs.c.

Function Documentation

◆ 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:4050
#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:4048
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:2772
#define FILE_FLOPPY_DISKETTE
Definition: nt_native.h:809
#define ExFreePool(addr)
Definition: env_spec_w32.h:352

Referenced by FsRecFsControl().

◆ FsRecIsFfs1Volume()

BOOLEAN NTAPI FsRecIsFfs1Volume ( IN PFFSD_SUPER_BLOCK  sb)

Definition at line 29 of file ffs.c.

30 {
31  return (sb->fs_magic == FS_UFS1_MAGIC);
32 }
superblock * sb
Definition: btrfs.c:4162
#define FS_UFS1_MAGIC
Definition: fs.h:369

Referenced by FsRecFfsFsControl().

◆ FsRecIsFfs2Volume()

BOOLEAN NTAPI FsRecIsFfs2Volume ( IN PFFSD_SUPER_BLOCK  sb)

Definition at line 36 of file ffs.c.

37 {
38  return (sb->fs_magic == FS_UFS2_MAGIC);
39 }
superblock * sb
Definition: btrfs.c:4162
#define FS_UFS2_MAGIC
Definition: fs.h:370

Referenced by FsRecFfsFsControl().

◆ FsRecIsFfsDiskLabel()

BOOLEAN NTAPI FsRecIsFfsDiskLabel ( IN PFFSD_DISKLABEL  dl)

Definition at line 22 of file ffs.c.

23 {
24  return (dl->d_magic == DISKMAGIC);
25 }
#define DISKMAGIC
Definition: disklabel.h:126

Referenced by FsRecFfsFsControl().