xref: /netbsd-src/external/gpl2/mkhybrid/dist/apple.h (revision 785d5ade45d5c4273ed022c6e65f4287fd6512b5)
1 /*
2 ** apple.h:	cut down macfile.h from CAP distribution
3 */
4 #ifndef _APPLE_H
5 
6 #include <sys/param.h>
7 #include <mactypes.h>
8 
9 #ifdef __sgi		/* bit of a hack ... need to investigate further */
10 #define __svr4__	/* maybe there's a "configure" solution ? */
11 #endif /* __sgi */
12 
13 #ifndef O_BINARY
14 #define O_BINARY 0
15 #endif /* O_BINARY */
16 
17 #ifdef _WIN32_TEST
18 #undef UNICODE
19 #include <windows.h>
20 #endif /* _WIN32 */
21 
22 #ifndef MIN
23 #define MIN(a,b) (((a)<(b))?(a):(b))
24 #endif /* MIN */
25 
26 #define CT_SIZE		4			/* Size of type/creator */
27 #define NUMMAP		512			/* initial number of maps */
28 #define BLANK		"    "			/* blank type/creator */
29 #define DEFMATCH	"*"			/* default mapping extension */
30 
31 typedef struct {
32 	char		*extn;			/* filename extension */
33 	int		elen;			/* length of extension */
34 	char		type[CT_SIZE+1];	/* extension type */
35 	char		creator[CT_SIZE+1];	/* extension creator */
36 	unsigned short	fdflags;		/* finder flags */
37 } afpmap;
38 
39 /* from "data.h" - libhfs routines */
40 unsigned long d_toutime(unsigned long);
41 long d_getl(unsigned char *);
42 short d_getw(unsigned char *);
43 
44 #include "libfile/proto.h"
45 
46 /****** TYPE_CAP ******/
47 
48 /*
49  * taken from the CAP distribution:
50  * macfile.h - header file with Macintosh file definitions
51  *
52  * AppleTalk package for UNIX (4.2 BSD).
53  *
54  * Copyright (c) 1986, 1987, 1988 by The Trustees of Columbia University in the
55  * City of New York.
56  *
57  * Edit History:
58  *
59  *  Sept 1987	Created by Charlie
60  *
61  */
62 
63 
64 #ifndef USE_MAC_DATES
65 #define	USE_MAC_DATES
66 #endif /* USE_MAC_DATES */
67 
68 typedef unsigned char byte;
69 typedef char sbyte;
70 typedef unsigned short word;
71 typedef short sword;
72 typedef unsigned int dword;
73 typedef int sdword;
74 /*
75 typedef unsigned long dword;
76 typedef long sdword;
77 */
78 
79 #define MAXCLEN 199		/* max size of a comment string */
80 #define FINFOLEN 32		/* Finder info is 32 bytes */
81 #define MAXMACFLEN 31		/* max Mac file name length */
82 
83 typedef struct {
84   /* base finder information */
85   byte fdType[4];		/* File type [4]*/
86   byte fdCreator[4];		/* File creator [8]*/
87   word fdFlags;			/* Finder flags [10]*/
88   word fdLocation[2];		/* File's location [14] */
89   word fdFldr;			/* File's window [16] */
90   /* extended finder information */
91   word fdIconID;		/* Icon ID [18] */
92   word fdUnused[4];		/* Unused [26] */
93   word fdComment;		/* Comment ID [28] */
94   dword fdPutAway;		/* Home directory ID [32] */
95   word fi_attr;			/* attributes */
96 #define FI_MAGIC1 255
97   byte fi_magic1;		/* was: length of comment */
98 #define FI_VERSION 0x10		/* version major 1, minor 0 */
99 				/* if we have more than 8 versions wer're */
100 				/* doiong something wrong anyway */
101   byte fi_version;		/* version number */
102 #define FI_MAGIC 0xda
103   byte fi_magic;		/* magic word check */
104   byte fi_bitmap;		/* bitmap of included info */
105 #define FI_BM_SHORTFILENAME 0x1	/* is this included? */
106 #define FI_BM_MACINTOSHFILENAME 0x2 /* is this included? */
107   byte fi_shortfilename[12+1];	/* possible short file name */
108   byte fi_macfilename[32+1];	/* possible macintosh file name */
109   byte fi_comln;		/* comment length */
110   byte fi_comnt[MAXCLEN+1];	/* comment string */
111 #ifdef USE_MAC_DATES
112   byte fi_datemagic;		/* sanity check */
113 #define FI_MDATE 0x01		/* mtime & utime are valid */
114 #define FI_CDATE 0x02		/* ctime is valid */
115   byte fi_datevalid;		/* validity flags */
116   byte fi_ctime[4];		/* mac file create time */
117   byte fi_mtime[4];		/* mac file modify time */
118   byte fi_utime[4];		/* (real) time mtime was set */
119 #endif /* USE_MAC_DATES */
120 } FileInfo;
121 
122 /* Atribute flags */
123 #define FI_ATTR_SETCLEAR 0x8000 /* set-clear attributes */
124 #define FI_ATTR_READONLY 0x20	/* file is read-only */
125 #define FI_ATTR_ROPEN 0x10	/* resource fork in use */
126 #define FI_ATTR_DOPEN 0x80	/* data fork in use */
127 #define FI_ATTR_MUSER 0x2	/* multi-user */
128 #define FI_ATTR_INVISIBLE 0x1	/* invisible */
129 
130 /**** MAC STUFF *****/
131 
132 /* Flags */
133 #define FNDR_fOnDesk 0x1
134 #define FNDR_fHasBundle 0x2000
135 #define FNDR_fInvisible 0x4000
136 /* locations */
137 #define FNDR_fTrash -3	/* File in Trash */
138 #define FNDR_fDesktop -2	/* File on desktop */
139 #define FNDR_fDisk 0	/* File in disk window */
140 
141 /****** TYPE_ESHARE ******/
142 
143 /*
144 **	Information supplied by Jens-Uwe Mager (jum@helios.de)
145 */
146 
147 #define ES_VERSION 	0x0102
148 #define ES_MAGIC 	0x3681093
149 #define ES_INFOLEN	32
150 #define ES_INFO_SIZE	512
151 
152 typedef unsigned char uint8;
153 typedef unsigned short uint16;
154 typedef unsigned int uint32;
155 
156 typedef struct {
157 	uint32	  	magic;
158 	uint32	  	serno;			/* written only, never read */
159 	uint16	  	version;
160 	uint16	  	attr;			/* invisible... */
161 	uint16	  	openMax;		/* max number of opens */
162 	uint16	  	filler0;
163 	uint32	  	backupCleared;		/* time backup bit cleared */
164 	uint32          id;			/* dir/file id */
165         uint32          createTime;             /* unix format */
166         uint32          backupTime;             /* unix format */
167 /*	uint8		finderInfo[INFOLEN];*/
168   	/* base finder information (compatible with CAP) */
169 	uint8		fdType[4];		/* File type [4]*/
170 	uint8		fdCreator[4];		/* File creator [8]*/
171 	uint16		fdFlags;		/* Finder flags [10]*/
172 	uint16		fdLocation[2];		/* File's location [14] */
173 	uint16		fdFldr;			/* File's window [16] */
174 	/* extended finder information */
175 	uint16		fdIconID;		/* Icon ID [18] */
176 	uint16		fdUnused[4];		/* Unused [26] */
177 	uint16		fdComment;		/* Comment ID [28] */
178 	uint32		fdPutAway;		/* Home directory ID [32] */
179 } es_FileInfo;
180 
181 /****** TYPE_USHARE ******/
182 
183 /* similar to the EtherShare layout, but the finder info stuff is different
184    info provided by: Phil Sylvester <psylvstr@interaccess.com> */
185 
186 typedef struct {
187 	uint8		fdType[4];		/* File type [4]*/
188 	uint8		fdCreator[4];		/* File creator [8]*/
189 	uint16		fdFlags;		/* Finder flags [10]*/
190 	uint8		unknown1[22];		/* ignore [32] */
191 	uint32		btime;			/* mac file backup time [36]*/
192 	uint8		unknown2[4];		/* ignore [40] */
193 	uint32		ctime;			/* mac file create time [44]*/
194 	uint8		unknown3[8];		/* ignore [52] */
195 	uint32		mtime;			/* mac file modify time [56]*/
196 	uint8		unknown4[456];		/* ignore [512] */
197 } us_FileInfo;
198 
199 /****** TYPE_DOUBLE, TYPE_SINGLE ******/
200 
201 /*
202 **	Taken from cvt2cap (c) May 1988, Paul Campbell
203 */
204 
205 typedef struct {
206 	dword id;
207 	dword offset;
208 	dword length;
209 } a_entry;
210 
211 typedef struct {
212 	dword   magic;
213 	dword   version;
214 	char    home[16];
215 	word    nentries;
216 	a_entry	entries[1];
217 } a_hdr;
218 
219 #define A_HDR_SIZE	26
220 #define A_ENTRY_SIZE	sizeof(a_entry)
221 
222 #define A_VERSION	0x00010000
223 #define APPLE_SINGLE	0x00051600
224 #define APPLE_DOUBLE	0x00051607
225 #define ID_DATA		1
226 #define ID_RESOURCE	2
227 #define ID_NAME		3
228 #define ID_FINDER	9
229 
230 /****** TYPE_MACBIN ******/
231 /*
232 **	taken from capit.c by Nigel Perry, np@doc.ic.ac.uk which is adapted
233 **	from unmacbin by John M. Sellens, jmsellens@watdragon.uwaterloo.ca
234 */
235 
236 
237 #define MB_NAMELEN 63              /* maximum legal Mac file name length */
238 #define MB_SIZE 128
239 
240 /* Format of a bin file:
241 A bin file is composed of 128 byte blocks.  The first block is the
242 info_header (see below).  Then comes the data fork, null padded to fill the
243 last block.  Then comes the resource fork, padded to fill the last block.  A
244 proposal to follow with the text of the Get Info box has not been implemented,
245 to the best of my knowledge.  Version, zero1 and zero2 are what the receiving
246 program looks at to determine if a MacBinary transfer is being initiated.
247 */
248 typedef struct {     /* info file header (128 bytes). Unfortunately, these
249                         longs don't align to word boundaries */
250             byte version;           /* there is only a version 0 at this time */
251             byte nlen;              /* Length of filename. */
252             byte name[MB_NAMELEN];  /* Filename */
253             byte type[4];           /* File type. */
254             byte auth[4];           /* File creator. */
255             byte flags;             /* file flags: LkIvBnSyBzByChIt */
256             byte zero1;             /* Locked, Invisible,Bundle, System */
257                                     /* Bozo, Busy, Changed, Init */
258             byte icon_vert[2];      /* Vertical icon position within window */
259             byte icon_horiz[2];     /* Horizontal icon postion in window */
260             byte window_id[2];      /* Window or folder ID. */
261             byte protect;           /* = 1 for protected file, 0 otherwise */
262             byte zero2;
263             byte dflen[4];          /* Data Fork length (bytes) - most sig.  */
264             byte rflen[4];          /* Resource Fork length       byte first */
265             byte cdate[4];          /* File's creation date. */
266             byte mdate[4];          /* File's "last modified" date. */
267             byte ilen[2];           /* GetInfo message length */
268 	    byte flags2;            /* Finder flags, bits 0-7 */
269 	    byte unused[14];
270 	    byte packlen[4];        /* length of total files when unpacked */
271 	    byte headlen[2];        /* length of secondary header */
272 	    byte uploadvers;        /* Version of MacBinary II that the uploading program is written for */
273 	    byte readvers;          /* Minimum MacBinary II version needed to read this file */
274             byte crc[2];            /* CRC of the previous 124 bytes */
275 	    byte padding[2];        /* two trailing unused bytes */
276 } mb_info;
277 
278 /*
279 **	An array useful for CRC calculations that use 0x1021 as the "seed"
280 **	taken from mcvert.c modified by Jim Van Verth.
281 */
282 
283 static unsigned short mb_magic[] = {
284     0x0000,  0x1021,  0x2042,  0x3063,  0x4084,  0x50a5,  0x60c6,  0x70e7,
285     0x8108,  0x9129,  0xa14a,  0xb16b,  0xc18c,  0xd1ad,  0xe1ce,  0xf1ef,
286     0x1231,  0x0210,  0x3273,  0x2252,  0x52b5,  0x4294,  0x72f7,  0x62d6,
287     0x9339,  0x8318,  0xb37b,  0xa35a,  0xd3bd,  0xc39c,  0xf3ff,  0xe3de,
288     0x2462,  0x3443,  0x0420,  0x1401,  0x64e6,  0x74c7,  0x44a4,  0x5485,
289     0xa56a,  0xb54b,  0x8528,  0x9509,  0xe5ee,  0xf5cf,  0xc5ac,  0xd58d,
290     0x3653,  0x2672,  0x1611,  0x0630,  0x76d7,  0x66f6,  0x5695,  0x46b4,
291     0xb75b,  0xa77a,  0x9719,  0x8738,  0xf7df,  0xe7fe,  0xd79d,  0xc7bc,
292     0x48c4,  0x58e5,  0x6886,  0x78a7,  0x0840,  0x1861,  0x2802,  0x3823,
293     0xc9cc,  0xd9ed,  0xe98e,  0xf9af,  0x8948,  0x9969,  0xa90a,  0xb92b,
294     0x5af5,  0x4ad4,  0x7ab7,  0x6a96,  0x1a71,  0x0a50,  0x3a33,  0x2a12,
295     0xdbfd,  0xcbdc,  0xfbbf,  0xeb9e,  0x9b79,  0x8b58,  0xbb3b,  0xab1a,
296     0x6ca6,  0x7c87,  0x4ce4,  0x5cc5,  0x2c22,  0x3c03,  0x0c60,  0x1c41,
297     0xedae,  0xfd8f,  0xcdec,  0xddcd,  0xad2a,  0xbd0b,  0x8d68,  0x9d49,
298     0x7e97,  0x6eb6,  0x5ed5,  0x4ef4,  0x3e13,  0x2e32,  0x1e51,  0x0e70,
299     0xff9f,  0xefbe,  0xdfdd,  0xcffc,  0xbf1b,  0xaf3a,  0x9f59,  0x8f78,
300     0x9188,  0x81a9,  0xb1ca,  0xa1eb,  0xd10c,  0xc12d,  0xf14e,  0xe16f,
301     0x1080,  0x00a1,  0x30c2,  0x20e3,  0x5004,  0x4025,  0x7046,  0x6067,
302     0x83b9,  0x9398,  0xa3fb,  0xb3da,  0xc33d,  0xd31c,  0xe37f,  0xf35e,
303     0x02b1,  0x1290,  0x22f3,  0x32d2,  0x4235,  0x5214,  0x6277,  0x7256,
304     0xb5ea,  0xa5cb,  0x95a8,  0x8589,  0xf56e,  0xe54f,  0xd52c,  0xc50d,
305     0x34e2,  0x24c3,  0x14a0,  0x0481,  0x7466,  0x6447,  0x5424,  0x4405,
306     0xa7db,  0xb7fa,  0x8799,  0x97b8,  0xe75f,  0xf77e,  0xc71d,  0xd73c,
307     0x26d3,  0x36f2,  0x0691,  0x16b0,  0x6657,  0x7676,  0x4615,  0x5634,
308     0xd94c,  0xc96d,  0xf90e,  0xe92f,  0x99c8,  0x89e9,  0xb98a,  0xa9ab,
309     0x5844,  0x4865,  0x7806,  0x6827,  0x18c0,  0x08e1,  0x3882,  0x28a3,
310     0xcb7d,  0xdb5c,  0xeb3f,  0xfb1e,  0x8bf9,  0x9bd8,  0xabbb,  0xbb9a,
311     0x4a75,  0x5a54,  0x6a37,  0x7a16,  0x0af1,  0x1ad0,  0x2ab3,  0x3a92,
312     0xfd2e,  0xed0f,  0xdd6c,  0xcd4d,  0xbdaa,  0xad8b,  0x9de8,  0x8dc9,
313     0x7c26,  0x6c07,  0x5c64,  0x4c45,  0x3ca2,  0x2c83,  0x1ce0,  0x0cc1,
314     0xef1f,  0xff3e,  0xcf5d,  0xdf7c,  0xaf9b,  0xbfba,  0x8fd9,  0x9ff8,
315     0x6e17,  0x7e36,  0x4e55,  0x5e74,  0x2e93,  0x3eb2,  0x0ed1,  0x1ef0
316 };
317 
318 
319 /****** TYPE_FE ******/
320 
321 /* Information provided by Mark Weinstein <mrwesq@earthlink.net> */
322 
323 typedef struct {
324 	byte	nlen;
325 	byte	name[31];
326 	byte	type[4];
327 	byte	creator[4];
328 	byte	flags[2];
329 	byte	location[4];
330 	byte	fldr[2];
331 	byte	xinfo[16];
332 	byte	cdate[4];
333 	byte	mdate[4];
334 	byte	bdate[4];
335 	byte	fileid[4];
336 	byte	sname[8];
337 	byte	ext[3];
338 	byte	pad;
339 } fe_info;
340 
341 #define FE_SIZE 92
342 
343 /****** TYPE_SGI ******/
344 
345 typedef struct {
346 	char    unknown1[8];
347 	char    type[4];
348 	char    creator[4];
349 	char    unknown2[238];
350 	char    name[32];
351 	char    unknown3[14];
352 } sgi_info;
353 
354 #define SGI_SIZE 300
355 
356 #define _APPLE_H
357 #endif /* _APPLE_H */
358