static int isonum_733(unsigned char *p, int xflag) { int le = isonum_731(p); int be = isonum_732(p + 4); if (xflag && le != be) /* translation is useless */ warnx("733error: 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); }; }
main(int argc, char * argv[]){ int file_addr, file_size; char c; int nbyte; struct iso_primary_descriptor ipd; struct iso_directory_record * idr; int typel_extent, typem_extent; int path_table_size; int i,j; if(argc < 2) return 0; infile = fopen(argv[1],"rb"); file_addr = 32768; lseek(fileno(infile), file_addr, 0); read(fileno(infile), &ipd, sizeof(ipd)); idr = (struct iso_directory_record *) &ipd.root_directory_record; blocksize = isonum_723((char *)ipd.logical_block_size); if( blocksize != 512 && blocksize != 1024 && blocksize != 2048 ) { blocksize = 2048; } file_addr = isonum_733(idr->extent) + isonum_711((char *)idr->ext_attr_length); file_size = isonum_733(idr->size); printf("Root at extent %x, %d bytes\n", file_addr, file_size); file_addr = file_addr * blocksize; check_tree(file_addr, file_size, file_addr); typel_extent = isonum_731((char *)ipd.type_l_path_table); typem_extent = isonum_732((char *)ipd.type_m_path_table); path_table_size = isonum_733(ipd.path_table_size); /* Enable this to get the dump of the path tables */ #if 0 check_path_tables(typel_extent, typem_extent, path_table_size); #endif fclose(infile); if(!ngoof) printf("No errors found\n"); }
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; }
static void hf_probe_volume_advanced_disc_detect (int fd) { size_t secsz = ISO_DEFAULT_BLOCK_SIZE; int readoff; struct iso_primary_descriptor desc; u_char *ptbl; int ptbl_size, ptbl_bsize; int ptbl_lbn; struct iso_path_table_entry *pte; int pte_len; int name_len; int off; readoff = ISO_VOLDESC_SEC * secsz; do { if (pread(fd, &desc, sizeof desc, readoff) != sizeof desc) { hfp_warning("volume descriptor read error"); return; } if (isonum_711(desc.type) == ISO_VD_END) return; readoff += secsz; } while (isonum_711(desc.type) != ISO_VD_PRIMARY); ptbl_size = isonum_733(desc.path_table_size); #if BYTE_ORDER == LITTLE_ENDIAN ptbl_lbn = isonum_731(desc.type_l_path_table); #else ptbl_lbn = isonum_732(desc.type_m_path_table); #endif ptbl_bsize = (ptbl_size + secsz - 1) / secsz * secsz; ptbl = g_malloc(ptbl_bsize); if (ptbl == NULL) { hfp_warning("path table allocation failure"); return; } readoff = ptbl_lbn * secsz; if (pread(fd, ptbl, ptbl_bsize, readoff) != ptbl_bsize) { g_free(ptbl); hfp_warning("path table read error"); } for (off = 0; off < ptbl_size; off += pte_len) { pte = (struct iso_path_table_entry *)(ptbl + off); name_len = *pte->name_len; pte_len = ISO_PATH_TABLE_ENTRY_SIZE + name_len + (name_len % 2); if (*(short *)pte->parent_no != 1) continue; if (name_len == 8 && strncmp(pte->name, "VIDEO_TS", 8) == 0) { libhal_device_set_property_bool(hfp_ctx, hfp_udi, "volume.disc.is_videodvd", TRUE, &hfp_error); break; } else if (name_len == 3 && strncmp(pte->name, "VCD", 8) == 0) { libhal_device_set_property_bool(hfp_ctx, hfp_udi, "volume.disc.is_vcd", TRUE, &hfp_error); break; } else if (name_len == 4 && strncmp(pte->name, "SVCD", 4) == 0) { libhal_device_set_property_bool(hfp_ctx, hfp_udi, "volume.disc.is_svcd", TRUE, &hfp_error); break; } } g_free(ptbl); }