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)
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
;
21 UNREFERENCED_PARAMETER(DeviceObject
);
23 if( !SocketAcquireStateLock( FCB
) ) return LostSocket( Irp
);
25 if( FCB
->ContextSize
< ContextSize
) ContextSize
= FCB
->ContextSize
;
28 RtlCopyMemory( Irp
->UserBuffer
,
31 Status
= STATUS_SUCCESS
;
34 AFD_DbgPrint(MID_TRACE
,("Returning %x\n", Status
));
36 return UnlockAndMaybeComplete( FCB
, Status
, Irp
, ContextSize
);
40 AfdGetContextSize( PDEVICE_OBJECT DeviceObject
, PIRP Irp
,
41 PIO_STACK_LOCATION IrpSp
)
43 PFILE_OBJECT FileObject
= IrpSp
->FileObject
;
44 PAFD_FCB FCB
= FileObject
->FsContext
;
46 UNREFERENCED_PARAMETER(DeviceObject
);
48 if( !SocketAcquireStateLock( FCB
) ) return LostSocket( Irp
);
50 if (IrpSp
->Parameters
.DeviceIoControl
.OutputBufferLength
< sizeof(ULONG
))
52 AFD_DbgPrint(MIN_TRACE
,("Buffer too small\n"));
53 return UnlockAndMaybeComplete(FCB
, STATUS_BUFFER_TOO_SMALL
, Irp
, sizeof(ULONG
));
56 RtlCopyMemory(Irp
->UserBuffer
,
60 return UnlockAndMaybeComplete(FCB
, STATUS_SUCCESS
, Irp
, sizeof(ULONG
));
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
);
70 UNREFERENCED_PARAMETER(DeviceObject
);
72 if( !SocketAcquireStateLock( FCB
) ) return LostSocket( Irp
);
75 return UnlockAndMaybeComplete(FCB
, STATUS_NO_MEMORY
, Irp
, 0);
78 ExFreePool( FCB
->Context
);
82 FCB
->Context
= ExAllocatePool( PagedPool
,
83 IrpSp
->Parameters
.DeviceIoControl
.InputBufferLength
);
85 if( !FCB
->Context
) return UnlockAndMaybeComplete( FCB
, STATUS_NO_MEMORY
, Irp
, 0 );
87 FCB
->ContextSize
= IrpSp
->Parameters
.DeviceIoControl
.InputBufferLength
;
89 RtlCopyMemory( FCB
->Context
,
93 return UnlockAndMaybeComplete( FCB
, STATUS_SUCCESS
, Irp
, 0 );