mirror of
https://github.com/switchbrew/libnx.git
synced 2025-06-23 05:12:39 +02:00
Removed output bytes_written for fsFileWrite() since the command doesn't actually return that. In fsdev_open(), set the FS_OPEN_APPEND flag when opening for writing. Adjusted file-creation handling in fsdev_open().
This commit is contained in:
parent
40dd1adc23
commit
59880e9488
@ -80,7 +80,7 @@ void fsFsClose(FsFileSystem* fs);
|
|||||||
|
|
||||||
// IFile
|
// IFile
|
||||||
Result fsFileRead(FsFile* f, u64 off, void* buf, size_t len, size_t* out);
|
Result fsFileRead(FsFile* f, u64 off, void* buf, size_t len, size_t* out);
|
||||||
Result fsFileWrite(FsFile* f, u64 off, const void* buf, size_t len, size_t* out);
|
Result fsFileWrite(FsFile* f, u64 off, const void* buf, size_t len);
|
||||||
Result fsFileFlush(FsFile* f);
|
Result fsFileFlush(FsFile* f);
|
||||||
Result fsFileSetSize(FsFile* f, u64 sz);
|
Result fsFileSetSize(FsFile* f, u64 sz);
|
||||||
Result fsFileGetSize(FsFile* f, u64* out);
|
Result fsFileGetSize(FsFile* f, u64* out);
|
||||||
|
@ -512,12 +512,12 @@ fsdev_open(struct _reent *r,
|
|||||||
|
|
||||||
/* write-only */
|
/* write-only */
|
||||||
case O_WRONLY:
|
case O_WRONLY:
|
||||||
fsdev_flags |= FS_OPEN_WRITE;
|
fsdev_flags |= FS_OPEN_WRITE | FS_OPEN_APPEND;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
/* read and write */
|
/* read and write */
|
||||||
case O_RDWR:
|
case O_RDWR:
|
||||||
fsdev_flags |= (FS_OPEN_READ | FS_OPEN_WRITE);
|
fsdev_flags |= (FS_OPEN_READ | FS_OPEN_WRITE | FS_OPEN_APPEND);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
/* an invalid option was supplied */
|
/* an invalid option was supplied */
|
||||||
@ -527,13 +527,16 @@ fsdev_open(struct _reent *r,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Test O_EXCL. */
|
/* Test O_EXCL. */
|
||||||
if((flags & O_CREAT) && (flags & O_EXCL))
|
if((flags & O_CREAT))
|
||||||
{
|
{
|
||||||
rc = fsFsCreateFile(&device->fs, fs_path, 0, attributes);
|
rc = fsFsCreateFile(&device->fs, fs_path, 0, attributes);
|
||||||
if(R_FAILED(rc))
|
if(flags & O_EXCL)
|
||||||
{
|
{
|
||||||
r->_errno = fsdev_translate_error(rc);
|
if(R_FAILED(rc))
|
||||||
return -1;
|
{
|
||||||
|
r->_errno = fsdev_translate_error(rc);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -608,7 +611,6 @@ fsdev_write(struct _reent *r,
|
|||||||
size_t len)
|
size_t len)
|
||||||
{
|
{
|
||||||
Result rc;
|
Result rc;
|
||||||
size_t bytes;
|
|
||||||
|
|
||||||
/* get pointer to our data */
|
/* get pointer to our data */
|
||||||
fsdev_file_t *file = (fsdev_file_t*)fd;
|
fsdev_file_t *file = (fsdev_file_t*)fd;
|
||||||
@ -631,20 +633,20 @@ fsdev_write(struct _reent *r,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
rc = fsFileWrite(&file->fd, file->offset, ptr, len, &bytes);
|
rc = fsFileWrite(&file->fd, file->offset, ptr, len);
|
||||||
if(R_FAILED(rc))
|
if(R_FAILED(rc))
|
||||||
{
|
{
|
||||||
r->_errno = fsdev_translate_error(rc);
|
r->_errno = fsdev_translate_error(rc);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
file->offset += bytes;
|
file->offset += len;
|
||||||
|
|
||||||
/* check if this is synchronous or not */
|
/* check if this is synchronous or not */
|
||||||
if(file->flags & O_SYNC)
|
if(file->flags & O_SYNC)
|
||||||
fsFileFlush(&file->fd);
|
fsFileFlush(&file->fd);
|
||||||
|
|
||||||
return bytes;
|
return len;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*! Write to an open file
|
/*! Write to an open file
|
||||||
@ -664,7 +666,7 @@ fsdev_write_safe(struct _reent *r,
|
|||||||
size_t len)
|
size_t len)
|
||||||
{
|
{
|
||||||
Result rc;
|
Result rc;
|
||||||
size_t bytes, bytesWritten = 0;
|
size_t bytesWritten = 0;
|
||||||
|
|
||||||
/* get pointer to our data */
|
/* get pointer to our data */
|
||||||
fsdev_file_t *file = (fsdev_file_t*)fd;
|
fsdev_file_t *file = (fsdev_file_t*)fd;
|
||||||
@ -701,7 +703,7 @@ fsdev_write_safe(struct _reent *r,
|
|||||||
memcpy(tmp_buffer, ptr, toWrite);
|
memcpy(tmp_buffer, ptr, toWrite);
|
||||||
|
|
||||||
/* write the data */
|
/* write the data */
|
||||||
rc = fsFileWrite(&file->fd, file->offset, tmp_buffer, toWrite, &bytes);
|
rc = fsFileWrite(&file->fd, file->offset, tmp_buffer, toWrite);
|
||||||
|
|
||||||
if(R_FAILED(rc))
|
if(R_FAILED(rc))
|
||||||
{
|
{
|
||||||
@ -717,10 +719,10 @@ fsdev_write_safe(struct _reent *r,
|
|||||||
if(file->flags & O_SYNC)
|
if(file->flags & O_SYNC)
|
||||||
fsFileFlush(&file->fd);
|
fsFileFlush(&file->fd);
|
||||||
|
|
||||||
file->offset += bytes;
|
file->offset += toWrite;
|
||||||
bytesWritten += bytes;
|
bytesWritten += toWrite;
|
||||||
ptr += bytes;
|
ptr += toWrite;
|
||||||
len -= bytes;
|
len -= toWrite;
|
||||||
}
|
}
|
||||||
|
|
||||||
return bytesWritten;
|
return bytesWritten;
|
||||||
|
@ -584,7 +584,7 @@ Result fsFileRead(FsFile* f, u64 off, void* buf, size_t len, size_t* out) {
|
|||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
Result fsFileWrite(FsFile* f, u64 off, const void* buf, size_t len, size_t* out) {
|
Result fsFileWrite(FsFile* f, u64 off, const void* buf, size_t len) {
|
||||||
IpcCommand c;
|
IpcCommand c;
|
||||||
ipcInitialize(&c);
|
ipcInitialize(&c);
|
||||||
ipcAddSendBuffer(&c, buf, len, 1);
|
ipcAddSendBuffer(&c, buf, len, 1);
|
||||||
@ -614,14 +614,9 @@ Result fsFileWrite(FsFile* f, u64 off, const void* buf, size_t len, size_t* out)
|
|||||||
struct {
|
struct {
|
||||||
u64 magic;
|
u64 magic;
|
||||||
u64 result;
|
u64 result;
|
||||||
u64 bytes_written;
|
|
||||||
} *resp = r.Raw;
|
} *resp = r.Raw;
|
||||||
|
|
||||||
rc = resp->result;
|
rc = resp->result;
|
||||||
|
|
||||||
if (R_SUCCEEDED(rc)) {
|
|
||||||
*out = resp->bytes_written;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return rc;
|
return rc;
|
||||||
|
Loading…
Reference in New Issue
Block a user