003 File Manager
Current Path:
/usr/src/contrib/libarchive/libarchive
usr
/
src
/
contrib
/
libarchive
/
libarchive
/
📁
..
📄
archive.h
(51.93 KB)
📄
archive_acl.c
(51.2 KB)
📄
archive_acl_private.h
(3.13 KB)
📄
archive_blake2.h
(6.32 KB)
📄
archive_blake2_impl.h
(4.12 KB)
📄
archive_blake2s_ref.c
(9.46 KB)
📄
archive_blake2sp_ref.c
(9.11 KB)
📄
archive_check_magic.c
(4.7 KB)
📄
archive_cmdline.c
(5.21 KB)
📄
archive_cmdline_private.h
(1.82 KB)
📄
archive_crc32.h
(2.97 KB)
📄
archive_cryptor.c
(13.46 KB)
📄
archive_cryptor_private.h
(6.02 KB)
📄
archive_digest.c
(28.79 KB)
📄
archive_digest_private.h
(13.88 KB)
📄
archive_disk_acl_freebsd.c
(18.86 KB)
📄
archive_endian.h
(5.28 KB)
📄
archive_entry.3
(4.85 KB)
📄
archive_entry.c
(53.48 KB)
📄
archive_entry.h
(32.79 KB)
📄
archive_entry_acl.3
(14.32 KB)
📄
archive_entry_copy_stat.c
(3.73 KB)
📄
archive_entry_link_resolver.c
(11.74 KB)
📄
archive_entry_linkify.3
(5.9 KB)
📄
archive_entry_locale.h
(4.41 KB)
📄
archive_entry_misc.3
(2.47 KB)
📄
archive_entry_paths.3
(5.53 KB)
📄
archive_entry_perms.3
(7.59 KB)
📄
archive_entry_private.h
(6.09 KB)
📄
archive_entry_sparse.c
(3.95 KB)
📄
archive_entry_stat.3
(8.1 KB)
📄
archive_entry_stat.c
(4.29 KB)
📄
archive_entry_strmode.c
(2.6 KB)
📄
archive_entry_time.3
(4.5 KB)
📄
archive_entry_xattr.c
(3.86 KB)
📄
archive_getdate.c
(29.9 KB)
📄
archive_getdate.h
(1.56 KB)
📄
archive_hmac.c
(7.32 KB)
📄
archive_hmac_private.h
(3.59 KB)
📄
archive_match.c
(47.14 KB)
📄
archive_openssl_evp_private.h
(1.92 KB)
📄
archive_openssl_hmac_private.h
(1.98 KB)
📄
archive_options.c
(5.22 KB)
📄
archive_options_private.h
(2.02 KB)
📄
archive_pack_dev.c
(9.13 KB)
📄
archive_pack_dev.h
(2.08 KB)
📄
archive_pathmatch.c
(10.64 KB)
📄
archive_pathmatch.h
(2.09 KB)
📄
archive_platform.h
(5.93 KB)
📄
archive_platform_acl.h
(2 KB)
📄
archive_platform_xattr.h
(1.82 KB)
📄
archive_ppmd7.c
(27.63 KB)
📄
archive_ppmd7_private.h
(3.01 KB)
📄
archive_ppmd8.c
(31.05 KB)
📄
archive_ppmd8_private.h
(3.82 KB)
📄
archive_ppmd_private.h
(3.31 KB)
📄
archive_private.h
(5.56 KB)
📄
archive_random.c
(6.67 KB)
📄
archive_random_private.h
(1.6 KB)
📄
archive_rb.c
(20.84 KB)
📄
archive_rb.h
(4.43 KB)
📄
archive_read.3
(7.18 KB)
📄
archive_read.c
(48.21 KB)
📄
archive_read_add_passphrase.3
(2.48 KB)
📄
archive_read_add_passphrase.c
(5.21 KB)
📄
archive_read_append_filter.c
(6.1 KB)
📄
archive_read_data.3
(4.23 KB)
📄
archive_read_data_into_fd.c
(3.94 KB)
📄
archive_read_disk.3
(10.36 KB)
📄
archive_read_disk_entry_from_file.c
(27.96 KB)
📄
archive_read_disk_posix.c
(72.18 KB)
📄
archive_read_disk_private.h
(3.31 KB)
📄
archive_read_disk_set_standard_lookup.c
(8.03 KB)
📄
archive_read_extract.3
(4.39 KB)
📄
archive_read_extract.c
(2.21 KB)
📄
archive_read_extract2.c
(4.5 KB)
📄
archive_read_filter.3
(5.56 KB)
📄
archive_read_format.3
(5.97 KB)
📄
archive_read_free.3
(3.07 KB)
📄
archive_read_header.3
(2.97 KB)
📄
archive_read_new.3
(2.08 KB)
📄
archive_read_open.3
(6.78 KB)
📄
archive_read_open_fd.c
(5.92 KB)
📄
archive_read_open_file.c
(4.9 KB)
📄
archive_read_open_filename.c
(17.56 KB)
📄
archive_read_open_memory.c
(5.43 KB)
📄
archive_read_private.h
(9.26 KB)
📄
archive_read_set_format.c
(3.43 KB)
📄
archive_read_set_options.3
(6.53 KB)
📄
archive_read_set_options.c
(4.6 KB)
📄
archive_read_support_filter_all.c
(3.5 KB)
📄
archive_read_support_filter_by_code.c
(2.76 KB)
📄
archive_read_support_filter_bzip2.c
(9.93 KB)
📄
archive_read_support_filter_compress.c
(13.44 KB)
📄
archive_read_support_filter_grzip.c
(3.52 KB)
📄
archive_read_support_filter_gzip.c
(13.48 KB)
📄
archive_read_support_filter_lrzip.c
(3.79 KB)
📄
archive_read_support_filter_lz4.c
(20.26 KB)
📄
archive_read_support_filter_lzop.c
(13.59 KB)
📄
archive_read_support_filter_none.c
(1.87 KB)
📄
archive_read_support_filter_program.c
(13.21 KB)
📄
archive_read_support_filter_rpm.c
(6.84 KB)
📄
archive_read_support_filter_uu.c
(18.34 KB)
📄
archive_read_support_filter_xz.c
(21.51 KB)
📄
archive_read_support_filter_zstd.c
(7.59 KB)
📄
archive_read_support_format_7zip.c
(97.12 KB)
📄
archive_read_support_format_all.c
(3.47 KB)
📄
archive_read_support_format_ar.c
(17.4 KB)
📄
archive_read_support_format_by_code.c
(2.99 KB)
📄
archive_read_support_format_cab.c
(83 KB)
📄
archive_read_support_format_cpio.c
(31.93 KB)
📄
archive_read_support_format_empty.c
(2.93 KB)
📄
archive_read_support_format_iso9660.c
(92.13 KB)
📄
archive_read_support_format_lha.c
(83.33 KB)
📄
archive_read_support_format_mtree.c
(51.86 KB)
📄
archive_read_support_format_rar.c
(84.34 KB)
📄
archive_read_support_format_rar5.c
(107.18 KB)
📄
archive_read_support_format_raw.c
(5.43 KB)
📄
archive_read_support_format_tar.c
(83.23 KB)
📄
archive_read_support_format_warc.c
(21.17 KB)
📄
archive_read_support_format_xar.c
(79.96 KB)
📄
archive_read_support_format_zip.c
(117.12 KB)
📄
archive_string.c
(104.04 KB)
📄
archive_string.h
(9.26 KB)
📄
archive_string_composition.h
(80.15 KB)
📄
archive_string_sprintf.c
(5.13 KB)
📄
archive_util.3
(6.97 KB)
📄
archive_util.c
(14.54 KB)
📄
archive_version_details.c
(3.55 KB)
📄
archive_virtual.c
(3.95 KB)
📄
archive_write.3
(7.32 KB)
📄
archive_write.c
(21.65 KB)
📄
archive_write_add_filter.c
(2.63 KB)
📄
archive_write_add_filter_b64encode.c
(8.41 KB)
📄
archive_write_add_filter_by_name.c
(2.65 KB)
📄
archive_write_add_filter_bzip2.c
(11.14 KB)
📄
archive_write_add_filter_compress.c
(12.62 KB)
📄
archive_write_add_filter_grzip.c
(4.22 KB)
📄
archive_write_add_filter_gzip.c
(12.34 KB)
📄
archive_write_add_filter_lrzip.c
(5.72 KB)
📄
archive_write_add_filter_lz4.c
(18.85 KB)
📄
archive_write_add_filter_lzop.c
(13.69 KB)
📄
archive_write_add_filter_none.c
(1.67 KB)
📄
archive_write_add_filter_program.c
(9.77 KB)
📄
archive_write_add_filter_uuencode.c
(8.09 KB)
📄
archive_write_add_filter_xz.c
(14.97 KB)
📄
archive_write_add_filter_zstd.c
(10.7 KB)
📄
archive_write_blocksize.3
(4.13 KB)
📄
archive_write_data.3
(3.09 KB)
📄
archive_write_disk.3
(11.82 KB)
📄
archive_write_disk_posix.c
(123.89 KB)
📄
archive_write_disk_private.h
(1.77 KB)
📄
archive_write_disk_set_standard_lookup.c
(6.91 KB)
📄
archive_write_filter.3
(4.47 KB)
📄
archive_write_finish_entry.3
(2.67 KB)
📄
archive_write_format.3
(5.99 KB)
📄
archive_write_free.3
(3.05 KB)
📄
archive_write_header.3
(2.44 KB)
📄
archive_write_new.3
(2.02 KB)
📄
archive_write_open.3
(8.01 KB)
📄
archive_write_open_fd.c
(3.9 KB)
📄
archive_write_open_file.c
(2.93 KB)
📄
archive_write_open_filename.c
(6.85 KB)
📄
archive_write_open_memory.c
(3.61 KB)
📄
archive_write_private.h
(5.64 KB)
📄
archive_write_set_format.c
(4 KB)
📄
archive_write_set_format_7zip.c
(55.14 KB)
📄
archive_write_set_format_ar.c
(14.08 KB)
📄
archive_write_set_format_by_name.c
(3.35 KB)
📄
archive_write_set_format_cpio.c
(14.24 KB)
📄
archive_write_set_format_cpio_newc.c
(13.11 KB)
📄
archive_write_set_format_filter_by_ext.c
(4.67 KB)
📄
archive_write_set_format_gnutar.c
(22.62 KB)
📄
archive_write_set_format_iso9660.c
(206.67 KB)
📄
archive_write_set_format_mtree.c
(58.1 KB)
📄
archive_write_set_format_pax.c
(59.85 KB)
📄
archive_write_set_format_private.h
(1.71 KB)
📄
archive_write_set_format_raw.c
(3.65 KB)
📄
archive_write_set_format_shar.c
(16.93 KB)
📄
archive_write_set_format_ustar.c
(21.98 KB)
📄
archive_write_set_format_v7tar.c
(18.02 KB)
📄
archive_write_set_format_warc.c
(11.2 KB)
📄
archive_write_set_format_xar.c
(79.49 KB)
📄
archive_write_set_format_zip.c
(48.7 KB)
📄
archive_write_set_options.3
(21.85 KB)
📄
archive_write_set_options.c
(4.07 KB)
📄
archive_write_set_passphrase.3
(2.46 KB)
📄
archive_write_set_passphrase.c
(2.89 KB)
📄
archive_xxhash.h
(1.86 KB)
📄
cpio.5
(10.45 KB)
📄
filter_fork.h
(1.68 KB)
📄
filter_fork_posix.c
(6.18 KB)
📄
libarchive-formats.5
(18.29 KB)
📄
libarchive.3
(8.02 KB)
📄
libarchive_changes.3
(9.95 KB)
📄
libarchive_internals.3
(13.36 KB)
📄
tar.5
(31 KB)
📁
test
📄
xxhash.c
(15.77 KB)
Editing: archive_entry_link_resolver.c
/*- * Copyright (c) 2003-2007 Tim Kientzle * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "archive_platform.h" __FBSDID("$FreeBSD$"); #ifdef HAVE_SYS_STAT_H #include <sys/stat.h> #endif #ifdef HAVE_ERRNO_H #include <errno.h> #endif #include <stdio.h> #ifdef HAVE_STDLIB_H #include <stdlib.h> #endif #ifdef HAVE_STRING_H #include <string.h> #endif #include "archive.h" #include "archive_entry.h" /* * This is mostly a pretty straightforward hash table implementation. * The only interesting bit is the different strategies used to * match up links. These strategies match those used by various * archiving formats: * tar - content stored with first link, remainder refer back to it. * This requires us to match each subsequent link up with the * first appearance. * cpio - Old cpio just stored body with each link, match-ups were * implicit. This is trivial. * new cpio - New cpio only stores body with last link, match-ups * are implicit. This is actually quite tricky; see the notes * below. */ /* Users pass us a format code, we translate that into a strategy here. */ #define ARCHIVE_ENTRY_LINKIFY_LIKE_TAR 0 #define ARCHIVE_ENTRY_LINKIFY_LIKE_MTREE 1 #define ARCHIVE_ENTRY_LINKIFY_LIKE_OLD_CPIO 2 #define ARCHIVE_ENTRY_LINKIFY_LIKE_NEW_CPIO 3 /* Initial size of link cache. */ #define links_cache_initial_size 1024 struct links_entry { struct links_entry *next; struct links_entry *previous; struct archive_entry *canonical; struct archive_entry *entry; size_t hash; unsigned int links; /* # links not yet seen */ }; struct archive_entry_linkresolver { struct links_entry **buckets; struct links_entry *spare; unsigned long number_entries; size_t number_buckets; int strategy; }; #define NEXT_ENTRY_DEFERRED 1 #define NEXT_ENTRY_PARTIAL 2 #define NEXT_ENTRY_ALL (NEXT_ENTRY_DEFERRED | NEXT_ENTRY_PARTIAL) static struct links_entry *find_entry(struct archive_entry_linkresolver *, struct archive_entry *); static void grow_hash(struct archive_entry_linkresolver *); static struct links_entry *insert_entry(struct archive_entry_linkresolver *, struct archive_entry *); static struct links_entry *next_entry(struct archive_entry_linkresolver *, int); struct archive_entry_linkresolver * archive_entry_linkresolver_new(void) { struct archive_entry_linkresolver *res; /* Check for positive power-of-two */ if (links_cache_initial_size == 0 || (links_cache_initial_size & (links_cache_initial_size - 1)) != 0) return (NULL); res = calloc(1, sizeof(struct archive_entry_linkresolver)); if (res == NULL) return (NULL); res->number_buckets = links_cache_initial_size; res->buckets = calloc(res->number_buckets, sizeof(res->buckets[0])); if (res->buckets == NULL) { free(res); return (NULL); } return (res); } void archive_entry_linkresolver_set_strategy(struct archive_entry_linkresolver *res, int fmt) { int fmtbase = fmt & ARCHIVE_FORMAT_BASE_MASK; switch (fmtbase) { case ARCHIVE_FORMAT_7ZIP: case ARCHIVE_FORMAT_AR: case ARCHIVE_FORMAT_ZIP: res->strategy = ARCHIVE_ENTRY_LINKIFY_LIKE_OLD_CPIO; break; case ARCHIVE_FORMAT_CPIO: switch (fmt) { case ARCHIVE_FORMAT_CPIO_SVR4_NOCRC: case ARCHIVE_FORMAT_CPIO_SVR4_CRC: res->strategy = ARCHIVE_ENTRY_LINKIFY_LIKE_NEW_CPIO; break; default: res->strategy = ARCHIVE_ENTRY_LINKIFY_LIKE_OLD_CPIO; break; } break; case ARCHIVE_FORMAT_MTREE: res->strategy = ARCHIVE_ENTRY_LINKIFY_LIKE_MTREE; break; case ARCHIVE_FORMAT_ISO9660: case ARCHIVE_FORMAT_SHAR: case ARCHIVE_FORMAT_TAR: case ARCHIVE_FORMAT_XAR: res->strategy = ARCHIVE_ENTRY_LINKIFY_LIKE_TAR; break; default: res->strategy = ARCHIVE_ENTRY_LINKIFY_LIKE_OLD_CPIO; break; } } void archive_entry_linkresolver_free(struct archive_entry_linkresolver *res) { struct links_entry *le; if (res == NULL) return; while ((le = next_entry(res, NEXT_ENTRY_ALL)) != NULL) archive_entry_free(le->entry); free(res->buckets); free(res); } void archive_entry_linkify(struct archive_entry_linkresolver *res, struct archive_entry **e, struct archive_entry **f) { struct links_entry *le; struct archive_entry *t; *f = NULL; /* Default: Don't return a second entry. */ if (*e == NULL) { le = next_entry(res, NEXT_ENTRY_DEFERRED); if (le != NULL) { *e = le->entry; le->entry = NULL; } return; } /* If it has only one link, then we're done. */ if (archive_entry_nlink(*e) == 1) return; /* Directories, devices never have hardlinks. */ if (archive_entry_filetype(*e) == AE_IFDIR || archive_entry_filetype(*e) == AE_IFBLK || archive_entry_filetype(*e) == AE_IFCHR) return; switch (res->strategy) { case ARCHIVE_ENTRY_LINKIFY_LIKE_TAR: le = find_entry(res, *e); if (le != NULL) { archive_entry_unset_size(*e); archive_entry_copy_hardlink(*e, archive_entry_pathname(le->canonical)); } else insert_entry(res, *e); return; case ARCHIVE_ENTRY_LINKIFY_LIKE_MTREE: le = find_entry(res, *e); if (le != NULL) { archive_entry_copy_hardlink(*e, archive_entry_pathname(le->canonical)); } else insert_entry(res, *e); return; case ARCHIVE_ENTRY_LINKIFY_LIKE_OLD_CPIO: /* This one is trivial. */ return; case ARCHIVE_ENTRY_LINKIFY_LIKE_NEW_CPIO: le = find_entry(res, *e); if (le != NULL) { /* * Put the new entry in le, return the * old entry from le. */ t = *e; *e = le->entry; le->entry = t; /* Make the old entry into a hardlink. */ archive_entry_unset_size(*e); archive_entry_copy_hardlink(*e, archive_entry_pathname(le->canonical)); /* If we ran out of links, return the * final entry as well. */ if (le->links == 0) { *f = le->entry; le->entry = NULL; } } else { /* * If we haven't seen it, tuck it away * for future use. */ le = insert_entry(res, *e); if (le == NULL) /* XXX We should return an error code XXX */ return; le->entry = *e; *e = NULL; } return; default: break; } return; } static struct links_entry * find_entry(struct archive_entry_linkresolver *res, struct archive_entry *entry) { struct links_entry *le; size_t hash, bucket; dev_t dev; int64_t ino; /* Free a held entry. */ if (res->spare != NULL) { archive_entry_free(res->spare->canonical); archive_entry_free(res->spare->entry); free(res->spare); res->spare = NULL; } dev = archive_entry_dev(entry); ino = archive_entry_ino64(entry); hash = (size_t)(dev ^ ino); /* Try to locate this entry in the links cache. */ bucket = hash & (res->number_buckets - 1); for (le = res->buckets[bucket]; le != NULL; le = le->next) { if (le->hash == hash && dev == archive_entry_dev(le->canonical) && ino == archive_entry_ino64(le->canonical)) { /* * Decrement link count each time and release * the entry if it hits zero. This saves * memory and is necessary for detecting * missed links. */ --le->links; if (le->links > 0) return (le); /* Remove it from this hash bucket. */ if (le->previous != NULL) le->previous->next = le->next; if (le->next != NULL) le->next->previous = le->previous; if (res->buckets[bucket] == le) res->buckets[bucket] = le->next; res->number_entries--; /* Defer freeing this entry. */ res->spare = le; return (le); } } return (NULL); } static struct links_entry * next_entry(struct archive_entry_linkresolver *res, int mode) { struct links_entry *le; size_t bucket; /* Free a held entry. */ if (res->spare != NULL) { archive_entry_free(res->spare->canonical); archive_entry_free(res->spare->entry); free(res->spare); res->spare = NULL; } /* Look for next non-empty bucket in the links cache. */ for (bucket = 0; bucket < res->number_buckets; bucket++) { for (le = res->buckets[bucket]; le != NULL; le = le->next) { if (le->entry != NULL && (mode & NEXT_ENTRY_DEFERRED) == 0) continue; if (le->entry == NULL && (mode & NEXT_ENTRY_PARTIAL) == 0) continue; /* Remove it from this hash bucket. */ if (le->next != NULL) le->next->previous = le->previous; if (le->previous != NULL) le->previous->next = le->next; else res->buckets[bucket] = le->next; res->number_entries--; /* Defer freeing this entry. */ res->spare = le; return (le); } } return (NULL); } static struct links_entry * insert_entry(struct archive_entry_linkresolver *res, struct archive_entry *entry) { struct links_entry *le; size_t hash, bucket; /* Add this entry to the links cache. */ le = calloc(1, sizeof(struct links_entry)); if (le == NULL) return (NULL); le->canonical = archive_entry_clone(entry); /* If the links cache is getting too full, enlarge the hash table. */ if (res->number_entries > res->number_buckets * 2) grow_hash(res); hash = (size_t)(archive_entry_dev(entry) ^ archive_entry_ino64(entry)); bucket = hash & (res->number_buckets - 1); /* If we could allocate the entry, record it. */ if (res->buckets[bucket] != NULL) res->buckets[bucket]->previous = le; res->number_entries++; le->next = res->buckets[bucket]; le->previous = NULL; res->buckets[bucket] = le; le->hash = hash; le->links = archive_entry_nlink(entry) - 1; return (le); } static void grow_hash(struct archive_entry_linkresolver *res) { struct links_entry *le, **new_buckets; size_t new_size; size_t i, bucket; /* Try to enlarge the bucket list. */ new_size = res->number_buckets * 2; if (new_size < res->number_buckets) return; new_buckets = calloc(new_size, sizeof(struct links_entry *)); if (new_buckets == NULL) return; for (i = 0; i < res->number_buckets; i++) { while (res->buckets[i] != NULL) { /* Remove entry from old bucket. */ le = res->buckets[i]; res->buckets[i] = le->next; /* Add entry to new bucket. */ bucket = le->hash & (new_size - 1); if (new_buckets[bucket] != NULL) new_buckets[bucket]->previous = le; le->next = new_buckets[bucket]; le->previous = NULL; new_buckets[bucket] = le; } } free(res->buckets); res->buckets = new_buckets; res->number_buckets = new_size; } struct archive_entry * archive_entry_partial_links(struct archive_entry_linkresolver *res, unsigned int *links) { struct archive_entry *e; struct links_entry *le; /* Free a held entry. */ if (res->spare != NULL) { archive_entry_free(res->spare->canonical); archive_entry_free(res->spare->entry); free(res->spare); res->spare = NULL; } le = next_entry(res, NEXT_ENTRY_PARTIAL); if (le != NULL) { e = le->canonical; if (links != NULL) *links = le->links; le->canonical = NULL; } else { e = NULL; if (links != NULL) *links = 0; } return (e); }
Upload File
Create Folder