Some cleanup

This commit is contained in:
Nekotekina 2014-07-07 21:22:36 +04:00
parent faab4ed6db
commit d1fff053c2
23 changed files with 278 additions and 850 deletions

View file

@ -146,39 +146,11 @@ s32 cellFsRead(u32 fd, u32 buf_addr, u64 nbytes, mem64_t nread)
if (nread.GetAddr() && !nread.IsGood()) return CELL_EFAULT;
u32 res = 0;
u32 count = nbytes;
if (nbytes != (u64)count) return CELL_ENOMEM;
if (nbytes != (u32)nbytes) return CELL_ENOMEM;
if (!Memory.IsGoodAddr(buf_addr)) return CELL_EFAULT;
// TODO: checks
if (count) if (u32 frag = buf_addr & 4095) // memory page fragment
{
u32 req = std::min(count, 4096 - frag);
u32 read = file->Read(Memory + buf_addr, req);
buf_addr += req;
res += read;
count -= req;
if (read < req) goto fin;
}
for (u32 pages = count / 4096; pages > 0; pages--) // full pages
{
if (!Memory.IsGoodAddr(buf_addr)) goto fin; // ??? (probably EFAULT)
u32 read = file->Read(Memory + buf_addr, 4096);
buf_addr += 4096;
res += read;
count -= 4096;
if (read < 4096) goto fin;
}
if (count) // last fragment
{
if (!Memory.IsGoodAddr(buf_addr)) goto fin;
res += file->Read(Memory + buf_addr, count);
}
fin:
const u64 res = nbytes ? file->Read(Memory.GetMemFromAddr(buf_addr), nbytes) : 0;
if (nread.GetAddr()) nread = res; // write value if not NULL
@ -192,16 +164,15 @@ s32 cellFsWrite(u32 fd, u32 buf_addr, u64 nbytes, mem64_t nwrite)
vfsStream* file;
if(!sys_fs->CheckId(fd, file)) return CELL_ESRCH;
if(Memory.IsGoodAddr(buf_addr) && !Memory.IsGoodAddr(buf_addr, nbytes))
{
MemoryBlock& block = Memory.GetMemByAddr(buf_addr);
nbytes = block.GetSize() - (buf_addr - block.GetStartAddr());
}
if (nwrite.GetAddr() && !nwrite.IsGood()) return CELL_EFAULT;
if (nbytes != (u32)nbytes) return CELL_ENOMEM;
// TODO: checks
const u64 res = nbytes ? file->Write(Memory.GetMemFromAddr(buf_addr), nbytes) : 0;
if(nwrite.IsGood())
nwrite = res;
if (nwrite.GetAddr()) nwrite = res; // write value if not NULL
return CELL_OK;
}