static int isonum_723(unsigned char *p, int xflag) { int le = isonum_721(p); int be = isonum_722(p + 2); if (xflag && le != be) /* translation is useless */ warnx("723error: le=%d be=%d", le, be); return (le); }
check_path_tables(int typel_extent, int typem_extent, int path_table_size){ int file_addr; int count; int j; char * pnt; char * typel, *typem; /* Now read in the path tables */ typel = (char *) malloc(path_table_size); lseek(fileno(infile), typel_extent * blocksize, 0); read(fileno(infile), typel, path_table_size); typem = (char *) malloc(path_table_size); lseek(fileno(infile), typem_extent * blocksize, 0); read(fileno(infile), typem, path_table_size); j = path_table_size; pnt = typel; count = 1; while(j){ int namelen, extent, index; char name[32]; namelen = *pnt++; pnt++; extent = isonum_731(pnt); pnt += 4; index = isonum_721(pnt); pnt+= 2; j -= 8+namelen; memset(name, 0, sizeof(name)); strncpy(name, pnt, namelen); pnt += namelen; if(j & 1) { j--; pnt++;}; printf("%4.4d %4.4d %8.8x %s\n",count++, index, extent, name); }; j = path_table_size; pnt = typem; count = 1; while(j){ int namelen, extent, index; char name[32]; namelen = *pnt++; pnt++; extent = isonum_732(pnt); pnt += 4; index = isonum_722(pnt); pnt+= 2; j -= 8+namelen; memset(name, 0, sizeof(name)); strncpy(name, pnt, namelen); pnt += namelen; if(j & 1) { j--; pnt++;}; printf("%4.4d %4.4d %8.8x %s\n", count++, index, extent, name); }; }
int cd9660_open(const char *path, struct open_file *f) { struct file *fp = 0; void *buf; struct iso_primary_descriptor *vd; size_t buf_size, nread, psize, dsize; daddr_t bno; int parent, ent; struct ptable_ent *pp; struct iso_directory_record *dp = 0; int rc; /* First find the volume descriptor */ buf_size = ISO_DEFAULT_BLOCK_SIZE; buf = alloc(buf_size); vd = buf; for (bno = 16;; bno++) { #if !defined(LIBSA_NO_TWIDDLE) twiddle(); #endif rc = DEV_STRATEGY(f->f_dev)(f->f_devdata, F_READ, cdb2devb(bno), ISO_DEFAULT_BLOCK_SIZE, buf, &nread); if (rc) goto out; if (nread != ISO_DEFAULT_BLOCK_SIZE) { rc = EIO; goto out; } rc = EINVAL; if (memcmp(vd->id, ISO_STANDARD_ID, sizeof vd->id) != 0) goto out; if (isonum_711(vd->type) == ISO_VD_END) goto out; if (isonum_711(vd->type) == ISO_VD_PRIMARY) break; } if (isonum_723(vd->logical_block_size) != ISO_DEFAULT_BLOCK_SIZE) goto out; /* Now get the path table and lookup the directory of the file */ bno = isonum_732(vd->type_m_path_table); psize = isonum_733(vd->path_table_size); if (psize > ISO_DEFAULT_BLOCK_SIZE) { dealloc(buf, ISO_DEFAULT_BLOCK_SIZE); buf = alloc(buf_size = roundup(psize, ISO_DEFAULT_BLOCK_SIZE)); } #if !defined(LIBSA_NO_TWIDDLE) twiddle(); #endif rc = DEV_STRATEGY(f->f_dev)(f->f_devdata, F_READ, cdb2devb(bno), buf_size, buf, &nread); if (rc) goto out; if (nread != buf_size) { rc = EIO; goto out; } parent = 1; pp = (struct ptable_ent *)buf; ent = 1; bno = isonum_732(pp->block) + isonum_711(pp->extlen); rc = ENOENT; /* * Remove extra separators */ while (*path == '/') path++; while (*path) { if ((char *)pp >= (char *)buf + psize) break; if (isonum_722(pp->parent) != parent) break; if (!pnmatch(path, pp)) { pp = (struct ptable_ent *)((char *)pp + PTSIZE(pp)); ent++; continue; } path += isonum_711(pp->namlen) + 1; parent = ent; bno = isonum_732(pp->block) + isonum_711(pp->extlen); while ((char *)pp < (char *)buf + psize) { if (isonum_722(pp->parent) == parent) break; pp = (struct ptable_ent *)((char *)pp + PTSIZE(pp)); ent++; } } /* * Now bno has the start of the directory that supposedly * contains the file */ bno--; dsize = 1; /* Something stupid, but > 0 XXX */ for (psize = 0; psize < dsize;) { if (!(psize % ISO_DEFAULT_BLOCK_SIZE)) { bno++; #if !defined(LIBSA_NO_TWIDDLE) twiddle(); #endif rc = DEV_STRATEGY(f->f_dev)(f->f_devdata, F_READ, cdb2devb(bno), ISO_DEFAULT_BLOCK_SIZE, buf, &nread); if (rc) goto out; if (nread != ISO_DEFAULT_BLOCK_SIZE) { rc = EIO; goto out; } dp = (struct iso_directory_record *)buf; } if (!isonum_711(dp->length)) { if ((void *)dp == buf) psize += ISO_DEFAULT_BLOCK_SIZE; else psize = roundup(psize, ISO_DEFAULT_BLOCK_SIZE); continue; } if (dsize == 1) dsize = isonum_733(dp->size); if (dirmatch(path, dp)) break; psize += isonum_711(dp->length); dp = (struct iso_directory_record *) ((char *)dp + isonum_711(dp->length)); } if (psize >= dsize) { rc = ENOENT; goto out; } /* allocate file system specific data structure */ fp = alloc(sizeof(struct file)); memset(fp, 0, sizeof(struct file)); f->f_fsdata = (void *)fp; fp->off = 0; fp->bno = isonum_733(dp->extent); fp->size = isonum_733(dp->size); dealloc(buf, buf_size); return 0; out: if (fp) dealloc(fp, sizeof(struct file)); dealloc(buf, buf_size); return rc; }