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.4 by cebix, 1999-11-08T18:05:57Z vs.
Revision 1.8 by cebix, 2000-07-21T18:01:06Z

# 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        uint16 pad0;
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 187 | Line 184 | static const ext2type e2t_translation[]
184          {".tga", 'TPIC', 'ogle'},
185          {".tif", 'TIFF', 'ogle'},
186          {".tiff", 'TIFF', 'ogle'},
187 +        {".htm", 'TEXT', 'MOSS'},
188          {".html", 'TEXT', 'MOSS'},
189          {".txt", 'TEXT', 'ttxt'},
190          {".rtf", 'TEXT', 'MSWD'},
# Line 207 | Line 205 | static const ext2type e2t_translation[]
205          {".mov", 'MooV', 'TVOD'},
206          {".fli", 'FLI ', 'TVOD'},
207          {".avi", 'VfW ', 'TVOD'},
208 +        {".qxd", 'XDOC', 'XPR3'},
209 +        {".hfv", 'DDim', 'ddsk'},
210 +        {".dsk", 'DDim', 'ddsk'},
211 +        {".img", 'rohd', 'ddsk'},
212          {NULL, 0, 0}    // End marker
213   };
214  
215 < void get_finder_type(const char *path, uint32 &type, uint32 &creator)
215 > void get_finfo(const char *path, uint32 finfo, uint32 fxinfo)
216   {
217 <        type = 0;
218 <        creator = 0;
217 >        // Set default finder info
218 >        Mac_memset(finfo, 0, SIZEOF_FInfo);
219 >        if (fxinfo)
220 >                Mac_memset(fxinfo, 0, SIZEOF_FXInfo);
221 >        WriteMacInt16(finfo + fdFlags, DEFAULT_FINDER_FLAGS);
222 >        WriteMacInt32(finfo + fdLocation, (uint32)-1);
223  
224 <        // Open Finder info file
224 >        // Read Finder info file
225          int fd = open_finf(path, O_RDONLY);
226          if (fd >= 0) {
227 <
228 <                // Read file
229 <                finf_struct finf;
224 <                if (read(fd, &finf, sizeof(finf_struct)) == sizeof(finf_struct)) {
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 <                }
227 >                ssize_t actual = read(fd, Mac2HostAddr(finfo), SIZEOF_FInfo);
228 >                if (fxinfo)
229 >                        actual += read(fd, Mac2HostAddr(fxinfo), SIZEOF_FXInfo);
230                  close(fd);
231 +                if (actual >= SIZEOF_FInfo)
232 +                        return;
233          }
234  
235          // No Finder info file, translate file name extension to MacOS type/creator
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 (!strcmp(path + path_len - ext_len, e2t_translation[i].ext)) {
242 <                        type = e2t_translation[i].type;
243 <                        creator = e2t_translation[i].creator;
244 <                        break;
236 >        struct stat st;
237 >        if (stat(path, &st) == 0 && !S_ISDIR(st.st_mode)) {
238 >                int path_len = strlen(path);
239 >                for (int i=0; e2t_translation[i].ext; i++) {
240 >                        int ext_len = strlen(e2t_translation[i].ext);
241 >                        if (path_len < ext_len)
242 >                                continue;
243 >                        if (!strcasecmp(path + path_len - ext_len, e2t_translation[i].ext)) {
244 >                                WriteMacInt32(finfo + fdType, e2t_translation[i].type);
245 >                                WriteMacInt32(finfo + fdCreator, e2t_translation[i].creator);
246 >                                break;
247 >                        }
248                  }
249          }
250   }
251  
252 < 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 = {0, 0, DEFAULT_FINDER_FLAGS, 0};
258 <        read(fd, &finf, sizeof(finf_struct));
259 <
260 <        // Set Finder flags
261 <        finf.type = htonl(type);
262 <        finf.creator = htonl(creator);
263 <
264 <        // Update file
265 <        lseek(fd, 0, SEEK_SET);
266 <        write(fd, &finf, sizeof(finf_struct));
267 <        close(fd);
268 < }
269 <
270 <
271 < /*
272 < *  Get/set finder flags for file/dir specified by full path
273 < */
274 <
275 < void get_finder_flags(const char *path, uint16 &flags)
276 < {
277 <        flags = DEFAULT_FINDER_FLAGS;   // Default
278 <
279 <        // Open Finder info file
280 <        int fd = open_finf(path, O_RDONLY);
281 <        if (fd < 0)
282 <                return;
283 <
284 <        // Read Finder flags
285 <        finf_struct finf;
286 <        if (read(fd, &finf, sizeof(finf_struct)) == sizeof(finf_struct))
287 <                flags = ntohs(finf.flags);
288 <
289 <        // Close file
290 <        close(fd);
291 < }
292 <
293 < void set_finder_flags(const char *path, uint16 flags)
252 > void set_finfo(const char *path, uint32 finfo, uint32 fxinfo)
253   {
254          // Open Finder info file
255          int fd = open_finf(path, O_RDWR);
256          if (fd < 0)
257                  return;
258  
259 <        // Read file
260 <        finf_struct finf = {0, 0, DEFAULT_FINDER_FLAGS, 0};
261 <        read(fd, &finf, sizeof(finf_struct));
262 <
304 <        // Set Finder flags
305 <        finf.flags = htons(flags);
306 <
307 <        // Update file
308 <        lseek(fd, 0, SEEK_SET);
309 <        write(fd, &finf, sizeof(finf_struct));
259 >        // Write file
260 >        write(fd, Mac2HostAddr(finfo), SIZEOF_FInfo);
261 >        if (fxinfo)
262 >                write(fd, Mac2HostAddr(fxinfo), SIZEOF_FXInfo);
263          close(fd);
264   }
265  
# Line 343 | Line 296 | void close_rfork(const char *path, int f
296  
297   /*
298   *  Read "length" bytes from file to "buffer",
299 < *  returns number of bytes read (or 0)
299 > *  returns number of bytes read (or -1 on error)
300   */
301  
302 < size_t extfs_read(int fd, void *buffer, size_t length)
302 > ssize_t extfs_read(int fd, void *buffer, size_t length)
303   {
351        errno = 0;
304          return read(fd, buffer, length);
305   }
306  
307  
308   /*
309   *  Write "length" bytes from "buffer" to file,
310 < *  returns number of bytes written (or 0)
310 > *  returns number of bytes written (or -1 on error)
311   */
312  
313 < size_t extfs_write(int fd, void *buffer, size_t length)
313 > ssize_t extfs_write(int fd, void *buffer, size_t length)
314   {
363        errno = 0;
315          return write(fd, buffer, length);
316   }
317  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines