Пример #1
0
//! @brief This function displays the free space of each drive present
//!
void ushell_cmd_free_space( void )
{
   uint8_t u8_tmp;
   Fs_index sav_index = nav_getindex();      // Save current position
   for( u8_tmp=0; u8_tmp<nav_drive_nb(); u8_tmp++ )
   {
      nav_drive_set( u8_tmp );      // Select drive
      if( !nav_partition_mount() )  // Mount drive
         continue;

      // Display drive letter name (a, b...)
      printf("%c: %s\r\n", 'a'+u8_tmp, mem_name(u8_tmp) );
      if( g_s_arg[0][0]=='l' )        // Choose command option
      {
         // Long and exact function
         printf("Free space: %llu Bytes / %llu Bytes\n\r",
                   (uint64_t)(nav_partition_freespace() << FS_SHIFT_B_TO_SECTOR),
                   (uint64_t)(nav_partition_space() << FS_SHIFT_B_TO_SECTOR));
      }
      else
      {
         // Otherwise use fast command
         printf("Free space: %u %%\n\r", nav_partition_freespace_percent() );
      }
   }
   nav_gotoindex(&sav_index);       // Restore position
}
Пример #2
0
//! @brief This function displays the disk space of current drive
//!
void ushell_cmd_space( void )
{
   uint32_t u32_space;
   // Display drive letter name (a, b...)
   fputs( mem_name(nav_drive_get()), stdout);
   putchar(' ');
   putchar( nav_drive_get()+'a');
   // Otherwise use fast command
   u32_space = nav_partition_space();
   if( 1024 >(u32_space % (2*1024)) )
   {
      u32_space = u32_space/(2*1024);
   }else{
      u32_space = (u32_space/(2*1024))+1;
   }
   printf(": space: %luMB \n\r", u32_space );
}
Пример #3
0
//!
//! @brief Synchronize the contents of two directories (limited to files).
//!
//! @param dst_fs_idx   Fs_index *:   File system index for destination navigation path
//! @param dst_dir      const char *: Pointer to destination directory name
//! @param src_fs_idx   Fs_index *:   File system index for source navigation path
//! @param src_dir      const char *: Pointer to source directory name
//!
//! @return bool: true on success
//!
//! @todo Do recursive directory copy...
//!
bool host_mass_storage_task_sync_dir(Fs_index *dst_fs_idx, const char *dst_dir, Fs_index *src_fs_idx, const char *src_dir)
{
  uint8_t nb_file;
  uint8_t i;
  uint32_t free_space;
  uint16_t file_size;

  // First, check the host controller is in full operating mode with the
  // B-device attached and enumerated
  if (!Is_host_ready()) return false;

  // Go to source navigation
  nav_gotoindex(src_fs_idx);
  if (!goto_code_name(src_dir)) return false;   // Check that source directory exists
  nav_dir_cd();                                 // Source directory exists, so go to it
  *src_fs_idx = nav_getindex();                 // Save navigation position
  nav_filelist_first(FS_FILE);                  // Go to first file
  nb_file = nav_filelist_nb(FS_FILE);           // Get the number of files in this directory

  // Go to destination navigation
  nav_gotoindex(dst_fs_idx);
  if (!goto_code_name(dst_dir))                 // Destination directory does not exist, so create it
  {
    str_code_to_unicode_ram(dst_dir, ms_str_unicode);
    nav_dir_make(ms_str_unicode);
    if (!goto_code_name(dst_dir)) return false; // Check that destination directory has been created
  }
  nav_dir_cd();
  *dst_fs_idx = nav_getindex();

  // Get available free space
  free_space = nav_partition_space();
  nav_gotoindex(src_fs_idx);
  nav_filelist_first(FS_FILE);

  // For all files in directory
  for (i = 0; i < nb_file; i++)
  {
    // Get source name to be used as destination name
    nav_file_name(ms_str_unicode, MAX_FILE_PATH_LENGTH, FS_NAME_GET);
    file_size = nav_file_lgtsector();           // Get file size
    if (file_size > free_space) return false;   // Check that there is enough free space left
    // Update free space (to save time, do no call nav_partition_space() again)
    free_space -= file_size;
    // Mark source
    nav_file_copy();
    // Save current source position
    *src_fs_idx = nav_getindex();

    // Go to destination navigation
    nav_gotoindex(dst_fs_idx);
    if (goto_unicode_name(ms_str_unicode))      // If file already exists
    {
      nav_file_del();                           // Delete it
    }

    // Paste
    nav_file_paste_start(ms_str_unicode);
    // Restore previous navigation position
    nav_gotoindex(src_fs_idx);
    // Copy
    while (nav_file_paste_state(false) == COPY_BUSY);

    // Restore previous navigation position
    nav_gotoindex(src_fs_idx);
    nav_filelist_set(0, FS_FIND_NEXT);
  }

  return true;
}