]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
Do not depend on sys/decmpfs.h since Snow Leopard does not have it.
authorMichihiro NAKAJIMA <ggcueroad@gmail.com>
Sat, 27 Oct 2012 01:28:33 +0000 (10:28 +0900)
committerMichihiro NAKAJIMA <ggcueroad@gmail.com>
Sat, 27 Oct 2012 01:28:33 +0000 (10:28 +0900)
CMakeLists.txt
build/cmake/config.h.in
configure.ac
libarchive/archive_write_disk_posix.c

index d6ba12fa5a204c98ce42ed00edff1b2c29a2a1f6..8b4aaca2eab8de408d3a3a397f7db1450ad30bf4 100644 (file)
@@ -446,7 +446,6 @@ LA_CHECK_INCLUDE_FILE("string.h" HAVE_STRING_H)
 LA_CHECK_INCLUDE_FILE("strings.h" HAVE_STRINGS_H)
 LA_CHECK_INCLUDE_FILE("sys/acl.h" HAVE_SYS_ACL_H)
 LA_CHECK_INCLUDE_FILE("sys/cdefs.h" HAVE_SYS_CDEFS_H)
-LA_CHECK_INCLUDE_FILE("sys/decmpfs.h" HAVE_SYS_DECMPFS_H)
 LA_CHECK_INCLUDE_FILE("sys/ioctl.h" HAVE_SYS_IOCTL_H)
 LA_CHECK_INCLUDE_FILE("sys/mkdev.h" HAVE_SYS_MKDEV_H)
 LA_CHECK_INCLUDE_FILE("sys/mount.h" HAVE_SYS_MOUNT_H)
index ae0fe94faa98c351f31212d24cdb1ff2b3488c32..ab2ef2f187dd90d097037bbcd6d606071f6bd6d3 100644 (file)
@@ -845,9 +845,6 @@ typedef uint64_t uintmax_t;
 /* Define to 1 if you have the <sys/cdefs.h> header file. */
 #cmakedefine HAVE_SYS_CDEFS_H 1
 
-/* Define to 1 if you have the <sys/decmpfs.h> header file. */
-#cmakedefine HAVE_SYS_DECMPFS_H 1
-
 /* Define to 1 if you have the <sys/dir.h> header file, and it defines `DIR'.
    */
 #cmakedefine HAVE_SYS_DIR_H 1
index 9cca9dcb9e8e867b75cb41b90d1d7ff920a1e9a2..f81059575381f96a1402d27c59cf797f7df0a02c 100644 (file)
@@ -220,7 +220,7 @@ AC_CHECK_HEADERS([inttypes.h io.h langinfo.h limits.h])
 AC_CHECK_HEADERS([linux/fiemap.h linux/fs.h linux/magic.h linux/types.h])
 AC_CHECK_HEADERS([locale.h paths.h poll.h pwd.h regex.h signal.h spawn.h])
 AC_CHECK_HEADERS([stdarg.h stdint.h stdlib.h string.h])
-AC_CHECK_HEADERS([sys/acl.h sys/cdefs.h sys/decmpfs.h sys/extattr.h])
+AC_CHECK_HEADERS([sys/acl.h sys/cdefs.h sys/extattr.h])
 AC_CHECK_HEADERS([sys/ioctl.h sys/mkdev.h sys/mount.h])
 AC_CHECK_HEADERS([sys/param.h sys/poll.h sys/select.h sys/statfs.h sys/statvfs.h])
 AC_CHECK_HEADERS([sys/time.h sys/utime.h sys/utsname.h sys/vfs.h])
index 6f2ae015752fb33567872a4567772a0b72d01830..3d258e8cb14a1c8c8bc4f15a4ba6cd9104aabca9 100644 (file)
@@ -33,9 +33,6 @@ __FBSDID("$FreeBSD$");
 #ifdef HAVE_SYS_TYPES_H
 #include <sys/types.h>
 #endif
-#ifdef HAVE_SYS_DECMPFS_H
-#include <sys/decmpfs.h>
-#endif
 #ifdef HAVE_SYS_EXTATTR_H
 #include <sys/extattr.h>
 #endif
@@ -253,10 +250,9 @@ struct archive_write_disk {
        /*
         * HFS+ Compression.
         */
-#ifdef HAVE_SYS_DECMPFS_H
        /* Xattr "com.apple.decmpfs". */
-       decmpfs_header          *decmpfs_header_p;
-#endif
+       uint32_t                 decmpfs_attr_size;
+       unsigned char           *decmpfs_header_p;
        /* ResourceFork set options used for fsetxattr. */
        int                      rsrc_xattr_options;
        /* Xattr "com.apple.ResourceFork". */
@@ -313,6 +309,16 @@ struct archive_write_disk {
 #define RSRC_F_SIZE    50      /* Size of Resource fork footer. */
 /* Size to write compressed data to resource fork. */
 #define COMPRESSED_W_SIZE      (64 * 1024)
+/* decmpfs difinitions. */
+#define MAX_DECMPFS_XATTR_SIZE         3802
+#ifndef DECMPFS_XATTR_NAME
+#define DECMPFS_XATTR_NAME             "com.apple.decmpfs"
+#endif
+#define DECMPFS_MAGIC                  0x636d7066
+#define DECMPFS_COMPRESSION_MAGIC      0
+#define DECMPFS_COMPRESSION_TYPE       4
+#define DECMPFS_UNCOMPRESSED_SIZE      8
+#define DECMPFS_HEADER_SIZE            16
 
 
 static int     check_symlinks(struct archive_write_disk *);
@@ -779,7 +785,7 @@ write_data_block(struct archive_write_disk *a, const char *buff, size_t size)
        return (start_size - size);
 }
 
-#if defined(HAVE_ZLIB_H) && defined(HAVE_SYS_DECMPFS_H)
+#if defined(HAVE_ZLIB_H) && defined(UF_COMPRESSED)
 
 /*
  * HFS+ Compression decmpfs
@@ -806,25 +812,25 @@ write_data_block(struct archive_write_disk *a, const char *buff, size_t size)
 static int
 hfs_write_decmpfs(struct archive_write_disk *a)
 {
-       decmpfs_disk_header *disk_header;
        int r;
+       uint32_t compression_type;
 
+       compression_type =
+           *(uint32_t *)&a->decmpfs_header_p[DECMPFS_COMPRESSION_TYPE];
        /* Convert the endianess of decmpfs_header. */
-       disk_header = (decmpfs_disk_header *)
-           &a->decmpfs_header_p->compression_magic;
-       archive_le32enc(&disk_header->compression_magic,
-           a->decmpfs_header_p->compression_magic);
-       archive_le32enc(&disk_header->compression_type,
-           a->decmpfs_header_p->compression_type);
-       archive_le64enc(&disk_header->uncompressed_size,
-           a->decmpfs_header_p->uncompressed_size);
-
-       r = fsetxattr(a->fd, DECMPFS_XATTR_NAME, disk_header,
-           a->decmpfs_header_p->attr_size, 0, 0);
+       archive_le32enc(a->decmpfs_header_p + DECMPFS_COMPRESSION_MAGIC,
+           *(uint32_t *)(a->decmpfs_header_p + DECMPFS_COMPRESSION_MAGIC));
+       archive_le32enc(a->decmpfs_header_p + DECMPFS_COMPRESSION_TYPE,
+           *(uint32_t *)(a->decmpfs_header_p + DECMPFS_COMPRESSION_TYPE));
+       archive_le64enc(a->decmpfs_header_p + DECMPFS_UNCOMPRESSED_SIZE,
+           *(uint64_t *)(a->decmpfs_header_p + DECMPFS_UNCOMPRESSED_SIZE));
+
+       r = fsetxattr(a->fd, DECMPFS_XATTR_NAME, a->decmpfs_header_p,
+           a->decmpfs_attr_size, 0, 0);
        if (r < 0) {
                archive_set_error(&a->archive, errno,
                    "Cannot restore xattr:%s", DECMPFS_XATTR_NAME);
-               if (a->decmpfs_header_p->compression_type == CMP_RESOURCE_FORK)
+               if (compression_type == CMP_RESOURCE_FORK)
                        fremovexattr(a->fd, XATTR_RESOURCEFORK_NAME,
                            XATTR_SHOWCOMPRESSION);
                return (ARCHIVE_WARN);
@@ -1065,15 +1071,16 @@ hfs_drive_compressor(struct archive_write_disk *a, const char *buff,
         * data to decmpfs xattr instead of the resource fork.
         */
        if (a->decmpfs_block_count == 1 &&
-           (a->decmpfs_header_p->attr_size + bytes_compressed)
+           (a->decmpfs_attr_size + bytes_compressed)
              <= MAX_DECMPFS_XATTR_SIZE) {
 #if DECMPFS_DEBUG
 fprintf(stderr, "block %u bytes --> %u bytes in decmpfs xattr\n", (unsigned)size, (unsigned)bytes_compressed);
 #endif
-               a->decmpfs_header_p->compression_type = CMP_XATTR;
-               memcpy(a->decmpfs_header_p->attr_bytes,
+               *(uint32_t *)&a->decmpfs_header_p[DECMPFS_COMPRESSION_TYPE]
+                   = CMP_XATTR;
+               memcpy(a->decmpfs_header_p + DECMPFS_HEADER_SIZE,
                    buffer_compressed, bytes_compressed);
-               a->decmpfs_header_p->attr_size += bytes_compressed;
+               a->decmpfs_attr_size += bytes_compressed;
                /*
                 * Write the decmpfs xattr.
                 */
@@ -1158,10 +1165,13 @@ hfs_write_decmpfs_block(struct archive_write_disk *a, const char *buff,
                        }
                        a->decmpfs_header_p = new_block;
                }
-               a->decmpfs_header_p->attr_size = sizeof(decmpfs_disk_header);
-               a->decmpfs_header_p->compression_magic = DECMPFS_MAGIC;
-               a->decmpfs_header_p->compression_type = CMP_RESOURCE_FORK;
-               a->decmpfs_header_p->uncompressed_size = a->filesize;
+               a->decmpfs_attr_size = DECMPFS_HEADER_SIZE;
+               *(uint32_t *)&a->decmpfs_header_p[DECMPFS_COMPRESSION_MAGIC]
+                   = DECMPFS_MAGIC;
+               *(uint32_t *)&a->decmpfs_header_p[DECMPFS_COMPRESSION_TYPE]
+                    = CMP_RESOURCE_FORK;
+               *(uint64_t *)&a->decmpfs_header_p[DECMPFS_UNCOMPRESSED_SIZE]
+                    = a->filesize;
 
                /* Calculate a block count of the file. */
                a->decmpfs_block_count =
@@ -1208,11 +1218,13 @@ fprintf(stderr, "\nblock count = %u, file size = %u\n", a->decmpfs_block_count,
                 */
                if ((ret = lazy_stat(a)) != ARCHIVE_OK)
                        return (ret);
+#if 0
                if (fchflags(a->fd, a->st.st_flags | UF_COMPRESSED) != 0) {
                        archive_set_error(&a->archive, errno,
                            "failed fchflags for decmpfs");
                        return (ARCHIVE_FAILED);
                }
+#endif
 
                /* If the resource fork exists, remove it since we cannot
                 * truncate and we may use decmpfs xattr only. */
@@ -1407,7 +1419,7 @@ _archive_write_disk_finish_entry(struct archive *_a)
        } else if (a->fd_offset == a->filesize) {
                /* Last write ended at exactly the filesize; we're done. */
                /* Hopefully, this is the common case. */
-#if defined(HAVE_ZLIB_H) && defined(HAVE_SYS_DECMPFS_H)
+#if defined(HAVE_ZLIB_H) && defined(UF_COMPRESSED)
        } else if (a->todo & TODO_HFS_COMPRESSION) {
                char null_d[1024];
                ssize_t r;
@@ -2091,9 +2103,7 @@ _archive_write_disk_free(struct archive *_a)
        archive_string_free(&a->path_safe);
        a->archive.magic = 0;
        __archive_clean(&a->archive);
-#ifdef HAVE_SYS_DECMPFS_H
        free(a->decmpfs_header_p);
-#endif
        free(a->resource_fork);
        free(a->compressed_buffer);
        free(a->uncompressed_buffer);