Source code of Windows XP (NT5)
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.

785 lines
14 KiB

  1. /*++
  2. Copyright (c) 1998 Intel Corporation
  3. Module Name:
  4. shelle.h
  5. Abstract:
  6. Revision History
  7. --*/
  8. #include "shell.h"
  9. #include "shellenv.h"
  10. /*
  11. * Internal defines
  12. */
  13. typedef struct {
  14. UINTN Signature;
  15. LIST_ENTRY Link;
  16. CHAR16 *Line;
  17. CHAR16 Buffer[80];
  18. } DEFAULT_CMD;
  19. #define MAX_CMDLINE 256
  20. #define MAX_ARG_COUNT 32
  21. #define MAX_ARG_LENGTH 256
  22. #define NON_VOL 1
  23. #define VOL 0
  24. #define IsWhiteSpace(c) (c == ' ' || c == '\t' || c == '\n' || c == '\r')
  25. #define IsValidChar(c) (c >= ' ')
  26. #define IsDigit(c) (c >= '0' && c <= '9')
  27. #define IsAlpha(c) ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z' ))
  28. #define GOTO_TARGET_FOUND (1)
  29. #define GOTO_TARGET_NOT_FOUND (2)
  30. #define GOTO_TARGET_DOESNT_EXIST (3)
  31. /*
  32. * Internal structures
  33. */
  34. #define VARIABLE_SIGNATURE EFI_SIGNATURE_32('v','i','d',' ')
  35. typedef struct {
  36. UINTN Signature;
  37. LIST_ENTRY Link;
  38. CHAR16 *Name;
  39. UINTN ValueSize;
  40. union {
  41. UINT8 *Value;
  42. CHAR16 *Str;
  43. } u;
  44. CHAR16 *CurDir;
  45. UINT8 Flags ;
  46. } VARIABLE_ID;
  47. /*
  48. * IDs of different variables stored by the shell environment
  49. */
  50. #define ENVIRONMENT_VARIABLE_ID \
  51. { 0x47c7b224, 0xc42a, 0x11d2, 0x8e, 0x57, 0x0, 0xa0, 0xc9, 0x69, 0x72, 0x3b }
  52. #define DEVICE_PATH_MAPPING_ID \
  53. { 0x47c7b225, 0xc42a, 0x11d2, 0x8e, 0x57, 0x0, 0xa0, 0xc9, 0x69, 0x72, 0x3b }
  54. #define PROTOCOL_ID_ID \
  55. { 0x47c7b226, 0xc42a, 0x11d2, 0x8e, 0x57, 0x0, 0xa0, 0xc9, 0x69, 0x72, 0x3b }
  56. #define ALIAS_ID \
  57. { 0x47c7b227, 0xc42a, 0x11d2, 0x8e, 0x57, 0x0, 0xa0, 0xc9, 0x69, 0x72, 0x3b }
  58. /*
  59. *
  60. */
  61. #define ENV_REDIR_SIGNATURE EFI_SIGNATURE_32('r','i','d','s')
  62. typedef struct {
  63. UINTN Signature;
  64. BOOLEAN Ascii;
  65. EFI_STATUS WriteError;
  66. EFI_FILE_HANDLE File;
  67. EFI_DEVICE_PATH *FilePath;
  68. EFI_HANDLE Handle;
  69. SIMPLE_TEXT_OUTPUT_INTERFACE Out;
  70. SIMPLE_INPUT_INTERFACE In;
  71. } ENV_SHELL_REDIR_FILE;
  72. typedef struct {
  73. EFI_SHELL_INTERFACE ShellInt;
  74. EFI_SYSTEM_TABLE *SystemTable;
  75. ENV_SHELL_REDIR_FILE StdIn;
  76. ENV_SHELL_REDIR_FILE StdOut;
  77. ENV_SHELL_REDIR_FILE StdErr;
  78. } ENV_SHELL_INTERFACE;
  79. /*
  80. * Internal prototypes from init.c
  81. */
  82. EFI_SHELL_INTERFACE *
  83. SEnvNewShell (
  84. IN EFI_HANDLE ImageHandle
  85. );
  86. /*
  87. * Internal prototypes from cmddisp.c
  88. */
  89. VOID
  90. SEnvInitCommandTable (
  91. VOID
  92. );
  93. EFI_STATUS
  94. SEnvAddCommand (
  95. IN SHELLENV_INTERNAL_COMMAND Handler,
  96. IN CHAR16 *Cmd,
  97. IN CHAR16 *CmdFormat,
  98. IN CHAR16 *CmdHelpLine,
  99. IN CHAR16 *CmdVerboseHelp
  100. );
  101. SHELLENV_INTERNAL_COMMAND
  102. SEnvGetCmdDispath(
  103. IN CHAR16 *CmdName
  104. );
  105. /*
  106. * From exec.c
  107. */
  108. EFI_STATUS
  109. SEnvExecute (
  110. IN EFI_HANDLE *ParentImageHandle,
  111. IN CHAR16 *CommandLine,
  112. IN BOOLEAN DebugOutput
  113. );
  114. EFI_STATUS
  115. SEnvDoExecute (
  116. IN EFI_HANDLE *ParentImageHandle,
  117. IN CHAR16 *CommandLine,
  118. IN ENV_SHELL_INTERFACE *Shell,
  119. IN BOOLEAN Output
  120. );
  121. EFI_STATUS
  122. SEnvExit (
  123. IN EFI_HANDLE ImageHandle,
  124. IN EFI_SYSTEM_TABLE *SystemTable
  125. );
  126. EFI_STATUS
  127. SEnvStringToArg (
  128. IN CHAR16 *Str,
  129. IN BOOLEAN Output,
  130. OUT CHAR16 ***pArgv,
  131. OUT UINT32 *pArgc
  132. );
  133. /*
  134. * Internal prototypes from protid.c
  135. */
  136. VOID
  137. INTERNAL
  138. SEnvInitProtocolInfo (
  139. VOID
  140. );
  141. EFI_STATUS
  142. SEnvLoadDefaults (
  143. IN EFI_HANDLE Parent,
  144. IN EFI_SYSTEM_TABLE *SystemTable
  145. );
  146. EFI_STATUS
  147. SEnvReloadDefaults (
  148. IN EFI_HANDLE Parent,
  149. IN EFI_SYSTEM_TABLE *SystemTable
  150. );
  151. VOID
  152. INTERNAL
  153. SEnvLoadInternalProtInfo (
  154. VOID
  155. );
  156. VOID
  157. INTERNAL
  158. SEnvFreeHandleProtocolInfo (
  159. VOID
  160. );
  161. VOID
  162. SEnvAddProtocol (
  163. IN EFI_GUID *Protocol,
  164. IN SHELLENV_DUMP_PROTOCOL_INFO DumpToken OPTIONAL,
  165. IN SHELLENV_DUMP_PROTOCOL_INFO DumpInfo OPTIONAL,
  166. IN CHAR16 *IdString
  167. );
  168. VOID
  169. INTERNAL
  170. SEnvIAddProtocol (
  171. IN BOOLEAN SaveId,
  172. IN EFI_GUID *Protocol,
  173. IN SHELLENV_DUMP_PROTOCOL_INFO DumpToken OPTIONAL,
  174. IN SHELLENV_DUMP_PROTOCOL_INFO DumpInfo OPTIONAL,
  175. IN CHAR16 *IdString
  176. );
  177. VOID
  178. INTERNAL
  179. SEnvLoadHandleProtocolInfo (
  180. IN EFI_GUID *Skip
  181. );
  182. CHAR16 *
  183. SEnvGetProtocol (
  184. IN EFI_GUID *ProtocolId,
  185. IN BOOLEAN GenId
  186. );
  187. EFI_STATUS
  188. INTERNAL
  189. SEnvCmdProt (
  190. IN EFI_HANDLE ImageHandle,
  191. IN EFI_SYSTEM_TABLE *SystemTable
  192. );
  193. VOID
  194. SEnvDHProt (
  195. IN BOOLEAN Verbose,
  196. IN UINTN HandleNo,
  197. IN EFI_HANDLE Handle
  198. );
  199. EFI_STATUS
  200. INTERNAL
  201. SEnvCmdDH (
  202. IN EFI_HANDLE ImageHandle,
  203. IN EFI_SYSTEM_TABLE *SystemTable
  204. );
  205. EFI_STATUS
  206. SEnvIGetProtID (
  207. IN CHAR16 *Str,
  208. OUT EFI_GUID *ProtId
  209. );
  210. /*
  211. * Handle.c
  212. */
  213. VOID
  214. INTERNAL
  215. SEnvInitHandleGlobals(
  216. VOID
  217. );
  218. VOID
  219. INTERNAL
  220. SEnvLoadHandleTable (
  221. VOID
  222. );
  223. VOID
  224. INTERNAL
  225. SEnvFreeHandleTable (
  226. VOID
  227. );
  228. UINTN
  229. SEnvHandleNoFromStr(
  230. IN CHAR16 *Str
  231. );
  232. EFI_HANDLE
  233. SEnvHandleFromStr(
  234. IN CHAR16 *Str
  235. );
  236. /*
  237. * Internal prototypes from var.c
  238. */
  239. VOID
  240. SEnvInitVariables (
  241. VOID
  242. );
  243. EFI_STATUS
  244. SEnvCmdSet (
  245. IN EFI_HANDLE ImageHandle,
  246. IN EFI_SYSTEM_TABLE *SystemTable
  247. );
  248. EFI_STATUS
  249. SEnvCmdAlias (
  250. IN EFI_HANDLE ImageHandle,
  251. IN EFI_SYSTEM_TABLE *SystemTable
  252. );
  253. CHAR16 *
  254. SEnvGetMap (
  255. IN CHAR16 *Name
  256. );
  257. CHAR16 *
  258. SEnvGetEnv (
  259. IN CHAR16 *Name
  260. );
  261. CHAR16 *
  262. SEnvGetAlias (
  263. IN CHAR16 *Name
  264. );
  265. /*
  266. * Prototypes from conio.c
  267. */
  268. VOID
  269. SEnvConIoInitDosKey (
  270. VOID
  271. );
  272. EFI_STATUS
  273. SEnvConIoOpen (
  274. IN struct _EFI_FILE_HANDLE *File,
  275. OUT struct _EFI_FILE_HANDLE **NewHandle,
  276. IN CHAR16 *FileName,
  277. IN UINT64 OpenMode,
  278. IN UINT64 Attributes
  279. );
  280. EFI_STATUS
  281. SEnvConIoNop (
  282. IN struct _EFI_FILE_HANDLE *File
  283. );
  284. EFI_STATUS
  285. SEnvConIoGetPosition (
  286. IN struct _EFI_FILE_HANDLE *File,
  287. OUT UINT64 *Position
  288. );
  289. EFI_STATUS
  290. SEnvConIoSetPosition (
  291. IN struct _EFI_FILE_HANDLE *File,
  292. OUT UINT64 Position
  293. );
  294. EFI_STATUS
  295. SEnvConIoGetInfo (
  296. IN struct _EFI_FILE_HANDLE *File,
  297. IN EFI_GUID *InformationType,
  298. IN OUT UINTN *BufferSize,
  299. OUT VOID *Buffer
  300. );
  301. EFI_STATUS
  302. SEnvConIoSetInfo (
  303. IN struct _EFI_FILE_HANDLE *File,
  304. IN EFI_GUID *InformationType,
  305. IN UINTN BufferSize,
  306. OUT VOID *Buffer
  307. );
  308. EFI_STATUS
  309. SEnvConIoWrite (
  310. IN struct _EFI_FILE_HANDLE *File,
  311. IN OUT UINTN *BufferSize,
  312. IN VOID *Buffer
  313. );
  314. EFI_STATUS
  315. SEnvConIoRead (
  316. IN struct _EFI_FILE_HANDLE *File,
  317. IN OUT UINTN *BufferSize,
  318. IN VOID *Buffer
  319. );
  320. EFI_STATUS
  321. SEnvErrIoWrite (
  322. IN struct _EFI_FILE_HANDLE *File,
  323. IN OUT UINTN *BufferSize,
  324. IN VOID *Buffer
  325. );
  326. EFI_STATUS
  327. SEnvErrIoRead (
  328. IN struct _EFI_FILE_HANDLE *File,
  329. IN OUT UINTN *BufferSize,
  330. IN VOID *Buffer
  331. );
  332. EFI_STATUS
  333. SEnvReset (
  334. IN SIMPLE_TEXT_OUTPUT_INTERFACE *This,
  335. IN BOOLEAN ExtendedVerification
  336. );
  337. EFI_STATUS
  338. SEnvOutputString (
  339. IN SIMPLE_TEXT_OUTPUT_INTERFACE *This,
  340. IN CHAR16 *String
  341. );
  342. EFI_STATUS
  343. SEnvTestString (
  344. IN SIMPLE_TEXT_OUTPUT_INTERFACE *This,
  345. IN CHAR16 *String
  346. );
  347. EFI_STATUS
  348. SEnvQueryMode (
  349. IN SIMPLE_TEXT_OUTPUT_INTERFACE *This,
  350. IN UINTN ModeNumber,
  351. OUT UINTN *Columns,
  352. OUT UINTN *Rows
  353. );
  354. EFI_STATUS
  355. SEnvSetMode (
  356. IN SIMPLE_TEXT_OUTPUT_INTERFACE *This,
  357. IN UINTN ModeNumber
  358. );
  359. EFI_STATUS
  360. SEnvSetAttribute (
  361. IN SIMPLE_TEXT_OUTPUT_INTERFACE *This,
  362. IN UINTN Attribute
  363. );
  364. EFI_STATUS
  365. SEnvClearScreen (
  366. IN SIMPLE_TEXT_OUTPUT_INTERFACE *This
  367. );
  368. EFI_STATUS
  369. SEnvSetCursorPosition (
  370. IN SIMPLE_TEXT_OUTPUT_INTERFACE *This,
  371. IN UINTN Column,
  372. IN UINTN Row
  373. );
  374. EFI_STATUS
  375. SEnvEnableCursor (
  376. IN SIMPLE_TEXT_OUTPUT_INTERFACE *This,
  377. IN BOOLEAN Enable
  378. );
  379. /*
  380. * Prototypes from batch.c
  381. */
  382. VOID
  383. SEnvInitBatch(
  384. VOID
  385. );
  386. BOOLEAN
  387. SEnvBatchIsActive(
  388. VOID
  389. );
  390. VOID
  391. SEnvSetBatchAbort(
  392. VOID
  393. );
  394. VOID
  395. SEnvBatchGetConsole(
  396. OUT SIMPLE_INPUT_INTERFACE **ConIn,
  397. OUT SIMPLE_TEXT_OUTPUT_INTERFACE **ConOut
  398. );
  399. EFI_STATUS
  400. SEnvBatchEchoCommand(
  401. IN ENV_SHELL_INTERFACE *Shell
  402. );
  403. VOID
  404. SEnvBatchSetEcho(
  405. IN BOOLEAN Val
  406. );
  407. BOOLEAN
  408. SEnvBatchGetEcho(
  409. VOID
  410. );
  411. EFI_STATUS
  412. SEnvBatchSetFilePos(
  413. IN UINT64 NewPos
  414. );
  415. EFI_STATUS
  416. SEnvBatchGetFilePos(
  417. UINT64 *FilePos
  418. );
  419. VOID
  420. SEnvBatchSetCondition(
  421. IN BOOLEAN Val
  422. );
  423. VOID
  424. SEnvBatchSetGotoActive(
  425. VOID
  426. );
  427. BOOLEAN
  428. SEnvBatchVarIsLastError(
  429. IN CHAR16 *Name
  430. );
  431. CHAR16*
  432. SEnvBatchGetLastError(
  433. VOID
  434. );
  435. VOID
  436. SEnvBatchSetLastError(
  437. IN UINTN NewLastError
  438. );
  439. EFI_STATUS
  440. SEnvBatchGetArg(
  441. IN UINTN Argno,
  442. OUT CHAR16 **Argval
  443. );
  444. EFI_STATUS
  445. SEnvExecuteScript(
  446. IN ENV_SHELL_INTERFACE *Shell,
  447. IN EFI_FILE_HANDLE File
  448. );
  449. /*
  450. * Prototypes from dprot.c
  451. */
  452. VOID SEnvDPath (EFI_HANDLE, VOID *);
  453. VOID SEnvDPathTok (EFI_HANDLE, VOID *);
  454. VOID SEnvTextOut (EFI_HANDLE, VOID *);
  455. VOID SEnvBlkIo (EFI_HANDLE, VOID *);
  456. VOID SEnvImageTok (EFI_HANDLE, VOID *);
  457. VOID SEnvImage (EFI_HANDLE, VOID *);
  458. /*
  459. * Prototypes from map.c
  460. */
  461. VOID
  462. SEnvInitMap (
  463. VOID
  464. );
  465. CHAR16 *
  466. SEnvGetDefaultMapping (
  467. IN EFI_HANDLE ImageHandle
  468. );
  469. EFI_STATUS
  470. INTERNAL
  471. SEnvCmdMap (
  472. IN EFI_HANDLE ImageHandle,
  473. IN EFI_SYSTEM_TABLE *SystemTable
  474. );
  475. EFI_STATUS
  476. INTERNAL
  477. SEnvCmdMount (
  478. IN EFI_HANDLE ImageHandle,
  479. IN EFI_SYSTEM_TABLE *SystemTable
  480. );
  481. VARIABLE_ID *
  482. SEnvMapDeviceFromName (
  483. IN OUT CHAR16 **pPath
  484. );
  485. EFI_DEVICE_PATH *
  486. SEnvIFileNameToPath (
  487. IN CHAR16 *Path
  488. );
  489. EFI_DEVICE_PATH *
  490. SEnvFileNameToPath (
  491. IN CHAR16 *Path
  492. );
  493. EFI_DEVICE_PATH *
  494. SEnvNameToPath (
  495. IN CHAR16 *PathName
  496. );
  497. EFI_STATUS
  498. SEnvSetCurrentDevice (
  499. IN CHAR16 *Name
  500. );
  501. CHAR16 *
  502. SEnvGetCurDir (
  503. IN CHAR16 *DeviceName OPTIONAL
  504. );
  505. EFI_STATUS
  506. SEnvCmdCd (
  507. IN EFI_HANDLE ImageHandle,
  508. IN EFI_SYSTEM_TABLE *SystemTable
  509. );
  510. /*
  511. * Prototypes from echo.c
  512. */
  513. EFI_STATUS
  514. SEnvCmdEcho (
  515. IN EFI_HANDLE ImageHandle,
  516. IN EFI_SYSTEM_TABLE *SystemTable
  517. );
  518. /*
  519. * Prototypes from if.c
  520. */
  521. EFI_STATUS
  522. SEnvCmdIf (
  523. IN EFI_HANDLE ImageHandle,
  524. IN EFI_SYSTEM_TABLE *SystemTable
  525. );
  526. EFI_STATUS
  527. SEnvCmdEndif (
  528. IN EFI_HANDLE ImageHandle,
  529. IN EFI_SYSTEM_TABLE *SystemTable
  530. );
  531. /*
  532. * Prototypes from goto.c
  533. */
  534. EFI_STATUS
  535. SEnvCmdGoto (
  536. IN EFI_HANDLE ImageHandle,
  537. IN EFI_SYSTEM_TABLE *SystemTable
  538. );
  539. EFI_STATUS
  540. SEnvCheckForGotoTarget(
  541. IN CHAR16 *Candidate,
  542. IN UINT64 GotoFilePos,
  543. IN UINT64 FilePosition,
  544. OUT UINTN *GotoTargetStatus
  545. );
  546. VOID
  547. SEnvPrintLabelNotFound(
  548. VOID
  549. );
  550. VOID
  551. SEnvInitTargetLabel(
  552. VOID
  553. );
  554. VOID
  555. SEnvFreeTargetLabel(
  556. VOID
  557. );
  558. /*
  559. * Prototypes from for.c
  560. */
  561. VOID
  562. SEnvInitForLoopInfo (
  563. VOID
  564. );
  565. EFI_STATUS
  566. SEnvSubstituteForLoopIndex(
  567. IN CHAR16 *Str,
  568. OUT CHAR16 **Val
  569. );
  570. EFI_STATUS
  571. SEnvCmdFor (
  572. IN EFI_HANDLE ImageHandle,
  573. IN EFI_SYSTEM_TABLE *SystemTable
  574. );
  575. EFI_STATUS
  576. SEnvCmdEndfor (
  577. IN EFI_HANDLE ImageHandle,
  578. IN EFI_SYSTEM_TABLE *SystemTable
  579. );
  580. /*
  581. * Prototypes from pause.c
  582. */
  583. EFI_STATUS
  584. SEnvCmdPause (
  585. IN EFI_HANDLE ImageHandle,
  586. IN EFI_SYSTEM_TABLE *SystemTable
  587. );
  588. /*
  589. * Prototypes from marg.c
  590. */
  591. CHAR16 *
  592. SEnvFileHandleToFileName (
  593. IN EFI_FILE_HANDLE Handle
  594. );
  595. EFI_STATUS
  596. SEnvFreeFileList (
  597. IN OUT LIST_ENTRY *ListHead
  598. );
  599. EFI_STATUS
  600. SEnvFileMetaArg (
  601. IN CHAR16 *Arg,
  602. IN OUT LIST_ENTRY *ListHead
  603. );
  604. VOID
  605. EFIStructsPrint (
  606. IN VOID *Buffer,
  607. IN UINTN BlockSize,
  608. IN UINT64 BlockAddress,
  609. IN EFI_BLOCK_IO *BlkIo
  610. );
  611. EFI_STATUS
  612. DumpBlockDev (
  613. IN EFI_HANDLE ImageHandle,
  614. IN EFI_SYSTEM_TABLE *SystemTable
  615. );
  616. /*
  617. * Global data
  618. */
  619. extern EFI_GUID SEnvEnvId;
  620. extern EFI_GUID SEnvMapId;
  621. extern EFI_GUID SEnvProtId;
  622. extern EFI_GUID SEnvAliasId;
  623. extern EFI_SHELL_ENVIRONMENT SEnvInterface;
  624. extern EFI_FILE SEnvIOFromCon;
  625. extern EFI_FILE SEnvErrIOFromCon;
  626. extern FLOCK SEnvLock;
  627. extern FLOCK SEnvGuidLock;
  628. extern UINTN SEnvNoHandles;
  629. extern EFI_HANDLE *SEnvHandles;
  630. extern SIMPLE_TEXT_OUTPUT_INTERFACE SEnvConToIo;