mirror of
https://github.com/kanjitalk755/macemu.git
synced 2025-01-12 16:30:44 +00:00
- extfs_read() and extfs_write() return -1 on error and don't clear errno
- parent CNIDs of FSItems are exchanged in fs_rename() and fs_cat_move()
This commit is contained in:
parent
b27458fb2d
commit
92be3b6781
BasiliskII/src
@ -343,24 +343,22 @@ void close_rfork(const char *path, int fd)
|
||||
|
||||
/*
|
||||
* Read "length" bytes from file to "buffer",
|
||||
* returns number of bytes read (or 0)
|
||||
* returns number of bytes read (or -1 on error)
|
||||
*/
|
||||
|
||||
size_t extfs_read(int fd, void *buffer, size_t length)
|
||||
ssize_t extfs_read(int fd, void *buffer, size_t length)
|
||||
{
|
||||
errno = 0;
|
||||
return read(fd, buffer, length);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Write "length" bytes from "buffer" to file,
|
||||
* returns number of bytes written (or 0)
|
||||
* returns number of bytes written (or -1 on error)
|
||||
*/
|
||||
|
||||
size_t extfs_write(int fd, void *buffer, size_t length)
|
||||
ssize_t extfs_write(int fd, void *buffer, size_t length)
|
||||
{
|
||||
errno = 0;
|
||||
return write(fd, buffer, length);
|
||||
}
|
||||
|
||||
|
@ -369,7 +369,7 @@ void close_rfork(const char *path, int fd)
|
||||
|
||||
/*
|
||||
* Read "length" bytes from file to "buffer",
|
||||
* returns number of bytes read (or 0)
|
||||
* returns number of bytes read (or -1 on error)
|
||||
*/
|
||||
|
||||
static inline ssize_t sread(int fd, void *buf, size_t count)
|
||||
@ -379,42 +379,38 @@ static inline ssize_t sread(int fd, void *buf, size_t count)
|
||||
return res;
|
||||
}
|
||||
|
||||
size_t extfs_read(int fd, void *buffer, size_t length)
|
||||
ssize_t extfs_read(int fd, void *buffer, size_t length)
|
||||
{
|
||||
errno = 0;
|
||||
|
||||
// Buffer in kernel space?
|
||||
size_t actual = 0;
|
||||
if ((uint32)buffer < 0x80000000) {
|
||||
|
||||
// Yes, transfer via buffer
|
||||
ssize_t actual = 0;
|
||||
while (length) {
|
||||
size_t transfer_size = (length > TMP_BUF_SIZE) ? TMP_BUF_SIZE : length;
|
||||
ssize_t res = sread(fd, tmp_buf, transfer_size);
|
||||
if (res >= 0) {
|
||||
memcpy(buffer, tmp_buf, res);
|
||||
buffer = (void *)((uint8 *)buffer + res);
|
||||
length -= res;
|
||||
actual += res;
|
||||
}
|
||||
if (res < 0)
|
||||
return res;
|
||||
memcpy(buffer, tmp_buf, res);
|
||||
buffer = (void *)((uint8 *)buffer + res);
|
||||
length -= res;
|
||||
actual += res;
|
||||
if (res != transfer_size)
|
||||
return actual;
|
||||
}
|
||||
return actual;
|
||||
|
||||
} else {
|
||||
|
||||
// No, transfer directly
|
||||
actual = sread(fd, buffer, length);
|
||||
if (actual < 0)
|
||||
actual = 0;
|
||||
return sread(fd, buffer, length);
|
||||
}
|
||||
return actual;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Write "length" bytes from "buffer" to file,
|
||||
* returns number of bytes written (or 0)
|
||||
* returns number of bytes written (or -1 on error)
|
||||
*/
|
||||
|
||||
static inline ssize_t swrite(int fd, void *buf, size_t count)
|
||||
@ -424,36 +420,32 @@ static inline ssize_t swrite(int fd, void *buf, size_t count)
|
||||
return res;
|
||||
}
|
||||
|
||||
size_t extfs_write(int fd, void *buffer, size_t length)
|
||||
ssize_t extfs_write(int fd, void *buffer, size_t length)
|
||||
{
|
||||
errno = 0;
|
||||
|
||||
// Buffer in kernel space?
|
||||
size_t actual = 0;
|
||||
if ((uint32)buffer < 0x80000000) {
|
||||
|
||||
// Yes, transfer via buffer
|
||||
ssize_t actual = 0;
|
||||
while (length) {
|
||||
size_t transfer_size = (length > TMP_BUF_SIZE) ? TMP_BUF_SIZE : length;
|
||||
memcpy(tmp_buf, buffer, transfer_size);
|
||||
ssize_t res = swrite(fd, tmp_buf, transfer_size);
|
||||
if (res >= 0) {
|
||||
buffer = (void *)((uint8 *)buffer + res);
|
||||
length -= res;
|
||||
actual += res;
|
||||
}
|
||||
if (res < 0)
|
||||
return res;
|
||||
buffer = (void *)((uint8 *)buffer + res);
|
||||
length -= res;
|
||||
actual += res;
|
||||
if (res != transfer_size)
|
||||
return actual;
|
||||
}
|
||||
return actual;
|
||||
|
||||
} else {
|
||||
|
||||
// No, transfer directly
|
||||
actual = swrite(fd, buffer, length);
|
||||
if (actual < 0)
|
||||
actual = 0;
|
||||
return swrite(fd, buffer, length);
|
||||
}
|
||||
return actual;
|
||||
}
|
||||
|
||||
|
||||
|
@ -348,24 +348,22 @@ void close_rfork(const char *path, int fd)
|
||||
|
||||
/*
|
||||
* Read "length" bytes from file to "buffer",
|
||||
* returns number of bytes read (or 0)
|
||||
* returns number of bytes read (or -1 on error)
|
||||
*/
|
||||
|
||||
size_t extfs_read(int fd, void *buffer, size_t length)
|
||||
ssize_t extfs_read(int fd, void *buffer, size_t length)
|
||||
{
|
||||
errno = 0;
|
||||
return read(fd, buffer, length);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Write "length" bytes from "buffer" to file,
|
||||
* returns number of bytes written (or 0)
|
||||
* returns number of bytes written (or -1 on error)
|
||||
*/
|
||||
|
||||
size_t extfs_write(int fd, void *buffer, size_t length)
|
||||
ssize_t extfs_write(int fd, void *buffer, size_t length)
|
||||
{
|
||||
errno = 0;
|
||||
return write(fd, buffer, length);
|
||||
}
|
||||
|
||||
|
@ -222,6 +222,23 @@ static void get_path_for_fsitem(FSItem *p)
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Exchange parent CNIDs in all FSItems
|
||||
*/
|
||||
|
||||
static void swap_parent_ids(uint32 parent1, uint32 parent2)
|
||||
{
|
||||
FSItem *p = first_fs_item;
|
||||
while (p) {
|
||||
if (p->parent_id == parent1)
|
||||
p->parent_id = parent2;
|
||||
else if (p->parent_id == parent2)
|
||||
p->parent_id = parent1;
|
||||
p = p->next;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* String handling functions
|
||||
*/
|
||||
@ -1778,15 +1795,15 @@ static int16 fs_read(uint32 pb)
|
||||
}
|
||||
|
||||
// Read
|
||||
size_t actual = extfs_read(fd, Mac2HostAddr(ReadMacInt32(pb + ioBuffer)), ReadMacInt32(pb + ioReqCount));
|
||||
ssize_t actual = extfs_read(fd, Mac2HostAddr(ReadMacInt32(pb + ioBuffer)), ReadMacInt32(pb + ioReqCount));
|
||||
int16 read_err = errno2oserr();
|
||||
D(bug(" actual %d\n", actual));
|
||||
WriteMacInt32(pb + ioActCount, actual);
|
||||
WriteMacInt32(pb + ioActCount, actual >= 0 ? actual : 0);
|
||||
uint32 pos = lseek(fd, 0, SEEK_CUR);
|
||||
WriteMacInt32(fcb + fcbCrPs, pos);
|
||||
WriteMacInt32(pb + ioPosOffset, pos);
|
||||
if (actual != ReadMacInt32(pb + ioReqCount))
|
||||
return read_err ? read_err : eofErr;
|
||||
return actual < 0 ? read_err : eofErr;
|
||||
else
|
||||
return noErr;
|
||||
}
|
||||
@ -1827,10 +1844,10 @@ static int16 fs_write(uint32 pb)
|
||||
}
|
||||
|
||||
// Write
|
||||
size_t actual = extfs_write(fd, Mac2HostAddr(ReadMacInt32(pb + ioBuffer)), ReadMacInt32(pb + ioReqCount));
|
||||
ssize_t actual = extfs_write(fd, Mac2HostAddr(ReadMacInt32(pb + ioBuffer)), ReadMacInt32(pb + ioReqCount));
|
||||
int16 write_err = errno2oserr();
|
||||
D(bug(" actual %d\n", actual));
|
||||
WriteMacInt32(pb + ioActCount, actual);
|
||||
WriteMacInt32(pb + ioActCount, actual >= 0 ? actual : 0);
|
||||
uint32 pos = lseek(fd, 0, SEEK_CUR);
|
||||
WriteMacInt32(fcb + fcbCrPs, pos);
|
||||
WriteMacInt32(pb + ioPosOffset, pos);
|
||||
@ -1940,6 +1957,7 @@ static int16 fs_rename(uint32 pb, uint32 dirID)
|
||||
return errno2oserr();
|
||||
else {
|
||||
// The ID of the old file/dir has to stay the same, so we swap the IDs of the FSItems
|
||||
swap_parent_ids(fs_item->id, new_item->id);
|
||||
uint32 t = fs_item->id;
|
||||
fs_item->id = new_item->id;
|
||||
new_item->id = t;
|
||||
@ -1985,6 +2003,7 @@ static int16 fs_cat_move(uint32 pb)
|
||||
// The ID of the old file/dir has to stay the same, so we swap the IDs of the FSItems
|
||||
FSItem *new_item = find_fsitem(fs_item->name, new_dir_item);
|
||||
if (new_item) {
|
||||
swap_parent_ids(fs_item->id, new_item->id);
|
||||
uint32 t = fs_item->id;
|
||||
fs_item->id = new_item->id;
|
||||
new_item->id = t;
|
||||
|
@ -40,8 +40,8 @@ extern void set_finder_flags(const char *path, uint16 flags);
|
||||
extern uint32 get_rfork_size(const char *path);
|
||||
extern int open_rfork(const char *path, int flag);
|
||||
extern void close_rfork(const char *path, int fd);
|
||||
extern size_t extfs_read(int fd, void *buffer, size_t length);
|
||||
extern size_t extfs_write(int fd, void *buffer, size_t length);
|
||||
extern ssize_t extfs_read(int fd, void *buffer, size_t length);
|
||||
extern ssize_t extfs_write(int fd, void *buffer, size_t length);
|
||||
extern bool extfs_remove(const char *path);
|
||||
extern bool extfs_rename(const char *old_path, const char *new_path);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user