[FASTFAT_NEW]
[reactos.git] / reactos / drivers / filesystems / fastfat_new / lock.c
1 /*
2 * PROJECT: ReactOS FAT file system driver
3 * LICENSE: GNU GPLv3 as published by the Free Software Foundation
4 * FILE: drivers/filesystems/fastfat/lock.c
5 * PURPOSE: Lock support routines
6 * PROGRAMMERS: Aleksey Bragin (aleksey@reactos.org)
7 */
8
9 /* INCLUDES *****************************************************************/
10
11 #define NDEBUG
12 #include "fastfat.h"
13
14 /* FUNCTIONS ****************************************************************/
15
16 NTSTATUS
17 NTAPI
18 FatiLockControl(PFAT_IRP_CONTEXT IrpContext, PIRP Irp)
19 {
20 PIO_STACK_LOCATION IrpSp;
21 TYPE_OF_OPEN TypeOfOpen;
22 PVCB Vcb;
23 PFCB Fcb;
24 PCCB Ccb;
25 NTSTATUS Status;
26
27 /* Get IRP stack location */
28 IrpSp = IoGetCurrentIrpStackLocation(Irp);
29
30 /* Determine type of open */
31 TypeOfOpen = FatDecodeFileObject(IrpSp->FileObject, &Vcb, &Fcb, &Ccb);
32
33 /* Only user file open is allowed */
34 if (TypeOfOpen != UserFileOpen)
35 {
36 FatCompleteRequest(IrpContext, Irp, STATUS_INVALID_PARAMETER);
37 return STATUS_INVALID_PARAMETER;
38 }
39
40 /* Acquire shared FCB lock */
41 if (!FatAcquireSharedFcb(IrpContext, Fcb))
42 {
43 UNIMPLEMENTED;
44 //Status = FatFsdPostRequest(IrpContext, Irp);
45 Status = STATUS_NOT_IMPLEMENTED;
46 return Status;
47 }
48
49 /* Check oplock state */
50 Status = FsRtlCheckOplock(&Fcb->Fcb.Oplock,
51 Irp,
52 IrpContext,
53 FatOplockComplete,
54 NULL);
55
56 if (Status != STATUS_SUCCESS)
57 {
58 /* Release FCB lock */
59 FatReleaseFcb(IrpContext, Fcb);
60
61 return Status;
62 }
63
64 /* Process the lock */
65 Status = FsRtlProcessFileLock(&Fcb->Fcb.Lock, Irp, NULL);
66
67 /* Update Fast I/O state */
68 Fcb->Header.IsFastIoPossible = FatIsFastIoPossible(Fcb);
69
70 /* Complete the request */
71 FatCompleteRequest(IrpContext, NULL, 0);
72
73 /* Release FCB lock */
74 FatReleaseFcb(IrpContext, Fcb);
75
76 return Status;
77 }
78
79 NTSTATUS
80 NTAPI
81 FatLockControl(PDEVICE_OBJECT DeviceObject, PIRP Irp)
82 {
83 PFAT_IRP_CONTEXT IrpContext;
84 NTSTATUS Status;
85 BOOLEAN TopLevel;
86
87 DPRINT1("FatLockControl()\n");
88
89 /* Enter FsRtl critical region */
90 FsRtlEnterFileSystem();
91
92 /* Set Top Level IRP if not set */
93 TopLevel = FatIsTopLevelIrp(Irp);
94
95 /* Build an irp context */
96 IrpContext = FatBuildIrpContext(Irp, IoIsOperationSynchronous(Irp));
97
98 /* Call internal function */
99 Status = FatiLockControl(IrpContext, Irp);
100
101 /* Reset Top Level IRP */
102 if (TopLevel) IoSetTopLevelIrp(NULL);
103
104 /* Leave FsRtl critical region */
105 FsRtlExitFileSystem();
106
107 return Status;
108 }
109
110 VOID
111 NTAPI
112 FatOplockComplete(IN PVOID Context,
113 IN PIRP Irp)
114 {
115 UNIMPLEMENTED;
116 }
117
118 VOID
119 NTAPI
120 FatPrePostIrp(IN PVOID Context,
121 IN PIRP Irp)
122 {
123 UNIMPLEMENTED;
124 }
125
126 /* EOF */