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