72 |
|
|
73 |
|
|
74 |
|
/* |
75 |
+ |
* Add component to path name |
76 |
+ |
*/ |
77 |
+ |
|
78 |
+ |
void add_path_component(char *path, const char *component) |
79 |
+ |
{ |
80 |
+ |
int l = strlen(path); |
81 |
+ |
if (l < MAX_PATH_LENGTH-1 && path[l-1] != '/') { |
82 |
+ |
path[l] = '/'; |
83 |
+ |
path[l+1] = 0; |
84 |
+ |
} |
85 |
+ |
strncat(path, component, MAX_PATH_LENGTH-1); |
86 |
+ |
} |
87 |
+ |
|
88 |
+ |
|
89 |
+ |
/* |
90 |
|
* Get/set finder type/creator for file specified by full path |
91 |
|
*/ |
92 |
|
|
283 |
|
// Open temporary file for resource fork |
284 |
|
char rname[L_tmpnam]; |
285 |
|
tmpnam(rname); |
286 |
< |
int rfd = open(rname, O_RDWR | O_CREAT | O_TRUNC, 0664); |
286 |
> |
int rfd = open(rname, O_RDWR | O_CREAT | O_TRUNC, 0666); |
287 |
|
if (rfd < 0) { |
288 |
|
close(fd); |
289 |
|
return -1; |
369 |
|
|
370 |
|
/* |
371 |
|
* Read "length" bytes from file to "buffer", |
372 |
< |
* returns number of bytes read (or 0) |
372 |
> |
* returns number of bytes read (or -1 on error) |
373 |
|
*/ |
374 |
|
|
375 |
|
static inline ssize_t sread(int fd, void *buf, size_t count) |
379 |
|
return res; |
380 |
|
} |
381 |
|
|
382 |
< |
size_t extfs_read(int fd, void *buffer, size_t length) |
382 |
> |
ssize_t extfs_read(int fd, void *buffer, size_t length) |
383 |
|
{ |
369 |
– |
errno = 0; |
370 |
– |
|
384 |
|
// Buffer in kernel space? |
372 |
– |
size_t actual = 0; |
385 |
|
if ((uint32)buffer < 0x80000000) { |
386 |
|
|
387 |
|
// Yes, transfer via buffer |
388 |
+ |
ssize_t actual = 0; |
389 |
|
while (length) { |
390 |
|
size_t transfer_size = (length > TMP_BUF_SIZE) ? TMP_BUF_SIZE : length; |
391 |
|
ssize_t res = sread(fd, tmp_buf, transfer_size); |
392 |
< |
if (res >= 0) { |
393 |
< |
memcpy(buffer, tmp_buf, res); |
394 |
< |
buffer = (void *)((uint8 *)buffer + res); |
395 |
< |
length -= res; |
396 |
< |
actual += res; |
397 |
< |
} |
392 |
> |
if (res < 0) |
393 |
> |
return res; |
394 |
> |
memcpy(buffer, tmp_buf, res); |
395 |
> |
buffer = (void *)((uint8 *)buffer + res); |
396 |
> |
length -= res; |
397 |
> |
actual += res; |
398 |
|
if (res != transfer_size) |
399 |
|
return actual; |
400 |
|
} |
401 |
+ |
return actual; |
402 |
|
|
403 |
|
} else { |
404 |
|
|
405 |
|
// No, transfer directly |
406 |
< |
actual = sread(fd, buffer, length); |
393 |
< |
if (actual < 0) |
394 |
< |
actual = 0; |
406 |
> |
return sread(fd, buffer, length); |
407 |
|
} |
396 |
– |
return actual; |
408 |
|
} |
409 |
|
|
410 |
|
|
411 |
|
/* |
412 |
|
* Write "length" bytes from "buffer" to file, |
413 |
< |
* returns number of bytes written (or 0) |
413 |
> |
* returns number of bytes written (or -1 on error) |
414 |
|
*/ |
415 |
|
|
416 |
|
static inline ssize_t swrite(int fd, void *buf, size_t count) |
420 |
|
return res; |
421 |
|
} |
422 |
|
|
423 |
< |
size_t extfs_write(int fd, void *buffer, size_t length) |
423 |
> |
ssize_t extfs_write(int fd, void *buffer, size_t length) |
424 |
|
{ |
414 |
– |
errno = 0; |
415 |
– |
|
425 |
|
// Buffer in kernel space? |
417 |
– |
size_t actual = 0; |
426 |
|
if ((uint32)buffer < 0x80000000) { |
427 |
|
|
428 |
|
// Yes, transfer via buffer |
429 |
+ |
ssize_t actual = 0; |
430 |
|
while (length) { |
431 |
|
size_t transfer_size = (length > TMP_BUF_SIZE) ? TMP_BUF_SIZE : length; |
432 |
|
memcpy(tmp_buf, buffer, transfer_size); |
433 |
|
ssize_t res = swrite(fd, tmp_buf, transfer_size); |
434 |
< |
if (res >= 0) { |
435 |
< |
buffer = (void *)((uint8 *)buffer + res); |
436 |
< |
length -= res; |
437 |
< |
actual += res; |
438 |
< |
} |
434 |
> |
if (res < 0) |
435 |
> |
return res; |
436 |
> |
buffer = (void *)((uint8 *)buffer + res); |
437 |
> |
length -= res; |
438 |
> |
actual += res; |
439 |
|
if (res != transfer_size) |
440 |
|
return actual; |
441 |
|
} |
442 |
+ |
return actual; |
443 |
|
|
444 |
|
} else { |
445 |
|
|
446 |
|
// No, transfer directly |
447 |
< |
actual = swrite(fd, buffer, length); |
438 |
< |
if (actual < 0) |
439 |
< |
actual = 0; |
447 |
> |
return swrite(fd, buffer, length); |
448 |
|
} |
449 |
< |
return actual; |
449 |
> |
} |
450 |
> |
|
451 |
> |
|
452 |
> |
/* |
453 |
> |
* Remove file/directory, returns false on error (and sets errno) |
454 |
> |
*/ |
455 |
> |
|
456 |
> |
bool extfs_remove(const char *path) |
457 |
> |
{ |
458 |
> |
if (remove(path) < 0) { |
459 |
> |
if (errno == EISDIR) |
460 |
> |
return rmdir(path) == 0; |
461 |
> |
else |
462 |
> |
return false; |
463 |
> |
} |
464 |
> |
return true; |
465 |
> |
} |
466 |
> |
|
467 |
> |
|
468 |
> |
/* |
469 |
> |
* Rename/move file/directory, returns false on error (and sets errno) |
470 |
> |
*/ |
471 |
> |
|
472 |
> |
bool extfs_rename(const char *old_path, const char *new_path) |
473 |
> |
{ |
474 |
> |
return rename(old_path, new_path) == 0; |
475 |
|
} |