Directory copy - USBHostlite

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Directory copy - USBHostlite

235 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by nikita on Sat Nov 09 03:14:16 MST 2013
I want  to copy whole directory to another directory in USBHostlite. Now it supports only file copy .

What changes do I need to do ?

Thank you
0 Kudos
2 Replies

219 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by nikita on Thu Nov 21 05:22:59 MST 2013
I got some source code for it .Now by some modifications I am able to copy all files at a time from one directory to another. but only separate file copy is possible .

Now I need to copy with Directory name itself .


  /*********************************************************************//**
    + * @brief                      Read DIR contents.
    + * @return             Return code.
    + *                                     NOT_FOUND
    + *                                     MATCH_FOUND
    + **********************************************************************/
    int32_t  DIR_Open (uint8_t  *ent_name_given)
    {
     int32_t rc;
     uint32_t sec_num, first_sec_num,end_sec_num ;
     FILE_ENTRY* entry = &FAT_CurDirEntry.dir_info;
     uint8_t   ent_type;
     uint8_t   ent_name_read[80];
     uint8_t   len = 0;
     uint8_t   sum = 0;
     volatile uint8_t        *buf, *afile;
     DIR_ENTRY* ptr = FAT_CurDirEntry.entries;

     // Find the entry for the given folder
     if(entry->FileStatus == 0 )
     {
     if(FAT_StrCaseCmp(ent_name_given,".") == 0)
         {
     if(FAT_BootSec.FATType == FAT_32) {
             entry->CurrClus=  FAT_BootSec.RootClus;
             } else {
             entry->CurrClus =  FAT_BootSec.RootDirStartSec/FAT_BootSec.SecPerClus;
             }
             entry->CurrClusOffset = 0;
             entry->FileStatus = 1;
        }
        else
        {
        rc = FAT_FindEntry(ent_name_given, entry);
            if (rc == MATCH_FOUND) {
            entry->FileStatus = 1;
            }
            else
            {
            return NOT_FOUND;
            }
       }

     }
     else
     {
     uint16_t    i = 0;

         // Find in the current directory
         for(i = 0; i < FAT_CurDirEntry.entry_num; i++)
         {
         if(FAT_StrCaseCmp(ent_name_given,FAT_CurDirEntry.entries.name) == 0)
             {
             *entry = FAT_CurDirEntry.entries.info;
             entry->FileStatus = 1;
             break;
             }
         }
     }

     FAT_CurDirEntry.entry_num = 0;
     first_sec_num = FAT_GetFirstSectorOfCluster(entry->CurrClus);
     end_sec_num = first_sec_num + FAT_BootSec.SecPerClus;

     for(sec_num = first_sec_num; sec_num < end_sec_num; sec_num++)
     {
     // Read all sub-entries
         MS_BulkRecv(sec_num, 1, FATBuffer);                  /* Read one sector                             */
         buf = FATBuffer;
         while (buf < (FATBuffer + FAT_BootSec.BytsPerSec)) {
         rc = NOT_FOUND;
             ent_type = FAT_ChkEntType(buf);                  /* Check for the entry type                    */
             if(ent_type == SFN_ENTRY ||ent_type == LFN_ENTRY)
             {
             afile = buf;
                 if (ent_type == SFN_ENTRY) {                     /* If it is short entry get short file name    */
                 FAT_GetSFN(buf, ent_name_read);
                 // add the entry list
                 FAT_StrCopy(ptr->name,ent_name_read);
                 rc = MATCH_FOUND;
                 } else if (ent_type == LFN_ENTRY) {
                 sum = buf[LDIR_CHK_SUM_IDX];
                 len = FAT_GetLfn(&buf,&sec_num,FATBuffer,FATBuffer+FAT_BootSec.BytsPerSec,ent_name_read);
                 if(len > 0) {
                 FAT_StrCopy(ptr->name,ent_name_read);
                 afile = buf;
                 FAT_GetSFN(buf, ent_name_read);
                 ent_type = FAT_ChkEntType(buf);
                 if(ent_type == SFN_ENTRY && sum == FAT_LFN_ChkSum((uint8_t*)buf))
                 {
                  // add the entry list
                  rc = MATCH_FOUND;
                 }
                 }
                 }

                 if(rc == MATCH_FOUND)
                 {
                 ptr->info.FileAttr = afile[DIR_ATT_IDX];
                     ptr->info.CurrClus = ReadLE16U(&afile[DIR_FST_CLUS_HI_IDX])<<16 & 0xFFFF0000;   /*      High word of the first cluster number*/
                     ptr->info.CurrClus |= ReadLE16U(&afile[DIR_FST_CLUS_LO_IDX]);   /* Low word of the first cluster number     */
                     ptr->info.CurrClusOffset = 0;
                     ptr->info.FileSize  = ReadLE32U(&afile[DIR_SIZE_IDX]);  /* Get file size                               */
                     ptr->info.EntrySec = sec_num;           /* Get sector number where the filename is located */
                     ptr->info.EntrySecOffset = afile - FATBuffer; /* Get offset in this sector where the filename is located */
                     ptr++;
                     FAT_CurDirEntry.entry_num++;
                 }
              }

              if (ent_type == LAST_ENTRY) {    /* If it is the last entry, no more entries will exist.  */
              break;
              }
              buf = buf + FAT_ENTRY_SIZE;                                  /* Move to the next entry                      */
         }
     }
     return MATCH_FOUND;
    }




what changes do i need to do here?


Please reply.

0 Kudos

219 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by nikita on Sat Nov 09 03:38:48 MST 2013
Is there any suggestion to display files in the directory given?
0 Kudos