Identifying Resource and Data Forks


Files on Mac OS X can be composed of two distinct halves called forks. Much more popular in the OS 9 days, resource forks were used to contain objectlike information such as icons, strings, and small chunks of code, while the data fork was used for unclassified raw data such as that involved in composing an image file. In Mac OS X, most files keep their data exclusively in the data fork, but resource forks are still used by older applications, and even by Mac OS X to store elements such as custom file icons.

Copying Forked Files on HFS Plus

When you use the graphical user interface to move files around, the File Manager built in to Mac OS X handles forked files automatically.

As of Mac OS X v10.4, most command-line utilities, such as cp, mv, and tar, now handle forked files properly. Previous versions of Mac OS X required command-line utilities that were designed for use with forked files. Two such commandsditto (with the rsrcFork option) and CpMacwere specifically written to handle forked files correctly. Though it is no longer necessary to use these utilities, ditto is still included on all Mac OS X systems. You must install the Developer Tools package to get CpMac, which will then be placed in the /Developer/Tools/ directory.

The following figure shows what happens when you copy files within an HFS Plus file system or between two such file systems using cp, tar, ditto rsrcFork, or CpMac.

You can use a number of commands to check whether a file has a resource fork. If you need to check only for the existence of a resource fork, you can simply use the ls command. Normally you look at a long file listing with the l option:

ls l MyFile rwr  r  1 david david 3624 Oct 20 22:02 MyFile


In the line above, the data fork is 3,624 bytes. You can examine the resource fork by looking at what acts like a hidden object inside the file, as follows:

ls l MyFile/..namedfork/rsrc rwr  r  1 david david 9928 Oct 20 22:02 MyFile/..namedfork/rsrc


Although it's redundant, you can also use this method to look specifically at the data fork, like this:

ls l MyFile/..namedfork/data rwr  r  1 david david 3624 Oct 20 22:02 MyFile/..namedfork/data


You can dump the contents of a resource fork by using the developer tool DeRez. Note that the Mac OS 9 application program SimpleText appears to be empty when you look at it with ls. All the content of this file is in the resource fork. Note that the output of DeRez is the same whether the file has a resource fork or a shadow file (shadow files are discussed in the next section).

Copying Forked Files to Other File Systems

When you use the Finder to move forked files to a file system that does not support forks, such as UFS, the File Manager puts the resource fork information into shadow files. A shadow file has the same name as the original file, with ._ prepended to its name. When you copy the file back to an HFS Plus file system, the File Manager re-creates the specific file forks.

The same happens when you use ditto rsrcFork or CpMac to copy files to and from a nonHFS Plus file system.

Copying Forked Files With Non-Mac Applications

In Mac OS X versions prior to v10.4, ordinary UNIX command-line utilities, such as cp and mv, were not designed to handle file forks or shadow files. When you used cp to copy forked files or files with shadow files, you lost the resource fork or shadow file. This was true whether the destination was HFS Plus or another file system. DeRez will also report that the copy has no resource fork and ls lists no shadow files.

Similarly, applications on Windows computers were not designed to handle file forks or shadow files. This can be an issue if, for example, you transfer files back and forth between your Mac OS X computer and a Windows computer using a flash memory storage device. If you use the Finder or CpMac to copy the files to the device, the files will preserve their shadow files. But if you rename the files or move them around while the device is connected to the Windows computer, the shadow files are lost.

In some cases, you won't notice any problems if the resource fork is missing. In other cases, however, you may notice missing file information. Fonts may be absent from a document. Mac OS X might not know what application to use to open the file. In most cases, a file's custom icon will be replaced with a more generic icon.




Apple Training Series. Mac OS X System Administration Reference, Volume 1
Apple Training Series: Mac OS X System Administration Reference, Volume 1
ISBN: 032136984X
EAN: 2147483647
Year: 2005
Pages: 258
Authors: Schoun Regan

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net