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.

140 lines
2.9 KiB

  1. /*++
  2. Copyright (c) 1997 Microsoft Corporation
  3. Module Name:
  4. disksel.c
  5. Abstract:
  6. Routine to allow the user to select a disk
  7. from a list of disks. The UI is a simple character-based
  8. deal.
  9. Author:
  10. Ted Miller (tedm) 29-May-1997
  11. Revision History:
  12. --*/
  13. #include <mytypes.h>
  14. #include <misclib.h>
  15. #include <diskio.h>
  16. #include <partimag.h>
  17. #include <stdio.h>
  18. #include <stdlib.h>
  19. #include <string.h>
  20. typedef
  21. BOOL
  22. (*PDISKSEL_VALIDATION_ROUTINE) (
  23. IN USHORT DiskId
  24. );
  25. INT
  26. _far
  27. SelectDisk(
  28. IN UINT DiskCount,
  29. IN FPCHAR Prompt,
  30. IN PDISKSEL_VALIDATION_ROUTINE Validate, OPTIONAL
  31. OUT char *AlternateResponse, OPTIONAL
  32. IN FPCHAR textDisk,
  33. IN FPCHAR textPaddedMbCount,
  34. IN FPCHAR textInvalidSelection,
  35. IN FPCHAR textMasterDisk
  36. )
  37. {
  38. UINT i,l;
  39. BYTE Int13Unit;
  40. BYTE SectorsPerTrack;
  41. USHORT Heads;
  42. USHORT Cylinders;
  43. ULONG SectorCount;
  44. UINT Selection;
  45. CHAR line[256];
  46. FPVOID Buffer,OriginalBuffer;
  47. if(!AllocTrackBuffer(1,&Buffer,&OriginalBuffer)) {
  48. Buffer = NULL;
  49. OriginalBuffer = NULL;
  50. }
  51. select:
  52. printf("\n\n");
  53. for(i=0; i<DiskCount; i++) {
  54. if(Validate ? Validate(i) : TRUE) {
  55. printf("%2u) ",i+1);
  56. GetDiskInfoById(
  57. i,
  58. 0,
  59. &Int13Unit,
  60. &SectorsPerTrack,
  61. &Heads,
  62. &Cylinders,
  63. &SectorCount
  64. );
  65. if(!SectorCount) {
  66. SectorCount = (ULONG)Heads * (ULONG)Cylinders * (ULONG)SectorsPerTrack;
  67. }
  68. printf(" ");
  69. if(Int13Unit) {
  70. printf(textDisk);
  71. printf(" ");
  72. printf("%2x",Int13Unit);
  73. } else {
  74. l = strlen(textDisk) + 3;
  75. while(l) {
  76. printf(" ");
  77. l--;
  78. }
  79. }
  80. printf(" ");
  81. printf(textPaddedMbCount,SectorCount / 2048);
  82. if(Buffer && IsMasterDisk(i,Buffer)) {
  83. printf(" %s",textMasterDisk);
  84. }
  85. printf("\n");
  86. }
  87. }
  88. printf("\n%s ",Prompt);
  89. gets(line);
  90. Selection = atoi(line);
  91. if(!Selection || (Selection > DiskCount)) {
  92. if(AlternateResponse) {
  93. strcpy(AlternateResponse,line);
  94. if(OriginalBuffer) {
  95. free(OriginalBuffer);
  96. }
  97. return(-1);
  98. } else {
  99. printf("\n\n%s\n",textInvalidSelection);
  100. goto select;
  101. }
  102. }
  103. if(Validate && !Validate(Selection-1)) {
  104. printf("\n\n%s\n",textInvalidSelection);
  105. goto select;
  106. }
  107. if(OriginalBuffer) {
  108. free(OriginalBuffer);
  109. }
  110. return(Selection-1);
  111. }