343 |
|
|
344 |
|
/* |
345 |
|
* Read "length" bytes from file to "buffer", |
346 |
< |
* returns number of bytes read (or 0) |
346 |
> |
* returns number of bytes read (or -1 on error) |
347 |
|
*/ |
348 |
|
|
349 |
< |
size_t extfs_read(int fd, void *buffer, size_t length) |
349 |
> |
ssize_t extfs_read(int fd, void *buffer, size_t length) |
350 |
|
{ |
351 |
– |
errno = 0; |
351 |
|
return read(fd, buffer, length); |
352 |
|
} |
353 |
|
|
354 |
|
|
355 |
|
/* |
356 |
|
* Write "length" bytes from "buffer" to file, |
357 |
< |
* returns number of bytes written (or 0) |
357 |
> |
* returns number of bytes written (or -1 on error) |
358 |
|
*/ |
359 |
|
|
360 |
< |
size_t extfs_write(int fd, void *buffer, size_t length) |
360 |
> |
ssize_t extfs_write(int fd, void *buffer, size_t length) |
361 |
|
{ |
363 |
– |
errno = 0; |
362 |
|
return write(fd, buffer, length); |
363 |
|
} |
364 |
|
|
377 |
|
make_helper_path(path, helper_path, ".rsrc/", false); |
378 |
|
remove(helper_path); |
379 |
|
|
380 |
< |
// Now remove file or directory |
380 |
> |
// Now remove file or directory (and helper directories in the directory) |
381 |
|
if (remove(path) < 0) { |
382 |
< |
if (errno == EISDIR) |
382 |
> |
if (errno == EISDIR || errno == ENOTEMPTY) { |
383 |
> |
helper_path[0] = 0; |
384 |
> |
strncpy(helper_path, path, MAX_PATH_LENGTH-1); |
385 |
> |
add_path_component(helper_path, ".finf"); |
386 |
> |
rmdir(helper_path); |
387 |
> |
helper_path[0] = 0; |
388 |
> |
strncpy(helper_path, path, MAX_PATH_LENGTH-1); |
389 |
> |
add_path_component(helper_path, ".rsrc"); |
390 |
> |
rmdir(helper_path); |
391 |
|
return rmdir(path) == 0; |
392 |
< |
else |
392 |
> |
} else |
393 |
|
return false; |
394 |
|
} |
395 |
|
return true; |
396 |
|
} |
397 |
|
|
398 |
|
|
399 |
+ |
/* |
400 |
+ |
* Rename/move file/directory (and associated helper files), |
401 |
+ |
* returns false on error (and sets errno) |
402 |
+ |
*/ |
403 |
+ |
|
404 |
+ |
bool extfs_rename(const char *old_path, const char *new_path) |
405 |
+ |
{ |
406 |
+ |
// Rename helpers first, don't complain if this fails |
407 |
+ |
char old_helper_path[MAX_PATH_LENGTH], new_helper_path[MAX_PATH_LENGTH]; |
408 |
+ |
make_helper_path(old_path, old_helper_path, ".finf/", false); |
409 |
+ |
make_helper_path(new_path, new_helper_path, ".finf/", false); |
410 |
+ |
create_helper_dir(new_path, ".finf/"); |
411 |
+ |
rename(old_helper_path, new_helper_path); |
412 |
+ |
make_helper_path(old_path, old_helper_path, ".rsrc/", false); |
413 |
+ |
make_helper_path(new_path, new_helper_path, ".rsrc/", false); |
414 |
+ |
create_helper_dir(new_path, ".rsrc/"); |
415 |
+ |
rename(old_helper_path, new_helper_path); |
416 |
+ |
|
417 |
+ |
// Now rename file |
418 |
+ |
return rename(old_path, new_path) == 0; |
419 |
+ |
} |
420 |
+ |
|
421 |
+ |
|
422 |
|
/* |
423 |
|
* ftruncate() is missing from libnix |
424 |
|
*/ |