Ejemplo n.º 1
0
static afs_uint32
file_cb(afs_vnode * v, XFILE * X, void *refcon)
{
    char *vnodepath, vnpx[30];
    dt_uint64 where;
    XFILE OX;
    int r, use = 0;

    if (!dirs_done) {
	dirs_done = 1;
	if (verbose)
	    printf("* Extracting files...\n");
    }

    /* Should we even use this? */
    if (!use_vnum) {
	if ((r = Path_Build(X, &phi, v->vnode, &vnodepath, !use_realpath)))
	    return r;
	if (!(use = usevnode(X, v->vnode, vnodepath))) {
	    free(vnodepath);
	    return 0;
	}
	if (use == 2) {
	    free(vnodepath);
	    sprintf(vnpx, "#%d:%d", v->vnode, v->vuniq);
	    vnodepath = vnpx;
	}
    } else {
	sprintf(vnpx, "#%d:%d", v->vnode, v->vuniq);
	vnodepath = vnpx;
    }

    /* Print it out */
    if (verbose) {
	printf("-%s %3d %-11d %11d %s %s\n", modestr(v->mode), v->nlinks,
	       v->owner, v->size, datestr(v->server_date), vnodepath);
    } else if (!quiet) {
	printf("%s\n", vnodepath);
    }

    if (!nomode) {
	if ((r = xftell(X, &where))
	    || (r = xfseek(X, &v->d_offset))
	    || (r =
		xfopen_path(&OX, O_RDWR | O_CREAT | O_TRUNC, vnodepath + 1,
			    0644))) {
	    if (vnodepath != vnpx)
		free(vnodepath);
	    return r;
	}
	r = copyfile(X, &OX, v->size);
	xfclose(&OX);
	xfseek(X, &where);
    } else
	r = 0;

    if (vnodepath != vnpx)
	free(vnodepath);
    return r;
}
CSFAPI int CSFile_load(CSFile** outcsf, const char* filename, CSFileMemoryPTR mem)
{
  FILE* file;
  if (fopen_s(&file,filename,"rb")){
    *outcsf = 0;
    return CADSCENEFILE_ERROR_NOFILE;
  }

  CSFile header;
  size_t sizeshould = 0;
  if (!fread_s(&header,sizeof(header),sizeof(header),1,file) ||
      !(sizeshould=CSFile_getRawSize(&header)))
  {
    fclose(file);
    *outcsf = 0;
    return CADSCENEFILE_ERROR_VERSION;
  }
  
  // load the full file to memory
  xfseek(file, 0, SEEK_END);
  size_t size = (size_t)xftell(file);
  xfseek(file, 0, SEEK_SET);

  if (sizeshould != size){
    fclose(file);
    *outcsf = 0;
    return CADSCENEFILE_ERROR_VERSION;
  }
  
  char* data  = (char*)mem->alloc(size);
  fread_s(data,size,size,1,file);
  fclose(file);

  return CSFile_loadRaw(outcsf,size,data);
}
Ejemplo n.º 3
0
int main(int argc, char **argv)
{
    FILE *fp;
    long size;
    uint32_t chksum;
    const char *desc = "Chinachip PMP firmware V1.0";

    if (argc != 2 && argc != 3) {
        printf("Dingoo A320 hxf-file packer tool by unterwulf\n"
               "usage: %s <hxf-file>\n", argv[0]);
        return EXIT_SUCCESS;
    }

    fp = xfopen(argv[1], "w+");
    xfseek(fp, HXF_HDR_SIZE, SEEK_SET); /* skip header */
    process_filelist(fp);
    xfwritedw(0, fp); /* zero dword at the end of file */
    size = ftell(fp);
    xfseek(fp, HXF_HDR_SIZE, SEEK_SET); /* skip header */
    chksum = calc_chksum(fp);
    xfseek(fp, 0, SEEK_SET);
    write_header(fp, size, chksum, desc);
    fclose(fp);

    return EXIT_SUCCESS;
}
Ejemplo n.º 4
0
/* Parse a dump header, including its tagged attributes, and call the
 * dump-header callback, if one is defined.
 */
static afs_uint32
parse_dumphdr(XFILE * X, unsigned char *tag, tagged_field * field,
	      afs_uint32 value, tag_parse_info * pi, void *g_refcon,
	      void *l_refcon)
{
    dump_parser *p = (dump_parser *) g_refcon;
    afs_dump_header hdr;
    dt_uint64 where;
    afs_uint32 r;

    memset(&hdr, 0, sizeof(hdr));
    if ((r = xftell(X, &where)))
	return r;
    sub64_32(hdr.offset, where, 1);

    if ((r = ReadInt32(X, &hdr.magic)))
	return r;
    if ((r = ReadInt32(X, &hdr.version)))
	return r;

    if (hdr.magic != DUMPBEGINMAGIC) {
	if (p->cb_error)
	    (p->cb_error) (DSERR_MAGIC, 1, p->err_refcon,
			   "Invalid magic number (0x%08x) in dump header",
			   hdr.magic);
	return DSERR_MAGIC;
    }
    if (hdr.version != DUMPVERSION) {
	if (p->cb_error)
	    (p->cb_error) (DSERR_MAGIC, 1, p->err_refcon,
			   "Unknown dump format version (%d) in dump header",
			   hdr.version);
	return DSERR_MAGIC;
    }

    if (p->print_flags & DSPRINT_DUMPHDR)
	printf("%s [%s = 0x%s]\n", field->label,
	       decimate_int64(&hdr.offset, 0), hexify_int64(&hdr.offset, 0));
    if (p->print_flags & DSPRINT_DUMPHDR) {
	printf(" Magic number: 0x%08x\n", hdr.magic);
	printf(" Version:      %d\n", hdr.version);
    }
    r = ParseTaggedData(X, dumphdr_fields, tag, pi, g_refcon, (void *)&hdr);

    if (!r && p->cb_dumphdr) {
	r = xftell(X, &where);
	if (!r)
	    r = (p->cb_dumphdr) (&hdr, X, p->refcon);
	if (p->flags & DSFLAG_SEEK) {
	    if (!r)
		r = xfseek(X, &where);
	    else
		xfseek(X, &where);
	}
    }
    if (hdr.field_mask & F_DUMPHDR_VOLNAME)
	free(hdr.volname);
    return r;
}
static unsigned long long lengthOfFile(FILE *file)
{
    long int currentPosition = xftell(file);
    xfseek(file , 0L , SEEK_END);
    long int length = xftell(file);
    xfseek(file, currentPosition, SEEK_SET);

    return length;
}
Ejemplo n.º 6
0
Hash_table*
smp_load(const char *project, const char *skel)
{
  const char *file = NULL;
  FILE *f_skl = NULL;
  unsigned long nstr;
  const char *tab, *tabp;
  Hash_table *htab;
  int i;
  struct stat sbuf;
  char *cbdid;

  if (NULL == (file = skl_file_e(project,skel,"smp")))
    return NULL;

  if (NULL == (f_skl = fopen(file,"r")))
    {
      if (strcmp(project,"cdli"))
	{
	  free((char*)file);
	  if (NULL == (file = skl_file_e("cdli",skel,"smp")))
	    return NULL;
	  if (NULL == (f_skl = fopen(file,"r")))
	    {
	      free((char*)file);
	      return NULL;
	    }
	}
      else
	{
	  free((char*)file);
	  return NULL;
	}
    }

  stat(file,&sbuf);
  xfread(file,1,&nstr,4,1,f_skl);
  tab = tabp = malloc(sbuf.st_size - 4);
  xfseek(file,f_skl,4,SEEK_SET);
  xfread(file,1,tab,1,sbuf.st_size - 4,f_skl);
  xfclose(file,f_skl);

  htab = hash_create(nstr);
  hash_add(htab,(unsigned char *)"#cbd",cbdid = cbd_ident(project,skel));
  for (i = 0; i < nstr; ++i)
    {
      const char *data = tabp+strlen(tabp)+1;
      hash_add(htab,(unsigned char *)tabp,(void*)data);
      tabp = data + strlen(data) + 1;
    }

  skels = realloc(skels,(nskels+1)*sizeof(struct loaded_skl));
  skels[nskels].hash = htab;
  skels[nskels].tab = (unsigned char*)tab;
  skels[nskels].file = (char*)file;
  skels[nskels].cbd = cbdid;
  ++nskels;

  return htab;
}
Ejemplo n.º 7
0
static void ttfLoadLTSH (FILE *fp,LTSHPtr ltsh,ULONG offset)
{
    xfseek(fp, offset, SEEK_SET, "ttfLoadLTSH");
    
    ltsh->version = ttfGetUSHORT(fp);
    ltsh->numGlyphs = ttfGetUSHORT(fp);
    
    ltsh->yPels = ttfMakeBYTE (ltsh->numGlyphs, fp);
}
Ejemplo n.º 8
0
static void
local_writeComponent(art_t    art,
                     uint64_t pSkip,
                     uint64_t pWrite,
                     stai_t   component,
                     bool     doByteswap)
{
	if ((component == NULL) || (pSkip == art->numParticlesInPage)) {
		xfseek(art->f, art->numParticlesInPage * sizeof(float), SEEK_CUR);
		return;
	}
	float *buffer;
	bool  bufferIsAllocated = false;

	if (stai_isLinear(component)
	    && (stai_getSizeOfElementInBytes(component) == sizeof(float))) {
		buffer = stai_getBase(component);
	} else {
		buffer            = xmalloc(sizeof(float) * pWrite);
		bufferIsAllocated = true;
		local_fillBufferFromStai(buffer, component, pWrite);
	}

	if (doByteswap) {
		for (int i = 0; i < pWrite; i++)
			byteswap(buffer + i, sizeof(float));
	}

	xfseek(art->f, (long)pSkip * sizeof(float), SEEK_CUR);
	xfwrite(buffer, sizeof(float), pWrite, art->f);
	xfseek(art->f,
	       (long)(art->numParticlesInPage - pSkip - pWrite) * sizeof(float),
	       SEEK_CUR);

	if (doByteswap && !bufferIsAllocated) {
		// Restore the original byte order of the data array.
		for (int i = 0; i < art->numParticlesInPage; i++)
			byteswap(buffer + i, sizeof(float));
	}
	if (bufferIsAllocated)
		xfree(buffer);
} /* local_writeComponent */
Ejemplo n.º 9
0
afs_uint32
try_backuphdr(XFILE * X, char *tag, tagged_field * field, afs_uint32 value,
	      tag_parse_info * pi, void *g_refcon, void *l_refcon)
{
    dump_parser *p = (dump_parser *) g_refcon;
    backup_system_header bh;
    u_int64 where;
    afs_uint32 r;

    /* Which header should we try (if any)? */
    switch (*tag) {
    case STAGE_VERSMIN:
      r = ParseStageHdr(X, (unsigned char *)tag, &bh);
	break;
    default:
	return DSERR_MAGIC;
    }
    if (r)
	return r;

    /* Do something with it... */
    if (p->print_flags & DSPRINT_BCKHDR)
	PrintBackupHdr(&bh);
    if (p->cb_bckhdr) {
	r = xftell(X, &where);
	if (!r && p->cb_bckhdr)
	    r = (p->cb_bckhdr) (&bh, X, p->refcon);
	if (p->flags & DSFLAG_SEEK) {
	    if (!r)
		r = xfseek(X, &where);
	    else
		xfseek(X, &where);
	}
    }
    if (bh.server)
	free(bh.server);
    if (bh.part)
	free(bh.part);
    if (bh.volname)
	free(bh.volname);
    return r;
}
Ejemplo n.º 10
0
/* do_seek for profiled xfiles */
static afs_uint32
xf_PROFILE_do_seek(XFILE * X, u_int64 * offset)
{
    PFILE *PF = X->refcon;
    afs_uint32 err;

    err = xfseek(&PF->content, offset);
    xfprintf(&PF->profile, "SEEK %s =%ld\n", hexify_int64(offset, 0),
	     (long)err);
    return err;
}
Ejemplo n.º 11
0
/* Parse a volume header, including any tagged attributes, and call the
 * volume-header callback, if one is defined.
 */
afs_uint32
parse_volhdr(XFILE * X, unsigned char *tag, tagged_field * field,
	     afs_uint32 value, tag_parse_info * pi, void *g_refcon,
	     void *l_refcon)
{
    dump_parser *p = (dump_parser *) g_refcon;
    afs_vol_header hdr;
    u_int64 where;
    afs_uint32 r;

    memset(&hdr, 0, sizeof(hdr));
    if (r = xftell(X, &where))
	return r;
    sub64_32(hdr.offset, where, 1);
    if (p->print_flags & DSPRINT_VOLHDR)
	printf("%s [%s = 0x%s]\n", field->label,
	       decimate_int64(&hdr.offset, 0), hexify_int64(&hdr.offset, 0));

    r = ParseTaggedData(X, volhdr_fields, tag, pi, g_refcon, (void *)&hdr);

    if (!r && p->cb_volhdr) {
	if (r = xftell(X, &where))
	    return r;
	r = (p->cb_volhdr) (&hdr, X, p->refcon);
	if (p->flags & DSFLAG_SEEK) {
	    if (!r)
		r = xfseek(X, &where);
	    else
		xfseek(X, &where);
	}
    }
    if (hdr.field_mask & F_VOLHDR_VOLUNIQ)
	p->vol_uniquifier = hdr.voluniq;
    if (hdr.field_mask & F_VOLHDR_VOLNAME)
	free(hdr.volname);
    if (hdr.field_mask & F_VOLHDR_OFFLINE_MSG)
	free(hdr.offline_msg);
    if (hdr.field_mask & F_VOLHDR_MOTD)
	free(hdr.motd_msg);
    return r;
}
Ejemplo n.º 12
0
static void
local_seekToPage(art_t art, int pageNumber)
{
	long pos;
	long posExpected;

	posExpected = ((long)art->numParticlesInPage) * ART_SIZEOF_PARTICLE
	              * pageNumber;
	pos         = ftell(art->f);

	if (pos != posExpected)
		xfseek(art->f, posExpected, SEEK_SET);
}
Ejemplo n.º 13
0
static void
local_readComponent(art_t    art,
                    uint64_t pSkip,
                    uint64_t pRead,
                    stai_t   component,
                    bool     doByteswap)
{
	if ((component == NULL) || (pSkip == art->numParticlesInPage)) {
		xfseek(art->f, art->numParticlesInPage * sizeof(float), SEEK_CUR);
		return;
	}
	float *buffer;
	bool  bufferIsAllocated;

	if (stai_isLinear(component)
	    && (stai_getSizeOfElementInBytes(component) == sizeof(float))) {
		buffer = stai_getBase(component);
	} else {
		buffer            = xmalloc(sizeof(float) * pRead);
		bufferIsAllocated = true;
	}

	xfseek(art->f, (long)pSkip * sizeof(float), SEEK_CUR);
	xfread(buffer, sizeof(float), pRead, art->f);
	xfseek(art->f,
	       (long)(art->numParticlesInPage - pSkip - pRead) * sizeof(float),
	       SEEK_CUR);
	if (doByteswap) {
		for (int i = 0; i < pRead; i++)
			byteswap(buffer + i, sizeof(float));
	}

	if (bufferIsAllocated) {
		local_copyBufferToStai(buffer, component, pRead);
		xfree(buffer);
	}
}
Ejemplo n.º 14
0
static void
local_writeParticle(FILE        *f,
                    const float *partData,
                    bool        doByteswap)
{
	for (int i = 0; i < 6; i++) {
		if (isnan(partData[i]))
			xfseek(f, sizeof(float), SEEK_CUR);
		else {
			float val = partData[i];
			if (doByteswap)
				byteswap(&val, sizeof(float));
			xfwrite(&val, sizeof(float), 1, f);
		}
	}
}
Ejemplo n.º 15
0
void
sky_dump(const char *project, const char *skel, const char *values, const char *type)
{
  struct skl *skltab = NULL,*s;
  const char *file = NULL;
  FILE *f_skl = NULL;
  unsigned long ntab;
  const unsigned char *tab, *tabp;
  int i;
  int skyext = 1;

  if (NULL == (file = skl_file(project,skel,skyext)))
    {
      fprintf(stderr,"sklshow: %s/%s.sky not found\n",project,skel);
      return;
    }
  if (NULL == (f_skl = fopen(file,"r")))
    {
      fprintf(stderr, "sklshow: %s found but not openable\n", file);
      return;
    }
  xfread(file,1,&ntab,4,1,f_skl);
  skltab = malloc(ntab * sizeof(struct skl));
  xfread(file,1,skltab,sizeof(struct skl),ntab,f_skl);
  for (s = skltab,i=0; i < ntab; ++i,++s)
    if (!strcmp(s->values,values) && !strcmp(s->type,type))
      break;
  if (i == ntab)
    {
      fprintf(stderr, "sklshow: values/type %s/%s not found in %s/%s.sky\n",
	      values, type, project, skel);
      return;
    }

  /*FIXME: should keep a list of these so they can be free'd */
  tab = tabp = malloc(s->length);
  xfseek(file,f_skl,s->offset,SEEK_SET);
  xfread(file,1,tab,1,s->length,f_skl);
  xfclose(file,f_skl);

  for (i = 0; i < s->count; ++i)
    {
      printf("%s\n",tabp);
      tabp += strlen((const char *)tabp) + 1;
    }
}
Ejemplo n.º 16
0
static void ttfLoadGASP (FILE *fp,GASPPtr gasp,ULONG offset)
{
    int i;

    xfseek(fp, offset, SEEK_SET, "ttfLoadGASP");
    
    gasp->version = ttfGetUSHORT(fp);
    gasp->numRanges = ttfGetUSHORT(fp);
    
    gasp->gaspRange = XCALLOC (gasp->numRanges, GASPRANGE);
    
    for (i=0;i<gasp->numRanges;i++)
	{
	    gasp->gaspRange[i].rangeMaxPPEM = ttfGetUSHORT(fp);
	    gasp->gaspRange[i].rangeGaspBehavior = ttfGetUSHORT(fp);
	}
}
Ejemplo n.º 17
0
static afs_uint32
resync_vnode(XFILE * X, dump_parser * p, afs_vnode * v, int start, int limit)
{
    dt_uint64 where, expected_where;
    afs_uint32 r;
    int i;

    if ((r = xftell(X, &expected_where)))
	return r;
    cp64(where, expected_where);

    r = match_next_vnode(X, p, &where, v->vnode);
    if (r && r != DSERR_FMT)
	return r;
    if (r)
	for (i = -start; i < limit; i++) {
	    add64_32(where, expected_where, i);
	    r = match_next_vnode(X, p, &where, v->vnode);
	    if (!r)
		break;
	    if (r != DSERR_FMT)
		return r;
	}
    if (r) {
	if (p->cb_error)
	    (p->cb_error) (r, 1, p->err_refcon,
			   "Unable to resync after vnode %d [%s = 0x%s]",
			   v->vnode, decimate_int64(&expected_where, 0),
			   hexify_int64(&expected_where, 0));
	return r;
    }
    if (ne64(where, expected_where) && p->cb_error) {
	(p->cb_error) (DSERR_FMT, 0, p->err_refcon,
		       "Vnode after %d not in expected location", v->vnode);
	(p->cb_error) (DSERR_FMT, 0, p->err_refcon,
		       "Expected location: %s = 0x%s",
		       decimate_int64(&expected_where, 0),
		       hexify_int64(&expected_where, 0));
	(p->cb_error) (DSERR_FMT, 0, p->err_refcon,
		       "Actual location: %s = 0x%s", decimate_int64(&where,
								    0),
		       hexify_int64(&where, 0));
    }
    return xfseek(X, &where);
}
Ejemplo n.º 18
0
afs_uint32
xfskip(XFILE * X, afs_uint32 count)
{
    afs_uint32 code;
    u_int64 tmp64;

    /* Use the skip method, if there is one */
    if (X->do_skip && !X->passthru) {
	code = (X->do_skip) (X, count);
	if (code)
	    return code;
	add64_32(tmp64, X->filepos, count);
	cp64(X->filepos, tmp64);
	return 0;
    }

    /* Simulate using absolute seek, if available */
    if (X->do_seek && !X->passthru) {
	if ((code = xftell(X, &tmp64)))
	    return code;
	add64_32(X->filepos, tmp64, count);
	cp64(tmp64, X->filepos);
	return xfseek(X, &tmp64);
    }

    /* Do it the hard/slow way - read all the data to be skipped.
     * This is done if no other method is available, or if we are
     * supposed to be copying all the data to another XFILE
     */
    {
	char buf[SKIP_SIZE];
	afs_uint32 n;

	while (count) {
	    n = (count > SKIP_SIZE) ? SKIP_SIZE : count;
	    if ((code = xfread(X, buf, n)))
		return code;
	    count -= n;
	}
	return 0;
    }
}
Ejemplo n.º 19
0
static void ttfLoadMAXP(FILE *fp,MAXPPtr maxp,ULONG offset)
{
    xfseek(fp, offset, SEEK_SET, "ttfLoadMAXP");

    maxp->version = ttfGetFixed(fp);
    maxp->numGlyphs = ttfGetUSHORT(fp);
    maxp->maxPoints = ttfGetUSHORT(fp);
    maxp->maxContours = ttfGetUSHORT(fp);
    maxp->maxCompositePoints = ttfGetUSHORT(fp);
    maxp->maxCompositeContours = ttfGetUSHORT(fp);
    maxp->maxZones = ttfGetUSHORT(fp);
    maxp->maxTwilightPoints = ttfGetUSHORT(fp);
    maxp->maxStorage = ttfGetUSHORT(fp);
    maxp->maxFunctionDefs = ttfGetUSHORT(fp);
    maxp->maxInstructionDefs = ttfGetUSHORT(fp);
    maxp->maxStackElements = ttfGetUSHORT(fp);
    maxp->maxSizeOfInstructions = ttfGetUSHORT(fp);
    maxp->maxComponentElements = ttfGetUSHORT(fp);
    maxp->maxComponentDepth = ttfGetUSHORT(fp);
}
Ejemplo n.º 20
0
static void ttfLoadVMTX(FILE *fp,VMTXPtr vmtx,ULONG offset)
{
    USHORT i,n = vmtx->numOfLongVerMetrics,m=vmtx->numOfTSB;

    xfseek(fp, offset, SEEK_SET, "ttfLoadVMTX");
    
    vmtx->vMetrics = XCALLOC (n, longVerMetric);
    for (i=0;i<n;i++)
	{
	    (vmtx->vMetrics+i)->advanceHeight = ttfGetuFWord(fp);
	    (vmtx->vMetrics+i)->topSideBearing = ttfGetFWord(fp);
	}

    /* codes dealing with topSideBearing entry */
    if (m)
	{
	    vmtx->topSideBearing = XCALLOC (m, FWord);
	    for (i=0;i<m;i++)
		{
		    (vmtx->topSideBearing)[i] = ttfGetFWord(fp);
		}
	}
}
Ejemplo n.º 21
0
/* Parse a VNode, including any tagged attributes and data, and call the
 * appropriate callback, if one is defined.
 */
afs_uint32
parse_vnode(XFILE * X, unsigned char *tag, tagged_field * field,
	    afs_uint32 value, tag_parse_info * pi, void *g_refcon,
	    void *l_refcon)
{
    dump_parser *p = (dump_parser *) g_refcon;
    afs_uint32(*cb) (afs_vnode *, XFILE *, void *);
    dt_uint64 where, offset2k;
    afs_vnode v;
    afs_uint32 r;


    if ((r = xftell(X, &where)))
	return r;
    memset(&v, 0, sizeof(v));
    sub64_32(v.offset, where, 1);
    if ((r = ReadInt32(X, &v.vnode)))
	return r;
    if ((r = ReadInt32(X, &v.vuniq)))
	return r;

    mk64(offset2k, 0, 2048);
    if (!LastGoodVNode
	|| ((p->flags & DSFLAG_SEEK) && v.vnode == 1
	    && lt64(v.offset, offset2k)))
	LastGoodVNode = -1;

    if (p->print_flags & DSPRINT_ITEM) {
	printf("%s %d/%d [%s = 0x%s]\n", field->label, v.vnode, v.vuniq,
	       decimate_int64(&where, 0), hexify_int64(&where, 0));
    }

    r = ParseTaggedData(X, vnode_fields, tag, pi, g_refcon, (void *)&v);

    /* Try to resync, if requested */
    if (!r && (p->repair_flags & DSFIX_VFSYNC)) {
	afs_uint32 drop;
	dt_uint64 xwhere;

	if ((r = xftell(X, &where)))
	    return r;
	sub64_32(xwhere, where, 1);

	/* Are we at the start of a valid vnode (or dump end)? */
	r = match_next_vnode(X, p, &xwhere, v.vnode);
	if (r && r != DSERR_FMT)
	    return r;
	if (r) {		/* Nope. */
	    /* Was _this_ a valid vnode?  If so, we can keep it and search for
	     * the next one.  Otherwise, we throw it out, and start the search
	     * at the starting point of this vnode.
	     */
	    drop = r = match_next_vnode(X, p, &v.offset, LastGoodVNode);
	    if (r && r != DSERR_FMT)
		return r;
	    if (!r) {
		add64_32(where, v.offset, 1);
		if ((r = xfseek(X, &v.offset)))
		    return r;
	    } else {
		if ((r = xfseek(X, &xwhere)))
		    return r;
	    }
	    if ((r = resync_vnode(X, p, &v, 0, 1024)))
		return r;
	    if ((r = ReadByte(X, tag)))
		return r;
	    if (drop) {
		if (p->cb_error)
		    (p->cb_error) (DSERR_FMT, 0, p->err_refcon,
				   "Dropping vnode %d", v.vnode);
		return 0;
	    }
	} else {
	    if ((r = xfseek(X, &where)))
		return r;
	}
    }
    LastGoodVNode = v.vnode;

    if (!r) {
	if (v.field_mask & F_VNODE_TYPE)
	    switch (v.type) {
	    case vFile:
		cb = p->cb_vnode_file;
		break;
	    case vDirectory:
		cb = p->cb_vnode_dir;
		break;
	    case vSymlink:
		cb = p->cb_vnode_link;
		break;
	    default:
		cb = p->cb_vnode_wierd;
		break;
	} else
	    cb = p->cb_vnode_empty;
	if (cb) {
	    dt_uint64 where;

	    if ((r = xftell(X, &where)))
		return r;
	    r = (cb) (&v, X, p->refcon);
	    if (p->flags & DSFLAG_SEEK) {
		if (!r)
		    r = xfseek(X, &where);
		else
		    xfseek(X, &where);
	    }
	}
    }
    return r;
}
Ejemplo n.º 22
0
void read_jpg_info(integer img)
{
    int i, units = 0;
    unsigned char jpg_id[] = "JFIF";
    img_xres(img) = img_yres(img) = 0;
    jpg_ptr(img)->file = xfopen(img_name(img), FOPEN_RBIN_MODE);
    /* no LFS needed, as JPEG is limited to <4GiB */
    xfseek(jpg_ptr(img)->file, 0, SEEK_END, cur_file_name);
    jpg_ptr(img)->length = xftell(jpg_ptr(img)->file, cur_file_name);
    xfseek(jpg_ptr(img)->file, 0, SEEK_SET, cur_file_name);
    if (read2bytes(jpg_ptr(img)->file) != 0xFFD8)
        pdftex_fail("reading JPEG image failed (no JPEG header found)");
    /* currently only true JFIF files allow extracting img_xres and img_yres */
    if (read2bytes(jpg_ptr(img)->file) == 0xFFE0) {     /* check for JFIF */
        (void) read2bytes(jpg_ptr(img)->file);
        for (i = 0; i < 5; i++) {
            if (xgetc(jpg_ptr(img)->file) != jpg_id[i])
                break;
        }
        if (i == 5) {           /* it's JFIF */
            read2bytes(jpg_ptr(img)->file);
            units = xgetc(jpg_ptr(img)->file);
            img_xres(img) = read2bytes(jpg_ptr(img)->file);
            img_yres(img) = read2bytes(jpg_ptr(img)->file);
            switch (units) {
            case 1:
                break;          /* pixels per inch */
            case 2:
                img_xres(img) *= 2.54;
                img_yres(img) *= 2.54;
                break;          /* pixels per cm */
            default:
                img_xres(img) = img_yres(img) = 0;
                break;
            }
        }
    }
    xfseek(jpg_ptr(img)->file, 0, SEEK_SET, cur_file_name);
    while (1) {
        if (feof(jpg_ptr(img)->file))
            pdftex_fail("reading JPEG image failed (premature file end)");
        if (fgetc(jpg_ptr(img)->file) != 0xFF)
            pdftex_fail("reading JPEG image failed (no marker found)");
        switch (xgetc(jpg_ptr(img)->file)) {
        case M_SOF5:
        case M_SOF6:
        case M_SOF7:
        case M_SOF9:
        case M_SOF10:
        case M_SOF11:
        case M_SOF13:
        case M_SOF14:
        case M_SOF15:
            pdftex_fail("unsupported type of compression");
        case M_SOF2:
            if (fixedpdfminorversion <= 2)
                pdftex_fail("cannot use progressive DCT with PDF-1.2");
        case M_SOF0:
        case M_SOF1:
        case M_SOF3:
            (void) read2bytes(jpg_ptr(img)->file);      /* read segment length  */
            jpg_ptr(img)->bits_per_component = xgetc(jpg_ptr(img)->file);
            img_height(img) = read2bytes(jpg_ptr(img)->file);
            img_width(img) = read2bytes(jpg_ptr(img)->file);
            jpg_ptr(img)->color_space = xgetc(jpg_ptr(img)->file);
            xfseek(jpg_ptr(img)->file, 0, SEEK_SET, cur_file_name);
            switch (jpg_ptr(img)->color_space) {
            case JPG_GRAY:
                img_color(img) = IMAGE_COLOR_B;
                break;
            case JPG_RGB:
                img_color(img) = IMAGE_COLOR_C;
                break;
            case JPG_CMYK:
                img_color(img) = IMAGE_COLOR_C;
                break;
            default:
                pdftex_fail("Unsupported color space %i",
                            (int) jpg_ptr(img)->color_space);
            }
            return;
        case M_SOI:            /* ignore markers without parameters */
        case M_EOI:
        case M_TEM:
        case M_RST0:
        case M_RST1:
        case M_RST2:
        case M_RST3:
        case M_RST4:
        case M_RST5:
        case M_RST6:
        case M_RST7:
            break;
        default:               /* skip variable length markers */
            xfseek(jpg_ptr(img)->file, read2bytes(jpg_ptr(img)->file) - 2,
                   SEEK_CUR, cur_file_name);
            break;
        }
    }
}
 void seek(size_t offset, int pos)
 {
   xfseek (m_file, offset, pos);
 }
Ejemplo n.º 24
0
/* Main program */
int
main(int argc, char **argv)
{
    XFILE input_file;
    afs_uint32 r;

    parse_options(argc, argv);
    initialize_acfg_error_table();
    initialize_AVds_error_table();
    initialize_rxk_error_table();
    initialize_u_error_table();
    initialize_vl_error_table();
    initialize_vols_error_table();
    initialize_xFil_error_table();
    r = xfopen(&input_file, O_RDONLY, input_path);
    if (r) {
	afs_com_err(argv0, r, "opening %s", input_path);
	exit(2);
    }

    memset(&dp, 0, sizeof(dp));
    dp.cb_error = my_error_cb;
    if (input_file.is_seekable)
	dp.flags |= DSFLAG_SEEK;
    dirs_done = 0;

    if (!use_vnum) {
	dt_uint64 where;

	memset(&phi, 0, sizeof(phi));
	phi.p = &dp;

	if (verbose)
	    printf("* Building pathname info...\n");
	if ((r = xftell(&input_file, &where))
	    || (r = Path_PreScan(&input_file, &phi, 1))
	    || (r = xfseek(&input_file, &where))) {
	    afs_com_err(argv0, r, "- path initialization failed");
	    xfclose(&input_file);
	    exit(1);
	}
    }

    dp.cb_vnode_dir = directory_cb;
    dp.cb_vnode_file = file_cb;
    dp.cb_vnode_link = symlink_cb;
    dp.cb_vnode_empty = lose_cb;
    dp.cb_vnode_wierd = lose_cb;
    if (do_headers) {
	dp.cb_dumphdr = dumphdr_cb;
	dp.cb_volhdr = volhdr_cb;
    }

    if (!nomode) {
	mkdir(target, 0755);
	if (chdir(target)) {
	    fprintf(stderr, "chdir %s failed: %s\n", target, strerror(errno));
	    exit(1);
	}
    }
    r = ParseDumpFile(&input_file, &dp);

    if (verbose && error_count)
	fprintf(stderr, "*** %d errors\n", error_count);
    if (r && !quiet)
	fprintf(stderr, "*** FAILED: %s\n", afs_error_message(r));
    exit(0);
}
Ejemplo n.º 25
0
static afs_uint32
symlink_cb(afs_vnode * v, XFILE * X, void *refcon)
{
    char *vnodepath, *linktarget, vnpx[30];
    dt_uint64 where;
    int r, use = 0;

    if (!dirs_done) {
	dirs_done = 1;
	if (verbose)
	    printf("* Extracting files...\n");
    }

    /* Should we even use this? */
    if (!use_vnum) {
	if ((r = Path_Build(X, &phi, v->vnode, &vnodepath, !use_realpath)))
	    return r;
	if (!(use = usevnode(X, v->vnode, vnodepath))) {
	    free(vnodepath);
	    return 0;
	}
	if (use == 2) {
	    free(vnodepath);
	    sprintf(vnpx, "#%d:%d", v->vnode, v->vuniq);
	    vnodepath = vnpx;
	}
    } else {
	sprintf(vnpx, "#%d:%d", v->vnode, v->vuniq);
	vnodepath = vnpx;
    }

    if (!(linktarget = malloc(v->size + 1))) {
	if (vnodepath != vnpx)
	    free(vnodepath);
	return DSERR_MEM;
    }
    if ((r = xftell(X, &where))
	|| (r = xfseek(X, &v->d_offset))
	|| (r = xfread(X, linktarget, v->size))) {
	if (vnodepath != vnpx)
	    free(vnodepath);
	free(linktarget);
	return r;
    }
    xfseek(X, &where);
    linktarget[v->size] = 0;

    /* Print it out */
    if (verbose)
	printf("l%s %3d %-11d %11d %s %s -> %s\n", modestr(v->mode),
	       v->nlinks, v->owner, v->size, datestr(v->server_date),
	       vnodepath, linktarget);
    else if (!quiet)
	printf("%s\n", vnodepath);

    r = 0;
    if (!nomode) {
	if (symlink(linktarget, vnodepath + 1))
	    r = errno;
    }

    free(linktarget);
    if (vnodepath != vnpx)
	free(vnodepath);
    return r;
}
Ejemplo n.º 26
0
static dirtab_entry *ttf_seek_tab(const char *name, TTF_LONG offset)
{
    dirtab_entry *tab = ttf_name_lookup(name, true);
    xfseek(INFILE, tab->offset + offset, SEEK_SET, cur_file_name);
    return tab;
}
Ejemplo n.º 27
0
/* Main program */
void
main(int argc, char **argv)
{
    XFILE *X;
    afs_uint32 r;

    parse_options(argc, argv);
    initialize_UB_error_table();
    initialize_UBsp_error_table();
    initialize_AVds_error_table();
    r = xfopen(&X, input_path, O_RDONLY, 0);
    if (r) {
	afs_com_err(argv0, r, "opening %s", input_path);
	exit(2);
    }

    bzero(&dp, sizeof(dp));
    dp.cb_error = my_error_cb;
    dp.repair_flags = repairflags;
    if (X->is_seekable)
	dp.flags |= DSFLAG_SEEK;
    else {
	if (repairflags)
	    fprintf(stderr,
		    "Repair modes available only for seekable dumps\n");
	if (printflags & DSPRINT_PATH)
	    fprintf(stderr,
		    "Path-printing available only for seekable dumps\n");
	if (repairflags || (printflags & DSPRINT_PATH))
	    exit(1);
    }

    if (gendump_path && (r = setup_repair())) {
	afs_com_err(argv0, r, "setting up repair output");
	xfclose(X);
	exit(2);
    }

    if (printflags & DSPRINT_PATH) {
	u_int64 where;

	dp.print_flags = printflags & DSPRINT_DEBUG;
	bzero(&phi, sizeof(phi));
	phi.p = &dp;

	if ((r = xftell(X, &where))
	    || (r = Path_PreScan(X, &phi, 0))
	    || (r = xfseek(X, &where))) {
	    afs_com_err(argv0, r, "- path initialization failed");
	    xfclose(X);
	    exit(2);
	}

	dp.cb_vnode_dir = print_vnode_path;
	dp.cb_vnode_file = print_vnode_path;
	dp.cb_vnode_link = print_vnode_path;
	dp.cb_vnode_empty = print_vnode_path;
	dp.cb_vnode_wierd = print_vnode_path;
    }

    if (add_admin) {
	dp.cb_vnode_dir = munge_admin_acl;
    }

    dp.print_flags = printflags;
    r = ParseDumpFile(X, &dp);
    if (gendump_path) {
	if (!r)
	    r = DumpDumpEnd(&repair_output);
	if (!r)
	    r = xfclose(&repair_output);
	else
	    xfclose(&repair_output);
    }

    if (verbose && error_count)
	fprintf(stderr, "*** %d errors\n", error_count);
    if (r && !quiet)
	fprintf(stderr, "*** FAILED: %s\n", afs_error_message(r));
    exit(0);
}
Ejemplo n.º 28
0
static void ttf_seek_off(TTF_LONG offset)
{
    xfseek(INFILE, offset, SEEK_SET, cur_file_name);
}
Ejemplo n.º 29
0
static void ttfLoadCVT(FILE *fp,FWord *cvt,USHORT length,ULONG offset)
{
    xfseek(fp, offset, SEEK_SET, "ttfLoadCVT");

    ttfReadFWord (cvt, length, fp);
}
Ejemplo n.º 30
0
/* Parse a stage backup header.
 * If tag is non-NULL, *tag should contain the first byte (already read),
 * and will be filled in with the first byte after the header, if one exists.
 * On success, returns 0 and leaves us positioned after the header
 * On failure, returns an error and position is undefined
 * Iff there is no header, returns DSERR_MAGIC and leaves us
 * positioned where we started.
 */
afs_uint32
ParseStageHdr(XFILE * X, unsigned char *tag, backup_system_header * hdr)
{
    char buf[STAGE_HDRLEN];
    struct stage_header *bckhdr = (struct stage_header *)buf;
    u_int64 where;
    afs_int32 r;

    if ((r = xftell(X, &where)))
	return r;
    if (hdr)
	memset(hdr, 0, sizeof(*hdr));
    if (tag) {
	if (*tag != STAGE_VERSMIN)
	    return DSERR_MAGIC;
	buf[0] = *tag;
	r = xfread(X, buf + 1, STAGE_HDRLEN - 1);
    } else {
	r = xfread(X, buf, STAGE_HDRLEN);
    }

    if (r == ERROR_XFILE_EOF) {
	r = xfseek(X, &where);
	return r ? r : DSERR_MAGIC;
    } else if (r)
	return r;

    if (bckhdr->c_vers < STAGE_VERSMIN
	|| ntohl(bckhdr->c_magic) != STAGE_MAGIC
	|| hdr_checksum(buf, STAGE_HDRLEN) != STAGE_CHECKSUM) {
	r = xfseek(X, &where);
	return r ? r : DSERR_MAGIC;
    }

    if (hdr) {
	hdr->version = bckhdr->c_vers;
	hdr->from_date = ntohl(bckhdr->c_fdate);
	hdr->to_date = ntohl(bckhdr->c_tdate);
	hdr->dump_date = ntohl(bckhdr->c_time);
	hdr->filenum = ntohl(bckhdr->c_filenum);
	hdr->volid = ntohl(bckhdr->c_id);
#ifdef NATIVE_INT64
	hdr->dumplen = ntohl(bckhdr->c_length);
#else
        hdr->dumplen.hi = 0;
        hdr->dumplen.lo = ntohl(bckhdr->c_length);
#endif
	hdr->level = ntohl(bckhdr->c_level);
	hdr->magic = ntohl(bckhdr->c_magic);
	hdr->cksum = ntohl(bckhdr->c_checksum);
	hdr->flags = ntohl(bckhdr->c_flags);
	hdr->server = malloc(strlen(bckhdr->c_host) + 1);
	hdr->part = malloc(strlen(bckhdr->c_disk) + 1);
	hdr->volname = malloc(strlen(bckhdr->c_name) + 1);

	if (!hdr->server || !hdr->part || !hdr->volname) {
	    if (hdr->server)
		free(hdr->server);
	    if (hdr->part)
		free(hdr->part);
	    if (hdr->volname)
		free(hdr->volname);
	    return ENOMEM;
	}
	strcpy((char *)hdr->server, bckhdr->c_host);
	strcpy((char *)hdr->part, bckhdr->c_disk);
	strcpy((char *)hdr->volname, bckhdr->c_name);
    }

    if (tag)
	return ReadByte(X, tag);
    else
	return 0;
}