Subject: bug#51857: cross-filesystem copying broken on macOS with coreutils >= 9.0

From: Cameron Katri <[email-masked]>
Date: Mon, 15 Nov 2021 16:49:40 -0500

On Mon, Nov 15, 2021 at 01:33:44PM -0800, Paul Eggert wrote:
> On 11/15/21 09:40, Cameron Katri wrote:
> 
> Did you build vanilla coreutils 9.0 yourself? If so, what commands did you
> you use to build it, exactly? If not, who built coreutils and how did they
> configure and/or modify it? I worry that we're looking at a version of
> coreutils cp that has been modified somehow, or that you're dtrussing the
> wrong cp somehow.

I forgot that I had a patch to enable reflink on APFS, I just rebuilt a
vanilla coreutils with just ./configure && make and the issue persists.
Sorry about that, here is the correct dtruss:

cameron in Documents/coreutils-9.0/src at build
\> sudo dtruss ./cp /usr/bin/clear /tmp/test
SYSCALL(args)            = return
access("/AppleInternal/XBS/.isChrooted\0", 0x0, 0x0)             = -1 Err#2
bsdthread_register(0x1AEC802C8, 0x1AEC802BC, 0x4000)             = 1073742303 0
shm_open(0x1AEB48F55, 0x0, 0x4158000)            = 3 0
fstat64(0x3, 0x16BCA6130, 0x0)           = 0 0
mmap(0x0, 0x4000, 0x1, 0x40001, 0x3, 0x0)                = 0x104298000 0
close(0x3)               = 0 0
ioctl(0x2, 0x4004667A, 0x16BCA61DC)              = 0 0
mprotect(0x1042A4000, 0x4000, 0x0)               = 0 0
mprotect(0x1042B0000, 0x4000, 0x0)               = 0 0
mprotect(0x1042B4000, 0x4000, 0x0)               = 0 0
mprotect(0x1042C0000, 0x4000, 0x0)               = 0 0
mprotect(0x1042C4000, 0x4000, 0x0)               = 0 0
mprotect(0x1042D0000, 0x4000, 0x0)               = 0 0
mprotect(0x10429C000, 0x90, 0x1)                 = 0 0
mprotect(0x10429C000, 0x90, 0x3)                 = 0 0
mprotect(0x10429C000, 0x90, 0x1)                 = 0 0
mprotect(0x1042D4000, 0x4000, 0x1)               = 0 0
mprotect(0x1042D8000, 0x90, 0x1)                 = 0 0
mprotect(0x1042D8000, 0x90, 0x3)                 = 0 0
mprotect(0x1042D8000, 0x90, 0x1)                 = 0 0
mprotect(0x10429C000, 0x90, 0x3)                 = 0 0
mprotect(0x10429C000, 0x90, 0x1)                 = 0 0
mprotect(0x1042D4000, 0x4000, 0x3)               = 0 0
mprotect(0x1042D4000, 0x4000, 0x1)               = 0 0
objc_bp_assist_cfg_np(0x1AEB103C0, 0x8000000000201048, 0x0)              = -1 Err#5
issetugid(0x0, 0x0, 0x0)                 = 0 0
getentropy(0x16BCA5FF8, 0x20, 0x0)               = 0 0
getentropy(0x16BCA6048, 0x40, 0x0)               = 0 0
getpid(0x0, 0x0, 0x0)            = 91358 0
stat64("/AppleInternal\0", 0x16BCA6740, 0x0)             = -1 Err#2
csops_audittoken(0x164DE, 0x7, 0x16BCA6270)              = 0 0
proc_info(0x2, 0x164DE, 0xD)             = 64 0
csops_audittoken(0x164DE, 0x7, 0x16BCA6330)              = 0 0
sysctlbyname(kern.osvariant_status, 0x15, 0x16BCA67A8, 0x16BCA67A0, 0x0)                 = 0 0
csops(0x164DE, 0x0, 0x16BCA67CC)                 = 0 0
mprotect(0x104190000, 0x100000, 0x1)             = 0 0
open_nocancel("/usr/share/locale/en_US.UTF-8/LC_COLLATE\0", 0x0, 0x0)            = 3 0
fcntl_nocancel(0x3, 0x3, 0x0)            = 0 0
getrlimit(0x1008, 0x16BCA7178, 0x0)              = 0 0
fstat64(0x3, 0x16BCA70F0, 0x0)           = 0 0
read_nocancel(0x3, "1.1A\n\0", 0x1000)           = 2086 0
close_nocancel(0x3)              = 0 0
open_nocancel("/usr/share/locale/en_US.UTF-8/LC_CTYPE\0", 0x0, 0x0)              = 3 0
fcntl_nocancel(0x3, 0x3, 0x0)            = 0 0
fstat64(0x3, 0x16BCA7220, 0x0)           = 0 0
fstat64(0x3, 0x16BCA7010, 0x0)           = 0 0
lseek(0x3, 0x0, 0x1)             = 0 0
lseek(0x3, 0x0, 0x0)             = 0 0
read_nocancel(0x3, "RuneMagAUTF-8\0", 0x1000)            = 4096 0
read_nocancel(0x3, "\0", 0x1000)                 = 4096 0
read_nocancel(0x3, "\0", 0x1000)                 = 4096 0
read_nocancel(0x3, "\0", 0x1000)                 = 4096 0
read_nocancel(0x3, "\0", 0x1000)                 = 4096 0
read_nocancel(0x3, "\0", 0x1000)                 = 4096 0
read_nocancel(0x3, "\0", 0x1000)                 = 4096 0
read_nocancel(0x3, "@\004\211\0", 0xF5D0)                = 62928 0
close_nocancel(0x3)              = 0 0
open_nocancel("/usr/share/locale/en_US.UTF-8/LC_MONETARY\0", 0x0, 0x0)           = 3 0
fstat64(0x3, 0x16BCA7240, 0x0)           = 0 0
read_nocancel(0x3, "USD \n$\n.\n,\n3;3\n\n-\n2\n2\n1\n0\n1\n0\n1\n1\n(\0", 0x22)                 = 34 0
close_nocancel(0x3)              = 0 0
open_nocancel("/usr/share/locale/en_US.UTF-8/LC_NUMERIC\0", 0x0, 0x0)            = 3 0
fstat64(0x3, 0x16BCA7240, 0x0)           = 0 0
read_nocancel(0x3, ".\n,\n3;3\n@$\b\0", 0x8)             = 8 0
close_nocancel(0x3)              = 0 0
open_nocancel("/usr/share/locale/en_US.UTF-8/LC_TIME\0", 0x0, 0x0)               = 3 0
fstat64(0x3, 0x16BCA7250, 0x0)           = 0 0
read_nocancel(0x3, "Jan\nFeb\nMar\nApr\nMay\nJun\nJul\nAug\nSep\nOct\nNov\nDec\nJanuary\nFebruary\nMarch\nApril\nMay\nJune\nJuly\nAugust\nSeptember\nOctober\nNovember\nDecember\nSun\nMon\nTue\nWed\nThu\nFri\nSat\nSunday\nMonday\nTuesday\nWednesday\nThursday\nFriday\nSaturday\n%H:%M:%S\n%m/%d/%Y\n%a %b %e %X %Y\nAM\nP", 0x179)            = 377 0
close_nocancel(0x3)              = 0 0
open_nocancel("/usr/share/locale/en_US.UTF-8/LC_MESSAGES/LC_MESSAGES\0", 0x0, 0x0)               = 3 0
fstat64(0x3, 0x16BCA7250, 0x0)           = 0 0
read_nocancel(0x3, "^[yYsS].*\n^[nN].*\n(\0", 0x12)              = 18 0
close_nocancel(0x3)              = 0 0
geteuid(0x0, 0x0, 0x0)           = 0 0
stat64("/tmp/test\0", 0x16BCA7720, 0x0)          = 0 0
fstatat64(0xFFFFFFFFFFFFFFFE, 0x16BCA7C45, 0x16BCA73F0)          = 0 0
fstatat64(0xFFFFFFFFFFFFFFFE, 0x16BCA7C54, 0x16BCA7360)          = 0 0
open("/usr/bin/clear\0", 0x0, 0x0)               = 3 0
fstat64(0x3, 0x16BCA7490, 0x0)           = 0 0
open("/tmp/test\0", 0x401, 0x0)          = 4 0
fstat64(0x4, 0x16BCA75C0, 0x0)           = 0 0
sysctl([CTL_HW, 7, 0, 0, 0, 0] (2), 0x207EC4068, 0x16BCA7280, 0x0, 0x0)          = 0 0
lseek(0x3, 0x0, 0x4)             = -1 Err#6
ftruncate(0x4, 0x1D770, 0x0)             = 0 0
close(0x4)               = 0 0
close(0x3)               = 0 0
lseek(0x0, 0x0, 0x1)             = 146611 0
lseek(0x0, 0x0, 0x1)             = 146611 0
lseek(0x0, 0x23CB3, 0x0)                 = 146611 0
close_nocancel(0x0)              = 0 0
close_nocancel(0x1)              = 0 0
close_nocancel(0x2)              = 0 0

-- 
Cameron Katri
Email: [email-masked]
PGP Fingerprint: 7D3B36CEA40FCC2181FB6DCDBAFFD97826540F1C