summaryrefslogtreecommitdiff
path: root/genisoimage/desktop.c
blob: 51b0269b42c574495fec6a54465324ee74a6e23e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
/*
 * This file has been modified for the cdrkit suite.
 *
 * The behaviour and appearence of the program code below can differ to a major
 * extent from the version distributed by the original author(s).
 *
 * For details, see Changelog file distributed with the cdrkit package. If you
 * received this file from another source then ask the distributing person for
 * a log of modifications.
 *
 */

/* @(#)desktop.c	1.6 04/03/04 joerg, Copyright 1997, 1998, 1999, 2000 James Pearson */
/*
 *      Copyright (c) 1997, 1998, 1999, 2000 James Pearson
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2, or (at your option)
 * any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; see the file COPYING.  If not, write to
 * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
 */

/*
 *	make_desktop: create "Desktop DB" and "Desktop DF" files.
 *
 *	These are set up to prevent the Mac "rebuilding the desktop"
 *	when the CD is inserted ???
 *
 *	I don't know if these files should be populated, but I've just
 *	created these files in their initial states:
 *
 *	Desktop DB:	Initial size == volume's clump size
 *			first block contents found by using od ...
 *			rest of file seems to be padding
 *			No resource fork
 *
 *	Desktop DF:	Empty
 *
 *	If the files already exist, then set correct type/creator/flags
 *
 *	James Pearson 11/8/97
 *	Adapted from mkhfs routines for mkhybrid
 */

#ifdef APPLE_HYB

#include <mconfig.h>
#include "genisoimage.h"

#define	DB	"Desktop DB"
#define	DBFC	"DMGR"
#define	DBT	"BTFL"

#define	DF	"Desktop DF"
#define	DFT	"DTFL"

/*
 * from "data.h" - libhfs routines
 */
extern	void d_putw(unsigned char *, short);
extern	void d_putl(unsigned char *, long);

int	make_desktop(hfsvol *vol, int end);


extern	hce_mem *hce;	/* libhfs/genisoimage extras */

int
make_desktop(hfsvol *vol, int end)
{
	hfsfile		*hfp;			/* Mac file */
	hfsdirent	ent;			/* Mac finderinfo */
	unsigned long	clps;			/* clump size */
	unsigned short	blks;			/* blocks in a clump */
	unsigned char	*blk;			/* user data */

	/*
	 * set up default directory entries - not all these fields are needed,
	 * but we'll set them up anyway ...
	 * First do a memset because there was a report about randomly
	 * changing Desktop DB/DF entries...
	 */
	memset(&ent, 0, sizeof (hfsdirent));	/* First clear all ... */
	ent.u.file.rsize = 0;			/* resource size == 0 */
	strcpy(ent.u.file.creator, DBFC);	/* creator */
	strcpy(ent.u.file.type, DBT);		/* type */
	ent.crdate = ent.mddate = time(0);	/* date is now */
	ent.fdflags = HFS_FNDR_ISINVISIBLE;	/* invisible files */

	/*
	 * clear the DB file
	 */
	blk = hce->hfs_ce + hce->hfs_ce_size * HFS_BLOCKSZ;
	blks = hce->hfs_dt_size;
	clps = blks * HFS_BLOCKSZ;

	memset(blk, 0, clps);

	/*
	 * create "Desktop DB" (if it doesn't exist)
	 */
	if (hfs_create(vol, DB, ent.u.file.type, ent.u.file.creator) == 0) {
		/*
		 * DB file size from hce_mem info
		 * set up "Desktop DB" data - following found by od'ing the
		 * "Desktop DB" file
		 */
		d_putw(blk + 8, 0x100);
		d_putw(blk + 10, 0x3);

		d_putw(blk + 32, 0x200);
		d_putw(blk + 34, 0x25);

		d_putl(blk + 36, blks);
		d_putl(blk + 40, blks - 1);

		d_putl(blk + 46, clps);
		d_putw(blk + 50, 0xff);

		d_putw(blk + 120, 0x20a);
		d_putw(blk + 122, 0x100);

		d_putw(blk + 248, 0x8000);

		d_putl(blk + 504, 0x1f800f8);
		d_putl(blk + 508, 0x78000e);

		/* entries for "Desktop DB" */
		ent.u.file.dsize = clps;	/* size = clump size */

		/* open file */
		if ((hfp = hfs_open(vol, DB)) == 0)
			perr(hfs_error);

		/* "write" file */
		write_fork(hfp, clps);

		/* set DB file attributes */
		if (hfs_fsetattr(hfp, &ent) < 0)
			perr(hfs_error);

		/* find the real start of the file */
		end += hce->hfs_ce_size;

		/* close DB file */
		if (hfs_close(hfp, end, 0) < 0)
			perr(hfs_error);
	} else {
		/*
		 * if it already exists, then make sure it has the correct
		 * type/creator and flags
		 */
		if (hfs_setattr(vol, DB, &ent) < 0)
			perr(hfs_error);
	}

	/* setup "Desktop DF" file as an empty file */
	strcpy(ent.u.file.type, DFT);		/* type */
	ent.u.file.dsize = 0;			/* empty */

	/* create DF file (if it doesn't exist) - no need to open it */
	hfs_create(vol, DF, ent.u.file.type, ent.u.file.creator);

	/* set DB file attributes */
	if (hfs_setattr(vol, DF, &ent) < 0)
		perr(hfs_error);

	return (0);
}

#endif	/* APPLE_HYB */