help-cfengine
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] OS X Resource Fork and FinderType support


From: David Botsch
Subject: Re: [PATCH] OS X Resource Fork and FinderType support
Date: Mon, 18 Aug 2003 13:21:03 -0400
User-agent: Pan/0.11.2 (Unix)

Ok.
So, files on the Macintosh can have up to 3 parts, if you will (though
the 3rd part is more a feature of the file system and not the file
itself).

1. Data fork - this is the data -- what we consider the file under most
other file systems
2. Resource fork - as Martin said, this contains resources used by the
program. Dialog boxes, icons, and any of a number of other pieces.
3. Metadata - file meta data contains two things
3a. File Creator - identifies the application that created the file. This
allows you to double click on the file and have it opened in the
application that created it.
3b. File Type Code - a 4 letter code identifying the type of the file
(other operating systems use the .xxx extensions to identify file types).
For example, the 4 letter code APPL means the file is an application. The
four letter code TEXT means it is a text file. OSAX means OS X Scripting
Addition, I believe. There are lots more (applications can define their
own type codes for use by their files, iirc). In the absence of the file
creator type, I belive the file will be opened by whichever application
says "I handle files of this type). In the absece of both the file
creator and file type code, you get a dialog box which says something to
the effect of "Choose which application to use to open this file". So,
the absence of file type codes means applications won't run when you
double click them. You'll just get the aforementioned dialog box.

The patch incorporates resource fork support and file type code support
into CFEngine. 

The problem is this: commandline unix tools and unix system calls under
OS X don't understand resource forks and metadata. So, if you cp or mv a
file, you'll still have the data fork but will have lost the resource
fork and metadata. Note, though, that this can be useful for splitting
off data forks.

Apple did not completely screw us over, though. It turns out that they
did provide a way to access the resource fork of a file with cp as
well. To access the resouce fork of filename, you would cp
filename/..namedfork/rsrc (so, you can cp this to the data fork of
another file and back, you can md5sum it, you can access it as if it were
a separate file using normal unix system calls to read/write files, etc).
The only real limitation is that the datafork of filename must exist before
you copy a resource fork to filename/..namedfork/rsrc . So, this would
not work if filename did not already exist:

cp file-rsrc filename/..namedfork/rsrc
cp file-dat filename

(note: mv does not really work with ..namedfork/rsrc)

Ok, on to using cfengine:

1. You need to split the data fork and resource forks apart (make sure
that you use a tool to split only data and resource forks, you don't want
to use one that gives you the data fork in one file and the resource fork
and metadata in another file (read ._filename on non-HFS+ filesystems).
Metadata cannot be cp'ed back into filename/..namedfork/rsrc

eg:
cp filename/..namedfork/rsrc filename-rsrc
cp filename filename-data

resource fork is now in filename-rsrc and datafork is in filename-data
We haven't copied the metadata anywhere.

2. Get the Finder file type code if you need it: Highlighting a file in
the finder and pressing CMD-I will tell you the common name of the type, but 
not the 4
letter code... you can then usually google to get it (I'm not aware of
any commandline tools that will give you this info, but I am sure that they
exist). You can also use tools like ResEdit to get and change the type
code. Some type codes are easy to remember (like the eariler mentioned APPL and 
TEXT). 

Writing a quick C program to get this 4 letter code should be easy,
though.. see the patch source or hfstar source (which I used to figure
out how to do this in my patch).

3. Cfengine entries
In the copy: section of your cfengine config files:

Here is an example from our setup:

    $(masterfiles)/$(sys)/Applications/LaunchX11-datafork 
dest=/Applications/LaunchX11 type=sum mode=0755 owner=root group=admin 
findertype=APPL
    $(masterfiles)/$(sys)/Applications/LaunchX11-rsrcfork 
dest=/Applications/LaunchX11/..namedfork/rsrc type=sum mode=0755 owner=root 
group=admin

So, to take care of the resource fork, I just copy my split off resource
fork in filename/..namedfork/rsrc (treating it as a separate file as far
as cfengine is concerned)

the 4 letter finder type code is specified with the data fork ONLY and
with findertype=XXXX

4. Gotchas:
a. As we mentioned before, you must copy the data fork over BEFORE you
copy the resource fork. See above example. Attempting to do the opposite
won't work if the file does not already exist.
b. Finder type code only applies to the data fork .. don't try to apply
it to the resource fork
c. Finder type code should be all caps. I don't know what will happen if
you try all lowercase.
d. You cannot have a directory named ..namedfork ... this is a reserved
name under OS X to specify that we are going to be messing with one of
the forks... the patch takes care of this special case.


Does all this make sense? Or did I just confuse the issue more?

On Mon, 18 Aug 2003 08:45:32 -0400, Mark Burgess wrote:

> On 18 Aug, Martin A. Brooks wrote:
>> On Mon, 2003-08-18 at 13:28, Mark Burgess wrote:
>>> David - thanks for your comprehensive patch. Can you tell me what
>>> Resource FOrks means?
>> 
>> Macs split a file into two parts, a data fork and a resource fork. The
>> data fork can be thought of as the apoplication itself, the resource
>> fork will contain things like icons (for displaying in the Finder) or
>> custom dialogs used by the application.
>> 
>> There's a neat program called resedit for the Mac that's used to
>> manipulate these forks.
>> 
>> It's been a while since I used Macs, but I hope this helps to explain.
>> 
>> Regards
>> 
>> 
>> 
> So what does the patch do and how do people use it? M
> 
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> Work: +47 22453272            Email:  Mark.Burgess@iu.hio.no Fax : +47
> 22453205            WWW  :  http://www.iu.hio.no/~mark
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


reply via email to

[Prev in Thread] Current Thread [Next in Thread]