ReactOS  0.4.15-dev-2945-g7100a24
ntfs.c
Go to the documentation of this file.
1 /*
2  * ReactOS kernel
3  * Copyright (C) 2002 ReactOS Team
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
18  *
19  * COPYRIGHT: See COPYING in the top level directory
20  * PROJECT: ReactOS kernel
21  * FILE: drivers/filesystem/ntfs/ntfs.c
22  * PURPOSE: NTFS filesystem driver
23  * PROGRAMMER: Eric Kohl
24  * Pierre Schweitzer
25  */
26 
27 /* INCLUDES *****************************************************************/
28 
29 #include "ntfs.h"
30 
31 #define NDEBUG
32 #include <debug.h>
33 
34 /* GLOBALS *****************************************************************/
35 
37 
38 /* FUNCTIONS ****************************************************************/
39 
40 /*
41  * FUNCTION: Called by the system to initialize the driver
42  * ARGUMENTS:
43  * DriverObject = object describing this driver
44  * RegistryPath = path to our configuration entries
45  * RETURNS: Success or failure
46  */
47 CODE_SEG("INIT")
49 NTAPI
52 {
57  HANDLE DriverKey = NULL;
58 
59  TRACE_(NTFS, "DriverEntry(%p, '%wZ')\n", DriverObject, RegistryPath);
60 
62  sizeof(NTFS_GLOBAL_DATA),
63  &DeviceName,
65  0,
66  FALSE,
67  &DeviceObject);
68  if (!NT_SUCCESS(Status))
69  {
70  WARN_(NTFS, "IoCreateDevice failed with status: %lx\n", Status);
71  return Status;
72  }
73 
74  /* Initialize global data */
75  NtfsGlobalData = DeviceObject->DeviceExtension;
77 
81 
83 
85 
86  // Read registry to determine if write support should be enabled
90  NULL,
91  NULL);
92 
93  Status = ZwOpenKey(&DriverKey, KEY_READ, &Attributes);
94  if (NT_SUCCESS(Status))
95  {
99  ULONG ValueLength = sizeof(Buffer);
101 
102  RtlInitUnicodeString(&ValueName, L"MyDataDoesNotMatterSoEnableExperimentalWriteSupportForEveryNTFSVolume");
103 
104  Status = ZwQueryValueKey(DriverKey,
105  &ValueName,
107  Value,
108  ValueLength,
109  &ResultLength);
110 
111  if (NT_SUCCESS(Status) && Value->Data[0] == TRUE)
112  {
113  DPRINT1("\tEnabling write support on ALL NTFS volumes!\n");
115  }
116 
117  ZwClose(DriverKey);
118  }
119 
120  /* Keep trace of Driver Object */
122 
123  /* Initialize IRP functions array */
125 
126  /* Initialize CC functions array */
131 
136  DriverObject->FastIoDispatch = &NtfsGlobalData->FastIoDispatch;
137 
138  /* Initialize lookaside list for IRP contexts */
140  NULL, NULL, 0, sizeof(NTFS_IRP_CONTEXT), TAG_IRP_CTXT, 0);
141  /* Initialize lookaside list for FCBs */
143  NULL, NULL, 0, sizeof(NTFS_FCB), TAG_FCB, 0);
144  /* Initialize lookaside list for attributes contexts */
146  NULL, NULL, 0, sizeof(NTFS_ATTR_CONTEXT), TAG_ATT_CTXT, 0);
147 
148  /* Driver can't be unloaded */
149  DriverObject->DriverUnload = NULL;
150 
152 
153  /* Register file system */
156 
157  return STATUS_SUCCESS;
158 }
159 
160 
161 /*
162  * FUNCTION: Called within the driver entry to initialize the IRP functions array
163  * ARGUMENTS:
164  * DriverObject = object describing this driver
165  * RETURNS: Nothing
166  */
167 CODE_SEG("INIT")
168 VOID
169 NTAPI
171 {
172  DriverObject->MajorFunction[IRP_MJ_CREATE] = NtfsFsdDispatch;
173  DriverObject->MajorFunction[IRP_MJ_CLOSE] = NtfsFsdDispatch;
174  DriverObject->MajorFunction[IRP_MJ_CLEANUP] = NtfsFsdDispatch;
175  DriverObject->MajorFunction[IRP_MJ_READ] = NtfsFsdDispatch;
176  DriverObject->MajorFunction[IRP_MJ_WRITE] = NtfsFsdDispatch;
184 
185  return;
186 }
187 
188 /* EOF */
FAST_IO_WRITE NtfsFastIoWrite
Definition: ntfs.h:912
#define TAG_FCB
Definition: vfat.h:547
PDRIVER_OBJECT DriverObject
Definition: ntfs.h:147
#define IRP_MJ_CREATE
Definition: rdpdr.c:44
NTSTATUS NTAPI DriverEntry(PDRIVER_OBJECT DriverObject, PUNICODE_STRING RegistryPath)
Definition: ntfs.c:50
#define NTFS_TYPE_GLOBAL_DATA
Definition: ntfs.h:91
#define TAG_ATT_CTXT
Definition: ntfs.h:16
NPAGED_LOOKASIDE_LIST AttrCtxtLookasideList
Definition: ntfs.h:154
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
NPAGED_LOOKASIDE_LIST FcbLookasideList
Definition: ntfs.h:153
IN BOOLEAN OUT PSTR Buffer
Definition: progress.h:34
#define KEY_READ
Definition: nt_native.h:1023
#define TRUE
Definition: types.h:120
Definition: cdstruc.h:902
NTSYSAPI NTSTATUS NTAPI ZwClose(_In_ HANDLE Handle)
LONG NTSTATUS
Definition: precomp.h:26
_Must_inspect_result_ _In_ PDRIVER_OBJECT _In_ PCUNICODE_STRING RegistryPath
Definition: wdfdriver.h:213
#define IRP_MJ_SET_VOLUME_INFORMATION
NTSTATUS ExInitializeResourceLite(PULONG res)
Definition: env_spec_w32.h:641
VOID NTAPI NtfsRelLazyWrite(PVOID Context)
Definition: fastio.c:51
BOOLEAN NTAPI NtfsAcqReadAhead(PVOID Context, BOOLEAN Wait)
Definition: fastio.c:60
DRIVER_DISPATCH NtfsFsdDispatch
Definition: ntfs.h:888
#define OBJ_KERNEL_HANDLE
Definition: winternl.h:231
PNTFS_GLOBAL_DATA NtfsGlobalData
Definition: ntfs.c:36
#define DO_DIRECT_IO
Definition: env_spec_w32.h:396
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
_Must_inspect_result_ _In_ PWDFDEVICE_INIT _In_opt_ PCUNICODE_STRING DeviceName
Definition: wdfdevice.h:3272
NTSTATUS(* NTAPI)(IN PFILE_FULL_EA_INFORMATION EaBuffer, IN ULONG EaLength, OUT PULONG ErrorOffset)
Definition: IoEaTest.cpp:117
#define FALSE
Definition: types.h:117
ERESOURCE Resource
Definition: ntfs.h:146
struct _FAST_IO_DISPATCH FAST_IO_DISPATCH
Definition: bufpool.h:45
#define IRP_MJ_QUERY_VOLUME_INFORMATION
Definition: rdpdr.c:50
#define IRP_MJ_DIRECTORY_CONTROL
Definition: rdpdr.c:51
_Must_inspect_result_ _In_ PDRIVER_OBJECT DriverObject
Definition: wdfdriver.h:213
#define FILE_DEVICE_DISK_FILE_SYSTEM
Definition: winioctl.h:114
_Must_inspect_result_ _In_ WDFKEY _In_ PCUNICODE_STRING _Out_opt_ PUSHORT _Inout_opt_ PUNICODE_STRING Value
Definition: wdfregistry.h:406
Status
Definition: gdiplustypes.h:24
#define TRACE_(x)
Definition: compat.h:76
FAST_IO_CHECK_IF_POSSIBLE NtfsFastIoCheckIfPossible
Definition: ntfs.h:910
VOID NTAPI ExInitializeNPagedLookasideList(IN PNPAGED_LOOKASIDE_LIST Lookaside, IN PALLOCATE_FUNCTION Allocate OPTIONAL, IN PFREE_FUNCTION Free OPTIONAL, IN ULONG Flags, IN SIZE_T Size, IN ULONG Tag, IN USHORT Depth)
Definition: lookas.c:218
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
struct _KEY_VALUE_PARTIAL_INFORMATION * PKEY_VALUE_PARTIAL_INFORMATION
#define IRP_MJ_FILE_SYSTEM_CONTROL
PACQUIRE_FOR_LAZY_WRITE AcquireForLazyWrite
Definition: cctypes.h:39
PACQUIRE_FOR_READ_AHEAD AcquireForReadAhead
Definition: cctypes.h:41
_Must_inspect_result_ _In_ WDFKEY _In_ PCUNICODE_STRING ValueName
Definition: wdfregistry.h:240
unsigned char UCHAR
Definition: xmlstorage.h:181
#define IRP_MJ_CLOSE
Definition: rdpdr.c:45
static const WCHAR L[]
Definition: oid.c:1250
ULONG Type
Definition: ntfs.h:95
PRELEASE_FROM_READ_AHEAD ReleaseFromReadAhead
Definition: cctypes.h:42
FAST_IO_READ NtfsFastIoRead
Definition: ntfs.h:911
PDEVICE_OBJECT DeviceObject
Definition: ntfs.h:148
#define TAG_IRP_CTXT
Definition: ntfs.h:15
PFAST_IO_READ FastIoRead
Definition: iotypes.h:1735
PFAST_IO_WRITE FastIoWrite
Definition: iotypes.h:1736
NPAGED_LOOKASIDE_LIST IrpContextLookasideList
Definition: ntfs.h:152
CACHE_MANAGER_CALLBACKS CacheMgrCallbacks
Definition: ntfs.h:149
struct _KEY_VALUE_PARTIAL_INFORMATION KEY_VALUE_PARTIAL_INFORMATION
#define NULL
Definition: types.h:112
#define DPRINT1
Definition: precomp.h:8
VOID NTAPI NtfsRelReadAhead(PVOID Context)
Definition: fastio.c:72
#define IRP_MJ_READ
Definition: rdpdr.c:46
NTFSIDENTIFIER Identifier
Definition: ntfs.h:145
VOID NTAPI IoRegisterFileSystem(IN PDEVICE_OBJECT DeviceObject)
Definition: volume.c:987
#define IRP_MJ_CLEANUP
#define ObReferenceObject
Definition: obfuncs.h:204
PRELEASE_FROM_LAZY_WRITE ReleaseFromLazyWrite
Definition: cctypes.h:40
FAST_IO_DISPATCH FastIoDispatch
Definition: ntfs.h:151
#define IRP_MJ_SET_INFORMATION
Definition: rdpdr.c:49
unsigned int ULONG
Definition: retypes.h:1
NTSTATUS NTAPI IoCreateDevice(IN PDRIVER_OBJECT DriverObject, IN ULONG DeviceExtensionSize, IN PUNICODE_STRING DeviceName, IN DEVICE_TYPE DeviceType, IN ULONG DeviceCharacteristics, IN BOOLEAN Exclusive, OUT PDEVICE_OBJECT *DeviceObject)
Definition: device.c:1031
PFAST_IO_CHECK_IF_POSSIBLE FastIoCheckIfPossible
Definition: iotypes.h:1734
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
#define IRP_MJ_WRITE
Definition: rdpdr.c:47
_Must_inspect_result_ _In_ WDFDEVICE _In_ DEVICE_REGISTRY_PROPERTY _In_ ULONG _Out_ PULONG ResultLength
Definition: wdfdevice.h:3776
#define DEVICE_NAME
Definition: ext2fs.h:137
#define IRP_MJ_QUERY_INFORMATION
Definition: rdpdr.c:48
#define STATUS_SUCCESS
Definition: shellext.h:65
BOOLEAN NTAPI NtfsAcqLazyWrite(PVOID Context, BOOLEAN Wait)
Definition: fastio.c:39
static CODE_SEG("PAGE")
Definition: isapnp.c:1482
#define WARN_(ch,...)
Definition: debug.h:157
BOOLEAN EnableWriteSupport
Definition: ntfs.h:155
ULONG Size
Definition: ntfs.h:96
#define IRP_MJ_DEVICE_CONTROL
Definition: rdpdr.c:52
ULONG SizeOfFastIoDispatch
Definition: iotypes.h:1733
_Must_inspect_result_ _In_ WDFDMAENABLER _In_ _In_opt_ PWDF_OBJECT_ATTRIBUTES Attributes
VOID NTAPI NtfsInitializeFunctionPointers(PDRIVER_OBJECT DriverObject)
Definition: ntfs.c:170
#define RTL_CONSTANT_STRING(s)
Definition: tunneltest.c:14
_Must_inspect_result_ _In_ WDFKEY _In_ PCUNICODE_STRING _In_ ULONG ValueLength
Definition: wdfregistry.h:271