- Timestamp:
- Jan 23, 2012, 10:08:13 AM (13 years ago)
- google:author:
- gregli@hotmail.com
- Location:
- trunk/Serial_Server
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Serial_Server/library/FlatImage.cpp
r213 r217 12 12 #include "FlatImage.h" 13 13 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)14 FlatImage::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 ) 15 15 { 16 double sizef;16 long filesize; 17 17 18 18 if( p_create ) … … 40 40 41 41 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 ); 43 46 } 44 47 … … 48 51 49 52 fseek( fp, 0, SEEK_END ); 50 totallba= ftell( fp );53 filesize = ftell( fp ); 51 54 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 ); 54 57 55 if( totallba& 0x1ff )58 if( filesize & 0x1ff ) 56 59 log( -1, "'%s' not made up of 512 byte sectors", name ); 57 60 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 78 62 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 ); 81 64 } 82 65 -
trunk/Serial_Server/library/FlatImage.h
r209 r217 15 15 16 16 public: 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 ); 18 18 ~FlatImage(); 19 19 -
trunk/Serial_Server/library/Image.cpp
r211 r217 13 13 Image::Image( char *name, int p_readOnly, int p_drive ) 14 14 { 15 init( name, p_readOnly, p_drive );16 15 } 17 16 18 17 Image::Image( char *name, int p_readOnly, int p_drive, int p_create, unsigned long p_lba ) 19 18 { 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 21 Image::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 25 void 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 30 29 for( char *c = shortFileName = name; *c; c++ ) 31 30 if( *c == '\\' || *c == '/' || *c == ':' ) … … 40 39 readOnly = p_readOnly; 41 40 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 89 int Image::parseGeometry( char *str, unsigned long *p_cyl, unsigned long *p_head, unsigned long *p_sect ) 45 90 { 46 91 char *c, *s, *h; … … 48 93 49 94 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++ ) ; 51 102 if( !*s ) 52 103 return( 0 ); … … 54 105 *s = '\0'; 55 106 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++;62 107 63 108 cyl = atol(c); 109 head = atol(h); 64 110 sect = atol(s); 65 head = atol(h);66 111 67 112 if( cyl == 0 || sect == 0 || head == 0 ) … … 69 114 70 115 *p_cyl = cyl; 116 *p_head = head; 71 117 *p_sect = sect; 72 *p_head = head;73 118 74 119 return( 1 ); … … 145 190 buff[t] = (buff[t] >> 8) | (buff[t] << 8); 146 191 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 152 205 buff[ ATA_wGenCfg ] = ATA_wGenCfg_FIXED; 153 206 // 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 29 29 Image( char *name, int p_readOnly, int p_drive ); 30 30 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 ); 32 32 33 33 virtual ~Image() {}; 34 34 35 35 unsigned long cyl, sect, head; 36 int useCHS; 36 37 37 38 unsigned long totallba; … … 41 42 int drive; 42 43 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 ); 44 45 45 46 void respondInquire( unsigned short *buff, struct baudRate *baudRate, unsigned char portAndBaud ); 46 47 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 ); 49 49 }; 50 50 -
trunk/Serial_Server/library/Process.cpp
r215 r217 252 252 workCommand = buff.chs.command & SERIAL_COMMAND_RWMASK; 253 253 254 if( (workCommand != SERIAL_COMMAND_INQUIRE) && (buff.chs. command & ATA_COMMAND_LBA) )254 if( (workCommand != SERIAL_COMMAND_INQUIRE) && (buff.chs.driveAndHead & ATA_COMMAND_LBA) ) 255 255 { 256 256 mylba = ((((unsigned long) buff.lba.bits24) & ATA_COMMAND_HEADMASK) << 24) … … 279 279 + SERIAL_INQUIRE_PORTANDBAUD_STARTINGPORT, 280 280 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 ) 282 282 log( 1, "%s %d: LBA=%u, Count=%u", comStr, img == image0 ? 0 : 1, 283 283 mylba, workCount ); -
trunk/Serial_Server/win32/Win32.cpp
r215 r217 26 26 "usage: SerDrive [options] imagefile [[slave-options] slave-imagefile]", 27 27 "", 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", 49 51 "", 50 52 "On the client computer, a serial port can be configured for use as a hard disk", … … 83 85 84 86 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; 86 89 87 90 int imagecount = 0; … … 122 125 break; 123 126 case 'g': case 'G': 124 if( !Image::parseGeometry( argv[++t], &cyl, §, &head ) ) 125 usage(); 126 explicitGeometry = 1; 127 if( atol(argv[t+1]) != 0 ) 128 { 129 if( !Image::parseGeometry( argv[++t], &cyl, &head, § ) ) 130 usage(); 131 } 132 useCHS = 1; 127 133 break; 128 134 case 'h': case 'H': case '?': … … 137 143 head = 16; 138 144 cyl = (size*1024*2) / (16*63); 139 explicitGeometry = 1;140 145 } 141 146 break; … … 157 162 else if( imagecount < 2 ) 158 163 { 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 ); 160 165 imagecount++; 161 createFile = readOnly = cyl = sect = head = 0;166 createFile = readOnly = cyl = sect = head = useCHS = 0; 162 167 } 163 168 else
Note:
See TracChangeset
for help on using the changeset viewer.