X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=KernelLand%2FKernel%2Fvfs%2Fio.c;h=dc55fe2ac856fed44df6579804383140fba70aaf;hb=bf62604f78c2d8bc88cac3664e15ed02c6e6d581;hp=dacf720ee3e9e14b5cb8b0da07c67d4982efbb02;hpb=4c76c235551f3f936a20b17cfe727578644493f1;p=tpg%2Facess2.git diff --git a/KernelLand/Kernel/vfs/io.c b/KernelLand/Kernel/vfs/io.c index dacf720e..dc55fe2a 100644 --- a/KernelLand/Kernel/vfs/io.c +++ b/KernelLand/Kernel/vfs/io.c @@ -4,18 +4,19 @@ */ #define DEBUG 0 #include -#include "vfs.h" -#include "vfs_int.h" +#include +#include +#include // === CODE === /** * \fn Uint64 VFS_Read(int FD, Uint64 Length, void *Buffer) * \brief Read data from a node (file) */ -Uint64 VFS_Read(int FD, Uint64 Length, void *Buffer) +size_t VFS_Read(int FD, size_t Length, void *Buffer) { tVFS_Handle *h; - Uint64 ret; + size_t ret; ENTER("iFD XLength pBuffer", FD, Length, Buffer); @@ -38,9 +39,15 @@ Uint64 VFS_Read(int FD, Uint64 Length, void *Buffer) LOG("No read method"); LEAVE_RET('i', -1); } + + if( !MM_GetPhysAddr(h->Node->Type->Read) ) { + Log_Error("VFS", "Node type %p(%s) read method is junk %p", h->Node->Type, h->Node, h->Node->Type->TypeName, + h->Node->Type->Read); + LEAVE_RET('i', -1); + } ret = h->Node->Type->Read(h->Node, h->Position, Length, Buffer); - if(ret == -1) LEAVE_RET('i', -1); + if(ret == (size_t)-1) LEAVE_RET('i', -1); h->Position += ret; LEAVE('X', ret); @@ -51,10 +58,10 @@ Uint64 VFS_Read(int FD, Uint64 Length, void *Buffer) * \fn Uint64 VFS_ReadAt(int FD, Uint64 Offset, Uint64 Length, void *Buffer) * \brief Read data from a given offset (atomic) */ -Uint64 VFS_ReadAt(int FD, Uint64 Offset, Uint64 Length, void *Buffer) +size_t VFS_ReadAt(int FD, Uint64 Offset, size_t Length, void *Buffer) { tVFS_Handle *h; - Uint64 ret; + size_t ret; h = VFS_GetHandle(FD); if(!h) return -1; @@ -66,8 +73,15 @@ Uint64 VFS_ReadAt(int FD, Uint64 Offset, Uint64 Length, void *Buffer) Warning("VFS_ReadAt - Node %p, does not have a read method", h->Node); return 0; } + + if( !MM_GetPhysAddr(h->Node->Type->Read) ) { + Log_Error("VFS", "Node type %p(%s) read method is junk %p", h->Node->Type, h->Node, h->Node->Type->TypeName, + h->Node->Type->Read); + LEAVE_RET('i', -1); + } + ret = h->Node->Type->Read(h->Node, Offset, Length, Buffer); - if(ret == -1) return -1; + if(ret == (size_t)-1) return -1; return ret; } @@ -75,10 +89,10 @@ Uint64 VFS_ReadAt(int FD, Uint64 Offset, Uint64 Length, void *Buffer) * \fn Uint64 VFS_Write(int FD, Uint64 Length, const void *Buffer) * \brief Read data from a node (file) */ -Uint64 VFS_Write(int FD, Uint64 Length, const void *Buffer) +size_t VFS_Write(int FD, size_t Length, const void *Buffer) { tVFS_Handle *h; - Uint64 ret; + size_t ret; h = VFS_GetHandle(FD); if(!h) return -1; @@ -87,9 +101,15 @@ Uint64 VFS_Write(int FD, Uint64 Length, const void *Buffer) if( h->Node->Flags & VFS_FFLAG_DIRECTORY ) return -1; if( !h->Node->Type || !h->Node->Type->Write ) return 0; + + if( !MM_GetPhysAddr(h->Node->Type->Write) ) { + Log_Error("VFS", "Node type %p(%s) write method is junk %p", h->Node->Type, h->Node, h->Node->Type->TypeName, + h->Node->Type->Write); + return -1; + } ret = h->Node->Type->Write(h->Node, h->Position, Length, Buffer); - if(ret == -1) return -1; + if(ret == (size_t)-1) return -1; h->Position += ret; return ret; @@ -99,10 +119,10 @@ Uint64 VFS_Write(int FD, Uint64 Length, const void *Buffer) * \fn Uint64 VFS_WriteAt(int FD, Uint64 Offset, Uint64 Length, const void *Buffer) * \brief Write data to a file at a given offset */ -Uint64 VFS_WriteAt(int FD, Uint64 Offset, Uint64 Length, const void *Buffer) +size_t VFS_WriteAt(int FD, Uint64 Offset, size_t Length, const void *Buffer) { tVFS_Handle *h; - Uint64 ret; + size_t ret; h = VFS_GetHandle(FD); if(!h) return -1; @@ -111,9 +131,14 @@ Uint64 VFS_WriteAt(int FD, Uint64 Offset, Uint64 Length, const void *Buffer) if( h->Node->Flags & VFS_FFLAG_DIRECTORY ) return -1; if(!h->Node->Type || !h->Node->Type->Write) return 0; - ret = h->Node->Type->Write(h->Node, Offset, Length, Buffer); - if(ret == -1) return -1; + if( !MM_GetPhysAddr(h->Node->Type->Write) ) { + Log_Error("VFS", "Node type %p(%s) write method is junk %p", h->Node->Type, h->Node, h->Node->Type->TypeName, + h->Node->Type->Write); + return -1; + } + ret = h->Node->Type->Write(h->Node, Offset, Length, Buffer); + if(ret == (size_t)-1) return -1; return ret; } @@ -156,7 +181,7 @@ int VFS_Seek(int FD, Sint64 Offset, int Whence) // Set relative to end of file if(Whence < 0) { - if( h->Node->Size == -1 ) return -1; + if( h->Node->Size == (Uint64)-1 ) return -1; h->Position = h->Node->Size - Offset; return 0;