wok view linld/stuff/src/ISO9660.CPP @ rev 23999

syslinux/iso2exe: read isolinux.cfg
author Pascal Bellard <pascal.bellard@slitaz.org>
date Tue Jan 12 07:47:12 2021 +0000 (2021-01-12)
parents a946c1651082
children 61df94a0fa43
line source
1 #include "crtl.h"
2 #include "iso9660.h"
4 #define setdirpage(to,sec) ((to) = *(int*)&(sec)<<(SECTORBITS-8))
5 #define cpytodirpage(to,from) ((to) = *(int*)((char*)&(from)+1))
6 #define cpyfromdirpage(to,from) (*(int*)((char*)&(to)+1) = (from))
8 #define isoroot() \
9 { \
10 extern void isoreadrootsector(void); \
11 isoreadrootsector(); \
12 setdirpage(x->dirpage, (* (unsigned long *) (isostate.buffer + 0x9E))); \
13 x->dirsize = filesize2dirsize(* (unsigned long *) (isostate.buffer + 0xA6)); \
14 }
16 static int isoreaddir(void)
17 {
18 char *p;
20 struct isostate *x=&isostate;
22 p = x->buffer;
23 if (x->curpos >= SECTORSZ || * (short *) (p + x->curpos) == 0) {
24 if ((x->curdirsize =- DIRSECTORSZ) < 0) return -1;
25 isoreadsector(&x->curdirofs); // x->filepos = 0
26 //x->curdirofs += SECTORSZ;
27 *(int *)((char *) &x->curdirofs+1) += SECTORSZ/256;
28 x->curpos = 0;
29 }
30 p += x->curpos;
31 x->fileofs = (* (unsigned long *) (p + 2)) << SECTORBITS;
32 if ((x->entrysize = * (short *) p) == 0) {
33 return -1;
34 }
35 // x->filename = "";
36 x->filesize = * (unsigned long *) (p + 10);
37 x->filemod = 0x81ED; if (p[25] & 2) ((char *)&(x->filemod))[1] = 0x41;
38 p = x->buffer + 34 + ((p[32] + x->curpos) & -2);
39 x->curpos += x->entrysize;
40 do {
41 register len = p[2];
42 if (* (short *) p == 0x4D4E) {
43 x->filename = p + 5;
44 p[len] = 0;
45 goto found;
46 }
47 p += len;
48 } while (x->buffer + x->curpos - 3 >= p);
49 found:
50 return 0;
51 }
53 #define isoreaddir_reset() \
54 { \
55 x->curdirsize = x->dirsize; \
56 cpyfromdirpage(x->curdirofs, x->dirpage); \
57 x->curpos = -1; \
58 }
60 int _isoopen(void)
61 {
62 // char *name, *s, c;
63 // char _64bits = cpuhaslm();
64 struct isostate *x=&isostate;
65 #define name (x->filename2open)
66 #define c (x->c)
67 #define _64bits (x->_64bits)
68 char *s;
70 #ifdef ISOHOOK
71 _64bits = cpuhaslm();
72 _32bits:
73 #endif
74 s = (char *) x->filename2open;
75 if (*s == '/') {
76 s++;
77 isoroot();
78 //if (strncmp(x->buffer+1,"CD001,5) == -1) return -1;
79 //if (*(int*)(x->buffer+1) != 0x4443) return -1;
80 }
81 next:
82 isoreaddir_reset();
83 name = s;
84 do s++; while (*s && *s != '/');
85 c = *s; *s = 0;
86 do {
87 if (isoreaddir() == -1) {
88 #ifdef ISOHOOK
89 if ((_64bits ^= CPUMASKLM) == 0) goto _32bits;
90 #endif
91 return -1;
92 }
93 const char *n = name;
94 #define i (x->tmp)
95 i = x->filename;
96 #ifdef ISOHOOK
97 if (_64bits) {
98 if (strhead(i, n) == -1) continue;
99 n = "64";
100 i += s - name; // strlen(name);
101 }
102 #endif
103 if (strcmp(i, n) != -1) break;
104 } while (1);
105 *s++ = c;
106 #define IS_DIR(x)( (*((char*) &x + 1) & (char)0676) == (char)0)
107 if (IS_DIR(x->filemod)) {
108 cpytodirpage(x->dirpage, x->fileofs);
109 x->dirsize = filesize2dirsize(x->filesize);
110 if (c) goto next;
111 }
112 isolseek(&x->fileofs);
113 return x->fd;
114 }