ReactOS 0.4.16-dev-197-g92996da
shutdown.c
Go to the documentation of this file.
1/*
2 * PROJECT: VFAT Filesystem
3 * LICENSE: GPL-2.0-or-later (https://spdx.org/licenses/GPL-2.0-or-later)
4 * PURPOSE: Shutdown handlers
5 * COPYRIGHT: Copyright 2000-2013 Eric Kohl <eric.kohl@reactos.org>
6 */
7
8/* INCLUDES *****************************************************************/
9
10#include "vfat.h"
11
12#define NDEBUG
13#include <debug.h>
14
15/* FUNCTIONS ****************************************************************/
16
17static
20 PVCB Vcb)
21{
22 PIRP Irp;
26
29 NULL, 0, NULL, &Event, &IoStatus);
30 if (Irp)
31 {
32 Status = IoCallDriver(Vcb->StorageDevice, Irp);
34 {
36 Status = IoStatus.Status;
37 }
38 }
39 else
40 {
42 }
43
44 return Status;
45}
46
47
52 PIRP Irp)
53{
55 PLIST_ENTRY ListEntry;
56 PDEVICE_EXTENSION DeviceExt;
57
58 DPRINT("VfatShutdown(DeviceObject %p, Irp %p)\n",DeviceObject, Irp);
59
61
62 /* FIXME: block new mount requests */
64
66 {
67 Irp->IoStatus.Status = STATUS_SUCCESS;
70 while (ListEntry != &VfatGlobalData->VolumeListHead)
71 {
72 DeviceExt = CONTAINING_RECORD(ListEntry, VCB, VolumeListEntry);
73 ListEntry = ListEntry->Flink;
74
75 ExAcquireResourceExclusiveLite(&DeviceExt->DirResource, TRUE);
76
77 /* Flush volume & files */
78 Status = VfatFlushVolume(DeviceExt, DeviceExt->VolumeFcb);
79
80 /* We're performing a clean shutdown */
81 if (BooleanFlagOn(DeviceExt->VolumeFcb->Flags, VCB_CLEAR_DIRTY) &&
82 BooleanFlagOn(DeviceExt->VolumeFcb->Flags, VCB_IS_DIRTY))
83 {
84 /* Drop the dirty bit */
85 if (NT_SUCCESS(SetDirtyStatus(DeviceExt, FALSE)))
86 DeviceExt->VolumeFcb->Flags &= ~VCB_IS_DIRTY;
87 }
88
89 if (NT_SUCCESS(Status))
90 {
91 Status = VfatDiskShutDown(DeviceExt);
92 if (!NT_SUCCESS(Status))
93 {
94 DPRINT1("VfatDiskShutDown failed, status = %x\n", Status);
95 }
96 }
97 else
98 {
99 DPRINT1("VfatFlushVolume failed, status = %x\n", Status);
100 }
101 ExReleaseResourceLite(&DeviceExt->DirResource);
102
103 /* Unmount the logical volume */
104#ifdef ENABLE_SWAPOUT
105 VfatCheckForDismount(DeviceExt, FALSE);
106#endif
107
108 if (!NT_SUCCESS(Status))
109 Irp->IoStatus.Status = Status;
110 }
112
113 /* FIXME: Free all global acquired resources */
114
115 Status = Irp->IoStatus.Status;
116 }
117 else
118 {
119 Irp->IoStatus.Status = STATUS_INVALID_DEVICE_REQUEST;
121 }
122
123 Irp->IoStatus.Information = 0;
125
127
128 return Status;
129}
130
131/* EOF */
LONG NTSTATUS
Definition: precomp.h:26
#define DPRINT1
Definition: precomp.h:8
_In_ PIRP Irp
Definition: csq.h:116
#define STATUS_PENDING
Definition: d3dkmdt.h:43
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
NTSTATUS SetDirtyStatus(PDEVICE_EXTENSION DeviceExt, BOOLEAN DirtyStatus)
Definition: fat.c:1017
BOOLEAN VfatCheckForDismount(IN PDEVICE_EXTENSION DeviceExt, IN BOOLEAN Force)
Definition: misc.c:495
static NTSTATUS VfatDiskShutDown(PVCB Vcb)
Definition: shutdown.c:19
#define KeWaitForSingleObject(pEvt, foo, a, b, c)
Definition: env_spec_w32.h:478
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
#define ExAcquireResourceExclusiveLite(res, wait)
Definition: env_spec_w32.h:615
#define BooleanFlagOn(F, SF)
Definition: ext2fs.h:183
PVFAT_GLOBAL_DATA VfatGlobalData
Definition: iface.c:18
#define FsRtlEnterFileSystem
#define FsRtlExitFileSystem
Status
Definition: gdiplustypes.h:25
__in UCHAR __in POWER_STATE __in_opt PVOID __in PIO_STATUS_BLOCK IoStatus
Definition: mxum.h:159
#define KernelMode
Definition: asm.h:34
@ NotificationEvent
VOID FASTCALL ExReleaseResourceLite(IN PERESOURCE Resource)
Definition: resource.c:1822
PIRP NTAPI IoBuildSynchronousFsdRequest(IN ULONG MajorFunction, IN PDEVICE_OBJECT DeviceObject, IN PVOID Buffer, IN ULONG Length, IN PLARGE_INTEGER StartingOffset, IN PKEVENT Event, IN PIO_STATUS_BLOCK IoStatusBlock)
Definition: irp.c:1069
#define IoCompleteRequest
Definition: irp.c:1240
#define IoCallDriver
Definition: irp.c:1225
#define Vcb
Definition: cdprocs.h:1415
#define STATUS_SUCCESS
Definition: shellext.h:65
#define DPRINT
Definition: sndvol32.h:73
ERESOURCE VolumeListLock
Definition: vfat.h:415
LIST_ENTRY VolumeListHead
Definition: vfat.h:416
PDEVICE_OBJECT DeviceObject
Definition: vfat.h:412
BOOLEAN ShutdownStarted
Definition: vfat.h:428
Definition: typedefs.h:120
struct _LIST_ENTRY * Flink
Definition: typedefs.h:121
Definition: cdstruc.h:498
#define NTAPI
Definition: typedefs.h:36
#define CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:260
#define STATUS_INVALID_DEVICE_REQUEST
Definition: udferr_usr.h:138
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
#define VCB_CLEAR_DIRTY
Definition: vfat.h:245
DRIVER_DISPATCH VfatShutdown
Definition: vfat.h:1210
#define VCB_IS_DIRTY
Definition: vfat.h:244
NTSTATUS VfatFlushVolume(PDEVICE_EXTENSION DeviceExt, PVFATFCB VolumeFcb)
Definition: flush.c:51
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
#define IO_NO_INCREMENT
Definition: iotypes.h:598
#define IRP_MJ_SHUTDOWN
@ Executive
Definition: ketypes.h:415