rev |
line source |
pascal@19515
|
1 #include "crtl.h"
|
pascal@19515
|
2 #include "crtlx.h"
|
pascal@19515
|
3 #include "iso9660.h"
|
pascal@19515
|
4 #define __ROCKRIDGE
|
pascal@19515
|
5
|
pascal@20747
|
6 #if 1
|
pascal@20747
|
7 #define setdirofs(to,sec) (*(int*)((char*)&(to)+1) = *(int*)&(sec)<<(SECTORBITS-8))
|
pascal@20747
|
8 #define cpydirofs(to,from) (*(int*)((char*)&(to)+1) = *(int*)((char*)&(from)+1))
|
pascal@20747
|
9 #else
|
pascal@20747
|
10 #define setdirofs(to,sec) (to = (sec)<<SECTORBITS)
|
pascal@20747
|
11 #define cpydirofs(to,from) ((to) = (from))
|
pascal@20747
|
12 #endif
|
pascal@20747
|
13
|
pascal@21628
|
14 int isoroot(void)
|
pascal@19515
|
15 {
|
pascal@19825
|
16 static const unsigned long root = 16UL * 2048;
|
pascal@19571
|
17 struct isostate *x=&isostate;
|
pascal@21628
|
18 if (isoreadsector(&root) == -1 || strhead(x->buffer+1,"CD001") == -1) {
|
pascal@19571
|
19 //close(x->fd);
|
pascal@19515
|
20 return -1;
|
pascal@19515
|
21 }
|
pascal@20747
|
22 setdirofs(x->dirofs, (* (unsigned long *) (isostate.buffer + 0x9E)));
|
pascal@20632
|
23 x->dirsize = filesize2dirsize(* (unsigned long *) (isostate.buffer + 0xA6));
|
pascal@19515
|
24 return 0;
|
pascal@19515
|
25 }
|
pascal@19515
|
26
|
pascal@20747
|
27 int isoreaddir(void)
|
pascal@19515
|
28 {
|
pascal@19636
|
29 char *p;
|
pascal@19515
|
30 #ifdef __ROCKRIDGE
|
pascal@19515
|
31 char *endname;
|
pascal@19515
|
32 #endif
|
pascal@19571
|
33 struct isostate *x=&isostate;
|
pascal@19515
|
34
|
pascal@20747
|
35 if (x->curdirsize == 0xFFFF) {
|
pascal@19826
|
36 x->curdirsize = x->dirsize;
|
pascal@20747
|
37 cpydirofs(x->curdirofs, x->dirofs);
|
pascal@19826
|
38 goto restarted;
|
pascal@19515
|
39 }
|
pascal@20534
|
40 if (x->curpos >= SECTORSZ || * (short *) (x->buffer + x->curpos) == 0) {
|
pascal@20538
|
41 restarted:
|
pascal@19826
|
42 if (x->curdirsize < DIRSECTORSZ) return -1;
|
pascal@20534
|
43 isoreadsector(&x->curdirofs);
|
pascal@20453
|
44 //x->curdirofs += SECTORSZ;
|
pascal@20453
|
45 *(int *)((char *) &x->curdirofs+1) += SECTORSZ/256;
|
pascal@19826
|
46 x->curdirsize -= DIRSECTORSZ;
|
pascal@20458
|
47 x->curpos = 0;
|
pascal@19515
|
48 }
|
pascal@20534
|
49 p = x->buffer; p += x->curpos;
|
pascal@21735
|
50 if ((x->entrysize = * (short *) p) == 0) {
|
pascal@19515
|
51 return -1;
|
pascal@20538
|
52 }
|
pascal@19636
|
53 x->fileofs = (* (unsigned long *) (p + 2)) << SECTORBITS;
|
pascal@19636
|
54 x->filesize = * (unsigned long *) (p + 10);
|
pascal@20543
|
55 x->filemod = 0x81ED; if (p[25] & 2) ((char *)&(x->filemod))[1] = 0x41;
|
pascal@20543
|
56 //x->filemod = (p[25] & 2) ? 0040755 : 0100755;
|
pascal@20453
|
57 //x->filemod = 0100755 - ((p[25] & (char)2) << 13);
|
pascal@19515
|
58 #ifdef __ROCKRIDGE
|
pascal@19515
|
59 endname = NULL;
|
pascal@19636
|
60 // p += 34 + (p[32] & -2); ?
|
pascal@20534
|
61 p = x->buffer + 34 + ((p[32] + x->curpos) & -2);
|
pascal@19515
|
62 do {
|
pascal@19636
|
63 int len = p[2];
|
pascal@20751
|
64 # if 0
|
pascal@19636
|
65 switch (* (short *) p) {
|
pascal@19515
|
66 case 0x5850: // PX
|
pascal@19636
|
67 x->filemod = * (short *) (p + 4);
|
pascal@19515
|
68 break;
|
pascal@20751
|
69 case 0x4D4E: // NM
|
pascal@20751
|
70 # else
|
pascal@20751
|
71 if (* (short *) p == 0x4D4E) {
|
pascal@20751
|
72 # endif
|
pascal@20751
|
73 x->filename = p + 5;
|
pascal@20751
|
74 endname = p + len;
|
pascal@19515
|
75 }
|
pascal@19636
|
76 p += len;
|
pascal@21735
|
77 } while (x->buffer + x->curpos + x->entrysize - 2 > p);
|
pascal@19515
|
78 if (endname)
|
pascal@19515
|
79 *endname = 0;
|
pascal@19515
|
80 else
|
pascal@19515
|
81 #endif
|
pascal@19515
|
82 {
|
pascal@20534
|
83 p = x->buffer + 33; x->filename = p += x->curpos;
|
pascal@19636
|
84 p--;
|
pascal@20453
|
85 if (((* (short *) p) & 0xFEFF) -1 == 0) {
|
pascal@20453
|
86 x->filename = "..";
|
pascal@22632
|
87 if (--(* (short *) p) == 0)
|
pascal@20453
|
88 x->filename++;
|
pascal@20453
|
89 }
|
pascal@20453
|
90 else {
|
pascal@19636
|
91 p += *p; p--;
|
pascal@19636
|
92 if (* (short *) (p) != 0x313B) {
|
pascal@19636
|
93 p++; p++; // no ;1 to remove
|
pascal@19636
|
94 }
|
pascal@19636
|
95 if (p[-1] == '.') p--;
|
pascal@19636
|
96 *p = 0;
|
pascal@19515
|
97 }
|
pascal@19515
|
98 }
|
pascal@21735
|
99 x->curpos += x->entrysize;
|
pascal@19515
|
100 return 0;
|
pascal@19515
|
101 }
|
pascal@19515
|
102
|
pascal@19825
|
103 //#define IS_DIR(x)( ((x) & ~0777) == 040000)
|
pascal@20454
|
104 //#define IS_DIR(x)( (char)((x) >> 9) == (char)040)
|
pascal@20454
|
105 //#define IS_DIR(x)( (*((char*) &x + 1) & (char)0776) == (char)0100)
|
pascal@20454
|
106 #define IS_DIR(x)( (*((char*) &x + 1) & (char)0676) == (char)0)
|
pascal@21628
|
107 int _isoopen(void)
|
pascal@19515
|
108 {
|
pascal@21735
|
109 // char *name, *s, c;
|
pascal@21735
|
110 // char _64bits = cpuhaslm();
|
pascal@19571
|
111 struct isostate *x=&isostate;
|
pascal@21735
|
112 #define name (x->filename2open)
|
pascal@21754
|
113 #define c (x->c)
|
pascal@21754
|
114 #define _64bits (x->_64bits)
|
pascal@21735
|
115 char *s;
|
pascal@19515
|
116
|
pascal@21735
|
117 _64bits = cpuhaslm();
|
pascal@20528
|
118 do {
|
pascal@21628
|
119 for (s = (char *) x->filename2open; *s == '/' ; s++) {
|
pascal@21628
|
120 isoroot();
|
pascal@19515
|
121 }
|
pascal@19825
|
122 next:
|
pascal@20751
|
123 name = s;
|
pascal@21754
|
124 do s++; while (*s && *s != '/');
|
pascal@21750
|
125 c = *s; *s = 0;
|
pascal@21576
|
126 for (x->curdirsize = 0xFFFF; isoreaddir() != -1;) {
|
pascal@21735
|
127 const char *n = name;
|
pascal@21735
|
128 #define i (x->tmp)
|
pascal@21735
|
129 i = x->filename;
|
pascal@19825
|
130 if (_64bits) {
|
pascal@21628
|
131 if (strhead(i, n) == -1) continue;
|
pascal@19825
|
132 n = "64";
|
pascal@19825
|
133 i += s - name; // strlen(name);
|
pascal@19515
|
134 }
|
pascal@19825
|
135 if (strcmp(i, n)) continue;
|
pascal@19825
|
136 *s++ = c;
|
pascal@19825
|
137 if (IS_DIR(x->filemod)) {
|
pascal@20747
|
138 cpydirofs(x->dirofs, x->fileofs);
|
pascal@19826
|
139 x->dirsize = filesize2dirsize(x->filesize);
|
pascal@19825
|
140 if (c) goto next;
|
pascal@19515
|
141 }
|
pascal@19825
|
142 isolseek(&x->fileofs);
|
pascal@19825
|
143 return 0;
|
pascal@19515
|
144 }
|
pascal@20528
|
145 } while ((_64bits ^= CPUMASKLM) == 0);
|
pascal@19825
|
146 return -1;
|
pascal@19515
|
147 }
|