ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/cebix/BasiliskII/src/AmigaOS/extfs_amiga.cpp
(Generate patch)

Comparing BasiliskII/src/AmigaOS/extfs_amiga.cpp (file contents):
Revision 1.6 by cebix, 2000-01-21T13:47:02Z vs.
Revision 1.9 by cebix, 2000-07-22T16:07:19Z

# Line 1 | Line 1
1   /*
2   *  extfs_amiga.cpp - MacOS file system for access native file system access, AmigaOS specific stuff
3   *
4 < *  Basilisk II (C) 1997-1999 Christian Bauer
4 > *  Basilisk II (C) 1997-2000 Christian Bauer
5   *
6   *  This program is free software; you can redistribute it and/or modify
7   *  it under the terms of the GNU General Public License as published by
# Line 77 | Line 77 | void add_path_component(char *path, cons
77   *    /path/.finf/file
78   *  Resource fork:
79   *    /path/.rsrc/file
80 + *
81 + *  The .finf files store a FInfo/DInfo, followed by a FXInfo/DXInfo
82 + *  (16+16 bytes)
83   */
84  
82 // Layout of Finder info helper files (all fields big-endian)
83 struct finf_struct {
84        uint32 type;
85        uint32 creator;
86        uint16 flags;
87        uint8 pad0[22]; // total size: 32 bytes to match the size of FInfo+FXInfo
88 };
89
85   static void make_helper_path(const char *src, char *dest, const char *add, bool only_dir = false)
86   {
87          dest[0] = 0;
# Line 110 | Line 105 | static int create_helper_dir(const char
105   {
106          char helper_dir[MAX_PATH_LENGTH];
107          make_helper_path(path, helper_dir, add, true);
108 +        if (helper_dir[strlen(helper_dir) - 1] == '/')  // Remove trailing "/"
109 +                helper_dir[strlen(helper_dir) - 1] = 0;
110          return mkdir(helper_dir, 0777);
111   }
112  
# Line 156 | Line 153 | struct ext2type {
153   };
154  
155   static const ext2type e2t_translation[] = {
156 <        {".Z", 'ZIVM', 'LZIV'},
157 <        {".gz", 'Gzip', 'Gzip'},
158 <        {".hqx", 'TEXT', 'SITx'},
159 <        {".pdf", 'PDF ', 'CARO'},
160 <        {".ps", 'TEXT', 'ttxt'},
161 <        {".sit", 'SIT!', 'SITx'},
162 <        {".tar", 'TARF', 'TAR '},
163 <        {".uu", 'TEXT', 'SITx'},
164 <        {".uue", 'TEXT', 'SITx'},
165 <        {".zip", 'ZIP ', 'ZIP '},
166 <        {".8svx", '8SVX', 'SNDM'},
167 <        {".aifc", 'AIFC', 'TVOD'},
168 <        {".aiff", 'AIFF', 'TVOD'},
169 <        {".au", 'ULAW', 'TVOD'},
170 <        {".mid", 'MIDI', 'TVOD'},
171 <        {".midi", 'MIDI', 'TVOD'},
172 <        {".mp2", 'MPG ', 'TVOD'},
173 <        {".mp3", 'MPG ', 'TVOD'},
174 <        {".wav", 'WAVE', 'TVOD'},
175 <        {".bmp", 'BMPf', 'ogle'},
176 <        {".gif", 'GIFf', 'ogle'},
177 <        {".lbm", 'ILBM', 'GKON'},
178 <        {".ilbm", 'ILBM', 'GKON'},
179 <        {".jpg", 'JPEG', 'ogle'},
180 <        {".jpeg", 'JPEG', 'ogle'},
181 <        {".pict", 'PICT', 'ogle'},
182 <        {".png", 'PNGf', 'ogle'},
183 <        {".sgi", '.SGI', 'ogle'},
184 <        {".tga", 'TPIC', 'ogle'},
185 <        {".tif", 'TIFF', 'ogle'},
186 <        {".tiff", 'TIFF', 'ogle'},
187 <        {".html", 'TEXT', 'MOSS'},
188 <        {".txt", 'TEXT', 'ttxt'},
189 <        {".rtf", 'TEXT', 'MSWD'},
190 <        {".c", 'TEXT', 'R*ch'},
191 <        {".C", 'TEXT', 'R*ch'},
192 <        {".cc", 'TEXT', 'R*ch'},
193 <        {".cpp", 'TEXT', 'R*ch'},
194 <        {".cxx", 'TEXT', 'R*ch'},
195 <        {".h", 'TEXT', 'R*ch'},
196 <        {".hh", 'TEXT', 'R*ch'},
197 <        {".hpp", 'TEXT', 'R*ch'},
198 <        {".hxx", 'TEXT', 'R*ch'},
199 <        {".s", 'TEXT', 'R*ch'},
200 <        {".S", 'TEXT', 'R*ch'},
201 <        {".i", 'TEXT', 'R*ch'},
202 <        {".mpg", 'MPEG', 'TVOD'},
203 <        {".mpeg", 'MPEG', 'TVOD'},
204 <        {".mov", 'MooV', 'TVOD'},
205 <        {".fli", 'FLI ', 'TVOD'},
206 <        {".avi", 'VfW ', 'TVOD'},
156 >        {".z", FOURCC('Z','I','V','M'), FOURCC('L','Z','I','V')},
157 >        {".gz", FOURCC('G','z','i','p'), FOURCC('G','z','i','p')},
158 >        {".hqx", FOURCC('T','E','X','T'), FOURCC('S','I','T','x')},
159 >        {".pdf", FOURCC('P','D','F',' '), FOURCC('C','A','R','O')},
160 >        {".ps", FOURCC('T','E','X','T'), FOURCC('t','t','x','t')},
161 >        {".sit", FOURCC('S','I','T','!'), FOURCC('S','I','T','x')},
162 >        {".tar", FOURCC('T','A','R','F'), FOURCC('T','A','R',' ')},
163 >        {".uu", FOURCC('T','E','X','T'), FOURCC('S','I','T','x')},
164 >        {".uue", FOURCC('T','E','X','T'), FOURCC('S','I','T','x')},
165 >        {".zip", FOURCC('Z','I','P',' '), FOURCC('Z','I','P',' ')},
166 >        {".8svx", FOURCC('8','S','V','X'), FOURCC('S','N','D','M')},
167 >        {".aifc", FOURCC('A','I','F','C'), FOURCC('T','V','O','D')},
168 >        {".aiff", FOURCC('A','I','F','F'), FOURCC('T','V','O','D')},
169 >        {".au", FOURCC('U','L','A','W'), FOURCC('T','V','O','D')},
170 >        {".mid", FOURCC('M','I','D','I'), FOURCC('T','V','O','D')},
171 >        {".midi", FOURCC('M','I','D','I'), FOURCC('T','V','O','D')},
172 >        {".mp2", FOURCC('M','P','G',' '), FOURCC('T','V','O','D')},
173 >        {".mp3", FOURCC('M','P','G',' '), FOURCC('T','V','O','D')},
174 >        {".wav", FOURCC('W','A','V','E'), FOURCC('T','V','O','D')},
175 >        {".bmp", FOURCC('B','M','P','f'), FOURCC('o','g','l','e')},
176 >        {".gif", FOURCC('G','I','F','f'), FOURCC('o','g','l','e')},
177 >        {".lbm", FOURCC('I','L','B','M'), FOURCC('G','K','O','N')},
178 >        {".ilbm", FOURCC('I','L','B','M'), FOURCC('G','K','O','N')},
179 >        {".jpg", FOURCC('J','P','E','G'), FOURCC('o','g','l','e')},
180 >        {".jpeg", FOURCC('J','P','E','G'), FOURCC('o','g','l','e')},
181 >        {".pict", FOURCC('P','I','C','T'), FOURCC('o','g','l','e')},
182 >        {".png", FOURCC('P','N','G','f'), FOURCC('o','g','l','e')},
183 >        {".sgi", FOURCC('.','S','G','I'), FOURCC('o','g','l','e')},
184 >        {".tga", FOURCC('T','P','I','C'), FOURCC('o','g','l','e')},
185 >        {".tif", FOURCC('T','I','F','F'), FOURCC('o','g','l','e')},
186 >        {".tiff", FOURCC('T','I','F','F'), FOURCC('o','g','l','e')},
187 >        {".htm", FOURCC('T','E','X','T'), FOURCC('M','O','S','S')},
188 >        {".html", FOURCC('T','E','X','T'), FOURCC('M','O','S','S')},
189 >        {".txt", FOURCC('T','E','X','T'), FOURCC('t','t','x','t')},
190 >        {".rtf", FOURCC('T','E','X','T'), FOURCC('M','S','W','D')},
191 >        {".c", FOURCC('T','E','X','T'), FOURCC('R','*','c','h')},
192 >        {".cc", FOURCC('T','E','X','T'), FOURCC('R','*','c','h')},
193 >        {".cpp", FOURCC('T','E','X','T'), FOURCC('R','*','c','h')},
194 >        {".cxx", FOURCC('T','E','X','T'), FOURCC('R','*','c','h')},
195 >        {".h", FOURCC('T','E','X','T'), FOURCC('R','*','c','h')},
196 >        {".hh", FOURCC('T','E','X','T'), FOURCC('R','*','c','h')},
197 >        {".hpp", FOURCC('T','E','X','T'), FOURCC('R','*','c','h')},
198 >        {".hxx", FOURCC('T','E','X','T'), FOURCC('R','*','c','h')},
199 >        {".s", FOURCC('T','E','X','T'), FOURCC('R','*','c','h')},
200 >        {".i", FOURCC('T','E','X','T'), FOURCC('R','*','c','h')},
201 >        {".mpg", FOURCC('M','P','E','G'), FOURCC('T','V','O','D')},
202 >        {".mpeg", FOURCC('M','P','E','G'), FOURCC('T','V','O','D')},
203 >        {".mov", FOURCC('M','o','o','V'), FOURCC('T','V','O','D')},
204 >        {".fli", FOURCC('F','L','I',' '), FOURCC('T','V','O','D')},
205 >        {".avi", FOURCC('V','f','W',' '), FOURCC('T','V','O','D')},
206 >        {".qxd", FOURCC('X','D','O','C'), FOURCC('X','P','R','3')},
207 >        {".hfv", FOURCC('D','D','i','m'), FOURCC('d','d','s','k')},
208 >        {".dsk", FOURCC('D','D','i','m'), FOURCC('d','d','s','k')},
209 >        {".img", FOURCC('r','o','h','d'), FOURCC('d','d','s','k')},
210          {NULL, 0, 0}    // End marker
211   };
212  
213 < void get_finder_type(const char *path, uint32 &type, uint32 &creator)
213 > void get_finfo(const char *path, uint32 finfo, uint32 fxinfo)
214   {
215 <        type = 0;
216 <        creator = 0;
215 >        // Set default finder info
216 >        Mac_memset(finfo, 0, SIZEOF_FInfo);
217 >        if (fxinfo)
218 >                Mac_memset(fxinfo, 0, SIZEOF_FXInfo);
219 >        WriteMacInt16(finfo + fdFlags, DEFAULT_FINDER_FLAGS);
220 >        WriteMacInt32(finfo + fdLocation, (uint32)-1);
221  
222 <        // Open Finder info file
222 >        // Read Finder info file
223          int fd = open_finf(path, O_RDONLY);
224          if (fd >= 0) {
225 <
226 <                // Read file
227 <                finf_struct finf;
224 <                if (read(fd, &finf, sizeof(finf_struct)) >= 8) {
225 <
226 <                        // Type/creator are in Finder info file, return them
227 <                        type = ntohl(finf.type);
228 <                        creator = ntohl(finf.creator);
229 <                        close(fd);
230 <                        return;
231 <                }
225 >                ssize_t actual = read(fd, Mac2HostAddr(finfo), SIZEOF_FInfo);
226 >                if (fxinfo)
227 >                        actual += read(fd, Mac2HostAddr(fxinfo), SIZEOF_FXInfo);
228                  close(fd);
229 +                if (actual >= SIZEOF_FInfo)
230 +                        return;
231          }
232  
233          // No Finder info file, translate file name extension to MacOS type/creator
234 <        int path_len = strlen(path);
235 <        for (int i=0; e2t_translation[i].ext; i++) {
236 <                int ext_len = strlen(e2t_translation[i].ext);
237 <                if (path_len < ext_len)
238 <                        continue;
239 <                if (!strcmp(path + path_len - ext_len, e2t_translation[i].ext)) {
240 <                        type = e2t_translation[i].type;
241 <                        creator = e2t_translation[i].creator;
242 <                        break;
234 >        struct stat st;
235 >        if (stat(path, &st) == 0 && !S_ISDIR(st.st_mode)) {
236 >                int path_len = strlen(path);
237 >                for (int i=0; e2t_translation[i].ext; i++) {
238 >                        int ext_len = strlen(e2t_translation[i].ext);
239 >                        if (path_len < ext_len)
240 >                                continue;
241 >                        if (!strcasecmp(path + path_len - ext_len, e2t_translation[i].ext)) {
242 >                                WriteMacInt32(finfo + fdType, e2t_translation[i].type);
243 >                                WriteMacInt32(finfo + fdCreator, e2t_translation[i].creator);
244 >                                break;
245 >                        }
246                  }
247          }
248   }
249  
250 < void set_finder_type(const char *path, uint32 type, uint32 creator)
250 < {
251 <        // Open Finder info file
252 <        int fd = open_finf(path, O_RDWR);
253 <        if (fd < 0)
254 <                return;
255 <
256 <        // Read file
257 <        finf_struct finf;
258 <        finf.flags = DEFAULT_FINDER_FLAGS;
259 <        memset(&finf, 0, sizeof(finf_struct));
260 <        read(fd, &finf, sizeof(finf_struct));
261 <
262 <        // Set Finder flags
263 <        finf.type = htonl(type);
264 <        finf.creator = htonl(creator);
265 <
266 <        // Update file
267 <        lseek(fd, 0, SEEK_SET);
268 <        write(fd, &finf, sizeof(finf_struct));
269 <        close(fd);
270 < }
271 <
272 <
273 < /*
274 < *  Get/set finder flags for file/dir specified by full path
275 < */
276 <
277 < void get_finder_flags(const char *path, uint16 &flags)
278 < {
279 <        flags = DEFAULT_FINDER_FLAGS;   // Default
280 <
281 <        // Open Finder info file
282 <        int fd = open_finf(path, O_RDONLY);
283 <        if (fd < 0)
284 <                return;
285 <
286 <        // Read Finder flags
287 <        finf_struct finf;
288 <        if (read(fd, &finf, sizeof(finf_struct)) >= 10)
289 <                flags = ntohs(finf.flags);
290 <
291 <        // Close file
292 <        close(fd);
293 < }
294 <
295 < void set_finder_flags(const char *path, uint16 flags)
250 > void set_finfo(const char *path, uint32 finfo, uint32 fxinfo)
251   {
252          // Open Finder info file
253          int fd = open_finf(path, O_RDWR);
254          if (fd < 0)
255                  return;
256  
257 <        // Read file
258 <        finf_struct finf;
259 <        memset(&finf, 0, sizeof(finf_struct));
260 <        finf.flags = DEFAULT_FINDER_FLAGS;
306 <        read(fd, &finf, sizeof(finf_struct));
307 <
308 <        // Set Finder flags
309 <        finf.flags = htons(flags);
310 <
311 <        // Update file
312 <        lseek(fd, 0, SEEK_SET);
313 <        write(fd, &finf, sizeof(finf_struct));
257 >        // Write file
258 >        write(fd, Mac2HostAddr(finfo), SIZEOF_FInfo);
259 >        if (fxinfo)
260 >                write(fd, Mac2HostAddr(fxinfo), SIZEOF_FXInfo);
261          close(fd);
262   }
263  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines