Beispiel #1
0
EFI_STATUS InitializeRamDiskDriver(
	IN EFI_HANDLE       ImageHandle,
	IN EFI_SYSTEM_TABLE *SystemTable)
{
	EFI_STATUS           Status;
	RAM_DISK_DEV         *RamDiskDev;
	UINT32               RamDiskSize;
	UINT32               NumPages;
	UINT32               BlockSize;
	UINT64               DiskId;

	/*
	 * Make a copy of the system table to workaround load command bug
	 */
	CopyMem(&BackupSystemTable,SystemTable,sizeof(BackupSystemTable));

	/*
	 * Initialize EFI library
	 */
	//InitializeLib(ImageHandle,&BackupSystemTable);

	/* IA64 compiler is removing version string (unused?) so I use it */
	//v[0] = 'v';

	/*
	 *  Set the disk size
	 */
	RamDiskSize = GetDiskSize(ImageHandle);
	BlockSize   = 512;

	/* Allocate storage for ramdisk device info on the heap.
	 */
	RamDiskDev = AllocateZeroPool(sizeof(RAM_DISK_DEV));
	if(RamDiskDev == NULL)
		return EFI_OUT_OF_RESOURCES;

	/*
	 * Compute the number of 4KB pages needed by the ramdisk and allocate the memory.
	 */
	NumPages = RamDiskSize / EFI_PAGE_SIZE;
	if(NumPages % RamDiskSize)
		NumPages++;

	Status = gBS->AllocatePages(AllocateAnyPages,EfiBootServicesData,NumPages,&RamDiskDev->Start);
	if(EFI_ERROR(Status)) {
		FreePool(RamDiskDev);
		return Status;
	}

	/*
	 * Initialize the ramdisk's device info.
	 */
	(void)gBS->GetNextMonotonicCount(&DiskId);
	CopyMem(&RamDiskDevicePath.DiskId, &DiskId, sizeof(DiskId));

	RamDiskDev->Signature            = PBLOCK_DEVICE_SIGNATURE;
	RamDiskDev->BlkIo.Revision       = EFI_BLOCK_IO_INTERFACE_REVISION;
	RamDiskDev->BlkIo.Media          = &RamDiskDev->Media;
	RamDiskDev->Media.RemovableMedia = FALSE;
	RamDiskDev->Media.MediaPresent   = TRUE;
	
	RamDiskDev->Media.LastBlock        = RamDiskSize/BlockSize - 1;
	RamDiskDev->Media.BlockSize        = BlockSize;
	RamDiskDev->Media.LogicalPartition = TRUE;
	RamDiskDev->Media.ReadOnly         = FALSE;
	RamDiskDev->Media.WriteCaching     = TRUE;
	
	RamDiskDev->BlkIo.ReadBlocks  = RamDiskReadBlocks;
	RamDiskDev->BlkIo.WriteBlocks = RamDiskWriteBlocks;
	RamDiskDev->BlkIo.FlushBlocks = RamDiskFlushBlocks;
	
	RamDiskDev->DevicePath = DuplicateDevicePath((EFI_DEVICE_PATH*)&RamDiskDevicePath);
	
	/*
	 * Build a FAT16 file system on the ramdisk.
	 */
	FormatRamdisk((VOID*)(UINTN)RamDiskDev->Start,RamDiskSize);
	
	/*
	 * Install the device.
	 */

	Status = gBS->InstallMultipleProtocolInterfaces(
	&ImageHandle,
	&gEfiBlockIoProtocolGuid,
	&RamDiskDev->BlkIo,
	&gEfiDevicePathProtocolGuid,
	RamDiskDev->DevicePath,
	NULL);

DEBUG((EFI_D_ERROR,"ramdisk:blckio install. Status=%r\n",Status));
	return Status;
}
void ManagerList::SaveResults(ostream * file, int access_index, int result_type)
{
	char specname[MAX_WORKER_NAME];
	int stat = 0;
	struct _timeb tb;
	struct tm *ptm;
	char acDummy[64];

	// Writing result header information.
	(*file) << "'Results" << endl
	    << "'Target Type,Target Name,Access Specification Name,# Managers,"
	    << "# Workers,# Disks,IOps,Read IOps,Write IOps,MBps,Read MBps,"
	    << "Write MBps,Transactions per Second,Connections per Second,"
	    << "Average Response Time,Average Read Response Time,"
	    << "Average Write Response Time,Average Transaction Time,"
	    << "Average Connection Time,Maximum Response Time,"
	    << "Maximum Read Response Time,Maximum Write Response Time,"
	    << "Maximum Transaction Time,Maximum Connection Time,"
	    << "Errors,Read Errors,Write Errors,Bytes Read,Bytes Written,Read I/Os,"
	    << "Write I/Os,Connections,Transactions per Connection,"
	    << "Total Raw Read Response Time,Total Raw Write Response Time,"
	    << "Total Raw Transaction Time,Total Raw Connection Time,"
	    << "Maximum Raw Read Response Time,Maximum Raw Write Response Time,"
	    << "Maximum Raw Transaction Time,Maximum Raw Connection Time,"
	    << "Total Raw Run Time,Starting Sector,Maximum Size,Queue Depth,"
	    << "% CPU Utilization,% User Time,% Privileged Time,% DPC Time,"
	    << "% Interrupt Time,Processor Speed,Interrupts per Second,"
	    << "CPU Effectiveness,Packets/Second,Packet Errors," << "Segments Retransmitted/Second" << endl;

	// Writing manager list results

	(*file) << "ALL" << "," << "All" << "," << GetCommonAccessSpec(access_index, specname)
	    << "," << ManagerCount(ActiveType)
	    << "," << WorkerCount(ActiveType)
	    << "," << TargetCount(ActiveType) + WorkerCount((TargetType) (GenericClientType | ActiveType))
	    << "," << results[WHOLE_TEST_PERF].IOps
	    << "," << results[WHOLE_TEST_PERF].read_IOps
	    << "," << results[WHOLE_TEST_PERF].write_IOps
	    << "," << results[WHOLE_TEST_PERF].MBps
	    << "," << results[WHOLE_TEST_PERF].read_MBps
	    << "," << results[WHOLE_TEST_PERF].write_MBps
	    << "," << results[WHOLE_TEST_PERF].transactions_per_second
	    << "," << results[WHOLE_TEST_PERF].connections_per_second
	    << "," << results[WHOLE_TEST_PERF].ave_latency
	    << "," << results[WHOLE_TEST_PERF].ave_read_latency
	    << "," << results[WHOLE_TEST_PERF].ave_write_latency
	    << "," << results[WHOLE_TEST_PERF].ave_transaction_latency
	    << "," << results[WHOLE_TEST_PERF].ave_connection_latency
	    << "," << results[WHOLE_TEST_PERF].max_latency
	    << "," << results[WHOLE_TEST_PERF].max_read_latency
	    << "," << results[WHOLE_TEST_PERF].max_write_latency
	    << "," << results[WHOLE_TEST_PERF].max_transaction_latency
	    << "," << results[WHOLE_TEST_PERF].max_connection_latency
	    << "," << results[WHOLE_TEST_PERF].total_errors
	    << "," << results[WHOLE_TEST_PERF].raw.read_errors
	    << "," << results[WHOLE_TEST_PERF].raw.write_errors
	    << "," << results[WHOLE_TEST_PERF].raw.bytes_read
	    << "," << results[WHOLE_TEST_PERF].raw.bytes_written
	    << "," << results[WHOLE_TEST_PERF].raw.read_count
	    << "," << results[WHOLE_TEST_PERF].raw.write_count
	    << "," << results[WHOLE_TEST_PERF].raw.connection_count << ",";

	if (GetConnectionRate(ActiveType) == ENABLED_VALUE)
		(*file) << GetTransPerConn(ActiveType);
	else
		(*file) << AMBIGUOUS_VALUE;

	(*file) << ",,,,,,,,,";	// unused raw results for manager list

	(*file) << "," << GetDiskStart((TargetType) (GenericDiskType | ActiveType))
	    << "," << GetDiskSize((TargetType) (GenericDiskType | ActiveType))
	    << "," << GetQueueDepth(ActiveType);

	for (stat = 0; stat < CPU_UTILIZATION_RESULTS; stat++)
		(*file) << "," << results[WHOLE_TEST_PERF].CPU_utilization[stat];

	(*file) << ","		// processor speed
	    << "," << results[WHOLE_TEST_PERF].CPU_utilization[CPU_IRQ];

	(*file) << "," << results[WHOLE_TEST_PERF].CPU_effectiveness;

	for (stat = 0; stat < NI_COMBINE_RESULTS; stat++)
		(*file) << "," << results[WHOLE_TEST_PERF].ni_statistics[stat];

	for (stat = 0; stat < TCP_RESULTS; stat++)
		(*file) << "," << results[WHOLE_TEST_PERF].tcp_statistics[stat];

	(*file) << endl;

	// If requested, save manager results.
	if (result_type == RecordAll || result_type == RecordNoTargets || result_type == RecordNoWorkers) {
		for (int i = 0; i < ManagerCount(); i++)
			GetManager(i)->SaveResults(file, access_index, result_type);
	}
	// Write current timestamp into the result file
	(*file) << "'Time Stamp" << endl;
	_ftime(&tb);
	ptm = localtime(&tb.time);
	sprintf(acDummy, "%04d-%02d-%02d %02d:%02d:%02d:%003d", ptm->tm_year + 1900,
		ptm->tm_mon + 1, ptm->tm_mday, ptm->tm_hour, ptm->tm_min, ptm->tm_sec, tb.millitm);
	(*file) << acDummy << endl;
}
Beispiel #3
0
main()
{
    static char text[MAXSEARCH];  /* Pointer to buffer for search text  */
    static char date_time[19];    /* Receive file date and time         */
    int err, mode, handle, len;   /* Codes, file handle, bytes read     */
    int row, col, ch;             /* Cursor coordinates, kb character   */
    int i, j, attr;               /* Index variables, file attribute    */
    int disp_attr;                /* Display attribute                  */
    char *spec, *ptr, *buffer;    /* File spec, char match, read buffer */
    long dsize, disk_use;         /* Disk size and usage                */
    struct DISKSTAT disk;         /* Structure for disk size params     */

    static char copy_msg[] =
    {
        "Files can be copied or moved in 2 different modes:\n" \
        "      0  -  overwrite target file if it exists\n" \
        "      1  -  abort if target file exists\n\n" \
        "Mode 1 is supported only with DOS versions 3.0 or higher.\n"
    };
    static char move_msg[] =
    {
        "Quick Move uses DOS function 56h (Rename File) to effectively " \
        "move a file from\none directory to another directory on the " \
        "same drive.  It copies the entry\nfrom the source directory to " \
        "the target directory, but does not physically\ncopy the file.\n\n" \
        "Source and target specifications must be given in full, " \
        "including filenames,\neven if the names are the same."
    };
    static char grep_msg[] =
    {
        "The Find Text option uses the StrFindChar and StrCompare procedures " \
        "to locate\na text string within specified files, like Unix's " \
        "\"grep\" command.  Find Text\nis limited to case-sensitive searches " \
        "within the current directory.\n\nEnter the desired search string " \
        "without quotation marks.  When specifying the\nfilename, use " \
        "wildcard characters to expand the search to a group of files --\n" \
        "for example, \"*.*\" searches all files within the current " \
        "directory, \"*.bat\"\nlimits the search to batch files, and so forth."
    };
    static char attr_msg[] =
    {
        "\t\t\t1    normal      \n" \
        "\t\t\t2    read-only   \n" \
        "\t\t\t3    hidden      \n" \
        "\t\t\t4    system      \n" \
        "\t\t\t     volume      \n" \
        "\t\t\t     subdirectory\n" \
        "\t\t\t5    archive     \n"
    };

    GetVidConfig();
    ReadCharAttr( &disp_attr );
    clear_scrn( disp_attr, 0, 24 );
    SetCurPos( 8, 0 );
    puts( "Welcome to the FILEDEMO program.\n\n\nThis program is meant " \
          "to encourage experimentation while demonstrating how to\naccess " \
          "DOS from assembly-language procedures.  As a safety precaution, " \
          "however,\nwe suggest you DO NOT experiment with files that " \
          "cannot easily be replaced." );
    press();

    do
    {
        /* Display current drive and directory */
        clear_scrn( disp_attr, 0, 24 );
        SetCurPos( 0, 0 );
        printf( "Current Directory:  %c:\\", (char)(GetCurDrive() + 'A') );
        GetCurDir( source );
        puts( source );

        /* Display DOS version */
        SetCurPos( 1, 0 );
        printf( "DOS Version:        %2.1f", ( (float) GetVer() ) / 100 );

        /* Display disk statistics for current drive */
        SetCurPos( 0, 58 );
        GetDiskSize( 0, &disk );
        dsize = (long)disk.bytes * disk.sects * disk.total;
        disk_use = (long)(disk.total - disk.avail) * disk.bytes * disk.sects;
        printf( "Disk Size: %6lu K", dsize / 1024 );
        SetCurPos( 1, 58 );
        printf( "Disk Use:  %6lu K", disk_use / 1024 );

        /* Display menu and poll for keystroke */
        clear_scrn( disp_attr, 2, 23 );
        SetCurPos( 5, 0 );
        puts( " \t               ***      FILE " \
              "Demonstration Program      ***" );
        SetCurPos( 7, 0 );
        puts( " \tA  List Directory       \t\tH  Get/Set File Attribute" );
        puts( " \tB  Copy File            \t\tI  Get File Date and Time" );
        puts( " \tC  Move File            \t\tJ  Rename File" );
        puts( " \tD  Make Subdirectory    \t\tK  Delete File" );
        puts( " \tE  Remove Subdirectory  \t\tL  Create Unique File" );
        puts( " \tF  Change Default Drive \t\tM  Quick Move" );
        puts( " \tG  Change Directory     \t\tN  Find Text" );
        printf( "\n\n\tSelect an option, or press ESC to quit: " );
        ch = getch();
        switch( (ch = toupper( ch )) )
        {
            /* List first 60 files in specified directory */
            case 'A':
                err  = list_dir( get_spec( 1 ), disp_attr );
                if( !err )
                    press();
                break;

            /* Copy or Move File according to requested mode:
             *          0 = overwrite target
             *          1 = abort if target exists
             * If Move requested, delete source file after copy.
             */
            case 'B':
            case 'C':
                clear_scrn( disp_attr, 2, 17 );
                SetCurPos( 9, 0 );
                puts( copy_msg );
                mode = -1;
                while( (mode < 0)  ||  (mode > 1) )
                {
                    SetCurPos( 16, 0 );
                    printf( "Enter copy mode:  " );
                    mode = (int)(getche() - '0');
                }
                spec = get_spec( 2 );                   /* Get source     */
                strcpy( source, spec );                 /* Save in buffer */
                spec = get_spec( 3 );                   /* Get target     */
                err  = CopyFile( mode, source, spec );
                if( (ch == 'C')  &&  !err )
                    err = DelFile( source );
                break;

            /* Make Directory */
            case 'D':
                err = MakeDir( get_spec( 1 ) );
                break;

            /* Remove Directory */
            case 'E':
                err = RemoveDir( get_spec( 1 ) );
                break;

            /* Change Default Drive */
            case 'F':
                SetCurPos( 18, 0 );
                printf( "Enter new drive letter:  " );
                ch = getch();
                ch = toupper( ch );
                ChangeDrive( ch );
                err = 0;
                break;

            /* Change Directory */
            case 'G':
                err = ChangeDir( get_spec( 1 ) );
                break;

            /* Get and Set File Attributes */
            case 'H':
                strcpy( source, get_spec( 3 ) );
                if( (err = GetAttribute( source )) != -1 )
                {
                    attr = err;
                    if( !attr )
                        attr_msg[6] = '*';
                    else
                        attr_msg[6] = ' ';
                    for( j = 1, i = 27; j <= 32; j <<= 1, i+= 21 )
                    {
                        attr_msg[i] = ' ';
                        if( attr & j )
                            attr_msg[i] = '*';
                    }
                    err = 0;
                    clear_scrn( disp_attr, 2, 17 );
                    SetCurPos( 7, 0 );
                    puts( attr_msg );
                    printf( "\n\nToggle attribute bits by selecting 1-5, " \
                            "or any other key to exit:  " );
                    mode = (int)( getch() - '0' );
                    if( (mode > 0)  &&  (mode < 6) )
                    {
                        switch( --mode )
                        {
                            case 0:
                                attr = 0;
                                break;

                            case 1:
                            case 2:
                            case 3:
                                attr = attr ^ (1 << (--mode) );
                                break;

                            case 4:
                                attr = attr ^ 32;
                        }
                        err = SetAttribute( attr, source );
                    }
                }
                break;

            /* Get File Date and Time */
            case 'I':
                if( (handle = OpenFile( 0, get_spec( 3 ) )) == -1 )
                    err = 1;
                else
                    err = 0;
                if( !err )
                {
                    if( !(err = GetFileTime( handle, date_time )) )
                    {
                        clear_scrn( disp_attr, 2, 17 );
                        SetCurPos( 12, 10 );
                        printf( "File's date and time stamp:  %s", date_time );
                        CloseFile( handle );
                        press();
                    }
                }
                break;

            /* Rename File */
            case 'J':
                strcpy( source, get_spec( 2 ) );
                err = RenameFile( source, get_spec( 3 ) );
                break;

            /* Delete File */
            case 'K':
                err = DelFile( get_spec( 3 ) );
                break;

            /* Create File with Unique Name */
            case 'L':
                strcpy( source, get_spec( 1 ) );
                handle = UniqueFile( 0, source );   /* Normal file attr = 0 */
                if( handle >= 0 )
                {
                    printf( "\n\nDOS creates file %s", source );
                    press();
                    err = 0;
                }
                else err = 1;
                break;

            /* Quick Move from one directory to another */
            case 'M':
                clear_scrn( disp_attr, 2, 17 );
                SetCurPos( 8, 0 );
                puts( move_msg );
                strcpy( source, get_spec( 2 ) );
                err = RenameFile( source, get_spec( 3 ) );
                break;

            /* Search files for specified text */
            case 'N':
                clear_scrn( disp_attr, 2, 17 );
                buffer = (char *) malloc( BUFFSIZE + 1 );
                if( buffer == NULL )
                {
                    SetCurPos( 12, 26 );
                    puts( "Insufficient memory for option" );
                    err = 1;
                    break;
                }
                SetCurPos( 7, 0 );
                puts( grep_msg );
                SetCurPos( 18, 0 );
                printf( "Enter search text:  " );
                GetStr( text, MAXSEARCH );

                /* Find first data file. */
                if( err = FindFirst( 0, get_spec( 3 ), &file ) )
                {
                    clear_scrn( disp_attr, 2, 17 );
                    SetCurPos( 12, 24 );
                    puts( "No files found matching specification" );
                }

                /* If file found, initialize screen coordinates and
                 * open file for reading.
                 */
                else
                {
                    clear_scrn( disp_attr, 2, 17 );
                    row = 6;
                    col = 0;
                    do
                    {
                        if( (handle = OpenFile( 0, file.filename )) != -1 )
                        {

                            /* If file opened successfully, read a block
                             * of BUFFSIZE bytes. If end-of-file encountered
                             * (number of bytes read not equal to BUFFSIZE)
                             * or read error, set error flag to break loop.
                             * Terminate block with a NULL character to 
                             * make it an ASCIIZ string.
                             */
                            err = 0;
                            while( !err )
                            {
                                len = ReadFile( handle, BUFFSIZE, buffer );
                                if( (len == 0)  ||  (len != BUFFSIZE) )
                                    ++err;
                                ptr = buffer;
                                *( ptr + len ) = 0;

                                /* Search block for first character in text */
                                while( spec = StrFindChar( text[0], ptr, 0 ) )
                                {

                                    /* If initial character found, compare
                                     * remaining characters in search text.
                                     * If all characters match, display file
                                     * name and break out of loop.
                                     */
                                    ptr = StrCompare( ++spec, &text[1],
                                          (strlen( text ) - 1) );
                                    if( !ptr )
                                    {
                                        SetCurPos( row++, col );
                                        puts( file.filename );
                                        if( row == 16)
                                        {
                                            row  = 6;
                                            col += 20;
                                        }
                                        err  = 1;
                                        break;
                                    }
                                }
                            }
                            CloseFile( handle );
                        }
                        else
                        {
                            err = 1;
                            break;
                        }
                    } while( !FindNext( &file ) );

                    if( (row == 6)  &&  (col == 0) )
                    {
                        SetCurPos( 12, 22 );
                        puts( "Text not found in specified file(s)" );
                    }
                    press();
                    err = 0;
                }
                free( buffer );             /* Free allocated block */
                break;

            default:
                continue;
        }

        if( err )
        {
            clear_scrn( disp_attr, 24, 24 );
            SetCurPos( 24, 0 );
            printf( "***  Error  ***\a" );
            press();
        }

    } while( ch != ESCAPE );            /* Exit if ESC key pressed    */

    clear_scrn( disp_attr, 0, 24 );     /* Clear screen before exit   */
    SetCurPos( 23, 0 );                 /*   and set cursor to bottom */
    return( 0 );
}