Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maximum size of xattr in OS X

Tags:

json

macos

xattr

I would like to use xattr to store some meta-data on my files directly on the files. These are essentially tags that I use for the categorization of files when I do searches on them. My goal is to extend the usual Mac OS X tags by associating more info to each tag, for instance the date of addition of that tag and maybe other thing.

I was thinking to add an xattr to the files, using xattr -w. My first guess would be to store something like a JSON in this xattr value, but I was wondering

1) what are the limits of size I can store in an xattr? (man of xattr is vauge and refers to something called _PC_XATTR_SIZE_BITS which I cannot locate anywhere)

2) anything wrong with storing a JSON formatted string as an xattr?

like image 616
Rho Phi Avatar asked Oct 21 '25 22:10

Rho Phi


1 Answers

According to man pathconf, there is a “configurable system limit or option variable” called _PC_XATTR_SIZE_BITS which is

the number of bits used to store maximum extended attribute size in bytes. For example, if the maximum attribute size supported by a file system is 128K, the value returned will be 18. However a value 18 can mean that the maximum attribute size can be anywhere from (256KB - 1) to 128KB. As a special case, the resource fork can have much larger size, and some file system specific extended attributes can have smaller and preset size; for example, Finder Info is always 32 bytes.

You can determine the value of this parameter using this small command line tool written in Swift 4:

import Foundation

let args = CommandLine.arguments.dropFirst()

guard let pathArg = args.first else {
  print ("File path argument missing!")
  exit (EXIT_FAILURE)
}

let v = pathconf(pathArg, _PC_XATTR_SIZE_BITS)

print ("_PC_XATTR_SIZE_BITS: \(v)")

exit (EXIT_SUCCESS)

I get:

  • 31 bits for HFS+ on OS X 10.11
  • 64 bits for APFS on macOS 10.13

as the number of bits used to store maximum extended attribute size. These imply that the actual maximum xattr sizes are somewhere in the ranges

  • 1 GiB ≤ maximum < 2 GiB for HFS+ on OS X 10.11
  • 8 EiB ≤ maximum < 16 EiB for APFS on macOS 10.13
like image 55
Dr. F. Avatar answered Oct 23 '25 15:10

Dr. F.



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!