Ejemplo n.º 1
0
int_32  Shell_di(int_32 argc, char_ptr argv[] )
{ /* Body */
   boolean           print_usage, shorthelp = FALSE;
   int_32            return_code = SHELL_EXIT_SUCCESS;
   int_32            offset;

   MQX_FILE_PTR      fd, fs;

   uint_32           backup=0;
   uchar_ptr         buffer=NULL;

   print_usage = Shell_check_help_request(argc, argv, &shorthelp );

   if (!print_usage)  {
      if ((argc < 2 ) || (argc > 3)) {
         printf("Invalid number of parameters\n");
         return_code = SHELL_EXIT_ERROR;
         print_usage=TRUE;
      } else if ( !Shell_parse_uint_32(argv[1], (uint_32_ptr) &offset ))  {
         printf("Error, invalid length\n");
         return_code = SHELL_EXIT_ERROR;
         print_usage=TRUE;
      } else {
         buffer = _mem_alloc(SECTOR_SIZE);
         if (buffer==NULL) {
            printf("Error, unable to allocate sector buffer\n");
            return  SHELL_EXIT_ERROR;
         }

         if (argc==3) {
            fd = fopen(argv[2], "b");
         } else {   
            fs = Shell_get_current_filesystem(argv);
            _io_ioctl(fs, IO_IOCTL_GET_DEVICE_HANDLE, &fd);
         }
              

         if (fd)  {
            if (fseek(fd, offset, IO_SEEK_SET) == IO_ERROR)  {
               printf("Error, unable to seek to sector %s.\n", argv[1] );
               return_code = SHELL_EXIT_ERROR;
            } else if (_io_read(fd, (char_ptr) buffer, 1) != 1) {
               printf("Error, unable to read sector %s.\n", argv[1] );
               return_code = SHELL_EXIT_ERROR;
            }
            
            if (return_code == SHELL_EXIT_SUCCESS) {
               printf("\n");
               backup = print_bpb(buffer);
               if (backup) {
                  if (fseek(fd, backup, IO_SEEK_SET) == IO_ERROR)  {
                     printf("Error, unable to seek to sector %s.\n", argv[1] );
                     return_code = SHELL_EXIT_ERROR;
                  } else if (_io_read(fd, (char_ptr) buffer, 1) != 1) {
                     printf("Error, unable to read sector %s.\n", argv[1] );
                     return_code = SHELL_EXIT_ERROR;
                  }  
                  if (return_code == SHELL_EXIT_SUCCESS) {
                     printf("\n");
                     print_bpb(buffer);
                  }
               }
            }
            if (fseek(fd, 1, IO_SEEK_SET) == IO_ERROR)  {
               printf("Error, unable to seek to sector %s.\n", argv[1] );
               return_code = SHELL_EXIT_ERROR;
            } else if (_io_read(fd, (char_ptr) buffer, 1) != 1) {
               printf("Error, unable to read sector %s.\n", argv[1] );
               return_code = SHELL_EXIT_ERROR;
            }  
            if (return_code == SHELL_EXIT_SUCCESS) {
               printf("\n");
               print_fsi(buffer);
            }
            if (argc==3) {
               fclose(fd);
            }
         }
         _mem_free(buffer);
      }
   }
   
   
   if (print_usage)  {
      if (shorthelp)  {
         printf("%s <sector> [<device>]\n", argv[0]);
      } else  {
         printf("Usage: %s <sector> [<device>]\n", argv[0]);
         printf("   <sector>     = sector number\n");
         printf("   <device>     = low level device\n");
      }
   }
   return return_code;
} /* Endbody */
Ejemplo n.º 2
0
boolean fips_partition::split (fips_harddrive hd)
{
	if (read_boot_sector ())
		error ("Error reading boot sector");

	if (global.debug_mode)
	{
		fprintf
		(
			global.debugfile,
			"\nBoot sector drive %02Xh, partition %u:\n\n",
			hd.number,
			number + 1
		);

		hexwrite
		(
			boot_sector->data,
			512,
			global.debugfile
		);
	}

	get_bpb ();

	printx ("\nBoot sector:\n\n");
	print_bpb ();

	get_info ();
	if (global.debug_mode)
		write_info_debugfile ();

	check ();

	fat16 fat1 (this,1);
	fat16 fat2 (this,2);

	fat1.check_against (&fat2);

	dword new_part_min_cylinder =
		min_cylinder (fat2, hd.geometry);

	if (ask_if_save()) save_root_and_boot(&hd,this);

	dword new_start_cylinder =
		ask_for_new_start_cylinder
		(
			partition_info->start_cylinder,
			new_part_min_cylinder,
			partition_info->end_cylinder,
			hd.geometry.heads * hd.geometry.sectors
		);

	fat2.check_empty
	(
		new_start_cylinder
			* hd.geometry.heads
			* hd.geometry.sectors
		- partition_info->start_sector_abs
	);

	hd.calculate_new_root (new_start_cylinder, this);

	hd.put_partition_table();
	hd.get_partition_table();

	printx ("\nNew partition table:\n\n");
	hd.print_partition_table ();

	hd.check (FINAL_CHECK);

	if (ask_if_continue () == false)
	{
		return (false);
	}

	calculate_new_boot ();

	put_bpb ();
	get_bpb ();

	printx ("\nNew boot sector:\n\n");
	print_bpb ();

	get_info ();
	if (global.debug_mode)
		write_info_debugfile ();

	check();

	if (!global.test_mode)
	{
		ask_for_write_permission ();

		if (hd.write_root_sector ())
			error ("Error writing root sector");

		if (write_boot_sector ())
			error ("Error writing boot sector");

		printx ("Repartitioning complete\n");
	}

	return (true);
}