Skip to main content
Kelvas blog
  1. Posts/

macOS xattr attributes

·393 words·2 mins
Image

What is a file attribute? #

I will probably push an open door, but a file system has attributes on the files. In particular, the read, write and execute of each file and this for the different groups:

-rw-rw-r-- 1 kelvas users  5120 Jul 09 04:30 sample.txt

But these attributes were not enough for many cases. So an extension was added to the inodes to allow more functionality on the files: the extended attributes or xattr.

How it works #

Unlike regular attributes, extended attributes are not interpreted by the file system, but are stored and managed separately. Any extended attribute is identified by a pair (name:value) that allows manipulation of the stored information.

Some file systems require special mount options to enable support for extended attributes.

Linux and macOS #

Many Linux distributions include the extended attributes and also macOS since version 10.4 thanks to the HFS+ file system.

Okay, but why? #

You’re going to say to me, “Why are you talking about this today?”. Well, it’s quite simple. You know I like to code and I like to share. Well recently I had to share a macOS application with a friend and he could never open the application because of this error:

Image

Strange because I tested the application just before sending it and everything worked perfectly. Of course, my first reflex was to make him re-download the ZIP containing the application: without success. My second reflex was to question my ZIP and to change for a TAR or a GZIP: no change yet.

And it’s after several research that I discovered these famous xattr.Once downloaded and unzipped, the application had the following attributes:

com.apple.quarantine: 0083;61b9bd2d;Safari;7E8E7E48-6187-4915-BF12-2FF346BF1306

As the application was not downloaded from the store, it was automatically quarantined by the system, which of course prevents the execution of the software even though the “standard” attribute of execution is valid for the user and his group.

To see the list of extended attributes, you will need this command:

xattr -l path/to/myFile.ext

And if you need to remove all extended attributes from a file, this command will be very useful:

xattr -cr path/to/myFile.ext

In my case removing the quarantine, attribute allowed me to launch the application. Of course, I invite you to be careful with the management of these attributes that are used by the system and the applications to work properly.