Subject: [netatalk-admins] megatron patch

From: "Frank Morton" <[email-masked]>
Date: Thu, 27 Aug 1998 13:33:23 -0500

I have needed the ability to get the macintosh type/creator from a
specified file from the command line and have made the following
patches (diffs) to megatron.c and megatron.h. I would like to see
this integrated in the distributed source, but since I am on the outside
looking in, I'm sending to multiple places hoping one is right.

I have been using the asun version, but it looks like the megatron
utility has not been touched in awhile.

I have added two "modules" as the source code calls it: macheader
and macbinaryheader. These should be linked in the bin directory
just like unhex, macbinary, etc.

To use them, on an apple double format file, you do one of the following:

macheader filename

or

macbinary -header filename

On a macbinary file, to get the same info, you do one of the following:

macbinaryheader filename.bin

or

unbin -header filename.bin

In all cases, the following is written to standard output in a format like
this:

name: filename_in_the_fork
comment:
forklen_0: 1305233
forklen_1: 242877
create_date: 2980256773
mod_date: 2980256778
backup_date: 0
type: EPSF
creator: PSMC
flags: 400

The name field is the filename in the file itself, not necessary the linux
filename. Comment is self explanatory and will usually be blank. The
forklen_0 corresponds to the length of the data fork. I thought about
naming it forklen_data but decided to leave it open-ended to be
consistent with the rest of the source. forklen_1 is the length of the
resource fork. Dates are the corresponding dates to their descriptions.
The type and creator fields are the 4-byte fields in the finder info that
are commonly used. The flags, printed in hex (as in %x) are the status
flags in the finder info. There are a few other fields which I left out
as they are more bookkeeping fields than externally useful info.

To use this to extract, as an example, the creator of the file, I plan to
do the following in a bash shell:

export imagecreator=`macheader filename|awk '{print $2}'`

I will welcome any comments and glad to make any reasonable
additional changes.

Below are the diffs, first for megatron.h and then for megatron.c.
I realize e-mail isn't the best way to send these. If you would rather
me ftp (or whatever) the diffs or the complete megatron.(h,c) files,
let me know:

start megatron.h------------------------------------
26,29c26,27
< #define MACHEADER       6       /* macheader */
< #define MACBINARYHEADER 7       /* macbinaryheader */
< #define MEGATRON 8 /* megatron, default, usually HEX2NAD */
< #define CONVERTS 9 /* # conversions defined */
---
> #define MEGATRON 6 /* megatron, default, usually HEX2NAD */
> #define CONVERTS 7 /* # conversions defined */

end megatron.h-------------------------------------

start megatron.c------------------------------------
23,24d22
<        "macheader",
<        "macbinaryheader",
35d32
<     int  showheaderonly = 0;
54d50
<     if (( module == MACHEADER ) || ( module == MACBINARYHEADER ))
showheaderonly = 1;
61,65c57
<  if ( strcmp( argv [ c ], "-header" ) == 0 ) {
<   showheaderonly = 1;
<   continue;
<  }
<  if ( rc = megatron( argv[ c ], module , showheaderonly ) != 0 ) {
---
>  if ( rc = megatron( argv[ c ], module ) != 0 ) {
72c64
< megatron( path, module, showheaderonly )
---
> megatron( path, module )
75d66
<     int  showheaderonly;
82d72
<     int                 k;
109,121d98
<     if ( showheaderonly ) {
<         printf("name: %s\n",fh.name);
<         printf("comment: %s\n",fh.comment);
<         for(k=0;k<NUMFORKS;++k) printf("forklen_%d: %u\n", k,
h.forklen[ k ]);
<         printf("create_date: %u\n",fh.create_date);
<         printf("mod_date: %u\n",fh.mod_date);
<         printf("backup_date: %u\n",fh.backup_date);
<         printf("type: %4.4s\n",(char *)(&(fh.finder_info.fdType)));
<         printf("creator: %4.4s\n",(char *)(&(fh.finder_info.fdCreator)));
<         printf("flags: %x\n",fh.finder_info.fdFlags);
<         return( from_close( module ));
<     }
<
183d159
<  case MACBINARYHEADER :
187d162
<  case MACHEADER :

end megatron.c-------------------------------------

---

From: "Frank Morton" <[email-masked]>
Date: Thu, 27 Aug 1998 17:08:35 -0500

Woops...regarding my earlier megatron patch...I already have a
patch to it. I forgot about big/little endian issues. The original
patch works fine on SPARC, but not on Intel format.

Here is a patch to the previous patch that fixes that. I have "lightly"
tested this under Solaris and Linux.

Sorry for jumping the gun...

If anyone would like to send them the doubly patched source, just
let me know where you want it ftp'd (or whatever).

>start megatron.c------------------------------------
113,115c113,115
<         printf("create_date: %u\n",htonl(fh.create_date));
<         printf("mod_date: %u\n",htonl(fh.mod_date));
<         printf("backup_date: %u\n",htonl(fh.backup_date));
---
>         printf("create_date: %u\n",fh.create_date);
>         printf("mod_date: %u\n",fh.mod_date);
>         printf("backup_date: %u\n",fh.backup_date);
118c118
<         printf("flags: %x\n",htons(fh.finder_info.fdFlags));
---
>         printf("flags: %x\n",fh.finder_info.fdFlags);

---

From: "Frank Morton" <[email-masked]>
Date: Fri, 28 Aug 1998 10:21:48 -0500

>   I know this is a stupid question, but what is megatron and what does it
>do.? I looked in the man pages, but found nothing.  ( I think I installed
>the man pages improperly.)

there is a man page.

megatron is a utility I discovered lately that provides conversion between
different formats. For example, if you want to convert a file placed on the
server from a macintosh into macbinary format for make sure you
properly send both the data and resource fork, keep the macintosh type
and creator, you can invoke megatron as "macbinary" to do so.

if you look in your atalk/bin directory, you will see a number of symbolic
links to megatron. it is one of these utilities that looks at how it was
invoked to know what to do.

i needed the ability to get the finder info (like type and creator) for a
java-based image management system i am putting together...which is
why i patched megatron.

another example where I used megatron. this same image management
system need the ability to download images via the web. to do so properly
to the mac, i decided to use macbinary to do so. so, when a person
selects a file for download that has a resource fork, it temporarily makes
a macbinary file on-the-fly to send down the pipe to the browser
using megatron. it is really quite capable.