wok view linld/stuff/src/ISO9660.CPP @ rev 24019
syslinux: fix build
author | Pascal Bellard <pascal.bellard@slitaz.org> |
---|---|
date | Sun Feb 28 16:32:57 2021 +0000 (2021-02-28) |
parents | 5c1ce90eb1d6 |
children | 42b4b9d947f3 |
line source
1 #include "crtl.h"
2 #include "common.h"
3 #include "iso9660.h"
5 #ifdef ISO9660
6 #define setdirpage(to,sec) ((to) = *(int*)&(sec)<<(SECTORBITS-8))
7 #define cpytodirpage(to,from) ((to) = *(int*)((char*)&(from)+1))
8 #define cpyfromdirpage(to,from) (*(int*)((char*)&(to)+1) = (from))
10 #define isoroot() \
11 { \
12 extern void isoreadrootsector(void); \
13 isoreadrootsector(); \
14 setdirpage(x->dirpage, (* (unsigned long *) (isostate.buffer + 0x9E))); \
15 x->dirsize = filesize2dirsize(* (unsigned long *) (isostate.buffer + 0xA6)); \
16 }
18 #if !defined(BASIC_ISO9660) && !defined(ROCKRIDGE)
19 #define ROCKRIDGE
20 #endif
21 static int isoreaddir(void)
22 {
23 char *p;
25 struct isostate *x=&isostate;
27 p = x->buffer;
28 if (x->curpos >= SECTORSZ || * (short *) (p + x->curpos) == 0) {
29 if ((x->curdirsize =- DIRSECTORSZ) < 0) return -1;
30 isoreadsector(&x->curdirofs); // x->filepos = 0
31 //x->curdirofs += SECTORSZ;
32 *(int *)((char *) &x->curdirofs+1) += SECTORSZ/256;
33 x->curpos = 0;
34 }
35 p += x->curpos;
36 x->fileofs = (* (unsigned long *) (p + 2)) << SECTORBITS;
37 if ((x->entrysize = * (short *) p) == 0) {
38 return -1;
39 }
40 // x->filename = "";
41 x->filesize = * (unsigned long *) (p + 10);
42 x->filemod = 0x81ED; if (p[25] & 2) ((char *)&(x->filemod))[1] = 0x41;
43 p = x->buffer + 34 + ((p[32] + x->curpos) & -2);
44 x->curpos += x->entrysize;
45 #ifdef ROCKRIDGE
46 do {
47 register len = p[2];
48 if (* (short *) p == 0x4D4E) {
49 x->filename = p + 5;
50 p[len] = 0;
51 goto found;
52 }
53 p += len;
54 } while (x->buffer + x->curpos - 3 >= p);
55 #endif
56 #ifdef BASIC_ISO9660
57 char *s;
58 p = x->buffer + 33; p += x->curpos;
59 s = ".."+1-p[0];
60 p--;
61 if (((* (short *) p) & 0xFEFF) -1 != 0) {
62 s = p + 1; p += *p;
63 if (* (short *) (p-1) != 0x313B) p+=2; // no ;1 to remove
64 if (*p != '.') p++;
65 *p = 0;
66 }
67 x->filename = s;
68 #endif
69 found:
70 return 0;
71 }
73 #define isoreaddir_reset() \
74 { \
75 x->curdirsize = x->dirsize; \
76 cpyfromdirpage(x->curdirofs, x->dirpage); \
77 x->curpos = -1; \
78 }
80 int _isoopen(void)
81 {
82 // char *name, *s, c;
83 // char _64bits = cpuhaslm();
84 struct isostate *x=&isostate;
85 #define name (x->filename2open)
86 #define c (x->c)
87 #define _64bits (x->_64bits)
88 char *s;
90 #ifdef ISOHOOK
91 _64bits = cpuhaslm();
92 _32bits:
93 #endif
94 s = (char *) x->filename2open;
95 if (*s == '/') {
96 s++;
97 isoroot();
98 //if (strncmp(x->buffer+1,"CD001,5) == -1) return -1;
99 //if (*(int*)(x->buffer+1) != 0x4443) return -1;
100 }
101 next:
102 isoreaddir_reset();
103 name = s;
104 do s++; while (*s && *s != '/');
105 c = *s; *s = 0;
106 do {
107 if (isoreaddir() == -1) {
108 #ifdef ISOHOOK
109 if ((_64bits ^= CPUMASKLM) == 0) goto _32bits;
110 #endif
111 return -1;
112 }
113 const char *n = name;
114 #define i (x->tmp)
115 i = x->filename;
116 #ifdef ISOHOOK
117 if (_64bits) {
118 if (strhead(i, n) == -1) continue;
119 n = "64";
120 i += s - name; // strlen(name);
121 }
122 #endif
123 if (strcmp(i, n) != -1) break;
124 } while (1);
125 *s++ = c;
126 #define IS_DIR(x)( (*((char*) &x + 1) & (char)0676) == (char)0)
127 if (IS_DIR(x->filemod)) {
128 cpytodirpage(x->dirpage, x->fileofs);
129 x->dirsize = filesize2dirsize(x->filesize);
130 if (c) goto next;
131 }
132 isolseek(&x->fileofs);
133 return x->fd;
134 }
135 #endif