update for HEAD-2003021201
[reactos.git] / drivers / fs / vfat / shutdown.c
1 /* $Id$
2  *
3  * COPYRIGHT:        See COPYING in the top level directory
4  * PROJECT:          ReactOS kernel
5  * FILE:             services/fs/vfat/shutdown.c
6  * PURPOSE:          VFAT Filesystem
7  * PROGRAMMER:       Eric Kohl (ekohl@rz-online.de)
8  */
9
10 /* INCLUDES *****************************************************************/
11
12 #include <ddk/ntddk.h>
13
14 #define NDEBUG
15 #include <debug.h>
16
17 #include "vfat.h"
18
19 /* FUNCTIONS ****************************************************************/
20
21 NTSTATUS STDCALL
22 VfatShutdown(PDEVICE_OBJECT DeviceObject, PIRP Irp)
23 {
24    NTSTATUS Status;
25    PLIST_ENTRY ListEntry;
26    PDEVICE_EXTENSION DeviceExt;
27
28    DPRINT("VfatShutdown(DeviceObject %x, Irp %x)\n",DeviceObject, Irp);
29
30    /* FIXME: block new mount requests */
31
32    if (DeviceObject == VfatGlobalData->DeviceObject)
33    {
34       Irp->IoStatus.Status = STATUS_SUCCESS;
35       ExAcquireResourceExclusiveLite(&VfatGlobalData->VolumeListLock, TRUE);
36       ListEntry = VfatGlobalData->VolumeListHead.Flink;
37       while (ListEntry != &VfatGlobalData->VolumeListHead)
38       {
39          DeviceExt = CONTAINING_RECORD(ListEntry, VCB, VolumeListEntry);
40          ListEntry = ListEntry->Flink;
41
42          ExAcquireResourceExclusiveLite(&DeviceExt->DirResource, TRUE);
43          Status = VfatFlushVolume(DeviceExt, DeviceExt->VolumeFcb);
44          ExReleaseResourceLite(&DeviceExt->DirResource);
45          if (!NT_SUCCESS(Status))
46          {
47             DPRINT1("VfatFlushVolume failed, status = %x\n", Status);
48             Irp->IoStatus.Status = Status;
49          }
50          /* FIXME: Unmount the logical volume */
51
52          ExReleaseResourceLite(&VfatGlobalData->VolumeListLock);
53       }
54       /* FIXME: Free all global acquired resources */
55
56       Status = Irp->IoStatus.Status;
57    }
58    else
59    {
60       Status = STATUS_INVALID_DEVICE_REQUEST;
61    }
62
63    Irp->IoStatus.Status = Status;
64    Irp->IoStatus.Information = 0;
65
66    IoCompleteRequest(Irp, IO_NO_INCREMENT);
67    return(Status);
68 }
69
70 /* EOF */