Changeset 225 in xtideuniversalbios for trunk/Serial_Server


Ignore:
Timestamp:
Jan 27, 2012, 6:19:21 PM (12 years ago)
Author:
gregli@…
google:author:
gregli@hotmail.com
Message:

Serial Server, minor improvements to file handling.

Location:
trunk/Serial_Server
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/Serial_Server/library/File.h

    r219 r225  
    1818{
    1919public:
    20     void Create( char *p_name )
     20    int Create( char *p_name )
    2121    {
    2222        fp = fopen( p_name, "r" );
    2323
    2424        if( fp )
    25             log( -1, "Create Failure: '%s' already exists", p_name );
     25        {
     26            log( 0, "'%s' file already exists", p_name );
     27            fclose( fp );
     28            return( 0 );
     29        }
    2630       
    2731        if( !(fp = fopen( p_name, "w" )) )
     
    2933
    3034        name = p_name;
     35       
     36        return( 1 );
    3137    }
    3238
  • trunk/Serial_Server/library/FlatImage.h

    r219 r225  
    3030            sizef = size / 2048.0;   // 512 byte sectors -> MB
    3131
    32             cf.Create( name );
    33 
    34             memset( &buff[0], 0, 512 );
    35             while( size-- )
    36                 cf.Write( &buff[0], 512 );
    37        
    38             if( p_cyl > 1024 )
    39                 log( 0, "Created file '%s', size %.1lf MB", name, sizef );
    40             else
    41                 log( 0, "Created file '%s', geometry %u:%u:%u, size %.1lf MB", name, p_cyl, p_sect, p_head, sizef );
    42 
    43             cf.Close();
     32            if( cf.Create( name ) )
     33            {
     34                memset( &buff[0], 0, 512 );
     35                while( size-- )
     36                    cf.Write( &buff[0], 512 );
     37               
     38                if( p_cyl > 1024 )
     39                    log( 0, "Created file '%s', size %.1lf MB", name, sizef );
     40                else
     41                    log( 0, "Created file '%s', geometry %u:%u:%u, size %.1lf MB", name, p_cyl, p_sect, p_head, sizef );
     42                cf.Close();
     43            }
    4444        }
    4545
  • trunk/Serial_Server/win32/Win32.cpp

    r219 r225  
    2626        "",
    2727        "  -g [cyl:head:sect]  Geometry in cylinders, sectors per cylinder, and heads",
    28         "                      -g without parameters uses CHS mode (default is LBA28)",
     28        "                      -g also implies CHS addressing mode (default is LBA28)",
    2929        "",
    3030        "  -n [megabytes]      Create new disk with given size or use -g geometry",
     
    161161        else if( imagecount < 2 )
    162162        {
     163            if( createFile && cyl == 0 )
     164            {
     165                cyl = 65;
     166                sect = 63;
     167                head = 16;
     168            }
    163169            images[imagecount] = new FlatImage( argv[t], readOnly, imagecount, createFile, cyl, head, sect, useCHS );
    164170            imagecount++;
  • trunk/Serial_Server/win32/Win32File.h

    r219 r225  
    1818{
    1919public:
    20     void Create( char *p_name )
     20    int Create( char *p_name )
    2121    {
    2222        fp = CreateFileA( p_name, GENERIC_WRITE, 0, 0, CREATE_NEW, FILE_ATTRIBUTE_NORMAL, 0 );
    23         if( !fp )
    24             log( -1, "'%s', could not create file", p_name );
     23
     24        if( fp == INVALID_HANDLE_VALUE )
     25        {
     26            if( GetLastError() == ERROR_FILE_EXISTS )
     27            {
     28                log( 0, "'%s', file already exists", p_name );
     29                return( 0 );
     30            }
     31            else
     32                log( -1, "'%s', could not create file", p_name );
     33        }
     34
    2535        name = p_name;
     36
     37        return( 1 );
    2638    }
    2739
     
    2941    {
    3042        fp = CreateFileA( p_name, GENERIC_READ|GENERIC_WRITE, 0, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0 );
    31         if( !fp )
     43
     44        if( fp == INVALID_HANDLE_VALUE )
    3245            log( -1, "'%s', could not open file", p_name );
     46
    3347        name = p_name;
    3448    }
     
    7892
    7993        if( !ReadFile( fp, buff, len, &out_len, NULL ) || len != out_len )
    80             log( -1, "'%s', ReadFile failed" );
     94            log( -1, "'%s', ReadFile failed", name );
    8195    }
    8296
     
    86100
    87101        if( !WriteFile( fp, buff, len, &out_len, NULL ) || len != out_len )
    88             log( -1, "'%s', WriteFile failed" );
     102            log( -1, "'%s', WriteFile failed", name );
    89103    }
    90104
  • trunk/Serial_Server/win32/Win32Serial.h

    r219 r225  
    4040       
    4141            pipe = CreateNamedPipeA( PIPENAME, PIPE_ACCESS_DUPLEX, PIPE_TYPE_BYTE|PIPE_REJECT_REMOTE_CLIENTS, 2, 1024, 1024, 0, NULL );
    42             if( !pipe )
     42            if( pipe == INVALID_HANDLE_VALUE )
    4343                log( -1, "Could not CreateNamedPipe " PIPENAME );
    4444       
     
    6262           
    6363                pipe = CreateFileA( name, GENERIC_READ|GENERIC_WRITE, 0, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0 );
    64                 if( !pipe )
     64                if( pipe == INVALID_HANDLE_VALUE )
    6565                    log( -1, "Could not Open \"%s\"", name );
    6666           
Note: See TracChangeset for help on using the changeset viewer.