xref: /reactos/drivers/filesystems/vfatfs/iface.c (revision ccef43f3)
1 /*
2  * PROJECT:     VFAT Filesystem
3  * LICENSE:     GPL-2.0-or-later (https://spdx.org/licenses/GPL-2.0-or-later)
4  * PURPOSE:     Driver entry interface
5  * COPYRIGHT:   Copyright 1998 Jason Filby <jasonfilby@yahoo.com>
6  *              Copyright 2010-2018 Pierre Schweitzer <pierre@reactos.org>
7  */
8 
9 /* INCLUDES *****************************************************************/
10 
11 #include "vfat.h"
12 
13 #define NDEBUG
14 #include <debug.h>
15 
16 /* GLOBALS *****************************************************************/
17 
18 PVFAT_GLOBAL_DATA VfatGlobalData;
19 
20 /* FUNCTIONS ****************************************************************/
21 
22 /*
23  * FUNCTION: Called by the system to initialize the driver
24  * ARGUMENTS:
25  *           DriverObject = object describing this driver
26  *           RegistryPath = path to our configuration entries
27  * RETURNS: Success or failure
28  */
29 CODE_SEG("INIT")
30 NTSTATUS
31 NTAPI
32 DriverEntry(
33     IN PDRIVER_OBJECT DriverObject,
34     IN PUNICODE_STRING RegistryPath)
35 {
36     PDEVICE_OBJECT DeviceObject;
37     UNICODE_STRING DeviceName = RTL_CONSTANT_STRING(L"\\FatX");
38     NTSTATUS Status;
39 
40     UNREFERENCED_PARAMETER(RegistryPath);
41 
42     Status = IoCreateDevice(DriverObject,
43                             sizeof(VFAT_GLOBAL_DATA),
44                             &DeviceName,
45                             FILE_DEVICE_DISK_FILE_SYSTEM,
46                             0,
47                             FALSE,
48                             &DeviceObject);
49     if (!NT_SUCCESS(Status))
50     {
51         return Status;
52     }
53 
54     VfatGlobalData = DeviceObject->DeviceExtension;
55     RtlZeroMemory (VfatGlobalData, sizeof(VFAT_GLOBAL_DATA));
56     VfatGlobalData->DriverObject = DriverObject;
57     VfatGlobalData->DeviceObject = DeviceObject;
58     VfatGlobalData->NumberProcessors = KeNumberProcessors;
59     /* Enable this to enter the debugger when file system corruption
60      * has been detected:
61     VfatGlobalData->Flags = VFAT_BREAK_ON_CORRUPTION; */
62 
63     /* Delayed close support */
64     ExInitializeFastMutex(&VfatGlobalData->CloseMutex);
65     InitializeListHead(&VfatGlobalData->CloseListHead);
66     VfatGlobalData->CloseCount = 0;
67     VfatGlobalData->CloseWorkerRunning = FALSE;
68     VfatGlobalData->ShutdownStarted = FALSE;
69     VfatGlobalData->CloseWorkItem = IoAllocateWorkItem(DeviceObject);
70     if (VfatGlobalData->CloseWorkItem == NULL)
71     {
72         IoDeleteDevice(DeviceObject);
73         return STATUS_INSUFFICIENT_RESOURCES;
74     }
75 
76     DeviceObject->Flags |= DO_DIRECT_IO;
77     DriverObject->MajorFunction[IRP_MJ_CLOSE] = VfatBuildRequest;
78     DriverObject->MajorFunction[IRP_MJ_CREATE] = VfatBuildRequest;
79     DriverObject->MajorFunction[IRP_MJ_READ] = VfatBuildRequest;
80     DriverObject->MajorFunction[IRP_MJ_WRITE] = VfatBuildRequest;
81     DriverObject->MajorFunction[IRP_MJ_FILE_SYSTEM_CONTROL] = VfatBuildRequest;
82     DriverObject->MajorFunction[IRP_MJ_QUERY_INFORMATION] = VfatBuildRequest;
83     DriverObject->MajorFunction[IRP_MJ_SET_INFORMATION] = VfatBuildRequest;
84     DriverObject->MajorFunction[IRP_MJ_DIRECTORY_CONTROL] = VfatBuildRequest;
85     DriverObject->MajorFunction[IRP_MJ_QUERY_VOLUME_INFORMATION] = VfatBuildRequest;
86     DriverObject->MajorFunction[IRP_MJ_SET_VOLUME_INFORMATION] = VfatBuildRequest;
87     DriverObject->MajorFunction[IRP_MJ_SHUTDOWN] = VfatShutdown;
88     DriverObject->MajorFunction[IRP_MJ_LOCK_CONTROL] = VfatBuildRequest;
89     DriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL] = VfatBuildRequest;
90     DriverObject->MajorFunction[IRP_MJ_CLEANUP] = VfatBuildRequest;
91     DriverObject->MajorFunction[IRP_MJ_FLUSH_BUFFERS] = VfatBuildRequest;
92     DriverObject->MajorFunction[IRP_MJ_PNP] = VfatBuildRequest;
93 
94     DriverObject->DriverUnload = NULL;
95 
96     /* Cache manager */
97     VfatGlobalData->CacheMgrCallbacks.AcquireForLazyWrite = VfatAcquireForLazyWrite;
98     VfatGlobalData->CacheMgrCallbacks.ReleaseFromLazyWrite = VfatReleaseFromLazyWrite;
99     VfatGlobalData->CacheMgrCallbacks.AcquireForReadAhead = VfatAcquireForLazyWrite;
100     VfatGlobalData->CacheMgrCallbacks.ReleaseFromReadAhead = VfatReleaseFromLazyWrite;
101 
102     /* Fast I/O */
103     VfatInitFastIoRoutines(&VfatGlobalData->FastIoDispatch);
104     DriverObject->FastIoDispatch = &VfatGlobalData->FastIoDispatch;
105 
106     /* Private lists */
107     ExInitializeNPagedLookasideList(&VfatGlobalData->FcbLookasideList,
108                                     NULL, NULL, 0, sizeof(VFATFCB), TAG_FCB, 0);
109     ExInitializeNPagedLookasideList(&VfatGlobalData->CcbLookasideList,
110                                     NULL, NULL, 0, sizeof(VFATCCB), TAG_CCB, 0);
111     ExInitializeNPagedLookasideList(&VfatGlobalData->IrpContextLookasideList,
112                                     NULL, NULL, 0, sizeof(VFAT_IRP_CONTEXT), TAG_IRP, 0);
113     ExInitializePagedLookasideList(&VfatGlobalData->CloseContextLookasideList,
114                                    NULL, NULL, 0, sizeof(VFAT_CLOSE_CONTEXT), TAG_CLOSE, 0);
115 
116     ExInitializeResourceLite(&VfatGlobalData->VolumeListLock);
117     InitializeListHead(&VfatGlobalData->VolumeListHead);
118     IoRegisterFileSystem(DeviceObject);
119 
120 #ifdef KDBG
121     {
122         BOOLEAN Registered;
123 
124         Registered = KdRosRegisterCliCallback(vfatKdbgHandler);
125         DPRINT1("VFATFS KDBG extension registered: %s\n", (Registered ? "yes" : "no"));
126     }
127 #endif
128 
129     return STATUS_SUCCESS;
130 }
131 
132 /* EOF */
133