This article is about list_entry traversal in wdk. The previous article (Implementation and simple application of list_entry operations related functions in wdk) is
All the implementation methods have been implemented. traversal is certainly not a problem.
// List_entry.c # include <ntddk. h> /************************************* * ********************* File Name: list_entry.c file path :. /list_entry/list_entry.c Creation Time: 2013-2-4, 22: 49: 43 file Author: girl does not cry file Description: This file implements the list_entry two-way linked list operation in wdk: traversal, insert, remove ~ For more information about how to implement the list_entry operating system functions, see explain struct {int num; list_entry list;} my_data, * pmy_data; void testlistentry (void) {// define a header node. The list_entry list_head; plist_entry P = NULL; int it; // initialize the header node, initializelisthead (& list_head) is required; // Step 4: Initialize the test data for (IT = 0; it <16; it ++) {// call exallocatepool cyclically to allocate memory pmy_data PMD = (pmy_data) exallocatepool (pagedpool, sizeof (my_data); // data field, I only defined one int type variable, assign a value to pMD-> num = it; // the header insertion method. Note that the value is & pMD-> List // you can also change it to inserttaillist to insert a node from the end. // inserttaillist (& list_head, & pMD-> list); insertheadlist (& list_head, & pMD-> list);} // Step 6: traverse the two-way linked list (nodes are not removed ), // P = list_head.flink points to 1st nodes // If the linked list is empty: list_head.flink/blink ==& list_head kdprint ("sequential traversal of two-way linked list: \ n "));
// Note p! = & List_head, in fact, <Chu crazy Windows Driver Programming basics>
// This is wrong. It is p! = & List_head.flink for (P = list_head.flink; P! = & List_head; P = p-> flink) {// use containing_record to get the pointer of my_data. // For more information about containing_record, see my other article. // http: //~ Pmy_data PMD = containing_record (p, my_data, list); kdprint ("pMD-> num: % d \ n", pMD-> num ));} kdprint ("reverse traversal of two-way linked list: \ n"); For (P = list_head.blink; P! = & List_head; P = p-> blink) {pmy_data PMD = containing_record (p, my_data, list); kdprint ("pMD-> num: % d \ n ", pMD-> num);} // Step 2: dump all node pointers (node removed) kdprint ("dump all nodes: \ n"); While (! Islistempty (& list_head) {// obtain the list_entry member list pointer in the my_data pointer. // note that the node has been removed, the node does not exist in the list_head two-way linked list. // You can also replace it with removetaillist to remove the node from the tail. // plist_entry plist = removetaillist (& list_head); plist_entry plist = removeheadlist ); pmy_data PMD = containing_record (plist, my_data, list); // print the stored data and verify the program result kdprint ("pMD-> num = % d \ n ", pMD-> num); // The node has been removed, and can be released after use. // note that the entire PMD pointer is released, instead of plist exfreepool (PMD );}} void driverunload (pdriver_object pdriverobject) {} ntstatus DriverEntry (pdriver_object pdriverobject, punicode_string pregistrypath) {pdriverobject-> driverunload = driverunload; testlistentry (); return response ;}
Source code download: http://files.cnblogs.com/nbsofer/list_entry.7z
Girl don't cry (QQ: 191035066) @ 2013-02-25 13:45:50 http://www.cnblogs.com/nbsofer