wok-current view linld/stuff/src/ISO9660.CPP @ rev 23870
syslinux: update iso2exe.sh
author | Pascal Bellard <pascal.bellard@slitaz.org> |
---|---|
date | Tue Jun 23 08:04:01 2020 +0000 (2020-06-23) |
parents | a2e843f5d9e4 |
children | 53914b720f76 |
line source
1 #include "crtl.h"
2 #include "crtlx.h"
3 #include "iso9660.h"
4 #define __ROCKRIDGE
6 #if 1
7 #define setdirofs(to,sec) (*(int*)((char*)&(to)+1) = *(int*)&(sec)<<(SECTORBITS-8))
8 #define cpydirofs(to,from) (*(int*)((char*)&(to)+1) = *(int*)((char*)&(from)+1))
9 #else
10 #define setdirofs(to,sec) (to = (sec)<<SECTORBITS)
11 #define cpydirofs(to,from) ((to) = (from))
12 #endif
14 #ifdef ISOHOOK
15 void isoroot(void)
16 #else
17 int isoroot(void)
18 #endif
19 {
20 static const unsigned long root = 16UL * 2048;
21 #ifdef ISOHOOK
22 isoreadsector(&root);
23 setdirofs(isostate.dirofs, (* (unsigned long *) (isostate.buffer + 0x9E)));
24 isostate.dirsize = filesize2dirsize(* (unsigned long *) (isostate.buffer + 0xA6));
25 #else
26 if (isoreadsector(&root) == -1 || strhead(isostate.buffer+1,"CD001") == -1) {
27 //close(isostate.fd);
28 return -1;
29 }
30 setdirofs(isostate.dirofs, (* (unsigned long *) (isostate.buffer + 0x9E)));
31 isostate.dirsize = filesize2dirsize(* (unsigned long *) (isostate.buffer + 0xA6));
32 return 0;
33 #endif
34 }
36 int isoreaddir(void)
37 {
38 char *p;
40 struct isostate *x=&isostate;
42 if (x->curdirsize == 0xFFFF) {
43 x->curdirsize = x->dirsize;
44 cpydirofs(x->curdirofs, x->dirofs);
45 goto restarted;
46 }
47 if (x->curpos >= SECTORSZ || * (short *) (x->buffer + x->curpos) == 0) {
48 restarted:
49 if (x->curdirsize < DIRSECTORSZ) return -1;
50 isoreadsector(&x->curdirofs);
51 //x->curdirofs += SECTORSZ;
52 *(int *)((char *) &x->curdirofs+1) += SECTORSZ/256;
53 x->curdirsize -= DIRSECTORSZ;
54 x->curpos = 0;
55 }
56 p = x->buffer; p += x->curpos;
57 if ((x->entrysize = * (short *) p) == 0) {
58 return -1;
59 }
60 x->fileofs = (* (unsigned long *) (p + 2)) << SECTORBITS;
61 x->filesize = * (unsigned long *) (p + 10);
62 x->filemod = 0x81ED; if (p[25] & 2) ((char *)&(x->filemod))[1] = 0x41;
63 //x->filemod = (p[25] & 2) ? 0040755 : 0100755;
64 //x->filemod = 0100755 - ((p[25] & (char)2) << 13);
65 #ifdef __ROCKRIDGE
66 // p += 34 + (p[32] & -2); ?
67 p = x->buffer + 34 + ((p[32] + x->curpos) & -2);
68 do {
69 register len = p[2];
70 if (* (short *) p == 0x4D4E) {
71 x->filename = p + 5;
72 p[len] = 0;
73 goto found;
74 }
75 p += len;
76 #ifndef ISOHOOK
77 } while (x->buffer + x->curpos + x->entrysize - 2 > p);
78 #else
79 } while (1);
80 #endif
81 #endif
82 #ifndef ISOHOOK
83 {
84 p = x->buffer + 33; x->filename = p += x->curpos;
85 p--;
86 if (((* (short *) p) & 0xFEFF) -1 == 0) {
87 x->filename = "..";
88 if (--(* (short *) p) == 0)
89 x->filename++;
90 }
91 else {
92 p += *p; p--;
93 if (* (short *) (p) != 0x313B) {
94 p++; p++; // no ;1 to remove
95 }
96 if (p[-1] == '.') p--;
97 *p = 0;
98 }
99 }
100 #endif
101 found:
102 x->curpos += x->entrysize;
103 return 0;
104 }
106 //#define IS_DIR(x)( ((x) & ~0777) == 040000)
107 //#define IS_DIR(x)( (char)((x) >> 9) == (char)040)
108 //#define IS_DIR(x)( (*((char*) &x + 1) & (char)0776) == (char)0100)
109 #define IS_DIR(x)( (*((char*) &x + 1) & (char)0676) == (char)0)
110 int _isoopen(void)
111 {
112 // char *name, *s, c;
113 // char _64bits = cpuhaslm();
114 struct isostate *x=&isostate;
115 #define name (x->filename2open)
116 #define c (x->c)
117 #define _64bits (x->_64bits)
118 char *s;
120 #ifdef ISOHOOK
121 extern int _cpuhaslm();
122 _64bits = _cpuhaslm();
123 #else
124 _64bits = cpuhaslm();
125 #endif
126 do {
127 #ifdef ISOHOOK
128 s = (char *) x->filename2open;
129 if (*s == '/') {
130 s++;
131 isoroot();
132 }
133 name = s;
134 while (*++s);
135 #else
136 for (s = (char *) x->filename2open; *s == '/' ; s++) {
137 isoroot();
138 }
139 next:
140 name = s;
141 do s++; while (*s && *s != '/');
142 c = *s; *s = 0;
143 #endif
144 for (x->curdirsize = 0xFFFF; isoreaddir() != -1;) {
145 const char *n = name;
146 #define i (x->tmp)
147 i = x->filename;
148 if (_64bits) {
149 if (strhead(i, n) == -1) continue;
150 n = "64";
151 i += s - name; // strlen(name);
152 }
153 if (strcmp(i, n)) continue;
154 #ifndef ISOHOOK
155 *s++ = c;
156 #endif
157 if (IS_DIR(x->filemod)) {
158 cpydirofs(x->dirofs, x->fileofs);
159 x->dirsize = filesize2dirsize(x->filesize);
160 #ifndef ISOHOOK
161 if (c) goto next;
162 #endif
163 }
164 isolseek(&x->fileofs);
165 return 0;
166 }
167 } while ((_64bits ^= CPUMASKLM) == 0);
168 return -1;
169 }