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.

1137 lines
34 KiB

  1. /*++
  2. Copyright (c) 1991-2001 Microsoft Corporation
  3. Module Name:
  4. format.cxx
  5. Abstract:
  6. Utility to format a disk
  7. Author:
  8. Norbert P. Kusters (norbertk) 12-April-1991
  9. Revision History:
  10. --*/
  11. #define _NTAPI_ULIB_
  12. #include "ulib.hxx"
  13. #if defined(FE_SB) && defined(_X86_)
  14. #include "machine.hxx"
  15. #endif
  16. #include "drive.hxx"
  17. #include "arg.hxx"
  18. #include "array.hxx"
  19. #include "smsg.hxx"
  20. #include "rtmsg.h"
  21. #include "system.hxx"
  22. #include "ifssys.hxx"
  23. #include "ulibcl.hxx"
  24. #include "ifsentry.hxx"
  25. #include "path.hxx"
  26. #include "parse.hxx"
  27. #include "hmem.hxx"
  28. #include "volume.hxx"
  29. extern "C" {
  30. #include "nturtl.h"
  31. }
  32. VOID
  33. DisplayFormatUsage(
  34. IN OUT PMESSAGE Message
  35. )
  36. /*++
  37. Routine Description:
  38. This routine outputs usage information on format.
  39. Arguments:
  40. Message - Supplies an outlet for messages.
  41. Return Value:
  42. None.
  43. --*/
  44. {
  45. Message->Set(MSG_FORMAT_INFO);
  46. Message->Display("");
  47. Message->Set(MSG_FORMAT_COMMAND_LINE_1);
  48. Message->Display("");
  49. Message->Set(MSG_FORMAT_COMMAND_LINE_2);
  50. Message->Display("");
  51. #if defined(FE_SB) && defined(_X86_)
  52. if(!IsPC98_N()) {
  53. #endif
  54. Message->Set(MSG_FORMAT_COMMAND_LINE_3);
  55. Message->Display("");
  56. #if defined(FE_SB) && defined(_X86_)
  57. }
  58. #endif
  59. Message->Set(MSG_FORMAT_COMMAND_LINE_4);
  60. Message->Display("");
  61. Message->Set(MSG_FORMAT_SLASH_V);
  62. Message->Display("");
  63. Message->Set(MSG_FORMAT_SLASH_Q);
  64. Message->Display("");
  65. Message->Set(MSG_FORMAT_SLASH_C);
  66. Message->Display("");
  67. Message->Set(MSG_FORMAT_SLASH_X);
  68. Message->Display("");
  69. Message->Set(MSG_FORMAT_SLASH_F);
  70. Message->Display("");
  71. // Message->Set(MSG_FORMAT_SUPPORTED_SIZES);
  72. // Message->Display("");
  73. Message->Set(MSG_FORMAT_SLASH_T);
  74. Message->Display("");
  75. Message->Set(MSG_FORMAT_SLASH_N);
  76. Message->Display("");
  77. #if defined(FE_SB) && defined(_X86_)
  78. if(!IsPC98_N()) {
  79. #endif
  80. // Message->Set(MSG_FORMAT_SLASH_1);
  81. // Message->Display("");
  82. // Message->Set(MSG_FORMAT_SLASH_4);
  83. // Message->Display("");
  84. // Message->Set(MSG_FORMAT_SLASH_8);
  85. // Message->Display("");
  86. #if defined(FE_SB) && defined(_X86_)
  87. }
  88. #endif
  89. }
  90. BOOLEAN
  91. DetermineMediaType(
  92. OUT PMEDIA_TYPE MediaType,
  93. IN OUT PMESSAGE Message,
  94. IN BOOLEAN Request160,
  95. IN BOOLEAN Request180,
  96. IN BOOLEAN Request320,
  97. IN BOOLEAN Request360,
  98. IN BOOLEAN Request720,
  99. IN BOOLEAN Request1200,
  100. IN BOOLEAN Request1440,
  101. IN BOOLEAN Request2880,
  102. IN BOOLEAN Request20800
  103. #if defined(FE_SB) && defined(_X86_)
  104. // FMR Jul.12.1994 SFT KMR
  105. // Add Request640 on to the parmeter of DetermineMediaType()
  106. // Add Request1232 on to the parmeter of DetermineMediaType()
  107. ,IN BOOLEAN Request256
  108. ,IN BOOLEAN Request640
  109. ,IN BOOLEAN Request1232
  110. #endif
  111. )
  112. /*++
  113. Routine Description:
  114. This routine determines the media type to format to.
  115. Arguments:
  116. MediaType - Supplies the current media type and returns
  117. a new media type.
  118. Message - Supplies an outlet for messages.
  119. Request160 - Supplies whether or not the user wished to format 160.
  120. Request180 - Supplies whether or not the user wished to format 180.
  121. Request320 - Supplies whether or not the user wished to format 320.
  122. Request360 - Supplies whether or not the user wished to format 360.
  123. Request720 - Supplies whether or not the user wished to format 720.
  124. Request1200 - Supplies whether or not the user wished to format 1200.
  125. Request1440 - Supplies whether or not the user wished to format 1440.
  126. Request2880 - Supplies whether or not the user wished to format 2880.
  127. Request20800 - Supplies whether or not the use wished to format 20800.
  128. #if defined(FE_SB) && defined(_X86_)
  129. // FMR Jul.12.1994 SFT KMR
  130. Request256 - Supplies whether or not the user wished to format 256. --NEC--
  131. // Add Request640 on to the parmeter of DetermineMediaType()
  132. Request640 - Supplies whether or not the user wished to format 640.
  133. // Add Request1232 on to the parmeter of DetermineMediaType()
  134. Request1232 - Supplies whether or not the user wished to format 1232.
  135. #endif
  136. Return Value:
  137. FALSE - Failure.
  138. TRUE - Success.
  139. --*/
  140. {
  141. INT sum;
  142. // First, normalize all of the booleans.
  143. if (Request160) {
  144. Request160 = 1;
  145. *MediaType = F5_160_512;
  146. }
  147. if (Request180) {
  148. Request180 = 1;
  149. *MediaType = F5_180_512;
  150. }
  151. #if defined(FE_SB) && (_X86_)
  152. if (Request256) {
  153. Request256 = 1;
  154. *MediaType = F8_256_128;
  155. }
  156. #endif
  157. if (Request320) {
  158. Request320 = 1;
  159. *MediaType = F5_320_512;
  160. }
  161. if (Request360) {
  162. Request360 = 1;
  163. *MediaType = F5_360_512;
  164. }
  165. #if defined(FE_SB) && (_X86_)
  166. if (Request640) {
  167. Request640 = 1;
  168. *MediaType = F5_640_512;
  169. }
  170. #endif
  171. if (Request720) {
  172. Request720 = 1;
  173. *MediaType = F3_720_512;
  174. }
  175. if (Request1200) {
  176. Request1200 = 1;
  177. *MediaType = F5_1Pt2_512;
  178. }
  179. #if defined(FE_SB) && (_X86_)
  180. if (Request1232) {
  181. Request1232 = 1;
  182. *MediaType = F5_1Pt23_1024;
  183. }
  184. #endif
  185. if (Request1440) {
  186. Request1440 = 1;
  187. *MediaType = F3_1Pt44_512;
  188. }
  189. if (Request2880) {
  190. Request2880 = 1;
  191. *MediaType = F3_2Pt88_512;
  192. }
  193. if (Request20800) {
  194. Request20800 = 1;
  195. *MediaType = F3_20Pt8_512;
  196. }
  197. sum = Request160 +
  198. Request180 +
  199. #if defined(FE_SB) && defined(_X86_)
  200. Request256 +
  201. #endif
  202. Request320 +
  203. Request360 +
  204. #if defined(FE_SB) && defined(_X86_)
  205. Request640 +
  206. #endif
  207. Request720 +
  208. Request1200 +
  209. #if defined(FE_SB) && defined(_X86_)
  210. Request1232 +
  211. #endif
  212. Request1440 +
  213. Request2880 +
  214. Request20800;
  215. if (sum > 1) {
  216. Message->Set(MSG_INCOMPATIBLE_PARAMETERS);
  217. Message->Display();
  218. return FALSE;
  219. }
  220. if (sum == 0) {
  221. *MediaType = Unknown;
  222. }
  223. return TRUE;
  224. }
  225. int __cdecl
  226. main(
  227. )
  228. /*++
  229. Routine Description:
  230. This routine is the main procedure for format. This routine
  231. parses the arguments, determines the appropriate file system,
  232. and invokes the appropriate version of format.
  233. The arguments accepted by format are:
  234. /fs:fs - specifies file system to install on volume
  235. /v:label - specifies a volume label.
  236. /q - specifies a "quick" format.
  237. /c - the file system is compressed.
  238. /f:size - specifies the size of the floppy disk to format
  239. /t - specifies the number of tracks per disk side
  240. /n - specifies the number of sectors per track
  241. /1 - formats a single side of a floppy
  242. /4 - formats a 360K floppy in a high density drive
  243. /8 - formats eight sectors per track
  244. /backup - refrain from prompting the user
  245. Arguments:
  246. None.
  247. Return Value:
  248. 0 - Success.
  249. 1 - Failure.
  250. 4 - Fatal error
  251. 5 - User pressed N to stop formatting
  252. --*/
  253. {
  254. STREAM_MESSAGE msg;
  255. PMESSAGE message;
  256. MEDIA_TYPE media_type, cmd_line_media_type;
  257. DSTRING dosdrivename;
  258. DSTRING displaydrivename;
  259. DSTRING arg_fsname;
  260. DSTRING arg_label;
  261. BOOLEAN label_spec;
  262. BOOLEAN quick_format;
  263. BOOLEAN compressed;
  264. BOOLEAN force_mode;
  265. INT errorlevel;
  266. DSTRING ntdrivename;
  267. DSTRING fsname;
  268. DSTRING fsNameAndVersion;
  269. DSTRING currentdrive;
  270. DSTRING raw_str;
  271. DSTRING fat_str;
  272. DSTRING fat32_str;
  273. DSTRING ntfs_str;
  274. DSTRING hpfs_str;
  275. PWSTRING old_volume_label = NULL;
  276. PATH dos_drive_path;
  277. VOL_SERIAL_NUMBER old_serial;
  278. DSTRING user_old_label;
  279. DSTRING null_string;
  280. BOOLEAN do_format;
  281. BOOLEAN do_floppy_return;
  282. DSTRING LibSuffix;
  283. DSTRING LibraryName;
  284. HANDLE FsUtilityHandle = NULL;
  285. DSTRING FormatString;
  286. FORMATEX_FN Format = NULL;
  287. DRIVE_TYPE drive_type;
  288. BIG_INT bigint;
  289. NTSTATUS Status;
  290. DWORD OldErrorMode;
  291. ULONG cluster_size;
  292. BOOLEAN no_prompts;
  293. BOOLEAN force_dismount;
  294. BOOLEAN old_fs = TRUE;
  295. FORMATEX_FN_PARAM Param;
  296. BOOLEAN writeable;
  297. #if defined(FE_SB) && defined(_X86_)
  298. // FMR Jul.14.1994 SFT KMR
  299. // Add the value to use the process to judge for 5inci or 3.5inch
  300. PCDRTYPE nt_media_types;
  301. INT num_types;
  302. INT i;
  303. // FMR Oct.07.1994 SFT YAM
  304. // Add the flag check whether unformat-disk.
  305. INT Unknown_flag = FALSE;
  306. InitializeMachineData();
  307. #endif
  308. if (!msg.Initialize(Get_Standard_Output_Stream(),
  309. Get_Standard_Input_Stream())) {
  310. return 4;
  311. }
  312. if( !null_string.Initialize( "" ) ) {
  313. return 4;
  314. }
  315. if (!ParseArguments(&msg, &cmd_line_media_type, &dosdrivename, &displaydrivename,
  316. &arg_label, &label_spec, &arg_fsname, &quick_format,
  317. &force_mode, &cluster_size, &compressed, &no_prompts,
  318. &force_dismount, &errorlevel )) {
  319. return errorlevel;
  320. }
  321. if (force_mode) {
  322. force_dismount = TRUE; // don't ask the user; just do it
  323. if (!label_spec) { // if no label is specified, assume it's empty
  324. if (!arg_label.Initialize("")) {
  325. return 4;
  326. }
  327. label_spec = TRUE;
  328. }
  329. }
  330. message = &msg;
  331. if (!hpfs_str.Initialize("HPFS")) {
  332. return 4;
  333. }
  334. if (arg_fsname == hpfs_str) {
  335. message->Set(MSG_HPFS_NO_FORMAT);
  336. message->Display("");
  337. return 1;
  338. }
  339. // Disable popups while we determine the drive type.
  340. OldErrorMode = SetErrorMode( SEM_FAILCRITICALERRORS );
  341. drive_type = SYSTEM::QueryDriveType(&dosdrivename);
  342. // Re-enable harderror popups.
  343. SetErrorMode( OldErrorMode );
  344. switch (drive_type) {
  345. case UnknownDrive:
  346. message->Set(MSG_NONEXISTENT_DRIVE);
  347. message->Display("");
  348. return 1;
  349. case RemoteDrive:
  350. message->Set(MSG_FORMAT_NO_NETWORK);
  351. message->Display("");
  352. return 1;
  353. case RamDiskDrive:
  354. message->Set(MSG_FORMAT_NO_RAMDISK);
  355. message->Display("");
  356. return 1;
  357. default:
  358. break;
  359. }
  360. if (!SYSTEM::QueryCurrentDosDriveName(&currentdrive) ||
  361. currentdrive == dosdrivename) {
  362. message->Set(MSG_CANT_LOCK_CURRENT_DRIVE);
  363. message->Display();
  364. }
  365. if (!IFS_SYSTEM::DosDriveNameToNtDriveName(&dosdrivename, &ntdrivename)) {
  366. return 4;
  367. }
  368. if (!raw_str.Initialize("RAW") ||
  369. !fat_str.Initialize("FAT") ||
  370. !fat32_str.Initialize("FAT32") ||
  371. !ntfs_str.Initialize("NTFS")) {
  372. return 4;
  373. }
  374. for (;;) {
  375. DP_DRIVE dpdrive;
  376. // ------------------------------------
  377. // Figure out if the drive is a floppy.
  378. // ------------------------------------
  379. if (drive_type == FixedDrive && cmd_line_media_type != Unknown) {
  380. message->Set(MSG_INCOMPATIBLE_PARAMETERS_FOR_FIXED);
  381. message->Display("");
  382. return 1;
  383. }
  384. if (drive_type == RemovableDrive && !no_prompts) {
  385. message->Set(MSG_INSERT_DISK);
  386. message->Display("%W", &displaydrivename);
  387. message->Set(MSG_PRESS_ENTER_WHEN_READY);
  388. message->Display("");
  389. message->WaitForUserSignal();
  390. }
  391. // -----------------------
  392. // Now get the media type.
  393. // -----------------------
  394. // Disable hard-error popups while we initialize the drive.
  395. // Otherwise, we'll may get the 'unformatted medium' popup,
  396. // which doesn't make a lot of sense.
  397. OldErrorMode = SetErrorMode( SEM_FAILCRITICALERRORS );
  398. if (!dpdrive.Initialize(&ntdrivename, message)) {
  399. // Re-enable hard-error popups
  400. SetErrorMode( OldErrorMode );
  401. return 4;
  402. }
  403. #if defined(FE_SB) && defined(_X86_)
  404. // FMR Oct.07.1994 SFT YAM
  405. // Add the check whether unformat-disk.
  406. if(dpdrive.QueryMediaType()==Unknown) {
  407. Unknown_flag = TRUE;
  408. }
  409. // FMR Jul.14.1994 SFT KMR
  410. // Add the process to judge for 5inch or 3.5inch
  411. // FMR is surport 3.5/5 inch disk drive. System default 2HD.
  412. // Return 3.5 or 5inch type media. driver used.
  413. // Search drive list on media type.
  414. // FJMERGE.16 95/07/13 J.Yamamoto 3mode PC/AT uses.
  415. //if (IsFMR_N() || IsPC98_N()) {
  416. if (!(nt_media_types = dpdrive.GetSupportedList(&num_types))) {
  417. return 4;
  418. }
  419. for (i = 0; i < num_types; i++) {
  420. if ( nt_media_types[i].MediaType == cmd_line_media_type) break;
  421. }
  422. if (i == num_types) {
  423. MEDIA_TYPE alt_media_type;
  424. switch(cmd_line_media_type) {
  425. case F5_1Pt23_1024:
  426. alt_media_type = F3_1Pt23_1024;
  427. break;
  428. case F3_1Pt23_1024:
  429. alt_media_type = F5_1Pt23_1024;
  430. break;
  431. case F5_1Pt2_512:
  432. alt_media_type = F3_1Pt2_512;
  433. break;
  434. case F3_1Pt2_512:
  435. alt_media_type = F5_1Pt2_512;
  436. break;
  437. case F3_720_512:
  438. alt_media_type = F5_720_512;
  439. break;
  440. case F5_720_512:
  441. alt_media_type = F3_720_512;
  442. break;
  443. case F5_640_512:
  444. alt_media_type = F3_640_512;
  445. break;
  446. case F3_640_512:
  447. alt_media_type = F5_640_512;
  448. break;
  449. default:
  450. alt_media_type = Unknown;
  451. break;
  452. }
  453. for (i = 0; i < num_types; i++) {
  454. if ( nt_media_types[i].MediaType == alt_media_type){
  455. cmd_line_media_type = alt_media_type;
  456. break;
  457. }
  458. }
  459. }
  460. // FJMERGE.16 95/07/13 J.Yamamoto
  461. //}
  462. #endif
  463. // Re-enable hard-error popups
  464. SetErrorMode( OldErrorMode );
  465. if (cmd_line_media_type == Unknown) {
  466. media_type = dpdrive.QueryMediaType();
  467. } else {
  468. media_type = cmd_line_media_type;
  469. }
  470. if (media_type == Unknown) {
  471. media_type = dpdrive.QueryRecommendedMediaType();
  472. if (media_type == Unknown) {
  473. // This should never happen.
  474. DebugPrint("No media types supported by this device.\n");
  475. return 4;
  476. }
  477. }
  478. do_floppy_return = dpdrive.IsFloppy();
  479. // Disable hard error popups. This will prevent the file system
  480. // from throwing up the popup that says 'unformatted medium'.
  481. OldErrorMode = SetErrorMode( SEM_FAILCRITICALERRORS );
  482. if (!IFS_SYSTEM::QueryFileSystemName(&ntdrivename, &fsname,
  483. &Status, &fsNameAndVersion)) {
  484. if( Status == STATUS_ACCESS_DENIED ) {
  485. message->Set( MSG_DASD_ACCESS_DENIED );
  486. message->Display( "" );
  487. } else {
  488. message->Set( MSG_FS_NOT_DETERMINED );
  489. message->Display( "%W", &displaydrivename );
  490. }
  491. // Re-enable hard error popups.
  492. SetErrorMode( OldErrorMode );
  493. return 1;
  494. }
  495. // Re-enable hard error popups.
  496. SetErrorMode( OldErrorMode );
  497. if (!fsname.Strupr()) {
  498. message->Set(MSG_FS_NOT_DETERMINED);
  499. message->Display("%W", &displaydrivename);
  500. return 4;
  501. }
  502. if (drive_type == CdRomDrive) {
  503. if (0 == ntfs_str.Stricmp( 0 != arg_fsname.QueryChCount() ?
  504. &arg_fsname : &fsname )) {
  505. message->Set(MSG_FMT_NO_NTFS_ALLOWED);
  506. message->Display();
  507. return 1;
  508. }
  509. }
  510. if (dpdrive.IsSonyMS() || dpdrive.IsNtfsNotSupported()) {
  511. if (0 == ntfs_str.Stricmp( 0 != arg_fsname.QueryChCount() ?
  512. &arg_fsname : &fsname )) {
  513. message->Set(dpdrive.IsSonyMS() ?
  514. MSG_FMT_NO_NTFS_ALLOWED :
  515. MSG_FMT_NTFS_NOT_SUPPORTED);
  516. message->Display();
  517. return 1;
  518. }
  519. }
  520. if (dpdrive.IsSonyMS()) {
  521. if (cmd_line_media_type == F3_1Pt44_512) {
  522. message->Set(MSG_FMT_INVALID_SLASH_F_OPTION);
  523. message->Display();
  524. return 1;
  525. }
  526. if (0 == fat32_str.Stricmp( 0 != arg_fsname.QueryChCount() ?
  527. &arg_fsname : &fsname )) {
  528. message->Set(MSG_FMT_NO_FAT32_ALLOWED);
  529. message->Display();
  530. return 1;
  531. }
  532. if (dpdrive.IsFloppy()) { // no hw to test this on
  533. message->Set(MSG_FMT_SONY_MEM_STICK_ON_FLOPPY_NOT_ALLOWED);
  534. message->Display();
  535. return 1;
  536. }
  537. }
  538. message->Set(MSG_FILE_SYSTEM_TYPE);
  539. message->Display("%W", &fsname);
  540. //
  541. // If compression is requested, make sure we can compress the
  542. // indicated file system type (or the current filesystem type,
  543. // if the user didn't specify one). Compression is not supported
  544. // for 64k-cluster NTFS volumes.
  545. //
  546. if (compressed) {
  547. if (0 != ntfs_str.Stricmp( 0 != arg_fsname.QueryChCount() ?
  548. &arg_fsname : &fsname )) {
  549. message->Set(MSG_COMPRESSION_NOT_AVAILABLE);
  550. message->Display("%W", 0 != arg_fsname.QueryChCount() ?
  551. &arg_fsname : &fsname );
  552. return 1;
  553. }
  554. if (cluster_size > 4096) {
  555. message->Set(MSG_CANNOT_COMPRESS_HUGE_CLUSTERS);
  556. message->Display();
  557. return 1;
  558. }
  559. }
  560. //
  561. // Determine which IFS library to load. The IFS
  562. // utilities for file system xxxx reside in Uxxxx.DLL.
  563. // If the use specified the file system with the /FS:
  564. // parameter, use that file system; otherwise, take
  565. // whatever's already on the disk (returned from
  566. // SYSTEM::QueryFileSystemName).
  567. //
  568. if( !LibraryName.Initialize( "U" ) ) {
  569. return 4;
  570. }
  571. if (!LibSuffix.Initialize(arg_fsname.QueryChCount() ?
  572. &arg_fsname : &fsname) ||
  573. !LibSuffix.Strupr()) {
  574. return 4;
  575. }
  576. if (LibSuffix == ntfs_str)
  577. old_fs = FALSE;
  578. if (fsname != LibSuffix) {
  579. message->Set(MSG_NEW_FILE_SYSTEM_TYPE);
  580. message->Display("%W", &LibSuffix);
  581. } else if (fsname == raw_str) {
  582. if (dpdrive.IsFloppy()) {
  583. if (!LibSuffix.Initialize(&fat_str)) {
  584. return 4;
  585. }
  586. message->Set(MSG_NEW_FILE_SYSTEM_TYPE);
  587. message->Display("%W", &LibSuffix);
  588. } else {
  589. message->Set(MSG_FORMAT_PLEASE_USE_FS_SWITCH);
  590. message->Display("");
  591. return 1;
  592. }
  593. }
  594. if (LibSuffix == fat32_str) {
  595. if(!LibSuffix.Initialize("FAT")) {
  596. return 4;
  597. }
  598. old_fs = FALSE;
  599. }
  600. if ( !LibraryName.Strcat( &LibSuffix ) ) {
  601. return 4;
  602. }
  603. if( !FormatString.Initialize( "FormatEx" ) ) {
  604. return 4;
  605. }
  606. if( (Format =
  607. (FORMATEX_FN)SYSTEM::QueryLibraryEntryPoint( &LibraryName,
  608. &FormatString,
  609. &FsUtilityHandle )) ==
  610. NULL ) {
  611. message->Set( MSG_FS_NOT_SUPPORTED );
  612. message->Display( "%s%W", "FORMAT", &LibSuffix );
  613. message->Set( MSG_BLANK_LINE );
  614. message->Display( "" );
  615. return 1;
  616. }
  617. if (drive_type != RemovableDrive) {
  618. // If the volume has a label, prompt the user for it.
  619. // Note that if we can't get the label, we'll treat it
  620. // as without a label (since we have to handle unformatted
  621. // volumes).
  622. OldErrorMode = SetErrorMode( SEM_FAILCRITICALERRORS );
  623. if( !force_mode &&
  624. dos_drive_path.Initialize( &dosdrivename) &&
  625. (old_volume_label =
  626. SYSTEM::QueryVolumeLabel( &dos_drive_path,
  627. &old_serial )) != NULL &&
  628. old_volume_label->Stricmp( &null_string ) != 0 ) {
  629. // This fixed drive has a label. To give the user
  630. // a bit more protection, prompt for the old label:
  631. message->Set( MSG_ENTER_CURRENT_LABEL );
  632. message->Display( "%W", &displaydrivename );
  633. message->QueryStringInput( &user_old_label );
  634. if( old_volume_label->Stricmp( &user_old_label ) != 0 ) {
  635. // Re-enable hard error popups.
  636. SetErrorMode( OldErrorMode );
  637. message->Set( MSG_WRONG_CURRENT_LABEL );
  638. message->Display( "" );
  639. DELETE( old_volume_label );
  640. return 1;
  641. }
  642. }
  643. // Re-enable hard error popups.
  644. SetErrorMode( OldErrorMode );
  645. DELETE( old_volume_label );
  646. old_volume_label = NULL;
  647. if (!force_mode) {
  648. message->Set(MSG_WARNING_FORMAT);
  649. message->Display("%W", &displaydrivename);
  650. if (!message->IsYesResponse(FALSE)) {
  651. return 5;
  652. }
  653. }
  654. }
  655. // ------------------------------------
  656. // Print the formatting <size> message.
  657. // ------------------------------------
  658. do_format = (BOOLEAN) (media_type != dpdrive.QueryMediaType());
  659. switch (media_type) {
  660. case F5_160_512:
  661. case F5_180_512:
  662. case F5_320_512:
  663. case F5_360_512:
  664. case F3_720_512:
  665. #if defined (FE_SB) && defined(_X86_)
  666. // FMR Jul.12.1994 SFT KMR
  667. // Modify the process to be display
  668. // when formating 640KB and 5inch's 720KB disk
  669. case F8_256_128:
  670. case F5_640_512:
  671. case F3_640_512:
  672. case F5_720_512:
  673. #endif
  674. if (quick_format) {
  675. message->Set(MSG_QUICKFORMATTING_KB);
  676. } else if (do_format) {
  677. message->Set(MSG_FORMATTING_KB);
  678. } else {
  679. message->Set(MSG_VERIFYING_KB);
  680. }
  681. break;
  682. case F5_1Pt2_512:
  683. case F3_1Pt44_512:
  684. case F3_2Pt88_512:
  685. case F3_20Pt8_512:
  686. #if defined(FE_SB) && defined(_X86_)
  687. // FMR Jul.12.1994 SFT KMR
  688. // Modify the process to be display
  689. // when formating 1.20/1.23MB disk
  690. case F3_1Pt2_512:
  691. case F5_1Pt23_1024:
  692. case F3_1Pt23_1024:
  693. #endif
  694. if (quick_format) {
  695. message->Set(MSG_QUICKFORMATTING_DOT_MB);
  696. } else if (do_format) {
  697. message->Set(MSG_FORMATTING_DOT_MB);
  698. } else {
  699. message->Set(MSG_VERIFYING_DOT_MB);
  700. }
  701. break;
  702. case RemovableMedia:
  703. case FixedMedia:
  704. case F3_120M_512:
  705. case F3_200Mb_512:
  706. case F3_240M_512:
  707. #if defined(FE_SB) // main():OpticalDisk support
  708. case F3_128Mb_512:
  709. case F3_230Mb_512:
  710. #endif
  711. if (quick_format) {
  712. message->Set(MSG_QUICKFORMATTING_MB);
  713. } else if (do_format) {
  714. message->Set(MSG_FORMATTING_MB);
  715. } else {
  716. message->Set(MSG_VERIFYING_MB);
  717. }
  718. break;
  719. case F5_320_1024:
  720. case Unknown:
  721. // This can't happen.
  722. return 4;
  723. }
  724. switch (media_type) {
  725. case F5_160_512:
  726. message->Display("%d", 160);
  727. break;
  728. case F5_180_512:
  729. message->Display("%d", 180);
  730. break;
  731. #if defined(FE_SB) && defined(_X86_)
  732. case F8_256_128:
  733. message->Display("%d", 256);
  734. break;
  735. #endif
  736. case F5_320_512:
  737. message->Display("%d", 320);
  738. break;
  739. case F5_360_512:
  740. message->Display("%d", 360);
  741. break;
  742. case F3_720_512:
  743. #if defined(FE_SB) && defined(_X86_)
  744. case F5_720_512:
  745. #endif
  746. message->Display("%d", 720);
  747. break;
  748. case F5_1Pt2_512:
  749. #if defined(FE_SB) && defined(_X86_)
  750. case F3_1Pt2_512:
  751. #endif
  752. message->Display("%d%d", 1, 2);
  753. break;
  754. case F3_1Pt44_512:
  755. message->Display("%d%d", 1, 44);
  756. break;
  757. case F3_2Pt88_512:
  758. message->Display("%d%d", 2, 88);
  759. break;
  760. case F3_20Pt8_512:
  761. message->Display("%d%d", 20, 8);
  762. break;
  763. case RemovableMedia:
  764. case FixedMedia:
  765. case F3_120M_512:
  766. case F3_200Mb_512:
  767. case F3_240M_512:
  768. #if defined(FE_SB) // main():Optical Disk support
  769. case F3_128Mb_512:
  770. case F3_230Mb_512:
  771. #endif
  772. bigint = dpdrive.QuerySectors()*
  773. dpdrive.QuerySectorSize()/
  774. 1048576;
  775. DebugAssert(bigint.GetHighPart() == 0);
  776. message->Display("%d", bigint.GetLowPart());
  777. break;
  778. case F5_320_1024:
  779. case Unknown:
  780. // This can't happen.
  781. return 4;
  782. #if defined(FE_SB) && defined(_X86_)
  783. case F5_640_512:
  784. case F3_640_512:
  785. message->Display("%d", 640);
  786. break;
  787. case F5_1Pt23_1024:
  788. case F3_1Pt23_1024:
  789. if (IsPC98_N()){
  790. message->Display("%d%d", 1, 25);
  791. }
  792. else{
  793. message->Display("%d%d", 1, 23);
  794. }
  795. break;
  796. #endif
  797. }
  798. #if defined (FE_SB) && defined (_X86_)
  799. // FMR Oct.07.1994 SFT YAM
  800. // If the sector-size when the last format differ from next format,
  801. // initialize a hard one-byte of disk.
  802. // at this time,if next formated disk is unformat-disk,
  803. // this process is undone.
  804. ULONG old_sec_size;
  805. ULONG new_sec_size;
  806. HMEM hmem;
  807. PUCHAR rw_buff;
  808. LOG_IO_DP_DRIVE *LDpDrive = NEW LOG_IO_DP_DRIVE;
  809. UCHAR FirstByte = 0;
  810. if ((IsPC98_N() && drive_type == FixedDrive) ?
  811. !hmem.Acquire(dpdrive.QuerySectorSize(), max(dpdrive.QueryAlignmentMask(), dpdrive.QuerySectorSize()-1)) :
  812. !hmem.Acquire(dpdrive.QuerySectorSize(), dpdrive.QueryAlignmentMask())) {
  813. message->Set(MSG_INSUFFICIENT_MEMORY);
  814. message->Display();
  815. return 1;
  816. }
  817. rw_buff = (PUCHAR)hmem.GetBuf();
  818. if(drive_type == RemovableDrive && !no_prompts) {
  819. if(Unknown_flag == FALSE) {
  820. old_sec_size = dpdrive.QuerySectorSize();
  821. if(cmd_line_media_type == F5_1Pt23_1024 || cmd_line_media_type == F3_1Pt23_1024) {
  822. new_sec_size = 1024;
  823. }
  824. else {
  825. new_sec_size = 512;
  826. }
  827. if(new_sec_size != old_sec_size) {
  828. // PC98 Sep.25.1995 UPDATE
  829. // When LDpDrive is fales to initialize,
  830. // we don't have to use LDpDrive.
  831. if( LDpDrive->Initialize(&ntdrivename,message,TRUE)){
  832. LDpDrive->Read(0,1,rw_buff);
  833. FirstByte = rw_buff[0];
  834. rw_buff[0] = 0;
  835. LDpDrive->Write(0,1,rw_buff);
  836. }
  837. }
  838. }
  839. }
  840. else {
  841. if (IsFMR_N()) {
  842. if(LibSuffix.Stricmp(&fsname)) {
  843. LDpDrive->Initialize(&ntdrivename,message,TRUE);
  844. LDpDrive->Read(0,1,rw_buff);
  845. FirstByte = rw_buff[0];
  846. rw_buff[0] = 0;
  847. LDpDrive->Write(0,1,rw_buff);
  848. }
  849. }
  850. }
  851. // PC98 Sep.25.1995 ADD
  852. // If the sector-size when the last format differ from next format,
  853. // initialize a hard one-byte of disk.
  854. // at this time,if next formated disk is unformat-disk,
  855. // this process is undone.
  856. if( IsPC98_N() ){
  857. if( drive_type == FixedDrive && Unknown_flag == FALSE &&
  858. dpdrive.QuerySectorSize()!=dpdrive.QueryPhysicalSectorSize()){
  859. if( LDpDrive->Initialize(&ntdrivename,message,TRUE)){
  860. LDpDrive->Read(0,1,rw_buff);
  861. FirstByte = rw_buff[0];
  862. rw_buff[0] = 0;
  863. LDpDrive->Write(0,1,rw_buff);
  864. }
  865. }
  866. }
  867. DELETE( LDpDrive );
  868. #endif
  869. // Disable hard-error popups.
  870. OldErrorMode = SetErrorMode( SEM_FAILCRITICALERRORS );
  871. Param.Major = 1;
  872. Param.Minor = 0;
  873. Param.Flags = (quick_format ? FORMAT_QUICK : 0) |
  874. (old_fs ? FORMAT_BACKWARD_COMPATIBLE : 0) |
  875. (force_dismount ? FORMAT_FORCE : 0) |
  876. (force_mode ? FORMAT_YES : 0);
  877. Param.LabelString = (label_spec ? &arg_label : NULL);
  878. Param.ClusterSize = cluster_size;
  879. if( !Format( &ntdrivename,
  880. message,
  881. &Param,
  882. media_type
  883. ) ) {
  884. #if defined (FE_SB) && defined (_X86_)
  885. if (FirstByte) {
  886. LOG_IO_DP_DRIVE *LDpDrive = NEW LOG_IO_DP_DRIVE;
  887. if( LDpDrive->Initialize(&ntdrivename,message,TRUE)){
  888. rw_buff[0] = FirstByte;
  889. LDpDrive->Write(0,1,rw_buff);
  890. }
  891. DELETE( LDpDrive );
  892. }
  893. #endif
  894. // Enable hard-error popups.
  895. SetErrorMode( OldErrorMode );
  896. SYSTEM::FreeLibraryHandle( FsUtilityHandle );
  897. return 4;
  898. }
  899. // Enable hard-error popups.
  900. SetErrorMode( OldErrorMode );
  901. SYSTEM::FreeLibraryHandle( FsUtilityHandle );
  902. if (do_floppy_return && !no_prompts) {
  903. message->Set(quick_format ? MSG_QUICKFMT_ANOTHER : MSG_FORMAT_ANOTHER);
  904. message->Display("");
  905. if (!message->IsYesResponse(FALSE)) {
  906. break;
  907. }
  908. } else {
  909. break;
  910. }
  911. }
  912. // Make sure that the file system is installed.
  913. if (!do_floppy_return &&
  914. !IFS_SYSTEM::IsFileSystemEnabled(&LibSuffix)) {
  915. message->Set(MSG_FMT_INSTALL_FILE_SYSTEM);
  916. message->Display("%W", &LibSuffix);
  917. if (message->IsYesResponse(TRUE)) {
  918. if (!IFS_SYSTEM::EnableFileSystem(&LibSuffix)) {
  919. message->Set(MSG_FMT_CANT_INSTALL_FILE_SYSTEM);
  920. message->Display();
  921. return 1;
  922. }
  923. message->Set(MSG_FMT_FILE_SYSTEM_INSTALLED);
  924. message->Display();
  925. }
  926. }
  927. if (compressed && !IFS_SYSTEM::EnableVolumeCompression(&ntdrivename)) {
  928. message->Set(MSG_CANNOT_ENABLE_COMPRESSION);
  929. message->Display();
  930. return 1;
  931. }
  932. return 0;
  933. }