wok view linld/stuff/src/ISO9660.CPP @ rev 23423
updated pgbadger (10.3 -> 11.2)
author | Hans-G?nter Theisgen |
---|---|
date | Wed Apr 01 08:15:38 2020 +0100 (2020-04-01) |
parents | 8b9f768b711e |
children | d70f7cc6e3ac |
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 int isoroot(void)
15 {
16 static const unsigned long root = 16UL * 2048;
17 struct isostate *x=&isostate;
18 if (isoreadsector(&root) == -1 || strhead(x->buffer+1,"CD001") == -1) {
19 //close(x->fd);
20 return -1;
21 }
22 setdirofs(x->dirofs, (* (unsigned long *) (isostate.buffer + 0x9E)));
23 x->dirsize = filesize2dirsize(* (unsigned long *) (isostate.buffer + 0xA6));
24 return 0;
25 }
27 int isoreaddir(void)
28 {
29 char *p;
30 #ifdef __ROCKRIDGE
31 char *endname;
32 #endif
33 struct isostate *x=&isostate;
35 if (x->curdirsize == 0xFFFF) {
36 x->curdirsize = x->dirsize;
37 cpydirofs(x->curdirofs, x->dirofs);
38 goto restarted;
39 }
40 if (x->curpos >= SECTORSZ || * (short *) (x->buffer + x->curpos) == 0) {
41 restarted:
42 if (x->curdirsize < DIRSECTORSZ) return -1;
43 isoreadsector(&x->curdirofs);
44 //x->curdirofs += SECTORSZ;
45 *(int *)((char *) &x->curdirofs+1) += SECTORSZ/256;
46 x->curdirsize -= DIRSECTORSZ;
47 x->curpos = 0;
48 }
49 p = x->buffer; p += x->curpos;
50 if ((x->entrysize = * (short *) p) == 0) {
51 return -1;
52 }
53 x->fileofs = (* (unsigned long *) (p + 2)) << SECTORBITS;
54 x->filesize = * (unsigned long *) (p + 10);
55 x->filemod = 0x81ED; if (p[25] & 2) ((char *)&(x->filemod))[1] = 0x41;
56 //x->filemod = (p[25] & 2) ? 0040755 : 0100755;
57 //x->filemod = 0100755 - ((p[25] & (char)2) << 13);
58 #ifdef __ROCKRIDGE
59 endname = NULL;
60 // p += 34 + (p[32] & -2); ?
61 p = x->buffer + 34 + ((p[32] + x->curpos) & -2);
62 do {
63 int len = p[2];
64 # if 0
65 switch (* (short *) p) {
66 case 0x5850: // PX
67 x->filemod = * (short *) (p + 4);
68 break;
69 case 0x4D4E: // NM
70 # else
71 if (* (short *) p == 0x4D4E) {
72 # endif
73 x->filename = p + 5;
74 endname = p + len;
75 }
76 p += len;
77 } while (x->buffer + x->curpos + x->entrysize - 2 > p);
78 if (endname)
79 *endname = 0;
80 else
81 #endif
82 {
83 p = x->buffer + 33; x->filename = p += x->curpos;
84 p--;
85 if (((* (short *) p) & 0xFEFF) -1 == 0) {
86 x->filename = "..";
87 if (--(* (short *) p) == 0)
88 x->filename++;
89 }
90 else {
91 p += *p; p--;
92 if (* (short *) (p) != 0x313B) {
93 p++; p++; // no ;1 to remove
94 }
95 if (p[-1] == '.') p--;
96 *p = 0;
97 }
98 }
99 x->curpos += x->entrysize;
100 return 0;
101 }
103 //#define IS_DIR(x)( ((x) & ~0777) == 040000)
104 //#define IS_DIR(x)( (char)((x) >> 9) == (char)040)
105 //#define IS_DIR(x)( (*((char*) &x + 1) & (char)0776) == (char)0100)
106 #define IS_DIR(x)( (*((char*) &x + 1) & (char)0676) == (char)0)
107 int _isoopen(void)
108 {
109 // char *name, *s, c;
110 // char _64bits = cpuhaslm();
111 struct isostate *x=&isostate;
112 #define name (x->filename2open)
113 #define c (x->c)
114 #define _64bits (x->_64bits)
115 char *s;
117 _64bits = cpuhaslm();
118 do {
119 for (s = (char *) x->filename2open; *s == '/' ; s++) {
120 isoroot();
121 }
122 next:
123 name = s;
124 do s++; while (*s && *s != '/');
125 c = *s; *s = 0;
126 for (x->curdirsize = 0xFFFF; isoreaddir() != -1;) {
127 const char *n = name;
128 #define i (x->tmp)
129 i = x->filename;
130 if (_64bits) {
131 if (strhead(i, n) == -1) continue;
132 n = "64";
133 i += s - name; // strlen(name);
134 }
135 if (strcmp(i, n)) continue;
136 *s++ = c;
137 if (IS_DIR(x->filemod)) {
138 cpydirofs(x->dirofs, x->fileofs);
139 x->dirsize = filesize2dirsize(x->filesize);
140 if (c) goto next;
141 }
142 isolseek(&x->fileofs);
143 return 0;
144 }
145 } while ((_64bits ^= CPUMASKLM) == 0);
146 return -1;
147 }