From e94e553a8208714e29e6674e92abb677f98028fe Mon Sep 17 00:00:00 2001 From: Xiao-Long Chen Date: Thu, 29 Oct 2015 17:17:31 -0400 Subject: [PATCH] Avoid statvfs/fstatvfs calls on systems where it is not available --- libarchive/archive_read_disk_posix.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/libarchive/archive_read_disk_posix.c b/libarchive/archive_read_disk_posix.c index f48053922..dad915176 100644 --- a/libarchive/archive_read_disk_posix.c +++ b/libarchive/archive_read_disk_posix.c @@ -1681,7 +1681,9 @@ setup_current_filesystem(struct archive_read_disk *a) { struct tree *t = a->tree; struct statfs sfs; +#if defined(HAVE_STATVFS) struct statvfs svfs; +#endif int r, vr = 0, xr = 0; if (tree_current_is_symblic_link_target(t)) { @@ -1698,7 +1700,9 @@ setup_current_filesystem(struct archive_read_disk *a) "openat failed"); return (ARCHIVE_FAILED); } +#if defined(HAVE_FSTATVFS) vr = fstatvfs(fd, &svfs);/* for f_flag, mount flags */ +#endif r = fstatfs(fd, &sfs); if (r == 0) xr = get_xfer_size(t, fd, NULL); @@ -1708,14 +1712,18 @@ setup_current_filesystem(struct archive_read_disk *a) archive_set_error(&a->archive, errno, "fchdir failed"); return (ARCHIVE_FAILED); } +#if defined(HAVE_STATVFS) vr = statvfs(tree_current_access_path(t), &svfs); +#endif r = statfs(tree_current_access_path(t), &sfs); if (r == 0) xr = get_xfer_size(t, -1, tree_current_access_path(t)); #endif } else { #ifdef HAVE_FSTATFS +#if defined(HAVE_FSTATVFS) vr = fstatvfs(tree_current_dir_fd(t), &svfs); +#endif r = fstatfs(tree_current_dir_fd(t), &sfs); if (r == 0) xr = get_xfer_size(t, tree_current_dir_fd(t), NULL); @@ -1724,7 +1732,9 @@ setup_current_filesystem(struct archive_read_disk *a) archive_set_error(&a->archive, errno, "fchdir failed"); return (ARCHIVE_FAILED); } +#if defined(HAVE_STATVFS) vr = statvfs(".", &svfs); +#endif r = statfs(".", &sfs); if (r == 0) xr = get_xfer_size(t, -1, "."); @@ -1737,10 +1747,17 @@ setup_current_filesystem(struct archive_read_disk *a) return (ARCHIVE_FAILED); } else if (xr == 1) { /* pathconf(_PC_REX_*) operations are not supported. */ +#if defined(HAVE_STATVFS) t->current_filesystem->xfer_align = svfs.f_frsize; t->current_filesystem->max_xfer_size = -1; t->current_filesystem->min_xfer_size = svfs.f_bsize; t->current_filesystem->incr_xfer_size = svfs.f_bsize; +#else + t->current_filesystem->xfer_align = sfs.f_frsize; + t->current_filesystem->max_xfer_size = -1; + t->current_filesystem->min_xfer_size = sfs.f_bsize; + t->current_filesystem->incr_xfer_size = sfs.f_bsize; +#endif } switch (sfs.f_type) { case AFS_SUPER_MAGIC: @@ -1765,7 +1782,11 @@ setup_current_filesystem(struct archive_read_disk *a) } #if defined(ST_NOATIME) +#if defined(HAVE_STATVFS) if (svfs.f_flag & ST_NOATIME) +#else + if (sfs.f_flag & ST_NOATIME) +#endif t->current_filesystem->noatime = 1; else #endif -- 2.47.2