]> git.saurik.com Git - apple/copyfile.git/commitdiff
copyfile-146.200.3.tar.gz macos-1014 macos-10141 macos-10142 macos-10143 v146.200.3
authorApple <opensource@apple.com>
Fri, 20 Jul 2018 18:11:38 +0000 (18:11 +0000)
committerApple <opensource@apple.com>
Fri, 20 Jul 2018 18:11:38 +0000 (18:11 +0000)
copyfile.c
copyfile.xcodeproj/project.pbxproj
xattr_flags.c
xcodescripts/copyfile.xcconfig

index f07b86d4b03bd21e2f08e544b503558db35155aa..885bd4d2193db286662f07a3a382a4eb76693da9 100644 (file)
@@ -79,6 +79,8 @@ static int qtn_file_set_flags(void *x, uint32_t flags) { return 0; }
 #include "copyfile_private.h"
 #include "xattr_flags.h"
 
+#define XATTR_ROOT_INSTALLED_NAME "com.apple.root.installed"
+
 enum cfInternalFlags {
        cfDelayAce                = 1 << 0, /* set if ACE shouldn't be set until post-order traversal */
        cfMakeFileInvisible       = 1 << 1, /* set if kFinderInvisibleMask is on src */
@@ -2330,7 +2332,7 @@ static int copyfile_data(copyfile_state_t s)
        int ret = 0;
        size_t iBlocksize = 0, iMinblocksize = 0;
        size_t oBlocksize = 0, oMinblocksize = 0; // If 0, we don't support sparse copying.
-       const size_t onegig = 1 << 30;
+       const size_t blocksize_limit = 1 << 30; // 1 GiB
        struct statfs sfs;
        copyfile_callback_t status = s->statuscb;
 
@@ -2350,6 +2352,8 @@ static int copyfile_data(copyfile_state_t s)
        }
 #endif
 
+       // Calculate the input and output block sizes.
+       // Our output block size can be no greater than our input block size.
        if (fstatfs(s->src_fd, &sfs) == -1) {
                iBlocksize = s->sb.st_blksize;
        } else {
@@ -2357,23 +2361,27 @@ static int copyfile_data(copyfile_state_t s)
                iMinblocksize = sfs.f_bsize;
        }
 
-       /* Work-around for 6453525, limit blocksize to 1G */
-       if (iBlocksize > onegig) {
-               iBlocksize = onegig;
-       }
-
        if (fstatfs(s->dst_fd, &sfs) == -1) {
                oBlocksize = iBlocksize;
-       } else if (sfs.f_iosize == 0) {
-               oBlocksize = iBlocksize;
-               oMinblocksize = sfs.f_bsize;
        } else {
+               oBlocksize = (sfs.f_iosize == 0) ? iBlocksize : MIN((size_t) sfs.f_iosize, iBlocksize);
                oMinblocksize = sfs.f_bsize;
-               oBlocksize = sfs.f_iosize;
-               if (oBlocksize > onegig)
-                       oBlocksize = onegig;
        }
 
+       // 6453525 and 34848916 require us to limit our blocksize to resonable values.
+       if ((size_t) s->sb.st_size < iBlocksize && iMinblocksize > 0) {
+               copyfile_debug(3, "rounding up block size from fsize: %lld to multiple of %zu\n", s->sb.st_size, iMinblocksize);
+               iBlocksize = roundup((size_t) s->sb.st_size, iMinblocksize);
+               oBlocksize = MIN(oBlocksize, iBlocksize);
+       }
+
+       if (iBlocksize > blocksize_limit) {
+               iBlocksize = blocksize_limit;
+               oBlocksize = MIN(oBlocksize, iBlocksize);
+       }
+
+       copyfile_debug(3, "input block size: %zu output block size: %zu\n", iBlocksize, oBlocksize);
+
        s->totalCopied = 0;
 
        // If requested, attempt a sparse copy.
@@ -2958,9 +2966,16 @@ static int copyfile_xattr(copyfile_state_t s)
                }
                if (fsetxattr(s->dst_fd, name, xa_dataptr, xa_size, 0, look_for_decmpea) < 0)
                {
-                       if (s->statuscb)
+                       int error = errno;
+                       if (error == EPERM && strcmp(name, XATTR_ROOT_INSTALLED_NAME) == 0) {
+                               //Silently ignore if we fail to set XATTR_ROOT_INSTALLED_NAME
+                               errno = error;
+                               continue;
+                       }
+                       else if (s->statuscb)
                        {
                                int rv;
+                               error = errno;
                                if (s->xattr_name == NULL)
                                        s->xattr_name = strdup(name);
                                rv = (*s->statuscb)(COPYFILE_COPY_XATTR, COPYFILE_ERR, s, s->src, s->dst, s->ctx);
@@ -2973,8 +2988,9 @@ static int copyfile_xattr(copyfile_state_t s)
                        }
                        else
                        {
+                               errno = error;
                                ret = -1;
-                               copyfile_warn("could not set attributes %s on destination file descriptor: %s", name, strerror(errno));
+                               copyfile_warn("could not set attributes %s on destination file descriptor: %s", name, strerror(error));
                                continue;
                        }
                }
@@ -3918,9 +3934,14 @@ static int copyfile_unpack(copyfile_state_t s)
                                                        goto exit;
                                                }
                                        }
-                                       if (fsetxattr(s->dst_fd, (char *)entry->name, dataptr, entry->length, 0, 0) == -1) {
+                                       //Silently ignore failure to set XATTR_ROOT_INSTALLED_NAME
+                                       int result = fsetxattr(s->dst_fd, (char *)entry->name, dataptr, entry->length, 0, 0);
+                                       int errorcode = errno;
+                                       if (result == -1 && !(errorcode == EPERM &&
+                                                                                strcmp((char*)entry->name, XATTR_ROOT_INSTALLED_NAME) == 0)) {
+                                               errno = errorcode;
                                                if (COPYFILE_VERBOSE & s->flags)
-                                                       copyfile_warn("error %d setting attribute %s", errno, entry->name);
+                                                       copyfile_warn("error %d setting attribute %s", errorcode, entry->name);
                                                if (s->statuscb) {
                                                        int rv;
 
@@ -3940,6 +3961,7 @@ static int copyfile_unpack(copyfile_state_t s)
                                                }
                                        } else if (s->statuscb) {
                                                int rv;
+                                               errno = errorcode;
                                                s->xattr_name = strdup((char*)entry->name);
                                                s->totalCopied = entry->length;
                                                rv = (*s->statuscb)(COPYFILE_COPY_XATTR, COPYFILE_FINISH, s, s->src, s->dst, s->ctx);
@@ -3952,6 +3974,8 @@ static int copyfile_unpack(copyfile_state_t s)
                                                        s->err = ECANCELED;
                                                        goto exit;
                                                }
+                                       } else {
+                                               errno = errorcode;
                                        }
                                }
                        }
index 37eb53f69a51d5974c20c80e399f8d6a3cee5293..b8ec504038649744601a719e723addfc8d5523bd 100644 (file)
                                        "$(inherited)",
                                        "$(SDKROOT)/usr/lib/system",
                                );
-                               MACOSX_DEPLOYMENT_TARGET = 10.13;
                                MTL_ENABLE_DEBUG_INFO = NO;
                                PRODUCT_NAME = "$(TARGET_NAME)";
                                SDKROOT = macosx;
+                               SUPPORTS_TEXT_BASED_API = YES;
+                               TAPI_VERIFY_MODE = Pedantic;
                        };
                        name = Release;
                };
                                );
                                SDKROOT = macosx.internal;
                                "SIM_SUFFIX[sdk=iphonesimulator*]" = _sim;
+                               SUPPORTS_TEXT_BASED_API = YES;
+                               TAPI_VERIFY_MODE = Pedantic;
                                WARNING_CFLAGS = (
                                        "-Wall",
                                        "-Wextra",
index 8e8fd0512f1060ff80703b4630f9b570c5ba07bc..7144a4da4645a0e6b751a741d0c72d9015e5f89e 100644 (file)
@@ -58,6 +58,7 @@ defaultUnboxedPropertyTable[] = {
        { "com.apple.security.", "S", propFlagsPrefix },
        { XATTR_RESOURCEFORK_NAME, "PCS", 0 },  // Don't keep for safe save
        { XATTR_FINDERINFO_NAME, "PCS", 0 },    // Same as ResourceFork
+       { "com.apple.root.installed", "PC", 0}, // Don't share or sync. Copyable by entitled callers
        { 0, 0, 0 },
 };
 
@@ -69,6 +70,7 @@ defaultSandboxedPropertyTable[] = {
     { "com.apple.security.", "N", propFlagsPrefix },
     { XATTR_RESOURCEFORK_NAME, "PCS", 0 },     // Don't keep for safe save
     { XATTR_FINDERINFO_NAME, "PCS", 0 },       // Same as ResourceFork
+       { "com.apple.root.installed", "PC", 0}, // Don't share or sync. Copyable by entitled callers
     { 0, 0, 0 },
 };
 
index d365fb5fb198adff56f8b132a6ac1cd46ad92084..c1aedf468694080ef2d98be384e07f89c448ea3f 100644 (file)
@@ -6,5 +6,7 @@ PUBLIC_HEADERS_FOLDER_PATH = /usr/include
 PRIVATE_HEADERS_FOLDER_PATH = /usr/local/include
 
 BUILD_VARIANTS = normal debug
+VERSION_INFO_PREFIX = __attribute__((visibility("hidden")))
+IS_ZIPPERED = YES
 
 PRODUCT_NAME = copyfile