Equivalent macOS API for GetFileInformationByHandle to Retrieve File Attributes (e.g., Sync Drive Attributes)

I'm working on a cross-platform application that needs to access file attributes, specifically for files and directories in sync drives like OneDrive. On Windows, I use the GetFileInformationByHandle API to retrieve attributes such as FILE_ATTRIBUTE_RECALL_ON_DATA_ACCESS and FILE_ATTRIBUTE_RECALL_ON_OPEN to identify files that are stored remotely or in the cloud.

Is there an equivalent API or mechanism on macOS to achieve the same? Specifically, I’m looking for a way to:

Identify attributes similar to cloud/offline storage status for files in synced drives (e.g., OneDrive, DropBox etc). Retrieve metadata to distinguish files/folders stored locally versus those stored remotely and downloaded on access.

If there’s a preferred macOS framework (like Core Services or FileManager in Swift) for such operations, examples would be greatly appreciated!

Identify attributes similar to cloud/offline storage status for files in synced drives (e.g., OneDrive, DropBox etc). Retrieve metadata to distinguish files/folders stored locally versus those stored remotely and downloaded on access.

First off, there are actually two different cases the can happen here depending on the product, system version, etc:

  1. Historically, products like this were implemented by either using kauth, the VFS layer (most commonly, through FUSE), or through a "loopback" SMB server. The "kauth" API has been deprecated long enough that I don't think you'll run into that case anymore, but the other two cases still exist "in the wild".

  2. The "modern" approach is to use NSFileProviderReplicatedExtension to integrate into with the system.

As far as the system is concerned, we only have API support for #2. The first case is either totally invisible (kauth) or can't be differentiated for other use cases of the same file system APIs.

SO, focusing on #2:

If there’s a preferred macOS framework (like Core Services or FileManager in Swift) for such operations, examples would be greatly appreciated!

In terms of high level APIs, these issues are why file coordination exists. The article "Improving performance and stability when accessing the file system" has good overview of the basic process and APIs, while the older "File System Programming Guide" has a much more in depth discussion, particularly "The Role of File Coordinators and Presenters". Note that while that document is specifically focused on iCloud Drive, the actually APIs are the same across anything using #2. Finally, the low-level POSIX layer APIs for this are documented in "TN3150: Getting ready for dataless files".

__
Kevin Elliott
DTS Engineer, CoreOS/Hardware

Equivalent macOS API for GetFileInformationByHandle to Retrieve File Attributes (e.g., Sync Drive Attributes)
 
 
Q