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