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

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