1 /*
2 ** make_desktop: create "Desktop DB" and "Desktop DF" files.
3 **
4 ** These are set up to prevent the Mac "rebuilding the desktop"
5 ** when the CD is inserted ???
6 **
7 ** I don't know if these files should be populated, but I've just
8 ** created these files in their initial states:
9 **
10 ** Desktop DB: Initial size == volume's clump size
11 ** first block contents found by using od ...
12 ** rest of file seems to be padding
13 ** No resource fork
14 **
15 ** Desktop DF: Empty
16 **
17 ** If the files already exist, then set correct type/creator/flags
18 **
19 ** James Pearson 11/8/97
20 ** Adapted from mkhfs routines for mkhybrid
21 */
22
23 #ifdef APPLE_HYB
24
25 #include <string.h>
26 #include <err.h>
27 #include "hfs.h"
28
29 #define DB "Desktop DB"
30 #define DBFC "DMGR"
31 #define DBT "BTFL"
32
33 #define DF "Desktop DF"
34 #define DFT "DTFL"
35
36 /* from "data.h" - libhfs routines */
37 void d_putw(unsigned char *, short);
38 void d_putl(unsigned char *, long);
39 /* from volume.c */
40 void write_fork(hfsfile *, long);
41
42 extern hce_mem *hce; /* libhfs/mkisofs extras */
43
44 int
make_desktop(hfsvol * vol,int end)45 make_desktop(hfsvol *vol, int end)
46 /* hfsvol *vol; Mac volume */
47 {
48 hfsfile *hfp; /* Mac file */
49 hfsdirent ent; /* Mac finderinfo */
50 unsigned short clps; /* clump size */
51 unsigned short blks; /* blocks in a clump */
52 unsigned char *blk; /* user data */
53
54 /* set up default directory entries - not all these fields
55 are needed, but we'll set them up anyway ... */
56 ent.rsize = 0; /* resource size == 0 */
57 strcpy(ent.creator, DBFC); /* creator */
58 strcpy(ent.type, DBT); /* type */
59 ent.crdate = ent.mddate = time(0); /* date is now */
60 ent.fdflags = HFS_FNDR_ISINVISIBLE; /* invisible files */
61
62 /* clear the DB file */
63 blk = hce->hfs_ce + hce->hfs_ce_size*HFS_BLOCKSZ;
64 blks = hce->hfs_dt_size;
65 clps = blks*HFS_BLOCKSZ;
66
67 memset(blk, 0, clps);
68
69 /* create "Desktop DB" (if it doesn't exist) */
70 if(hfs_create(vol, DB, ent.type, ent.creator) == 0)
71 {
72 /* DB file size from hce_mem info */
73 /* set up "Desktop DB" data - following found by od'ing
74 the "Desktop DB" file */
75 d_putw(blk+8, 0x100);
76 d_putw(blk+10, 0x3);
77
78 d_putw(blk+32, 0x200);
79 d_putw(blk+34, 0x25);
80
81 d_putl(blk+36, blks);
82 d_putl(blk+40, blks - 1);
83
84 d_putw(blk+48, clps);
85 d_putw(blk+50, 0xff);
86
87 d_putw(blk+120, 0x20a);
88 d_putw(blk+122, 0x100);
89
90 d_putw(blk+248, 0x8000);
91
92 d_putl(blk+504, 0x1f800f8);
93 d_putl(blk+508, 0x78000e);
94
95 /* entries for "Desktop DB" */
96 ent.dsize = clps; /* size = clump size */
97
98 /* open file */
99 if((hfp = hfs_open(vol, DB)) == 0)
100 err(1, "%s", hfs_error);
101
102 /* "write" file */
103 write_fork(hfp, clps);
104
105 /* set DB file attributes */
106 if (hfs_fsetattr(hfp, &ent) < 0)
107 err(1, "%s", hfs_error);
108
109 /* find the real start of the file */
110 end += hce->hfs_ce_size;
111
112 /* close DB file */
113 if (hfs_close(hfp, end, 0) < 0)
114 err(1, "%s", hfs_error);
115 }
116 else
117 {
118 /* if it already exists, then make sure it has the correct
119 type/creator and flags */
120 if(hfs_setattr(vol, DB, &ent) < 0)
121 err(1, "%s", hfs_error);
122 }
123
124 /* setup "Desktop DF" file as an empty file */
125 strcpy(ent.type, DFT); /* type */
126 ent.dsize = 0; /* empty */
127
128 /* create DF file (if it doesn't exist) - no need to open it */
129 hfs_create(vol, DF, ent.type, ent.creator);
130
131 /* set DB file attributes */
132 if (hfs_setattr(vol, DF, &ent) < 0)
133 err(1, "%s", hfs_error);
134 return 0;
135 }
136 #endif /* APPLE_HYB */
137