Changeset 217 in xtideuniversalbios for trunk/Serial_Server/library/Image.cpp
- Timestamp:
- Jan 23, 2012, 10:08:13 AM (13 years ago)
- google:author:
- gregli@hotmail.com
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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 }
Note:
See TracChangeset
for help on using the changeset viewer.