ATMEL: Copy a disk on other disk

- Main Page
- Modules
- Data Structures
- Files
- Related Pages

# Copy a disk on other disk
[Examples]

This example uses three navigators :

- to move on source disk
- to move on destination disk
- for the copy/paste feature (navigator defined by FS_NAV_ID_COPYFILE)

    Bool copydisk( void )
    {
       const UNICODE _MEM_TYPE_SLOW_ name[50];
       U8 u8_folder_level = 0;

    //trace("Mount drive\n");
       //** Use three navigators (0 to explore SD, 1 to explore NF disk, 2 used by copy file routine)
       nav_select( 0 );
       if( !nav_drive_set( LUN_ID_MMC_SD ))
          return FALSE;
       if( !nav_partition_mount() )
          return FALSE;
       nav_select( 1 );
       if( !nav_drive_set( LUN_ID_NF_DISKMASS ))
          return FALSE;
       if( !nav_partition_mount() )
          return FALSE;

       // loop to scan and create ALL folders and files
       while(1)
       {
          // No dir in current dir then go to parent dir on SD and NandFlash disk
          while(1)
          {
    //trace("Search files or dir\n");
             // Reselect SD
             nav_select( 0 );
             if( nav_filelist_set( 0 , FS_FIND_NEXT ) )
                break;   // a next file and directory is found

             // No other dir or file in current dir then go to parent dir on SD and NandFlash disk
             if( 0 == u8_folder_level )
             {
                // end of update folder
    //trace("End of copy\n");
                return TRUE;   //********* END OF COPY **************
             }

    //trace("Go to parent\n");
             // Remark, nav_dir_gotoparent() routine go to in parent dir and select the children dir in list
             u8_folder_level--;
             if( !nav_dir_gotoparent() )
                return FALSE;
             // Select NandFlash navigator and go to the same dir of SD
             nav_select( 1 );
             if( !nav_dir_gotoparent() )
                return FALSE;
          } // end of while (1)

          if( nav_file_isdir())
          {
    //trace("Dir found - create dir & CD\n");
             //** here, a new directory is found and is selected
             // Get name of current selection (= dir name on SD)
             if( !nav_file_name( (FS_STRING )name , 50  , FS_NAME_GET, FALSE  ))
                return FALSE;
             // Enter in dir (on SD)
             if( !nav_dir_cd())
                return FALSE;
             u8_folder_level++;
             // Select NandFlash disk
             nav_select( 1 );
             // Create folder in NandFlash disk
             if( !nav_dir_make( (FS_STRING )name ))
             {
                if( FS_ERR_FILE_EXIST != fs_g_status )
                   return FALSE;
                // here, error the name exist
             }
             // Here the navigator have selected the folder on NandFlash
             if( !nav_dir_cd())
             {
                if( FS_ERR_NO_DIR == fs_g_status )
                {
                   // FYC -> Copy impossible, because a file have the same name of folder
                }
                return FALSE;
             }
             // here, the folder is created and the navigatorS is entered in this dir
          }
          else
          {
    //trace("File found - copy file\n");
             //** here, a new file is found and is selected
             // Get name of current selection (= file name on SD)
             if( !nav_file_name( (FS_STRING )name , 50  , FS_NAME_GET , FALSE  ))
                return FALSE;
             if( !nav_file_copy())
                return FALSE;

             // Paste file in current dir of NandFlash disk
             nav_select( 1 );
             while( !nav_file_paste_start( (FS_STRING)name ) )
             {
                // Error
                if( fs_g_status != FS_ERR_FILE_EXIST )
                   return FALSE;
    //trace("del file\n");
                // File exists then deletes this one
                if( !nav_file_del( TRUE ) )
                   return FALSE;
                // here, retry PASTE
             }
             // Copy running
             {
             U8 status;
             do{
                status = nav_file_paste_state(FALSE);
             }while( COPY_BUSY == status );

             if( COPY_FINISH != status )
                return FALSE;
             }
          } // if dir OR file
       } // end of first while(1)
    }