Lines Matching refs:file_hdr
69 struct file_header file_hdr; member
310 struct file_header *file_hdr = &tar->file_hdr; in extract_to_stdout() local
312 copy_in_out(tar->src_fd, 0, file_hdr->size); in extract_to_stdout()
313 tar->offset += file_hdr->size; in extract_to_stdout()
320 struct file_header *file_hdr = &tar->file_hdr; in extract_to_command() local
323 if (!S_ISREG(file_hdr->mode)) return; //only regular files are supported. in extract_to_command()
332 sprintf(buf, "%0o", file_hdr->mode); in extract_to_command()
334 sprintf(buf, "%ld", (long)file_hdr->size); in extract_to_command()
336 setenv("TAR_FILENAME", file_hdr->name, 1); in extract_to_command()
337 setenv("TAR_UNAME", file_hdr->uname, 1); in extract_to_command()
338 setenv("TAR_GNAME", file_hdr->gname, 1); in extract_to_command()
339 sprintf(buf, "%0o", (int)file_hdr->mtime); in extract_to_command()
341 sprintf(buf, "%0o", file_hdr->uid); in extract_to_command()
343 sprintf(buf, "%0o", file_hdr->gid); in extract_to_command()
352 copy_in_out(tar->src_fd, pipefd[1], file_hdr->size); in extract_to_command()
353 tar->offset += file_hdr->size; in extract_to_command()
366 struct file_header *file_hdr = &tar->file_hdr; in extract_to_disk() local
368 if (file_hdr->name[strlen(file_hdr->name)-1] == '/') in extract_to_disk()
369 file_hdr->name[strlen(file_hdr->name)-1] = 0; in extract_to_disk()
371 if ((s = strrchr(file_hdr->name, '/'))) { in extract_to_disk()
372 if (mkpathat(AT_FDCWD, file_hdr->name, 00, 2) && errno !=EEXIST) { in extract_to_disk()
373 error_msg(":%s: not created", file_hdr->name); in extract_to_disk()
379 if (!(toys.optflags & FLAG_k) && !S_ISDIR(file_hdr->mode) in extract_to_disk()
380 && !lstat( file_hdr->name, &ex)) { in extract_to_disk()
381 if (unlink(file_hdr->name)) { in extract_to_disk()
382 perror_msg("can't remove: %s",file_hdr->name); in extract_to_disk()
387 if (S_ISREG(file_hdr->mode) && file_hdr->link_target) { in extract_to_disk()
388 if (link(file_hdr->link_target, file_hdr->name)) in extract_to_disk()
389 perror_msg("can't link '%s' -> '%s'",file_hdr->name, file_hdr->link_target); in extract_to_disk()
393 switch (file_hdr->mode & S_IFMT) { in extract_to_disk()
397 dst_fd = open(file_hdr->name, flags, file_hdr->mode & 07777); in extract_to_disk()
398 if (dst_fd == -1) perror_msg("%s: can't open", file_hdr->name); in extract_to_disk()
401 if ((mkdir(file_hdr->name, file_hdr->mode) == -1) && errno != EEXIST) in extract_to_disk()
402 perror_msg("%s: can't create", file_hdr->name); in extract_to_disk()
405 if (symlink(file_hdr->link_target, file_hdr->name)) in extract_to_disk()
406 perror_msg("can't link '%s' -> '%s'",file_hdr->name, file_hdr->link_target); in extract_to_disk()
411 if (mknod(file_hdr->name, file_hdr->mode, file_hdr->device)) in extract_to_disk()
412 perror_msg("can't create '%s'", file_hdr->name); in extract_to_disk()
421 copy_in_out(tar->src_fd, dst_fd, file_hdr->size); in extract_to_disk()
422 tar->offset += file_hdr->size; in extract_to_disk()
425 if (S_ISLNK(file_hdr->mode)) return; in extract_to_disk()
428 uid_t u = file_hdr->uid; in extract_to_disk()
429 gid_t g = file_hdr->gid; in extract_to_disk()
432 struct group *gr = getgrnam(file_hdr->gname); in extract_to_disk()
433 struct passwd *pw = getpwnam(file_hdr->uname); in extract_to_disk()
437 if (chown(file_hdr->name, u, g)) in extract_to_disk()
438 perror_msg("chown %d:%d '%s'", u, g, file_hdr->name);; in extract_to_disk()
442 chmod(file_hdr->name, file_hdr->mode); in extract_to_disk()
446 struct timeval times[2] = {{file_hdr->mtime, 0},{file_hdr->mtime, 0}}; in extract_to_disk()
447 utimes(file_hdr->name, times); in extract_to_disk()
571 struct file_header *file_hdr; in unpack_tar() local
615 file_hdr = &tar_hdl->file_hdr; in unpack_tar()
616 memset(file_hdr, 0, sizeof(struct file_header)); in unpack_tar()
617 file_hdr->mode = otoi(tar.mode, sizeof(tar.mode)); in unpack_tar()
618 file_hdr->uid = otoi(tar.uid, sizeof(tar.uid)); in unpack_tar()
619 file_hdr->gid = otoi(tar.gid, sizeof(tar.gid)); in unpack_tar()
620 file_hdr->size = otoi(tar.size, sizeof(tar.size)); in unpack_tar()
621 file_hdr->mtime = otoi(tar.mtime, sizeof(tar.mtime)); in unpack_tar()
622 file_hdr->uname = xstrdup(tar.uname); in unpack_tar()
623 file_hdr->gname = xstrdup(tar.gname); in unpack_tar()
626 file_hdr->device = makedev(maj, min); in unpack_tar()
631 file_hdr->link_target = xmalloc(sz + 1); in unpack_tar()
632 memcpy(file_hdr->link_target, tar.link, sz); in unpack_tar()
633 file_hdr->link_target[sz] = '\0'; in unpack_tar()
636 file_hdr->name = xzalloc(256);// pathname supported size in unpack_tar()
638 memcpy(file_hdr->name, tar.prefix, sizeof(tar.prefix)); in unpack_tar()
639 sz = strlen(file_hdr->name); in unpack_tar()
640 if (file_hdr->name[sz-1] != '/') file_hdr->name[sz] = '/'; in unpack_tar()
642 sz = strlen(file_hdr->name); in unpack_tar()
643 memcpy(file_hdr->name + sz, tar.name, sizeof(tar.name)); in unpack_tar()
644 if (file_hdr->name[255]) error_exit("filename too long"); in unpack_tar()
652 file_hdr->mode |= S_IFREG; in unpack_tar()
655 file_hdr->mode |= S_IFLNK; in unpack_tar()
658 file_hdr->mode |= S_IFCHR; in unpack_tar()
661 file_hdr->mode |= S_IFBLK; in unpack_tar()
664 file_hdr->mode |= S_IFDIR; in unpack_tar()
667 file_hdr->mode |= S_IFIFO; in unpack_tar()
670 longlink = xzalloc(file_hdr->size +1); in unpack_tar()
671 xread(tar_hdl->src_fd, longlink, file_hdr->size); in unpack_tar()
672 tar_hdl->offset += file_hdr->size; in unpack_tar()
676 longname = xzalloc(file_hdr->size +1); in unpack_tar()
677 xread(tar_hdl->src_fd, longname, file_hdr->size); in unpack_tar()
678 tar_hdl->offset += file_hdr->size; in unpack_tar()
686 tar_skip(tar_hdl, file_hdr->size); in unpack_tar()
690 longname = process_extended_hdr(tar_hdl, file_hdr->size); in unpack_tar()
696 free(file_hdr->name); in unpack_tar()
697 file_hdr->name = longname; in unpack_tar()
701 free(file_hdr->link_target); in unpack_tar()
702 file_hdr->link_target = longlink; in unpack_tar()
706 if ((file_hdr->mode & S_IFREG) && in unpack_tar()
707 file_hdr->name[strlen(file_hdr->name)-1] == '/') { in unpack_tar()
708 file_hdr->name[strlen(file_hdr->name)-1] = '\0'; in unpack_tar()
709 file_hdr->mode &= ~S_IFREG; in unpack_tar()
710 file_hdr->mode |= S_IFDIR; in unpack_tar()
713 if ((file_hdr->link_target && *(file_hdr->link_target)) in unpack_tar()
714 || S_ISLNK(file_hdr->mode) || S_ISDIR(file_hdr->mode)) in unpack_tar()
715 file_hdr->size = 0; in unpack_tar()
717 if (filter(TT.exc, file_hdr->name) || in unpack_tar()
718 (TT.inc && !filter(TT.inc, file_hdr->name))) goto SKIP; in unpack_tar()
719 add_to_list(&TT.pass, xstrdup(file_hdr->name)); in unpack_tar()
724 struct tm *lc = localtime((const time_t*)&(file_hdr->mtime)); in unpack_tar()
726 mode_to_string(file_hdr->mode, perm); in unpack_tar()
727 printf("%s %s/%s %9ld %d-%02d-%02d %02d:%02d:%02d ",perm,file_hdr->uname, in unpack_tar()
728 file_hdr->gname, (long)file_hdr->size, 1900+lc->tm_year, in unpack_tar()
731 printf("%s",file_hdr->name); in unpack_tar()
732 if (file_hdr->link_target) printf(" -> %s",file_hdr->link_target); in unpack_tar()
735 tar_skip(tar_hdl, file_hdr->size); in unpack_tar()
737 if (toys.optflags & FLAG_v) printf("%s\n",file_hdr->name); in unpack_tar()
740 free(file_hdr->name); in unpack_tar()
741 free(file_hdr->link_target); in unpack_tar()
742 free(file_hdr->uname); in unpack_tar()
743 free(file_hdr->gname); in unpack_tar()