1 |
|
/* |
2 |
|
* extfs_beos.cpp - MacOS file system for access native file system access, BeOS 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 |
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 |
|
{ |
384 |
– |
errno = 0; |
385 |
– |
|
384 |
|
// Buffer in kernel space? |
387 |
– |
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); |
408 |
< |
if (actual < 0) |
409 |
< |
actual = 0; |
406 |
> |
return sread(fd, buffer, length); |
407 |
|
} |
411 |
– |
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 |
|
{ |
429 |
– |
errno = 0; |
430 |
– |
|
425 |
|
// Buffer in kernel space? |
432 |
– |
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); |
453 |
< |
if (actual < 0) |
454 |
< |
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 |
|
} |