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

linld: add iso support
author Pascal Bellard <pascal.bellard@slitaz.org>
date Fri Jan 08 20:15:35 2021 +0000 (2021-01-08)
parents 431c14b76522
children 5c1ce90eb1d6
line source
1 #include "crtl.h"
2 #include "iso9660.h"
4 #define setdirpage(to,sec) ((to) = *(int*)&(sec)<<(SECTORBITS-8))
5 #define cpytodirpage(to,from) ((to) = *(int*)((char*)&(from)+1))
6 #define cpyfromdirpage(to,from) (*(int*)((char*)&(to)+1) = (from))
8 #define isoroot() \
9 { \
10 extern void isoreadrootsector(void); \
11 isoreadrootsector(); \
12 setdirpage(x->dirpage, (* (unsigned long *) (isostate.buffer + 0x9E))); \
13 x->dirsize = filesize2dirsize(* (unsigned long *) (isostate.buffer + 0xA6)); \
14 }
16 static int isoreaddir(void)
17 {
18 char *p;
20 struct isostate *x=&isostate;
22 if (x->curpos >= SECTORSZ || * (short *) (x->buffer + x->curpos) == 0) {
23 if ((x->curdirsize =- DIRSECTORSZ) < 0) return -1;
24 isoreadsector(&x->curdirofs); // x->filepos = 0
25 //x->curdirofs += SECTORSZ;
26 *(int *)((char *) &x->curdirofs+1) += SECTORSZ/256;
27 x->curpos = 0;
28 }
29 p = x->buffer; p += x->curpos;
30 x->fileofs = (* (unsigned long *) (p + 2)) << SECTORBITS;
31 if ((x->entrysize = * (short *) p) == 0) {
32 return -1;
33 }
34 // x->filename = "";
35 x->filesize = * (unsigned long *) (p + 10);
36 x->filemod = 0x81ED; if (p[25] & 2) ((char *)&(x->filemod))[1] = 0x41;
37 p = x->buffer + 34 + ((p[32] + x->curpos) & -2);
38 x->curpos += x->entrysize;
39 do {
40 register len = p[2];
41 if (* (short *) p == 0x4D4E) {
42 x->filename = p + 5;
43 p[len] = 0;
44 goto found;
45 }
46 p += len;
47 } while (x->buffer + x->curpos - 3 >= p);
48 found:
49 return 0;
50 }
52 #define isoreaddir_reset() \
53 { \
54 x->curdirsize = x->dirsize; \
55 cpyfromdirpage(x->curdirofs, x->dirpage); \
56 x->curpos = -1; \
57 }
59 int _isoopen(void)
60 {
61 // char *name, *s, c;
62 // char _64bits = cpuhaslm();
63 struct isostate *x=&isostate;
64 #define name (x->filename2open)
65 #define c (x->c)
66 #define _64bits (x->_64bits)
67 char *s;
69 _64bits = cpuhaslm();
70 _32bits:
71 s = (char *) x->filename2open;
72 if (*s == '/') {
73 s++;
74 isoroot();
75 //if (strncmp(x->buffer+1,"CD001,5) == -1) return -1;
76 //if (*(int*)(x->buffer+1) != 0x4443) return -1;
77 }
78 next:
79 isoreaddir_reset();
80 name = s;
81 do s++; while (*s && *s != '/');
82 c = *s; *s = 0;
83 do {
84 if (isoreaddir() == -1) {
85 if ((_64bits ^= CPUMASKLM) == 0) goto _32bits;
86 return -1;
87 }
88 const char *n = name;
89 #define i (x->tmp)
90 i = x->filename;
91 if (_64bits) {
92 if (strhead(i, n) == -1) continue;
93 n = "64";
94 i += s - name; // strlen(name);
95 }
96 if (strcmp(i, n) != -1) break;
97 } while (1);
98 *s++ = c;
99 #define IS_DIR(x)( (*((char*) &x + 1) & (char)0676) == (char)0)
100 if (IS_DIR(x->filemod)) {
101 cpytodirpage(x->dirpage, x->fileofs);
102 x->dirsize = filesize2dirsize(x->filesize);
103 if (c) goto next;
104 }
105 isolseek(&x->fileofs);
106 return x->fd;
107 }