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

syslinux/isoboot.s: accept user args
author Pascal Bellard <pascal.bellard@slitaz.org>
date Fri Jun 19 15:46:21 2020 +0000 (2020-06-19)
parents d70f7cc6e3ac
children a2e843f5d9e4
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;
39 #ifdef __ROCKRIDGE
40 char *endname;
41 #endif
42 struct isostate *x=&isostate;
44 if (x->curdirsize == 0xFFFF) {
45 x->curdirsize = x->dirsize;
46 cpydirofs(x->curdirofs, x->dirofs);
47 goto restarted;
48 }
49 if (x->curpos >= SECTORSZ || * (short *) (x->buffer + x->curpos) == 0) {
50 restarted:
51 if (x->curdirsize < DIRSECTORSZ) return -1;
52 isoreadsector(&x->curdirofs);
53 //x->curdirofs += SECTORSZ;
54 *(int *)((char *) &x->curdirofs+1) += SECTORSZ/256;
55 x->curdirsize -= DIRSECTORSZ;
56 x->curpos = 0;
57 }
58 p = x->buffer; p += x->curpos;
59 if ((x->entrysize = * (short *) p) == 0) {
60 return -1;
61 }
62 x->fileofs = (* (unsigned long *) (p + 2)) << SECTORBITS;
63 x->filesize = * (unsigned long *) (p + 10);
64 x->filemod = 0x81ED; if (p[25] & 2) ((char *)&(x->filemod))[1] = 0x41;
65 //x->filemod = (p[25] & 2) ? 0040755 : 0100755;
66 //x->filemod = 0100755 - ((p[25] & (char)2) << 13);
67 #ifdef __ROCKRIDGE
68 endname = NULL;
69 // p += 34 + (p[32] & -2); ?
70 p = x->buffer + 34 + ((p[32] + x->curpos) & -2);
71 do {
72 int len = p[2];
73 # if 0
74 switch (* (short *) p) {
75 case 0x5850: // PX
76 x->filemod = * (short *) (p + 4);
77 break;
78 case 0x4D4E: // NM
79 # else
80 if (* (short *) p == 0x4D4E) {
81 # endif
82 x->filename = p + 5;
83 endname = p + len;
84 }
85 p += len;
86 } while (x->buffer + x->curpos + x->entrysize - 2 > p);
87 if (endname)
88 *endname = 0;
89 else
90 #endif
91 {
92 p = x->buffer + 33; x->filename = p += x->curpos;
93 p--;
94 if (((* (short *) p) & 0xFEFF) -1 == 0) {
95 x->filename = "..";
96 if (--(* (short *) p) == 0)
97 x->filename++;
98 }
99 else {
100 p += *p; p--;
101 if (* (short *) (p) != 0x313B) {
102 p++; p++; // no ;1 to remove
103 }
104 if (p[-1] == '.') p--;
105 *p = 0;
106 }
107 }
108 x->curpos += x->entrysize;
109 return 0;
110 }
112 //#define IS_DIR(x)( ((x) & ~0777) == 040000)
113 //#define IS_DIR(x)( (char)((x) >> 9) == (char)040)
114 //#define IS_DIR(x)( (*((char*) &x + 1) & (char)0776) == (char)0100)
115 #define IS_DIR(x)( (*((char*) &x + 1) & (char)0676) == (char)0)
116 int _isoopen(void)
117 {
118 // char *name, *s, c;
119 // char _64bits = cpuhaslm();
120 struct isostate *x=&isostate;
121 #define name (x->filename2open)
122 #define c (x->c)
123 #define _64bits (x->_64bits)
124 char *s;
126 #ifdef ISOHOOK
127 extern int _cpuhaslm();
128 _64bits = _cpuhaslm();
129 #else
130 _64bits = cpuhaslm();
131 #endif
132 do {
133 #ifdef ISOHOOK
134 s = (char *) x->filename2open;
135 if (*s == '/') {
136 s++;
137 isoroot();
138 }
139 name = s;
140 while (*++s);
141 #else
142 for (s = (char *) x->filename2open; *s == '/' ; s++) {
143 isoroot();
144 }
145 next:
146 name = s;
147 do s++; while (*s && *s != '/');
148 c = *s; *s = 0;
149 #endif
150 for (x->curdirsize = 0xFFFF; isoreaddir() != -1;) {
151 const char *n = name;
152 #define i (x->tmp)
153 i = x->filename;
154 if (_64bits) {
155 if (strhead(i, n) == -1) continue;
156 n = "64";
157 i += s - name; // strlen(name);
158 }
159 if (strcmp(i, n)) continue;
160 #ifndef ISOHOOK
161 *s++ = c;
162 #endif
163 if (IS_DIR(x->filemod)) {
164 cpydirofs(x->dirofs, x->fileofs);
165 x->dirsize = filesize2dirsize(x->filesize);
166 #ifndef ISOHOOK
167 if (c) goto next;
168 #endif
169 }
170 isolseek(&x->fileofs);
171 return 0;
172 }
173 } while ((_64bits ^= CPUMASKLM) == 0);
174 return -1;
175 }