2

It says here...

https://en.wikipedia.org/wiki/Fork_(file_system)#Apple

...that the HFS+ file system in OSX supports "multiple named forks". How do I create a named fork at command line, and then how do I store data in it? Also, what are the maximum number of bytes I can place in my named fork?

3

Extended attributes is what you're looking for. xattr will allow you to view and modify extended attributes at the command line. Look at the man page for more details, but in brief you can write one with the following command

xattr -w com.foo.myattribute "A bunch of data" /path/to/file

2

I don't know about named forks except the resource fork. I can create it like so in Terminal (Bash shell):

echo "data fork area" > /tmp/test.txt
echo "resource fork area" > /tmp/test.txt/..namedfork/rsrc
cat /tmp/test.txt
cat /tmp/test.txt/..namedfork/rsrc

I don't know about size limitations.

You can also copy a binary executable into the resource fork, and extract the bytes back out into a file, and execute that file:

cp /usr/bin/whoami > /tmp/test.txt/..namedfork/rsrc
# get ready for some bells to sound in your terminal
cat /tmp/test.txt/..namedfork/rsrc > /tmp/test.bin
chmod u+x /tmp/test.bin
/tmp/test.bin

Note that the whoami command is kind of weird when you do this because it's really the id command, and so when you restore it, it reverts to the id command and you can do man id to learn more about that.

  • 1
    This method creates an extended attribute with the name com.apple.ResourceFork. You can view it with the xattr command. – iWill Feb 22 '16 at 4:06
  • @iWill: Yes the newer extended attribute feature seems to provide an additional interface to the very old resource fork feature. – hippietrail Jun 9 '16 at 14:31

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .