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