ReactOS  0.4.14-dev-77-gd9e7c48
shutdown.c
Go to the documentation of this file.
1 /*
2  * COPYRIGHT: See COPYING in the top level directory
3  * PROJECT: ReactOS kernel
4  * FILE: drivers/fs/vfat/shutdown.c
5  * PURPOSE: VFAT Filesystem
6  * PROGRAMMER: Eric Kohl
7  */
8 
9 /* INCLUDES *****************************************************************/
10 
11 #include "vfat.h"
12 
13 #define NDEBUG
14 #include <debug.h>
15 
16 /* FUNCTIONS ****************************************************************/
17 
18 static
21  PVCB Vcb)
22 {
23  PIRP Irp;
24  KEVENT Event;
27 
30  NULL, 0, NULL, &Event, &IoStatus);
31  if (Irp)
32  {
33  Status = IoCallDriver(Vcb->StorageDevice, Irp);
34  if (Status == STATUS_PENDING)
35  {
37  Status = IoStatus.Status;
38  }
39  }
40  else
41  {
43  }
44 
45  return Status;
46 }
47 
48 
50 NTAPI
53  PIRP Irp)
54 {
56  PLIST_ENTRY ListEntry;
57  PDEVICE_EXTENSION DeviceExt;
58 
59  DPRINT("VfatShutdown(DeviceObject %p, Irp %p)\n",DeviceObject, Irp);
60 
62 
63  /* FIXME: block new mount requests */
65 
67  {
68  Irp->IoStatus.Status = STATUS_SUCCESS;
70  ListEntry = VfatGlobalData->VolumeListHead.Flink;
71  while (ListEntry != &VfatGlobalData->VolumeListHead)
72  {
73  DeviceExt = CONTAINING_RECORD(ListEntry, VCB, VolumeListEntry);
74  ListEntry = ListEntry->Flink;
75 
76  ExAcquireResourceExclusiveLite(&DeviceExt->DirResource, TRUE);
77 
78  /* Flush volume & files */
79  Status = VfatFlushVolume(DeviceExt, DeviceExt->VolumeFcb);
80 
81  /* We're performing a clean shutdown */
82  if (BooleanFlagOn(DeviceExt->VolumeFcb->Flags, VCB_CLEAR_DIRTY) &&
83  BooleanFlagOn(DeviceExt->VolumeFcb->Flags, VCB_IS_DIRTY))
84  {
85  /* Drop the dirty bit */
86  if (NT_SUCCESS(SetDirtyStatus(DeviceExt, FALSE)))
87  DeviceExt->VolumeFcb->Flags &= ~VCB_IS_DIRTY;
88  }
89 
90  if (NT_SUCCESS(Status))
91  {
92  Status = VfatDiskShutDown(DeviceExt);
93  if (!NT_SUCCESS(Status))
94  {
95  DPRINT1("VfatDiskShutDown failed, status = %x\n", Status);
96  }
97  }
98  else
99  {
100  DPRINT1("VfatFlushVolume failed, status = %x\n", Status);
101  }
102  ExReleaseResourceLite(&DeviceExt->DirResource);
103 
104  /* Unmount the logical volume */
105 #ifdef ENABLE_SWAPOUT
106  VfatCheckForDismount(DeviceExt, FALSE);
107 #endif
108 
109  if (!NT_SUCCESS(Status))
110  Irp->IoStatus.Status = Status;
111  }
113 
114  /* FIXME: Free all global acquired resources */
115 
116  Status = Irp->IoStatus.Status;
117  }
118  else
119  {
120  Irp->IoStatus.Status = STATUS_INVALID_DEVICE_REQUEST;
122  }
123 
124  Irp->IoStatus.Information = 0;
126 
128 
129  return Status;
130 }
131 
132 /* EOF */
#define TRUE
Definition: types.h:120
LIST_ENTRY VolumeListHead
Definition: vfat.h:410
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
#define FsRtlEnterFileSystem
#define FsRtlExitFileSystem
IN PLARGE_INTEGER IN ULONG IN BOOLEAN IN ULONG IN BOOLEAN OUT PIO_STATUS_BLOCK IoStatus
Definition: fatprocs.h:2650
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 IRP_MJ_SHUTDOWN
_In_ PIRP Irp
Definition: csq.h:116
#define BooleanFlagOn(F, SF)
Definition: ext2fs.h:183
#define VCB_IS_DIRTY
Definition: vfat.h:244
LONG NTSTATUS
Definition: precomp.h:26
#define VCB_CLEAR_DIRTY
Definition: vfat.h:245
NTSTATUS VfatFlushVolume(PDEVICE_EXTENSION DeviceExt, PVFATFCB VolumeFcb)
Definition: flush.c:51
#define STATUS_INVALID_DEVICE_REQUEST
Definition: udferr_usr.h:138
Definition: cdstruc.h:504
static NTSTATUS VfatDiskShutDown(PVCB Vcb)
Definition: shutdown.c:20
NTSTATUS NTAPI KeWaitForSingleObject(IN PVOID Object, IN KWAIT_REASON WaitReason, IN KPROCESSOR_MODE WaitMode, IN BOOLEAN Alertable, IN PLARGE_INTEGER Timeout OPTIONAL)
Definition: wait.c:416
BOOLEAN NTAPI ExAcquireResourceExclusiveLite(IN PERESOURCE Resource, IN BOOLEAN Wait)
Definition: resource.c:770
NTSTATUS(* NTAPI)(IN PFILE_FULL_EA_INFORMATION EaBuffer, IN ULONG EaLength, OUT PULONG ErrorOffset)
Definition: IoEaTest.cpp:117
_In_ PVOID _In_ ULONG Event
Definition: iotypes.h:435
smooth NULL
Definition: ftsmooth.c:416
#define IoCompleteRequest
Definition: irp.c:1240
void DPRINT(...)
Definition: polytest.cpp:61
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
struct _LIST_ENTRY * Flink
Definition: typedefs.h:119
PDEVICE_OBJECT DeviceObject
Definition: vfat.h:406
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define STATUS_PENDING
Definition: ntstatus.h:82
#define Vcb
Definition: cdprocs.h:1425
VOID FASTCALL ExReleaseResourceLite(IN PERESOURCE Resource)
Definition: resource.c:1817
Definition: typedefs.h:117
BOOLEAN VfatCheckForDismount(IN PDEVICE_EXTENSION DeviceExt, IN BOOLEAN Force)
Definition: misc.c:417
Status
Definition: gdiplustypes.h:24
PVFAT_GLOBAL_DATA VfatGlobalData
Definition: iface.c:40
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
BOOLEAN ShutdownStarted
Definition: vfat.h:422
NTSTATUS NTAPI IoCallDriver(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: irp.c:1218
#define DPRINT1
Definition: precomp.h:8
ERESOURCE VolumeListLock
Definition: vfat.h:409
#define IO_NO_INCREMENT
Definition: iotypes.h:566
return STATUS_SUCCESS
Definition: btrfs.c:2966
NTSTATUS SetDirtyStatus(PDEVICE_EXTENSION DeviceExt, BOOLEAN DirtyStatus)
Definition: fat.c:1015
NTSTATUS NTAPI VfatShutdown(PDEVICE_OBJECT DeviceObject, PIRP Irp)
Definition: shutdown.c:51