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

linld: _fastcall calls
author Pascal Bellard <pascal.bellard@slitaz.org>
date Wed Nov 28 19:46:10 2018 +0100 (2018-11-28)
parents af959ebf1305
children 16d1d23aefee
line source
1 #include "crtl.h"
2 #include "crtlx.h"
3 #include "iso9660.h"
4 #define __ROCKRIDGE
6 struct isostate isostate;
8 int isoreset(char *name)
9 {
10 static const unsigned long root = 16UL * 2048;
11 struct isostate *x=&isostate;
12 if (name) {
13 //x->fd = open(name, O_RDONLY);
14 x->fd = open(name);
15 }
16 if (isoreadsector(&root) < 0 || strhead(x->buffer+1,"CD001")) {
17 //close(x->fd);
18 return -1;
19 }
20 x->dirofs = (* (unsigned long *) (x->buffer + 0x9E)) << SECTORBITS;
21 x->dirsize = filesize2dirsize(* (unsigned long *) (x->buffer + 0xA6));
22 return 0;
23 }
25 int isoreaddir(int restart)
26 {
27 int size;
28 char *p;
29 #ifdef __ROCKRIDGE
30 char *endname;
31 #endif
32 struct isostate *x=&isostate;
34 if (restart) {
35 x->curdirsize = x->dirsize;
36 x->curdirofs = x->dirofs;
37 goto restarted;
38 }
39 if (x->curpos >= SECTORSZ || * (short *) (x->buffer + x->curpos) == 0) {
40 restarted:
41 if (x->curdirsize < DIRSECTORSZ) return -1;
42 isoreadsector(&x->curdirofs);
43 //x->curdirofs += SECTORSZ;
44 *(int *)((char *) &x->curdirofs+1) += SECTORSZ/256;
45 x->curdirsize -= DIRSECTORSZ;
46 x->curpos = 0;
47 }
48 p = x->buffer; p += x->curpos;
49 if ((size = * (short *) p) == 0) {
50 return -1;
51 }
52 x->fileofs = (* (unsigned long *) (p + 2)) << SECTORBITS;
53 x->filesize = * (unsigned long *) (p + 10);
54 x->filemod = (p[25] & 2) ? 0040755 : 0100755;
55 //x->filemod = 0100755 - ((p[25] & (char)2) << 13);
56 #ifdef __ROCKRIDGE
57 endname = NULL;
58 // p += 34 + (p[32] & -2); ?
59 p = x->buffer + 34 + ((p[32] + x->curpos) & -2);
60 do {
61 int len = p[2];
62 switch (* (short *) p) {
63 case 0x4D4E: // NM
64 x->filename = p + 5;
65 endname = p + len;
66 break;
67 case 0x5850: // PX
68 x->filemod = * (short *) (p + 4);
69 break;
70 }
71 p += len;
72 } while (x->buffer + x->curpos + size - p > 2);
73 if (endname)
74 *endname = 0;
75 else
76 #endif
77 {
78 p = x->buffer + 33; x->filename = p += x->curpos;
79 p--;
80 if (((* (short *) p) & 0xFEFF) -1 == 0) {
81 x->filename = "..";
82 if ((* (short *) p) == 1)
83 x->filename++;
84 }
85 else {
86 p += *p; p--;
87 if (* (short *) (p) != 0x313B) {
88 p++; p++; // no ;1 to remove
89 }
90 if (p[-1] == '.') p--;
91 *p = 0;
92 }
93 }
94 x->curpos += size;
95 return 0;
96 }
98 //#define IS_DIR(x)( ((x) & ~0777) == 040000)
99 //#define IS_DIR(x)( (char)((x) >> 9) == (char)040)
100 //#define IS_DIR(x)( (*((char*) &x + 1) & (char)0776) == (char)0100)
101 #define IS_DIR(x)( (*((char*) &x + 1) & (char)0676) == (char)0)
102 int isoopen(const char *filename)
103 {
104 int restart;
105 char *name, *s, c;
106 char _64bits = cpuhaslm();
107 struct isostate *x=&isostate;
109 do {
110 for (s = (char *) filename; *s == '/' ; s++) {
111 isoreset(NULL);
112 }
113 next:
114 for (name = s; *s && *s != '/'; s++);
115 c = *s;
116 *s = 0;
117 for (restart = 1; isoreaddir(restart) == 0; restart = 0) {
118 const char *n = name, *i = x->filename;
119 if (_64bits) {
120 if (strhead(i, n)) continue;
121 n = "64";
122 i += s - name; // strlen(name);
123 }
124 if (strcmp(i, n)) continue;
125 *s++ = c;
126 if (IS_DIR(x->filemod)) {
127 x->dirofs = x->fileofs;
128 x->dirsize = filesize2dirsize(x->filesize);
129 if (c) goto next;
130 }
131 isolseek(&x->fileofs);
132 return 0;
133 }
134 } while ((_64bits ^= CPUMASKLM) == 0);
135 return -1;
136 }