Browse code

port chmunpack to fmap, fix some warnings

aCaB authored on 2009/08/25 22:10:21
Showing 3 changed files
... ...
@@ -33,18 +33,7 @@
33 33
 #endif
34 34
 #include <string.h>
35 35
 
36
-#if defined(HAVE_ATTRIB_PACKED) || defined(HAVE_PRAGMA_PACK) || defined(HAVE_PRAGMA_PACK_HPPA)
37
-#if HAVE_MMAP
38
-#if HAVE_SYS_MMAN_H
39
-#include <sys/mman.h>
40
-#else /* HAVE_SYS_MMAN_H */
41
-#undef HAVE_MMAP
42
-#endif /* HAVE_SYS_MMAN_H */
43
-#endif /* HAVE_MMAP */
44
-#else/* PACKED */
45
-#undef HAVE_MMAP
46
-#endif
47
-
36
+#include "fmap.h"
48 37
 #include "others.h"
49 38
 #include "mspack.h"
50 39
 #include "cltypes.h"
... ...
@@ -117,26 +106,12 @@ typedef struct lzx_content_tag {
117 117
 #define chm_endian_convert_64(x) le64_to_host(x)
118 118
 
119 119
 /* Read in a block of data from either the mmap area or the given fd */
120
-static int chm_read_data(int fd, char *dest, off_t offset, off_t len,
121
-			char *m_area, off_t m_length)
120
+static int chm_read_data(struct F_MAP *map, char *dest, off_t offset, off_t len)
122 121
 {
123
-	if ((offset < 0) || (len < 0) || ((offset+len) < 0)) {
124
-		return FALSE;
125
-	}
126
-	if (m_area != NULL) {
127
-		if ((offset+len) > m_length) {
128
-			return FALSE;
129
-		}
130
-		memcpy(dest, m_area+offset, len);
131
-	} else {
132
-		if (lseek(fd, offset, SEEK_SET) != offset) {
133
-			return FALSE;
134
-		}
135
-		if (cli_readn(fd, dest, len) != len) {
136
-			return FALSE;
137
-		}
138
-	}
139
-	return TRUE;
122
+    void *src = fmap_need_off_once(map, offset, len);
123
+    if(!src) return FALSE;
124
+    memcpy(dest, src, len);
125
+    return TRUE;
140 126
 }
141 127
 
142 128
 static uint64_t chm_copy_file_data(int ifd, int ofd, uint64_t len)
... ...
@@ -182,56 +157,11 @@ static void itsf_print_header(chm_itsf_header_t *itsf_hdr)
182 182
 	}
183 183
 }
184 184
 
185
-static int itsf_read_header(int fd, chm_itsf_header_t *itsf_hdr, char *m_area, off_t m_length)
185
+static int itsf_read_header(chm_metadata_t *metadata)
186 186
 {
187
-#if defined(HAVE_ATTRIB_PACKED) || defined(HAVE_PRAGMA_PACK) || defined(HAVE_PRAGMA_PACK_HPPA)
188
-	if (!chm_read_data(fd, (char *) itsf_hdr, 0, CHM_ITSF_MIN_LEN,
189
-				m_area,	m_length)) {
190
-		return FALSE;
191
-	}
192
-#else
193
-	if (cli_readn(fd, &itsf_hdr->signature, 4) != 4) {
194
-		return FALSE;
195
-	}
196
-	if (cli_readn(fd, &itsf_hdr->version, 4) != 4) {
187
+	chm_itsf_header_t *itsf_hdr = &metadata->itsf_hdr;
188
+	if (!chm_read_data(metadata->map, (char *)itsf_hdr, 0, CHM_ITSF_MIN_LEN))
197 189
 		return FALSE;
198
-	}
199
-	if (cli_readn(fd, &itsf_hdr->header_len, 4) != 4) {
200
-		return FALSE;
201
-	}
202
-	if (cli_readn(fd, &itsf_hdr->unknown, 4) != 4) {
203
-		return FALSE;
204
-	}
205
-	if (cli_readn(fd, &itsf_hdr->last_modified, 4) != 4) {
206
-		return FALSE;
207
-	}
208
-	if (cli_readn(fd, &itsf_hdr->lang_id, 4) != 4) {
209
-		return FALSE;
210
-	}
211
-	if (cli_readn(fd, &itsf_hdr->dir_clsid, 16) != 16) {
212
-		return FALSE;
213
-	}
214
-	if (cli_readn(fd, &itsf_hdr->stream_clsid, 16) != 16) {
215
-		return FALSE;
216
-	}
217
-	if (cli_readn(fd, &itsf_hdr->sec0_offset, 8) != 8) {
218
-		return FALSE;
219
-	}
220
-	if (cli_readn(fd, &itsf_hdr->sec0_len, 8) != 8) {
221
-		return FALSE;
222
-	}
223
-	if (cli_readn(fd, &itsf_hdr->dir_offset, 8) != 8) {
224
-		return FALSE;
225
-	}
226
-	if (cli_readn(fd, &itsf_hdr->dir_len, 8) != 8) {
227
-		return FALSE;
228
-	}
229
-	if (itsf_hdr->version > 2) {
230
-		if (cli_readn(fd, &itsf_hdr->data_offset, 8) != 8) {
231
-			return FALSE;
232
-		}
233
-	}
234
-#endif
235 190
 	if (memcmp(itsf_hdr->signature, "ITSF", 4) != 0) {
236 191
 		cli_dbgmsg("ITSF signature mismatch\n");
237 192
 		return FALSE;
... ...
@@ -270,64 +200,11 @@ static void itsp_print_header(chm_itsp_header_t *itsp_hdr)
270 270
 	cli_dbgmsg("Lang ID:\t%u\n\n", itsp_hdr->lang_id);
271 271
 }
272 272
 
273
-static int itsp_read_header(int fd, chm_itsp_header_t *itsp_hdr, off_t offset,
274
-				char *m_area, off_t m_length)
273
+static int itsp_read_header(chm_metadata_t *metadata, off_t offset)
275 274
 {
276
-#if defined(HAVE_ATTRIB_PACKED) || defined(HAVE_PRAGMA_PACK) || defined(HAVE_PRAGMA_PACK_HPPA)
277
-	if (!chm_read_data(fd, (char *) itsp_hdr, offset, CHM_ITSP_LEN,
278
-				m_area,	m_length)) {
279
-		return FALSE;
280
-	}
281
-#else
282
-	if (lseek(fd, offset, SEEK_SET) != offset) {
283
-		return FALSE;
284
-	}
285
-	if (cli_readn(fd, &itsp_hdr->signature, 4) != 4) {
286
-		return FALSE;
287
-	}
288
-	if (cli_readn(fd, &itsp_hdr->version, 4) != 4) {
289
-		return FALSE;
290
-	}
291
-	if (cli_readn(fd, &itsp_hdr->header_len, 4) != 4) {
292
-		return FALSE;
293
-	}
294
-	if (cli_readn(fd, &itsp_hdr->unknown1, 4) != 4) {
295
-		return FALSE;
296
-	}
297
-	if (cli_readn(fd, &itsp_hdr->block_len, 4) != 4) {
298
-		return FALSE;
299
-	}
300
-	if (cli_readn(fd, &itsp_hdr->blockidx_intvl, 4) != 4) {
301
-		return FALSE;
302
-	}
303
-	if (cli_readn(fd, &itsp_hdr->index_depth, 4) != 4) {
304
-		return FALSE;
305
-	}
306
-	if (cli_readn(fd, &itsp_hdr->index_root, 4) != 4) {
307
-		return FALSE;
308
-	}
309
-	if (cli_readn(fd, &itsp_hdr->index_head, 4) != 4) {
310
-		return FALSE;
311
-	}
312
-	if (cli_readn(fd, &itsp_hdr->index_tail, 4) != 4) {
313
-		return FALSE;
314
-	}
315
-	if (cli_readn(fd, &itsp_hdr->unknown2, 4) != 4) {
316
-		return FALSE;
317
-	}
318
-	if (cli_readn(fd, &itsp_hdr->num_blocks, 4) != 4) {
319
-		return FALSE;
320
-	}
321
-	if (cli_readn(fd, &itsp_hdr->lang_id, 4) != 4) {
322
-		return FALSE;
323
-	}
324
-	if (cli_readn(fd, &itsp_hdr->system_clsid, 16) != 16) {
325
-		return FALSE;
326
-	}
327
-	if (cli_readn(fd, &itsp_hdr->unknown4, 16) != 16) {
275
+	chm_itsp_header_t *itsp_hdr = &metadata->itsp_hdr;
276
+	if (!chm_read_data(metadata->map, (char *)itsp_hdr, offset, CHM_ITSP_LEN))
328 277
 		return FALSE;
329
-	}
330
-#endif
331 278
 	if (memcmp(itsp_hdr->signature, "ITSP", 4) != 0) {
332 279
 		cli_dbgmsg("ITSP signature mismatch\n");
333 280
 		return FALSE;
... ...
@@ -417,7 +294,7 @@ static int read_control_entries(chm_metadata_t *metadata)
417 417
 	return TRUE;
418 418
 }
419 419
 
420
-static int prepare_file(int fd, chm_metadata_t *metadata)
420
+static int prepare_file(chm_metadata_t *metadata)
421 421
 {
422 422
 	uint64_t name_len, section;
423 423
 
... ...
@@ -445,7 +322,7 @@ static int prepare_file(int fd, chm_metadata_t *metadata)
445 445
 	return CL_BREAK;
446 446
 }
447 447
 
448
-static int read_chunk(chm_metadata_t *metadata, int fd)
448
+static int read_chunk(chm_metadata_t *metadata)
449 449
 {
450 450
 	cli_dbgmsg("in read_chunk\n");
451 451
 
... ...
@@ -453,29 +330,15 @@ static int read_chunk(chm_metadata_t *metadata, int fd)
453 453
 		return CL_EFORMAT;
454 454
 	}
455 455
 
456
-	if (metadata->m_area != NULL) {
457
-		if (metadata->chunk_offset > metadata->m_length) {
458
-			return CL_EFORMAT;
459
-		}
460
-		if ((metadata->chunk_offset + metadata->itsp_hdr.block_len) > metadata->m_length) {
461
-			return CL_EFORMAT;
462
-		}
463
-		metadata->chunk_data = metadata->m_area + metadata->chunk_offset;
464
-
465
-	} else {
466
-		if (!metadata->chunk_data) {
467
-			metadata->chunk_data = (char *) cli_malloc(metadata->itsp_hdr.block_len);
468
-			if (!metadata->chunk_data) {
469
-				return CL_EMEM;
470
-			}
471
-		}
472
-        	if (lseek(fd, metadata->chunk_offset, SEEK_SET) != metadata->chunk_offset) {
473
-                	goto abort;
474
-        	}
475
-        	if ((uint32_t) cli_readn(fd, metadata->chunk_data, metadata->itsp_hdr.block_len) != metadata->itsp_hdr.block_len) {
476
-               		goto abort;
477
-        	}
456
+	if (metadata->chunk_offset > metadata->m_length) {
457
+		return CL_EFORMAT;
458
+	}
459
+	if ((metadata->chunk_offset + metadata->itsp_hdr.block_len) > metadata->m_length) {
460
+		return CL_EFORMAT;
478 461
 	}
462
+	metadata->chunk_data = fmap_need_off_once(metadata->map, metadata->chunk_offset, metadata->itsp_hdr.block_len);
463
+	if(!metadata->chunk_data) return CL_EFORMAT;
464
+
479 465
 	metadata->chunk_current = metadata->chunk_data + CHM_CHUNK_HDR_LEN;
480 466
 	metadata->chunk_end = metadata->chunk_data + metadata->itsp_hdr.block_len;
481 467
 
... ...
@@ -483,19 +346,10 @@ static int read_chunk(chm_metadata_t *metadata, int fd)
483 483
 		metadata->chunk_entries = (uint16_t)((((uint8_t const *)(metadata->chunk_data))[metadata->itsp_hdr.block_len-2] << 0)
484 484
 					| (((uint8_t const *)(metadata->chunk_data))[metadata->itsp_hdr.block_len-1] << 8));
485 485
 	} else if (memcmp(metadata->chunk_data, "PMGI", 4) != 0) {
486
-		if (!metadata->m_area && metadata->chunk_data) {
487
-			free(metadata->chunk_data);
488
-		}
489 486
 		return CL_BREAK;
490 487
 	}
491 488
 
492 489
 	return CL_SUCCESS;
493
-abort:
494
-	if (!metadata->m_area && metadata->chunk_data) {
495
-		free(metadata->chunk_data);
496
-		metadata->chunk_data = NULL;
497
-	}
498
-	return CL_EFORMAT;
499 490
 }
500 491
 
501 492
 static void print_sys_control(lzx_control_t *lzx_control)
... ...
@@ -514,7 +368,7 @@ static void print_sys_control(lzx_control_t *lzx_control)
514 514
 	cli_dbgmsg("Cache Size:\t%d\n\n", lzx_control->cache_size);
515 515
 }
516 516
 
517
-static int read_sys_control(int fd, chm_metadata_t *metadata, lzx_control_t *lzx_control)
517
+static int read_sys_control(chm_metadata_t *metadata, lzx_control_t *lzx_control)
518 518
 {
519 519
 	off_t offset;
520 520
 	
... ...
@@ -526,34 +380,10 @@ static int read_sys_control(int fd, chm_metadata_t *metadata, lzx_control_t *lzx
526 526
 		return FALSE;
527 527
 	}
528 528
 
529
-#if defined(HAVE_ATTRIB_PACKED) || defined(HAVE_PRAGMA_PACK) || defined(HAVE_PRAGMA_PACK_HPPA)
530
-	if (!chm_read_data(fd, (char *) lzx_control, offset, CHM_CONTROL_LEN,
531
-				metadata->m_area, metadata->m_length)) {
532
-		return FALSE;
533
-	}
534
-#else
535
-	if (lseek(fd, offset, SEEK_SET) != offset) {
536
-		return FALSE;
537
-	}
538
-	if (cli_readn(fd, &lzx_control->length, 4) != 4) {
539
-		return FALSE;
540
-	}
541
-	if (cli_readn(fd, &lzx_control->signature, 4) != 4) {
529
+	if (!chm_read_data(metadata->map, (char *) lzx_control, offset, CHM_CONTROL_LEN)) {
542 530
 		return FALSE;
543 531
 	}
544
-	if (cli_readn(fd, &lzx_control->version, 4) != 4) {
545
-		return FALSE;
546
-	}
547
-	if (cli_readn(fd, &lzx_control->reset_interval, 4) != 4) {
548
-		return FALSE;
549
-	}
550
-	if (cli_readn(fd, &lzx_control->window_size, 4) != 4) {
551
-		return FALSE;
552
-	}
553
-	if (cli_readn(fd, &lzx_control->cache_size, 4) != 4) {
554
-		return FALSE;
555
-	}
556
-#endif
532
+
557 533
 	lzx_control->length = chm_endian_convert_32(lzx_control->length);
558 534
 	lzx_control->version = chm_endian_convert_32(lzx_control->version);
559 535
 	lzx_control->reset_interval = chm_endian_convert_32(lzx_control->reset_interval);
... ...
@@ -591,7 +421,7 @@ static void print_sys_content(lzx_content_t *lzx_content)
591 591
 	cli_dbgmsg("Length:\t%lu\n\n", (unsigned long int) lzx_content->length);
592 592
 }
593 593
 
594
-static int read_sys_content(int fd, chm_metadata_t *metadata, lzx_content_t *lzx_content)
594
+static int read_sys_content(chm_metadata_t *metadata, lzx_content_t *lzx_content)
595 595
 {
596 596
 	lzx_content->offset = metadata->itsf_hdr.data_offset + metadata->sys_content.offset;
597 597
 	lzx_content->length = metadata->sys_content.length;
... ...
@@ -615,7 +445,7 @@ static void print_sys_reset_table(lzx_reset_table_t *lzx_reset_table)
615 615
 	cli_dbgmsg("Frame Len:\t%lu\n\n", (unsigned long int) lzx_reset_table->frame_len);
616 616
 }
617 617
 
618
-static int read_sys_reset_table(int fd, chm_metadata_t *metadata, lzx_reset_table_t *lzx_reset_table)
618
+static int read_sys_reset_table(chm_metadata_t *metadata, lzx_reset_table_t *lzx_reset_table)
619 619
 {
620 620
 	off_t offset;
621 621
 
... ...
@@ -632,34 +462,10 @@ static int read_sys_reset_table(int fd, chm_metadata_t *metadata, lzx_reset_tabl
632 632
 	/* Save the entry offset for later use */
633 633
 	lzx_reset_table->rt_offset = offset-4;
634 634
 
635
-#if defined(HAVE_ATTRIB_PACKED) || defined(HAVE_PRAGMA_PACK) || defined(HAVE_PRAGMA_PACK_HPPA)
636
-	if (!chm_read_data(fd, (char *) lzx_reset_table, offset, CHM_RESET_TABLE_LEN,
637
-				metadata->m_area, metadata->m_length)) {
638
-		return FALSE;
639
-	}
640
-#else	
641
-	if (lseek(fd, offset, SEEK_SET) != offset) {
642
-		return FALSE;
643
-	}
644
-	if (cli_readn(fd, &lzx_reset_table->num_entries, 4) != 4) {
645
-		return FALSE;
646
-	}
647
-	if (cli_readn(fd, &lzx_reset_table->entry_size, 4) != 4) {
648
-		return FALSE;
649
-	}
650
-	if (cli_readn(fd, &lzx_reset_table->table_offset, 4) != 4) {
651
-		return FALSE;
652
-	}
653
-	if (cli_readn(fd, &lzx_reset_table->uncom_len, 8) != 8) {
654
-		return FALSE;
655
-	}
656
-	if (cli_readn(fd, &lzx_reset_table->com_len, 8) != 8) {
657
-		return FALSE;
658
-	}
659
-	if (cli_readn(fd, &lzx_reset_table->frame_len, 8) != 8) {
635
+	if (!chm_read_data(metadata->map, (char *) lzx_reset_table, offset, CHM_RESET_TABLE_LEN)) {
660 636
 		return FALSE;
661 637
 	}
662
-#endif
638
+
663 639
 	lzx_reset_table->num_entries = chm_endian_convert_32(lzx_reset_table->num_entries);
664 640
 	lzx_reset_table->entry_size = chm_endian_convert_32(lzx_reset_table->entry_size);
665 641
 	lzx_reset_table->table_offset = chm_endian_convert_32(lzx_reset_table->table_offset);
... ...
@@ -705,13 +511,13 @@ static int chm_decompress_stream(int fd, chm_metadata_t *metadata, const char *d
705 705
 		goto abort;
706 706
 	}
707 707
 
708
-	if (!read_sys_control(fd, metadata, &lzx_control)) {
708
+	if (!read_sys_control(metadata, &lzx_control)) {
709 709
 		goto abort;
710 710
 	}
711
-	if (!read_sys_content(fd, metadata, &lzx_content)) {
711
+	if (!read_sys_content(metadata, &lzx_content)) {
712 712
 		goto abort;
713 713
 	}
714
-	if (!read_sys_reset_table(fd, metadata, &lzx_reset_table)) {
714
+	if (!read_sys_reset_table(metadata, &lzx_reset_table)) {
715 715
 		goto abort;
716 716
 	}
717 717
 	
... ...
@@ -793,7 +599,7 @@ static int chm_init_metadata(chm_metadata_t *metadata)
793 793
 	}
794 794
 	
795 795
 	metadata->sys_control.length = metadata->sys_content.length = metadata->sys_reset.length = 0;
796
-	metadata->m_area = NULL;
796
+	metadata->map = NULL;
797 797
 	metadata->ufd = -1;
798 798
 	metadata->num_chunks = metadata->chunk_entries = 0;
799 799
 	metadata->chunk_data = NULL;
... ...
@@ -805,17 +611,10 @@ void cli_chm_close(chm_metadata_t *metadata)
805 805
 	if (metadata->ufd >= 0) {
806 806
 		close(metadata->ufd);
807 807
 	}
808
-	if (!metadata->m_area && metadata->chunk_data) {
809
-		free(metadata->chunk_data);
810
-	}
811
-#ifdef HAVE_MMAP
812
-	if (metadata->m_area) {
813
-		munmap(metadata->m_area, metadata->m_length);
814
-	}
815
-#endif
808
+	fmunmap(metadata->map);
816 809
 }
817 810
 
818
-int cli_chm_extract_file(int fd, char *dirname, chm_metadata_t *metadata, cli_ctx *ctx)
811
+int cli_chm_extract_file(char *dirname, chm_metadata_t *metadata, cli_ctx *ctx)
819 812
 {
820 813
 	char filename[1024];
821 814
 	uint64_t len;
... ...
@@ -841,7 +640,7 @@ int cli_chm_extract_file(int fd, char *dirname, chm_metadata_t *metadata, cli_ct
841 841
 	return CL_SUCCESS;
842 842
 }	
843 843
 
844
-int cli_chm_prepare_file(int fd, char *dirname, chm_metadata_t *metadata)
844
+int cli_chm_prepare_file(chm_metadata_t *metadata)
845 845
 {
846 846
 	int retval;
847 847
 	
... ...
@@ -852,13 +651,13 @@ int cli_chm_prepare_file(int fd, char *dirname, chm_metadata_t *metadata)
852 852
 			if (metadata->num_chunks == 0) {
853 853
 				return CL_BREAK;
854 854
 			}
855
-			if ((retval = read_chunk(metadata, fd)) != CL_SUCCESS) {
855
+			if ((retval = read_chunk(metadata)) != CL_SUCCESS) {
856 856
 				return retval;
857 857
 			}
858 858
 			metadata->num_chunks--;
859 859
 			metadata->chunk_offset += metadata->itsp_hdr.block_len;
860 860
 		}
861
-		retval = prepare_file(fd, metadata);
861
+		retval = prepare_file(metadata);
862 862
 	} while (retval == CL_BREAK); /* Ran out of chunk entries before finding a file */
863 863
 	return retval;
864 864
 }
... ...
@@ -874,25 +673,23 @@ int cli_chm_open(int fd, const char *dirname, chm_metadata_t *metadata, cli_ctx
874 874
 		return retval;
875 875
 	}
876 876
 
877
-#ifdef HAVE_MMAP
878 877
 	if (fstat(fd, &statbuf) == 0) {
879 878
 		if (statbuf.st_size < CHM_ITSF_MIN_LEN) {
880
-			goto abort;
879
+			return CL_ESTAT;
881 880
 		}
882 881
 		metadata->m_length = statbuf.st_size;
883
-		metadata->m_area = (char *) mmap(NULL, metadata->m_length, PROT_READ, MAP_PRIVATE, fd, 0);
884
-		if (metadata->m_area == MAP_FAILED) {
885
-			metadata->m_area = NULL;
882
+		metadata->map = fmap(fd, 0, metadata->m_length);
883
+		if (!metadata->map) {
884
+			return CL_EMAP;
886 885
 		}
887 886
 	}
888
-#endif
889 887
 
890
-	if (!itsf_read_header(fd, &metadata->itsf_hdr, metadata->m_area, metadata->m_length)) {
888
+	if (!itsf_read_header(metadata)) {
891 889
 		goto abort;
892 890
 	}
893 891
 	itsf_print_header(&metadata->itsf_hdr);
894 892
 
895
-	if (!itsp_read_header(fd, &metadata->itsp_hdr, metadata->itsf_hdr.dir_offset, metadata->m_area, metadata->m_length)) {
893
+	if (!itsp_read_header(metadata, metadata->itsf_hdr.dir_offset)) {
896 894
 		goto abort;
897 895
 	}
898 896
 	itsp_print_header(&metadata->itsp_hdr);
... ...
@@ -916,7 +713,7 @@ int cli_chm_open(int fd, const char *dirname, chm_metadata_t *metadata, cli_ctx
916 916
 	}
917 917
 	
918 918
 	while (metadata->num_chunks) {
919
-		if (read_chunk(metadata, fd) != CL_SUCCESS) {
919
+		if (read_chunk(metadata) != CL_SUCCESS) {
920 920
 			cli_dbgmsg("read_chunk failed\n");
921 921
 			goto abort;
922 922
 		}
... ...
@@ -945,10 +742,6 @@ int cli_chm_open(int fd, const char *dirname, chm_metadata_t *metadata, cli_ctx
945 945
 	return CL_SUCCESS;
946 946
 
947 947
 abort:
948
-#ifdef HAVE_MMAP
949
-	if (metadata->m_area) {
950
-		munmap(metadata->m_area, metadata->m_length);
951
-	}
952
-#endif
948
+	fmunmap(metadata->map);
953 949
 	return CL_EFORMAT;
954 950
 }
... ...
@@ -29,6 +29,7 @@
29 29
 
30 30
 #include "cltypes.h"
31 31
 #include "others.h"
32
+#include "fmap.h"
32 33
 
33 34
 #ifndef HAVE_ATTRIB_PACKED
34 35
 #define __attribute__(x)
... ...
@@ -101,7 +102,6 @@ typedef struct chm_metadata_tag {
101 101
 	chm_sys_entry_t sys_content;
102 102
 	chm_sys_entry_t sys_reset;
103 103
 	off_t m_length;
104
-	char *m_area;
105 104
 	chm_itsf_header_t itsf_hdr;
106 105
 	chm_itsp_header_t itsp_hdr;
107 106
 	int ufd;
... ...
@@ -111,11 +111,12 @@ typedef struct chm_metadata_tag {
111 111
 	char *chunk_data;
112 112
 	char *chunk_current;
113 113
 	char *chunk_end;
114
+	struct F_MAP *map;
114 115
 	uint16_t chunk_entries;
115 116
 } chm_metadata_t;
116 117
 
117 118
 int cli_chm_open(int fd, const char *dirname, chm_metadata_t *metadata, cli_ctx *ctx);
118
-int cli_chm_prepare_file(int fd, char *dirname, chm_metadata_t *metadata);
119
-int cli_chm_extract_file(int fd, char *dirname, chm_metadata_t *metadata, cli_ctx *ctx);
119
+int cli_chm_prepare_file(chm_metadata_t *metadata);
120
+int cli_chm_extract_file(char *dirname, chm_metadata_t *metadata, cli_ctx *ctx);
120 121
 void cli_chm_close(chm_metadata_t *metadata);
121 122
 #endif
... ...
@@ -1293,11 +1293,11 @@ static int cli_scanmschm(int desc, cli_ctx *ctx)
1293 1293
     }
1294 1294
 
1295 1295
    do {
1296
-	ret = cli_chm_prepare_file(desc, dir, &metadata);
1296
+	ret = cli_chm_prepare_file(&metadata);
1297 1297
 	if (ret != CL_SUCCESS) {
1298 1298
 	   break;
1299 1299
 	}
1300
-	ret = cli_chm_extract_file(desc, dir, &metadata, ctx);
1300
+	ret = cli_chm_extract_file(dir, &metadata, ctx);
1301 1301
 	if (ret == CL_SUCCESS) {
1302 1302
 	    lseek(metadata.ofd, 0, SEEK_SET);
1303 1303
 	    rc = cli_magic_scandesc(metadata.ofd, ctx);