Atomic Test And Set Of Disk Block Returned False For Equality — No Sign-up

Modern drives use 4096-byte (4K) sectors. Legacy software sometimes assumes 512-byte sectors. If you try to perform an atomic test-and-set on a 512-byte chunk that straddles two physical 4K blocks, you aren't testing one atomic unit. You are testing half of block A and half of block B. The disk firmware will return a "false" because the comparison wasn't aligned to its native boundary.

| API/Command | Purpose | |-------------|---------| | sync_file_range(2) + fdatasync(2) | Control write ordering | | io_uring_ops with IORING_OP_COMPARE_AND_WRITE | Linux native TAS on block devices | | fcntl(F_OFD_SETLK) | POSIX file locking (not block-level) | | nvme compare and nvme write | NVMe’s compare-and-write primitives | | rados cas (Ceph) | Object-level atomic compare-and-swap | Modern drives use 4096-byte (4K) sectors

Typical atomic TAS on disk block:

bool block_compare_and_swap(block_id, old_val, new_val) 
    disk_read(block_id, buffer);
    if (memcmp(buffer, old_val) == 0) 
        memcpy(buffer, new_val);
        disk_write(block_id, buffer);
        return true;   // succeeded
return false;      // false for equality — what you reported