wok diff 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 diff
     1.1 --- a/linld/stuff/src/ISO9660.CPP	Wed Nov 25 20:41:41 2020 +0000
     1.2 +++ b/linld/stuff/src/ISO9660.CPP	Fri Jan 08 20:15:35 2021 +0000
     1.3 @@ -1,73 +1,41 @@
     1.4  #include "crtl.h"
     1.5 -#include "crtlx.h"
     1.6  #include "iso9660.h"
     1.7 -#define __ROCKRIDGE
     1.8  
     1.9 -#if 1
    1.10 -#define setdirofs(to,sec)	(*(int*)((char*)&(to)+1) = *(int*)&(sec)<<(SECTORBITS-8))
    1.11 -#define cpydirofs(to,from)	(*(int*)((char*)&(to)+1) = *(int*)((char*)&(from)+1))
    1.12 -#else
    1.13 -#define setdirofs(to,sec)	(to = (sec)<<SECTORBITS)
    1.14 -#define cpydirofs(to,from)	((to) = (from))
    1.15 -#endif
    1.16 +#define setdirpage(to,sec)	((to) = *(int*)&(sec)<<(SECTORBITS-8))
    1.17 +#define cpytodirpage(to,from)	((to) = *(int*)((char*)&(from)+1))
    1.18 +#define cpyfromdirpage(to,from)	(*(int*)((char*)&(to)+1) = (from))
    1.19  
    1.20 -#ifdef ISOHOOK
    1.21  #define isoroot() \
    1.22  { \
    1.23 -	static const unsigned long root = 16UL * 2048; \
    1.24 -	isoreadsector(&root); \
    1.25 -	setdirofs(isostate.dirofs, (* (unsigned long *) (isostate.buffer + 0x9E))); \
    1.26 -	isostate.dirsize = filesize2dirsize(* (unsigned long *) (isostate.buffer + 0xA6)); \
    1.27 +	extern void isoreadrootsector(void); \
    1.28 +	isoreadrootsector(); \
    1.29 +	setdirpage(x->dirpage, (* (unsigned long *) (isostate.buffer + 0x9E))); \
    1.30 +	x->dirsize = filesize2dirsize(* (unsigned long *) (isostate.buffer + 0xA6)); \
    1.31  }
    1.32 -#else
    1.33 -int isoroot(void)
    1.34 -{
    1.35 -	static const unsigned long root = 16UL * 2048;
    1.36 -	if (isoreadsector(&root) == -1 || strhead(isostate.buffer+1,"CD001") == -1) {
    1.37 -		//close(isostate.fd);
    1.38 -		return -1;
    1.39 -	}
    1.40 -	setdirofs(isostate.dirofs, (* (unsigned long *) (isostate.buffer + 0x9E)));
    1.41 -	isostate.dirsize = filesize2dirsize(* (unsigned long *) (isostate.buffer + 0xA6));
    1.42 -	return 0;
    1.43 -}
    1.44 -#endif
    1.45  
    1.46 -int isoreaddir(void)
    1.47 +static int isoreaddir(void)
    1.48  {
    1.49  	char *p;
    1.50  
    1.51  	struct isostate *x=&isostate;
    1.52  
    1.53 -	if (x->curdirsize == 0xFFFF) {
    1.54 -		x->curdirsize = x->dirsize;
    1.55 -		cpydirofs(x->curdirofs, x->dirofs);
    1.56 -		goto restarted;
    1.57 -	}
    1.58  	if (x->curpos >= SECTORSZ || * (short *) (x->buffer + x->curpos) == 0) {
    1.59 -	restarted:
    1.60 -		if (x->curdirsize < DIRSECTORSZ) return -1;
    1.61 -		isoreadsector(&x->curdirofs);
    1.62 +		if ((x->curdirsize =- DIRSECTORSZ) < 0) return -1;
    1.63 +		isoreadsector(&x->curdirofs);	// x->filepos = 0
    1.64  		//x->curdirofs += SECTORSZ;
    1.65  		*(int *)((char *) &x->curdirofs+1) += SECTORSZ/256;
    1.66 -		x->curdirsize -= DIRSECTORSZ;
    1.67  		x->curpos = 0;
    1.68  	}
    1.69  	p = x->buffer; p += x->curpos;
    1.70 +	x->fileofs = (* (unsigned long *) (p + 2)) << SECTORBITS;
    1.71  	if ((x->entrysize = * (short *) p) == 0) {
    1.72  		return -1;
    1.73  	}
    1.74 -	x->fileofs = (* (unsigned long *) (p + 2)) << SECTORBITS;
    1.75 +	// x->filename = "";
    1.76  	x->filesize = * (unsigned long *) (p + 10);
    1.77  	x->filemod = 0x81ED; if (p[25] & 2) ((char *)&(x->filemod))[1] = 0x41;
    1.78 -	//x->filemod = (p[25] & 2) ? 0040755 : 0100755;
    1.79 -	//x->filemod = 0100755 - ((p[25] & (char)2) << 13);
    1.80 -#ifdef __ROCKRIDGE
    1.81 -	// p += 34 + (p[32] & -2); ?
    1.82  	p = x->buffer + 34 + ((p[32] + x->curpos) & -2);
    1.83 -#ifdef ISOHOOK
    1.84  	x->curpos += x->entrysize;
    1.85 -#endif
    1.86  	do {
    1.87  		register len = p[2];
    1.88  		if (* (short *) p == 0x4D4E) {
    1.89 @@ -76,42 +44,18 @@
    1.90  			goto found;
    1.91  		}
    1.92  		p += len;
    1.93 -#ifdef ISOHOOK
    1.94 -	} while (x->buffer + x->curpos - 2 > p);
    1.95 -#else
    1.96 -	} while (x->buffer + x->curpos + x->entrysize - 2 > p);
    1.97 -#endif
    1.98 -#endif
    1.99 -#ifndef ISOHOOK
   1.100 -	{
   1.101 -		p = x->buffer + 33; x->filename = p += x->curpos;
   1.102 -		p--;
   1.103 -		if (((* (short *) p) & 0xFEFF) -1 == 0) {
   1.104 -			x->filename = "..";
   1.105 -			if (--(* (short *) p) == 0)
   1.106 -				x->filename++;
   1.107 -		}
   1.108 -		else {
   1.109 -			p += *p; p--;
   1.110 -			if (* (short *) (p) != 0x313B) {
   1.111 -				p++; p++; // no ;1 to remove
   1.112 -			}
   1.113 -			if (p[-1] == '.') p--;
   1.114 -			*p = 0;
   1.115 -		}
   1.116 -	}
   1.117 -#endif
   1.118 +	} while (x->buffer + x->curpos - 3 >= p);
   1.119  found:
   1.120 -#ifndef ISOHOOK
   1.121 -	x->curpos += x->entrysize;
   1.122 -#endif
   1.123  	return 0;
   1.124  }
   1.125  
   1.126 -//#define IS_DIR(x)( ((x) & ~0777) == 040000)
   1.127 -//#define IS_DIR(x)( (char)((x) >> 9) == (char)040)
   1.128 -//#define IS_DIR(x)( (*((char*) &x + 1) & (char)0776) == (char)0100)
   1.129 -#define IS_DIR(x)( (*((char*) &x + 1) & (char)0676) == (char)0)
   1.130 +#define isoreaddir_reset() \
   1.131 +{ \
   1.132 +	x->curdirsize = x->dirsize; \
   1.133 +	cpyfromdirpage(x->curdirofs, x->dirpage); \
   1.134 +	x->curpos = -1; \
   1.135 +}
   1.136 +
   1.137  int _isoopen(void)
   1.138  {
   1.139  //	char *name, *s, c;
   1.140 @@ -123,25 +67,24 @@
   1.141  	char *s;
   1.142  
   1.143  	_64bits = cpuhaslm();
   1.144 -    do {
   1.145 -#ifdef ISOHOOK
   1.146 +  _32bits:
   1.147  	s = (char *) x->filename2open;
   1.148  	if (*s == '/') {
   1.149  		s++;
   1.150  		isoroot();
   1.151 -	}
   1.152 -	name = s;
   1.153 -	while (*++s);
   1.154 -#else
   1.155 -	for (s = (char *) x->filename2open; *s == '/' ; s++) {
   1.156 -		isoroot();
   1.157 +		//if (strncmp(x->buffer+1,"CD001,5) == -1) return -1;
   1.158 +		//if (*(int*)(x->buffer+1) != 0x4443) return -1;
   1.159  	}
   1.160    next:
   1.161 +	isoreaddir_reset();
   1.162  	name = s;
   1.163  	do s++; while (*s && *s != '/');
   1.164  	c = *s; *s = 0;
   1.165 -#endif
   1.166 -	for (x->curdirsize = 0xFFFF; isoreaddir() != -1;) {
   1.167 +	do {
   1.168 +		if (isoreaddir() == -1) {
   1.169 +			if ((_64bits ^= CPUMASKLM) == 0) goto _32bits;
   1.170 +			return -1;
   1.171 +		}
   1.172  		const char *n = name;
   1.173  #define i (x->tmp)
   1.174  		i = x->filename;
   1.175 @@ -150,20 +93,15 @@
   1.176  			n = "64";
   1.177  			i += s - name; // strlen(name);
   1.178  		}
   1.179 -		if (strcmp(i, n) == -1) continue;
   1.180 -#ifndef ISOHOOK
   1.181 -		*s++ = c;
   1.182 -#endif
   1.183 -		if (IS_DIR(x->filemod)) {
   1.184 -			cpydirofs(x->dirofs, x->fileofs);
   1.185 -			x->dirsize = filesize2dirsize(x->filesize);
   1.186 -#ifndef ISOHOOK
   1.187 -			if (c) goto next;
   1.188 -#endif
   1.189 -		}
   1.190 -		isolseek(&x->fileofs);
   1.191 -		return 0;
   1.192 +		if (strcmp(i, n) != -1) break;
   1.193 +	} while (1);
   1.194 +	*s++ = c;
   1.195 +#define IS_DIR(x)( (*((char*) &x + 1) & (char)0676) == (char)0)
   1.196 +	if (IS_DIR(x->filemod)) {
   1.197 +		cpytodirpage(x->dirpage, x->fileofs);
   1.198 +		x->dirsize = filesize2dirsize(x->filesize);
   1.199 +		if (c) goto next;
   1.200  	}
   1.201 -    } while ((_64bits ^= CPUMASKLM) == 0);
   1.202 -	return -1;
   1.203 +	isolseek(&x->fileofs);
   1.204 +	return x->fd;
   1.205  }