Changeset 217 in xtideuniversalbios for trunk/Serial_Server


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.

Location:
trunk/Serial_Server
Files:
6 edited

Legend:

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

    r213 r217  
    1212#include "FlatImage.h"
    1313
    14 FlatImage::FlatImage( char *name, int p_readOnly, int p_drive, int p_create, unsigned long p_cyl, unsigned long p_sect, unsigned long p_head )   :   Image( name, p_readOnly, p_drive, p_create, p_cyl, p_sect, p_head )
     14FlatImage::FlatImage( 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 )   :   Image( name, p_readOnly, p_drive, p_create, p_cyl, p_head, p_sect, p_useCHS )
    1515{
    16     double sizef;
     16    long filesize;
    1717
    1818    if( p_create )
     
    4040       
    4141        sizef = size2/2048.0;
    42         log( 0, "Created file '%s' with geometry %u:%u:%u, size %.1lf megabytes\n", name, p_cyl, p_sect, p_head, sizef );
     42        if( p_cyl > 1024 )
     43            log( 0, "Created file '%s', size %.1lf MB", name, sizef );
     44        else
     45            log( 0, "Created file '%s', geometry %u:%u:%u, size %.1lf MB", name, p_cyl, p_sect, p_head, sizef );
    4346    }
    4447
     
    4851
    4952    fseek( fp, 0, SEEK_END );
    50     totallba = ftell( fp );
     53    filesize = ftell( fp );
    5154
    52     if( !totallba )
    53         log( -1, "Could not get file size for '%s'", name );
     55    if( filesize == 0 || filesize == -1L )
     56        log( -1, "Could not get file size for '%s', file possibly larger than 2 GB", name );
    5457
    55     if( totallba & 0x1ff )
     58    if( filesize & 0x1ff )
    5659        log( -1, "'%s' not made up of 512 byte sectors", name );
    5760
    58     totallba >>= 9;
    59     if( totallba != (p_sect * p_head * p_cyl) )
    60     {
    61         if( p_sect || p_head || p_cyl )
    62             log( -1, "'%s', file size does not match geometry", name );
    63         else if( (totallba % 16) != 0 || ((totallba/16) % 63) != 0 )
    64             log( -1, "'%s', file size does not match standard geometry (x:16:63), please geometry explicitly with -g", name );
    65         else
    66         {
    67             sect = 63;
    68             head = 16;
    69             cyl = (totallba / sect / head);
    70         }
    71     }
    72     else
    73     {
    74         sect = p_sect;
    75         head = p_head;
    76         cyl = p_cyl;
    77     }
     61    totallba = filesize >> 9;     // 512 bytes per sector
    7862
    79     sizef = totallba/2048.0;
    80     log( 0, "Opening disk '%s', geometry %u:%u:%u, total size %.1lf MB", name, cyl, sect, head, sizef );
     63    init( name, p_readOnly, p_drive, p_cyl, p_head, p_sect, p_useCHS );
    8164}
    8265
  • trunk/Serial_Server/library/FlatImage.h

    r209 r217  
    1515
    1616public:
    17     FlatImage( char *name, int p_readOnly, int p_drive, int create, unsigned long cyl, unsigned long sect, unsigned long head );
     17    FlatImage( char *name, int p_readOnly, int p_drive, int create, unsigned long cyl, unsigned long head, unsigned long sect, int useCHS );
    1818    ~FlatImage();
    1919
  • 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}
  • trunk/Serial_Server/library/Library.h

    r215 r217  
    2929    Image( char *name, int p_readOnly, int p_drive );
    3030    Image( char *name, int p_readOnly, int p_drive, int p_create, unsigned long p_lba );
    31     Image( char *name, int p_readOnly, int p_drive, int p_create, unsigned long p_cyl, unsigned long p_sect, unsigned long p_head );
     31    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 );
    3232
    3333    virtual ~Image() {};
    3434
    3535    unsigned long cyl, sect, head;
     36    int useCHS;
    3637
    3738    unsigned long totallba;
     
    4142    int drive;
    4243
    43     static int parseGeometry( char *str, unsigned long *p_cyl, unsigned long *p_sect, unsigned long *p_head );
     44    static int parseGeometry( char *str, unsigned long *p_cyl, unsigned long *p_head, unsigned long *p_sect );
    4445
    4546    void respondInquire( unsigned short *buff, struct baudRate *baudRate, unsigned char portAndBaud );
    4647
    47 private:
    48     void init( char *name, int p_readOnly, int p_drive );
     48    void init( char *name, int p_readOnly, int p_drive, unsigned long p_cyl, unsigned long p_head, unsigned long p_sect, int p_useCHS );
    4949};
    5050
  • trunk/Serial_Server/library/Process.cpp

    r215 r217  
    252252                workCommand = buff.chs.command & SERIAL_COMMAND_RWMASK;
    253253
    254                 if( (workCommand != SERIAL_COMMAND_INQUIRE) && (buff.chs.command & ATA_COMMAND_LBA) )
     254                if( (workCommand != SERIAL_COMMAND_INQUIRE) && (buff.chs.driveAndHead & ATA_COMMAND_LBA) )
    255255                {
    256256                    mylba = ((((unsigned long) buff.lba.bits24) & ATA_COMMAND_HEADMASK) << 24)
     
    279279                             + SERIAL_INQUIRE_PORTANDBAUD_STARTINGPORT,
    280280                             baudRateMatchDivisor( buff.inquire.portAndBaud & SERIAL_INQUIRE_PORTANDBAUD_BAUDMASK )->display );
    281                     else if( buff.chs.command & ATA_COMMAND_LBA )
     281                    else if( buff.chs.driveAndHead & ATA_COMMAND_LBA )
    282282                        log( 1, "%s %d: LBA=%u, Count=%u", comStr, img == image0 ? 0 : 1,
    283283                             mylba, workCount );
  • trunk/Serial_Server/win32/Win32.cpp

    r215 r217  
    2626        "usage: SerDrive [options] imagefile [[slave-options] slave-imagefile]",
    2727        "",
    28         "  -g cyl:sect:head  Geometry in cylinders, sectors per cylinder, and heads",
    29         "                    (default is 65:63:16 for a 32 MB disk)",
    30         "",
    31         "  -n [megabytes]    Create new disk with given size or use -g geometry",
    32         "",
    33         "  -p                Named Pipe mode for emulators (pipe is '" PIPENAME "')",
    34         "",
    35         "  -c COMPortNumber  COM Port to use (default is first found)",
    36         "",
    37         "  -b BaudRate       Baud rate to use on the COM port ",
    38         "                    Without a rate multiplier: 2400, 9600, 38400, 115200",
    39         "                    With a 2x rate multiplier: 4800, 19200, 76800, 230400",
    40         "                    With a 4x rate multiplier: 9600, 38400, 153600, 460800",
    41         "                    Abbreviations also accepted (ie, '460K', '38.4K', etc)",
    42         "                    (default is 38400, 115200 in named pipe mode)",
    43         "",
    44         "  -t                Disable timeout, useful for long delays when debugging",
    45         "",
    46         "  -r                Read Only disk, do not allow writes",
    47         "",
    48         "  -v [level]        Reporting level 1-6, with increasing information",
     28        "  -g [cyl:head:sect]  Geometry in cylinders, sectors per cylinder, and heads",
     29        "                      -g without parameters uses CHS mode (default is LBA28)",
     30        "",
     31        "  -n [megabytes]      Create new disk with given size or use -g geometry",
     32        "                      Maximum size is 137.4 GB (LBA28 limit)",
     33        "                      (default is a 32 MB disk, with CHS geometry 65:63:16)",
     34        "",
     35        "  -p                  Named Pipe mode for emulators (pipe is '" PIPENAME "')",
     36        "",
     37        "  -c COMPortNumber    COM Port to use (default is first found)",
     38        "",
     39        "  -b BaudRate         Baud rate to use on the COM port ",
     40        "                      Without a rate multiplier: 2400, 9600, 38400, 115200",
     41        "                      With a 2x rate multiplier: 4800, 19200, 76800, 230400",
     42        "                      With a 4x rate multiplier: 9600, 38400, 153600, 460800",
     43        "                      Abbreviations also accepted (ie, '460K', '38.4K', etc)",
     44        "                      (default is 38400, 115200 in named pipe mode)",
     45        "",
     46        "  -t                  Disable timeout, useful for long delays when debugging",
     47        "",
     48        "  -r                  Read Only disk, do not allow writes",
     49        "",
     50        "  -v [level]          Reporting level 1-6, with increasing information",
    4951        "",
    5052        "On the client computer, a serial port can be configured for use as a hard disk",
     
    8385
    8486    unsigned long cyl = 0, sect = 0, head = 0;
    85     int readOnly = 0, createFile = 0, explicitGeometry = 0;
     87    int readOnly = 0, createFile = 0;
     88    int useCHS = 0;
    8689
    8790    int imagecount = 0;
     
    122125                break;           
    123126            case 'g': case 'G':
    124                 if( !Image::parseGeometry( argv[++t], &cyl, &sect, &head ) )
    125                     usage();
    126                 explicitGeometry = 1;
     127                if( atol(argv[t+1]) != 0 )
     128                {
     129                    if( !Image::parseGeometry( argv[++t], &cyl, &head, &sect ) )
     130                        usage();
     131                }
     132                useCHS = 1;
    127133                break;
    128134            case 'h': case 'H': case '?':
     
    137143                    head = 16;
    138144                    cyl = (size*1024*2) / (16*63);
    139                     explicitGeometry = 1;
    140145                }
    141146                break;
     
    157162        else if( imagecount < 2 )
    158163        {
    159             images[imagecount] = new FlatImage( argv[t], readOnly, imagecount, createFile, cyl, sect, head );
     164            images[imagecount] = new FlatImage( argv[t], readOnly, imagecount, createFile, cyl, head, sect, useCHS );
    160165            imagecount++;
    161             createFile = readOnly = cyl = sect = head = 0;
     166            createFile = readOnly = cyl = sect = head = useCHS = 0;
    162167        }
    163168        else
Note: See TracChangeset for help on using the changeset viewer.