ReactOS  0.4.13-dev-100-gc8611ae
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 #if defined(ALLOC_PRAGMA)
35 #pragma alloc_text(INIT, DriverEntry)
36 #pragma alloc_text(INIT, NtfsInitializeFunctionPointers)
37 #endif
38 
39 /* GLOBALS *****************************************************************/
40 
42 
43 /* FUNCTIONS ****************************************************************/
44 
45 /*
46  * FUNCTION: Called by the system to initialize the driver
47  * ARGUMENTS:
48  * DriverObject = object describing this driver
49  * RegistryPath = path to our configuration entries
50  * RETURNS: Success or failure
51  */
52 INIT_FUNCTION
54 NTAPI
57 {
62  HANDLE DriverKey = NULL;
63 
64  TRACE_(NTFS, "DriverEntry(%p, '%wZ')\n", DriverObject, RegistryPath);
65 
67  sizeof(NTFS_GLOBAL_DATA),
68  &DeviceName,
70  0,
71  FALSE,
72  &DeviceObject);
73  if (!NT_SUCCESS(Status))
74  {
75  WARN_(NTFS, "IoCreateDevice failed with status: %lx\n", Status);
76  return Status;
77  }
78 
79  /* Initialize global data */
82 
86 
88 
90 
91  // Read registry to determine if write support should be enabled
95  NULL,
96  NULL);
97 
98  Status = ZwOpenKey(&DriverKey, KEY_READ, &Attributes);
99  if (NT_SUCCESS(Status))
100  {
102  UCHAR Buffer[sizeof(KEY_VALUE_PARTIAL_INFORMATION) + sizeof(ULONG)];
104  ULONG ValueLength = sizeof(Buffer);
106 
107  RtlInitUnicodeString(&ValueName, L"MyDataDoesNotMatterSoEnableExperimentalWriteSupportForEveryNTFSVolume");
108 
109  Status = ZwQueryValueKey(DriverKey,
110  &ValueName,
112  Value,
113  ValueLength,
114  &ResultLength);
115 
116  if (NT_SUCCESS(Status) && Value->Data[0] == TRUE)
117  {
118  DPRINT1("\tEnabling write support on ALL NTFS volumes!\n");
120  }
121 
122  ZwClose(DriverKey);
123  }
124 
125  /* Keep trace of Driver Object */
127 
128  /* Initialize IRP functions array */
130 
131  /* Initialize CC functions array */
136 
142 
143  /* Initialize lookaside list for IRP contexts */
145  NULL, NULL, 0, sizeof(NTFS_IRP_CONTEXT), TAG_IRP_CTXT, 0);
146  /* Initialize lookaside list for FCBs */
148  NULL, NULL, 0, sizeof(NTFS_FCB), TAG_FCB, 0);
149  /* Initialize lookaside list for attributes contexts */
151  NULL, NULL, 0, sizeof(NTFS_ATTR_CONTEXT), TAG_ATT_CTXT, 0);
152 
153  /* Driver can't be unloaded */
155 
157 
158  /* Register file system */
161 
162  return STATUS_SUCCESS;
163 }
164 
165 
166 /*
167  * FUNCTION: Called within the driver entry to initialize the IRP functions array
168  * ARGUMENTS:
169  * DriverObject = object describing this driver
170  * RETURNS: Nothing
171  */
172 INIT_FUNCTION
173 VOID
174 NTAPI
176 {
189 
190  return;
191 }
192 
193 /* EOF */
FAST_IO_WRITE NtfsFastIoWrite
Definition: ntfs.h:891
IN CINT OUT PVOID IN ULONG OUT PULONG ResultLength
Definition: conport.c:47
_In_opt_ ULONG _Out_ PULONG Value
Definition: rtlfuncs.h:2327
#define TAG_FCB
Definition: vfat.h:541
PDRIVER_OBJECT DriverObject
Definition: ntfs.h:147
#define TRUE
Definition: types.h:120
#define IRP_MJ_CREATE
Definition: rdpdr.c:44
#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
NPAGED_LOOKASIDE_LIST FcbLookasideList
Definition: ntfs.h:153
#define KEY_READ
Definition: nt_native.h:1023
Definition: cdstruc.h:908
NTSYSAPI NTSTATUS NTAPI ZwClose(_In_ HANDLE Handle)
LONG NTSTATUS
Definition: precomp.h:26
#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:867
WCHAR DeviceName[]
Definition: adapter.cpp:21
PNTFS_GLOBAL_DATA NtfsGlobalData
Definition: ntfs.c:41
#define DO_DIRECT_IO
Definition: env_spec_w32.h:396
INIT_FUNCTION NTSTATUS NTAPI DriverEntry(PDRIVER_OBJECT DriverObject, PUNICODE_STRING RegistryPath)
Definition: ntfs.c:55
_In_ PUNICODE_STRING ValueName
Definition: cmfuncs.h:264
NTSTATUS(* NTAPI)(IN PFILE_FULL_EA_INFORMATION EaBuffer, IN ULONG EaLength, OUT PULONG ErrorOffset)
Definition: IoEaTest.cpp:117
ERESOURCE Resource
Definition: ntfs.h:146
struct _FAST_IO_DISPATCH FAST_IO_DISPATCH
PVOID DeviceExtension
Definition: env_spec_w32.h:418
smooth NULL
Definition: ftsmooth.c:416
static PDRIVER_OBJECT DriverObject
Definition: template.c:42
INIT_FUNCTION VOID NTAPI NtfsInitializeFunctionPointers(PDRIVER_OBJECT DriverObject)
Definition: ntfs.c:175
Definition: bufpool.h:45
#define IRP_MJ_QUERY_VOLUME_INFORMATION
Definition: rdpdr.c:50
#define IRP_MJ_DIRECTORY_CONTROL
Definition: rdpdr.c:51
#define FILE_DEVICE_DISK_FILE_SYSTEM
Definition: winioctl.h:113
#define TRACE_(x)
Definition: compat.h:66
FAST_IO_CHECK_IF_POSSIBLE NtfsFastIoCheckIfPossible
Definition: ntfs.h:889
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:222
#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
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
PACQUIRE_FOR_READ_AHEAD AcquireForReadAhead
Definition: cctypes.h:41
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
PDRIVER_UNLOAD DriverUnload
Definition: iotypes.h:2179
_In_ GUID _In_ PVOID _In_ ULONG ValueLength
Definition: hubbusif.h:311
PRELEASE_FROM_READ_AHEAD ReleaseFromReadAhead
Definition: cctypes.h:42
FAST_IO_READ NtfsFastIoRead
Definition: ntfs.h:890
PDEVICE_OBJECT DeviceObject
Definition: ntfs.h:148
Status
Definition: gdiplustypes.h:24
#define TAG_IRP_CTXT
Definition: ntfs.h:15
PFAST_IO_READ FastIoRead
Definition: iotypes.h:1691
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
_Must_inspect_result_ _In_ USHORT _In_ PHIDP_PREPARSED_DATA _Out_writes_to_ LengthAttributes PHIDP_EXTENDED_ATTRIBUTES Attributes
Definition: hidpi.h:348
PFAST_IO_WRITE FastIoWrite
Definition: iotypes.h:1692
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 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:984
struct _FAST_IO_DISPATCH * FastIoDispatch
Definition: iotypes.h:2176
#define IRP_MJ_CLEANUP
#define ObReferenceObject
Definition: obfuncs.h:204
PDRIVER_DISPATCH MajorFunction[IRP_MJ_MAXIMUM_FUNCTION+1]
Definition: iotypes.h:2180
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:1690
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
_In_ PUNICODE_STRING RegistryPath
Definition: wmip.h:27
#define IRP_MJ_WRITE
Definition: rdpdr.c:47
#define DEVICE_NAME
Definition: ext2fs.h:137
#define IRP_MJ_QUERY_INFORMATION
Definition: rdpdr.c:48
BOOLEAN NTAPI NtfsAcqLazyWrite(PVOID Context, BOOLEAN Wait)
Definition: fastio.c:39
IN BOOLEAN OUT PSTR Buffer
Definition: progress.h:34
return STATUS_SUCCESS
Definition: btrfs.c:2725
#define OBJ_KERNEL_HANDLE
Definition: winternl.h:231
#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:1689
#define RTL_CONSTANT_STRING(s)
Definition: tunneltest.c:14