wok-6.x annotate linld/stuff/src/ISO9660.CPP @ rev 19826
linld: remove dead code
author | Pascal Bellard <pascal.bellard@slitaz.org> |
---|---|
date | Tue Mar 07 12:21:16 2017 +0100 (2017-03-07) |
parents | 6f494adb2c71 |
children | 46b511e941a7 |
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@19515 | 35 static char dots[] = ".."; |
pascal@19636 | 36 int size; |
pascal@19636 | 37 char *p; |
pascal@19515 | 38 #ifdef __ROCKRIDGE |
pascal@19515 | 39 char *endname; |
pascal@19515 | 40 #endif |
pascal@19571 | 41 struct isostate *x=&isostate; |
pascal@19515 | 42 |
pascal@19515 | 43 if (restart) { |
pascal@19826 | 44 x->curdirsize = x->dirsize; |
pascal@19571 | 45 x->curdirofs = x->dirofs; |
pascal@19826 | 46 goto restarted; |
pascal@19515 | 47 } |
pascal@19571 | 48 if (x->curpos >= SECTORSZ || * (short *) (buffer + x->curpos) == 0) { |
pascal@19826 | 49 if (x->curdirsize < DIRSECTORSZ) return -1; |
pascal@19826 | 50 restarted: |
pascal@19825 | 51 readsector(&x->curdirofs); |
pascal@19571 | 52 x->curdirofs += SECTORSZ; |
pascal@19826 | 53 x->curdirsize -= DIRSECTORSZ; |
pascal@19571 | 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@19515 | 62 #ifdef __ROCKRIDGE |
pascal@19515 | 63 endname = NULL; |
pascal@19636 | 64 // p += 34 + (p[32] & -2); ? |
pascal@19636 | 65 p = buffer + 34 + ((p[32] + x->curpos) & -2); |
pascal@19515 | 66 do { |
pascal@19636 | 67 int len = p[2]; |
pascal@19636 | 68 switch (* (short *) p) { |
pascal@19515 | 69 case 0x4D4E: // NM |
pascal@19636 | 70 x->filename = p + 5; |
pascal@19636 | 71 endname = p + len; |
pascal@19515 | 72 break; |
pascal@19515 | 73 case 0x5850: // PX |
pascal@19636 | 74 x->filemod = * (short *) (p + 4); |
pascal@19515 | 75 break; |
pascal@19515 | 76 } |
pascal@19636 | 77 p += len; |
pascal@19515 | 78 } |
pascal@19636 | 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@19636 | 87 switch (* (short *) p) { |
pascal@19515 | 88 case 0x0101: |
pascal@19571 | 89 x->filename = dots; |
pascal@19515 | 90 break; |
pascal@19515 | 91 case 0x0001: |
pascal@19571 | 92 x->filename = dots + 1; |
pascal@19515 | 93 break; |
pascal@19515 | 94 default: |
pascal@19636 | 95 p += *p; p--; |
pascal@19636 | 96 if (* (short *) (p) != 0x313B) { |
pascal@19636 | 97 p++; p++; // no ;1 to remove |
pascal@19636 | 98 } |
pascal@19636 | 99 if (p[-1] == '.') p--; |
pascal@19636 | 100 *p = 0; |
pascal@19515 | 101 } |
pascal@19515 | 102 } |
pascal@19571 | 103 x->curpos += size; |
pascal@19515 | 104 return 0; |
pascal@19515 | 105 } |
pascal@19515 | 106 |
pascal@19825 | 107 //#define IS_DIR(x)( ((x) & ~0777) == 040000) |
pascal@19825 | 108 #define IS_DIR(x)( (char)((x) >> 9) == (char)040) |
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 } |