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

Comparing BasiliskII/src/Unix/extfs_unix.cpp (file contents):
Revision 1.8 by cebix, 1999-11-08T17:00:13Z vs.
Revision 1.13 by cebix, 2000-07-21T18:01:07Z

# Line 1 | Line 1
1   /*
2   *  extfs_unix.cpp - MacOS file system for access native file system access, Unix 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 78 | Line 78 | void add_path_component(char *path, cons
78   *    /path/.finf/file
79   *  Resource fork:
80   *    /path/.rsrc/file
81 + *
82 + *  The .finf files store a FInfo/DInfo, followed by a FXInfo/DXInfo
83 + *  (16+16 bytes)
84   */
85  
83 // Layout of Finder info helper files (all fields big-endian)
84 struct finf_struct {
85        uint32 type;
86        uint32 creator;
87        uint16 flags;
88        uint16 pad0;
89 };
90
86   static void make_helper_path(const char *src, char *dest, const char *add, bool only_dir = false)
87   {
88          dest[0] = 0;
# Line 115 | Line 110 | static int create_helper_dir(const char
110   {
111          char helper_dir[MAX_PATH_LENGTH];
112          make_helper_path(path, helper_dir, add, true);
113 +        if (helper_dir[strlen(helper_dir) - 1] == '/')  // Remove trailing "/"
114 +                helper_dir[strlen(helper_dir) - 1] = 0;
115          return mkdir(helper_dir, 0777);
116   }
117  
# Line 151 | Line 148 | static int open_rsrc(const char *path, i
148  
149  
150   /*
151 < *  Get/set finder type/creator for file specified by full path
151 > *  Get/set finder info for file/directory specified by full path
152   */
153  
154   struct ext2type {
# Line 192 | Line 189 | static const ext2type e2t_translation[]
189          {".tga", 'TPIC', 'ogle'},
190          {".tif", 'TIFF', 'ogle'},
191          {".tiff", 'TIFF', 'ogle'},
192 +        {".htm", 'TEXT', 'MOSS'},
193          {".html", 'TEXT', 'MOSS'},
194          {".txt", 'TEXT', 'ttxt'},
195          {".rtf", 'TEXT', 'MSWD'},
# Line 212 | Line 210 | static const ext2type e2t_translation[]
210          {".mov", 'MooV', 'TVOD'},
211          {".fli", 'FLI ', 'TVOD'},
212          {".avi", 'VfW ', 'TVOD'},
213 +        {".qxd", 'XDOC', 'XPR3'},
214 +        {".hfv", 'DDim', 'ddsk'},
215 +        {".dsk", 'DDim', 'ddsk'},
216 +        {".img", 'rohd', 'ddsk'},
217          {NULL, 0, 0}    // End marker
218   };
219  
220 < void get_finder_type(const char *path, uint32 &type, uint32 &creator)
220 > void get_finfo(const char *path, uint32 finfo, uint32 fxinfo)
221   {
222 <        type = 0;
223 <        creator = 0;
222 >        // Set default finder info
223 >        Mac_memset(finfo, 0, SIZEOF_FInfo);
224 >        if (fxinfo)
225 >                Mac_memset(fxinfo, 0, SIZEOF_FXInfo);
226 >        WriteMacInt16(finfo + fdFlags, DEFAULT_FINDER_FLAGS);
227 >        WriteMacInt32(finfo + fdLocation, (uint32)-1);
228  
229 <        // Open Finder info file
229 >        // Read Finder info file
230          int fd = open_finf(path, O_RDONLY);
231          if (fd >= 0) {
232 <
233 <                // Read file
234 <                finf_struct finf;
229 <                if (read(fd, &finf, sizeof(finf_struct)) == sizeof(finf_struct)) {
230 <
231 <                        // Type/creator are in Finder info file, return them
232 <                        type = ntohl(finf.type);
233 <                        creator = ntohl(finf.creator);
234 <                        close(fd);
235 <                        return;
236 <                }
232 >                ssize_t actual = read(fd, Mac2HostAddr(finfo), SIZEOF_FInfo);
233 >                if (fxinfo)
234 >                        actual += read(fd, Mac2HostAddr(fxinfo), SIZEOF_FXInfo);
235                  close(fd);
236 +                if (actual >= SIZEOF_FInfo)
237 +                        return;
238          }
239  
240          // No Finder info file, translate file name extension to MacOS type/creator
241 <        int path_len = strlen(path);
242 <        for (int i=0; e2t_translation[i].ext; i++) {
243 <                int ext_len = strlen(e2t_translation[i].ext);
244 <                if (path_len < ext_len)
245 <                        continue;
246 <                if (!strcmp(path + path_len - ext_len, e2t_translation[i].ext)) {
247 <                        type = e2t_translation[i].type;
248 <                        creator = e2t_translation[i].creator;
249 <                        break;
241 >        struct stat st;
242 >        if (stat(path, &st) == 0 && !S_ISDIR(st.st_mode)) {
243 >                int path_len = strlen(path);
244 >                for (int i=0; e2t_translation[i].ext; i++) {
245 >                        int ext_len = strlen(e2t_translation[i].ext);
246 >                        if (path_len < ext_len)
247 >                                continue;
248 >                        if (!strcmp(path + path_len - ext_len, e2t_translation[i].ext)) {
249 >                                WriteMacInt32(finfo + fdType, e2t_translation[i].type);
250 >                                WriteMacInt32(finfo + fdCreator, e2t_translation[i].creator);
251 >                                break;
252 >                        }
253                  }
254          }
255   }
256  
257 < void set_finder_type(const char *path, uint32 type, uint32 creator)
257 > void set_finfo(const char *path, uint32 finfo, uint32 fxinfo)
258   {
259          // Open Finder info file
260          int fd = open_finf(path, O_RDWR);
261          if (fd < 0)
262                  return;
263  
264 <        // Read file
265 <        finf_struct finf = {0, 0, DEFAULT_FINDER_FLAGS, 0};
266 <        read(fd, &finf, sizeof(finf_struct));
267 <
265 <        // Set Finder flags
266 <        finf.type = htonl(type);
267 <        finf.creator = htonl(creator);
268 <
269 <        // Update file
270 <        lseek(fd, 0, SEEK_SET);
271 <        write(fd, &finf, sizeof(finf_struct));
272 <        close(fd);
273 < }
274 <
275 <
276 < /*
277 < *  Get/set finder flags for file/dir specified by full path
278 < */
279 <
280 < void get_finder_flags(const char *path, uint16 &flags)
281 < {
282 <        flags = DEFAULT_FINDER_FLAGS;   // Default
283 <
284 <        // Open Finder info file
285 <        int fd = open_finf(path, O_RDONLY);
286 <        if (fd < 0)
287 <                return;
288 <
289 <        // Read Finder flags
290 <        finf_struct finf;
291 <        if (read(fd, &finf, sizeof(finf_struct)) == sizeof(finf_struct))
292 <                flags = ntohs(finf.flags);
293 <
294 <        // Close file
295 <        close(fd);
296 < }
297 <
298 < void set_finder_flags(const char *path, uint16 flags)
299 < {
300 <        // Open Finder info file
301 <        int fd = open_finf(path, O_RDWR);
302 <        if (fd < 0)
303 <                return;
304 <
305 <        // Read file
306 <        finf_struct finf = {0, 0, DEFAULT_FINDER_FLAGS, 0};
307 <        read(fd, &finf, sizeof(finf_struct));
308 <
309 <        // Set Finder flags
310 <        finf.flags = htons(flags);
311 <
312 <        // Update file
313 <        lseek(fd, 0, SEEK_SET);
314 <        write(fd, &finf, sizeof(finf_struct));
264 >        // Write file
265 >        write(fd, Mac2HostAddr(finfo), SIZEOF_FInfo);
266 >        if (fxinfo)
267 >                write(fd, Mac2HostAddr(fxinfo), SIZEOF_FXInfo);
268          close(fd);
269   }
270  
# Line 348 | Line 301 | void close_rfork(const char *path, int f
301  
302   /*
303   *  Read "length" bytes from file to "buffer",
304 < *  returns number of bytes read (or 0)
304 > *  returns number of bytes read (or -1 on error)
305   */
306  
307 < size_t extfs_read(int fd, void *buffer, size_t length)
307 > ssize_t extfs_read(int fd, void *buffer, size_t length)
308   {
356        errno = 0;
309          return read(fd, buffer, length);
310   }
311  
312  
313   /*
314   *  Write "length" bytes from "buffer" to file,
315 < *  returns number of bytes written (or 0)
315 > *  returns number of bytes written (or -1 on error)
316   */
317  
318 < size_t extfs_write(int fd, void *buffer, size_t length)
318 > ssize_t extfs_write(int fd, void *buffer, size_t length)
319   {
368        errno = 0;
320          return write(fd, buffer, length);
321   }
322  
# Line 384 | Line 335 | bool extfs_remove(const char *path)
335          make_helper_path(path, helper_path, ".rsrc/", false);
336          remove(helper_path);
337  
338 <        // Now remove file or directory
338 >        // Now remove file or directory (and helper directories in the directory)
339          if (remove(path) < 0) {
340 <                if (errno == EISDIR)
340 >                if (errno == EISDIR || errno == ENOTEMPTY) {
341 >                        helper_path[0] = 0;
342 >                        strncpy(helper_path, path, MAX_PATH_LENGTH-1);
343 >                        add_path_component(helper_path, ".finf");
344 >                        rmdir(helper_path);
345 >                        helper_path[0] = 0;
346 >                        strncpy(helper_path, path, MAX_PATH_LENGTH-1);
347 >                        add_path_component(helper_path, ".rsrc");
348 >                        rmdir(helper_path);
349                          return rmdir(path) == 0;
350 <                else
350 >                } else
351                          return false;
352          }
353          return true;
354   }
355 +
356 +
357 + /*
358 + *  Rename/move file/directory (and associated helper files),
359 + *  returns false on error (and sets errno)
360 + */
361 +
362 + bool extfs_rename(const char *old_path, const char *new_path)
363 + {
364 +        // Rename helpers first, don't complain if this fails
365 +        char old_helper_path[MAX_PATH_LENGTH], new_helper_path[MAX_PATH_LENGTH];
366 +        make_helper_path(old_path, old_helper_path, ".finf/", false);
367 +        make_helper_path(new_path, new_helper_path, ".finf/", false);
368 +        create_helper_dir(new_path, ".finf/");
369 +        rename(old_helper_path, new_helper_path);
370 +        make_helper_path(old_path, old_helper_path, ".rsrc/", false);
371 +        make_helper_path(new_path, new_helper_path, ".rsrc/", false);
372 +        create_helper_dir(new_path, ".rsrc/");
373 +        rename(old_helper_path, new_helper_path);
374 +
375 +        // Now rename file
376 +        return rename(old_path, new_path) == 0;
377 + }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines