/[pcsx2_0.9.7]/trunk/plugins/CDVDpeops/libiso.c
ViewVC logotype

Contents of /trunk/plugins/CDVDpeops/libiso.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 31 - (show annotations) (download)
Tue Sep 7 03:24:11 2010 UTC (9 years, 11 months ago) by william
File MIME type: text/plain
File size: 16950 byte(s)
committing r3113 initial commit again...
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
4 #include <sys/types.h>
5 #include <sys/stat.h>
6 #include <fcntl.h>
7 //#include <zlib.h>
8
9 #define __MSCW32__
10 #ifdef __WIN32__
11 #include <windows.h>
12 #endif
13
14 #include "PS2Etypes.h"
15 //#include "CDVDiso.h"
16 #include "libiso.h"
17
18 /* some structs from libcdvd by Hiryu & Sjeep (C) 2002 */
19
20 #if defined(__WIN32__)
21 #pragma pack(1)
22 #endif
23
24 struct rootDirTocHeader
25 {
26 u16 length; //+00
27 u32 tocLBA; //+02
28 u32 tocLBA_bigend; //+06
29 u32 tocSize; //+0A
30 u32 tocSize_bigend; //+0E
31 u8 dateStamp[8]; //+12
32 u8 reserved[6]; //+1A
33 u8 reserved2; //+20
34 u8 reserved3; //+21
35 #if defined(__WIN32__)
36 }; //+22
37 #else
38 } __attribute__((packed));
39 #endif
40
41 struct asciiDate
42 {
43 char year[4];
44 char month[2];
45 char day[2];
46 char hours[2];
47 char minutes[2];
48 char seconds[2];
49 char hundreths[2];
50 char terminator[1];
51 #if defined(__WIN32__)
52 };
53 #else
54 } __attribute__((packed));
55 #endif
56
57 struct cdVolDesc
58 {
59 u8 filesystemType; // 0x01 = ISO9660, 0x02 = Joliet, 0xFF = NULL
60 u8 volID[5]; // "CD001"
61 u8 reserved2;
62 u8 reserved3;
63 u8 sysIdName[32];
64 u8 volName[32]; // The ISO9660 Volume Name
65 u8 reserved5[8];
66 u32 volSize; // Volume Size
67 u32 volSizeBig; // Volume Size Big-Endian
68 u8 reserved6[32];
69 u32 unknown1;
70 u32 unknown1_bigend;
71 u16 volDescSize; //+80
72 u16 volDescSize_bigend; //+82
73 u32 unknown3; //+84
74 u32 unknown3_bigend; //+88
75 u32 priDirTableLBA; // LBA of Primary Dir Table //+8C
76 u32 reserved7; //+90
77 u32 secDirTableLBA; // LBA of Secondary Dir Table //+94
78 u32 reserved8; //+98
79 struct rootDirTocHeader rootToc;
80 u8 volSetName[128];
81 u8 publisherName[128];
82 u8 preparerName[128];
83 u8 applicationName[128];
84 u8 copyrightFileName[37];
85 u8 abstractFileName[37];
86 u8 bibliographyFileName[37];
87 struct asciiDate creationDate;
88 struct asciiDate modificationDate;
89 struct asciiDate effectiveDate;
90 struct asciiDate expirationDate;
91 u8 reserved10;
92 u8 reserved11[1166];
93 #if defined(__WIN32__)
94 };
95 #else
96 } __attribute__((packed));
97 #endif
98
99
100 #ifdef __WIN32__
101 void *_openfile(const char *filename, int flags) {
102 HANDLE handle;
103
104 // printf("_openfile %s, %d\n", filename, flags & O_RDONLY);
105 if (flags & O_WRONLY) {
106 int _flags = CREATE_NEW;
107 if (flags & O_CREAT) _flags = CREATE_ALWAYS;
108 handle = CreateFile(filename, GENERIC_WRITE, 0, NULL, _flags, 0, NULL);
109 } else {
110 handle = CreateFile(filename, GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, NULL);
111 }
112
113 return handle == INVALID_HANDLE_VALUE ? NULL : handle;
114 }
115
116 u64 _tellfile(void *handle) {
117 u64 ofs;
118 DWORD *_ofs = (DWORD*)&ofs;
119 _ofs[1] = 0;
120 _ofs[0] = SetFilePointer(handle, 0, &_ofs[1], FILE_CURRENT);
121 return ofs;
122 }
123
124 int _seekfile(void *handle, u64 offset, int whence) {
125 u64 ofs = (u64)offset;
126 DWORD *_ofs = (DWORD*)&ofs;
127 // printf("_seekfile %p, %d_%d\n", handle, _ofs[1], _ofs[0]);
128 if (whence == SEEK_SET) {
129 SetFilePointer(handle, _ofs[0], &_ofs[1], FILE_BEGIN);
130 } else {
131 SetFilePointer(handle, _ofs[0], &_ofs[1], FILE_END);
132 }
133 return 0;
134 }
135
136 int _readfile(void *handle, void *dst, int size) {
137 DWORD ret;
138
139 // printf("_readfile %p %d\n", handle, size);
140 ReadFile(handle, dst, size, &ret, NULL);
141 // printf("_readfile ret %d; %d\n", ret, GetLastError());
142 return ret;
143 }
144
145 int _writefile(void *handle, void *src, int size) {
146 DWORD ret;
147
148 // printf("_writefile %p, %d\n", handle, size);
149 // _seekfile(handle, _tellfile(handle));
150 WriteFile(handle, src, size, &ret, NULL);
151 // printf("_writefile ret %d\n", ret);
152 return ret;
153 }
154
155 void _closefile(void *handle) {
156 CloseHandle(handle);
157 }
158
159 #else
160
161 void *_openfile(const char *filename, int flags) {
162 printf("_openfile %s %x\n", filename, flags);
163 if (flags & O_WRONLY)
164 return fopen(filename, "wb");
165 else return fopen(filename, "rb");
166 }
167
168 u64 _tellfile(void *handle) {
169 return ftell(handle);
170 }
171
172 int _seekfile(void *handle, u64 offset, int whence) {
173 return fseek(handle, offset, whence);
174 }
175
176 int _readfile(void *handle, void *dst, int size) {
177 return fread(dst, 1, size, handle);
178 }
179
180 int _writefile(void *handle, void *src, int size) {
181 return fwrite(src, 1, size, handle);
182 }
183
184 void _closefile(void *handle) {
185 fclose(handle);
186 }
187
188 #endif
189
190 int detect(isoFile *iso) {
191 char buf[2448];
192 struct cdVolDesc *volDesc;
193
194 if (isoReadBlock(iso, buf, 16) == -1) return -1;
195 volDesc = (struct cdVolDesc *)(buf + 24);
196 if (strncmp(volDesc->volID, "CD001", 5)) return 0;
197
198 if (volDesc->rootToc.tocSize == 2048) {
199 iso->type = ISOTYPE_CD;
200 } else {
201 iso->type = ISOTYPE_DVD;
202 }
203
204 return 1;
205 }
206
207 int _isoReadZtable(isoFile *iso) {
208 void *handle;
209 char table[256];
210 int size;
211
212 sprintf(table, "%s.table", iso->filename);
213 handle = _openfile(table, O_RDONLY);
214 if (handle == NULL) {
215 printf("Error loading %s\n", table);
216 return -1;
217 }
218
219 _seekfile(handle, 0, SEEK_END);
220 size = (int)_tellfile(handle);
221 iso->Ztable = (char*)malloc(size);
222 if (iso->Ztable == NULL) {
223 return -1;
224 }
225
226 _seekfile(handle, 0, SEEK_SET);
227 _readfile(handle, iso->Ztable, size);
228 _closefile(handle);
229
230 iso->blocks = size / 6;
231
232 return 0;
233 }
234
235 int _isoReadZ2table(isoFile *iso) {
236 void *handle;
237 char table[256];
238 u32 *Ztable;
239 int ofs;
240 int size;
241 int i;
242
243 sprintf(table, "%s.table", iso->filename);
244 handle = _openfile(table, O_RDONLY);
245 if (handle == NULL) {
246 printf("Error loading %s\n", table);
247 return -1;
248 }
249
250 _seekfile(handle, 0, SEEK_END);
251 size = (int)_tellfile(handle);
252 Ztable = (u32*)malloc(size);
253 if (Ztable == NULL) {
254 return -1;
255 }
256
257 _seekfile(handle, 0, SEEK_SET);
258 _readfile(handle, Ztable, size);
259 _closefile(handle);
260
261 iso->Ztable = (char*)malloc(iso->blocks*8);
262 if (iso->Ztable == NULL) {
263 return -1;
264 }
265
266 ofs=16;
267 for (i=0; i<iso->blocks; i++) {
268 *(u32*)&iso->Ztable[i*8+0] = ofs;
269 *(u32*)&iso->Ztable[i*8+4] = Ztable[i];
270 ofs+= Ztable[i];
271 }
272 free(Ztable);
273
274 return 0;
275 }
276
277 int _isoReadDtable(isoFile *iso) {
278 int ret;
279 int i;
280
281 _seekfile(iso->handle, 0, SEEK_END);
282 iso->dtablesize = (int)(_tellfile(iso->handle) - 16) / (iso->blocksize+4);
283 iso->dtable = (u32*)malloc(iso->dtablesize*4);
284
285 for (i=0; i<iso->dtablesize; i++) {
286 _seekfile(iso->handle, 16+(iso->blocksize+4)*i, SEEK_SET);
287 ret = _readfile(iso->handle, &iso->dtable[i], 4);
288 if (ret < 4) {
289 return -1;
290 }
291 }
292
293 return 0;
294 }
295
296 int isoDetect(isoFile *iso) { // based on florin's CDVDbin detection code :)
297 char buf[32];
298 int len;
299
300 iso->type = ISOTYPE_ILLEGAL;
301
302 len = strlen(iso->filename);
303 if (len >= 2) {
304 if (!strncmp(iso->filename+(len-2), ".Z", 2)) {
305 iso->flags = ISOFLAGS_Z;
306 iso->blocksize = 2352;
307 _isoReadZtable(iso);
308 return detect(iso) == 1 ? 0 : -1;
309 }
310 }
311
312 _seekfile(iso->handle, 0, SEEK_SET);
313 _readfile(iso->handle, buf, 4);
314 if (strncmp(buf, "BDV2", 4) == 0) {
315 iso->flags = ISOFLAGS_BLOCKDUMP;
316 _readfile(iso->handle, &iso->blocksize, 4);
317 _readfile(iso->handle, &iso->blocks, 4);
318 _readfile(iso->handle, &iso->blockofs, 4);
319 _isoReadDtable(iso);
320 return detect(iso) == 1 ? 0 : -1;
321 } else
322 if (strncmp(buf, "Z V2", 4) == 0) {
323 iso->flags = ISOFLAGS_Z2;
324 _readfile(iso->handle, &iso->blocksize, 4);
325 _readfile(iso->handle, &iso->blocks, 4);
326 _readfile(iso->handle, &iso->blockofs, 4);
327 _isoReadZ2table(iso);
328 return detect(iso) == 1 ? 0 : -1;
329 } else {
330 iso->blocks = 16;
331 }
332
333 // ISO 2048
334 iso->blocksize = 2048; iso->offset = 0; iso->blockofs = 24;
335 if (detect(iso) == 1) return 0;
336
337 // RAW 2336
338 iso->blocksize = 2336; iso->offset = 0; iso->blockofs = 16;
339 if (detect(iso) == 1) return 0;
340
341 // RAW 2352
342 iso->blocksize = 2352; iso->offset = 0; iso->blockofs = 0;
343 if (detect(iso) == 1) return 0;
344
345 // RAWQ 2448
346 iso->blocksize = 2448; iso->offset = 0; iso->blockofs = 0;
347 if (detect(iso) == 1) return 0;
348
349 // NERO ISO 2048
350 iso->blocksize = 2048; iso->offset = 150*2048; iso->blockofs = 24;
351 if (detect(iso) == 1) return 0;
352
353 // NERO RAW 2352
354 iso->blocksize = 2352; iso->offset = 150*2048; iso->blockofs = 0;
355 if (detect(iso) == 1) return 0;
356
357 // NERO RAWQ 2448
358 iso->blocksize = 2448; iso->offset = 150*2048; iso->blockofs = 0;
359 if (detect(iso) == 1) return 0;
360
361 // ISO 2048
362 iso->blocksize = 2048; iso->offset = -8; iso->blockofs = 24;
363 if (detect(iso) == 1) return 0;
364
365 // RAW 2352
366 iso->blocksize = 2352; iso->offset = -8; iso->blockofs = 0;
367 if (detect(iso) == 1) return 0;
368
369 // RAWQ 2448
370 iso->blocksize = 2448; iso->offset = -8; iso->blockofs = 0;
371 if (detect(iso) == 1) return 0;
372
373 iso->offset = 0;
374 iso->blocksize = 2352;
375 iso->type = ISOTYPE_AUDIO;
376 return 0;
377
378 return -1;
379 }
380
381 isoFile *isoOpen(const char *filename) {
382 isoFile *iso;
383
384 iso = (isoFile*)malloc(sizeof(isoFile));
385 if (iso == NULL) return NULL;
386
387 memset(iso, 0, sizeof(isoFile));
388 strcpy(iso->filename, filename);
389
390 iso->handle = _openfile(iso->filename, O_RDONLY);
391 if (iso->handle == NULL) {
392 printf("Error loading %s\n", iso->filename);
393 return NULL;
394 }
395
396 if (isoDetect(iso) == -1) return NULL;
397
398 if (iso->flags & (ISOFLAGS_Z | ISOFLAGS_Z2 | ISOFLAGS_BLOCKDUMP)) {
399 } else {
400 _seekfile(iso->handle, 0, SEEK_END);
401 iso->blocks = (u32)((_tellfile(iso->handle) - iso->offset) /
402 (iso->blocksize));
403 }
404 /*
405 if (strlen(IsoFile) > 3 &&
406 !strncmp(IsoFile + (strlen(IsoFile) - 3), "I00", 3)) {
407 int i;
408 int llsn=0;
409
410 for (i=0; i<8; i++) {
411 IsoFile[strlen(IsoFile) - 1] = '0' + i;
412 if (stat(IsoFile, &buf) == -1) break;
413 cdIndexs[i].slsn = llsn;
414 llsn+= buf.st_size / cdblocksize;
415 cdIndexs[i].elsn = llsn-1;
416 cdHandle[i] = fopen(IsoFile, "rb");
417 if (cdHandle[i] == NULL) break;
418 }
419
420 if (i == 0) {
421 SysMessage("Error loading %s\n", IsoFile);
422 return -1;
423 }
424 fmode = 3;
425 } else*//* {
426 iso->handle = _openfile(iso->filename, O_RDONLY);
427 if (iso->handle == NULL) {
428 printf("Error loading %s\n", iso->filename);
429 return NULL;
430 }
431 }*/
432
433 printf("isoOpen: %s ok\n", iso->filename);
434 printf("offset = %d\n", iso->offset);
435 printf("blockofs = %d\n", iso->blockofs);
436 printf("blocksize = %d\n", iso->blocksize);
437 printf("blocks = %d\n", iso->blocks);
438 printf("type = %d\n", iso->type);
439
440 return iso;
441 }
442
443 isoFile *isoCreate(const char *filename, int flags) {
444 isoFile *iso;
445 char Zfile[256];
446
447 iso = (isoFile*)malloc(sizeof(isoFile));
448 if (iso == NULL) return NULL;
449
450 memset(iso, 0, sizeof(isoFile));
451 strcpy(iso->filename, filename);
452 iso->flags = flags;
453 iso->offset = 0;
454 iso->blockofs = 24;
455 iso->blocksize = CD_FRAMESIZE_RAW;
456 iso->blocksize = 2048;
457
458 if (iso->flags & (ISOFLAGS_Z | ISOFLAGS_Z2)) {
459 sprintf(Zfile, "%s.table", iso->filename);
460 iso->htable = _openfile(Zfile, O_WRONLY);
461 if (iso->htable == NULL) {
462 return NULL;
463 }
464 }
465
466 iso->handle = _openfile(iso->filename, O_WRONLY);
467 if (iso->handle == NULL) {
468 printf("Error loading %s\n", iso->filename);
469 return NULL;
470 }
471 printf("isoCreate: %s ok\n", iso->filename);
472 printf("offset = %d\n", iso->offset);
473
474 return iso;
475 }
476
477 int isoSetFormat(isoFile *iso, int blockofs, int blocksize, int blocks) {
478 iso->blocksize = blocksize;
479 iso->blocks = blocks;
480 iso->blockofs = blockofs;
481 printf("blockofs = %d\n", iso->blockofs);
482 printf("blocksize = %d\n", iso->blocksize);
483 printf("blocks = %d\n", iso->blocks);
484 if (iso->flags & ISOFLAGS_Z2) {
485 if (_writefile(iso->handle, "Z V2", 4) < 4) return -1;
486 if (_writefile(iso->handle, &blocksize, 4) < 4) return -1;
487 if (_writefile(iso->handle, &blocks, 4) < 4) return -1;
488 if (_writefile(iso->handle, &blockofs, 4) < 4) return -1;
489 }
490 if (iso->flags & ISOFLAGS_BLOCKDUMP) {
491 if (_writefile(iso->handle, "BDV2", 4) < 4) return -1;
492 if (_writefile(iso->handle, &blocksize, 4) < 4) return -1;
493 if (_writefile(iso->handle, &blocks, 4) < 4) return -1;
494 if (_writefile(iso->handle, &blockofs, 4) < 4) return -1;
495 }
496
497 return 0;
498 }
499
500 s32 MSFtoLSN(u8 *Time) {
501 u32 lsn;
502
503 lsn = Time[2];
504 lsn+=(Time[1] - 2) * 75;
505 lsn+= Time[0] * 75 * 60;
506 return lsn;
507 }
508
509 void LSNtoMSF(u8 *Time, s32 lsn) {
510 u8 m, s, f;
511
512 lsn += 150;
513 m = lsn / 4500; // minuten
514 lsn = lsn - m * 4500; // minuten rest
515 s = lsn / 75; // sekunden
516 f = lsn - (s * 75); // sekunden rest
517 Time[0] = itob(m); Time[1] = itob(s); Time[2] = itob(f);
518 }
519
520 int _isoReadBlock(isoFile *iso, char *dst, int lsn) {
521 u64 ofs = (u64)lsn * iso->blocksize + iso->offset;
522 int ret;
523
524 // printf("_isoReadBlock %d, blocksize=%d, blockofs=%d\n", lsn, iso->blocksize, iso->blockofs);
525 memset(dst, 0, iso->blockofs);
526 _seekfile(iso->handle, ofs, SEEK_SET);
527 ret = _readfile(iso->handle, dst + iso->blockofs, iso->blocksize);
528 if (ret < iso->blocksize) {
529 printf("read error %d\n", ret);
530 return -1;
531 }
532
533 return 0;
534 }
535 /*
536 int _isoReadBlockZ(isoFile *iso, char *dst, int lsn) {
537 u32 pos, p;
538 uLongf size;
539 u8 Zbuf[CD_FRAMESIZE_RAW*2];
540 int ret;
541
542 // printf("_isoReadBlockZ %d, %d\n", lsn, iso->blocksize);
543 pos = *(unsigned long*)&iso->Ztable[lsn * 6];
544 p = *(unsigned short*)&iso->Ztable[lsn * 6 + 4];
545 // printf("%d, %d\n", pos, p);
546 _seekfile(iso->handle, pos, SEEK_SET);
547 ret = _readfile(iso->handle, Zbuf, p);
548 if (ret < p) {
549 printf("error reading block!!\n");
550 return -1;
551 }
552
553 size = CD_FRAMESIZE_RAW;
554 uncompress(dst, &size, Zbuf, p);
555
556 return 0;
557 }
558
559 int _isoReadBlockZ2(isoFile *iso, char *dst, int lsn) {
560 u32 pos, p;
561 uLongf size;
562 u8 Zbuf[16*1024];
563 int ret;
564
565 // printf("_isoReadBlockZ2 %d, %d\n", lsn, iso->blocksize);
566 pos = *(u32*)&iso->Ztable[lsn*8];
567 p = *(u32*)&iso->Ztable[lsn*8+4];
568 // printf("%d, %d\n", pos, p);
569 _seekfile(iso->handle, pos, SEEK_SET);
570 ret = _readfile(iso->handle, Zbuf, p);
571 if (ret < p) {
572 printf("error reading block!!\n");
573 return -1;
574 }
575
576 size = iso->blocksize;
577 uncompress(dst + iso->blockofs, &size, Zbuf, p);
578
579 return 0;
580 }
581 */
582 int _isoReadBlockD(isoFile *iso, char *dst, int lsn) {
583 int ret;
584 int i;
585
586 // printf("_isoReadBlockD %d, blocksize=%d, blockofs=%d\n", lsn, iso->blocksize, iso->blockofs);
587 memset(dst, 0, iso->blockofs);
588 for (i=0; i<iso->dtablesize;i++) {
589 if (iso->dtable[i] != lsn) continue;
590
591 _seekfile(iso->handle, 16+i*(iso->blocksize+4)+4, SEEK_SET);
592 ret = _readfile(iso->handle, dst + iso->blockofs, iso->blocksize);
593 if (ret < iso->blocksize) return -1;
594
595 return 0;
596 }
597 printf("block %d not found in dump\n", lsn);
598
599 return -1;
600 }
601
602 int isoReadBlock(isoFile *iso, char *dst, int lsn) {
603 int ret;
604
605 if (lsn > iso->blocks) {
606 printf("isoReadBlock: %d > %d\n", lsn, iso->blocks);
607 return -1;
608 }
609 /* if (iso->flags & ISOFLAGS_Z) {
610 ret = _isoReadBlockZ(iso, dst, lsn);
611 } else
612 if (iso->flags & ISOFLAGS_Z2) {
613 ret = _isoReadBlockZ2(iso, dst, lsn);
614 } else
615 */ if (iso->flags & ISOFLAGS_BLOCKDUMP) {
616 ret = _isoReadBlockD(iso, dst, lsn);
617 } else
618 ret = _isoReadBlock(iso, dst, lsn);
619 if (ret == -1) return ret;
620
621 if (iso->type == ISOTYPE_CD) {
622 LSNtoMSF(dst+12, lsn);
623 dst[15] = 2;
624 }
625
626 return 0;
627 }
628
629
630 int _isoWriteBlock(isoFile *iso, u8 *src, int lsn) {
631 u64 ofs = (u64)lsn * iso->blocksize + iso->offset;
632 int ret;
633
634 // printf("_isoWriteBlock %d (ofs=%d)\n", iso->blocksize, ofs);
635 _seekfile(iso->handle, ofs, SEEK_SET);
636 ret = _writefile(iso->handle, src + iso->blockofs, iso->blocksize);
637 // printf("_isoWriteBlock %d\n", ret);
638 if (ret < iso->blocksize) return -1;
639
640 return 0;
641 }
642 /*
643 int _isoWriteBlockZ(isoFile *iso, u8 *src, int lsn) {
644 u32 pos;
645 uLongf size;
646 u8 Zbuf[CD_FRAMESIZE_RAW];
647 int ret;
648
649 // printf("_isoWriteBlockZ %d\n", iso->blocksize);
650 size = 2352;
651 compress(Zbuf, &size, src, 2352);
652 // printf("_isoWriteBlockZ %d\n", size);
653
654 pos = (u32)_tellfile(iso->handle);
655 ret = _writefile(iso->htable, (u8*)&pos, 4);
656 if (ret < 4) return -1;
657 ret = _writefile(iso->htable, (u8*)&size, 2);
658 if (ret < 2) return -1;
659
660 ret = _writefile(iso->handle, Zbuf, size);
661 // printf("_isoWriteBlockZ %d\n", ret);
662 if (ret < size) {
663 printf("error writing block!!\n");
664 return -1;
665 }
666
667 return 0;
668 }
669
670 int _isoWriteBlockZ2(isoFile *iso, u8 *src, int lsn) {
671 uLongf size;
672 u8 Zbuf[1024*16];
673 int ret;
674
675 // printf("_isoWriteBlockZ %d\n", iso->blocksize);
676 size = 1024*16;
677 compress(Zbuf, &size, src + iso->blockofs, iso->blocksize);
678 // printf("_isoWriteBlockZ %d\n", size);
679
680 ret = _writefile(iso->htable, (u8*)&size, 4);
681 if (ret < 4) return -1;
682 ret = _writefile(iso->handle, Zbuf, size);
683 // printf("_isoWriteBlockZ %d\n", ret);
684 if (ret < size) {
685 printf("error writing block!!\n");
686 return -1;
687 }
688
689 return 0;
690 }
691 */
692 int _isoWriteBlockD(isoFile *iso, u8 *src, int lsn) {
693 int ret;
694
695 // printf("_isoWriteBlock %d (ofs=%d)\n", iso->blocksize, ofs);
696 ret = _writefile(iso->handle, &lsn, 4);
697 if (ret < 4) return -1;
698 ret = _writefile(iso->handle, src + iso->blockofs, iso->blocksize);
699 // printf("_isoWriteBlock %d\n", ret);
700 if (ret < iso->blocksize) return -1;
701
702 return 0;
703 }
704
705 int isoWriteBlock(isoFile *iso, char *src, int lsn) {
706 int ret;
707
708 /* if (iso->flags & ISOFLAGS_Z) {
709 ret = _isoWriteBlockZ(iso, src, lsn);
710 } else
711 if (iso->flags & ISOFLAGS_Z2) {
712 ret = _isoWriteBlockZ2(iso, src, lsn);
713 } else
714 */ if (iso->flags & ISOFLAGS_BLOCKDUMP) {
715 ret = _isoWriteBlockD(iso, src, lsn);
716 } else
717 ret = _isoWriteBlock(iso, src, lsn);
718 if (ret == -1) return ret;
719
720 return 0;
721 }
722
723 void isoClose(isoFile *iso) {
724 if (iso->handle) {
725 _closefile(iso->handle);
726 }
727 if (iso->htable) {
728 _closefile(iso->htable);
729 }
730 free(iso);
731 }
732

  ViewVC Help
Powered by ViewVC 1.1.22