From a68d0d1fe48afc7a7a7fd0ee42df1607f21fa996 Mon Sep 17 00:00:00 2001 From: Badhri Jagan Sridharan Date: Tue, 2 Jun 2015 14:47:57 -0700 Subject: [PATCH] libziparchive: fix fallocate failures The objective of fallocate call seems to be to make sure that we have enough enough space left in the disk to house the uncompressed file. But, fallocate is only supported in the following file systems: btrfs, ext4, ocfs2, and xfs Return error only when fallocate fails due to lack of space. The immediate ftruncate call is going to take of the majority of other errors. Bug: 21561449 Change-Id: I7083f3c7e5d745bd6e8a190ac9020297d638d9d4 --- libziparchive/zip_archive.cc | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/libziparchive/zip_archive.cc b/libziparchive/zip_archive.cc index 79c4c53c7..b2a9f88c5 100644 --- a/libziparchive/zip_archive.cc +++ b/libziparchive/zip_archive.cc @@ -1008,8 +1008,13 @@ class FileWriter : public Writer { // entry. Note that the call to ftruncate below will change the file size but // will not allocate space on disk and this call to fallocate will not // change the file size. + // Note: fallocate is only supported by the following filesystems - + // btrfs, ext4, ocfs2, and xfs. Therefore fallocate might fail with + // EOPNOTSUPP error when issued in other filesystems. + // Hence, check for the return error code before concluding that the + // disk does not have enough space. result = TEMP_FAILURE_RETRY(fallocate(fd, 0, current_offset, declared_length)); - if (result == -1) { + if (result == -1 && errno == ENOSPC) { ALOGW("Zip: unable to allocate space for file to %" PRId64 ": %s", static_cast(declared_length + current_offset), strerror(errno)); return std::unique_ptr(nullptr);