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

vlgothic-fonts: use archive.org as web_site
author Pascal Bellard <pascal.bellard@slitaz.org>
date Thu Jun 13 15:52:10 2019 +0200 (2019-06-13)
parents 861efbf7a5de
children f9e283da869a
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 char *p;
32 #ifdef __ROCKRIDGE
33 char *endname;
34 #endif
35 struct isostate *x=&isostate;
37 if (x->curdirsize == 0xFFFF) {
38 x->curdirsize = x->dirsize;
39 cpydirofs(x->curdirofs, x->dirofs);
40 goto restarted;
41 }
42 if (x->curpos >= SECTORSZ || * (short *) (x->buffer + x->curpos) == 0) {
43 restarted:
44 if (x->curdirsize < DIRSECTORSZ) return -1;
45 isoreadsector(&x->curdirofs);
46 //x->curdirofs += SECTORSZ;
47 *(int *)((char *) &x->curdirofs+1) += SECTORSZ/256;
48 x->curdirsize -= DIRSECTORSZ;
49 x->curpos = 0;
50 }
51 p = x->buffer; p += x->curpos;
52 if ((x->entrysize = * (short *) p) == 0) {
53 return -1;
54 }
55 x->fileofs = (* (unsigned long *) (p + 2)) << SECTORBITS;
56 x->filesize = * (unsigned long *) (p + 10);
57 x->filemod = 0x81ED; if (p[25] & 2) ((char *)&(x->filemod))[1] = 0x41;
58 //x->filemod = (p[25] & 2) ? 0040755 : 0100755;
59 //x->filemod = 0100755 - ((p[25] & (char)2) << 13);
60 #ifdef __ROCKRIDGE
61 endname = NULL;
62 // p += 34 + (p[32] & -2); ?
63 p = x->buffer + 34 + ((p[32] + x->curpos) & -2);
64 do {
65 int len = p[2];
66 # if 0
67 switch (* (short *) p) {
68 case 0x5850: // PX
69 x->filemod = * (short *) (p + 4);
70 break;
71 case 0x4D4E: // NM
72 # else
73 if (* (short *) p == 0x4D4E) {
74 # endif
75 x->filename = p + 5;
76 endname = p + len;
77 }
78 p += len;
79 } while (x->buffer + x->curpos + x->entrysize - 2 > p);
80 if (endname)
81 *endname = 0;
82 else
83 #endif
84 {
85 p = x->buffer + 33; x->filename = p += x->curpos;
86 p--;
87 if (((* (short *) p) & 0xFEFF) -1 == 0) {
88 x->filename = "..";
89 if ((* (short *) p) == 1)
90 x->filename++;
91 }
92 else {
93 p += *p; p--;
94 if (* (short *) (p) != 0x313B) {
95 p++; p++; // no ;1 to remove
96 }
97 if (p[-1] == '.') p--;
98 *p = 0;
99 }
100 }
101 x->curpos += x->entrysize;
102 return 0;
103 }
105 //#define IS_DIR(x)( ((x) & ~0777) == 040000)
106 //#define IS_DIR(x)( (char)((x) >> 9) == (char)040)
107 //#define IS_DIR(x)( (*((char*) &x + 1) & (char)0776) == (char)0100)
108 #define IS_DIR(x)( (*((char*) &x + 1) & (char)0676) == (char)0)
109 int _isoopen(void)
110 {
111 // char *name, *s, c;
112 // char _64bits = cpuhaslm();
113 struct isostate *x=&isostate;
114 #define name (x->filename2open)
115 #define c (((char *)&x->entrysize)[0])
116 #define _64bits (((char *)&x->entrysize)[1])
117 char *s;
119 _64bits = cpuhaslm();
120 do {
121 for (s = (char *) x->filename2open; *s == '/' ; s++) {
122 isoroot();
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;
131 #define i (x->tmp)
132 i = x->filename;
133 if (_64bits) {
134 if (strhead(i, n) == -1) continue;
135 n = "64";
136 i += s - name; // strlen(name);
137 }
138 if (strcmp(i, n)) continue;
139 *s++ = c;
140 if (IS_DIR(x->filemod)) {
141 cpydirofs(x->dirofs, x->fileofs);
142 x->dirsize = filesize2dirsize(x->filesize);
143 if (c) goto next;
144 }
145 isolseek(&x->fileofs);
146 return 0;
147 }
148 } while ((_64bits ^= CPUMASKLM) == 0);
149 return -1;
150 }