[AFD] Introduce and use pool tags. Thanks go to Arty for assisting me with this....
[reactos.git] / drivers / network / afd / afd / context.c
1 /*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS kernel
4 * FILE: drivers/net/afd/afd/context.c
5 * PURPOSE: Ancillary functions driver
6 * PROGRAMMER: Art Yerkes (ayerkes@speakeasy.net)
7 * UPDATE HISTORY:
8 * 20040708 Created
9 */
10
11 #include "afd.h"
12
13 NTSTATUS NTAPI
14 AfdGetContext( PDEVICE_OBJECT DeviceObject, PIRP Irp,
15 PIO_STACK_LOCATION IrpSp ) {
16 NTSTATUS Status = STATUS_INVALID_PARAMETER;
17 PFILE_OBJECT FileObject = IrpSp->FileObject;
18 PAFD_FCB FCB = FileObject->FsContext;
19 UINT ContextSize = IrpSp->Parameters.DeviceIoControl.OutputBufferLength;
20
21 UNREFERENCED_PARAMETER(DeviceObject);
22
23 if( !SocketAcquireStateLock( FCB ) ) return LostSocket( Irp );
24
25 if( FCB->ContextSize < ContextSize ) ContextSize = FCB->ContextSize;
26
27 if( FCB->Context ) {
28 RtlCopyMemory( Irp->UserBuffer,
29 FCB->Context,
30 ContextSize );
31 Status = STATUS_SUCCESS;
32 }
33
34 AFD_DbgPrint(MID_TRACE,("Returning %x\n", Status));
35
36 return UnlockAndMaybeComplete( FCB, Status, Irp, ContextSize );
37 }
38
39 NTSTATUS NTAPI
40 AfdGetContextSize( PDEVICE_OBJECT DeviceObject, PIRP Irp,
41 PIO_STACK_LOCATION IrpSp )
42 {
43 PFILE_OBJECT FileObject = IrpSp->FileObject;
44 PAFD_FCB FCB = FileObject->FsContext;
45
46 UNREFERENCED_PARAMETER(DeviceObject);
47
48 if( !SocketAcquireStateLock( FCB ) ) return LostSocket( Irp );
49
50 if (IrpSp->Parameters.DeviceIoControl.OutputBufferLength < sizeof(ULONG))
51 {
52 AFD_DbgPrint(MIN_TRACE,("Buffer too small\n"));
53 return UnlockAndMaybeComplete(FCB, STATUS_BUFFER_TOO_SMALL, Irp, sizeof(ULONG));
54 }
55
56 RtlCopyMemory(Irp->UserBuffer,
57 &FCB->ContextSize,
58 sizeof(ULONG));
59
60 return UnlockAndMaybeComplete(FCB, STATUS_SUCCESS, Irp, sizeof(ULONG));
61 }
62
63 NTSTATUS NTAPI
64 AfdSetContext( PDEVICE_OBJECT DeviceObject, PIRP Irp,
65 PIO_STACK_LOCATION IrpSp ) {
66 PFILE_OBJECT FileObject = IrpSp->FileObject;
67 PAFD_FCB FCB = FileObject->FsContext;
68 PVOID Context = LockRequest(Irp, IrpSp, FALSE, NULL);
69
70 UNREFERENCED_PARAMETER(DeviceObject);
71
72 if( !SocketAcquireStateLock( FCB ) ) return LostSocket( Irp );
73
74 if (!Context)
75 return UnlockAndMaybeComplete(FCB, STATUS_NO_MEMORY, Irp, 0);
76
77 if( FCB->Context ) {
78 ExFreePoolWithTag(FCB->Context, TAG_AFD_SOCKET_CONTEXT);
79 FCB->ContextSize = 0;
80 }
81
82 FCB->Context = ExAllocatePoolWithTag(PagedPool,
83 IrpSp->Parameters.DeviceIoControl.InputBufferLength,
84 TAG_AFD_SOCKET_CONTEXT);
85
86 if( !FCB->Context ) return UnlockAndMaybeComplete( FCB, STATUS_NO_MEMORY, Irp, 0 );
87
88 FCB->ContextSize = IrpSp->Parameters.DeviceIoControl.InputBufferLength;
89
90 RtlCopyMemory( FCB->Context,
91 Context,
92 FCB->ContextSize );
93
94 return UnlockAndMaybeComplete( FCB, STATUS_SUCCESS, Irp, 0 );
95 }