Changeset 623 for trunk/user/ksh


Ignore:
Timestamp:
Mar 6, 2019, 4:37:15 PM (5 years ago)
Author:
alain
Message:

Introduce three new types of vsegs (KCODE,KDATA,KDEV)
to map the kernel vsegs in the process VSL and GPT.
This now used by both the TSAR and the I86 architectures.

File:
1 edited

Legend:

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

    r619 r623  
    5858#define DEBUG_INTER         0
    5959#define DEBUG_PARSE         0
    60 #define DEBUG_CMD_CAT       0
     60#define DEBUG_CMD_CAT       1
    6161#define DEBUG_CMD_CP        0
    6262#define DEBUG_CMD_LOAD      0
     
    122122        if (argc != 2)
    123123    {
    124         fd   = -1;
    125         buf  = NULL;
    126         size = 0;
    127124                printf("  usage: cat pathname\n");
    128             goto cmd_cat_exit;
     125
     126        sem_post( &semaphore );
     127            return;
    129128    }
    130129
     
    135134    if (fd < 0)
    136135    {
    137         buf  = NULL;
    138         size = 0;
    139136            printf("  error: cannot open file <%s>\n", path);
    140             goto cmd_cat_exit;
     137
     138        sem_post( &semaphore );
     139            return;
    141140    }
    142141
    143142#if DEBUG_CMD_CAT
    144 snprintf( string , 64 , "[KSH] %s : file %s open", __FUNCTION__, path );
     143snprintf( string , 64 , "[ksh] %s : file %s open", __FUNCTION__, path );
    145144display_string( string );
    146145#endif
     
    149148    if ( stat( path , &st ) == -1)
    150149    {
    151         buf  = NULL;
    152         size = 0;
    153150            printf("  error: cannot stat <%s>\n", path);
    154             goto cmd_cat_exit;
     151
     152            close(fd);
     153        sem_post( &semaphore );
     154            return;
    155155    }
    156156
    157157        if ( S_ISDIR(st.st_mode) )
    158158    {
    159         buf  = NULL;
    160         size = 0;
    161159            printf("  error: <%s> is a directory\n", path);
    162             goto cmd_cat_exit;
     160
     161            close(fd);
     162        sem_post( &semaphore );
     163            return;
    163164    }
    164165
     
    167168
    168169#if DEBUG_CMD_CAT
    169 snprintf( string , 64 , "[KSH] %s : get size = %d", __FUNCTION__, size );
    170 display_string( string );
    171 #endif
    172 
    173     // MAP_FILE is default type when MAP_ANON and MAP_REMOTE are not specified
     170snprintf( string , 64 , "[ksh] %s : size = %d", __FUNCTION__, size );
     171display_string( string );
     172#endif
     173
     174    if( size == 0 )
     175    {
     176            printf("  error: size = 0 for <%s>\n", path);
     177
     178            close(fd);
     179        sem_post( &semaphore );
     180            return;
     181    }
     182
     183    // mapping type is MAP_FILE when MAP_ANON and MAP_REMOTE are not specified
    174184    buf = mmap( NULL , size , PROT_READ|PROT_WRITE , MAP_PRIVATE , fd , 0 );
    175185
     
    177187    {
    178188            printf("  error: cannot map file <%s>\n", path );
    179             goto cmd_cat_exit;
     189
     190            close(fd);
     191        sem_post( &semaphore );
     192            return;
    180193    }
    181194
    182195#if DEBUG_CMD_CAT
    183 snprintf( string , 64 , "[KSH] %s : map file %d to buffer %x", __FUNCTION__, fd , buf );
    184 display_string( string );
    185 display_vmm( 0 , getpid() );
     196snprintf( string , 64 , "[ksh] %s : maped file %d to buffer %x", __FUNCTION__, fd , buf );
     197display_string( string );
     198// unsigned int pid = getpid();
     199// unsigned int cxy = pid >> 16;
     200// display_vmm( cxy , pid );
    186201#endif
    187202
     
    189204    write( 1 , buf , size );
    190205
    191     // release semaphore to get next command
    192     sem_post( &semaphore );
    193 
    194     return;
    195 
    196 cmd_cat_exit:
    197 
    198         if (buf != NULL) munmap(buf, size);
    199         if (fd >= 0) close(fd);
     206    // unmap te file
     207    if( munmap( buf , size ) )
     208    {
     209            printf("  error: cannot unmap file <%s>\n", path );
     210    }
     211
     212#if DEBUG_CMD_CAT
     213snprintf( string , 64 , "[ksh] %s : unmaped file %d from buffer %x", __FUNCTION__, fd , buf );
     214display_string( string );
     215// display_vmm( cxy , pid );
     216#endif
     217
     218    // close the file
     219        if( close( fd ) )
     220    {
     221            printf("  error: cannot close file <%s>\n", path );
     222    }
    200223
    201224    // release semaphore to get next command
     
    267290
    268291#if DEBUG_CMD_CP
    269 snprintf( string , 64 , "[KSH] %s : file %s open", __FUNCTION__, srcpath );
     292snprintf( string , 64 , "[ksh] %s : file %s open", __FUNCTION__, srcpath );
    270293display_string( string );
    271294#endif
     
    280303
    281304#if DEBUG_CMD_CP
    282 snprintf( string , 64 , "[KSH] %s : got stats for %s", __FUNCTION__, srcpath );
     305snprintf( string , 64 , "[ksh] %s : got stats for %s", __FUNCTION__, srcpath );
    283306display_string( string );
    284307#endif
     
    304327
    305328#if DEBUG_CMD_CP
    306 snprintf( string , 64 , "[KSH] %s : file %s open", __FUNCTION__, dstpath );
     329snprintf( string , 64 , "[ksh] %s : file %s open", __FUNCTION__, dstpath );
    307330display_string( string );
    308331#endif
     
    315338
    316339#if DEBUG_CMD_CP
    317 snprintf( string , 64 , "[KSH] %s : got stats for %s", __FUNCTION__, dstpath );
     340snprintf( string , 64 , "[ksh] %s : got stats for %s", __FUNCTION__, dstpath );
    318341display_string( string );
    319342#endif
     
    339362
    340363#if DEBUG_CMD_CP
    341 snprintf( string , 64 , "[KSH] %s : read %d bytes from %s", __FUNCTION__, len, srcpath );
     364snprintf( string , 64 , "[ksh] %s : read %d bytes from %s", __FUNCTION__, len, srcpath );
    342365display_string( string );
    343366#endif
     
    351374
    352375#if DEBUG_CMD_CP
    353 snprintf( string , 64 , "[KSH] %s : write %d bytes to %s", __FUNCTION__, len, dstpath );
     376snprintf( string , 64 , "[ksh] %s : write %d bytes to %s", __FUNCTION__, len, dstpath );
    354377display_string( string );
    355378#endif
     
    381404               "         display  dqdt\n"             
    382405               "         display  locks    pid    trdid\n"
     406               "         display  barrier  pid\n"
    383407               "         display  mapper   path   page_id  nbytes\n");
    384408    }
     
    504528            {
    505529                printf("  error: illegal arguments pid = %x / trdid = %x\n", pid, trdid );
     530            }
     531        }
     532    }
     533    /////////////////////////////////////////////////
     534    else if( strcmp( argv[1] , "barrier" ) == 0 )
     535    {
     536        if( argc != 3 )
     537        {
     538                    printf("  usage: display barrier pid\n");
     539            }
     540        else
     541        {
     542                unsigned int pid   = atoi(argv[2]);
     543
     544            if( display_barrier( pid ) )
     545            {
     546                printf("  error: illegal arguments pid = %x\n", pid );
    506547            }
    507548        }
     
    678719
    679720#if DEBUG_CMD_LOAD
    680 snprintf( string , 64 , "[KSH] %s : ksh_pid %x / path %s / bg %d / place %d (%x)\n",
     721snprintf( string , 64 , "[ksh] %s : ksh_pid %x / path %s / bg %d / place %d (%x)\n",
    681722__FUNCTION__, ksh_pid, argv[1], background, placement, cxy );
    682723display_string( string );
     
    697738
    698739#if DEBUG_CMD_LOAD
    699 snprintf( string , 64 , "[KSH] %s : child_pid %x after fork, before exec\n",
     740snprintf( string , 64 , "[ksh] %s : child_pid %x after fork, before exec\n",
    700741__FUNCTION__ , getpid() );
    701742display_string( string );
     
    706747
    707748#if DEBUG_CMD_LOAD
    708 snprintf( string , 64 , "[KSH] %s : child_pid %x after exec / ret_exec %x\n",
     749snprintf( string , 64 , "[ksh] %s : child_pid %x after exec / ret_exec %x\n",
    709750__FUNCTION__ , getpid(), ret_exec );
    710751display_string( string );
     
    722763
    723764#if DEBUG_CMD_LOAD
    724 snprintf( string , 64 , "[KSH] %s : ksh_pid %x after fork / ret_fork %x\n",
     765snprintf( string , 64 , "[ksh] %s : ksh_pid %x after fork / ret_fork %x\n",
    725766__FUNCTION__, getpid(), ret_fork );
    726767display_string( string );
     
    795836
    796837#if DEBUG_CMD_LS
    797 snprintf( string , 64 , "[KSH] %s : directory <%s> open / DIR %x\n",
     838snprintf( string , 64 , "[ksh] %s : directory <%s> open / DIR %x\n",
    798839__FUNCTION__, pathname , dir );
    799840display_string( string );
     
    803844            {
    804845                    printf("  error : directory <%s> not found\n", pathname );
    805             goto cmd_ls_exit;
     846
     847            sem_post( &semaphore );
     848            return;
    806849            }
    807850
     
    816859
    817860#if DEBUG_CMD_LS
    818 snprintf( string , 64 , "[KSH] %s : directory <%s> closed\n",
     861snprintf( string , 64 , "[ksh] %s : directory <%s> closed\n",
    819862__FUNCTION__, pathname );
    820863display_string( string );
     
    822865
    823866    }
    824 
    825 cmd_ls_exit:
    826867
    827868    // release semaphore to get next command
     
    908949
    909950#if DEBUG_CMD_PS
    910 snprintf( string , 64 , "\n[KSH] %s : call display_cluster_process()", __FUNCTION__ );
     951snprintf( string , 64 , "\n[ksh] %s : call display_cluster_process()", __FUNCTION__ );
    911952display_string( string );
    912953#endif
     
    10711112#if DEBUG_PARSE
    10721113char string[64];
    1073 snprintf( string , 64 , "\n[KSH] %s : <%s>", __FUNCTION__ , buf );
     1114snprintf( string , 64 , "\n[ksh] %s : <%s>", __FUNCTION__ , buf );
    10741115display_string( string );
    10751116#endif
     
    10941135
    10951136#if DEBUG_PARSE
    1096 snprintf( string , 64 , "\n[KSH] %s : argc = %d for <%s>", __FUNCTION__ , argc , argv[0] );
     1137snprintf( string , 64 , "\n[ksh] %s : argc = %d for <%s>", __FUNCTION__ , argc , argv[0] );
    10971138display_string( string );
    10981139#endif
     
    11931234#if DEBUG_INTER
    11941235unsigned int pid = getpid();
    1195 snprintf( string , 64 , "\n[KSH] %s : request a new command", __FUNCTION__ );
     1236snprintf( string , 64 , "\n[ksh] %s : request a new command", __FUNCTION__ );
    11961237display_string( string );
    11971238#endif
     
    12301271
    12311272#if DEBUG_INTER
    1232 snprintf( string , 64 , "[KSH] %s : parse and execute <%s>", __FUNCTION__, cmd );
     1273snprintf( string , 64 , "[ksh] %s : parse and execute <%s>", __FUNCTION__, cmd );
    12331274display_string( string );
    12341275#endif
     
    13501391
    13511392#if DEBUG_INTER
    1352 snprintf( string , 64 , "\n[KSH] %s : complete <%s> command", __FUNCTION__, cmd );
     1393snprintf( string , 64 , "\n[ksh] %s : complete <%s> command", __FUNCTION__, cmd );
    13531394display_string( string );
    13541395#endif
Note: See TracChangeset for help on using the changeset viewer.