ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

topology.c
Go to the documentation of this file.
00001 /*
00002  * COPYRIGHT:       See COPYING in the top level directory
00003  * PROJECT:         ReactOS Kernel Streaming
00004  * FILE:            drivers/ksfilter/ks/topoology.c
00005  * PURPOSE:         KS Allocator functions
00006  * PROGRAMMER:      Johannes Anderwald
00007  */
00008 
00009 
00010 #include "priv.h"
00011 
00012 
00013 NTSTATUS
00014 NTAPI
00015 KspCreateObjectType(
00016     IN HANDLE ParentHandle,
00017     IN LPWSTR ObjectType,
00018     PVOID CreateParameters,
00019     UINT CreateParametersSize,
00020     IN  ACCESS_MASK DesiredAccess,
00021     OUT PHANDLE NodeHandle)
00022 {
00023     NTSTATUS Status;
00024     IO_STATUS_BLOCK IoStatusBlock;
00025     OBJECT_ATTRIBUTES ObjectAttributes;
00026     UNICODE_STRING Name;
00027 
00028     /* calculate request length */
00029     Name.Length = 0;
00030     Name.MaximumLength = wcslen(ObjectType) * sizeof(WCHAR) + CreateParametersSize +  1 * sizeof(WCHAR);
00031     Name.MaximumLength += sizeof(WCHAR);
00032     /* acquire request buffer */
00033     Name.Buffer = AllocateItem(NonPagedPool, Name.MaximumLength);
00034     /* check for success */
00035     if (!Name.Buffer)
00036     {
00037         /* insufficient resources */
00038         return STATUS_INSUFFICIENT_RESOURCES;
00039     }
00040 
00041     /* build a request which looks like {ObjectClass}\CreateParameters 
00042      * For pins the parent is the reference string used in registration
00043      * For clocks it is full path for pin\{ClockGuid}\ClockCreateParams
00044      */
00045     RtlAppendUnicodeToString(&Name, ObjectType);
00046     RtlAppendUnicodeToString(&Name, L"\\");
00047     /* append create parameters */
00048     RtlMoveMemory(Name.Buffer + (Name.Length / sizeof(WCHAR)), CreateParameters, CreateParametersSize);
00049     Name.Length += CreateParametersSize;
00050     Name.Buffer[Name.Length / 2] = L'\0';
00051 
00052     InitializeObjectAttributes(&ObjectAttributes, &Name, OBJ_KERNEL_HANDLE | OBJ_CASE_INSENSITIVE | OBJ_OPENIF, ParentHandle, NULL);
00053     /* create the instance */
00054     Status = IoCreateFile(NodeHandle,
00055                           DesiredAccess,
00056                           &ObjectAttributes,
00057                           &IoStatusBlock,
00058                           NULL,
00059                           0,
00060                           0,
00061                           FILE_OPEN,
00062                           0,
00063                           NULL,
00064                           0,
00065                           CreateFileTypeNone,
00066                           NULL,
00067                           IO_NO_PARAMETER_CHECKING | IO_FORCE_ACCESS_CHECK);
00068 
00069     /* free request buffer */
00070     FreeItem(Name.Buffer);
00071     return Status;
00072 }
00073 
00074 
00075 /*
00076     @implemented
00077 */
00078 KSDDKAPI NTSTATUS NTAPI
00079 KsCreateTopologyNode(
00080     IN  HANDLE ParentHandle,
00081     IN  PKSNODE_CREATE NodeCreate,
00082     IN  ACCESS_MASK DesiredAccess,
00083     OUT PHANDLE NodeHandle)
00084 {
00085     return KspCreateObjectType(ParentHandle,
00086                                KSSTRING_TopologyNode,
00087                                (PVOID)NodeCreate,
00088                                sizeof(KSNODE_CREATE),
00089                                DesiredAccess,
00090                                NodeHandle);
00091 }
00092 
00093 /*
00094     @implemented
00095 */
00096 KSDDKAPI
00097 NTSTATUS
00098 NTAPI
00099 KsValidateTopologyNodeCreateRequest(
00100     IN  PIRP Irp,
00101     IN  PKSTOPOLOGY Topology,
00102     OUT PKSNODE_CREATE* OutNodeCreate)
00103 {
00104     PKSNODE_CREATE NodeCreate;
00105     ULONG Size;
00106     NTSTATUS Status;
00107 
00108     /* did the caller miss the topology */
00109     if (!Topology)
00110         return STATUS_INVALID_PARAMETER;
00111 
00112     /* set create param  size */
00113     Size = sizeof(KSNODE_CREATE);
00114 
00115     /* fetch create parameters */
00116     Status = KspCopyCreateRequest(Irp,
00117                                   KSSTRING_TopologyNode,
00118                                   &Size,
00119                                   (PVOID*)&NodeCreate);
00120 
00121     if (!NT_SUCCESS(Status))
00122         return Status;
00123 
00124     if (NodeCreate->CreateFlags != 0 || (NodeCreate->Node >= Topology->TopologyNodesCount && NodeCreate->Node != MAXULONG))
00125     {
00126         /* invalid node create */
00127         FreeItem(NodeCreate);
00128         return STATUS_UNSUCCESSFUL;
00129     }
00130 
00131     /* store result */
00132     *OutNodeCreate = NodeCreate;
00133 
00134     return Status;
00135 }
00136 
00137 /*
00138     @implemented
00139 */
00140 KSDDKAPI
00141 NTSTATUS
00142 NTAPI
00143 KsTopologyPropertyHandler(
00144     IN  PIRP Irp,
00145     IN  PKSPROPERTY Property,
00146     IN  OUT PVOID Data,
00147     IN  const KSTOPOLOGY* Topology)
00148 {
00149     KSP_NODE * Node;
00150     PIO_STACK_LOCATION IoStack;
00151     NTSTATUS Status;
00152     PKEY_VALUE_PARTIAL_INFORMATION KeyInfo;
00153     LPGUID Guid;
00154 
00155     IoStack = IoGetCurrentIrpStackLocation(Irp);
00156 
00157     DPRINT("KsTopologyPropertyHandler Irp %p Property %p Data %p Topology %p OutputLength %lu PropertyId %lu\n", Irp, Property, Data, Topology, IoStack->Parameters.DeviceIoControl.OutputBufferLength, Property->Id);
00158 
00159     if (Property->Flags != KSPROPERTY_TYPE_GET)
00160     {
00161         Irp->IoStatus.Status = STATUS_NOT_IMPLEMENTED;
00162         Irp->IoStatus.Information = 0;
00163         return STATUS_NOT_IMPLEMENTED;
00164     }
00165 
00166     switch(Property->Id)
00167     {
00168         case KSPROPERTY_TOPOLOGY_CATEGORIES:
00169             return KsHandleSizedListQuery(Irp, Topology->CategoriesCount, sizeof(GUID), Topology->Categories);
00170 
00171         case KSPROPERTY_TOPOLOGY_NODES:
00172             return KsHandleSizedListQuery(Irp, Topology->TopologyNodesCount, sizeof(GUID), Topology->TopologyNodes);
00173 
00174         case KSPROPERTY_TOPOLOGY_CONNECTIONS:
00175             return KsHandleSizedListQuery(Irp, Topology->TopologyConnectionsCount, sizeof(KSTOPOLOGY_CONNECTION), Topology->TopologyConnections);
00176 
00177         case KSPROPERTY_TOPOLOGY_NAME:
00178             Node = (KSP_NODE*)Property;
00179 
00180             /* check for invalid node id */
00181             if (Node->NodeId >= Topology->TopologyNodesCount)
00182             {
00183                 /* invalid node id */
00184                 Irp->IoStatus.Information = 0;
00185                 Status = STATUS_INVALID_PARAMETER;
00186                 break;
00187             }
00188 
00189             /* check if there is a name supplied */
00190             if (!IsEqualGUIDAligned(&Topology->TopologyNodesNames[Node->NodeId], &GUID_NULL))
00191             {
00192                 /* node name has been supplied */
00193                 Guid = (LPGUID)&Topology->TopologyNodesNames[Node->NodeId];
00194             }
00195             else
00196             {
00197                 /* fallback to topology node type */
00198                 Guid = (LPGUID)&Topology->TopologyNodes[Node->NodeId];
00199             }
00200 
00201             /* read topology node name */
00202             Status = KspReadMediaCategory(Guid, &KeyInfo);
00203             if (!NT_SUCCESS(Status))
00204             {
00205                 Irp->IoStatus.Information = 0;
00206                 break;
00207             }
00208 
00209             /* store result size */
00210             Irp->IoStatus.Information = KeyInfo->DataLength + sizeof(WCHAR);
00211 
00212             /* check for buffer overflow */
00213             if (KeyInfo->DataLength + sizeof(WCHAR) > IoStack->Parameters.DeviceIoControl.OutputBufferLength)
00214             {
00215                 /* buffer too small */
00216                 Status = STATUS_BUFFER_OVERFLOW;
00217                 FreeItem(KeyInfo);
00218                 break;
00219             }
00220 
00221             /* copy result buffer */
00222             RtlMoveMemory(Irp->UserBuffer, &KeyInfo->Data, KeyInfo->DataLength);
00223 
00224             /* zero terminate it */
00225             ((LPWSTR)Irp->UserBuffer)[KeyInfo->DataLength / sizeof(WCHAR)] = L'\0';
00226 
00227             /* free key info */
00228             FreeItem(KeyInfo);
00229 
00230             break;
00231         default:
00232              Irp->IoStatus.Information = 0;
00233            Status = STATUS_NOT_FOUND;
00234     }
00235 
00236 
00237     return Status;
00238 }
00239 

Generated on Fri May 25 2012 04:26:05 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.