wok view linld/stuff/src/ISO9660.CPP @ rev 23867
syslinux/bootiso.S: merge isolinux boot sector
author | Pascal Bellard <pascal.bellard@slitaz.org> |
---|---|
date | Sat Jun 20 14:15:09 2020 +0000 (2020-06-20) |
parents | c04335df099f |
children | 26195667e7c9 |
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 #ifdef ISOHOOK
88 *endname = 0;
89 #else
90 if (endname)
91 *endname = 0;
92 else
93 #endif
94 #endif
95 #ifndef ISOHOOK
96 {
97 p = x->buffer + 33; x->filename = p += x->curpos;
98 p--;
99 if (((* (short *) p) & 0xFEFF) -1 == 0) {
100 x->filename = "..";
101 if (--(* (short *) p) == 0)
102 x->filename++;
103 }
104 else {
105 p += *p; p--;
106 if (* (short *) (p) != 0x313B) {
107 p++; p++; // no ;1 to remove
108 }
109 if (p[-1] == '.') p--;
110 *p = 0;
111 }
112 }
113 #endif
114 x->curpos += x->entrysize;
115 return 0;
116 }
118 //#define IS_DIR(x)( ((x) & ~0777) == 040000)
119 //#define IS_DIR(x)( (char)((x) >> 9) == (char)040)
120 //#define IS_DIR(x)( (*((char*) &x + 1) & (char)0776) == (char)0100)
121 #define IS_DIR(x)( (*((char*) &x + 1) & (char)0676) == (char)0)
122 int _isoopen(void)
123 {
124 // char *name, *s, c;
125 // char _64bits = cpuhaslm();
126 struct isostate *x=&isostate;
127 #define name (x->filename2open)
128 #define c (x->c)
129 #define _64bits (x->_64bits)
130 char *s;
132 #ifdef ISOHOOK
133 extern int _cpuhaslm();
134 _64bits = _cpuhaslm();
135 #else
136 _64bits = cpuhaslm();
137 #endif
138 do {
139 #ifdef ISOHOOK
140 s = (char *) x->filename2open;
141 if (*s == '/') {
142 s++;
143 isoroot();
144 }
145 name = s;
146 while (*++s);
147 #else
148 for (s = (char *) x->filename2open; *s == '/' ; s++) {
149 isoroot();
150 }
151 next:
152 name = s;
153 do s++; while (*s && *s != '/');
154 c = *s; *s = 0;
155 #endif
156 for (x->curdirsize = 0xFFFF; isoreaddir() != -1;) {
157 const char *n = name;
158 #define i (x->tmp)
159 i = x->filename;
160 if (_64bits) {
161 if (strhead(i, n) == -1) continue;
162 n = "64";
163 i += s - name; // strlen(name);
164 }
165 if (strcmp(i, n)) continue;
166 #ifndef ISOHOOK
167 *s++ = c;
168 #endif
169 if (IS_DIR(x->filemod)) {
170 cpydirofs(x->dirofs, x->fileofs);
171 x->dirsize = filesize2dirsize(x->filesize);
172 #ifndef ISOHOOK
173 if (c) goto next;
174 #endif
175 }
176 isolseek(&x->fileofs);
177 return 0;
178 }
179 } while ((_64bits ^= CPUMASKLM) == 0);
180 return -1;
181 }