iop.h 117 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410
  1. /*++
  2. Copyright (c) 2012 Minoca Corp. All Rights Reserved
  3. Module Name:
  4. iop.h
  5. Abstract:
  6. This header contains private definitions for the I/O Subsystem.
  7. Author:
  8. Evan Green 16-Sep-2012
  9. --*/
  10. //
  11. // ------------------------------------------------------------------- Includes
  12. //
  13. //
  14. // --------------------------------------------------------------------- Macros
  15. //
  16. //
  17. // This macro evaluates to non-zero if the given object is a device or a
  18. // volume.
  19. //
  20. #define IS_DEVICE_OR_VOLUME(_Object) \
  21. ((((POBJECT_HEADER)(_Object))->Type == ObjectDevice) || \
  22. (((POBJECT_HEADER)(_Object))->Type == ObjectVolume))
  23. //
  24. // This macro evaluates to non-zero if the given file object has no dirty data
  25. // and no dirty properties.
  26. //
  27. #define IS_FILE_OBJECT_CLEAN(_FileObject) \
  28. (((_FileObject)->Flags & \
  29. (FILE_OBJECT_FLAG_DIRTY_DATA | FILE_OBJECT_FLAG_DIRTY_PROPERTIES)) == 0)
  30. //
  31. // ---------------------------------------------------------------- Definitions
  32. //
  33. #define IO_ALLOCATION_TAG 0x21216F49 // '!!oI'
  34. #define FI_ALLOCATION_TAG 0x656C6946 // 'eliF'
  35. #define DEVICE_ALLOCATION_TAG 0x21766544 // '!veD'
  36. #define DEVICE_WORK_ALLOCATION_TAG 0x57766544 // 'WveD'
  37. #define IRP_ALLOCATION_TAG 0x21707249 // '!prI'
  38. #define DEVICE_INTERFACE_ALLOCATION_TAG 0x49766544 // 'IveD'
  39. #define DEVICE_INFORMATION_ALLOCATION_TAG 0x666E4944 // 'fnID'
  40. #define DEVICE_INFORMATION_REQUEST_ALLOCATION_TAG 0x526E4944 // 'RnID'
  41. #define PATH_ALLOCATION_TAG 0x68746150 // 'htaP'
  42. #define FILE_LOCK_ALLOCATION_TAG 0x6B434C46 // 'kcLF'
  43. #define SOCKET_INFORMATION_ALLOCATION_TAG 0x666E4953 // 'fnIS'
  44. #define UNIX_SOCKET_ALLOCATION_TAG 0x6F536E55 // 'oSnU'
  45. #define IRP_MAGIC_VALUE (USHORT)IRP_ALLOCATION_TAG
  46. //
  47. // This flag is set once the DriverEntry routine has been called for a driver.
  48. //
  49. #define DRIVER_FLAG_ENTRY_CALLED 0x00000001
  50. //
  51. // This flag is set if a driver returns a failing status code to its
  52. // DriverEntry routine.
  53. //
  54. #define DRIVER_FLAG_FAILED_DRIVER_ENTRY 0x00000002
  55. //
  56. // This flag is set if a driver was loaded by the boot environment.
  57. //
  58. #define DRIVER_FLAG_LOADED_AT_BOOT 0x00000004
  59. //
  60. // This flag is set on a device action if the action is to be sent down to the
  61. // entire subtree below this device. This performs a pre-order traversal.
  62. //
  63. #define DEVICE_ACTION_SEND_TO_SUBTREE 0x00000001
  64. //
  65. // This flag is set on a device action if the action is to be sent to the device
  66. // and its children. Only the children will receive the action, not
  67. // grandchildren.
  68. //
  69. #define DEVICE_ACTION_SEND_TO_CHILDREN 0x00000002
  70. //
  71. // This flag is set on a device action if the action should open the queue.
  72. //
  73. #define DEVICE_ACTION_OPEN_QUEUE 0x00000004
  74. //
  75. // This flag is set on a device action if the action should close the queue.
  76. //
  77. #define DEVICE_ACTION_CLOSE_QUEUE 0x00000008
  78. //
  79. // This flag is set when an IRP has been marked as complete.
  80. //
  81. #define IRP_COMPLETE 0x00000001
  82. //
  83. // This flag is set in an IRP when it's been marked as pending.
  84. //
  85. #define IRP_PENDING 0x00000002
  86. //
  87. // This flag is set in an IRP when it's active.
  88. //
  89. #define IRP_ACTIVE 0x00000004
  90. //
  91. // This flag is used during processing Query Children to mark pre-existing
  92. // devices and notice missing ones.
  93. //
  94. #define DEVICE_FLAG_ENUMERATED 0x00000001
  95. //
  96. // This flag is used to indicate that the device represents a volume that
  97. // should be mounted by a file system.
  98. //
  99. #define DEVICE_FLAG_MOUNTABLE 0x00000002
  100. //
  101. // This flag is set when a file system has successfully been mounted on the
  102. // device.
  103. //
  104. #define DEVICE_FLAG_MOUNTED 0x00000004
  105. //
  106. // This flag is set when a device is set to act as the paging device.
  107. //
  108. #define DEVICE_FLAG_PAGING_DEVICE 0x00000008
  109. //
  110. // This flag is set when a device isn't using its boot resources, or it has
  111. // no boot resources.
  112. //
  113. #define DEVICE_FLAG_NOT_USING_BOOT_RESOURCES 0x00000010
  114. //
  115. // This flag is set when a volume is in the process of being removed.
  116. //
  117. #define VOLUME_FLAG_UNMOUNTING 0x00000001
  118. //
  119. // This flag is set in the file object if it is closing.
  120. //
  121. #define FILE_OBJECT_FLAG_CLOSING 0x00000001
  122. //
  123. // This flag is set in the file object if it failed to close.
  124. //
  125. #define FILE_OBJECT_FLAG_CLOSE_FAILED 0x00000002
  126. //
  127. // This flag is set in the file object if it has been opened.
  128. //
  129. #define FILE_OBJECT_FLAG_OPEN 0x00000004
  130. //
  131. // This flag is set in the file object if its properties are dirty.
  132. //
  133. #define FILE_OBJECT_FLAG_DIRTY_PROPERTIES 0x00000008
  134. //
  135. // This flag is set in the file object if its data should not be cached.
  136. //
  137. #define FILE_OBJECT_FLAG_NON_CACHED 0x00000010
  138. //
  139. // This flag is set if the file object gets its I/O state from elsewhere, and
  140. // should not try to free it.
  141. //
  142. #define FILE_OBJECT_FLAG_EXTERNAL_IO_STATE 0x00000020
  143. //
  144. // This flag is set if the file object has any dirty page cache entries.
  145. //
  146. #define FILE_OBJECT_FLAG_DIRTY_DATA 0x00000040
  147. //
  148. // This flag is set to indicate that the page cache eviction operation is
  149. // executing as a result of a truncate.
  150. //
  151. #define PAGE_CACHE_EVICTION_FLAG_TRUNCATE 0x00000001
  152. //
  153. // This flag is set to indicate that the page cache eviction operation is
  154. // executing as a result of a delete. There should be no outstanding references
  155. // on the device or file.
  156. //
  157. #define PAGE_CACHE_EVICTION_FLAG_DELETE 0x00000002
  158. //
  159. // This flag is set to indicate that the page cache eviction operation is
  160. // executing as a result of a remove. There may be outstanding references on
  161. // the device or file, but all of its cache entries should be aggressively
  162. // removed.
  163. //
  164. #define PAGE_CACHE_EVICTION_FLAG_REMOVE 0x00000004
  165. //
  166. // This defines the amount of time the page cache worker will delay until
  167. // executing another cleaning. This allows writes to pool.
  168. //
  169. #define PAGE_CACHE_CLEAN_DELAY_MIN (5000 * MICROSECONDS_PER_MILLISECOND)
  170. //
  171. // Define the number of pages to clean if a random write stumbles into a page
  172. // cache that is too dirty.
  173. //
  174. #define PAGE_CACHE_DIRTY_PENANCE_PAGES 128
  175. //
  176. // The resource allocation work is currently assigned to the system work queue.
  177. //
  178. #define IoResourceAllocationWorkQueue NULL
  179. //
  180. // --------------------------------------------------------------------- Macros
  181. //
  182. //
  183. // This macro sets a problem code on a device, automatically generating the
  184. // source file and line number parameters. The first parameter is a PDEVICE,
  185. // the second parameter is a DEVICE_PROBLEM, and the third parameter is a
  186. // KSTATUS.
  187. //
  188. #define IopSetDeviceProblem(_Device, _Problem, _Status) \
  189. IopSetDeviceProblemEx((_Device), \
  190. (_Problem), \
  191. (_Status), \
  192. NULL, \
  193. 0, \
  194. __FILE__, \
  195. __LINE__) \
  196. //
  197. // This macro determines whether or not the device is in a state where it is
  198. // able to accept work. The parameter should be of type PDEVICE.
  199. //
  200. #define IO_IS_DEVICE_ALIVE(_Device) \
  201. (((_Device)->State != DeviceStateInvalid) && \
  202. ((_Device)->State != DeviceUnreported) && \
  203. ((_Device)->State != DeviceRemoved))
  204. //
  205. // This macro determines whether or not the device queue is in a state to be
  206. // accepting new work. The parameter should be of type PDEVICE.
  207. //
  208. #define IO_IS_DEVICE_QUEUE_OPEN(_Device) \
  209. (((_Device)->QueueState == DeviceQueueOpen) || \
  210. ((_Device)->QueueState == DeviceQueueActive))
  211. //
  212. // This macro determines if the given path point is a mount point. This is the
  213. // case if the path entry is equal to the owning mount point's target path
  214. // entry.
  215. //
  216. #define IO_IS_MOUNT_POINT(_PathPoint) \
  217. ((_PathPoint)->PathEntry == (_PathPoint)->MountPoint->TargetEntry)
  218. //
  219. // This macro determines whether this is a cacheable file-ish object. It
  220. // excludes block and character devices.
  221. //
  222. #define IO_IS_CACHEABLE_FILE(_IoObjectType) \
  223. ((_IoObjectType == IoObjectRegularFile) || \
  224. (_IoObjectType == IoObjectSymbolicLink) || \
  225. (_IoObjectType == IoObjectSharedMemoryObject))
  226. //
  227. // This macro determines whether or not a file type is cacheable.
  228. //
  229. #define IO_IS_CACHEABLE_TYPE(_IoObjectType) \
  230. ((_IoObjectType == IoObjectBlockDevice) || \
  231. IO_IS_CACHEABLE_FILE(_IoObjectType))
  232. //
  233. // This macro determines whether or not a file object is cacheable.
  234. //
  235. #define IO_IS_FILE_OBJECT_CACHEABLE(_FileObject) \
  236. ((IO_IS_CACHEABLE_TYPE(_FileObject->Properties.Type) != FALSE) && \
  237. ((_FileObject->Flags & FILE_OBJECT_FLAG_NON_CACHED) == 0))
  238. //
  239. // ------------------------------------------------------ Data Type Definitions
  240. //
  241. typedef enum _FILE_OBJECT_TIME_TYPE {
  242. FileObjectAccessTime,
  243. FileObjectModifiedTime,
  244. FileObjectStatusTime,
  245. } FILE_OBJECT_TIME_TYPE, *PFILE_OBJECT_TIME_TYPE;
  246. typedef struct _DEVICE_POWER DEVICE_POWER, *PDEVICE_POWER;
  247. /*++
  248. Structure Description:
  249. This structure defines a file object.
  250. Members:
  251. TreeEntry - Stores the Red-Black tree node information for this file object,
  252. used internally. Never access these members directly.
  253. ListEntry - Stores an entry into the list of file objects.
  254. PageCacheEntryTree - Stores a tree root for the page cache entries that
  255. belong to this file object.
  256. ReferenceCount - Stores the memory reference count on this structure, used
  257. internally. Never manipulate this member directly.
  258. PathEntryCount - Stores the count of path entries that are using this file
  259. object. This accounts for all ways that a file object whose hard link
  260. count has gone to zero can still be accessed. If a path entry is using
  261. it, I/O can still be done on the file object.
  262. Device - Stores a pointer to the device or volume that owns the file serial
  263. number.
  264. Directory - Stores a pointer to an open handle to the file's directory,
  265. which is used to synchronize deletes, opens, and metadata updates.
  266. Lock - Stores a pointer to the lock that serializes I/O operations on
  267. this file object and child path entry lookup, creation, and insertion.
  268. IoState - Stores a pointer to the I/O object state for this file object.
  269. SpecialIo - Stores a pointer to the context needed to do I/O if this is a
  270. special object (like a pipe, terminal, socket, or shared memory object).
  271. ReadyEvent - Stores a pointer to an event that must be waited on before
  272. using this file object.
  273. ImageSectionList - Stores a pointer to a list of image setions that map
  274. portions of this file object.
  275. DeviceContext - Stores a pointer to context supplied by the device with the
  276. file was opened.
  277. Flags - Stores a set of flags describing the file object state. See
  278. FILE_OBJECT_FLAG_* for definitions. This must be modified with atomic
  279. operations.
  280. PropertiesLock - Stores a the spin lock that serializes access to this
  281. file's properties and file size.
  282. FileSize - Store the system's value for the file size. This is not always
  283. in sync with the file size stored within the properties.
  284. Properties - Stores the characteristics for this file.
  285. FileLockList - Stores the head of the list of file locks held on this
  286. file object. This is a user mode thing.
  287. FileLockEvent - Stores a pointer to the event that's signalled when a file
  288. object lock is released.
  289. --*/
  290. typedef struct _FILE_OBJECT FILE_OBJECT, *PFILE_OBJECT;
  291. struct _FILE_OBJECT {
  292. RED_BLACK_TREE_NODE TreeEntry;
  293. LIST_ENTRY ListEntry;
  294. RED_BLACK_TREE PageCacheEntryTree;
  295. volatile ULONG ReferenceCount;
  296. volatile ULONG PathEntryCount;
  297. PDEVICE Device;
  298. PSHARED_EXCLUSIVE_LOCK Lock;
  299. PIO_OBJECT_STATE IoState;
  300. PVOID SpecialIo;
  301. PKEVENT ReadyEvent;
  302. volatile PIMAGE_SECTION_LIST ImageSectionList;
  303. volatile PVOID DeviceContext;
  304. volatile ULONG Flags;
  305. KSPIN_LOCK PropertiesLock;
  306. INT64_SYNC FileSize;
  307. FILE_PROPERTIES Properties;
  308. LIST_ENTRY FileLockList;
  309. PKEVENT FileLockEvent;
  310. };
  311. /*++
  312. Structure Description:
  313. This structure defines a path entry.
  314. Members:
  315. SiblingListEntry - Stores pointers to the next and previous entries in
  316. the parent directory.
  317. CacheListEntry - Stores pointers to the next and previous entries in the
  318. LRU list of the path entry cache.
  319. ReferenceCount - Stores the reference count of the entry.
  320. MountCount - Stores the number of mount points mounted on this path entry.
  321. MountFlags - Stores a bitmaks of mount related flags that get inherited
  322. from a path entry's parent.
  323. Negative - Stores a boolean indicating that is is a negative path entry,
  324. which caches the lack of a file here.
  325. DoNotCache - Stores a boolean indicating that this path entry should not
  326. be cached.
  327. Name - Stores a pointer to the name of the path entry, allocated in paged
  328. pool.
  329. NameSize - Stores the size of the name buffer in bytes including the null
  330. terminator.
  331. Hash - Stores a hash of the name, used for quick negative comparisons.
  332. SequenceNumber - Stores a sequence number to keep track of whether or not
  333. the path entry is in sync with the underlying file object.
  334. Parent - Stores a pointer to the parent node.
  335. ChildList - Stores the list of children for this node.
  336. FileObject - Stores a pointer to the file object backing this path entry.
  337. --*/
  338. struct _PATH_ENTRY {
  339. LIST_ENTRY SiblingListEntry;
  340. LIST_ENTRY CacheListEntry;
  341. volatile ULONG ReferenceCount;
  342. volatile ULONG MountCount;
  343. BOOL Negative;
  344. BOOL DoNotCache;
  345. PSTR Name;
  346. ULONG NameSize;
  347. ULONG Hash;
  348. PPATH_ENTRY Parent;
  349. LIST_ENTRY ChildList;
  350. PFILE_OBJECT FileObject;
  351. };
  352. /*++
  353. Struction Description:
  354. This structure defines a mount point.
  355. Members:
  356. SiblingListEntry - Stores pointers to the next and previous entries in
  357. the parent mount's list of children.
  358. ChildListHead- Stores the list head for its child mount points.
  359. Parent - Stores a pointer to the parent mount point. If set to NULL, then
  360. the parent has been unmounted.
  361. MountEntry - Stores a pointer to the path entry that the mount point is
  362. mounted on.
  363. TargetEntry - Stores a pointer to the path entry that is the target path
  364. entry to traverse for this mount point.
  365. TargetPath - Store a string to the original target path specified during
  366. the mount request.
  367. ReferenceCount - Stores the reference count of the mount point.
  368. Flags - Stores a bitmask of flags for this mount point. See MOUNT_FLAG_*
  369. for definitions.
  370. --*/
  371. struct _MOUNT_POINT {
  372. LIST_ENTRY SiblingListEntry;
  373. LIST_ENTRY ChildListHead;
  374. PMOUNT_POINT Parent;
  375. PPATH_ENTRY MountEntry;
  376. PPATH_ENTRY TargetEntry;
  377. PSTR TargetPath;
  378. volatile ULONG ReferenceCount;
  379. ULONG Flags;
  380. };
  381. /*++
  382. Enumeration Description:
  383. This enumeration describes the various I/O handle types.
  384. Values:
  385. IoHandleTypeDefault - Indicates a default I/O handle.
  386. IoHandleTypePaging - Indicates a paging I/O handle.
  387. --*/
  388. typedef enum _IO_HANDLE_TYPE {
  389. IoHandleTypeDefault,
  390. IoHandleTypePaging
  391. } IO_HANDLE_TYPE, *PIO_HANDLE_TYPE;
  392. /*++
  393. Structure Description:
  394. This structure defines the context behind a generic I/O handle.
  395. Members:
  396. HandleType - Stores the type of I/O handle. All I/O handle types must begin
  397. with a member of this type.
  398. Type - Stores the type of I/O object this handle represents.
  399. OpenFlags - Stores the flags the handle was opened with.
  400. Access - Stores the access permissions for the handle.
  401. ReferenceCount - Stores the current reference count on the I/O handle.
  402. Never manipulate this value directly, use the APIs provided to add
  403. or release a reference.
  404. Device - Stores a pointer to the underlying device or object that performs
  405. the I/O.
  406. DeviceContext - Stores a context pointer supplied by the device when the
  407. handle was opened.
  408. PathPoint - Stores the path context (path entry and mount point) for the
  409. file or object.
  410. CurrentOffset - Stores the current file pointer.
  411. --*/
  412. struct _IO_HANDLE {
  413. IO_HANDLE_TYPE HandleType;
  414. ULONG OpenFlags;
  415. ULONG Access;
  416. volatile ULONG ReferenceCount;
  417. PVOID DeviceContext;
  418. PATH_POINT PathPoint;
  419. ULONGLONG CurrentOffset;
  420. };
  421. /*++
  422. Structure Description:
  423. This structure defines the stripped down basic paging I/O handle. There
  424. is no locking, no reference counting, more or less just enough information
  425. to pass requests directly to the file system or block device.
  426. Members:
  427. HandleType - Stores the type of I/O handle. All I/O handle types must begin
  428. with a member of this type.
  429. IoHandle - Stores a pointer to the normal I/O handle.
  430. Device - Stores a pointer to the device this I/O handle points to.
  431. DeviceContext - Stores the context pointer returned by the file system or
  432. device when the object was opened.
  433. Capacity - Stores the total size of the file or block device, in bytes.
  434. OffsetAlignment - Stores the required alignment of all I/O offsets.
  435. SizeAlignment - Stores the required physical alignment of all I/O buffers.
  436. --*/
  437. typedef struct _PAGING_IO_HANDLE {
  438. IO_HANDLE_TYPE HandleType;
  439. PIO_HANDLE IoHandle;
  440. PDEVICE Device;
  441. PVOID DeviceContext;
  442. ULONGLONG Capacity;
  443. ULONG OffsetAlignment;
  444. ULONG SizeAlignment;
  445. } PAGING_IO_HANDLE, *PPAGING_IO_HANDLE;
  446. /*++
  447. Structure Description:
  448. This structure defines the context used for an I/O operation.
  449. Members:
  450. IoBuffer - Stores a pointer to an I/O buffer that either contains the data
  451. to write or will contain the read data.
  452. Offset - Stores the offset from the beginning of the file or device where
  453. the I/O should be done.
  454. SizeInBytes - Stores the number of bytes to read or write.
  455. BytesCompleted - Stores the number of bytes of I/O actually performed.
  456. Flags - Stores the flags regarding the I/O operation. See IO_FLAG_*
  457. definitions.
  458. TimeoutInMilliseconds - Stores the number of milliseconds that the I/O
  459. operation should be waited on before timing out. Use
  460. WAIT_TIME_INDEFINITE to wait forever on the I/O.
  461. Write - Stores a boolean value indicating if the I/O operation is a write
  462. (TRUE) or a read (FALSE).
  463. --*/
  464. typedef struct _IO_CONTEXT {
  465. PIO_BUFFER IoBuffer;
  466. ULONGLONG Offset;
  467. UINTN SizeInBytes;
  468. UINTN BytesCompleted;
  469. ULONG Flags;
  470. ULONG TimeoutInMilliseconds;
  471. BOOL Write;
  472. } IO_CONTEXT, *PIO_CONTEXT;
  473. /*++
  474. Structure Description:
  475. This structure defines an entry in the device database, which associates
  476. devices or device classes with drivers. These structures are generally
  477. paged.
  478. Members:
  479. ListEntry - Supplies pointers to the next and previous entries in the
  480. database.
  481. DeviceId - Supplies a string containing the device ID, in the case of a
  482. device to driver association.
  483. ClassId - Supplies a string containing the class ID, in the case of a
  484. device class to driver association.
  485. DriverName - Supplies a string containing the driver associated with this
  486. device or device class.
  487. --*/
  488. typedef struct _DEVICE_DATABASE_ENTRY {
  489. LIST_ENTRY ListEntry;
  490. union {
  491. PSTR DeviceId;
  492. PSTR ClassId;
  493. } U;
  494. PSTR DriverName;
  495. } DEVICE_DATABASE_ENTRY, *PDEVICE_DATABASE_ENTRY;
  496. /*++
  497. Enumeration Description:
  498. This enumeration describes the various device actions.
  499. Values:
  500. DeviceActionInvalid - Indicates an invalid device action.
  501. DeviceActionStart - Indicates that the device should be started.
  502. DeviceActionQueryChildren - Indicates that the devices children should be
  503. queried.
  504. DeviceActionPrepareRemove - Indicates that the device should prepare for
  505. removal.
  506. DeviceActionRemove - Indicates that the device should be removed.
  507. DeviceActionPowerTransition - Indicates that the device will undergo a
  508. power state change.
  509. --*/
  510. typedef enum _DEVICE_ACTION {
  511. DeviceActionInvalid,
  512. DeviceActionStart,
  513. DeviceActionQueryChildren,
  514. DeviceActionPrepareRemove,
  515. DeviceActionRemove,
  516. DeviceActionPowerTransition
  517. } DEVICE_ACTION, *PDEVICE_ACTION;
  518. /*++
  519. Structure Description:
  520. This structure defines a unit of work on a device. A queue of these work
  521. items are queued on a per-device basis.
  522. Members:
  523. ListEntry - Stores pointers to the next and previous entries in the
  524. queue.
  525. Action - Stores the action to perform on the device.
  526. Flags - Stores properties and options for the action. See DEVICE_ACTION_*
  527. definitions.
  528. Parameter - Stores a caller-supplied parameter that has different meanings
  529. depending on the type of work requested.
  530. --*/
  531. typedef struct _DEVICE_WORK_ENTRY {
  532. LIST_ENTRY ListEntry;
  533. DEVICE_ACTION Action;
  534. ULONG Flags;
  535. PVOID Parameter;
  536. } DEVICE_WORK_ENTRY, *PDEVICE_WORK_ENTRY;
  537. /*++
  538. Structure Description:
  539. This structure defines an entry in the driver stack for a device. A device
  540. contains one or more drivers from the functional driver to various filters,
  541. with a bus driver at the bottom.
  542. Members:
  543. ListEntry - Stores pointers to the next and previous entries in the
  544. stack.
  545. Driver - Stores a pointer to the driver associated with this driver
  546. stack entry.
  547. DriverContext - Stores a pointer supplied by the driver on AddDevice.
  548. This pointer will be passed to the driver each time it is asked to
  549. operate on this device. It is typically used to store device context.
  550. Flags - Stores a set of flags associated with this stack entry. See
  551. DRIVER_STACK_* definitions.
  552. --*/
  553. typedef struct _DRIVER_STACK_ENTRY {
  554. LIST_ENTRY ListEntry;
  555. PDRIVER Driver;
  556. PVOID DriverContext;
  557. ULONG Flags;
  558. } DRIVER_STACK_ENTRY, *PDRIVER_STACK_ENTRY;
  559. typedef enum _DEVICE_STATE {
  560. DeviceStateInvalid,
  561. DeviceUnreported,
  562. DeviceInitialized,
  563. DeviceDriversAdded,
  564. DeviceResourcesQueried,
  565. DeviceResourceAssignmentQueued,
  566. DeviceResourcesAssigned,
  567. DeviceAwaitingEnumeration,
  568. DeviceEnumerated,
  569. DeviceStarted,
  570. DeviceAwaitingRemoval,
  571. DeviceRemoved
  572. } DEVICE_STATE, *PDEVICE_STATE;
  573. typedef enum _DEVICE_QUEUE_STATE {
  574. DeviceQueueInvalid,
  575. DeviceQueueOpen,
  576. DeviceQueueActive,
  577. DeviceQueueActiveClosing,
  578. DeviceQueueClosed
  579. } DEVICE_QUEUE_STATE, *PDEVICE_QUEUE_STATE;
  580. typedef enum _DEVICE_PROBLEM {
  581. DeviceProblemNone,
  582. DeviceProblemNoDrivers,
  583. DeviceProblemFailedDriverLoad,
  584. DeviceProblemNoAddDevice,
  585. DeviceProblemNoFileSystem,
  586. DeviceProblemFailedAddDevice,
  587. DeviceProblemInvalidState,
  588. DeviceProblemFailedToQueueResourceAssignmentWork,
  589. DeviceProblemFailedQueryResources,
  590. DeviceProblemResourceConflict,
  591. DeviceProblemFailedStart,
  592. DeviceProblemFailedQueryChildren,
  593. DeviceProblemFailedToQueueStart,
  594. DeviceProblemFailedToQueueQueryChildren,
  595. DeviceProblemFailedToQueuePrepareRemove,
  596. DeviceProblemFailedToQueueRemove,
  597. DeviceProblemFailedToSendRemoveIrp,
  598. DeviceProblemFailedVolumeArrival,
  599. DeviceProblemFailedVolumeRemoval,
  600. DeviceProblemFailedPathRemoval,
  601. DeviceProblemDriverError
  602. } DEVICE_PROBLEM, *PDEVICE_PROBLEM;
  603. /*++
  604. Structure Description:
  605. This structure defines a device problem state.
  606. Members:
  607. Problem - Stores a device problem code.
  608. Status - Stores the failure status associated with the device problem.
  609. DriverCode - Stores a driver-specific error code.
  610. ProblemLine - Stores the line number of the source file where the problem
  611. was set.
  612. ProblemFile - Stores a pointer to a string containing the name of the
  613. source file where the problem was set.
  614. Driver - Stores a pointer to the driver that reported the device problem.
  615. The field is NULL if the system reported the problem.
  616. --*/
  617. typedef struct _DEVICE_PROBLEM_STATE {
  618. DEVICE_PROBLEM Problem;
  619. KSTATUS Status;
  620. ULONG DriverCode;
  621. ULONG Line;
  622. PSTR File;
  623. PDRIVER Driver;
  624. } DEVICE_PROBLEM_STATE, *PDEVICE_PROBLEM_STATE;
  625. /*++
  626. Structure Description:
  627. This structure defines a device.
  628. Members:
  629. Header - Stores the object header for this device, including the device's
  630. name.
  631. ListEntry - Stores pointers to the next and previous devices in the global
  632. list.
  633. State - Stores the current state of the device.
  634. StateHistoryNextIndex - Stores the index of where the next device state
  635. should be written to. The state history is a circular buffer.
  636. StateHistory - Stores a log containing the history of the last few device
  637. states.
  638. DeviceId - Stores the numeric identifier for the device.
  639. ActiveChildList - Store the head of the list of this device's active
  640. children.
  641. ActiveListEntry - Stores the list entry for the device's place in its
  642. parent's list of active children.
  643. Lock - Stores a pointer to a shared exclusive lock that synchronizes
  644. device removal with IRPs. Lock order is always parent, then child.
  645. ParentDevice - Stores a pointer to the device that created this device, aka
  646. the device's parent. Usually this points to the parent bus. This can
  647. be NULL for unenumerable devices.
  648. TargetDevice - Stores a pointer to a device that IRPs continue through
  649. if they've not been completed by this device stack.
  650. ClassId - Stores a pointer to a string containing the class ID for the
  651. device.
  652. CompatibleIds - Stores a pointer to a string containing the compatible IDs
  653. for this device.
  654. QueueLock - Stores a pointer to a queued lock that protects the work
  655. queue's state and list.
  656. QueueState - Stores the state of the work queue, describing whether or not
  657. it is accepting new requests. Writes of this variable are protected by
  658. the QueueLock.
  659. WorkQueue - Stores the list head of the device work queue. Access to this
  660. list is protected by the QueueLock. See the DEVICE_WORK_ENTRY
  661. definition.
  662. DriverStackHead - Stores the list head for the driver stack. The Next link
  663. of this head points to the top of the driver stack (the functional
  664. driver or uppermost filter).
  665. DriverStackSize - Stores the number of drivers in the driver stack.
  666. Flags - Stores device flags. See DEVICE_FLAG_* definitions.
  667. ProblemState - Stores device problem information reported by the system or
  668. a device driver.
  669. ArbiterListHead - Stores the head of the list of arbiters this device is
  670. responsible for.
  671. ResourceRequirements - Stores a pointer to set of possible resource
  672. configurations for the device.
  673. ArbiterAllocationListHead - Stores the head of the list of allocations
  674. assigned to the device by the arbiter.
  675. SelectedConfiguration - Stores a pointer to the configuration that was
  676. selected in the device's resource configuration list.
  677. BusLocalResources - Stores a pointer to the device's committed resources, as
  678. seen from the point of view of the device itself. These
  679. are the resources that the bus driver is likely use when programming
  680. things like the device's Base Address Registers.
  681. ProcessorLocalResources - Stores a pointer to the device's committed
  682. resources, as seen from the CPU complex. These are the resources the
  683. device driver would use to communicate with the device.
  684. BootResources - Stores a pointer to the resources the BIOS assigned to the
  685. device at boot.
  686. Power - Stores the power management information for the device.
  687. --*/
  688. struct _DEVICE {
  689. OBJECT_HEADER Header;
  690. LIST_ENTRY ListEntry;
  691. DEVICE_STATE State;
  692. ULONG StateHistoryNextIndex;
  693. DEVICE_STATE StateHistory[DEVICE_STATE_HISTORY];
  694. DEVICE_ID DeviceId;
  695. LIST_ENTRY ActiveChildListHead;
  696. LIST_ENTRY ActiveListEntry;
  697. PSHARED_EXCLUSIVE_LOCK Lock;
  698. PDEVICE ParentDevice;
  699. PDEVICE TargetDevice;
  700. PSTR ClassId;
  701. PSTR CompatibleIds;
  702. PQUEUED_LOCK QueueLock;
  703. DEVICE_QUEUE_STATE QueueState;
  704. LIST_ENTRY WorkQueue;
  705. LIST_ENTRY DriverStackHead;
  706. ULONG DriverStackSize;
  707. ULONG Flags;
  708. DEVICE_PROBLEM_STATE ProblemState;
  709. LIST_ENTRY ArbiterListHead;
  710. PRESOURCE_CONFIGURATION_LIST ResourceRequirements;
  711. LIST_ENTRY ArbiterAllocationListHead;
  712. PRESOURCE_REQUIREMENT_LIST SelectedConfiguration;
  713. PRESOURCE_ALLOCATION_LIST BusLocalResources;
  714. PRESOURCE_ALLOCATION_LIST ProcessorLocalResources;
  715. PRESOURCE_ALLOCATION_LIST BootResources;
  716. PDEVICE_POWER Power;
  717. };
  718. /*++
  719. Structure Description:
  720. This structure defines a volume device.
  721. Members:
  722. Device - Stores the data required for a standard device.
  723. Flags - Stores a bitmask of volume specific flags.
  724. ReferenceCount - Stores the number of references taken on the volume. This
  725. is used to track the number of mount points that target the volume.
  726. As such, volume creation does not set a reference count of 1.
  727. PathEntry - Stores a pointer to the anonymous path entry associated with
  728. the volume.
  729. --*/
  730. struct _VOLUME {
  731. DEVICE Device;
  732. ULONG Flags;
  733. volatile ULONG ReferenceCount;
  734. PPATH_ENTRY PathEntry;
  735. };
  736. /*++
  737. Structure Description:
  738. This structure defines a driver object.
  739. Members:
  740. Image - Stores a pointer to the driver's image.
  741. FunctionTable - Stores the driver's registered function pointers.
  742. Flags - Stores various state of the driver. See DRIVER_FLAG_* definitions.
  743. --*/
  744. struct _DRIVER {
  745. PVOID Image;
  746. DRIVER_FUNCTION_TABLE FunctionTable;
  747. ULONG Flags;
  748. };
  749. typedef
  750. KSTATUS
  751. (*PFILE_OBJECT_ITERATION_ROUTINE) (
  752. PFILE_OBJECT FileObject,
  753. PVOID Context
  754. );
  755. /*++
  756. Routine Description:
  757. This routine is called once for every file object in the file object list.
  758. Arguments:
  759. FileObject - Supplies a pointer to the current file object.
  760. Context - Supplies an optional opaque pointer of context that was provided
  761. when the iteration was requested.
  762. Return Value:
  763. Status code.
  764. --*/
  765. //
  766. // -------------------------------------------------------------------- Globals
  767. //
  768. //
  769. // Store list heads to the device databases. These list entries are of type
  770. // DEVICE_DATABASE_ENTRY, and store the mappings between devices and drivers
  771. // or device classes and drivers. All memory in these databases is paged.
  772. //
  773. extern LIST_ENTRY IoDeviceDatabaseHead;
  774. extern LIST_ENTRY IoDeviceClassDatabaseHead;
  775. extern PQUEUED_LOCK IoDeviceDatabaseLock;
  776. //
  777. // Store a pointer to the device work queue.
  778. //
  779. extern PWORK_QUEUE IoDeviceWorkQueue;
  780. //
  781. // Define the object that roots the device tree.
  782. //
  783. extern PDEVICE IoRootDevice;
  784. extern LIST_ENTRY IoDeviceList;
  785. extern PQUEUED_LOCK IoDeviceListLock;
  786. //
  787. // Store the number of active work items flowing around.
  788. //
  789. extern UINTN IoDeviceWorkItemsQueued;
  790. //
  791. // Store the array of devices that were delayed until the initial enumeration
  792. // was complete.
  793. //
  794. extern PDEVICE *IoDelayedDevices;
  795. extern UINTN IoDelayedDeviceCount;
  796. //
  797. // Store a pointer to the directory of all exposed interfaces.
  798. //
  799. extern POBJECT_HEADER IoInterfaceDirectory;
  800. extern PQUEUED_LOCK IoInterfaceLock;
  801. //
  802. // Keep the list of registered file systems.
  803. //
  804. extern LIST_ENTRY IoFileSystemList;
  805. //
  806. // This lock synchronizes access to the list of file systems.
  807. //
  808. extern PQUEUED_LOCK IoFileSystemListLock;
  809. //
  810. // Store a pointer to the volumes directory and the number of volumes in the
  811. // system.
  812. //
  813. extern POBJECT_HEADER IoVolumeDirectory;
  814. //
  815. // Store a pointer to the parent object of all IRPs.
  816. //
  817. extern POBJECT_HEADER IoIrpDirectory;
  818. //
  819. // Store a pointer to the pipes directory.
  820. //
  821. extern POBJECT_HEADER IoPipeDirectory;
  822. //
  823. // Store a pointer to the shared memory object directory.
  824. //
  825. extern POBJECT_HEADER IoSharedMemoryObjectDirectory;
  826. //
  827. // Store the saved boot information.
  828. //
  829. extern IO_BOOT_INFORMATION IoBootInformation;
  830. //
  831. // Store the global I/O statistics.
  832. //
  833. extern IO_GLOBAL_STATISTICS IoGlobalStatistics;
  834. //
  835. // Store a pointer to the root path point.
  836. //
  837. extern PATH_POINT IoPathPointRoot;
  838. //
  839. // Store a pointer to the mount lock.
  840. //
  841. extern PSHARED_EXCLUSIVE_LOCK IoMountLock;
  842. //
  843. // Store the path to the system directory on the system volume.
  844. //
  845. extern PSTR IoSystemDirectoryPath;
  846. //
  847. // -------------------------------------------------------- Function Prototypes
  848. //
  849. KSTATUS
  850. IopInitializeDriver (
  851. PVOID LoadedImage
  852. );
  853. /*++
  854. Routine Description:
  855. This routine is called to initialize a newly loaded driver. This routine
  856. should only be called internally by the system.
  857. Arguments:
  858. LoadedImage - Supplies a pointer to the image associated with the driver.
  859. Return Value:
  860. Status code.
  861. --*/
  862. KSTATUS
  863. IopCreateDevice (
  864. PDRIVER BusDriver,
  865. PVOID BusDriverContext,
  866. PDEVICE ParentDevice,
  867. PSTR DeviceId,
  868. PSTR ClassId,
  869. PSTR CompatibleIds,
  870. OBJECT_TYPE DeviceType,
  871. ULONG DeviceSize,
  872. PDEVICE *NewDevice
  873. );
  874. /*++
  875. Routine Description:
  876. This routine creates a new device or volume.
  877. Arguments:
  878. BusDriver - Supplies a pointer to the driver reporting this device.
  879. BusDriverContext - Supplies the context pointer that will be passed to the
  880. bus driver when IRPs are sent to the device.
  881. ParentDevice - Supplies a pointer to the device enumerating this device.
  882. Most devices are enumerated off of a bus, so this parameter will
  883. contain a pointer to that bus device. For unenumerable devices, this
  884. parameter can be NULL, in which case the device will be enumerated off
  885. of the root device.
  886. DeviceId - Supplies a pointer to a null terminated string identifying the
  887. device. This memory does not have to be retained, a copy of it will be
  888. created during this call.
  889. ClassId - Supplies a pointer to a null terminated string identifying the
  890. device class. This memory does not have to be retained, a copy of it
  891. will be created during this call.
  892. CompatibleIds - Supplies a semicolon-delimited list of device IDs that this
  893. device is compatible with.
  894. DeviceType - Supplies the type of the new device.
  895. DeviceSize - Supplies the size of the new device's data structure.
  896. NewDevice - Supplies a pointer where the new device or volume will be
  897. returned on success.
  898. Return Value:
  899. Status code.
  900. --*/
  901. VOID
  902. IopSetDeviceState (
  903. PDEVICE Device,
  904. DEVICE_STATE NewState
  905. );
  906. /*++
  907. Routine Description:
  908. This routine sets the device to a new state.
  909. Arguments:
  910. Device - Supplies a pointer to the device whose state is to be changed.
  911. NewState - Supplies a pointer to the new device state.
  912. Return Value:
  913. None.
  914. --*/
  915. KSTATUS
  916. IopQueueDeviceWork (
  917. PDEVICE Device,
  918. DEVICE_ACTION Action,
  919. PVOID Parameter,
  920. ULONG Flags
  921. );
  922. /*++
  923. Routine Description:
  924. This routine queues work on a device.
  925. Arguments:
  926. Device - Supplies a pointer to the device to queue work on.
  927. Action - Supplies the work to be done on that device.
  928. Parameter - Supplies a parameter that accompanies the action. The meaning
  929. of this parameter changes with the type of work queued.
  930. Flags - Supplies a set of flags and options about the work.
  931. See DEVICE_ACTION_* definitions.
  932. Return Value:
  933. STATUS_SUCCESS if the request was queued on at least one device.
  934. STATUS_NO_ELIGIBLE_DEVICES if the request could not be queued because the
  935. devices are not accepting work.
  936. STATUS_INSUFFICIENT_RESOURCES if memory could not be allocated.
  937. Other error codes on other failures.
  938. --*/
  939. VOID
  940. IopHandleDeviceQueueFailure (
  941. PDEVICE Device,
  942. DEVICE_ACTION Action
  943. );
  944. /*++
  945. Routine Description:
  946. This routine handles a failure to add a work item to a device queue.
  947. Arguments:
  948. Device - Supplies a pointer to the device that could not accept the action.
  949. Action - Supplies the action that failed to be added to the given device's
  950. work queue.
  951. Return Value:
  952. None.
  953. --*/
  954. VOID
  955. IopSetDeviceProblemEx (
  956. PDEVICE Device,
  957. DEVICE_PROBLEM Problem,
  958. KSTATUS Status,
  959. PDRIVER Driver,
  960. ULONG DriverCode,
  961. PSTR SourceFile,
  962. ULONG LineNumber
  963. );
  964. /*++
  965. Routine Description:
  966. This routine sets a device problem code on a given device. This problem is
  967. usually preventing a device from starting or otherwise making forward
  968. progress. Avoid calling this function directly, use the non-Ex version.
  969. Arguments:
  970. Device - Supplies a pointer to the device with the problem.
  971. Problem - Supplies the problem with the device.
  972. Status - Supplies the failure status generated by the error.
  973. Driver - Supplies a pointer to the driver reporting the error. This
  974. parameter is optional.
  975. DriverCode - Supplies an optional problem driver-specific error code.
  976. SourceFile - Supplies a pointer to the source file where the problem
  977. occurred. This is usually automatically generated by the compiler.
  978. LineNumber - Supplies the line number in the source file where the problem
  979. occurred. This is usually automatically generated by the compiler.
  980. Return Value:
  981. None.
  982. --*/
  983. VOID
  984. IopClearDeviceProblem (
  985. PDEVICE Device
  986. );
  987. /*++
  988. Routine Description:
  989. This routine clears any problem code associated with a device.
  990. Arguments:
  991. Device - Supplies a pointer to the device whose problem code should be
  992. cleared.
  993. Return Value:
  994. None.
  995. --*/
  996. VOID
  997. IopPrepareRemoveDevice (
  998. PDEVICE Device,
  999. PDEVICE_WORK_ENTRY Work
  1000. );
  1001. /*++
  1002. Routine Description:
  1003. This routine prepares a device for removal. It puts the device in the
  1004. awaiting removal state. If it has no children, it queues the removal work
  1005. item on itself. If this routine discovers that the device is already in the
  1006. awaiting removal state, it exits.
  1007. Arguments:
  1008. Device - Supplies a pointer to the device that is preparing to be removed.
  1009. Work - Supplies a pointer to the work request.
  1010. Return Value:
  1011. None.
  1012. --*/
  1013. VOID
  1014. IopRemoveDevice (
  1015. PDEVICE Device,
  1016. PDEVICE_WORK_ENTRY Work
  1017. );
  1018. /*++
  1019. Routine Description:
  1020. This routine removes a device by sending a removal IRP and then removing
  1021. the device reference added during device creation. The removal IRP allows
  1022. the driver to clean up any necessary state that cannot be cleaned up by the
  1023. object manager's destruction call-back.
  1024. Arguments:
  1025. Device - Supplies a pointer to the device that is to be removed.
  1026. Work - Supplies a pointer to the work request.
  1027. Return Value:
  1028. None.
  1029. --*/
  1030. VOID
  1031. IopAbortDeviceRemoval (
  1032. PDEVICE Device,
  1033. DEVICE_PROBLEM DeviceProblem,
  1034. BOOL RollbackDevice
  1035. );
  1036. /*++
  1037. Routine Description:
  1038. This routine aborts the device removal process for the given device. It
  1039. also walks back up the device tree reverting the removal process for any
  1040. ancestor devices that were awaiting the given device's removal.
  1041. Arguments:
  1042. Device - Supplies a pointer to the device that failed the removal process
  1043. and requires rollback.
  1044. DeviceProblem - Supplies the devices problem (i.e. the reason for the
  1045. abort).
  1046. RollbackDevice - Supplies a boolean indicating whether or not the supplied
  1047. device should be included in the rollback.
  1048. Return Value:
  1049. None.
  1050. --*/
  1051. VOID
  1052. IopDestroyDevice (
  1053. PVOID Object
  1054. );
  1055. /*++
  1056. Routine Description:
  1057. This routine destroys a device and its resources. The object manager will
  1058. clean up the object header, leaving this routine to clean up the device
  1059. specific elements of the object. This routine is meant only as a callback
  1060. for the object manager.
  1061. Arguments:
  1062. Object - Supplies a pointer to the object to be destroyed.
  1063. Return Value:
  1064. None.
  1065. --*/
  1066. DEVICE_ID
  1067. IopGetNextDeviceId (
  1068. VOID
  1069. );
  1070. /*++
  1071. Routine Description:
  1072. This routine allocates and returns a device ID.
  1073. Arguments:
  1074. None.
  1075. Return Value:
  1076. Returns a unique device ID number.
  1077. --*/
  1078. VOID
  1079. IopInitializeDeviceInformationSupport (
  1080. VOID
  1081. );
  1082. /*++
  1083. Routine Description:
  1084. This routine initializes device information support.
  1085. Arguments:
  1086. None.
  1087. Return Value:
  1088. None.
  1089. --*/
  1090. KSTATUS
  1091. IopAddFileSystem (
  1092. PDEVICE Device
  1093. );
  1094. /*++
  1095. Routine Description:
  1096. This routine adds a file system to the given volume.
  1097. Arguments:
  1098. Device - Supplies a pointer to the volume to attach a file system to.
  1099. Return Value:
  1100. Status code.
  1101. --*/
  1102. KSTATUS
  1103. IopCreateOrLookupVolume (
  1104. PDEVICE Device,
  1105. PVOLUME *Volume
  1106. );
  1107. /*++
  1108. Routine Description:
  1109. This routine returns the volume associated with the given device, if such
  1110. a volume exists. A reference is taken on the volume, which the caller is
  1111. expected to release.
  1112. Arguments:
  1113. Device - Supplies a pointer to the device whose volume is to be returned.
  1114. Volume - Supplies a pointer that receives a pointer to the created or found
  1115. volume.
  1116. Return Value:
  1117. Status code.
  1118. --*/
  1119. VOID
  1120. IopVolumeArrival (
  1121. PVOID Parameter
  1122. );
  1123. /*++
  1124. Routine Description:
  1125. This routine performs work associated with a new volume coming online.
  1126. Arguments:
  1127. Parameter - Supplies a pointer to the arriving volume.
  1128. Return Value:
  1129. None.
  1130. --*/
  1131. KSTATUS
  1132. IopRemoveDevicePaths (
  1133. PDEVICE Device
  1134. );
  1135. /*++
  1136. Routine Description:
  1137. This routine takes the device's paths offline.
  1138. Arguments:
  1139. Device - Supplies a pointer to the departing device.
  1140. Return Value:
  1141. Status code.
  1142. --*/
  1143. KSTATUS
  1144. IopInitializeMountPointSupport (
  1145. VOID
  1146. );
  1147. /*++
  1148. Routine Description:
  1149. This routine initializes the support for mount points.
  1150. Arguments:
  1151. None.
  1152. Return Value:
  1153. Status code.
  1154. --*/
  1155. KSTATUS
  1156. IopGetSetMountPointInformation (
  1157. PVOID Data,
  1158. PUINTN DataSize,
  1159. BOOL Set
  1160. );
  1161. /*++
  1162. Routine Description:
  1163. This routine gets or sets mount point information.
  1164. Arguments:
  1165. Data - Supplies a pointer to the data buffer where the data is either
  1166. returned for a get operation or given for a set operation.
  1167. DataSize - Supplies a pointer that on input contains the size of the
  1168. data buffer. On output, contains the required size of the data buffer.
  1169. Set - Supplies a boolean indicating if this is a get operation (FALSE) or
  1170. a set operation (TRUE).
  1171. Return Value:
  1172. Status code.
  1173. --*/
  1174. VOID
  1175. IopRemoveMountPoints (
  1176. PPATH_POINT RootPath
  1177. );
  1178. /*++
  1179. Routine Description:
  1180. This routine lazily unmounts all the mount points that exist under the
  1181. given root path point, including itself.
  1182. Arguments:
  1183. RootPath - Supplies a pointer to the root path point, under which all
  1184. mount points will be removed.
  1185. Return Value:
  1186. None.
  1187. --*/
  1188. PMOUNT_POINT
  1189. IopFindMountPoint (
  1190. PMOUNT_POINT Parent,
  1191. PPATH_ENTRY PathEntry
  1192. );
  1193. /*++
  1194. Routine Description:
  1195. This routine searches for a child mount point of the given parent whose
  1196. mount path entry matches the given path entry. If found, a reference is
  1197. taken on the returned mount point.
  1198. Arguments:
  1199. Parent - Supplies a pointer to a parent mount point whose children are
  1200. searched for a mount point that matches the path entry.
  1201. PathEntry - Supplies a pointer to a path entry to search for.
  1202. Return Value:
  1203. Returns a pointer to the found mount point on success, or NULL on failure.
  1204. --*/
  1205. PMOUNT_POINT
  1206. IopGetMountPointParent (
  1207. PMOUNT_POINT MountPoint
  1208. );
  1209. /*++
  1210. Routine Description:
  1211. This routine gets a mount point's parent. The parent can disappear at any
  1212. moment with a lazy unmount, so this routine acquires the mount lock in
  1213. shared mode to check the parent.
  1214. Arguments:
  1215. MountPoint - Supplies a pointer to a mount point.
  1216. Return Value:
  1217. Returns a pointer to the parent mount point on success, or NULL otherwise.
  1218. --*/
  1219. KSTATUS
  1220. IopOpen (
  1221. BOOL FromKernelMode,
  1222. PIO_HANDLE Directory,
  1223. PSTR Path,
  1224. ULONG PathLength,
  1225. ULONG Access,
  1226. ULONG Flags,
  1227. IO_OBJECT_TYPE TypeOverride,
  1228. PVOID OverrideParameter,
  1229. FILE_PERMISSIONS CreatePermissions,
  1230. PIO_HANDLE *Handle
  1231. );
  1232. /*++
  1233. Routine Description:
  1234. This routine opens a file, device, pipe, or other I/O object.
  1235. Arguments:
  1236. FromKernelMode - Supplies a boolean indicating the request is coming from
  1237. kernel mode.
  1238. Directory - Supplies an optional pointer to a handle to a directory to use
  1239. if the given path is relative. Supply NULL to use the current working
  1240. directory.
  1241. Path - Supplies a pointer to the path to open.
  1242. PathLength - Supplies the length of the path buffer in bytes, including the
  1243. null terminator.
  1244. Access - Supplies the desired access permissions to the object. See
  1245. IO_ACCESS_* definitions.
  1246. Flags - Supplies a bitfield of flags governing the behavior of the handle.
  1247. See OPEN_FLAG_* definitions.
  1248. TypeOverride - Supplies an object type that the regular file should be
  1249. converted to. Supply the invalid object type to specify no override.
  1250. OverrideParameter - Supplies an optional parameter to send along with the
  1251. override type.
  1252. CreatePermissions - Supplies the permissions to apply for created object
  1253. on create operations.
  1254. Handle - Supplies a pointer where a pointer to the open I/O handle will be
  1255. returned on success.
  1256. Return Value:
  1257. Status code.
  1258. --*/
  1259. KSTATUS
  1260. IopOpenPathPoint (
  1261. PPATH_POINT PathPoint,
  1262. ULONG Access,
  1263. ULONG Flags,
  1264. PIO_HANDLE *Handle
  1265. );
  1266. /*++
  1267. Routine Description:
  1268. This routine opens a path point object. This routine must be called
  1269. carefully by internal functions, as it skips all permission checks.
  1270. Arguments:
  1271. PathPoint - Supplies a pointer to the path point to open. Upon success this
  1272. routine will add a reference to the path point's path entry and mount
  1273. point.
  1274. Access - Supplies the desired access permissions to the object. See
  1275. IO_ACCESS_* definitions.
  1276. Flags - Supplies a bitfield of flags governing the behavior of the handle.
  1277. See OPEN_FLAG_* definitions.
  1278. Handle - Supplies a pointer where a pointer to the open I/O handle will be
  1279. returned on success.
  1280. Return Value:
  1281. Status code.
  1282. --*/
  1283. KSTATUS
  1284. IopOpenDevice (
  1285. PDEVICE Device,
  1286. ULONG Access,
  1287. ULONG Flags,
  1288. PIO_HANDLE *Handle
  1289. );
  1290. /*++
  1291. Routine Description:
  1292. This routine opens a device or volume.
  1293. Arguments:
  1294. Device - Supplies a pointer to a device to open.
  1295. Access - Supplies the desired access permissions to the object. See
  1296. IO_ACCESS_* definitions.
  1297. Flags - Supplies a bitfield of flags governing the behavior of the handle.
  1298. See OPEN_FLAG_* definitions.
  1299. Handle - Supplies a pointer where a pointer to the open I/O handle will be
  1300. returned on success.
  1301. Return Value:
  1302. Status code.
  1303. --*/
  1304. KSTATUS
  1305. IopCreateSpecialIoObject (
  1306. ULONG Flags,
  1307. IO_OBJECT_TYPE Type,
  1308. PVOID OverrideParameter,
  1309. FILE_PERMISSIONS CreatePermissions,
  1310. PFILE_OBJECT *FileObject
  1311. );
  1312. /*++
  1313. Routine Description:
  1314. This routine creates a special file object.
  1315. Arguments:
  1316. Type - Supplies the type of special object to create.
  1317. Flags - Supplies a bitfield of flags governing the behavior of the handle.
  1318. See OPEN_FLAG_* definitions.
  1319. OverrideParameter - Supplies an optional parameter to send along with the
  1320. override type.
  1321. CreatePermissions - Supplies the permissions to assign to the new file.
  1322. FileObject - Supplies a pointer where a pointer to the new file object
  1323. will be returned on success.
  1324. Return Value:
  1325. Status code.
  1326. --*/
  1327. KSTATUS
  1328. IopClose (
  1329. PIO_HANDLE IoHandle
  1330. );
  1331. /*++
  1332. Routine Description:
  1333. This routine shuts down an I/O handle that is about to be destroyed.
  1334. Arguments:
  1335. IoHandle - Supplies a pointer to the I/O handle returned when the file was
  1336. opened.
  1337. Return Value:
  1338. Status code.
  1339. --*/
  1340. KSTATUS
  1341. IopDelete (
  1342. BOOL FromKernelMode,
  1343. PIO_HANDLE Directory,
  1344. PSTR Path,
  1345. ULONG PathSize,
  1346. ULONG Flags
  1347. );
  1348. /*++
  1349. Routine Description:
  1350. This routine attempts to delete the object at the given path. If the path
  1351. points to a directory, the directory must be empty. If the path points to
  1352. a file object or shared memory object, its hard link count is decremented.
  1353. If the hard link count reaches zero and no processes have the object open,
  1354. the contents of the object are destroyed. If processes have open handles to
  1355. the object, the destruction of the object contents are deferred until the
  1356. last handle to the old file is closed. If the path points to a symbolic
  1357. link, the link itself is removed and not the destination. The removal of
  1358. the entry from the directory is immediate.
  1359. Arguments:
  1360. FromKernelMode - Supplies a boolean indicating the request is coming from
  1361. kernel mode.
  1362. Directory - Supplies an optional pointer to an open handle to a directory
  1363. for relative paths. Supply NULL to use the current working directory.
  1364. Path - Supplies a pointer to the path to delete.
  1365. PathSize - Supplies the length of the path buffer in bytes, including the
  1366. null terminator.
  1367. Flags - Supplies a bitfield of flags. See DELETE_FLAG_* definitions.
  1368. Return Value:
  1369. Status code.
  1370. --*/
  1371. KSTATUS
  1372. IopDeleteByHandle (
  1373. BOOL FromKernelMode,
  1374. PIO_HANDLE Handle,
  1375. ULONG Flags
  1376. );
  1377. /*++
  1378. Routine Description:
  1379. This routine attempts to delete the the object open by the given I/O
  1380. handle. This does not close or invalidate the handle, but it does attempt
  1381. to unlink the object so future path walks will not find it at that location.
  1382. Arguments:
  1383. FromKernelMode - Supplies a boolean indicating the request is coming from
  1384. kernel mode.
  1385. Handle - Supplies the open handle to the device.
  1386. Flags - Supplies a bitfield of flags. See DELETE_FLAG_* definitions.
  1387. Return Value:
  1388. Status code.
  1389. --*/
  1390. KSTATUS
  1391. IopDeletePathPoint (
  1392. BOOL FromKernelMode,
  1393. PPATH_POINT PathPoint,
  1394. ULONG Flags
  1395. );
  1396. /*++
  1397. Routine Description:
  1398. This routine attempts to delete the object at the given path. If the path
  1399. points to a directory, the directory must be empty. If the path point is
  1400. a file object or shared memory object, its hard link count is decremented.
  1401. If the hard link count reaches zero and no processes have the object open,
  1402. the contents of the object are destroyed. If processes have open handles to
  1403. the object, the destruction of the object contents are deferred until the
  1404. last handle to the old file is closed.
  1405. Arguments:
  1406. FromKernelMode - Supplies a boolean indicating the request is coming from
  1407. kernel mode.
  1408. PathPoint - Supplies a pointer to the path point to delete. The caller
  1409. should already have a reference on this path point, which will need to
  1410. be released by the caller when finished.
  1411. Flags - Supplies a bitfield of flags. See DELETE_FLAG_* definitions.
  1412. Return Value:
  1413. Status code.
  1414. --*/
  1415. KSTATUS
  1416. IopSendFileOperationIrp (
  1417. IRP_MINOR_CODE MinorCode,
  1418. PFILE_OBJECT FileObject,
  1419. PVOID DeviceContext,
  1420. ULONG Flags
  1421. );
  1422. /*++
  1423. Routine Description:
  1424. This routine sends a file operation IRP.
  1425. Arguments:
  1426. MinorCode - Supplies the minor code of the IRP to send.
  1427. FileObject - Supplies a pointer to the file object of the file being
  1428. operated on.
  1429. DeviceContext - Supplies a pointer to the device context to send down.
  1430. Flags - Supplies a bitmask of I/O flags. See IO_FLAG_* for definitions.
  1431. Return Value:
  1432. Status code.
  1433. --*/
  1434. KSTATUS
  1435. IopSendLookupRequest (
  1436. PDEVICE Device,
  1437. PFILE_OBJECT Directory,
  1438. PSTR FileName,
  1439. ULONG FileNameSize,
  1440. PFILE_PROPERTIES Properties
  1441. );
  1442. /*++
  1443. Routine Description:
  1444. This routine sends a lookup request IRP.
  1445. Arguments:
  1446. Device - Supplies a pointer to the device to send the request to.
  1447. Directory - Supplies a pointer to the file object of the directory to
  1448. search in.
  1449. FileName - Supplies a pointer to the name of the file, which may not be
  1450. null terminated.
  1451. FileNameSize - Supplies the size of the file name buffer including space
  1452. for a null terminator (which may be a null terminator or may be a
  1453. garbage character).
  1454. Properties - Supplies a pointer where the file properties will be returned
  1455. if the file was found.
  1456. Return Value:
  1457. Status code.
  1458. --*/
  1459. KSTATUS
  1460. IopSendRootLookupRequest (
  1461. PDEVICE Device,
  1462. PFILE_PROPERTIES Properties,
  1463. PULONG Flags
  1464. );
  1465. /*++
  1466. Routine Description:
  1467. This routine sends a lookup request IRP for the device's root.
  1468. Arguments:
  1469. Device - Supplies a pointer to the device to send the request to.
  1470. Properties - Supplies the file properties if the file was found.
  1471. Flags - Supplies a pointer that receives the flags returned by the root
  1472. lookup call. See LOOKUP_FLAG_* for definitions.
  1473. Return Value:
  1474. Status code.
  1475. --*/
  1476. KSTATUS
  1477. IopSendCreateRequest (
  1478. PDEVICE Device,
  1479. PFILE_OBJECT Directory,
  1480. PSTR Name,
  1481. ULONG NameSize,
  1482. PFILE_PROPERTIES Properties
  1483. );
  1484. /*++
  1485. Routine Description:
  1486. This routine sends a creation request to the device.
  1487. Arguments:
  1488. Device - Supplies a pointer to the device to send the request to.
  1489. Directory - Supplies a pointer to the file object of the directory to
  1490. create the file in.
  1491. Name - Supplies a pointer to the name of the file or directory to create,
  1492. which may not be null terminated.
  1493. NameSize - Supplies the size of the name buffer including space for a null
  1494. terminator (which may be a null terminator or may be a garbage
  1495. character).
  1496. Properties - Supplies a pointer to the file properties of the created file
  1497. on success. The permissions, object type, user ID, group ID, and access
  1498. times are all valid from the system.
  1499. Return Value:
  1500. Status code.
  1501. --*/
  1502. KSTATUS
  1503. IopSendUnlinkRequest (
  1504. PDEVICE Device,
  1505. PFILE_OBJECT FileObject,
  1506. PFILE_OBJECT DirectoryObject,
  1507. PSTR Name,
  1508. ULONG NameSize,
  1509. PBOOL Unlinked
  1510. );
  1511. /*++
  1512. Routine Description:
  1513. This routine sends an unlink request to the device. This routine assumes
  1514. that the directory's lock is held exclusively.
  1515. Arguments:
  1516. Device - Supplies a pointer to the device to send the request to.
  1517. FileObject - Supplies a pointer to the file object of the file that is to
  1518. be unlinked.
  1519. DirectoryObject - Supplies a pointer to the file object of the directory
  1520. from which the file will be unlinked.
  1521. Name - Supplies a pointer to the name of the file or directory to create,
  1522. which may not be null terminated.
  1523. NameSize - Supplies the size of the name buffer including space for a null
  1524. terminator (which may be a null terminator or may be a garbage
  1525. character).
  1526. Unlinked - Supplies a boolean that receives whether or not the file was
  1527. unlinked. The file may be unlinked even if the call fails.
  1528. Return Value:
  1529. Status code.
  1530. --*/
  1531. KSTATUS
  1532. IopPerformCacheableIoOperation (
  1533. PIO_HANDLE Handle,
  1534. PIO_CONTEXT IoContext
  1535. );
  1536. /*++
  1537. Routine Description:
  1538. This routine reads from or writes to the given handle. The I/O object type
  1539. of the given handle must be cacheable.
  1540. Arguments:
  1541. Handle - Supplies a pointer to the I/O handle.
  1542. IoContext - Supplies a pointer to the I/O context.
  1543. Return Value:
  1544. Status code. A failing status code does not necessarily mean no I/O made it
  1545. in or out. Check the bytes completed value in the I/O context to find out
  1546. how much occurred.
  1547. --*/
  1548. KSTATUS
  1549. IopPerformNonCachedRead (
  1550. PFILE_OBJECT FileObject,
  1551. PIO_CONTEXT IoContext,
  1552. PVOID DeviceContext
  1553. );
  1554. /*++
  1555. Routine Description:
  1556. This routine performs a non-cached read from a cacheable file object. It is
  1557. assumed that the file lock is held.
  1558. Arguments:
  1559. FileObject - Supplies a pointer to a cacheable file object.
  1560. IoContext - Supplies a pointer to the I/O context.
  1561. DeviceContext - Supplies a pointer to the device context to use when
  1562. writing to the backing device.
  1563. Return Value:
  1564. Status code.
  1565. --*/
  1566. KSTATUS
  1567. IopPerformNonCachedWrite (
  1568. PFILE_OBJECT FileObject,
  1569. PIO_CONTEXT IoContext,
  1570. PVOID DeviceContext,
  1571. BOOL UpdateFileSize
  1572. );
  1573. /*++
  1574. Routine Description:
  1575. This routine performs a non-cached write to a cacheable file object. It is
  1576. assumed that the file lock is held. This routine will always modify the
  1577. file size in the the file properties and conditionally modify the file size
  1578. in the file object.
  1579. Arguments:
  1580. FileObject - Supplies a pointer to the file object for the device or file.
  1581. IoContext - Supplies a pointer to the I/O context.
  1582. DeviceContext - Supplies a pointer to the device context to use when
  1583. writing to the backing device.
  1584. UpdateFileSize - Supplies a boolean indicating whether or not this routine
  1585. should update the file size in the file object. Only the page cache
  1586. code should supply FALSE.
  1587. Return Value:
  1588. Status code.
  1589. --*/
  1590. KSTATUS
  1591. IopPerformObjectIoOperation (
  1592. PIO_HANDLE IoHandle,
  1593. PIO_CONTEXT IoContext
  1594. );
  1595. /*++
  1596. Routine Description:
  1597. This routine reads from an object directory.
  1598. Arguments:
  1599. IoHandle - Supplies a pointer to the I/O handle.
  1600. IoContext - Supplies a pointer to the I/O context.
  1601. Return Value:
  1602. Status code. A failing status code does not necessarily mean no I/O made it
  1603. in or out. Check the bytes completed value in the I/O context to find out
  1604. how much occurred.
  1605. --*/
  1606. KSTATUS
  1607. IopCreateIoHandle (
  1608. PIO_HANDLE *Handle
  1609. );
  1610. /*++
  1611. Routine Description:
  1612. This routine creates a new I/O handle with a reference count of one.
  1613. Arguments:
  1614. Handle - Supplies a pointer where a pointer to the new I/O handle will be
  1615. returned on success.
  1616. Return Value:
  1617. Status code.
  1618. --*/
  1619. KSTATUS
  1620. IopInitializeFileObjectSupport (
  1621. VOID
  1622. );
  1623. /*++
  1624. Routine Description:
  1625. This routine performs global initialization for file object support.
  1626. Arguments:
  1627. None.
  1628. Return Value:
  1629. Status code.
  1630. --*/
  1631. KSTATUS
  1632. IopCreateOrLookupFileObject (
  1633. PFILE_PROPERTIES Properties,
  1634. PDEVICE Device,
  1635. ULONG Flags,
  1636. PFILE_OBJECT *FileObject,
  1637. PBOOL ObjectCreated
  1638. );
  1639. /*++
  1640. Routine Description:
  1641. This routine attempts to look up a file object with the given properties
  1642. (specifically the I-Node number and volume). If one does not exist, it
  1643. is created and inserted in the global list. If a special file object is
  1644. created, the ready event is left unsignaled so the remainder of the state
  1645. can be created.
  1646. Arguments:
  1647. Properties - Supplies a pointer to the file object properties.
  1648. Device - Supplies a pointer to the device that owns the file serial number.
  1649. This may also be a volume or an object directory.
  1650. Flags - Supplies a bitmask of file object flags. See FILE_OBJECT_FLAG_* for
  1651. definitions.
  1652. FileObject - Supplies a pointer where the file object will be returned on
  1653. success.
  1654. ObjectCreated - Supplies a pointer where a boolean will be returned
  1655. indicating whether or not the object was just created. If it was just
  1656. created, the caller is responsible for signaling the ready event when
  1657. the object is fully set up.
  1658. Return Value:
  1659. Status code.
  1660. --*/
  1661. ULONG
  1662. IopFileObjectAddReference (
  1663. PFILE_OBJECT Object
  1664. );
  1665. /*++
  1666. Routine Description:
  1667. This routine increments the reference count on a file object.
  1668. Arguments:
  1669. Object - Supplies a pointer to the object to retain.
  1670. Return Value:
  1671. Returns the reference count before the addition.
  1672. --*/
  1673. KSTATUS
  1674. IopFileObjectReleaseReference (
  1675. PFILE_OBJECT Object
  1676. );
  1677. /*++
  1678. Routine Description:
  1679. This routine decrements the reference count on a file object. If the
  1680. reference count hits zero, then the file object will be destroyed.
  1681. Arguments:
  1682. Object - Supplies a pointer to the object to release.
  1683. FailIfLastReference - Supplies a boolean that if set causes the reference
  1684. count not to be decremented if this would involve releasing the very
  1685. last reference on the file object. Callers that set this flag must be
  1686. able to take responsibility for the reference they continue to own in
  1687. the failure case. Set this to FALSE.
  1688. Return Value:
  1689. STATUS_SUCCESS on success.
  1690. Other error codes on failure to write out the file properties to the file
  1691. system or device.
  1692. --*/
  1693. VOID
  1694. IopFileObjectAddPathEntryReference (
  1695. PFILE_OBJECT FileObject
  1696. );
  1697. /*++
  1698. Routine Description:
  1699. This routine increments the path entry reference count on a file object.
  1700. Arguments:
  1701. FileObject - Supplies a pointer to a file object.
  1702. Return Value:
  1703. None.
  1704. --*/
  1705. VOID
  1706. IopFileObjectReleasePathEntryReference (
  1707. PFILE_OBJECT FileObject
  1708. );
  1709. /*++
  1710. Routine Description:
  1711. This routine decrements the path entry reference count on a file object.
  1712. Arguments:
  1713. FileObject - Supplies a pointer to a file object.
  1714. Return Value:
  1715. None.
  1716. --*/
  1717. KSTATUS
  1718. IopFlushFileObject (
  1719. PFILE_OBJECT FileObject,
  1720. ULONGLONG Offset,
  1721. ULONGLONG Size,
  1722. ULONG Flags,
  1723. PUINTN PageCount
  1724. );
  1725. /*++
  1726. Routine Description:
  1727. This routine flushes all file object data to the next lowest cache layer.
  1728. If the flags request synchronized I/O, then all file data and meta-data
  1729. will be flushed to the backing media.
  1730. Arguments:
  1731. FileObject - Supplies a pointer to a file object for the device or file.
  1732. Offset - Supplies the offset from the beginning of the file or device where
  1733. the flush should be done.
  1734. Size - Supplies the size, in bytes, of the region to flush. Supply a value
  1735. of -1 to flush from the given offset to the end of the file.
  1736. Flags - Supplies a bitmask of I/O flags. See IO_FLAG_* for definitions.
  1737. PageCount - Supplies an optional pointer describing how many pages to flush.
  1738. On output this value will be decreased by the number of pages actually
  1739. flushed. Supply NULL to flush all pages in the size range.
  1740. Return Value:
  1741. Status code.
  1742. --*/
  1743. KSTATUS
  1744. IopFlushFileObjects (
  1745. DEVICE_ID DeviceId,
  1746. ULONG Flags,
  1747. PUINTN PageCount
  1748. );
  1749. /*++
  1750. Routine Description:
  1751. This routine iterates over file objects in the global dirty file objects
  1752. list, flushing each one that belongs to the given device or to all entries
  1753. if a device ID of 0 is specified.
  1754. Arguments:
  1755. DeviceId - Supplies an optional device ID filter. Supply 0 to iterate over
  1756. dirty file objects for all devices.
  1757. Flags - Supplies a bitmask of I/O flags. See IO_FLAG_* for definitions.
  1758. PageCount - Supplies an optional pointer describing how many pages to flush.
  1759. On output this value will be decreased by the number of pages actually
  1760. flushed. Supply NULL to flush all pages.
  1761. Return Value:
  1762. STATUS_SUCCESS if all file object were successfully iterated.
  1763. STATUS_TRY_AGAIN if the iteration quit early for some reason (i.e. the page
  1764. cache was found to be too dirty when flushing file objects).
  1765. Other status codes for other errors.
  1766. --*/
  1767. VOID
  1768. IopEvictFileObjects (
  1769. DEVICE_ID DeviceId,
  1770. ULONG Flags
  1771. );
  1772. /*++
  1773. Routine Description:
  1774. This routine iterates over all file objects evicting page cache entries for
  1775. each one that belongs to the given device.
  1776. Arguments:
  1777. DeviceId - Supplies an optional device ID filter. Supply 0 to iterate over
  1778. file objects for all devices.
  1779. Flags - Supplies a bitmask of eviction flags. See
  1780. PAGE_CACHE_EVICTION_FLAG_* for definitions.
  1781. Return Value:
  1782. None.
  1783. --*/
  1784. KSTATUS
  1785. IopFlushAllFileObjectsProperties (
  1786. BOOL StopIfTooDirty
  1787. );
  1788. /*++
  1789. Routine Description:
  1790. This routine flushes all dirty file object properties.
  1791. Arguments:
  1792. StopIfTooDirty - Supplies a boolean that if set indicates this routine
  1793. should stop flushing file object properties if the page cache is too
  1794. dirty.
  1795. Return Value:
  1796. STATUS_SUCCESS if all file object properties were successfully flushed, or
  1797. the device ID was zero.
  1798. STATUS_TRY_AGAIN if the page cache became too dirty and the function quit
  1799. early.
  1800. Other status codes for other errors.
  1801. --*/
  1802. KSTATUS
  1803. IopFlushFileObjectPropertiesByDevice (
  1804. DEVICE_ID DeviceId,
  1805. BOOL StopIfTooDirty
  1806. );
  1807. /*++
  1808. Routine Description:
  1809. This routine flushes the file properties for all the file objects that
  1810. belong to a given device. If no device ID is specified, it flushes the file
  1811. objects for all devices.
  1812. Arguments:
  1813. DeviceId - Supplies the ID of the device whose file objects' properties are
  1814. to be flushed.
  1815. StopIfTooDirty - Supplies a boolean that if set indicates this routine
  1816. should stop flushing file object properties if the page cache is too
  1817. dirty.
  1818. Return Value:
  1819. STATUS_SUCCESS if all file object properties were successfully flushed, or
  1820. the device ID was zero.
  1821. STATUS_TRY_AGAIN if the page cache became too dirty and the function quit
  1822. early.
  1823. --*/
  1824. VOID
  1825. IopUpdateFileObjectTime (
  1826. PFILE_OBJECT FileObject,
  1827. FILE_OBJECT_TIME_TYPE TimeType
  1828. );
  1829. /*++
  1830. Routine Description:
  1831. This routine updates the given file object's access and modified times. The
  1832. latter is only updated upon request.
  1833. Arguments:
  1834. FileObject - Supplies a pointer to a file object.
  1835. TimeType - Supplies the type of time to update. Updating modified time also
  1836. updates status change time.
  1837. Return Value:
  1838. None.
  1839. --*/
  1840. VOID
  1841. IopUpdateFileObjectFileSize (
  1842. PFILE_OBJECT FileObject,
  1843. ULONGLONG NewSize,
  1844. BOOL UpdateFileObject,
  1845. BOOL UpdateProperties
  1846. );
  1847. /*++
  1848. Routine Description:
  1849. This routine decides whether or not to update the file size based on the
  1850. supplied size. This routine will never decrease the file size. It is not
  1851. intended to change the file size, just to update the size based on changes
  1852. that other parts of the system have already completed. Use
  1853. IopModifyFileObjectSize to actually change the size (e.g. truncate).
  1854. Arguments:
  1855. FileObject - Supplies a pointer to a file object.
  1856. NewSize - Supplies the new file size.
  1857. UpdateFileObject - Supplies a boolean indicating whether or not to update
  1858. the file size that is in the file object.
  1859. UpdateProperties - Supplies a boolean indicating whether or not to update
  1860. the file size that is within the file properties.
  1861. Return Value:
  1862. None.
  1863. --*/
  1864. KSTATUS
  1865. IopModifyFileObjectSize (
  1866. PFILE_OBJECT FileObject,
  1867. PVOID DeviceContext,
  1868. ULONGLONG NewFileSize
  1869. );
  1870. /*++
  1871. Routine Description:
  1872. This routine modifies the given file object's size. It will either increase
  1873. or decrease the file size. If the size is decreased then the file object's
  1874. driver will be notified, any existing page cache entries for the file will
  1875. be evicted and any image sections that map the file will be unmapped.
  1876. Arguments:
  1877. FileObject - Supplies a pointer to the file object whose size will be
  1878. modified.
  1879. DeviceContext - Supplies an optional pointer to the device context to use
  1880. when doing file operations. Not every file object has a built-in device
  1881. context.
  1882. NewFileSize - Supplies the desired new size of the file object.
  1883. Return Value:
  1884. Status code.
  1885. --*/
  1886. VOID
  1887. IopFileObjectIncrementHardLinkCount (
  1888. PFILE_OBJECT FileObject
  1889. );
  1890. /*++
  1891. Routine Description:
  1892. This routine decrements the hard link count for a file object.
  1893. Arguments:
  1894. FileObject - Supplies a pointer to a file object.
  1895. Return Value:
  1896. None.
  1897. --*/
  1898. VOID
  1899. IopFileObjectDecrementHardLinkCount (
  1900. PFILE_OBJECT FileObject
  1901. );
  1902. /*++
  1903. Routine Description:
  1904. This routine decrements the hard link count for a file object.
  1905. Arguments:
  1906. FileObject - Supplies a pointer to a file object.
  1907. Return Value:
  1908. None.
  1909. --*/
  1910. VOID
  1911. IopCleanupFileObjects (
  1912. VOID
  1913. );
  1914. /*++
  1915. Routine Description:
  1916. This routine releases any lingering file objects that were left around as a
  1917. result of I/O failures during the orignal release attempt.
  1918. Arguments:
  1919. None.
  1920. Return Value:
  1921. None.
  1922. --*/
  1923. VOID
  1924. IopAcquireFileObjectLocksExclusive (
  1925. PFILE_OBJECT Object1,
  1926. PFILE_OBJECT Object2
  1927. );
  1928. /*++
  1929. Routine Description:
  1930. This routine acquires two file object locks exclusive in the right order.
  1931. The order is to sort first by file object type, then by file object pointer.
  1932. Arguments:
  1933. Object1 - Supplies a pointer to the first file object.
  1934. Object2 - Supplies a pointer to the second file object.
  1935. Return Value:
  1936. None.
  1937. --*/
  1938. PIMAGE_SECTION_LIST
  1939. IopGetImageSectionListFromFileObject (
  1940. PFILE_OBJECT FileObject
  1941. );
  1942. /*++
  1943. Routine Description:
  1944. This routine gets the image section for the given file object.
  1945. Arguments:
  1946. FileObject - Supplies a pointer to a file object.
  1947. Return Value:
  1948. Returns a pointer to the file object's image section list or NULL on
  1949. failure.
  1950. --*/
  1951. VOID
  1952. IopMarkFileObjectDirty (
  1953. PFILE_OBJECT FileObject
  1954. );
  1955. /*++
  1956. Routine Description:
  1957. This routine marks the given file object as dirty, moving it to the list of
  1958. dirty file objects if it is not already on a list.
  1959. Arguments:
  1960. FileObject - Supplies a pointer to the dirty file object.
  1961. Return Value:
  1962. None.
  1963. --*/
  1964. VOID
  1965. IopMarkFileObjectPropertiesDirty (
  1966. PFILE_OBJECT FileObject
  1967. );
  1968. /*++
  1969. Routine Description:
  1970. This routine marks that the given file object's properties are dirty.
  1971. Arguments:
  1972. FileObject - Supplies a pointer to the file object whose properties are
  1973. dirty.
  1974. Return Value:
  1975. None.
  1976. --*/
  1977. POBJECT_HEADER
  1978. IopGetPipeDirectory (
  1979. VOID
  1980. );
  1981. /*++
  1982. Routine Description:
  1983. This routine returns the pipe root directory in the object system. This is
  1984. the only place in the object system pipe creation is allowed.
  1985. Arguments:
  1986. None.
  1987. Return Value:
  1988. Returns a pointer to the pipe directory.
  1989. --*/
  1990. KSTATUS
  1991. IopCreatePipe (
  1992. PSTR Name,
  1993. ULONG NameSize,
  1994. FILE_PERMISSIONS Permissions,
  1995. PFILE_OBJECT *FileObject
  1996. );
  1997. /*++
  1998. Routine Description:
  1999. This routine actually creates a new pipe.
  2000. Arguments:
  2001. Name - Supplies an optional pointer to the pipe name. This is only used for
  2002. named pipes created in the pipe directory.
  2003. NameSize - Supplies the size of the name in bytes including the null
  2004. terminator.
  2005. Permissions - Supplies the permissions to give to the file object.
  2006. FileObject - Supplies a pointer where a pointer to a newly created pipe
  2007. file object will be returned on success.
  2008. Return Value:
  2009. Status code.
  2010. --*/
  2011. KSTATUS
  2012. IopUnlinkPipe (
  2013. PFILE_OBJECT FileObject,
  2014. PBOOL Unlinked
  2015. );
  2016. /*++
  2017. Routine Description:
  2018. This routine unlinks a pipe from the accessible namespace.
  2019. Arguments:
  2020. FileObject - Supplies a pointer to the pipe's file object.
  2021. Unlinked - Supplies a pointer to a boolean that receives whether or not the
  2022. terminal was successfully unlinked.
  2023. Return Value:
  2024. Status code.
  2025. --*/
  2026. KSTATUS
  2027. IopOpenPipe (
  2028. PIO_HANDLE IoHandle
  2029. );
  2030. /*++
  2031. Routine Description:
  2032. This routine is called when a pipe is opened.
  2033. Arguments:
  2034. IoHandle - Supplies a pointer to the new I/O handle.
  2035. Return Value:
  2036. Status code.
  2037. --*/
  2038. KSTATUS
  2039. IopClosePipe (
  2040. PIO_HANDLE IoHandle
  2041. );
  2042. /*++
  2043. Routine Description:
  2044. This routine is called when a pipe is closed.
  2045. Arguments:
  2046. IoHandle - Supplies a pointer to the I/O handle being closed.
  2047. Return Value:
  2048. Status code.
  2049. --*/
  2050. KSTATUS
  2051. IopPerformPipeIoOperation (
  2052. PIO_HANDLE Handle,
  2053. PIO_CONTEXT IoContext
  2054. );
  2055. /*++
  2056. Routine Description:
  2057. This routine reads from or writes to a pipe.
  2058. Arguments:
  2059. Handle - Supplies a pointer to the pipe I/O handle.
  2060. IoContext - Supplies a pointer to the I/O context.
  2061. Return Value:
  2062. Status code. A failing status code does not necessarily mean no I/O made it
  2063. in or out. Check the bytes completed value in the I/O context to find out
  2064. how much occurred.
  2065. --*/
  2066. KSTATUS
  2067. IopInitializeTerminalSupport (
  2068. VOID
  2069. );
  2070. /*++
  2071. Routine Description:
  2072. This routine is called during system initialization to set up support for
  2073. terminals.
  2074. Arguments:
  2075. None.
  2076. Return Value:
  2077. Status code.
  2078. --*/
  2079. KSTATUS
  2080. IopTerminalOpenMaster (
  2081. PIO_HANDLE IoHandle
  2082. );
  2083. /*++
  2084. Routine Description:
  2085. This routine is called when a master terminal was just opened.
  2086. Arguments:
  2087. IoHandle - Supplies a pointer to the I/O handle for the terminal.
  2088. Return Value:
  2089. Status code.
  2090. --*/
  2091. KSTATUS
  2092. IopTerminalCloseMaster (
  2093. PIO_HANDLE IoHandle
  2094. );
  2095. /*++
  2096. Routine Description:
  2097. This routine is called when a master terminal was just closed.
  2098. Arguments:
  2099. IoHandle - Supplies a pointer to the handle to close.
  2100. Return Value:
  2101. Status code.
  2102. --*/
  2103. KSTATUS
  2104. IopTerminalOpenSlave (
  2105. PIO_HANDLE IoHandle
  2106. );
  2107. /*++
  2108. Routine Description:
  2109. This routine opens the slave side of a terminal object.
  2110. Arguments:
  2111. IoHandle - Supplies a pointer to the I/O handle for the terminal.
  2112. Return Value:
  2113. Status code.
  2114. --*/
  2115. KSTATUS
  2116. IopTerminalCloseSlave (
  2117. PIO_HANDLE IoHandle
  2118. );
  2119. /*++
  2120. Routine Description:
  2121. This routine is called when a master terminal was just closed.
  2122. Arguments:
  2123. IoHandle - Supplies a pointer to the handle to close.
  2124. Return Value:
  2125. Status code.
  2126. --*/
  2127. KSTATUS
  2128. IopPerformTerminalMasterIoOperation (
  2129. PIO_HANDLE Handle,
  2130. PIO_CONTEXT IoContext
  2131. );
  2132. /*++
  2133. Routine Description:
  2134. This routine reads from or writes to the master end of a terminal.
  2135. Arguments:
  2136. Handle - Supplies a pointer to the master terminal I/O handle.
  2137. IoContext - Supplies a pointer to the I/O context.
  2138. Return Value:
  2139. Status code. A failing status code does not necessarily mean no I/O made it
  2140. in or out. Check the bytes completed value in the I/O context to find out
  2141. how much occurred.
  2142. --*/
  2143. KSTATUS
  2144. IopPerformTerminalSlaveIoOperation (
  2145. PIO_HANDLE Handle,
  2146. PIO_CONTEXT IoContext
  2147. );
  2148. /*++
  2149. Routine Description:
  2150. This routine reads from or writes to the slave end of a terminal.
  2151. Arguments:
  2152. Handle - Supplies a pointer to the slave terminal I/O handle.
  2153. IoContext - Supplies a pointer to the I/O context.
  2154. Return Value:
  2155. Status code. A failing status code does not necessarily mean no I/O made it
  2156. in or out. Check the bytes completed value in the I/O context to find out
  2157. how much occurred.
  2158. --*/
  2159. KSTATUS
  2160. IopCreateTerminal (
  2161. IO_OBJECT_TYPE Type,
  2162. PVOID OverrideParameter,
  2163. FILE_PERMISSIONS CreatePermissions,
  2164. PFILE_OBJECT *FileObject
  2165. );
  2166. /*++
  2167. Routine Description:
  2168. This routine creates a terminal master or slave.
  2169. Arguments:
  2170. Type - Supplies the type of special object to create.
  2171. OverrideParameter - Supplies an optional parameter to send along with the
  2172. override type.
  2173. CreatePermissions - Supplies the permissions to assign to the new file.
  2174. FileObject - Supplies a pointer where a pointer to the new file object
  2175. will be returned on success.
  2176. Return Value:
  2177. Status code.
  2178. --*/
  2179. KSTATUS
  2180. IopUnlinkTerminal (
  2181. PFILE_OBJECT FileObject,
  2182. PBOOL Unlinked
  2183. );
  2184. /*++
  2185. Routine Description:
  2186. This routine unlinks a terminal from the accessible namespace.
  2187. Arguments:
  2188. FileObject - Supplies a pointer to the terminal's file object.
  2189. Unlinked - Supplies a pointer to a boolean that receives whether or not the
  2190. terminal was successfully unlinked.
  2191. Return Value:
  2192. Status code.
  2193. --*/
  2194. KSTATUS
  2195. IopTerminalUserControl (
  2196. PIO_HANDLE Handle,
  2197. TERMINAL_USER_CONTROL_CODE CodeNumber,
  2198. BOOL FromKernelMode,
  2199. PVOID ContextBuffer,
  2200. UINTN ContextBufferSize
  2201. );
  2202. /*++
  2203. Routine Description:
  2204. This routine handles user control requests destined for a terminal object.
  2205. Arguments:
  2206. Handle - Supplies the open file handle.
  2207. CodeNumber - Supplies the minor code of the request.
  2208. FromKernelMode - Supplies a boolean indicating whether or not this request
  2209. (and the buffer associated with it) originates from user mode (FALSE)
  2210. or kernel mode (TRUE).
  2211. ContextBuffer - Supplies a pointer to the context buffer allocated by the
  2212. caller for the request.
  2213. ContextBufferSize - Supplies the size of the supplied context buffer.
  2214. Return Value:
  2215. Status code.
  2216. --*/
  2217. KSTATUS
  2218. IopTerminalFlush (
  2219. PFILE_OBJECT FileObject,
  2220. ULONG Flags
  2221. );
  2222. /*++
  2223. Routine Description:
  2224. This routine flushes a terminal object, discarding unwritten and unread
  2225. data.
  2226. Arguments:
  2227. FileObject - Supplies a pointer to the terminal to flush.
  2228. Flags - Supplies the flags governing the flush operation. See FLUSH_FLAG_*
  2229. definitions.
  2230. Return Value:
  2231. Status code.
  2232. --*/
  2233. KSTATUS
  2234. IopCreateSocket (
  2235. PVOID Parameter,
  2236. FILE_PERMISSIONS CreatePermissions,
  2237. PFILE_OBJECT *FileObject
  2238. );
  2239. /*++
  2240. Routine Description:
  2241. This routine allocates resources associated with a new socket.
  2242. Arguments:
  2243. Parameter - Supplies the parameters the socket was created with.
  2244. CreatePermissions - Supplies the permissions to create the file with.
  2245. FileObject - Supplies a pointer where the new file object representing the
  2246. socket will be returned on success.
  2247. Return Value:
  2248. Status code.
  2249. --*/
  2250. KSTATUS
  2251. IopPerformSocketIoOperation (
  2252. PIO_HANDLE Handle,
  2253. PIO_CONTEXT IoContext
  2254. );
  2255. /*++
  2256. Routine Description:
  2257. This routine reads from or writes to a socket.
  2258. Arguments:
  2259. Handle - Supplies a pointer to the socket I/O handle.
  2260. IoContext - Supplies a pointer to the I/O context.
  2261. Return Value:
  2262. Status code. A failing status code does not necessarily mean no I/O made it
  2263. in or out. Check the bytes completed value in the I/O context to find out
  2264. how much occurred.
  2265. --*/
  2266. KSTATUS
  2267. IopOpenSocket (
  2268. PIO_HANDLE IoHandle
  2269. );
  2270. /*++
  2271. Routine Description:
  2272. This routine opens a socket connection.
  2273. Arguments:
  2274. IoHandle - Supplies a pointer to the I/O handle for the socket being opened.
  2275. Return Value:
  2276. Status code.
  2277. --*/
  2278. KSTATUS
  2279. IopCloseSocket (
  2280. PIO_HANDLE IoHandle
  2281. );
  2282. /*++
  2283. Routine Description:
  2284. This routine closes a socket connection.
  2285. Arguments:
  2286. IoHandle - Supplies a pointer to the socket handle to close.
  2287. Return Value:
  2288. Status code.
  2289. --*/
  2290. KSTATUS
  2291. IopOpenSharedMemoryObject (
  2292. PSTR Path,
  2293. ULONG PathLength,
  2294. ULONG Access,
  2295. ULONG Flags,
  2296. FILE_PERMISSIONS CreatePermissions,
  2297. PIO_HANDLE *Handle
  2298. );
  2299. /*++
  2300. Routine Description:
  2301. This routine opens a shared memory objeect.
  2302. Arguments:
  2303. Path - Supplies a pointer to the path to open.
  2304. PathLength - Supplies the length of the path buffer in bytes, including the
  2305. null terminator.
  2306. Access - Supplies the desired access permissions to the object. See
  2307. IO_ACCESS_* definitions.
  2308. Flags - Supplies a bitfield of flags governing the behavior of the handle.
  2309. See OPEN_FLAG_* definitions.
  2310. CreatePermissions - Supplies the permissions to apply for a created file.
  2311. Handle - Supplies a pointer where a pointer to the open I/O handle will be
  2312. returned on success.
  2313. Return Value:
  2314. Status code.
  2315. --*/
  2316. KSTATUS
  2317. IopDeleteSharedMemoryObject (
  2318. PSTR Path,
  2319. ULONG PathLength
  2320. );
  2321. /*++
  2322. Routine Description:
  2323. This routine deletes a shared memory object. It does not handle deletion of
  2324. unnamed anonymous shared memory objects.
  2325. Arguments:
  2326. Path - Supplies a pointer to the path of the shared memory object within
  2327. the shared memory object namespace.
  2328. PathLength - Supplies the length of the path, in bytes, including the null
  2329. terminator.
  2330. Return Value:
  2331. Status code.
  2332. --*/
  2333. POBJECT_HEADER
  2334. IopGetSharedMemoryObjectDirectory (
  2335. VOID
  2336. );
  2337. /*++
  2338. Routine Description:
  2339. This routine returns the shared memory objects' root directory in the
  2340. object manager's system. This is the only place in the object system
  2341. shared memory object creation is allowed.
  2342. Arguments:
  2343. None.
  2344. Return Value:
  2345. Returns a pointer to the shared memory object directory.
  2346. --*/
  2347. KSTATUS
  2348. IopCreateSharedMemoryObject (
  2349. PSTR Name,
  2350. ULONG NameSize,
  2351. ULONG Flags,
  2352. FILE_PERMISSIONS Permissions,
  2353. PFILE_OBJECT *FileObject
  2354. );
  2355. /*++
  2356. Routine Description:
  2357. This routine actually creates a new shared memory object.
  2358. Arguments:
  2359. Name - Supplies an optional pointer to the shared memory object name. This
  2360. is only used for shared memory objects created in the shared memory
  2361. directory.
  2362. NameSize - Supplies the size of the name in bytes including the null
  2363. terminator.
  2364. Flags - Supplies a bitfield of flags governing the behavior of the handle.
  2365. See OPEN_FLAG_* definitions.
  2366. Permissions - Supplies the permissions to give to the file object.
  2367. FileObject - Supplies a pointer where a pointer to a newly created pipe
  2368. file object will be returned on success.
  2369. Return Value:
  2370. Status code.
  2371. --*/
  2372. KSTATUS
  2373. IopTruncateSharedMemoryObject (
  2374. PFILE_OBJECT FileObject
  2375. );
  2376. /*++
  2377. Routine Description:
  2378. This routine truncates a shared memory object.
  2379. Arguments:
  2380. FileObject - Supplies a pointer to a shared memory object.
  2381. Return Value:
  2382. Status code.
  2383. --*/
  2384. KSTATUS
  2385. IopUnlinkSharedMemoryObject (
  2386. PFILE_OBJECT FileObject,
  2387. PBOOL Unlinked
  2388. );
  2389. /*++
  2390. Routine Description:
  2391. This routine unlinks a shared memory object from the accessible namespace.
  2392. Arguments:
  2393. FileObject - Supplies a pointer to the file object that owns the shared
  2394. memory object.
  2395. Unlinked - Supplies a pointer to a boolean that receives whether or not the
  2396. shared memory object was successfully unlinked.
  2397. Return Value:
  2398. Status code.
  2399. --*/
  2400. KSTATUS
  2401. IopPerformSharedMemoryIoOperation (
  2402. PFILE_OBJECT FileObject,
  2403. PIO_CONTEXT IoContext,
  2404. BOOL UpdateFileSize
  2405. );
  2406. /*++
  2407. Routine Description:
  2408. This routine performs a non-cached I/O operation on a shared memory object.
  2409. It is assumed that the file lock is held. This routine will always modify
  2410. the file size in the the file properties and conditionally modify the file
  2411. size in the file object.
  2412. Arguments:
  2413. FileObject - Supplies a pointer to the file object for the device or file.
  2414. IoContext - Supplies a pointer to the I/O context.
  2415. UpdateFileSize - Supplies a boolean indicating whether or not this routine
  2416. should update the file size in the file object. Only the page cache
  2417. code should supply FALSE.
  2418. Return Value:
  2419. Status code.
  2420. --*/
  2421. KSTATUS
  2422. IopInitializePathSupport (
  2423. VOID
  2424. );
  2425. /*++
  2426. Routine Description:
  2427. This routine is called at system initialization time to initialize support
  2428. for path traversal. It connects the root of the object manager to the root
  2429. of the path system.
  2430. Arguments:
  2431. None.
  2432. Return Value:
  2433. Status code.
  2434. --*/
  2435. KSTATUS
  2436. IopPathWalk (
  2437. BOOL FromKernelMode,
  2438. PPATH_POINT Directory,
  2439. PSTR *Path,
  2440. PULONG PathSize,
  2441. ULONG OpenFlags,
  2442. IO_OBJECT_TYPE TypeOverride,
  2443. PVOID OverrideParameter,
  2444. FILE_PERMISSIONS CreatePermissions,
  2445. PPATH_POINT Result
  2446. );
  2447. /*++
  2448. Routine Description:
  2449. This routine attempts to walk the given path.
  2450. Arguments:
  2451. FromKernelMode - Supplies a boolean indicating whether or not this request
  2452. is coming directly from kernel mode (and should use the kernel's root).
  2453. Directory - Supplies an optional pointer to a path point containing the
  2454. directory to start from if the path is relative. Supply NULL to use the
  2455. current working directory.
  2456. Path - Supplies a pointer that on input contains a pointer to the string
  2457. of the path to walk. This pointer will be advanced beyond the portion
  2458. of the path that was successfully walked.
  2459. PathSize - Supplies a pointer that on input contains the size of the
  2460. input path string in bytes. This value will be updated to reflect the
  2461. new size of the updated path string.
  2462. OpenFlags - Supplies a bitfield of flags governing the behavior of the
  2463. handle. See OPEN_FLAG_* definitions.
  2464. TypeOverride - Supplies the type of object to create. If this is invalid,
  2465. then this routine will try to open an existing object. If this type is
  2466. valid, then this routine will attempt to create an object of the given
  2467. type.
  2468. OverrideParameter - Supplies an optional parameter to send along with the
  2469. override type.
  2470. CreatePermissions - Supplies the permissions to assign to a created file.
  2471. Result - Supplies a pointer to a path point that receives the resulting
  2472. path entry and mount point on success. The path entry and mount point
  2473. will come with an extra reference on them, so the caller must be sure
  2474. to release the references when finished.
  2475. Return Value:
  2476. Status code.
  2477. --*/
  2478. VOID
  2479. IopFillOutFilePropertiesForObject (
  2480. PFILE_PROPERTIES Properties,
  2481. POBJECT_HEADER Object
  2482. );
  2483. /*++
  2484. Routine Description:
  2485. This routine fills out the file properties structure for an object manager
  2486. object.
  2487. Arguments:
  2488. Properties - Supplies a pointer to the file properties.
  2489. Object - Supplies a pointer to the object.
  2490. Return Value:
  2491. TRUE if the paths are equals.
  2492. FALSE if the paths differ in some way.
  2493. --*/
  2494. PPATH_ENTRY
  2495. IopCreateAnonymousPathEntry (
  2496. PFILE_OBJECT FileObject
  2497. );
  2498. /*++
  2499. Routine Description:
  2500. This routine creates a new path entry structure that is not connected to
  2501. the global path tree.
  2502. Arguments:
  2503. FileObject - Supplies a pointer to the file object backing this entry. This
  2504. routine takes ownership of an assumed reference on the file object.
  2505. Return Value:
  2506. Returns a pointer to the path entry on success.
  2507. NULL on allocation failure.
  2508. --*/
  2509. KSTATUS
  2510. IopPathSplit (
  2511. PSTR Path,
  2512. ULONG PathSize,
  2513. PSTR *DirectoryComponent,
  2514. PULONG DirectoryComponentSize,
  2515. PSTR *LastComponent,
  2516. PULONG LastComponentSize
  2517. );
  2518. /*++
  2519. Routine Description:
  2520. This routine creates a new string containing the last component of the
  2521. given path.
  2522. Arguments:
  2523. Path - Supplies a pointer to the null terminated path string.
  2524. PathSize - Supplies the size of the path string in bytes including the
  2525. null terminator.
  2526. DirectoryComponent - Supplies a pointer where a newly allocated string
  2527. containing only the directory component will be returned on success.
  2528. The caller is responsible for freeing this memory from paged pool.
  2529. DirectoryComponentSize - Supplies a pointer where the size of the directory
  2530. component buffer in bytes including the null terminator will be
  2531. returned.
  2532. LastComponent - Supplies a pointer where a newly allocated string
  2533. containing only the last component will be returned on success. The
  2534. caller is responsible for freeing this memory from paged pool.
  2535. LastComponentSize - Supplies a pointer where the size of the last component
  2536. buffer in bytes including the null terminator will be returned.
  2537. Return Value:
  2538. Status code.
  2539. --*/
  2540. PPATH_ENTRY
  2541. IopCreatePathEntry (
  2542. PSTR Name,
  2543. ULONG NameSize,
  2544. ULONG Hash,
  2545. PPATH_ENTRY Parent,
  2546. PFILE_OBJECT FileObject
  2547. );
  2548. /*++
  2549. Routine Description:
  2550. This routine creates a new path entry structure.
  2551. Arguments:
  2552. Name - Supplies an optional pointer to the name to give this path entry. A
  2553. copy of this name will be made.
  2554. NameSize - Supplies the size of the name buffer in bytes including the
  2555. null terminator.
  2556. Hash - Supplies the hash of the name string.
  2557. Parent - Supplies a pointer to the parent of this entry.
  2558. FileObject - Supplies an optional pointer to the file object backing this
  2559. entry. This routine takes ownership of an assumed reference on the file
  2560. object.
  2561. Return Value:
  2562. Returns a pointer to the path entry on success.
  2563. NULL on allocation failure.
  2564. --*/
  2565. BOOL
  2566. IopIsDescendantPath (
  2567. PPATH_ENTRY Ancestor,
  2568. PPATH_ENTRY DescendantEntry
  2569. );
  2570. /*++
  2571. Routine Description:
  2572. This routine determines whether or not the given descendant path entry is a
  2573. descendent of the given path entry. This does not take mount points into
  2574. account.
  2575. Arguments:
  2576. Ancestor - Supplies a pointer to the possible ancestor path entry.
  2577. DescendantEntry - Supplies a pointer to the possible descendant path entry.
  2578. Return Value:
  2579. Returns TRUE if it is a descendant, or FALSE otherwise.
  2580. --*/
  2581. VOID
  2582. IopPathUnlink (
  2583. PPATH_ENTRY Entry
  2584. );
  2585. /*++
  2586. Routine Description:
  2587. This routine unlinks the given path entry from the path hierarchy. This
  2588. assumes the caller hold both the path entry's file object lock (if it
  2589. exists) and the parent path entry's file object lock exclusively.
  2590. Arguments:
  2591. Entry - Supplies a pointer to the path entry that is to be unlinked from
  2592. the path hierarchy.
  2593. Return Value:
  2594. None.
  2595. --*/
  2596. KSTATUS
  2597. IopGetPathFromRoot (
  2598. PPATH_POINT Entry,
  2599. PPATH_POINT Root,
  2600. PSTR *Path,
  2601. PULONG PathSize
  2602. );
  2603. /*++
  2604. Routine Description:
  2605. This routine creates a string representing the path from the given root to
  2606. the given entry. If the entry is not a descendent of the given root, then
  2607. the full path is printed.
  2608. Arguments:
  2609. Entry - Supplies a pointer to the path point where to stop the string.
  2610. Root - Supplies a optional pointer to the path point to treat as root.
  2611. Path - Supplies a pointer that receives the full path string.
  2612. PathSize - Supplies a pointer that receives the size of the full path
  2613. string, in bytes.
  2614. Return Value:
  2615. Status code.
  2616. --*/
  2617. KSTATUS
  2618. IopGetPathFromRootUnlocked (
  2619. PPATH_POINT Entry,
  2620. PPATH_POINT Root,
  2621. PSTR *Path,
  2622. PULONG PathSize
  2623. );
  2624. /*++
  2625. Routine Description:
  2626. This routine creates a string representing the path from the given root to
  2627. the given entry. If the entry is not a descendent of the given root, then
  2628. the full path is printed. This routine assumes that the mount lock is held
  2629. in shared mode.
  2630. Arguments:
  2631. Entry - Supplies a pointer to the path point where to stop the string.
  2632. Root - Supplies a optional pointer to the path point to treat as root.
  2633. Path - Supplies a pointer that receives the full path string.
  2634. PathSize - Supplies a pointer that receives the size of the full path
  2635. string, in bytes.
  2636. Return Value:
  2637. Status code.
  2638. --*/
  2639. KSTATUS
  2640. IopPathLookup (
  2641. BOOL FromKernelMode,
  2642. PPATH_POINT Root,
  2643. PPATH_POINT Directory,
  2644. BOOL DirectoryLockHeld,
  2645. PSTR Name,
  2646. ULONG NameSize,
  2647. ULONG OpenFlags,
  2648. IO_OBJECT_TYPE TypeOverride,
  2649. PVOID OverrideParameter,
  2650. FILE_PERMISSIONS CreatePermissions,
  2651. PPATH_POINT Result
  2652. );
  2653. /*++
  2654. Routine Description:
  2655. This routine attempts to look up a child with the given name in a directory.
  2656. Arguments:
  2657. FromKernelMode - Supplies a boolean indicating whether this request is
  2658. originating from kernel mode (TRUE) or user mode (FALSE). Kernel mode
  2659. requests are not subjected to permission checks.
  2660. Root - Supplies a pointer to the caller's root path point.
  2661. Directory - Supplies a pointer to the path point to search.
  2662. DirectoryLockHeld - Supplies a boolean indicating whether or not the caller
  2663. had already acquired the directory's lock (exclusively).
  2664. Name - Supplies a pointer to the name string.
  2665. NameSize - Supplies a pointer to the size of the string in bytes
  2666. including an assumed null terminator.
  2667. OpenFlags - Supplies a bitfield of flags governing the behavior of the
  2668. handle. See OPEN_FLAG_* definitions.
  2669. TypeOverride - Supplies the type of object to create. If this is invalid,
  2670. then this routine will try to open an existing object. If this type is
  2671. valid, then this routine will attempt to create an object of the given
  2672. type.
  2673. OverrideParameter - Supplies an optional parameter to send along with the
  2674. override type.
  2675. CreatePermissions - Supplies the permissions to assign to a created file.
  2676. Result - Supplies a pointer to a path point that receives the resulting
  2677. path entry and mount point on success. The path entry and mount point
  2678. will come with an extra reference on them, so the caller must be sure
  2679. to release the references when finished. This routine may return a
  2680. path entry even on failing status codes, such as a negative path entry.
  2681. Return Value:
  2682. Status code.
  2683. --*/
  2684. KSTATUS
  2685. IopPathLookupUnlocked (
  2686. PPATH_POINT Root,
  2687. PPATH_POINT Directory,
  2688. BOOL DirectoryLockHeld,
  2689. PSTR Name,
  2690. ULONG NameSize,
  2691. ULONG OpenFlags,
  2692. IO_OBJECT_TYPE TypeOverride,
  2693. PVOID OverrideParameter,
  2694. FILE_PERMISSIONS CreatePermissions,
  2695. PPATH_POINT Result
  2696. );
  2697. /*++
  2698. Routine Description:
  2699. This routine attempts to look up a child with the given name in a directory
  2700. without acquiring the mount lock in shared mode.
  2701. Arguments:
  2702. Root - Supplies a pointer to the caller's root path point.
  2703. Directory - Supplies a pointer to the path point to search.
  2704. DirectoryLockHeld - Supplies a boolean indicating whether or not the caller
  2705. had already acquired the directory's lock (exclusively).
  2706. Name - Supplies a pointer to the name string.
  2707. NameSize - Supplies a pointer to the size of the string in bytes
  2708. including an assumed null terminator.
  2709. OpenFlags - Supplies a bitfield of flags governing the behavior of the
  2710. handle. See OPEN_FLAG_* definitions.
  2711. TypeOverride - Supplies the type of object to create. If this is invalid,
  2712. then this routine will try to open an existing object. If this type is
  2713. valid, then this routine will attempt to create an object of the given
  2714. type.
  2715. OverrideParameter - Supplies an optional parameter to send along with the
  2716. override type.
  2717. CreatePermissions - Supplies the permissions to assign to a created file.
  2718. Result - Supplies a pointer to a path point that receives the resulting
  2719. path entry and mount point on success. The path entry and mount point
  2720. will come with an extra reference on them, so the caller must be sure
  2721. to release this references when finished. This routine may return a
  2722. path entry even on failing status codes, such as a negative path entry.
  2723. Return Value:
  2724. Status code.
  2725. --*/
  2726. VOID
  2727. IopPathCleanCache (
  2728. PPATH_ENTRY RootPath
  2729. );
  2730. /*++
  2731. Routine Description:
  2732. This routine attempts to destroy any cached path entries below the given
  2733. root path.
  2734. Arguments:
  2735. RootPath - Supplies a pointer to the root path entry.
  2736. DoNotCache - Supplies a boolean indicating whether or not to mark open
  2737. path entries as non-cacheable or not.
  2738. Return Value:
  2739. None.
  2740. --*/
  2741. VOID
  2742. IopPathEntryIncrementMountCount (
  2743. PPATH_ENTRY PathEntry
  2744. );
  2745. /*++
  2746. Routine Description:
  2747. This routine increments the mount count for the given path entry.
  2748. Arguments:
  2749. PathEntry - Supplies a pointer to a path entry.
  2750. Return Value:
  2751. None.
  2752. --*/
  2753. VOID
  2754. IopPathEntryDecrementMountCount (
  2755. PPATH_ENTRY PathEntry
  2756. );
  2757. /*++
  2758. Routine Description:
  2759. This routine decrements the mount count for the given path entry.
  2760. Arguments:
  2761. PathEntry - Supplies a pointer to a path entry.
  2762. Return Value:
  2763. None.
  2764. --*/
  2765. VOID
  2766. IopGetParentPathPoint (
  2767. PPATH_POINT Root,
  2768. PPATH_POINT PathPoint,
  2769. PPATH_POINT ParentPathPoint
  2770. );
  2771. /*++
  2772. Routine Description:
  2773. This routine gets the parent path point of the given path point, correctly
  2774. traversing mount points. This routine takes references on the parent path
  2775. point's path entry and mount point.
  2776. Arguments:
  2777. Root - Supplies an optional pointer to the caller's path point root. If
  2778. supplied, then the parent will never be lower in the path tree than
  2779. the root.
  2780. PathPoint - Supplies a pointer to the path point whose parent is being
  2781. queried.
  2782. ParentPathPoint - Supplies a pointer to a path point that receives the
  2783. parent path point's information.
  2784. Return Value:
  2785. None.
  2786. --*/
  2787. KSTATUS
  2788. IopCheckPermissions (
  2789. BOOL FromKernelMode,
  2790. PPATH_POINT PathPoint,
  2791. ULONG Access
  2792. );
  2793. /*++
  2794. Routine Description:
  2795. This routine performs a permission check for the current user at the given
  2796. path point.
  2797. Arguments:
  2798. FromKernelMode - Supplies a boolean indicating whether the request actually
  2799. originates from kernel mode or not.
  2800. PathPoint - Supplies a pointer to the path point to check.
  2801. Access - Supplies the desired access the user needs.
  2802. Return Value:
  2803. STATUS_SUCCESS if the user has permission to access the given object in
  2804. the requested way.
  2805. STATUS_ACCESS_DENIED if the permission was not granted.
  2806. --*/
  2807. KSTATUS
  2808. IopCheckDeletePermission (
  2809. BOOL FromKernelMode,
  2810. PPATH_POINT DirectoryPathPoint,
  2811. PPATH_POINT FilePathPoint
  2812. );
  2813. /*++
  2814. Routine Description:
  2815. This routine performs a permission check for the current user at the given
  2816. path point, in preparation for removing a directory entry during a rename
  2817. or unlink operation.
  2818. Arguments:
  2819. FromKernelMode - Supplies a boolean indicating whether or not this
  2820. request actually originated from kernel mode.
  2821. DirectoryPathPoint - Supplies a pointer to the directory path point the
  2822. file resides in.
  2823. FilePathPoint - Supplies a pointer to the file path point being deleted or
  2824. renamed.
  2825. Return Value:
  2826. STATUS_SUCCESS if the user has permission to access the given object in
  2827. the requested way.
  2828. STATUS_ACCESS_DENIED if the permission was not granted.
  2829. --*/
  2830. KSTATUS
  2831. IopSendStateChangeIrp (
  2832. PDEVICE Device,
  2833. IRP_MINOR_CODE MinorCode,
  2834. PVOID IrpBody,
  2835. UINTN IrpBodySize
  2836. );
  2837. /*++
  2838. Routine Description:
  2839. This routine sends a state change IRP.
  2840. Arguments:
  2841. Device - Supplies a pointer to the device to send the IRP to.
  2842. MinorCode - Supplies the IRP minor code.
  2843. IrpBody - Supplies a pointer to a buffer that will be copied into the IRP
  2844. data union on input. On output, this buffer will receive the altered
  2845. data.
  2846. IrpBodySize - Supplies the size of the IRP body in bytes.
  2847. Return Value:
  2848. Status code.
  2849. --*/
  2850. KSTATUS
  2851. IopSendOpenIrp (
  2852. PDEVICE Device,
  2853. PIRP_OPEN OpenRequest
  2854. );
  2855. /*++
  2856. Routine Description:
  2857. This routine sends an open IRP.
  2858. Arguments:
  2859. Device - Supplies a pointer to the device to send the IRP to.
  2860. OpenRequest - Supplies a pointer that on input contains the open request
  2861. parameters. The contents of the IRP will also be copied here upon
  2862. returning.
  2863. Return Value:
  2864. Status code.
  2865. --*/
  2866. KSTATUS
  2867. IopSendCloseIrp (
  2868. PDEVICE Device,
  2869. PIRP_CLOSE CloseRequest
  2870. );
  2871. /*++
  2872. Routine Description:
  2873. This routine sends a close IRP to the given device.
  2874. Arguments:
  2875. Device - Supplies a pointer to the device to send the close IRP to.
  2876. CloseRequest - Supplies a pointer to the IRP close context.
  2877. Return Value:
  2878. Status code.
  2879. --*/
  2880. KSTATUS
  2881. IopSendIoIrp (
  2882. PDEVICE Device,
  2883. IRP_MINOR_CODE MinorCodeNumber,
  2884. PIRP_READ_WRITE Request
  2885. );
  2886. /*++
  2887. Routine Description:
  2888. This routine sends an I/O IRP.
  2889. Arguments:
  2890. Device - Supplies a pointer to the device to send the IRP to.
  2891. MinorCodeNumber - Supplies the minor code number to send to the IRP.
  2892. Request - Supplies a pointer that on input contains the I/O request
  2893. parameters.
  2894. Return Value:
  2895. Status code.
  2896. --*/
  2897. KSTATUS
  2898. IopSendIoReadIrp (
  2899. PDEVICE Device,
  2900. PIRP_READ_WRITE Request
  2901. );
  2902. /*++
  2903. Routine Description:
  2904. This routine sends an I/O read IRP to the given device. It makes sure that
  2905. the bytes completed that are returned do not extend beyond the file size.
  2906. Here the file size is that which is currently on the device and not in the
  2907. system's cached view of the world.
  2908. Arguments:
  2909. Device - Supplies a pointer to the device to send the IRP to.
  2910. Request - Supplies a pointer that on input contains the I/O request
  2911. parameters.
  2912. Return Value:
  2913. Status code.
  2914. --*/
  2915. KSTATUS
  2916. IopSendSystemControlIrp (
  2917. PDEVICE Device,
  2918. IRP_MINOR_CODE ControlNumber,
  2919. PVOID SystemContext
  2920. );
  2921. /*++
  2922. Routine Description:
  2923. This routine sends a system control request to the given device. This
  2924. routine must be called at low level.
  2925. Arguments:
  2926. Device - Supplies a pointer to the device to send the system control
  2927. request to.
  2928. ControlNumber - Supplies the system control number to send.
  2929. SystemContext - Supplies a pointer to the request details, which are
  2930. dependent on the control number.
  2931. Return Value:
  2932. Status code.
  2933. --*/
  2934. KSTATUS
  2935. IopSendUserControlIrp (
  2936. PDEVICE Device,
  2937. ULONG MinorCode,
  2938. BOOL FromKernelMode,
  2939. PVOID UserContext,
  2940. UINTN UserContextSize
  2941. );
  2942. /*++
  2943. Routine Description:
  2944. This routine sends a user control request to the given device. This
  2945. routine must be called at low level.
  2946. Arguments:
  2947. Device - Supplies a pointer to the device to send the user control
  2948. request to.
  2949. MinorCode - Supplies the minor code of the request.
  2950. FromKernelMode - Supplies a boolean indicating whether or not this request
  2951. (and the buffer associated with it) originates from user mode (FALSE)
  2952. or kernel mode (TRUE).
  2953. UserContext - Supplies a pointer to the context buffer allocated by the
  2954. caller for the request.
  2955. UserContextSize - Supplies the size of the supplied context buffer.
  2956. Return Value:
  2957. Status code.
  2958. --*/
  2959. KSTATUS
  2960. IopQueueResourceAssignment (
  2961. PDEVICE Device
  2962. );
  2963. /*++
  2964. Routine Description:
  2965. This routine puts this device in the resource assignment queue.
  2966. Arguments:
  2967. Device - Supplies a pointer to the device to queue for resource assignment.
  2968. Return Value:
  2969. Status code indicating whether or not the device was successfully queued.
  2970. (Not that it successfully made it through the queue or was processed in
  2971. any way).
  2972. --*/
  2973. KSTATUS
  2974. IopQueueDelayedResourceAssignment (
  2975. VOID
  2976. );
  2977. /*++
  2978. Routine Description:
  2979. This routine queues resource assignment for devices that were delayed to
  2980. allow devices with boot resources to go first.
  2981. Arguments:
  2982. None.
  2983. Return Value:
  2984. Status code.
  2985. --*/
  2986. KSTATUS
  2987. IopProcessResourceRequirements (
  2988. PDEVICE Device
  2989. );
  2990. /*++
  2991. Routine Description:
  2992. This routine attempts to find the best set of resources for a given device.
  2993. Arguments:
  2994. Device - Supplies a pointer to the device that will be receiving the
  2995. resource allocation.
  2996. Return Value:
  2997. Status code.
  2998. --*/
  2999. KSTATUS
  3000. IopArchInitializeKnownArbiterRegions (
  3001. VOID
  3002. );
  3003. /*++
  3004. Routine Description:
  3005. This routine performs any architecture-specific initialization of the
  3006. resource arbiters.
  3007. Arguments:
  3008. None.
  3009. Return Value:
  3010. Status code.
  3011. --*/
  3012. VOID
  3013. IopDestroyArbiterList (
  3014. PDEVICE Device
  3015. );
  3016. /*++
  3017. Routine Description:
  3018. This routine destroys the arbiter list of the given device.
  3019. Arguments:
  3020. Device - Supplies a pointer to a device whose arbiter list is to be
  3021. destroyed.
  3022. Return Value:
  3023. None.
  3024. --*/
  3025. KSTATUS
  3026. IopInitializePageCache (
  3027. VOID
  3028. );
  3029. /*++
  3030. Routine Description:
  3031. This routine initializes the page cache.
  3032. Arguments:
  3033. None.
  3034. Return Value:
  3035. Status code.
  3036. --*/
  3037. PPAGE_CACHE_ENTRY
  3038. IopLookupPageCacheEntry (
  3039. PFILE_OBJECT FileObject,
  3040. ULONGLONG Offset,
  3041. BOOL Write
  3042. );
  3043. /*++
  3044. Routine Description:
  3045. This routine searches for a page cache entry based on the file object and
  3046. offset. If found, this routine takes a reference on the page cache entry.
  3047. Arguments:
  3048. FileObject - Supplies a pointer to a file object for the device or file.
  3049. Offset - Supplies an offset into the file or device.
  3050. Write - Supplies a boolean indicating if the lookup is for a write
  3051. operation (TRUE) or a read operation (FALSE).
  3052. Return Value:
  3053. Returns a pointer to the found page cache entry on success, or NULL on
  3054. failure.
  3055. --*/
  3056. PPAGE_CACHE_ENTRY
  3057. IopCreateOrLookupPageCacheEntry (
  3058. PFILE_OBJECT FileObject,
  3059. PVOID VirtualAddress,
  3060. PHYSICAL_ADDRESS PhysicalAddress,
  3061. ULONGLONG Offset,
  3062. PPAGE_CACHE_ENTRY LinkEntry,
  3063. BOOL Write,
  3064. PBOOL EntryCreated
  3065. );
  3066. /*++
  3067. Routine Description:
  3068. This routine creates a page cache entry and inserts it into the cache. Or,
  3069. if a page cache entry already exists for the supplied file object and
  3070. offset, it returns the existing entry. The file object lock must be held
  3071. exclusive already.
  3072. Arguments:
  3073. FileObject - Supplies a pointer to a file object for the device or file
  3074. that owns the contents of the physical page.
  3075. VirtualAddress - Supplies an optional virtual address of the page.
  3076. PhysicalAddress - Supplies the physical address of the page.
  3077. Offset - Supplies the offset into the file or device where the page is
  3078. from.
  3079. LinkEntry - Supplies an optional pointer to a page cache entry that is
  3080. to share the physical address with this new page cache entry if it gets
  3081. inserted.
  3082. Write - Supplies a boolean indicating if the page cache entry is being
  3083. queried/created for a write operation (TRUE) or a read operation
  3084. (FALSE).
  3085. EntryCreated - Supplies an optional pointer that receives a boolean
  3086. indicating whether or not a new page cache entry was created.
  3087. Return Value:
  3088. Returns a pointer to a page cache entry on success, or NULL on failure.
  3089. --*/
  3090. PPAGE_CACHE_ENTRY
  3091. IopCreateAndInsertPageCacheEntry (
  3092. PFILE_OBJECT FileObject,
  3093. PVOID VirtualAddress,
  3094. PHYSICAL_ADDRESS PhysicalAddress,
  3095. ULONGLONG Offset,
  3096. PPAGE_CACHE_ENTRY LinkEntry,
  3097. BOOL Write
  3098. );
  3099. /*++
  3100. Routine Description:
  3101. This routine creates a page cache entry and inserts it into the cache. The
  3102. caller should be certain that there is not another entry in the cache for
  3103. the same file object and offset and that nothing else is in contention to
  3104. create the same entry.
  3105. Arguments:
  3106. FileObject - Supplies a pointer to a file object for the device or file
  3107. that owns the contents of the physical page.
  3108. VirtualAddress - Supplies an optional virtual address of the page.
  3109. PhysicalAddress - Supplies the physical address of the page.
  3110. Offset - Supplies the offset into the file or device where the page is
  3111. from.
  3112. LinkEntry - Supplies an optional pointer to a page cache entry that is to
  3113. share the physical address with the new page cache entry.
  3114. Write - Supplies a boolean indicating if the page cache entry is being
  3115. created for a write operation (TRUE) or a read operation (FALSE).
  3116. Return Value:
  3117. Returns a pointer to a page cache entry on success, or NULL on failure.
  3118. --*/
  3119. KSTATUS
  3120. IopCopyAndCacheIoBuffer (
  3121. PFILE_OBJECT FileObject,
  3122. ULONGLONG FileOffset,
  3123. PIO_BUFFER Destination,
  3124. UINTN CopySize,
  3125. PIO_BUFFER Source,
  3126. UINTN SourceSize,
  3127. UINTN SourceCopyOffset,
  3128. BOOL Write,
  3129. PUINTN BytesCopied
  3130. );
  3131. /*++
  3132. Routine Description:
  3133. This routine iterates over the source buffer, caching each page and copying
  3134. the pages to the destination buffer starting at the given copy offsets and
  3135. up to the given copy size. The file object lock must be held exclusive
  3136. already.
  3137. Arguments:
  3138. FileObject - Supplies a pointer to the file object for the device or file
  3139. that owns the data.
  3140. FileOffset - Supplies an offset into the file that corresponds to the
  3141. beginning of the source I/O buffer.
  3142. Destination - Supplies a pointer to the destination I/O buffer.
  3143. CopySize - Supplies the maximum number of bytes that can be copied
  3144. to the destination.
  3145. Source - Supplies a pointer to the source I/O buffer.
  3146. SourceSize - Supplies the number of bytes in the source that should be
  3147. cached.
  3148. SourceCopyOffset - Supplies the offset into the source buffer where the
  3149. copy to the destination should start.
  3150. Write - Supplies a boolean indicating if the I/O buffer is being cached for
  3151. a write operation (TRUE) or a read operation (FALSE).
  3152. BytesCopied - Supplies a pointer that receives the number of bytes copied
  3153. to the destination buffer.
  3154. Return Value:
  3155. Status code.
  3156. --*/
  3157. KSTATUS
  3158. IopFlushPageCacheEntries (
  3159. PFILE_OBJECT FileObject,
  3160. ULONGLONG Offset,
  3161. ULONGLONG Size,
  3162. ULONG Flags,
  3163. PUINTN PageCount
  3164. );
  3165. /*++
  3166. Routine Description:
  3167. This routine flushes the page cache entries for the given file object
  3168. starting at the given offset for the requested size. This routine does not
  3169. return until all file data has successfully been written to disk. It does
  3170. not guarantee that file meta-data has been flushed to disk.
  3171. Arguments:
  3172. FileObject - Supplies a pointer to a file object for the device or file.
  3173. Offset - Supplies the offset from the beginning of the file or device where
  3174. the flush should be done.
  3175. Size - Supplies the size, in bytes, of the region to flush. Supply a value
  3176. of -1 to flush from the given offset to the end of the file.
  3177. Flags - Supplies a bitmask of I/O flags. See IO_FLAG_* for definitions.
  3178. PageCount - Supplies an optional pointer describing how many pages to flush.
  3179. On output this value will be decreased by the number of pages actually
  3180. flushed. Supply NULL to flush all pages in the size range.
  3181. Return Value:
  3182. Status code.
  3183. --*/
  3184. VOID
  3185. IopEvictPageCacheEntries (
  3186. PFILE_OBJECT FileObject,
  3187. ULONGLONG Offset,
  3188. ULONG Flags
  3189. );
  3190. /*++
  3191. Routine Description:
  3192. This routine attempts to evict the page cache entries for a given file or
  3193. device, as specified by the file object. The flags specify how aggressive
  3194. this routine should be. The file object lock must already be held exclusive.
  3195. Arguments:
  3196. FileObject - Supplies a pointer to a file object for the device or file.
  3197. Offset - Supplies the starting offset into the file or device after which
  3198. all page cache entries should be evicted.
  3199. Flags - Supplies a bitmask of eviction flags. See
  3200. PAGE_CACHE_EVICTION_FLAG_* for definitions.
  3201. Return Value:
  3202. None.
  3203. --*/
  3204. BOOL
  3205. IopIsIoBufferPageCacheBacked (
  3206. PFILE_OBJECT FileObject,
  3207. PIO_BUFFER IoBuffer,
  3208. ULONGLONG Offset,
  3209. UINTN SizeInBytes
  3210. );
  3211. /*++
  3212. Routine Description:
  3213. This routine determines whether or not the given I/O buffer with data
  3214. targeting the given file object at the given offset is currently backed by
  3215. the page cache. The caller is expected to synchronize with eviction via
  3216. truncate.
  3217. Arguments:
  3218. FileObject - Supplies a pointer to a file object.
  3219. IoBuffer - Supplies a pointer to an I/O buffer.
  3220. Offset - Supplies an offset into the file or device object.
  3221. SizeInBytes - Supplied the number of bytes in the I/O buffer that should be
  3222. cache backed.
  3223. Return Value:
  3224. Returns TRUE if the I/O buffer is backed by valid page cache entries, or
  3225. FALSE otherwise.
  3226. --*/
  3227. VOID
  3228. IopNotifyPageCacheFilePropertiesUpdate (
  3229. VOID
  3230. );
  3231. /*++
  3232. Routine Description:
  3233. This routine is used to notify the page cache subsystem that a change to
  3234. file properties occurred. It decides what actions to take.
  3235. Arguments:
  3236. None.
  3237. Return Value:
  3238. None.
  3239. --*/
  3240. VOID
  3241. IopNotifyPageCacheFileDeleted (
  3242. VOID
  3243. );
  3244. /*++
  3245. Routine Description:
  3246. This routine notifies the page cache that a file has been deleted and that
  3247. it can clean up any cached entries for the file.
  3248. Arguments:
  3249. None.
  3250. Return Value:
  3251. None.
  3252. --*/
  3253. VOID
  3254. IopNotifyPageCacheWrite (
  3255. VOID
  3256. );
  3257. /*++
  3258. Routine Description:
  3259. This routine is used to notify the page cache subsystem that a write to the
  3260. page cache occurred. It decides what actions to take.
  3261. Arguments:
  3262. None.
  3263. Return Value:
  3264. None.
  3265. --*/
  3266. VOID
  3267. IopSchedulePageCacheCleaning (
  3268. ULONGLONG Delay
  3269. );
  3270. /*++
  3271. Routine Description:
  3272. This routine schedules a cleaning of the page cache or waits until it is
  3273. sure a cleaning is about to be scheduled by another caller.
  3274. Arguments:
  3275. Delay - Supplies the desired delay time before the cleaning begins,
  3276. in microseconds.
  3277. Return Value:
  3278. None.
  3279. --*/
  3280. ULONGLONG
  3281. IopGetPageCacheEntryOffset (
  3282. PPAGE_CACHE_ENTRY PageCacheEntry
  3283. );
  3284. /*++
  3285. Routine Description:
  3286. This routine gets the file or device offset of the given page cache entry.
  3287. Arguments:
  3288. PageCacheEntry - Supplies a pointer to a page cache entry.
  3289. Return Value:
  3290. Returns the file or device offset of the given page cache entry.
  3291. --*/
  3292. BOOL
  3293. IopMarkPageCacheEntryClean (
  3294. PPAGE_CACHE_ENTRY PageCacheEntry,
  3295. BOOL MoveToCleanList
  3296. );
  3297. /*++
  3298. Routine Description:
  3299. This routine marks the given page cache entry as clean.
  3300. Arguments:
  3301. PageCacheEntry - Supplies a pointer to a page cache entry.
  3302. MoveToCleanList - Supplies a boolean indicating if the page cache entry
  3303. should be moved to the list of clean page cache entries.
  3304. Return Value:
  3305. Returns TRUE if it marked the entry clean or FALSE if the entry was already
  3306. clean.
  3307. --*/
  3308. KSTATUS
  3309. IopCopyIoBufferToPageCacheEntry (
  3310. PPAGE_CACHE_ENTRY PageCacheEntry,
  3311. ULONG PageOffset,
  3312. PIO_BUFFER SourceBuffer,
  3313. UINTN SourceOffset,
  3314. ULONG ByteCount
  3315. );
  3316. /*++
  3317. Routine Description:
  3318. This routine copies up to a page from the given source buffer to the given
  3319. page cache entry.
  3320. Arguments:
  3321. PageCacheEntry - Supplies a pointer to a page cache entry.
  3322. PageOffset - Supplies an offset into the page where the copy should begin.
  3323. SourceBuffer - Supplies a pointer to the source buffer where the data
  3324. originates.
  3325. SourceOffset - Supplies an offset into the the source buffer where the data
  3326. copy should begin.
  3327. ByteCount - Supplies the number of bytes to copy.
  3328. Return Value:
  3329. Status code.
  3330. --*/
  3331. BOOL
  3332. IopCanLinkPageCacheEntry (
  3333. PPAGE_CACHE_ENTRY PageCacheEntry,
  3334. PFILE_OBJECT FileObject
  3335. );
  3336. /*++
  3337. Routine Description:
  3338. This routine determines if the given page cache entry could link with a
  3339. page cache entry for the given file object.
  3340. Arguments:
  3341. PageCacheEntry - Supplies a pointer to a page cache entry.
  3342. FileObject - Supplied a pointer to a file object.
  3343. Return Value:
  3344. Returns TRUE if the page cache entry could be linked to a page cache entry
  3345. with the given file object or FALSE otherwise.
  3346. --*/
  3347. BOOL
  3348. IopLinkPageCacheEntries (
  3349. PPAGE_CACHE_ENTRY LowerEntry,
  3350. PPAGE_CACHE_ENTRY UpperEntry
  3351. );
  3352. /*++
  3353. Routine Description:
  3354. This routine attempts to link the given link entry to the page cache entry
  3355. so that they can begin sharing a physical page that is currently used by
  3356. the link entry.
  3357. Arguments:
  3358. LowerEntry - Supplies a pointer to the lower (disk) level page cache entry
  3359. whose physical address is to be modified. The caller should ensure that
  3360. its reference on this entry does not come from an I/O buffer or else
  3361. the physical address in the I/O buffer would be invalid. The file
  3362. object lock for this entry must already be held exclusive.
  3363. UpperEntry - Supplies a pointer to the upper (file) page cache entry
  3364. that currently owns the physical page to be shared.
  3365. Return Value:
  3366. Returns TRUE if the two page cache entries are already connected or if the
  3367. routine is successful. It returns FALSE otherwise and both page cache
  3368. entries should continue to use their own physical pages.
  3369. --*/
  3370. VOID
  3371. IopTrimPageCache (
  3372. VOID
  3373. );
  3374. /*++
  3375. Routine Description:
  3376. This routine removes as many clean page cache entries as is necessary to
  3377. bring the size of the page cache back down to a reasonable level. It evicts
  3378. the page cache entries in LRU order.
  3379. Arguments:
  3380. None.
  3381. Return Value:
  3382. None.
  3383. --*/
  3384. BOOL
  3385. IopIsPageCacheTooDirty (
  3386. VOID
  3387. );
  3388. /*++
  3389. Routine Description:
  3390. This routine determines if the page cache has an uncomfortable number of
  3391. entries in it that are dirty. Dirty entries are dangerous because they
  3392. prevent the page cache from shrinking if memory gets tight.
  3393. Arguments:
  3394. None.
  3395. Return Value:
  3396. TRUE if the page cache has too many dirty entries and adding new ones
  3397. should generally be avoided.
  3398. FALSE if the page cache is relatively clean.
  3399. --*/
  3400. COMPARISON_RESULT
  3401. IopComparePageCacheEntries (
  3402. PRED_BLACK_TREE Tree,
  3403. PRED_BLACK_TREE_NODE FirstNode,
  3404. PRED_BLACK_TREE_NODE SecondNode
  3405. );
  3406. /*++
  3407. Routine Description:
  3408. This routine compares two Red-Black tree nodes contained inside file
  3409. objects.
  3410. Arguments:
  3411. Tree - Supplies a pointer to the Red-Black tree that owns both nodes.
  3412. FirstNode - Supplies a pointer to the left side of the comparison.
  3413. SecondNode - Supplies a pointer to the second side of the comparison.
  3414. Return Value:
  3415. Same if the two nodes have the same value.
  3416. Ascending if the first node is less than the second node.
  3417. Descending if the second node is less than the first node.
  3418. --*/
  3419. BOOL
  3420. IopIsTestHookSet (
  3421. ULONG TestHookMask
  3422. );
  3423. /*++
  3424. Routine Description:
  3425. This routine checks to see if the given test hook field is currently set in
  3426. the test hook bitmask.
  3427. Arguments:
  3428. TestHookMask - Supplies the test hook field this routine will check the
  3429. test hook bitmask against.
  3430. Return Value:
  3431. Returns TRUE if the test hook is set, or FALSE otherwise.
  3432. --*/
  3433. KSTATUS
  3434. IopGetFileLock (
  3435. PIO_HANDLE IoHandle,
  3436. PFILE_LOCK Lock
  3437. );
  3438. /*++
  3439. Routine Description:
  3440. This routine gets information about a file lock. Existing locks are not
  3441. reported if they are compatible with making a new lock in the given region.
  3442. So set the lock type to write if both read and write locks should be
  3443. reported.
  3444. Arguments:
  3445. IoHandle - Supplies a pointer to the open I/O handle.
  3446. Lock - Supplies a pointer to the lock information.
  3447. Return Value:
  3448. Status code.
  3449. --*/
  3450. KSTATUS
  3451. IopSetFileLock (
  3452. PIO_HANDLE IoHandle,
  3453. PFILE_LOCK Lock,
  3454. BOOL Blocking
  3455. );
  3456. /*++
  3457. Routine Description:
  3458. This routine locks or unlocks a portion of a file. If the process already
  3459. has a lock on any part of the region, the old lock is replaced with this
  3460. new region. Remove a lock by specifying a lock type of unlock.
  3461. Arguments:
  3462. IoHandle - Supplies a pointer to the open I/O handle.
  3463. Lock - Supplies a pointer to the lock information.
  3464. Blocking - Supplies a boolean indicating if this should block until a
  3465. determination is made.
  3466. Return Value:
  3467. Status code.
  3468. --*/
  3469. VOID
  3470. IopRemoveFileLocks (
  3471. PIO_HANDLE IoHandle,
  3472. PKPROCESS Process
  3473. );
  3474. /*++
  3475. Routine Description:
  3476. This routine destroys any locks the given process has on the file object
  3477. pointed to by the given I/O handle. This routine is called anytime any
  3478. file descriptor is closed by a process, even if other file descriptors
  3479. to the same file in the process remain open.
  3480. Arguments:
  3481. IoHandle - Supplies a pointer to the I/O handle being closed.
  3482. Process - Supplies the process closing the handle.
  3483. Return Value:
  3484. None.
  3485. --*/
  3486. KSTATUS
  3487. IopSynchronizeBlockDevice (
  3488. PDEVICE Device
  3489. );
  3490. /*++
  3491. Routine Description:
  3492. This routine sends a sync request to a block device to ensure all data is
  3493. written out to permanent storage.
  3494. Arguments:
  3495. Device - Supplies a pointer to the device to send the synchronize request
  3496. to.
  3497. Return Value:
  3498. Status code.
  3499. --*/