Lines Matching refs:file_hdr
70 struct file_header file_hdr; member
311 struct file_header *file_hdr = &tar->file_hdr; in extract_to_stdout() local
313 copy_in_out(tar->src_fd, 0, file_hdr->size); in extract_to_stdout()
314 tar->offset += file_hdr->size; in extract_to_stdout()
321 struct file_header *file_hdr = &tar->file_hdr; in extract_to_command() local
324 if (!S_ISREG(file_hdr->mode)) return; //only regular files are supported. in extract_to_command()
333 sprintf(buf, "%0o", file_hdr->mode); in extract_to_command()
335 sprintf(buf, "%ld", (long)file_hdr->size); in extract_to_command()
337 setenv("TAR_FILENAME", file_hdr->name, 1); in extract_to_command()
338 setenv("TAR_UNAME", file_hdr->uname, 1); in extract_to_command()
339 setenv("TAR_GNAME", file_hdr->gname, 1); in extract_to_command()
340 sprintf(buf, "%0o", (int)file_hdr->mtime); in extract_to_command()
342 sprintf(buf, "%0o", file_hdr->uid); in extract_to_command()
344 sprintf(buf, "%0o", file_hdr->gid); in extract_to_command()
353 copy_in_out(tar->src_fd, pipefd[1], file_hdr->size); in extract_to_command()
354 tar->offset += file_hdr->size; in extract_to_command()
367 struct file_header *file_hdr = &tar->file_hdr; in extract_to_disk() local
369 flags = strlen(file_hdr->name); in extract_to_disk()
371 if (strstr(file_hdr->name, "/../") || !strcmp(file_hdr->name, "../") || in extract_to_disk()
372 !strcmp(file_hdr->name+flags-3, "/..")) in extract_to_disk()
374 error_msg("drop %s", file_hdr->name); in extract_to_disk()
378 if (file_hdr->name[flags-1] == '/') file_hdr->name[flags-1] = 0; in extract_to_disk()
380 if ((s = strrchr(file_hdr->name, '/'))) { in extract_to_disk()
381 if (mkpath(file_hdr->name) && errno !=EEXIST) { in extract_to_disk()
382 error_msg(":%s: not created", file_hdr->name); in extract_to_disk()
388 if (!(toys.optflags & FLAG_k) && !S_ISDIR(file_hdr->mode) in extract_to_disk()
389 && !lstat( file_hdr->name, &ex)) { in extract_to_disk()
390 if (unlink(file_hdr->name)) { in extract_to_disk()
391 perror_msg("can't remove: %s",file_hdr->name); in extract_to_disk()
396 if (S_ISREG(file_hdr->mode) && file_hdr->link_target) { in extract_to_disk()
397 if (link(file_hdr->link_target, file_hdr->name)) in extract_to_disk()
398 perror_msg("can't link '%s' -> '%s'",file_hdr->name, file_hdr->link_target); in extract_to_disk()
402 switch (file_hdr->mode & S_IFMT) { in extract_to_disk()
406 dst_fd = open(file_hdr->name, flags, file_hdr->mode & 07777); in extract_to_disk()
407 if (dst_fd == -1) perror_msg("%s: can't open", file_hdr->name); in extract_to_disk()
410 if ((mkdir(file_hdr->name, file_hdr->mode) == -1) && errno != EEXIST) in extract_to_disk()
411 perror_msg("%s: can't create", file_hdr->name); in extract_to_disk()
414 if (symlink(file_hdr->link_target, file_hdr->name)) in extract_to_disk()
415 perror_msg("can't link '%s' -> '%s'",file_hdr->name, file_hdr->link_target); in extract_to_disk()
420 if (mknod(file_hdr->name, file_hdr->mode, file_hdr->device)) in extract_to_disk()
421 perror_msg("can't create '%s'", file_hdr->name); in extract_to_disk()
430 copy_in_out(tar->src_fd, dst_fd, file_hdr->size); in extract_to_disk()
431 tar->offset += file_hdr->size; in extract_to_disk()
434 if (S_ISLNK(file_hdr->mode)) return; in extract_to_disk()
437 uid_t u = file_hdr->uid; in extract_to_disk()
438 gid_t g = file_hdr->gid; in extract_to_disk()
441 struct group *gr = getgrnam(file_hdr->gname); in extract_to_disk()
442 struct passwd *pw = getpwnam(file_hdr->uname); in extract_to_disk()
446 if (chown(file_hdr->name, u, g)) in extract_to_disk()
447 perror_msg("chown %d:%d '%s'", u, g, file_hdr->name);; in extract_to_disk()
451 chmod(file_hdr->name, file_hdr->mode); in extract_to_disk()
455 struct timeval times[2] = {{file_hdr->mtime, 0},{file_hdr->mtime, 0}}; in extract_to_disk()
456 utimes(file_hdr->name, times); in extract_to_disk()
581 struct file_header *file_hdr; in unpack_tar() local
624 file_hdr = &tar_hdl->file_hdr; in unpack_tar()
625 memset(file_hdr, 0, sizeof(struct file_header)); in unpack_tar()
626 file_hdr->mode = otoi(tar.mode, sizeof(tar.mode)); in unpack_tar()
627 file_hdr->uid = otoi(tar.uid, sizeof(tar.uid)); in unpack_tar()
628 file_hdr->gid = otoi(tar.gid, sizeof(tar.gid)); in unpack_tar()
629 file_hdr->size = otoi(tar.size, sizeof(tar.size)); in unpack_tar()
630 file_hdr->mtime = otoi(tar.mtime, sizeof(tar.mtime)); in unpack_tar()
631 file_hdr->uname = xstrdup(tar.uname); in unpack_tar()
632 file_hdr->gname = xstrdup(tar.gname); in unpack_tar()
635 file_hdr->device = dev_makedev(maj, min); in unpack_tar()
640 file_hdr->link_target = xmalloc(sz + 1); in unpack_tar()
641 memcpy(file_hdr->link_target, tar.link, sz); in unpack_tar()
642 file_hdr->link_target[sz] = '\0'; in unpack_tar()
645 file_hdr->name = xzalloc(256);// pathname supported size in unpack_tar()
647 memcpy(file_hdr->name, tar.prefix, sizeof(tar.prefix)); in unpack_tar()
648 sz = strlen(file_hdr->name); in unpack_tar()
649 if (file_hdr->name[sz-1] != '/') file_hdr->name[sz] = '/'; in unpack_tar()
651 sz = strlen(file_hdr->name); in unpack_tar()
652 memcpy(file_hdr->name + sz, tar.name, sizeof(tar.name)); in unpack_tar()
653 if (file_hdr->name[255]) error_exit("filename too long"); in unpack_tar()
661 file_hdr->mode |= S_IFREG; in unpack_tar()
664 file_hdr->mode |= S_IFLNK; in unpack_tar()
667 file_hdr->mode |= S_IFCHR; in unpack_tar()
670 file_hdr->mode |= S_IFBLK; in unpack_tar()
673 file_hdr->mode |= S_IFDIR; in unpack_tar()
676 file_hdr->mode |= S_IFIFO; in unpack_tar()
679 longlink = xzalloc(file_hdr->size +1); in unpack_tar()
680 xread(tar_hdl->src_fd, longlink, file_hdr->size); in unpack_tar()
681 tar_hdl->offset += file_hdr->size; in unpack_tar()
685 longname = xzalloc(file_hdr->size +1); in unpack_tar()
686 xread(tar_hdl->src_fd, longname, file_hdr->size); in unpack_tar()
687 tar_hdl->offset += file_hdr->size; in unpack_tar()
695 tar_skip(tar_hdl, file_hdr->size); in unpack_tar()
699 longname = process_extended_hdr(tar_hdl, file_hdr->size); in unpack_tar()
705 free(file_hdr->name); in unpack_tar()
706 file_hdr->name = longname; in unpack_tar()
710 free(file_hdr->link_target); in unpack_tar()
711 file_hdr->link_target = longlink; in unpack_tar()
715 if ((file_hdr->mode & S_IFREG) && in unpack_tar()
716 file_hdr->name[strlen(file_hdr->name)-1] == '/') { in unpack_tar()
717 file_hdr->name[strlen(file_hdr->name)-1] = '\0'; in unpack_tar()
718 file_hdr->mode &= ~S_IFREG; in unpack_tar()
719 file_hdr->mode |= S_IFDIR; in unpack_tar()
722 if ((file_hdr->link_target && *(file_hdr->link_target)) in unpack_tar()
723 || S_ISLNK(file_hdr->mode) || S_ISDIR(file_hdr->mode)) in unpack_tar()
724 file_hdr->size = 0; in unpack_tar()
726 if (filter(TT.exc, file_hdr->name) || in unpack_tar()
727 (TT.inc && !filter(TT.inc, file_hdr->name))) goto SKIP; in unpack_tar()
728 add_to_list(&TT.pass, xstrdup(file_hdr->name)); in unpack_tar()
733 struct tm *lc = localtime((const time_t*)&(file_hdr->mtime)); in unpack_tar()
735 mode_to_string(file_hdr->mode, perm); in unpack_tar()
736 printf("%s %s/%s %9ld %d-%02d-%02d %02d:%02d:%02d ",perm,file_hdr->uname, in unpack_tar()
737 file_hdr->gname, (long)file_hdr->size, 1900+lc->tm_year, in unpack_tar()
740 printf("%s",file_hdr->name); in unpack_tar()
741 if (file_hdr->link_target) printf(" -> %s",file_hdr->link_target); in unpack_tar()
744 tar_skip(tar_hdl, file_hdr->size); in unpack_tar()
746 if (toys.optflags & FLAG_v) printf("%s\n",file_hdr->name); in unpack_tar()
749 free(file_hdr->name); in unpack_tar()
750 free(file_hdr->link_target); in unpack_tar()
751 free(file_hdr->uname); in unpack_tar()
752 free(file_hdr->gname); in unpack_tar()