wok-current view linld/stuff/src/ISO9660.CPP @ rev 24020

linld: fix iso9660/64
author Pascal Bellard <pascal.bellard@slitaz.org>
date Sat Mar 06 18:15:05 2021 +0000 (2021-03-06)
parents 61df94a0fa43
children 217c02cbbe8d
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 BASIC_ISO9660
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->filemod = 0x81ED; if (p[25] & 2) ((char *)&(x->filemod))[1] = 0x41;
41 register char *s;
42 x->filesize = * (unsigned long *) (p + 10);
43 s = ".."+1-p[33];
44 #ifdef ROCKRIDGE
45 p = x->buffer + 34 + ((p[32] + x->curpos) & -2);
46 x->curpos += x->entrysize;
47 do {
48 register len = p[2];
49 if (* (short *) p == 0x4D4E) {
50 s = p + 5;
51 p[len] = 0;
52 goto found;
53 }
54 p += len;
55 } while (x->buffer + x->curpos - 3 >= p);
56 #endif
57 #ifdef BASIC_ISO9660
58 # ifdef ROCKRIDGE
59 p = x->buffer + 32 + x->curpos - x->entrysize;
60 # else
61 x->curpos += x->entrysize;
62 p += 32;
63 # endif
64 if (((* (short *) p) & 0xFEFF) -1 != 0) {
65 s = p + 1; p += *p;
66 if (* (short *) (p-1) != 0x313B) p+=2; // no ;1 to remove
67 if (*p != '.') p++;
68 *p = 0;
69 }
70 #endif
71 found:
72 x->filename = s;
73 return 0;
74 }
76 #define isoreaddir_reset() \
77 { \
78 x->curdirsize = x->dirsize; \
79 cpyfromdirpage(x->curdirofs, x->dirpage); \
80 x->curpos = -1; \
81 }
83 int _isoopen(void)
84 {
85 // char *name, *s, c;
86 // char _64bits = cpuhaslm();
87 struct isostate *x=&isostate;
88 #define name (x->filename2open)
89 #define c (x->c)
90 #define _64bits (x->_64bits)
91 char *s;
93 s = (char *) x->filename2open;
94 if (*s == '/') {
95 s++;
96 isoroot();
97 //if (strncmp(x->buffer+1,"CD001,5) == -1) return -1;
98 //if (*(int*)(x->buffer+1) != 0x4443) return -1;
99 }
100 next:
101 name = s;
102 do s++; while (*s && *s != '/');
103 c = *s; *s = 0;
104 #ifdef ISOHOOK
105 _64bits = cpuhaslm();
106 _32bits:
107 #endif
108 isoreaddir_reset();
109 do {
110 if (isoreaddir() == -1) {
111 #ifdef ISOHOOK
112 if ((_64bits ^= CPUMASKLM) == 0) goto _32bits;
113 #endif
114 return -1;
115 }
116 const char *n = name;
117 #define i (x->tmp)
118 i = x->filename;
119 #ifdef ISOHOOK
120 if (_64bits) {
121 if (strhead(i, n) == -1) continue;
122 n = "64";
123 i += s - name; // strlen(name);
124 }
125 #endif
126 if (strcmp(i, n) != -1) break;
127 } while (1);
128 *s++ = c;
129 #define IS_DIR(x)( (*((char*) &x + 1) & (char)0676) == (char)0)
130 if (IS_DIR(x->filemod)) {
131 cpytodirpage(x->dirpage, x->fileofs);
132 x->dirsize = filesize2dirsize(x->filesize);
133 if (c) goto next;
134 }
135 isolseek(&x->fileofs);
136 return x->fd;
137 }
138 #endif