wok-current view linld/stuff/src/ISO9660.CPP @ rev 21628

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