wok-6.x view linld/stuff/src/ISO9660.CPP @ rev 20745
azpainter: update WGET_URL
author | Pascal Bellard <pascal.bellard@slitaz.org> |
---|---|
date | Sun Feb 10 10:35:42 2019 +0100 (2019-02-10) |
parents | 16d1d23aefee |
children | 6f2188ee6be5 |
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 *) (isostate.buffer + 0x9E)) << SECTORBITS;
21 x->dirsize = filesize2dirsize(* (unsigned long *) (isostate.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 = 0x81ED; if (p[25] & 2) ((char *)&(x->filemod))[1] = 0x41;
55 //x->filemod = (p[25] & 2) ? 0040755 : 0100755;
56 //x->filemod = 0100755 - ((p[25] & (char)2) << 13);
57 #ifdef __ROCKRIDGE
58 endname = NULL;
59 // p += 34 + (p[32] & -2); ?
60 p = x->buffer + 34 + ((p[32] + x->curpos) & -2);
61 do {
62 int len = p[2];
63 switch (* (short *) p) {
64 case 0x4D4E: // NM
65 x->filename = p + 5;
66 endname = p + len;
67 break;
68 case 0x5850: // PX
69 x->filemod = * (short *) (p + 4);
70 break;
71 }
72 p += len;
73 } while (x->buffer + x->curpos + size - p > 2);
74 if (endname)
75 *endname = 0;
76 else
77 #endif
78 {
79 p = x->buffer + 33; x->filename = p += x->curpos;
80 p--;
81 if (((* (short *) p) & 0xFEFF) -1 == 0) {
82 x->filename = "..";
83 if ((* (short *) p) == 1)
84 x->filename++;
85 }
86 else {
87 p += *p; p--;
88 if (* (short *) (p) != 0x313B) {
89 p++; p++; // no ;1 to remove
90 }
91 if (p[-1] == '.') p--;
92 *p = 0;
93 }
94 }
95 x->curpos += size;
96 return 0;
97 }
99 //#define IS_DIR(x)( ((x) & ~0777) == 040000)
100 //#define IS_DIR(x)( (char)((x) >> 9) == (char)040)
101 //#define IS_DIR(x)( (*((char*) &x + 1) & (char)0776) == (char)0100)
102 #define IS_DIR(x)( (*((char*) &x + 1) & (char)0676) == (char)0)
103 int isoopen(const char *filename)
104 {
105 int restart;
106 char *name, *s, c;
107 char _64bits = cpuhaslm();
108 struct isostate *x=&isostate;
110 do {
111 for (s = (char *) filename; *s == '/' ; s++) {
112 isoreset(NULL);
113 }
114 next:
115 for (name = s; *s && *s != '/'; s++);
116 c = *s;
117 *s = 0;
118 for (restart = 1; isoreaddir(restart) == 0; restart = 0) {
119 const char *n = name, *i = x->filename;
120 if (_64bits) {
121 if (strhead(i, n)) continue;
122 n = "64";
123 i += s - name; // strlen(name);
124 }
125 if (strcmp(i, n)) continue;
126 *s++ = c;
127 if (IS_DIR(x->filemod)) {
128 x->dirofs = x->fileofs;
129 x->dirsize = filesize2dirsize(x->filesize);
130 if (c) goto next;
131 }
132 isolseek(&x->fileofs);
133 return 0;
134 }
135 } while ((_64bits ^= CPUMASKLM) == 0);
136 return -1;
137 }