|
[x]
Posted via EE Mobile
|
||
Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again. |
||
| Question |
|
[x]
Attachment Details
|
||
|
[x]
The Solution Rating System
|
||
With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.
Your Input Matters If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support. Thank you! |
||
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: |
int decomp_ciso(void)
{
unsigned long long file_size;
unsigned int index , index2;
unsigned long long read_pos , read_size;
int total_sectors;
int index_size;
int block;
unsigned char buf4[4];
int cmp_size;
int status;
int percent_period;
int percent_cnt;
int plain;
// read header
if( fread(&ciso, 1, sizeof(ciso), fin) != sizeof(ciso) )
{
printf("file read error\n");
return 1;
}
// check header
if(
ciso.magic[0] != 'C' ||
ciso.magic[1] != 'I' ||
ciso.magic[2] != 'S' ||
ciso.magic[3] != 'O' ||
ciso.block_size ==0 ||
ciso.total_bytes == 0
)
{
printf("ciso file format error\n");
return 1;
}
//
ciso_total_block = ciso.total_bytes / ciso.block_size;
// allocate index block
index_size = (ciso_total_block + 1 ) * sizeof(unsigned long);
index_buf = malloc(index_size);
block_buf1 = malloc(ciso.block_size);
block_buf2 = malloc(ciso.block_size*2);
if( !index_buf || !block_buf1 || !block_buf2 )
{
printf("Can't allocate memory\n");
return 1;
}
memset(index_buf,0,index_size);
// read index block
if( fread(index_buf, 1, index_size, fin) != index_size )
{
printf("file read error\n");
return 1;
}
// show info
printf("Decompress '%s' to '%s'\n",fname_in,fname_out);
printf("Total File Size %ld bytes\n",ciso.total_bytes);
printf("block size %d bytes\n",ciso.block_size);
printf("total blocks %d blocks\n",ciso_total_block);
printf("index align %d\n",1<<ciso.align);
// init zlib
z.zalloc = Z_NULL;
z.zfree = Z_NULL;
z.opaque = Z_NULL;
// decompress data
percent_period = ciso_total_block/100;
percent_cnt = 0;
for(block = 0;block < ciso_total_block ; block++)
{
if(--percent_cnt<=0)
{
percent_cnt = percent_period;
printf("decompress %d%%\r",block / percent_period);
}
if (inflateInit2(&z,-15) != Z_OK)
{
printf("deflateInit : %s\n", (z.msg) ? z.msg : "???");
return 1;
}
// check index
index = index_buf[block];
plain = index & 0x80000000;
index &= 0x7fffffff;
read_pos = index << (ciso.align);
if(plain)
{
read_size = ciso.block_size;
}
else
{
index2 = index_buf[block+1] & 0x7fffffff;
read_size = (index2-index) << (ciso.align);
}
fseek(fin,read_pos,SEEK_SET);
z.avail_in = fread(block_buf2, 1, read_size , fin);
if(z.avail_in != read_size)
{
printf("block=%d : read error\n",block);
return 1;
}
if(plain)
{
memcpy(block_buf1,block_buf2,read_size);
cmp_size = read_size;
}
else
{
z.next_out = block_buf1;
z.avail_out = ciso.block_size;
z.next_in = block_buf2;
status = inflate(&z, Z_FULL_FLUSH);
if (status != Z_STREAM_END)
//if (status != Z_OK)
{
printf("block %d:inflate : %s[%d]\n", block,(z.msg) ? z.msg : "error",status);
return 1;
}
cmp_size = ciso.block_size - z.avail_out;
if(cmp_size != ciso.block_size)
{
printf("block %d : block size error %d != %d\n",block,cmp_size , ciso.block_size);
return 1;
}
}
// write decompressed block
if(fwrite(block_buf1, 1,cmp_size , fout) != cmp_size)
{
printf("block %d : Write error\n",block);
return 1;
}
// term zlib
if (inflateEnd(&z) != Z_OK)
{
printf("inflateEnd : %s\n", (z.msg) ? z.msg : "error");
return 1;
}
}
printf("ciso decompress completed\n");
return 0;
}
|
Advertisement
| Hall of Fame |