예제 #1
0
파일: filesys.c 프로젝트: ljalves/FUZIX
inoptr i_open(uint16_t dev, uint16_t ino)
{
    struct dinode *buf;
    inoptr nindex, j;
    bool isnew = false;

    if(!validdev(dev))
        panic("i_open: bad dev");

    if(!ino){        /* ino==0 means we want a new one */
        isnew = true;
        ino = i_alloc(dev);
        if(!ino) {
            udata.u_error = ENOSPC;
            return NULLINODE;
        }
    }

    /* Maybe make this DEBUG only eventually - the fs_tab_get cost
       is higher than ideal */
    if(ino < ROOTINODE || ino >= (fs_tab_get(dev)->m_fs->s_isize - 2) * 8) {
        kputs("i_open: bad inode number\n");
        return NULLINODE;
    }

    nindex = NULLINODE;
    for(j=i_tab; j<i_tab+ITABSIZE; j++){
        if(!j->c_refs) // free slot?
            nindex = j;

        if(j->c_dev == dev && j->c_num == ino) {
            nindex = j;
            goto found;
        }
    }
    /* Not already in the table. */

    if(!nindex){      /* No unrefed slots in inode table */
        udata.u_error = ENFILE;
        return(NULLINODE);
    }

    buf =(struct dinode *)bread(dev,(ino>>3)+2, 0);
    memcpy((char *)&(nindex->c_node), (char *)&(buf[ino & 0x07]), 64);
    brelse(buf);

    nindex->c_dev = dev;
    nindex->c_num = ino;
    nindex->c_magic = CMAGIC;

found:
    if(isnew) {
        if(nindex->c_node.i_nlink || nindex->c_node.i_mode & F_MASK)
            goto badino;
    } else {
        if(!(nindex->c_node.i_nlink && nindex->c_node.i_mode & F_MASK))
            goto badino;
    }
    nindex->c_refs++;
    return nindex;

badino:
    kputs("i_open: bad disk inode\n");
    return NULLINODE;
}
예제 #2
0
void Basic_Input(struct comm_info* c_info,
                 struct Bench** P_BList,
                 int *argc, char ***argv,int* NP_min)
/********************************************************************


---------------------------------------------------------------------
             VARIABLE |       TYPE        |   MEANING
---------------------------------------------------------------------
Input:       argc     | int*              | number of comm. line args
             argv     | char***           | command line arguments

In/Out     : c_info   | struct comm_info* | see comm_info.h
                      |                   | (will be partially initialized)
                      |                   |
Output     :
             P_BList  | struct Bench**    | *P_Blist =
                      |                   | array of Benchmarks descriptors
                      |                   |
             NP_min   | int               | minimum number of processes
                      |                   |
----------------------------------------------------------------------
----------------------------------------------------------------------
Description: Initializing options defined in command line.
             1. Selection of individual benchmarks
	        (e.g. mpirun -np * pmb Allreduce )
             2. Selection of additional args:
	        (e.g. mpirun -np * pmb -npmin * -group * )
--------------------------------------------------------------------*/


{
    int i,n_cases,iarg;
    int deflt;
    int * ALL_INFO;
    char** DEFC, **CMT;

    MPI_Comm_rank(MPI_COMM_WORLD,&c_info->w_rank);
    MPI_Comm_size(MPI_COMM_WORLD,&c_info->w_num_procs);

    unit = stdout;
    if( c_info->w_rank == 0 && strlen(OUTPUT_FILENAME) > 0 )
        unit = fopen(OUTPUT_FILENAME,"w");

#ifdef DEBUG

    dbgf_name = str("DBG_   ");
    sprintf(dbgf_name+4,"%d",c_info->w_rank);

    dbg_file = fopen(dbgf_name,"w");

#endif


    deflt = 0;

    c_info->group_mode = -1;
#ifdef MPIIO
    *NP_min=1;
#else
    *NP_min=2;
#endif

    if( c_info->w_rank == 0 )
    {
        /* Interpret command libe */

        if( *argc <= 1 )
        {
            /* Take default */
            deflt = 1;
        }
        else
        {
            n_cases = *argc-1;

            iarg = 1;

            while( iarg <= *argc-1 )
            {
                if(!strcmp((*argv)[iarg],"-npmin"))
                {
                    *NP_min=Str_Atoi((*argv)[iarg+1]);
                    if(*NP_min>=0) {
                        n_cases -= 2;
                    }
                    else
                    {
                        Err_Hand(0, APPL_ERR_OPTIONS);
                    }
                    iarg++;
                }
                if(!strcmp((*argv)[iarg],"-multi"))
                {
                    c_info->group_mode=Str_Atoi((*argv)[iarg+1]);
                    n_cases -= 2;
                    iarg++;
                }
                if(!strcmp((*argv)[iarg],"-input"))
                {
                    FILE*t = fopen((*argv)[iarg+1],"r");
                    n_cases -= 2;
                    if( t )
                    {
                        char inp_line[72];
                        while(fgets(inp_line,72,t))
                        {
                            if( inp_line[0] != '#' && strlen(inp_line)>1 )
                                n_cases++;
                        }
                        fclose(t);
                    }
                    else fprintf(unit,"Input File %s doesnt exist\n",(*argv)[iarg+1]);
                    iarg++;
                }
                iarg++;
            }

            if(n_cases <= 0 )
                deflt = 1;
            else
            {
                iarg = 1;

                while( iarg <= *argc-1 )
                {
                    if(!strcmp((*argv)[iarg],"-npmin"))
                        iarg++;
                    else if(!strcmp((*argv)[iarg],"-multi"))
                        iarg++;
                    else if(!strcmp((*argv)[iarg],"-input"))
                    {
                        FILE*t = fopen((*argv)[iarg+1],"r");
                        if( t )
                        {
                            char inp_line[72], nam[32];
                            while(fgets(inp_line,72,t))
                            {
                                if( inp_line[0] != '#' && strlen(inp_line)-1 )
                                {
                                    sscanf(inp_line,"%s",nam);
                                    Construct_BList(P_BList,n_cases,nam);
                                }
                            }
                            fclose(t);
                        }
                        else fprintf(unit,"Input File %s doesnt exist\n",(*argv)[iarg+1]);
                        iarg++;
                    }
                    else
                    {
                        Construct_BList(P_BList,n_cases,(*argv)[iarg]);
                    }
                    iarg ++;
                }
            }
        }

        if( deflt) {
            n_cases = 0;
            Construct_BList(P_BList,0,"ALL");
        }

        i_alloc(&ALL_INFO,4+n_cases,"Basic_Input");


        if( !deflt )
        {

            i=0;
            n_cases = 0;

            while( (*P_BList)[i].name )
            {
                int index;
                Get_Def_Index(&index,(*P_BList)[i].name );

                if( index >= 0 )
                    ALL_INFO[4+n_cases++] = index;

                i++;
            }
        }

        ALL_INFO[0] = *NP_min;
        ALL_INFO[1] = c_info->group_mode;
        ALL_INFO[2] = deflt;
        ALL_INFO[3] = n_cases;

        MPI_Bcast(ALL_INFO,4,MPI_INT,0,MPI_COMM_WORLD);

        if(n_cases > 0 && !deflt)
            MPI_Bcast(ALL_INFO+4,n_cases,MPI_INT,0,MPI_COMM_WORLD);

        free(ALL_INFO);

    }
    else  /* w_rank > 0 */
        /* Receive input arguments */

    {
        int TMP[4];
        MPI_Bcast(TMP,4,MPI_INT,0,MPI_COMM_WORLD);


        *NP_min = TMP[0];
        c_info->group_mode = TMP[1];
        deflt = TMP[2];
        n_cases = TMP[3];

        if( deflt )
            Construct_BList(P_BList,0,"ALL");
        else if( n_cases>0 )
        {
            i_alloc(&ALL_INFO,n_cases,"Basic_Input");
            MPI_Bcast(ALL_INFO,n_cases,MPI_INT,0,MPI_COMM_WORLD);
            Get_Def_Cases(&DEFC,&CMT);
            for( i = 0; i<n_cases; i++ )
                Construct_BList(P_BList,n_cases,DEFC[ALL_INFO[i]]);
            free(ALL_INFO);
        }
        else
            Construct_BList(P_BList,1,"");

    }

#ifndef EXT
    if( do_nonblocking )
        CPU_Exploit(TARGET_CPU_SECS, 1);
#endif

}