Changeset 610 for trunk/user


Ignore:
Timestamp:
Dec 27, 2018, 7:38:58 PM (6 years ago)
Author:
alain
Message:

Fix several bugs in VFS to support the following
ksh commandis : cp, mv, rm, mkdir, cd, pwd

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/user/ksh/ksh.c

    r608 r610  
    5555
    5656#define MAIN_DEBUG          0
     57
     58#define CMD_CAT_DEBUG       0
     59#define CMD_CP_DEBUG        0
    5760#define CMD_LOAD_DEBUG      0
    58 #define CMD_CAT_DEBUG       0
    5961
    6062//////////////////////////////////////////////////////////////////////////////////////////
     
    209211            path = argv[1];
    210212
    211         printf("  error: not implemented yet\n" );
     213        // call the relevant syscall
     214        if( chdir( path ) )
     215        {
     216            printf("  error: cannot found <%s> directory\n", path );
     217        }
    212218    }
    213219
     
    250256    }
    251257
     258#if CMD_CP_DEBUG
     259long long unsigned cycle;
     260get_cycle( &cycle );
     261printf("\n[%s] open file <%s> done / cycle %d\n",
     262__FUNCTION__ , srcpath , (int)cycle );
     263#endif
     264
    252265    // get file stats
    253266    if ( stat( srcpath , &st ) )
     
    258271    }
    259272
     273#if CMD_CP_DEBUG
     274get_cycle( &cycle );
     275printf("\n[%s] stats file <%s> done / cycle %d\n",
     276__FUNCTION__ , srcpath , (int)cycle );
     277#endif
     278
    260279        if ( S_ISDIR(st.st_mode) )
    261280    {
     
    277296        }
    278297
     298#if CMD_CP_DEBUG
     299get_cycle( &cycle );
     300printf("\n[%s] open file <%s> done / cycle %d\n",
     301__FUNCTION__ , dstpath , (int)cycle );
     302#endif
     303
    279304        if ( stat( dstpath , &st ) )
    280305    {
     
    282307                goto exit;
    283308        }
     309
     310#if CMD_CP_DEBUG
     311get_cycle( &cycle );
     312printf("\n[%s] stats file <%s> done / cycle %d\n",
     313__FUNCTION__ , dstpath , (int)cycle );
     314#endif
    284315
    285316        if ( S_ISDIR(st.st_mode ) )
     
    302333                }
    303334
     335#if CMD_CP_DEBUG
     336get_cycle( &cycle );
     337printf("\n[%s] %d bytes read from <%s> / cycle %d\n",
     338__FUNCTION__ , len, srcpath , (int)cycle );
     339#endif
     340
    304341                // write to the destination
    305342                if ( write( dst_fd , buf , len ) != len )
     
    308345                        goto exit;
    309346                }
     347
     348#if CMD_CP_DEBUG
     349get_cycle( &cycle );
     350printf("\n[%s] %d bytes writen to <%s> / cycle %d\n",
     351__FUNCTION__ , len, dstpath , (int)cycle );
     352#endif
    310353
    311354                bytes += len;
     
    733776        pathname = argv[1];
    734777
    735         printf("  error: not implemented yet\n");
     778        mkdir( pathname , 0x777 );
    736779    }
    737780
     
    744787static void cmd_mv( int argc , char **argv )
    745788{
    746 
    747         if (argc < 3)
    748         {
    749                 printf("  usage : mv src_pathname dst_pathname\n");
     789        char * old_path;
     790    char * new_path;
     791
     792        if (argc != 3)
     793    {
     794                printf("  usage: mv old_pathname new_pathname\n");
    750795        }
    751796    else
    752797    {
    753         printf("  error: not implemented yet\n");
    754     }
    755    
     798        old_path = argv[1];
     799        new_path = argv[2];
     800
     801        // call the relevant syscall
     802        if( rename( old_path , new_path ) )
     803        {
     804            printf("  error: unable to rename <%s> to <%s>\n", old_path, new_path );
     805        }
     806    }
     807
    756808    // release semaphore to get next command
    757809    sem_post( &semaphore );
     
    9961048
    9971049
    998 /* To lauch one application without interactive mode
     1050// To lauch one command without interactive mode
    9991051   
    10001052if( sem_wait( &semaphore ) )
     
    10051057else
    10061058{
    1007     printf("\n[ksh] for fft\n");
     1059    printf("\n[ksh] cp /home/Makefile /home/bloup\n");
    10081060}
    10091061
    1010 strcpy( buf , "load /bin/user/fft.elf" );
     1062strcpy( buf , "cp /home/Makefile /home/bloup" );
    10111063parse( buf );
    10121064
    1013 */
     1065//
    10141066
    10151067        enum fsm_states
Note: See TracChangeset for help on using the changeset viewer.