patch genisoimage multi extent
[platform/upstream/cdrkit.git] / genisoimage / desktop.c
1 /*
2  * This file has been modified for the cdrkit suite.
3  *
4  * The behaviour and appearence of the program code below can differ to a major
5  * extent from the version distributed by the original author(s).
6  *
7  * For details, see Changelog file distributed with the cdrkit package. If you
8  * received this file from another source then ask the distributing person for
9  * a log of modifications.
10  *
11  */
12
13 /* @(#)desktop.c        1.6 04/03/04 joerg, Copyright 1997, 1998, 1999, 2000 James Pearson */
14 /*
15  *      Copyright (c) 1997, 1998, 1999, 2000 James Pearson
16  *
17  * This program is free software; you can redistribute it and/or modify
18  * it under the terms of the GNU General Public License as published by
19  * the Free Software Foundation; either version 2, or (at your option)
20  * any later version.
21  *
22  * This program is distributed in the hope that it will be useful,
23  * but WITHOUT ANY WARRANTY; without even the implied warranty of
24  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
25  * GNU General Public License for more details.
26  *
27  * You should have received a copy of the GNU General Public License
28  * along with this program; see the file COPYING.  If not, write to
29  * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
30  */
31
32 /*
33  *      make_desktop: create "Desktop DB" and "Desktop DF" files.
34  *
35  *      These are set up to prevent the Mac "rebuilding the desktop"
36  *      when the CD is inserted ???
37  *
38  *      I don't know if these files should be populated, but I've just
39  *      created these files in their initial states:
40  *
41  *      Desktop DB:     Initial size == volume's clump size
42  *                      first block contents found by using od ...
43  *                      rest of file seems to be padding
44  *                      No resource fork
45  *
46  *      Desktop DF:     Empty
47  *
48  *      If the files already exist, then set correct type/creator/flags
49  *
50  *      James Pearson 11/8/97
51  *      Adapted from mkhfs routines for mkhybrid
52  */
53
54 #ifdef APPLE_HYB
55
56 #include <mconfig.h>
57 #include "genisoimage.h"
58
59 #define DB      "Desktop DB"
60 #define DBFC    "DMGR"
61 #define DBT     "BTFL"
62
63 #define DF      "Desktop DF"
64 #define DFT     "DTFL"
65
66 /*
67  * from "data.h" - libhfs routines
68  */
69 extern  void d_putw(unsigned char *, short);
70 extern  void d_putl(unsigned char *, long);
71
72 int     make_desktop(hfsvol *vol, int end);
73
74
75 extern  hce_mem *hce;   /* libhfs/genisoimage extras */
76
77 int
78 make_desktop(hfsvol *vol, int end)
79 {
80         hfsfile         *hfp;                   /* Mac file */
81         hfsdirent       ent;                    /* Mac finderinfo */
82         unsigned long   clps;                   /* clump size */
83         unsigned short  blks;                   /* blocks in a clump */
84         unsigned char   *blk;                   /* user data */
85
86         /*
87          * set up default directory entries - not all these fields are needed,
88          * but we'll set them up anyway ...
89          * First do a memset because there was a report about randomly
90          * changing Desktop DB/DF entries...
91          */
92         memset(&ent, 0, sizeof (hfsdirent));    /* First clear all ... */
93         ent.u.file.rsize = 0;                   /* resource size == 0 */
94         strcpy(ent.u.file.creator, DBFC);       /* creator */
95         strcpy(ent.u.file.type, DBT);           /* type */
96         ent.crdate = ent.mddate = time(0);      /* date is now */
97         ent.fdflags = HFS_FNDR_ISINVISIBLE;     /* invisible files */
98
99         /*
100          * clear the DB file
101          */
102         blk = hce->hfs_ce + hce->hfs_ce_size * HFS_BLOCKSZ;
103         blks = hce->hfs_dt_size;
104         clps = blks * HFS_BLOCKSZ;
105
106         memset(blk, 0, clps);
107
108         /*
109          * create "Desktop DB" (if it doesn't exist)
110          */
111         if (hfs_create(vol, DB, ent.u.file.type, ent.u.file.creator) == 0) {
112                 /*
113                  * DB file size from hce_mem info
114                  * set up "Desktop DB" data - following found by od'ing the
115                  * "Desktop DB" file
116                  */
117                 d_putw(blk + 8, 0x100);
118                 d_putw(blk + 10, 0x3);
119
120                 d_putw(blk + 32, 0x200);
121                 d_putw(blk + 34, 0x25);
122
123                 d_putl(blk + 36, blks);
124                 d_putl(blk + 40, blks - 1);
125
126                 d_putl(blk + 46, clps);
127                 d_putw(blk + 50, 0xff);
128
129                 d_putw(blk + 120, 0x20a);
130                 d_putw(blk + 122, 0x100);
131
132                 d_putw(blk + 248, 0x8000);
133
134                 d_putl(blk + 504, 0x1f800f8);
135                 d_putl(blk + 508, 0x78000e);
136
137                 /* entries for "Desktop DB" */
138                 ent.u.file.dsize = clps;        /* size = clump size */
139
140                 /* open file */
141                 if ((hfp = hfs_open(vol, DB)) == 0)
142                         perr(hfs_error);
143
144                 /* "write" file */
145                 write_fork(hfp, clps);
146
147                 /* set DB file attributes */
148                 if (hfs_fsetattr(hfp, &ent) < 0)
149                         perr(hfs_error);
150
151                 /* find the real start of the file */
152                 end += hce->hfs_ce_size;
153
154                 /* close DB file */
155                 if (hfs_close(hfp, end, 0) < 0)
156                         perr(hfs_error);
157         } else {
158                 /*
159                  * if it already exists, then make sure it has the correct
160                  * type/creator and flags
161                  */
162                 if (hfs_setattr(vol, DB, &ent) < 0)
163                         perr(hfs_error);
164         }
165
166         /* setup "Desktop DF" file as an empty file */
167         strcpy(ent.u.file.type, DFT);           /* type */
168         ent.u.file.dsize = 0;                   /* empty */
169
170         /* create DF file (if it doesn't exist) - no need to open it */
171         hfs_create(vol, DF, ent.u.file.type, ent.u.file.creator);
172
173         /* set DB file attributes */
174         if (hfs_setattr(vol, DF, &ent) < 0)
175                 perr(hfs_error);
176
177         return (0);
178 }
179
180 #endif  /* APPLE_HYB */