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.1 by cebix, 1999-11-01T16:24:09Z vs.
Revision 1.6 by cebix, 2000-01-21T13:47:02Z

# Line 84 | Line 84 | struct finf_struct {
84          uint32 type;
85          uint32 creator;
86          uint16 flags;
87 <        uint16 pad0;
87 >        uint8 pad0[22]; // total size: 32 bytes to match the size of FInfo+FXInfo
88   };
89  
90   static void make_helper_path(const char *src, char *dest, const char *add, bool only_dir = false)
# Line 118 | Line 118 | static int open_helper(const char *path,
118          char helper_path[MAX_PATH_LENGTH];
119          make_helper_path(path, helper_path, add);
120  
121 <        if ((flag & O_RDWR) || (flag && O_WRONLY))
121 >        if ((flag & O_ACCMODE) == O_RDWR || (flag & O_ACCMODE) == O_WRONLY)
122                  flag |= O_CREAT;
123          int fd = open(helper_path, flag, 0666);
124          if (fd < 0) {
# Line 221 | Line 221 | void get_finder_type(const char *path, u
221  
222                  // Read file
223                  finf_struct finf;
224 <                if (read(fd, &finf, sizeof(finf_struct)) == sizeof(finf_struct)) {
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);
# Line 254 | Line 254 | void set_finder_type(const char *path, u
254                  return;
255  
256          // Read file
257 <        finf_struct finf = {0, 0, DEFAULT_FINDER_FLAGS, 0};
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
# Line 283 | Line 285 | void get_finder_flags(const char *path,
285  
286          // Read Finder flags
287          finf_struct finf;
288 <        if (read(fd, &finf, sizeof(finf_struct)) == sizeof(finf_struct))
288 >        if (read(fd, &finf, sizeof(finf_struct)) >= 10)
289                  flags = ntohs(finf.flags);
290  
291          // Close file
# Line 298 | Line 300 | void set_finder_flags(const char *path,
300                  return;
301  
302          // Read file
303 <        finf_struct finf = {0, 0, DEFAULT_FINDER_FLAGS, 0};
303 >        finf_struct finf;
304 >        memset(&finf, 0, sizeof(finf_struct));
305 >        finf.flags = DEFAULT_FINDER_FLAGS;
306          read(fd, &finf, sizeof(finf_struct));
307  
308          // Set Finder flags
# Line 343 | Line 347 | void close_rfork(const char *path, int f
347  
348   /*
349   *  Read "length" bytes from file to "buffer",
350 < *  returns number of bytes read (or 0)
350 > *  returns number of bytes read (or -1 on error)
351   */
352  
353 < size_t extfs_read(int fd, void *buffer, size_t length)
353 > ssize_t extfs_read(int fd, void *buffer, size_t length)
354   {
351        errno = 0;
355          return read(fd, buffer, length);
356   }
357  
358  
359   /*
360   *  Write "length" bytes from "buffer" to file,
361 < *  returns number of bytes written (or 0)
361 > *  returns number of bytes written (or -1 on error)
362   */
363  
364 < size_t extfs_write(int fd, void *buffer, size_t length)
364 > ssize_t extfs_write(int fd, void *buffer, size_t length)
365   {
363        errno = 0;
366          return write(fd, buffer, length);
367   }
368  
369  
370 + /*
371 + *  Remove file/directory (and associated helper files),
372 + *  returns false on error (and sets errno)
373 + */
374 +
375 + bool extfs_remove(const char *path)
376 + {
377 +        // Remove helpers first, don't complain if this fails
378 +        char helper_path[MAX_PATH_LENGTH];
379 +        make_helper_path(path, helper_path, ".finf/", false);
380 +        remove(helper_path);
381 +        make_helper_path(path, helper_path, ".rsrc/", false);
382 +        remove(helper_path);
383 +
384 +        // Now remove file or directory (and helper directories in the directory)
385 +        if (remove(path) < 0) {
386 +                if (errno == EISDIR || errno == ENOTEMPTY) {
387 +                        helper_path[0] = 0;
388 +                        strncpy(helper_path, path, MAX_PATH_LENGTH-1);
389 +                        add_path_component(helper_path, ".finf");
390 +                        rmdir(helper_path);
391 +                        helper_path[0] = 0;
392 +                        strncpy(helper_path, path, MAX_PATH_LENGTH-1);
393 +                        add_path_component(helper_path, ".rsrc");
394 +                        rmdir(helper_path);
395 +                        return rmdir(path) == 0;
396 +                } else
397 +                        return false;
398 +        }
399 +        return true;
400 + }
401 +
402 +
403 + /*
404 + *  Rename/move file/directory (and associated helper files),
405 + *  returns false on error (and sets errno)
406 + */
407 +
408 + bool extfs_rename(const char *old_path, const char *new_path)
409 + {
410 +        // Rename helpers first, don't complain if this fails
411 +        char old_helper_path[MAX_PATH_LENGTH], new_helper_path[MAX_PATH_LENGTH];
412 +        make_helper_path(old_path, old_helper_path, ".finf/", false);
413 +        make_helper_path(new_path, new_helper_path, ".finf/", false);
414 +        create_helper_dir(new_path, ".finf/");
415 +        rename(old_helper_path, new_helper_path);
416 +        make_helper_path(old_path, old_helper_path, ".rsrc/", false);
417 +        make_helper_path(new_path, new_helper_path, ".rsrc/", false);
418 +        create_helper_dir(new_path, ".rsrc/");
419 +        rename(old_helper_path, new_helper_path);
420 +
421 +        // Now rename file
422 +        return rename(old_path, new_path) == 0;
423 + }
424 +
425 +
426   /*
427   *  ftruncate() is missing from libnix
428   */

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines