Changeset 217 in xtideuniversalbios for trunk/Serial_Server/library/Image.cpp


Ignore:
Timestamp:
Jan 23, 2012, 10:08:13 AM (12 years ago)
Author:
gregli@…
google:author:
gregli@hotmail.com
Message:

Serial Server: various improvements, turned on LBA28 support by default.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Serial_Server/library/Image.cpp

    r211 r217  
    1313Image::Image( char *name, int p_readOnly, int p_drive )
    1414{
    15     init( name, p_readOnly, p_drive );
    1615}
    1716
    1817Image::Image( char *name, int p_readOnly, int p_drive, int p_create, unsigned long p_lba )
    1918{
    20     init( name, p_readOnly, p_drive );
    21 }
    22 
    23 Image::Image( char *name, int p_readOnly, int p_drive, int p_create, unsigned long p_cyl, unsigned long p_sect, unsigned long p_head )
    24 {
    25     init( name, p_readOnly, p_drive );
    26 }
    27 
    28 void Image::init( char *name, int p_readOnly, int p_drive )
    29 {
     19}
     20
     21Image::Image( char *name, int p_readOnly, int p_drive, int p_create, unsigned long p_cyl, unsigned long p_head, unsigned long p_sect, int p_useCHS )
     22{
     23}
     24
     25void Image::init( char *name, int p_readOnly, int p_drive, unsigned long p_cyl, unsigned long p_head, unsigned long p_sect, int p_useCHS )
     26{
     27    double sizef;
     28
    3029    for( char *c = shortFileName = name; *c; c++ )
    3130        if( *c == '\\' || *c == '/' || *c == ':' )
     
    4039    readOnly = p_readOnly;
    4140    drive = p_drive;
    42 }
    43 
    44 int Image::parseGeometry( char *str, unsigned long *p_cyl, unsigned long *p_sect, unsigned long *p_head )
     41
     42    if( totallba > 0xfffffff )     // lba28 limit - 28 bits
     43        log( -1, "'%s', Image size larger than LBA28 maximum of 137,438,952,960 bytes, %lu", name, totallba );
     44
     45    if( totallba == 0 )
     46        log( -1, "'%s', Image size zero?" );
     47
     48    if( p_useCHS )
     49    {
     50        if( p_cyl )
     51        {
     52            if( p_sect > 63 || (p_head > 16 || p_head < 1) || (p_cyl > 1024 || p_cyl < 1) )
     53                log( -1, "'%s', parts of the CHS geometry (%lu:%lu:%lu) are out of the range (1-1024:1-16:1-63)", name, p_cyl, p_head, p_sect );
     54            else if( totallba != (p_sect * p_head * p_cyl) )
     55                log( -1, "'%s', file size does not match geometry", name );
     56            sect = p_sect;
     57            head = p_head;
     58            cyl = p_cyl;
     59        }
     60        else
     61        {
     62            if( (totallba % 16) != 0 || ((totallba/16) % 63) != 0 )
     63                log( -1, "'%s', file size does not match standard CHS geometry (x:16:63), please specify geometry explicitly with -g", name );
     64            else
     65            {
     66                sect = 63;
     67                head = 16;
     68                cyl = (totallba / sect / head);
     69                if( cyl > 1024 )
     70                    log( -1, "'%s', CHS geometry of %lu:%lu:%lu is larger than maximum values 1024:16:63", name, cyl, head, sect );
     71            }
     72        }
     73    }
     74    else
     75    {
     76        sect = 0;
     77        head = 0;
     78        cyl = 0;
     79    }
     80    useCHS = p_useCHS;
     81
     82    sizef = totallba/2048.0;
     83    if( useCHS )
     84        log( 0, "Opening '%s', CHS geometry %u:%u:%u, total size %.1lf MB", name, cyl, sect, head, sizef );
     85    else
     86        log( 0, "Opening '%s', total lba %lu, total size %.1lf MB", name, totallba, sizef );
     87}
     88
     89int Image::parseGeometry( char *str, unsigned long *p_cyl, unsigned long *p_head, unsigned long *p_sect )
    4590{
    4691    char *c, *s, *h;
     
    4893
    4994    c = str;
    50     for( s = c; *s && *s != ':' && *s != 'x' && *s != 'X'; s++ ) ;
     95    for( h = c; *h && *h != ':' && *h != 'x' && *h != 'X'; h++ ) ;
     96    if( !*h )
     97        return( 0 );
     98
     99    *h = '\0';
     100    h++;
     101    for( s = h+1; *s && *s != ':' && *s != 'x' && *s != 'X'; s++ ) ;
    51102    if( !*s )
    52103        return( 0 );
     
    54105    *s = '\0';
    55106    s++;
    56     for( h = s+1; *h && *h != ':' && *h != 'x' && *h != 'X'; h++ ) ;
    57     if( !*h )
    58         return( 0 );
    59 
    60     *h = '\0';
    61     h++;
    62107
    63108    cyl = atol(c);
     109    head = atol(h);
    64110    sect = atol(s);
    65     head = atol(h);
    66111
    67112    if( cyl == 0 || sect == 0 || head == 0 )
     
    69114
    70115    *p_cyl = cyl;
     116    *p_head = head;
    71117    *p_sect = sect;
    72     *p_head = head;
    73118
    74119    return( 1 );
     
    145190        buff[t] = (buff[t] >> 8) | (buff[t] << 8);
    146191
    147 #if 1
    148     buff[ ATA_wCylCnt ] = cyl;
    149     buff[ ATA_wHeadCnt ] = head;
    150     buff[ ATA_wSPT ] = sect;
    151 #endif
     192    if( useCHS )
     193    {
     194        buff[ ATA_wCylCnt ] = cyl;
     195        buff[ ATA_wHeadCnt ] = head;
     196        buff[ ATA_wSPT ] = sect;
     197    }
     198    else
     199    {
     200        buff[ ATA_wCaps ] = ATA_wCaps_LBA;
     201        buff[ ATA_dwLBACnt ] = (unsigned short) (totallba & 0xffff);
     202        buff[ ATA_dwLBACnt+1 ] = (unsigned short) (totallba >> 16);
     203    }
     204
    152205    buff[ ATA_wGenCfg ] = ATA_wGenCfg_FIXED;
    153206    //                  buff[ ATA_VendorSpecific_ReturnPortBaud ] = retWord;
    154 #if 0
    155     buff[ ATA_wCaps ] = ATA_wCaps_LBA;
    156  
    157     buff[ ATA_dwLBACnt ] = (unsigned short) (totallba & 0xffff);
    158     buff[ ATA_dwLBACnt+1 ] = (unsigned short) (totallba >> 16);
    159 #endif
    160 }
     207}
Note: See TracChangeset for help on using the changeset viewer.