Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

954 lines
20 KiB

  1. /*++
  2. Copyright (c) 1995-2001 Microsoft Corporation
  3. Module Name:
  4. sbentry.h
  5. Abstract:
  6. Contains the OS boot entry and boot options
  7. abstractions.
  8. Author:
  9. Vijay Jayaseelan (vijayj@microsoft.com) 14 Feb 2001
  10. Revision History:
  11. None.
  12. --*/
  13. #pragma once
  14. #include <nt.h>
  15. #include <ntrtl.h>
  16. #include <nturtl.h>
  17. #include <windows.h>
  18. #include <malloc.h>
  19. //
  20. // Allocate & Deallocate routines
  21. //
  22. typedef void* (* SBEMemAllocateRoutine)(size_t Size);
  23. typedef void (* SBEMemFreeRoutine)(void *Memory);
  24. extern SBEMemAllocateRoutine AllocRoutine;
  25. extern SBEMemFreeRoutine FreeRoutine;
  26. #define ARRAY_SIZE(x) (sizeof((x))/sizeof((x)[0]))
  27. //
  28. // Internal attributes for the boot entry
  29. //
  30. #define OSBE_ATTRIBUTE_NEW 0x00000001
  31. #define OSBE_ATTRIBUTE_DELETED 0x00000002
  32. #define OSBE_ATTRIBUTE_WINDOWS 0x00000004
  33. #define OSBE_ATTRIBUTE_DIRTY 0x10000000
  34. //
  35. //Internal attributes for the driver entry.
  36. //
  37. #define DRIVER_ATTRIBUTE_NEW 0x00000001
  38. #define DRIVER_ATTRIBUTE_DELETED 0x00000002
  39. #define DRIVER_ATTRIBUTE_DIRTY 0x10000000
  40. //
  41. // OS_BOOT_ENTRY abstraction
  42. //
  43. typedef struct _OS_BOOT_ENTRY *POS_BOOT_ENTRY;
  44. typedef struct _OS_BOOT_OPTIONS *POS_BOOT_OPTIONS;
  45. typedef VOID (* OSBEDeleteMethod)(
  46. IN POS_BOOT_ENTRY This
  47. );
  48. typedef BOOLEAN (* OSBEFlushMethod)(
  49. IN POS_BOOT_ENTRY This
  50. );
  51. typedef struct _OS_BOOT_ENTRY {
  52. //
  53. // Data members
  54. //
  55. ULONG Version;
  56. ULONG Id;
  57. WCHAR FriendlyName[MAX_PATH];
  58. WCHAR OsLoaderVolumeName[MAX_PATH];
  59. WCHAR OsLoaderPath[MAX_PATH];
  60. WCHAR BootVolumeName[MAX_PATH];
  61. WCHAR BootPath[MAX_PATH];
  62. WCHAR OsLoadOptions[MAX_PATH];
  63. ULONG Attributes;
  64. POS_BOOT_OPTIONS BootOptions;
  65. POS_BOOT_ENTRY NextEntry;
  66. //
  67. // Methods
  68. //
  69. OSBEDeleteMethod Delete;
  70. OSBEFlushMethod Flush;
  71. } OS_BOOT_ENTRY;
  72. //
  73. // Driver Entry abstraction.
  74. //
  75. typedef struct _DRIVER_ENTRY *PDRIVER_ENTRY;
  76. typedef VOID (* DriverEntryDeleteMethod)(
  77. IN POS_BOOT_OPTIONS This,
  78. IN ULONG Id
  79. );
  80. typedef BOOLEAN (* DriverEntryFlushMethod)(
  81. IN PDRIVER_ENTRY This
  82. );
  83. typedef struct _DRIVER_ENTRY {
  84. ULONG Id;
  85. WCHAR FileName[MAX_PATH];
  86. WCHAR NtDevicePath[MAX_PATH];
  87. WCHAR DirPath[MAX_PATH];
  88. WCHAR FriendlyName[MAX_PATH];
  89. ULONG Attributes;
  90. POS_BOOT_OPTIONS BootOptions;
  91. PDRIVER_ENTRY NextEntry;
  92. //
  93. // Methods
  94. //
  95. DriverEntryDeleteMethod Delete;
  96. DriverEntryFlushMethod Flush;
  97. } DRIVER_ENTRY;
  98. #define OSBE_IS_DIRTY(_osbe) (((POS_BOOT_ENTRY)(_osbe))->Attributes & OSBE_ATTRIBUTE_DIRTY)
  99. #define OSBE_IS_NEW(_osbe) (((POS_BOOT_ENTRY)(_osbe))->Attributes & OSBE_ATTRIBUTE_NEW)
  100. #define OSBE_IS_DELETED(_osbe) (((POS_BOOT_ENTRY)(_osbe))->Attributes & OSBE_ATTRIBUTE_DELETED)
  101. #define OSBE_IS_WINDOWS(_osbe) (((POS_BOOT_ENTRY)(_osbe))->Attributes & OSBE_ATTRIBUTE_WINDOWS)
  102. #define OSBE_SET_DIRTY(_osbe) (((POS_BOOT_ENTRY)(_osbe))->Attributes |= OSBE_ATTRIBUTE_DIRTY)
  103. #define OSBE_SET_NEW(_osbe) (((POS_BOOT_ENTRY)(_osbe))->Attributes |= OSBE_ATTRIBUTE_NEW)
  104. #define OSBE_SET_DELETED(_osbe) (((POS_BOOT_ENTRY)(_osbe))->Attributes |= OSBE_ATTRIBUTE_DELETED)
  105. #define OSBE_SET_WINDOWS(_osbe) (((POS_BOOT_ENTRY)(_osbe))->Attributes |= OSBE_ATTRIBUTE_WINDOWS)
  106. #define OSBE_RESET_DIRTY(_osbe) (((POS_BOOT_ENTRY)(_osbe))->Attributes &= ~OSBE_ATTRIBUTE_DIRTY)
  107. #define OSBE_RESET_NEW(_osbe) (((POS_BOOT_ENTRY)(_osbe))->Attributes &= ~OSBE_ATTRIBUTE_NEW)
  108. #define OSBE_RESET_DELETED(_osbe) (((POS_BOOT_ENTRY)(_osbe))->Attributes &= ~OSBE_ATTRIBUTE_DELETED)
  109. #define OSBE_RESET_WINDOWS(_osbe) (((POS_BOOT_ENTRY)(_osbe))->Attributes &= ~OSBE_ATTRIBUTE_WINDOWS)
  110. #define DRIVERENT_IS_DIRTY(_de) (((PDRIVER_ENTRY)(_de))->Attributes & DRIVER_ATTRIBUTE_DIRTY)
  111. #define DRIVERENT_IS_NEW(_de) (((PDRIVER_ENTRY)(_de))->Attributes & DRIVER_ATTRIBUTE_NEW)
  112. #define DRIVERENT_IS_DELETED(_de) (((PDRIVER_ENTRY)(_de))->Attributes & DRIVER_ATTRIBUTE_DELETED)
  113. #define DRIVERENT_SET_DIRTY(_de) (((PDRIVER_ENTRY)(_de))->Attributes |= DRIVER_ATTRIBUTE_DIRTY)
  114. #define DRIVERENT_SET_NEW(_de) (((PDRIVER_ENTRY)(_de))->Attributes |= DRIVER_ATTRIBUTE_NEW)
  115. #define DRIVERENT_SET_DELETED(_de) (((PDRIVER_ENTRY)(_de))->Attributes |= DRIVER_ATTRIBUTE_DELETED)
  116. #define DRIVERENT_RESET_DIRTY(_de) (((PDRIVER_ENTRY)(_de))->Attributes &= ~DRIVER_ATTRIBUTE_DIRTY)
  117. #define DRIVERENT_RESET_NEW(_de) (((PDRIVER_ENTRY)(_de))->Attributes &= ~DRIVER_ATTRIBUTE_NEW)
  118. #define DRIVERENT_RESET_DELETED(_de) (((PDRIVER_ENTRY)(_de))->Attributes &= ~DRIVER_ATTRIBUTE_DELETED)
  119. //
  120. // OS_BOOT_OPTIONS abstraction
  121. //
  122. typedef VOID (* OSBODeleteMethod)(
  123. IN POS_BOOT_OPTIONS This
  124. );
  125. typedef POS_BOOT_ENTRY (* OSBOAddNewBootEntryMethod)(
  126. IN POS_BOOT_OPTIONS This,
  127. IN PCWSTR FriendlyName,
  128. IN PCWSTR OsLoaderVolumeName,
  129. IN PCWSTR OsLoaderPath,
  130. IN PCWSTR BootVolumeName,
  131. IN PCWSTR BootPath,
  132. IN PCWSTR OsLoadOptions
  133. );
  134. typedef BOOLEAN (* OSBODeleteBootEntryMethod)(
  135. IN POS_BOOT_OPTIONS This,
  136. IN POS_BOOT_ENTRY BootEntry
  137. );
  138. typedef BOOLEAN (* OSBOFlushMethod)(
  139. IN POS_BOOT_OPTIONS This
  140. );
  141. typedef PDRIVER_ENTRY (* OSBOAddNewDriverEntryMethod)(
  142. IN POS_BOOT_OPTIONS This,
  143. IN PCWSTR FriendlyName,
  144. IN PCWSTR NtDevicePath,
  145. IN PCWSTR SrcNtFullPath
  146. );
  147. typedef BOOLEAN (* OSBODeleteDriverEntryMethod)(
  148. IN POS_BOOT_OPTIONS This,
  149. IN ULONG Id
  150. );
  151. typedef struct _OS_BOOT_OPTIONS {
  152. //
  153. // Data members
  154. //
  155. ULONG Version;
  156. ULONG Attributes;
  157. ULONG Timeout;
  158. POS_BOOT_ENTRY BootEntries;
  159. POS_BOOT_ENTRY CurrentEntry;
  160. ULONG EntryCount;
  161. PULONG BootOrder;
  162. ULONG BootOrderCount;
  163. PDRIVER_ENTRY DriverEntries;
  164. ULONG DriverEntryCount;
  165. PULONG DriverEntryOrder;
  166. ULONG DriverEntryOrderCount;
  167. //
  168. // Methods
  169. //
  170. OSBODeleteMethod Delete;
  171. OSBOFlushMethod Flush;
  172. OSBOAddNewBootEntryMethod AddNewBootEntry;
  173. OSBODeleteBootEntryMethod DeleteBootEntry;
  174. OSBOAddNewDriverEntryMethod AddNewDriverEntry;
  175. OSBODeleteDriverEntryMethod DeleteDriverEntry;
  176. } OS_BOOT_OPTIONS;
  177. #define OSBO_IS_DIRTY(_osbo) (((POS_BOOT_OPTIONS)(_osbo))->Attributes & OSBE_ATTRIBUTE_DIRTY)
  178. #define OSBO_SET_DIRTY(_osbo) (((POS_BOOT_OPTIONS)(_osbo))->Attributes |= OSBE_ATTRIBUTE_DIRTY)
  179. #define OSBO_RESET_DIRTY(_osbo) (((POS_BOOT_OPTIONS)(_osbo))->Attributes &= ~OSBE_ATTRIBUTE_DIRTY)
  180. //
  181. // OS_BOOT_ENTRY Methods
  182. //
  183. PCWSTR
  184. OSBEAddOsLoadOption(
  185. IN POS_BOOT_ENTRY This,
  186. IN PCWSTR BootOption
  187. );
  188. PCWSTR
  189. OSBERemoveOsLoadOption(
  190. IN POS_BOOT_ENTRY This,
  191. IN PCWSTR BootOption
  192. );
  193. BOOLEAN
  194. OSBEIsOsLoadOptionPresent(
  195. IN POS_BOOT_ENTRY This,
  196. IN PCWSTR BootOption
  197. );
  198. __inline
  199. VOID
  200. OSBEDelete(
  201. IN POS_BOOT_ENTRY This
  202. )
  203. {
  204. if (This) {
  205. (This->Delete)(This);
  206. }
  207. }
  208. __inline
  209. BOOLEAN
  210. OSBEFlush(
  211. IN POS_BOOT_ENTRY This
  212. )
  213. {
  214. return (This) ? This->Flush(This) : FALSE;
  215. }
  216. __inline
  217. ULONG
  218. OSBEGetId(
  219. IN POS_BOOT_ENTRY This
  220. )
  221. {
  222. return (This) ? This->Id : (-1);
  223. }
  224. __inline
  225. PCWSTR
  226. OSBEGetFriendlyName(
  227. IN POS_BOOT_ENTRY This
  228. )
  229. {
  230. return (This) ? This->FriendlyName : NULL;
  231. }
  232. __inline
  233. PCWSTR
  234. OSBESetFriendlyName(
  235. IN POS_BOOT_ENTRY This,
  236. IN PCWSTR Name
  237. )
  238. {
  239. PWSTR NewName = NULL;
  240. if (This && Name) {
  241. ULONG Size = ARRAY_SIZE(This->FriendlyName);
  242. wcsncpy(This->FriendlyName, Name, Size - 1);
  243. This->FriendlyName[Size - 1] = UNICODE_NULL;
  244. NewName = This->FriendlyName;
  245. OSBE_SET_DIRTY(This);
  246. OSBO_SET_DIRTY(This->BootOptions);
  247. }
  248. return NewName;
  249. }
  250. __inline
  251. PCWSTR
  252. OSBEGetOsLoaderVolumeName(
  253. IN POS_BOOT_ENTRY This
  254. )
  255. {
  256. return (This) ? This->OsLoaderVolumeName : NULL;
  257. }
  258. __inline
  259. PCWSTR
  260. OSBESetOsLoaderVolumeName(
  261. IN POS_BOOT_ENTRY This,
  262. IN PCWSTR Name
  263. )
  264. {
  265. PWSTR NewName = NULL;
  266. if (This && Name) {
  267. ULONG Size = ARRAY_SIZE(This->OsLoaderVolumeName);
  268. wcsncpy(This->OsLoaderVolumeName, Name, Size - 1);
  269. This->OsLoaderVolumeName[Size - 1] = UNICODE_NULL;
  270. NewName = This->OsLoaderVolumeName;
  271. OSBE_SET_DIRTY(This);
  272. OSBO_SET_DIRTY(This->BootOptions);
  273. }
  274. return NewName;
  275. }
  276. __inline
  277. PCWSTR
  278. OSBEGetOsLoaderPath(
  279. IN POS_BOOT_ENTRY This
  280. )
  281. {
  282. return (This) ? This->OsLoaderPath : NULL;
  283. }
  284. __inline
  285. PCWSTR
  286. OSBESetOsLoaderPath(
  287. IN POS_BOOT_ENTRY This,
  288. IN PCWSTR Name
  289. )
  290. {
  291. PWSTR NewName = NULL;
  292. if (This && Name) {
  293. ULONG Size = ARRAY_SIZE(This->OsLoaderPath);
  294. wcsncpy(This->OsLoaderPath, Name, Size - 1);
  295. This->OsLoaderPath[Size - 1] = UNICODE_NULL;
  296. NewName = This->OsLoaderPath;
  297. OSBE_SET_DIRTY(This);
  298. OSBO_SET_DIRTY(This->BootOptions);
  299. }
  300. return NewName;
  301. }
  302. __inline
  303. PCWSTR
  304. OSBEGetBootVolumeName(
  305. IN POS_BOOT_ENTRY This
  306. )
  307. {
  308. return (This) ? This->BootVolumeName : NULL;
  309. }
  310. __inline
  311. PCWSTR
  312. OSBESetBootVolumeName(
  313. IN POS_BOOT_ENTRY This,
  314. IN PCWSTR Name
  315. )
  316. {
  317. PWSTR NewName = NULL;
  318. if (This && Name) {
  319. ULONG Size = ARRAY_SIZE(This->BootVolumeName);
  320. wcsncpy(This->BootVolumeName, Name, Size - 1);
  321. This->BootVolumeName[Size - 1] = UNICODE_NULL;
  322. NewName = This->BootVolumeName;
  323. OSBE_SET_DIRTY(This);
  324. OSBO_SET_DIRTY(This->BootOptions);
  325. }
  326. return NewName;
  327. }
  328. __inline
  329. PCWSTR
  330. OSBEGetBootPath(
  331. IN POS_BOOT_ENTRY This
  332. )
  333. {
  334. return (This) ? This->BootPath : NULL;
  335. }
  336. __inline
  337. PCWSTR
  338. OSBESetBootPath(
  339. IN POS_BOOT_ENTRY This,
  340. IN PCWSTR Name
  341. )
  342. {
  343. PWSTR NewName = NULL;
  344. if (This && Name) {
  345. ULONG Size = ARRAY_SIZE(This->BootPath);
  346. wcsncpy(This->BootPath, Name, Size - 1);
  347. This->BootPath[Size - 1] = UNICODE_NULL;
  348. NewName = This->BootPath;
  349. OSBE_SET_DIRTY(This);
  350. OSBO_SET_DIRTY(This->BootOptions);
  351. }
  352. return NewName;
  353. }
  354. __inline
  355. PCWSTR
  356. OSBEGetOsLoadOptions(
  357. IN POS_BOOT_ENTRY This
  358. )
  359. {
  360. return (This) ? This->OsLoadOptions : NULL;
  361. }
  362. __inline
  363. PCWSTR
  364. OSBESetOsLoadOptions(
  365. IN POS_BOOT_ENTRY This,
  366. IN PCWSTR LoadOptions
  367. )
  368. {
  369. WCHAR Buffer[MAX_PATH];
  370. PWSTR NewOptions = NULL;
  371. if (This && LoadOptions) {
  372. ULONG Size = ARRAY_SIZE(This->OsLoadOptions);
  373. wcscpy(Buffer, LoadOptions);
  374. _wcsupr(Buffer);
  375. wcsncpy(This->OsLoadOptions, Buffer, Size - 1);
  376. This->OsLoadOptions[Size - 1] = UNICODE_NULL;
  377. NewOptions = This->OsLoadOptions;
  378. OSBE_SET_DIRTY(This);
  379. OSBO_SET_DIRTY(This->BootOptions);
  380. }
  381. return NewOptions;
  382. }
  383. //
  384. // OS_BOOT_OPTIONS Methods
  385. //
  386. __inline
  387. BOOLEAN
  388. OSBOFlush(
  389. IN POS_BOOT_OPTIONS This
  390. )
  391. {
  392. return (This) ? (This->Flush(This)) : FALSE;
  393. }
  394. __inline
  395. VOID
  396. OSBODelete(
  397. IN POS_BOOT_OPTIONS This
  398. )
  399. {
  400. if (This) {
  401. This->Delete(This);
  402. }
  403. }
  404. __inline
  405. POS_BOOT_ENTRY
  406. OSBOAddNewBootEntry(
  407. IN POS_BOOT_OPTIONS This,
  408. IN PCWSTR FriendlyName,
  409. IN PCWSTR OsLoaderVolumeName,
  410. IN PCWSTR OsLoaderPath,
  411. IN PCWSTR BootVolumeName,
  412. IN PCWSTR BootPath,
  413. IN PCWSTR OsLoadOptions
  414. )
  415. {
  416. POS_BOOT_ENTRY Entry = NULL;
  417. if (This) {
  418. Entry = This->AddNewBootEntry(This,
  419. FriendlyName,
  420. OsLoaderVolumeName,
  421. OsLoaderPath,
  422. BootVolumeName,
  423. BootPath,
  424. OsLoadOptions);
  425. OSBO_SET_DIRTY(This);
  426. }
  427. return Entry;
  428. }
  429. __inline
  430. POS_BOOT_ENTRY
  431. OSBOGetActiveBootEntry(
  432. IN POS_BOOT_OPTIONS This
  433. )
  434. {
  435. POS_BOOT_ENTRY Entry = NULL;
  436. if (This) {
  437. Entry = This->CurrentEntry;
  438. }
  439. return Entry;
  440. }
  441. BOOLEAN
  442. OSBODeleteBootEntry(
  443. IN POS_BOOT_OPTIONS This,
  444. IN POS_BOOT_ENTRY BootEntry
  445. );
  446. POS_BOOT_ENTRY
  447. OSBOSetActiveBootEntry(
  448. IN POS_BOOT_OPTIONS This,
  449. IN POS_BOOT_ENTRY BootEntry
  450. );
  451. POS_BOOT_ENTRY
  452. OSBOGetFirstBootEntry(
  453. IN POS_BOOT_OPTIONS This,
  454. IN PULONG Index
  455. );
  456. POS_BOOT_ENTRY
  457. OSBOGetNextBootEntry(
  458. IN POS_BOOT_OPTIONS This,
  459. IN PULONG Index
  460. );
  461. ULONG
  462. OSBOGetBootEntryCount(
  463. IN POS_BOOT_OPTIONS This
  464. );
  465. ULONG
  466. OSBOGetOrderedBootEntryCount(
  467. IN POS_BOOT_OPTIONS This
  468. );
  469. ULONG
  470. OSBOGetBootEntryIdByOrder(
  471. IN POS_BOOT_OPTIONS This,
  472. IN ULONG Index
  473. );
  474. POS_BOOT_ENTRY
  475. OSBOFindBootEntry(
  476. IN POS_BOOT_OPTIONS This,
  477. IN ULONG Id
  478. );
  479. ULONG
  480. OSBOFindBootEntryOrder(
  481. IN POS_BOOT_OPTIONS This,
  482. IN ULONG Id
  483. );
  484. __inline
  485. ULONG
  486. OSBOGetTimeOut(
  487. IN POS_BOOT_OPTIONS This
  488. )
  489. {
  490. return (This) ? This->Timeout : 0;
  491. }
  492. __inline
  493. ULONG
  494. OSBOSetTimeOut(
  495. IN POS_BOOT_OPTIONS This,
  496. IN ULONG Timeout
  497. )
  498. {
  499. ULONG OldTimeout = 0;
  500. if (This) {
  501. OldTimeout = This->Timeout;
  502. This->Timeout = Timeout;
  503. OSBE_SET_DIRTY(This);
  504. }
  505. return OldTimeout;
  506. }
  507. __inline
  508. ULONG
  509. OSBOGetBootEntryCount(
  510. IN POS_BOOT_OPTIONS This
  511. )
  512. {
  513. ULONG Count = 0;
  514. if (This) {
  515. Count = This->EntryCount;
  516. }
  517. return Count;
  518. }
  519. __inline
  520. ULONG
  521. OSBOGetOrderedBootEntryCount(
  522. IN POS_BOOT_OPTIONS This
  523. )
  524. {
  525. ULONG Count = 0;
  526. if (This) {
  527. Count = This->BootOrderCount;
  528. }
  529. return Count;
  530. }
  531. __inline
  532. ULONG
  533. OSBOGetBootEntryIdByOrder(
  534. IN POS_BOOT_OPTIONS This,
  535. IN ULONG Index
  536. )
  537. {
  538. ULONG Entry = -1;
  539. if (Index < OSBOGetOrderedBootEntryCount(This)) {
  540. Entry = This->BootOrder[Index];
  541. }
  542. return Entry;
  543. }
  544. __inline
  545. BOOLEAN
  546. OSBOLibraryInit(
  547. SBEMemAllocateRoutine AllocFunction,
  548. SBEMemFreeRoutine FreeFunction
  549. )
  550. {
  551. BOOLEAN Result = FALSE;
  552. if (AllocFunction && FreeFunction) {
  553. AllocRoutine = AllocFunction;
  554. FreeRoutine = FreeFunction;
  555. Result = TRUE;
  556. }
  557. return Result;
  558. }
  559. //
  560. // Driver specific routines.
  561. //
  562. BOOLEAN
  563. OSBODeleteDriverEntry(
  564. IN POS_BOOT_OPTIONS This,
  565. IN ULONG Id
  566. );
  567. __inline
  568. PDRIVER_ENTRY
  569. OSBOGetFirstDriverEntry(
  570. IN POS_BOOT_OPTIONS This
  571. )
  572. {
  573. return (This) ? (This->DriverEntries) : NULL;
  574. }
  575. __inline
  576. PDRIVER_ENTRY
  577. OSBOGetNextDriverEntry(
  578. IN POS_BOOT_OPTIONS This,
  579. IN PDRIVER_ENTRY PrevDriverEntry
  580. )
  581. {
  582. return (This && PrevDriverEntry) ? PrevDriverEntry->NextEntry : NULL;
  583. }
  584. PDRIVER_ENTRY
  585. OSBOFindDriverEntryByName(
  586. IN POS_BOOT_OPTIONS This,
  587. IN PCWSTR DriverName
  588. );
  589. PDRIVER_ENTRY
  590. OSBOFindDriverEntryById(
  591. IN POS_BOOT_OPTIONS This,
  592. IN ULONG Id
  593. );
  594. __inline
  595. ULONG
  596. OSBOGetOrderedDriverEntryCount(
  597. IN POS_BOOT_OPTIONS This
  598. )
  599. {
  600. ULONG Count = 0;
  601. if (This) {
  602. Count = This->DriverEntryOrderCount;
  603. }
  604. return Count;
  605. }
  606. __inline
  607. ULONG
  608. OSBOGetDriverEntryIdByOrder(
  609. IN POS_BOOT_OPTIONS This,
  610. IN ULONG Index
  611. )
  612. {
  613. ULONG Entry = -1;
  614. if (Index < OSBOGetOrderedDriverEntryCount(This)) {
  615. Entry = This->DriverEntryOrder[Index];
  616. }
  617. return Entry;
  618. }
  619. __inline
  620. BOOLEAN
  621. OSDriverEntryFlush(
  622. IN PDRIVER_ENTRY This
  623. )
  624. {
  625. return (This) ? This->Flush(This) : FALSE;
  626. }
  627. __inline
  628. PDRIVER_ENTRY
  629. OSBOAddNewDriverEntry(
  630. IN POS_BOOT_OPTIONS This,
  631. IN PCWSTR FriendlyName,
  632. IN PCWSTR NtDevicePath,
  633. IN PCWSTR DirPath
  634. )
  635. {
  636. PDRIVER_ENTRY Entry = NULL;
  637. if (This) {
  638. Entry = This->AddNewDriverEntry(This,
  639. FriendlyName,
  640. NtDevicePath,
  641. DirPath);
  642. OSBO_SET_DIRTY(This);
  643. }
  644. return Entry;
  645. }
  646. __inline
  647. PCWSTR
  648. OSDriverSetFriendlyName(
  649. IN PDRIVER_ENTRY This,
  650. IN PCWSTR Name
  651. )
  652. {
  653. PWSTR NewName = NULL;
  654. if (This && Name) {
  655. ULONG Size = ARRAY_SIZE(This->FriendlyName);
  656. wcsncpy(This->FriendlyName, Name, Size - 1);
  657. This->FriendlyName[Size - 1] = UNICODE_NULL;
  658. NewName = This->FriendlyName;
  659. DRIVERENT_SET_DIRTY(This);
  660. DRIVERENT_SET_DIRTY(This->BootOptions);
  661. }
  662. return NewName;
  663. }
  664. __inline
  665. PCWSTR
  666. OSDriverSetFileName(
  667. IN PDRIVER_ENTRY This,
  668. IN PCWSTR Path
  669. )
  670. {
  671. PWSTR Result = NULL;
  672. if (This && Path && (Path[0] != UNICODE_NULL)) {
  673. PCWSTR FileName = wcsrchr((PCWSTR)Path, L'\\');
  674. if (FileName){
  675. ULONG Size = ARRAY_SIZE(This->FileName);
  676. wcsncpy(This->FileName, FileName+1, Size - 1);
  677. This->FileName[Size - 1] = UNICODE_NULL;
  678. Result = This->FileName;
  679. DRIVERENT_SET_DIRTY(This);
  680. DRIVERENT_SET_DIRTY(This->BootOptions);
  681. }
  682. }
  683. return Result;;
  684. }
  685. __inline
  686. BOOLEAN
  687. OSDriverSetNtPath(
  688. IN PDRIVER_ENTRY This,
  689. IN PCWSTR NtDevicePath
  690. )
  691. {
  692. BOOLEAN Result = FALSE;
  693. if (This && NtDevicePath && (NtDevicePath[0] != UNICODE_NULL)){
  694. ULONG Size = ARRAY_SIZE(This->NtDevicePath);
  695. wcsncpy(This->NtDevicePath, NtDevicePath, Size-1);
  696. This->NtDevicePath[Size - 1] = UNICODE_NULL;
  697. DRIVERENT_SET_DIRTY(This);
  698. DRIVERENT_SET_DIRTY(This->BootOptions);
  699. Result = TRUE;
  700. }
  701. return Result;
  702. }
  703. __inline
  704. BOOLEAN
  705. OSDriverSetDirPath(
  706. IN PDRIVER_ENTRY This,
  707. IN PCWSTR DirPath
  708. )
  709. {
  710. BOOLEAN Result = FALSE;
  711. if (This && DirPath && (DirPath[0] != UNICODE_NULL)){
  712. ULONG Size = ARRAY_SIZE(This->DirPath);
  713. wcsncpy(This->DirPath, DirPath, Size-1);
  714. This->DirPath[Size - 1] = UNICODE_NULL;
  715. DRIVERENT_SET_DIRTY(This);
  716. DRIVERENT_SET_DIRTY(This->BootOptions);
  717. Result = TRUE;
  718. }
  719. return Result;
  720. }
  721. __inline
  722. ULONG
  723. OSDriverGetId(
  724. IN PDRIVER_ENTRY This
  725. )
  726. {
  727. return (This) ? This->Id : (-1);
  728. }
  729. __inline
  730. PCWSTR
  731. OSDriverGetFriendlyName(
  732. IN PDRIVER_ENTRY This
  733. )
  734. {
  735. return (This) ? This->FriendlyName : NULL;
  736. }
  737. __inline
  738. PCWSTR
  739. OSDriverGetFileName(
  740. IN PDRIVER_ENTRY This
  741. )
  742. {
  743. return (This) ? This->FileName : NULL;
  744. }
  745. __inline
  746. PCWSTR
  747. OSDriverGetDevicePath(
  748. IN PDRIVER_ENTRY This
  749. )
  750. {
  751. return (This) ? This->NtDevicePath : NULL;
  752. }
  753. __inline
  754. PCWSTR
  755. OSDriverGetFilePath(
  756. IN PDRIVER_ENTRY This
  757. )
  758. {
  759. return (This) ? This->DirPath : NULL;
  760. }
  761. //
  762. // memory allocation & deallocation routines
  763. //
  764. __inline
  765. void*
  766. __cdecl
  767. SBE_MALLOC(
  768. IN size_t Size
  769. )
  770. {
  771. return AllocRoutine ? AllocRoutine(Size) : NULL;
  772. }
  773. __inline
  774. void
  775. __cdecl
  776. SBE_FREE(
  777. IN void *Memory
  778. )
  779. {
  780. if (Memory && FreeRoutine) {
  781. FreeRoutine(Memory);
  782. }
  783. }