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

Openssh (8.5p1)
author Pascal Bellard <pascal.bellard@slitaz.org>
date Thu Apr 08 09:21:26 2021 +0000 (2021-04-08)
parents 217c02cbbe8d
children
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 *) (buf2k + 0x9E))); \
15 x->dirsize = filesize2dirsize(* (unsigned long *) (buf2k + 0xA6)); \
16 }
18 #if !defined(BASIC_ISO9660) && defined(CLEAN_ISO9660)
19 #define BASIC_ISO9660
20 #endif
21 #if !defined(BASIC_ISO9660) && !defined(ROCKRIDGE)
22 #define BASIC_ISO9660
23 #endif
24 static int isoreaddir(void)
25 {
26 char *p;
28 struct isostate *x=&isostate;
30 p = buf2k;
31 if (x->curpos >= SECTORSZ || * (short *) (p + x->curpos) == 0) {
32 x->curpos = 0;
33 if ((x->curdirsize =- DIRSECTORSZ) < 0) return -1;
34 isoreadsector(&x->curdirofs); // x->filepos = 0
35 //x->curdirofs += SECTORSZ;
36 *(int *)((char *) &x->curdirofs+1) += SECTORSZ/256;
37 }
38 p += x->curpos;
39 x->fileofs = (* (unsigned long *) (p + 2)) << SECTORBITS;
40 if ((x->entrysize = * (short *) p) == 0) {
41 return -1;
42 }
43 #ifdef CHECKISOFILETYPE
44 x->c = p[25];
45 #endif
46 register char *s;
47 x->filesize = * (unsigned long *) (p + 10);
48 s = ".."+1-p[33];
49 #ifdef ROCKRIDGE
50 p = buf2k + 34 + ((p[32] + x->curpos) & -2);
51 x->curpos += x->entrysize;
52 do {
53 register len = p[2];
54 if (* (short *) p == 0x4D4E) {
55 s = p + 5;
56 p[len] = 0;
57 goto found;
58 }
59 p += len;
60 } while (buf2k - 3 + x->curpos >= p);
61 #endif
62 #ifdef BASIC_ISO9660
63 # ifdef ROCKRIDGE
64 p = buf2k + 32 + x->curpos - x->entrysize;
65 # else
66 x->curpos += x->entrysize;
67 p += 32;
68 # endif
69 if (((* (short *) p) & 0xFEFF) -1 != 0) {
70 s = p + 1; p += *p;
71 # ifdef CLEAN_ISO9660
72 if (* (short *) (p-1) == 0x313B) p-=2; // remove ;1
73 if (*p != '.') p++;
74 # endif
75 *p = 0;
76 }
77 #endif
78 found:
79 x->filename = s;
80 return 0;
81 }
83 #define isoreaddir_reset() \
84 { \
85 x->curdirsize = x->dirsize; \
86 cpyfromdirpage(x->curdirofs, x->dirpage); \
87 x->curpos = -1; \
88 }
90 int _isoopen(void)
91 {
92 // char *name, *s, c;
93 // char _64bits = cpuhaslm();
94 struct isostate *x=&isostate;
95 #define name (x->filename2open)
96 #define c (x->c)
97 #define _64bits (x->_64bits)
98 char *s;
100 s = (char *) x->filename2open;
101 if (*s == '/') {
102 isoroot();
103 //if (strncmp(buf2k+1,"CD001",5) == -1) return -1;
104 //if (*(int*)(buf2k+1) != 0x4443) return -1;
105 next:
106 s++;
107 }
108 name = s;
109 do s++; while (*s && *s != '/');
110 c = *s; *s = 0;
111 #ifdef ISOHOOK
112 _64bits = cpuhaslm();
113 _32bits:
114 #endif
115 isoreaddir_reset();
116 do {
117 if (isoreaddir() == -1) {
118 #ifdef ISOHOOK
119 if ((_64bits ^= CPUMASKLM) == 0) goto _32bits;
120 #endif
121 return -1;
122 }
123 const char *n = name;
124 #define i (x->tmp)
125 i = x->filename;
126 #ifdef ISOHOOK
127 if (_64bits) {
128 if (strhead(i, n) == -1) continue;
129 n = "64";
130 i += s - name; // strlen(name);
131 }
132 #endif
133 if (strcmp(i, n) != -1) break;
134 } while (1);
135 *s = c;
136 if (c) {
137 #ifdef CHECKISOFILETYPE
138 if ((x->c & 2) == 0) return -1;
139 #endif
140 cpytodirpage(x->dirpage, x->fileofs);
141 x->dirsize = filesize2dirsize(x->filesize);
142 goto next;
143 }
144 isolseek(&x->fileofs);
145 return x->fd;
146 }
147 #endif