Subversion Repositories NaviCtrl

Rev

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

Rev 353 Rev 359
Line 105... Line 105...
105
Root Directory Entry                            Start + # of Reserved + (# of Sectors Per FAT * 2)
105
Root Directory Entry                            Start + # of Reserved + (# of Sectors Per FAT * 2)
106
Data Area (Starts with Cluster #2)      Start + # of Reserved + (# of Sectors Per FAT * 2) + ((Maximum Root Directory Entries * 32) / Bytes per Sector)
106
Data Area (Starts with Cluster #2)      Start + # of Reserved + (# of Sectors Per FAT * 2) + ((Maximum Root Directory Entries * 32) / Bytes per Sector)
107
*/
107
*/
Line -... Line 108...
-
 
108
 
108
 
109
 
109
 
110
 
Line 110... Line 111...
110
/*
111
/*
111
________________________________________________________________________________________________________________________________________
112
________________________________________________________________________________________________________________________________________
Line 681... Line 682...
681
                result = 6;
682
                result = 6;
682
                goto end;
683
                goto end;
683
        }
684
        }
684
        Partition.IsValid = 1; // mark data in partition structure as valid
685
        Partition.IsValid = 1; // mark data in partition structure as valid
685
        Partition.CurrentWorkingDirectory = Partition.FirstRootDirSector;
686
        Partition.CurrentWorkingDirectory = Partition.FirstRootDirSector;
686
        strcpy(Partition.PathToCwd,"/");
687
        strcpy(Partition.PathToCwd,"/");       
687
        result = 0;
688
        result = 0;
688
        end:
689
        end:
689
        if(result != 0) Fat16_Deinit();
690
        if(result != 0) Fat16_Deinit();
690
        else UART1_PutString("ok");
691
        else UART1_PutString("ok");
691
        return(result);
692
        return(result);
Line 1496... Line 1497...
1496
/*      Returnvalue:    The filepointer to the file or 0 if faild.                                                                                                                                                              */
1497
/*      Returnvalue:    The filepointer to the file or 0 if faild.                                                                                                                                                              */
1497
/********************************************************************************************************************************************/
1498
/********************************************************************************************************************************************/
1498
File_t * fopen_(s8 * const filename, const s8 mode)
1499
File_t * fopen_(s8 * const filename, const s8 mode)
1499
{
1500
{
1500
        File_t *file    = 0;
1501
        File_t *file    = 0;
-
 
1502
        s8 *cptr;
Line 1501... Line 1503...
1501
 
1503
 
Line 1502... Line 1504...
1502
        if((!Partition.IsValid) || (filename == 0)) return(file);
1504
        if((!Partition.IsValid) || (filename == 0)) return(file);
1503
 
1505
 
Line 1518... Line 1520...
1518
        file->SectorInCache                             = SECTOR_UNDEFINED;             // the last sector read, wich is still in the sectorbuffer.
1520
        file->SectorInCache                             = SECTOR_UNDEFINED;             // the last sector read, wich is still in the sectorbuffer.
1519
        file->DirectorySector                   = SECTOR_UNDEFINED;             // the sectorposition where the directoryentry has been made.
1521
        file->DirectorySector                   = SECTOR_UNDEFINED;             // the sectorposition where the directoryentry has been made.
1520
        file->DirectoryIndex                    = 0;            // the index to the directoryentry within the specified sector.
1522
        file->DirectoryIndex                    = 0;            // the index to the directoryentry within the specified sector.
1521
        file->Attribute                                 = 0;            // the attribute of the file opened.
1523
        file->Attribute                                 = 0;            // the attribute of the file opened.
Line -... Line 1524...
-
 
1524
 
-
 
1525
        // bring the path into the correct syntax 
-
 
1526
        cptr = filename;
-
 
1527
        // search the whole string 
-
 
1528
        while(*cptr != 0)
-
 
1529
        {
-
 
1530
                // replace all '\' by '/'
-
 
1531
                if(*cptr == '\\') *cptr = '/';
-
 
1532
                cptr++;
1522
 
1533
        }
1523
        // check if a real file (no directory) to the given filename exist
1534
        // check if a real file (no directory) to the given filename exist
1524
        if(FileExist(filename, ATTR_NONE, ATTR_SUBDIRECTORY|ATTR_VOLUMELABEL, file))
1535
        if(FileExist(filename, ATTR_NONE, ATTR_SUBDIRECTORY|ATTR_VOLUMELABEL, file))
1525
        {  // file exist
1536
        {  // file exist
1526
                switch(mode)  // check mode
1537
                switch(mode)  // check mode
Line 2452... Line 2463...
2452
        u8      dircount = 0;                                   // the number of subdirectoryentries within the path
2463
        u8      dircount = 0;                                   // the number of subdirectoryentries within the path
2453
        u8      cache[64];                                              // a buffer containing the name of the subdirectory we are actually looking for
2464
        u8      cache[64];                                              // a buffer containing the name of the subdirectory we are actually looking for
2454
        Find_t  fe;                                                             // The findelement needed for function findfirst to find the subdirectoryentry
2465
        Find_t  fe;                                                             // The findelement needed for function findfirst to find the subdirectoryentry
2455
        s8              tp[256];                                                // temporarily we remember the actual path until the operation has finished successfully
2466
        s8              tp[256];                                                // temporarily we remember the actual path until the operation has finished successfully
2456
        u32     cwdt = 0;
2467
        u32     cwdt = 0;
-
 
2468
        s8     *cptr;
Line -... Line 2469...
-
 
2469
 
-
 
2470
        /* bring the path into the correct syntax */
-
 
2471
        cptr = path;
-
 
2472
        /* search the whole string */
-
 
2473
        while(*cptr != 0)
-
 
2474
        {
-
 
2475
                if(*cptr == '\\') *cptr = '/';
-
 
2476
                cptr++;
2457
 
2477
        }
2458
        /* lets remember the actual path */
2478
        /* lets remember the actual path */
2459
        strcpy(tp, Partition.PathToCwd);
2479
        strcpy(tp, Partition.PathToCwd);
-
 
2480
        cwdt = Partition.CurrentWorkingDirectory;
-
 
2481
        /* how many subdirectories are there within the path? */
2460
        cwdt = Partition.CurrentWorkingDirectory;
2482
        dircount = GetDirCount(path);  
2461
        /* if the path is absolute we begin at the rootdirectory */
2483
        /* if the path is absolute we begin at the rootdirectory */
2462
        if(path[0] == '/')
2484
        if(path[0] == '/')
2463
        {
2485
        {
2464
                strcpy(Partition.PathToCwd, "/");
2486
                strcpy(Partition.PathToCwd, "/");
-
 
2487
                Partition.CurrentWorkingDirectory = Partition.FirstRootDirSector;
-
 
2488
                /* if there is no other pathinformation we only switch to the rootdirectory. So theres nothing left todo.*/
2465
                Partition.CurrentWorkingDirectory = Partition.FirstRootDirSector;
2489
                if(!dircount) return(1);
2466
        }
-
 
2467
        /* how many subdirectories are there within the path? */
-
 
2468
        dircount = GetDirCount(path);  
2490
        }
2469
        /* now we parse through all the subdirectories within the path */
2491
        /* now we parse through all the subdirectories within the path */
2470
        do
2492
        do
2471
        {  
2493
        {  
2472
                /* until all the subdirectories within the path have been processed */
2494
                /* until all the subdirectories within the path have been processed */
Line 2505... Line 2527...
2505
                Partition.CurrentWorkingDirectory = cwdt;                                                  
2527
                Partition.CurrentWorkingDirectory = cwdt;                                                  
2506
                strcpy(Partition.PathToCwd, tp);
2528
                strcpy(Partition.PathToCwd, tp);
2507
        }
2529
        }
2508
        return(retvalue);      
2530
        return(retvalue);      
2509
}
2531
}
2510
 
-
 
2511
 
-
 
2512
 
-
 
2513
void Test(void)
-
 
2514
{
-
 
2515
        Find_t find;
-
 
2516
        text[64];
-
 
2517
 
-
 
2518
        UART1_PutString("\r\nsearching for elements in CWD:");
-
 
2519
        UART1_PutString(GetPath());
-
 
2520
                                                                                 
-
 
2521
        if(chdir_("log"))
-
 
2522
        {
-
 
2523
                UART1_PutString(" done");
-
 
2524
                UART1_PutString("\r\n cwd: "); UART1_PutString(GetPath());
-
 
2525
 
-
 
2526
                if(chdir_("log11"))
-
 
2527
                {
-
 
2528
                        UART1_PutString(" done");
-
 
2529
                        UART1_PutString("\r\n cwd: "); UART1_PutString(GetPath());
-
 
2530
 
-
 
2531
                        if(chdir_("log12"))
-
 
2532
                        {
-
 
2533
                                UART1_PutString(" done");
-
 
2534
                                UART1_PutString("\r\n cwd: "); UART1_PutString(GetPath());
-
 
2535
 
-
 
2536
                                if(findfirst_("*.*", 0xff, &find))
-
 
2537
                                {
-
 
2538
                                        sprintf(text,"\r\n %s %x",find.name, find.fp.Attribute); UART1_PutString(text);
-
 
2539
                                        while(findnext_(&find))
-
 
2540
                                        {
-
 
2541
                                                sprintf(text,"\r\n %s %x",find.name, find.fp.Attribute); UART1_PutString(text);
-
 
2542
                                        }
-
 
2543
                                }
-
 
2544
                                if(chdir_("."))
-
 
2545
                                {
-
 
2546
                                        UART1_PutString(" done");
-
 
2547
                                        UART1_PutString("\r\n cwd: "); UART1_PutString(GetPath());
-
 
2548
                                        if(findfirst_("*.*", 0xff, &find))
-
 
2549
                                        {
-
 
2550
                                                sprintf(text,"\r\n %s %x",find.name, find.fp.Attribute); UART1_PutString(text);
-
 
2551
                                                while(findnext_(&find))
-
 
2552
                                                {
-
 
2553
                                                        sprintf(text,"\r\n %s %x",find.name, find.fp.Attribute); UART1_PutString(text);
-
 
2554
                                                }
-
 
2555
                                        }
-
 
2556
                                }
-
 
2557
                                else UART1_PutString(" failed");
-
 
2558
                                if(chdir_(".."))
-
 
2559
                                {
-
 
2560
                                        UART1_PutString(" done");
-
 
2561
                                        UART1_PutString("\r\n cwd: "); UART1_PutString(GetPath());
-
 
2562
                                        if(findfirst_("*.*", 0xff, &find))
-
 
2563
                                        {
-
 
2564
                                                sprintf(text,"\r\n %s %x",find.name, find.fp.Attribute); UART1_PutString(text);
-
 
2565
                                                while(findnext_(&find))
-
 
2566
                                                {
-
 
2567
                                                        sprintf(text,"\r\n %s %x",find.name, find.fp.Attribute); UART1_PutString(text);
-
 
2568
                                                }
-
 
2569
                                        }
-
 
2570
                                }      
-
 
2571
                                else UART1_PutString(" failed");
-
 
2572
                                if(chdir_(".."))
-
 
2573
                                {
-
 
2574
                                        UART1_PutString(" done");
-
 
2575
                                        UART1_PutString("\r\n cwd: "); UART1_PutString(GetPath());
-
 
2576
                                        if(findfirst_("*.*", 0xff, &find))
-
 
2577
                                        {
-
 
2578
                                                sprintf(text,"\r\n %s %x",find.name, find.fp.Attribute); UART1_PutString(text);
-
 
2579
                                                while(findnext_(&find))
-
 
2580
                                                {
-
 
2581
                                                        sprintf(text,"\r\n %s %x",find.name, find.fp.Attribute); UART1_PutString(text);
-
 
2582
                                                }
-
 
2583
                                        }
-
 
2584
                                }      
-
 
2585
                                else UART1_PutString(" failed");
-
 
2586
                                if(chdir_(".."))
-
 
2587
                                {
-
 
2588
                                        UART1_PutString(" done");
-
 
2589
                                        UART1_PutString("\r\n cwd: "); UART1_PutString(GetPath());
-
 
2590
                                        if(findfirst_("*.*", 0xff, &find))
-
 
2591
                                        {
-
 
2592
                                                sprintf(text,"\r\n %s %x",find.name, find.fp.Attribute); UART1_PutString(text);
-
 
2593
                                                while(findnext_(&find))
-
 
2594
                                                {
-
 
2595
                                                        sprintf(text,"\r\n %s %x",find.name, find.fp.Attribute); UART1_PutString(text);
-
 
2596
                                                }
-
 
2597
                                        }
-
 
2598
                                }      
-
 
2599
                                else UART1_PutString(" failed");
-
 
2600
                        }
-
 
2601
                }
-
 
2602
        }
-
 
2603
        else UART1_PutString(" failed");
-
 
2604
}
-