Ignore:
Timestamp:
Feb 4, 2016, 5:05:56 PM (8 years ago)
Author:
alain
Message:

Introduce the dump command in shell.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • soft/giet_vm/applications/shell/shell.c

    r772 r775  
    4444static void cmd_time(int argc, char** argv)
    4545{
    46     giet_tty_printf("%d\n", giet_proctime());
     46    giet_tty_printf(" cycle = %d\n", giet_proctime());
    4747}
    4848
     
    5050static void cmd_ls(int argc, char** argv)
    5151{
    52     int fd;
    53     fat_dirent_t entry;
    54 
    55     if (argc < 2)
    56     {
    57         giet_tty_printf("  usage : %s <pathname>\n", argv[0]);
    58         return;
    59     }
    60 
    61     fd = giet_fat_opendir(argv[1]);
     52    int            fd;
     53    int            rec;
     54    char*          pathname;
     55    fat_dirent_t   entry;
     56
     57    if (argc == 2)
     58    {
     59        rec = 0;
     60        pathname = argv[1];
     61    }
     62    else if ( (argc == 3) && (strcmp( argv[1] , "-r" ) == 0) )
     63    {
     64        rec = 1;
     65        pathname = argv[2];
     66
     67        giet_tty_printf("  error : recursive mode not supported yet\n");
     68        return;
     69    }
     70    else
     71    {
     72        giet_tty_printf("  usage : ls [-r] pathname\n");
     73        return;
     74    }
     75
     76    fd  = giet_fat_opendir( pathname );
    6277
    6378    if (fd < 0)
     
    8499    if (argc < 2)
    85100    {
    86         giet_tty_printf("  usage : %s <path>\n", argv[0]);
     101        giet_tty_printf("  usage : mkdir pathname\n");
    87102        return;
    88103    }
     
    101116    if (argc < 3)
    102117    {
    103         giet_tty_printf("  usage : %s <src> <dst>\n", argv[0]);
     118        giet_tty_printf("  usage : cp src_pathname dst_pathname>\n");
    104119        return;
    105120    }
     
    141156    if (info.is_dir)
    142157    {
    143         giet_tty_printf("error : %s is a directory\n", argv[2] );  // TODO
     158        giet_tty_printf("  error : %s is a directory\n", argv[2] );  // TODO
    144159        goto exit;
    145160    }
     
    150165        int len = (size - i < 1024 ? size - i : 1024);
    151166        int wlen;
    152 
    153         giet_tty_printf("\rwrite %d/%d (%d%%)", i, size, 100*i/size);
    154167
    155168        len = giet_fat_read(src_fd, &buf, len);
     
    162175        i += len;
    163176    }
    164     giet_tty_printf("\n");
    165177
    166178exit:
     
    176188    if (argc < 2)
    177189    {
    178         giet_tty_printf("  usage : %s <file>\n", argv[0]);
     190        giet_tty_printf("  usage : rm pathname\n");
    179191        return;
    180192    }
     
    193205    if (argc < 2)
    194206    {
    195         giet_tty_printf("  usage : %s <pathname>\n", argv[0]);
     207        giet_tty_printf("  usage : rmdir pathname\n");
    196208        return;
    197209    }
     
    209221    if (argc < 3)
    210222    {
    211         giet_tty_printf("  usage : %s <src> <dst>\n", argv[0]);
     223        giet_tty_printf("  usage : %s src_pathname dst_pathname\n", argv[0]);
    212224        return;
    213225    }
     
    225237    if (argc < 2)
    226238    {
    227         giet_tty_printf("  usage : %s <vspace_name>\n", argv[0]);
     239        giet_tty_printf("  usage : %s vspace_name\n", argv[0]);
    228240        return;
    229241    }
     
    241253    if (argc < 2)
    242254    {
    243         giet_tty_printf("  usage : %s <vspace_name>\n", argv[0]);
     255        giet_tty_printf("  usage : %s vspace_name\n", argv[0]);
    244256        return;
    245257    }
     
    274286    if (argc < 3)
    275287    {
    276         giet_tty_printf("  usage : %s <vspace_name> <thread_name>\n", argv[0] );
     288        giet_tty_printf("  usage : %s vspace_name thread_name\n", argv[0] );
    277289        return;
    278290    }
     
    286298    if (argc < 3)
    287299    {
    288         giet_tty_printf("  usage : %s <vspace_name> <thread_name>\n", argv[0] );
     300        giet_tty_printf("  usage : %s vspace_name thread_name\n", argv[0] );
    289301        return;
    290302    }
     
    298310    if (argc < 3)
    299311    {
    300         giet_tty_printf("  usage : %s <vspace_name> <thread_name>\n", argv[0] );
     312        giet_tty_printf("  usage : %s vspace_name thread_name\n", argv[0] );
    301313        return;
    302314    }
     
    308320static void cmd_cat(int argc, char** argv)
    309321{
    310     if (argc < 2)
    311     {
    312         giet_tty_printf("  usage : %s <path_name> \n", argv[0] );
     322    if (argc != 2)
     323    {
     324        giet_tty_printf("  usage : cat pathname \n");
    313325        return;
    314326    }
     
    358370    }
    359371
    360 /*
    361     // allocate a temporary buffer for the file
    362     heap_init( x , y );
    363     buf = (char*)malloc( size ); 
    364     if( buf == NULL )
    365     {
    366         giet_tty_printf("  error : cannot allocate buffer with size = %d\n", size );
    367         goto exit;
    368     }
    369     // load the file
    370     len = giet_fat_read( fd , buf , size );
    371     if ( len != size )
    372     {
    373         giet_tty_printf("  error : cannot load file %s / size = %d / len = %d\n",
    374                         argv[1] , size , len );
    375         goto exit;
    376     }
    377 */
    378372    // set terminating '0'
    379373    buf[size] = 0;
     
    387381}
    388382
     383///////////////////////////////////////////
     384static void cmd_dump(int argc, char** argv)
     385{
     386    if ((argc == 2) && (strcmp( argv[1] , "-bs" ) == 0))
     387    {
     388        giet_fat_dump( DUMP_BS , NULL , 0 );
     389    }
     390    else if ((argc == 2) && (strcmp( argv[1] , "-fs" ) == 0))
     391    {
     392        giet_fat_dump( DUMP_FS , NULL , 0 );
     393    }
     394    else if ((argc == 3) && (strcmp( argv[1] , "-fat" ) == 0))
     395    {
     396        giet_fat_dump( DUMP_FAT , NULL , atoi( argv[2] ) );
     397    }
     398    else if ((argc == 4) && (strcmp( argv[1] , "-file" ) == 0))
     399    {
     400        giet_fat_dump( DUMP_FILE , argv[2] , atoi( argv[3] ) );
     401    }
     402    else if ((argc == 4) && (strcmp( argv[1] , "-dir" ) == 0))
     403    {
     404        giet_fat_dump( DUMP_DIR , argv[2] , atoi( argv[3] ) );
     405    }
     406    else
     407    {
     408        giet_tty_printf("  usage : dump [-bs] [-fs] [-fat block] "
     409                        "[-file pathname block] [-dir pathname block]\n");
     410        return;
     411    }
     412}
     413
     414
    389415////////////////////////////////////////////////////////////////////
    390416struct command_t cmd[] =
     
    393419    { "context",    "display a thread context",             cmd_context },
    394420    { "cp",         "replicate a file in file system",      cmd_cp },
     421    { "dump",       "display content of disk sector",       cmd_dump },
    395422    { "exec",       "start an application",                 cmd_exec },
    396423    { "help",       "list available commands",              cmd_help },
Note: See TracChangeset for help on using the changeset viewer.