Merge my current work done on the kd++ branch:
[reactos.git] / reactos / drivers / filesystems / fs_rec / udfs.c
1 /*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS File System Recognizer
4 * FILE: drivers/filesystems/fs_rec/udfs.c
5 * PURPOSE: USFS Recognizer
6 * PROGRAMMER: Alex Ionescu (alex.ionescu@reactos.org)
7 * Eric Kohl
8 */
9
10 /* INCLUDES *****************************************************************/
11
12 #include "fs_rec.h"
13 #define NDEBUG
14 #include <debug.h>
15
16 #include "udfs.h"
17
18 /* FUNCTIONS ****************************************************************/
19
20 BOOLEAN
21 NTAPI
22 FsRecIsUdfsVolume(IN PDEVICE_OBJECT DeviceObject,
23 IN ULONG SectorSize)
24 {
25 PVOLSTRUCTDESC VolumeStructDesc = NULL;
26 LARGE_INTEGER Offset;
27 ULONG State = 0;
28 PAGED_CODE();
29
30 Offset.QuadPart = UDFS_VRS_START_OFFSET;
31 while (TRUE)
32 {
33 if (!FsRecReadBlock(DeviceObject,
34 &Offset,
35 SectorSize,
36 SectorSize,
37 (PVOID)&VolumeStructDesc,
38 NULL))
39 {
40 break;
41 }
42
43 switch (State)
44 {
45 case 0:
46
47 if (!strncmp((const char*)VolumeStructDesc->Ident,
48 VSD_STD_ID_BEA01,
49 VSD_STD_ID_LEN))
50 {
51 State = 1;
52 }
53 else
54 {
55 ExFreePool(VolumeStructDesc);
56 return FALSE;
57 }
58 break;
59
60 case 1:
61
62 if (!strncmp((const char*)VolumeStructDesc->Ident,
63 VSD_STD_ID_NSR03,
64 VSD_STD_ID_LEN) ||
65 !strncmp((const char*)VolumeStructDesc->Ident,
66 VSD_STD_ID_NSR02,
67 VSD_STD_ID_LEN))
68 {
69 State = 2;
70 }
71 break;
72
73 case 2:
74
75 if (!strncmp((const char*)VolumeStructDesc->Ident,
76 VSD_STD_ID_TEA01,
77 VSD_STD_ID_LEN))
78 {
79 ExFreePool(VolumeStructDesc);
80 return TRUE;
81 }
82 break;
83 }
84
85 Offset.QuadPart += SectorSize;
86 if (Offset.QuadPart == UDFS_AVDP_SECTOR)
87 {
88 ExFreePool(VolumeStructDesc);
89 return FALSE;
90 }
91 }
92
93 ExFreePool(VolumeStructDesc);
94 return TRUE;
95 }
96
97 NTSTATUS
98 NTAPI
99 FsRecUdfsFsControl(IN PDEVICE_OBJECT DeviceObject,
100 IN PIRP Irp)
101 {
102 PIO_STACK_LOCATION Stack;
103 NTSTATUS Status;
104 PDEVICE_OBJECT MountDevice;
105 ULONG SectorSize;
106 PAGED_CODE();
107
108 /* Get the I/O Stack and check the function type */
109 Stack = IoGetCurrentIrpStackLocation(Irp);
110 switch (Stack->MinorFunction)
111 {
112 case IRP_MN_MOUNT_VOLUME:
113
114 /* Assume failure */
115 Status = STATUS_UNRECOGNIZED_VOLUME;
116
117 /* Get the device object and request the sector size */
118 MountDevice = Stack->Parameters.MountVolume.DeviceObject;
119 if (FsRecGetDeviceSectorSize(MountDevice, &SectorSize))
120 {
121 /* Check if it's an actual FAT volume */
122 if (FsRecIsUdfsVolume(MountDevice, SectorSize))
123 {
124 /* It is! */
125 Status = STATUS_FS_DRIVER_REQUIRED;
126 }
127 }
128
129 break;
130
131 case IRP_MN_LOAD_FILE_SYSTEM:
132
133 /* Load the file system */
134 Status = FsRecLoadFileSystem(DeviceObject,
135 L"\\Registry\\Machine\\System\\CurrentControlSet\\Services\\Udfs");
136 break;
137
138 default:
139
140 /* Invalid request */
141 Status = STATUS_INVALID_DEVICE_REQUEST;
142 }
143
144 /* Return Status */
145 return Status;
146 }
147
148 /* EOF */