Example #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;
}
Example #2
0
static afs_uint32
directory_cb(afs_vnode * v, XFILE * X, void *refcon)
{
    char *vnodepath;
    int r, use = 0;

    /* 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;
	}
    }

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

    /* Make the directory, if needed */
    if (!nomode && !use_vnum && use != 2) {
	if (strcmp(vnodepath, "/")
	    && (r = mkdirp(vnodepath + 1))) {
	    free(vnodepath);
	    return r;
	}
	if (do_acls) {
	    /* XXX do ACL's later */
	}
    }
    if (!use_vnum)
	free(vnodepath);
    return 0;
}
/* A callback to print the path of a vnode. */
static afs_uint32 print_vnode_path(afs_vnode *v, XFILE *X, void *refcon)
{
  afs_uint32 r;
  char *name = 0;

  /* Do repair, but only for known vnode types */
  if (gendump_path
  &&  (!(v->field_mask & F_VNODE_TYPE)
       || v->type != vFile
       || v->type != vDirectory
       || v->type != vSymlink)) {
    r = repair_vnode_cb(v, X, refcon);
    if (r) return r;
  }
  r = Path_Build(X, &phi, v->vnode, &name, 0);
  if (!r && name) printf(" Path: %s\n", name);
  if (name) free(name);
  return r;
}
Example #4
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;
}