Subversion Repositories NaviCtrl

Rev

Rev 387 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 387 Rev 396
Line 60... Line 60...
60
#include "fat16.h"
60
#include "fat16.h"
61
#include "sdc.h"
61
#include "sdc.h"
62
#include "uart1.h"
62
#include "uart1.h"
63
#include "main.h"
63
#include "main.h"
64
#include "logging.h"
64
#include "logging.h"
-
 
65
#include "debug.h"
Line 65... Line 66...
65
 
66
 
66
 
67
 
67
//________________________________________________________________________________________________________________________________________
68
//________________________________________________________________________________________________________________________________________
Line 584... Line 585...
584
        if(SD_WatchDog > 2000) SD_WatchDog = 2000;
585
        if(SD_WatchDog > 2000) SD_WatchDog = 2000;
585
        SD_LoggingError = 100;
586
        SD_LoggingError = 100;
586
        return(returnvalue);
587
        return(returnvalue);
587
}
588
}
Line -... Line 589...
-
 
589
 
588
 
590
 
589
/****************************************************************************************************************************************/
591
/****************************************************************************************************************************************/
590
/*      Function:               Fat16_Init(void);                                                                                                                                                                                                       */
592
/*      Function:               Fat16_Init(void);                                                                                                                                                                                                       */
591
/*                                                                                                                                                                                                                                                                          */
593
/*                                                                                                                                                                                                                                                                          */
592
/*      Description:    This function reads the Masterbootrecord and finds the position of the Volumebootrecord, the FAT and the Rootdir    */
594
/*      Description:    This function reads the Masterbootrecord and finds the position of the Volumebootrecord, the FAT and the Rootdir    */
Line 2146... Line 2148...
2146
        u8              readpointer = 0;
2148
        u8              readpointer = 0;
2147
        u8              writepointer = 0;
2149
        u8              writepointer = 0;
2148
        u8              retvalue = 0;
2150
        u8              retvalue = 0;
2149
        DirEntry_t      *DirectoryEntry;
2151
        DirEntry_t      *DirectoryEntry;
2150
        File_t  file;
2152
        File_t  file;
-
 
2153
        SD_Result_t res=0;
Line 2151... Line 2154...
2151
 
2154
 
2152
        file.FirstSectorOfCurrCluster   = findelement->fp.FirstSectorOfCurrCluster;
2155
        file.FirstSectorOfCurrCluster   = findelement->fp.FirstSectorOfCurrCluster;
2153
        file.SectorOfCurrCluster        = findelement->fp.SectorOfCurrCluster;
2156
        file.SectorOfCurrCluster        = findelement->fp.SectorOfCurrCluster;
Line 2164... Line 2167...
2164
                max_dir_sector = Partition.SectorsPerCluster;                           // limit max secters before next cluster
2167
                max_dir_sector = Partition.SectorsPerCluster;                           // limit max secters before next cluster
2165
        }
2168
        }
Line 2166... Line 2169...
2166
 
2169
 
2167
        do
2170
        do
2168
        {                                                                                                                                                               // search the next 16 rootentries in this sector of the roordirectory.          
2171
        {                                                                                                                                                               // search the next 16 rootentries in this sector of the roordirectory.          
-
 
2172
                res = SDC_GetSector(((u32) file.FirstSectorOfCurrCluster + (u32)file.SectorOfCurrCluster), file.Cache);                                         // Read the Rootdirectory.
2169
                if(SD_SUCCESS != SDC_GetSector(((u32) file.FirstSectorOfCurrCluster + (u32)file.SectorOfCurrCluster), file.Cache));                                             // Read the Rootdirectory.
2173
                if(res != SD_SUCCESS)
2170
                {
2174
                {
2171
                        Fat16_Deinit();
2175
                        Fat16_Deinit();
2172
                        return(0);
2176
                        return(0);
Line 2472... Line 2476...
2472
/*      Description:    This function changed the current working directory to the directory specified by the filepath                                                  */
2476
/*      Description:    This function changed the current working directory to the directory specified by the filepath                                                  */
2473
/*                  by function findfirst()                                                                                                                                                                                                     */
2477
/*                  by function findfirst()                                                                                                                                                                                                     */
2474
/*                                                                                                                                                                                                                                                                                      */
2478
/*                                                                                                                                                                                                                                                                                      */
2475
/*      Returnvalue:                                                                                                                                                                                                                                                    */
2479
/*      Returnvalue:                                                                                                                                                                                                                                                    */
2476
/********************************************************************************************************************************************/
2480
/********************************************************************************************************************************************/
2477
/*                                                                         
-
 
2478
#define ATTR_NONE               0x00    // normal file
-
 
2479
#define ATTR_READONLY           0x01    // file is readonly
-
 
2480
#define ATTR_HIDDEN                     0x02    // file is hidden
-
 
2481
#define ATTR_SYSTEM                     0x04    // file is a system file
-
 
2482
#define ATTR_VOLUMELABEL        0x08    // entry is a volume label
-
 
2483
#define ATTR_LONG_FILENAME      0x0F    // this is a long filename entry
-
 
2484
#define ATTR_SUBDIRECTORY       0x10    // entry is a directory name
-
 
2485
#define ATTR_ARCHIVE            0x20    // file is new or modified
-
 
2486
*/
-
 
Line 2487... Line 2481...
2487
 
2481
 
2488
u8 chdir_(s8 *path)
2482
u8 chdir_(s8 *path)
2489
{
2483
{
2490
        u8              retvalue = 0;                                   // the value returned by this function
2484
        u8              retvalue = 0;                                   // the value returned by this function
Line 2503... Line 2497...
2503
        while(*cptr != 0 )
2497
        while(*cptr != 0 )
2504
        {
2498
        {
2505
                if(*cptr == '\\') *cptr = '/';
2499
                if(*cptr == '\\') *cptr = '/';
2506
                cptr++;
2500
                cptr++;
2507
        }
2501
        }
-
 
2502
//              Debug("1");
2508
        /* lets remember the actual path */
2503
        /* lets remember the actual path */
2509
        strcpy(tp, Partition.PathToCwd);
2504
        strcpy(tp, Partition.PathToCwd);
2510
        cwdt = Partition.CurrentWorkingDirectory;
2505
        cwdt = Partition.CurrentWorkingDirectory;
2511
        /* how many subdirectories are there within the path? */
2506
        /* how many subdirectories are there within the path? */
2512
        dircount = GetDirCount(path);  
2507
        dircount = GetDirCount(path);  
Line 2516... Line 2511...
2516
                strcpy(Partition.PathToCwd, "/");
2511
                strcpy(Partition.PathToCwd, "/");
2517
                Partition.CurrentWorkingDirectory = Partition.FirstRootDirSector;
2512
                Partition.CurrentWorkingDirectory = Partition.FirstRootDirSector;
2518
                /* if there is no other pathinformation we only switch to the rootdirectory. So theres nothing left todo.*/
2513
                /* if there is no other pathinformation we only switch to the rootdirectory. So theres nothing left todo.*/
2519
                if(!dircount) return(1);
2514
                if(!dircount) return(1);
2520
        }
2515
        }
-
 
2516
//      Debug("2");
2521
        /* now we parse through all the subdirectories within the path */
2517
        /* now we parse through all the subdirectories within the path */
2522
        do
2518
        do
2523
        {  
2519
        {  
2524
                /* until all the subdirectories within the path have been processed */
2520
                /* until all the subdirectories within the path have been processed */
2525
        if(dircount) dircount--;
2521
        if(dircount) dircount--;
Line 2534... Line 2530...
2534
                        else if(cache[0] == '.') return(1);
2530
                        else if(cache[0] == '.') return(1);
2535
                        /* otherwise we append the name of the directory we are changing in to the path */
2531
                        /* otherwise we append the name of the directory we are changing in to the path */
2536
                        else AppendDirToPath(cache);
2532
                        else AppendDirToPath(cache);
2537
                        /* The startcluster within an directoryentry specifies the position within the fat where the file or directory starts */
2533
                        /* The startcluster within an directoryentry specifies the position within the fat where the file or directory starts */
2538
                        ultemp = (u32) fe.fp.FirstSectorOfFirstCluster;
2534
                        ultemp = (u32) fe.fp.FirstSectorOfFirstCluster;
-
 
2535
                        /* do we have to change into the rootdirectory? */
-
 
2536
                        if(ultemp)
-
 
2537
                        {
2539
                        /* the first 2 entries are reserved for '.' and '..' */
2538
                                /* the first 2 entries are reserved for '.' and '..' */
2540
                        ultemp -= 2;
2539
                                ultemp -= 2;
2541
                        /* now we have to transform the position within the fat into the corrosponding sectoraddress relative to the beginning of the datasection of the active partition*/
2540
                                /* now we have to transform the position within the fat into the corrosponding sectoraddress relative to the beginning of the datasection of the active partition*/
2542
                        ultemp *= Partition.SectorsPerCluster;
2541
                                ultemp *= Partition.SectorsPerCluster;
2543
                        /* at least we make the sectoraddress absolute by adding the relative address to the beginning of the datasection of the active partition */
2542
                                /* at least we make the sectoraddress absolute by adding the relative address to the beginning of the datasection of the active partition */
2544
                        ultemp += Partition.FirstDataSector;
2543
                                ultemp += Partition.FirstDataSector;
2545
                        /* the cwd now points to the specified directory */
2544
                                /* the cwd now points to the specified directory */
2546
                        Partition.CurrentWorkingDirectory = ultemp;
2545
                                Partition.CurrentWorkingDirectory = ultemp;
2547
                        /* we found the folder specified by the foldername */
2546
                                /* we found the folder specified by the foldername */
-
 
2547
                                retvalue = 1;
-
 
2548
                        }
-
 
2549
                        else
-
 
2550
                        {
-
 
2551
                                /* the cwd now points to the rootdirectory */
-
 
2552
                                Partition.CurrentWorkingDirectory = Partition.FirstRootDirSector;
-
 
2553
                                /* changed into the rootdirectory succesfully */
2548
                        retvalue = 1;
2554
                                retvalue = 1;
-
 
2555
                        }
2549
                }
2556
                }
2550
        }
2557
        }
2551
        /* do this until all subdirectories have been found or a subdirectory is missing */
2558
        while(dircount && retvalue );           /* do this until all subdirectories have been found or a subdirectory is missing */
2552
        while(dircount && retvalue );
2559
//      Debug("3");
Line 2553... Line 2560...
2553
 
2560
 
2554
        /* if we could not change to the specified directory we restore the actual path */
2561
        /* if we could not change to the specified directory we restore the actual path */
2555
        if(!retvalue)
2562
        if(!retvalue)
2556
        {
2563
        {
2557
                Partition.CurrentWorkingDirectory = cwdt;                                                  
2564
                Partition.CurrentWorkingDirectory = cwdt;                                                  
2558
                strcpy(Partition.PathToCwd, tp);
2565
                strcpy(Partition.PathToCwd, tp);
2559
        }
2566
        }
2560
        return(retvalue);      
2567
        return(retvalue);      
-
 
2568
}
-
 
2569
 
-
 
2570
 
-
 
2571
 
-
 
2572
/********************************************************************************************************************************************/
-
 
2573
/*      Function:               void DeleteDirectoryEntry(Find *item)                                                                                                                                                                   */
-
 
2574
/*      Description:    This function deletes the directoryentry of the file to be deleted from the filesystem                                                                  */
-
 
2575
/*                                                                                                                                                                                                                                      */
-
 
2576
/*                                                                                                                                                                                                                                                                                      */
-
 
2577
/*      Returnvalue:    none                                                                                                                                                                                                                                    */
-
 
2578
/********************************************************************************************************************************************/
-
 
2579
 
-
 
2580
void DeleteDirectoryEntry(Find_t *fe)
-
 
2581
{
-
 
2582
        DirEntry_t *DirectoryEntry = NULL;
-
 
2583
 
-
 
2584
        /* read the sector containint the directoryentry of the file to be deleted */
-
 
2585
        SDC_GetSector((u32) fe->fp.DirectorySector,fe->fp.Cache);                                                  
-
 
2586
        /* get access to the elements of the directoryentry */ 
-
 
2587
        DirectoryEntry = (DirEntry_t *)fe->fp.Cache;
-
 
2588
        /* delete the directoryentry */
-
 
2589
        DirectoryEntry[fe->fp.DirectoryIndex].Attribute = 0;
-
 
2590
        DirectoryEntry[fe->fp.DirectoryIndex].Name[0] = 0xE5;                                        
-
 
2591
        DirectoryEntry[fe->fp.DirectoryIndex].Size = 0;                                            
-
 
2592
        /* the file has been deleted from the directory, save the modified sector back to the filesystem */
-
 
2593
        SDC_PutSector((u32) fe->fp.DirectorySector,fe->fp.Cache);                                                      
-
 
2594
}
-
 
2595
 
-
 
2596
 
-
 
2597
 
-
 
2598
/********************************************************************************************************************************************/
-
 
2599
/*      Function:               fdelete_(s8* filename);                                                                                                                                                                                                 */
-
 
2600
/*                                                                                                                                                                                                                                                                                      */
-
 
2601
/*      Description:    This function deletes the file with the specified filename from the filesystem                                                                                  */
-
 
2602
/*                                                                                                                                                                                                                                      */
-
 
2603
/*                                                                                                                                                                                                                                                                                      */
-
 
2604
/*      Returnvalue:    1 : specified file deleted succesfully 0: specified file not found                                                                                                              */
-
 
2605
/********************************************************************************************************************************************/
-
 
2606
 
-
 
2607
u8 fdelete_(s8 *fname)
-
 
2608
{
-
 
2609
        u8 retvalue = 0;
-
 
2610
        Find_t fe;
-
 
2611
       
-
 
2612
        /* search for the specified item */
-
 
2613
        retvalue = (u8) findfirst_(fname, 0xff, &fe);
-
 
2614
        /* if the item was found */  
-
 
2615
        if(retvalue)
-
 
2616
        {
-
 
2617
                /* is the file marked as readonly? */
-
 
2618
                if(0)//(fe.fp.Attribute & ATTR_READONLY) == ATTR_READONLY)
-
 
2619
                {      
-
 
2620
                        return(0);
-
 
2621
                }
-
 
2622
                /* file is not marked as readonly */           
-
 
2623
                else
-
 
2624
                {      
-
 
2625
                        /* delete the file from the filesystem */
-
 
2626
                        DeleteClusterChain(fe.fp.FirstSectorOfFirstCluster);
-
 
2627
                        /* delete the directoryentry of the file */
-
 
2628
                        DeleteDirectoryEntry(&fe);
-
 
2629
                }
-
 
2630
   }
-
 
2631
 
-
 
2632
        return(retvalue);      
-
 
2633
}
-
 
2634
 
-
 
2635
 
-
 
2636