X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=Kernel%2Fvfs%2Fio.c;h=e7a2a0684370171cbbe3d1ec1889887cfd2ce2bc;hb=61cfad415a64c52ca253460231046f47fcb7fb15;hp=67d384c1d42e90e51add86fb8000d6653062c7b5;hpb=4e949acb1c98bc071af2d5d9038b4a3e703bf33d;p=tpg%2Facess2.git diff --git a/Kernel/vfs/io.c b/Kernel/vfs/io.c index 67d384c1..e7a2a068 100644 --- a/Kernel/vfs/io.c +++ b/Kernel/vfs/io.c @@ -2,22 +2,11 @@ * AcessMicro VFS * - File IO Passthru's */ +#define DEBUG 0 #include #include "vfs.h" #include "vfs_int.h" -#define DEBUG 0 - -#if DEBUG -#else -# undef ENTER -# undef LOG -# undef LEAVE -# define ENTER(...) -# define LOG(...) -# define LEAVE(...) -#endif - // === CODE === /** * \fn Uint64 VFS_Read(int FD, Uint64 Length, void *Buffer) @@ -31,23 +20,15 @@ Uint64 VFS_Read(int FD, Uint64 Length, void *Buffer) ENTER("iFD XLength pBuffer", FD, Length, Buffer); h = VFS_GetHandle(FD); - if(!h) return -1; + if(!h) LEAVE_RET('i', -1); - if( !(h->Mode & VFS_OPENFLAG_READ) || h->Node->Flags & VFS_FFLAG_DIRECTORY ) { - LEAVE('i', -1); - return -1; - } + if( !(h->Mode & VFS_OPENFLAG_READ) || h->Node->Flags & VFS_FFLAG_DIRECTORY ) + LEAVE_RET('i', -1); - if(!h->Node->Read) { - LEAVE('i', 0); - return 0; - } + if(!h->Node->Type || !h->Node->Type->Read) LEAVE_RET('i', 0); - ret = h->Node->Read(h->Node, h->Position, Length, Buffer); - if(ret == -1) { - LEAVE('i', -1); - return -1; - } + ret = h->Node->Type->Read(h->Node, h->Position, Length, Buffer); + if(ret == -1) LEAVE_RET('i', -1); h->Position += ret; LEAVE('X', ret); @@ -69,11 +50,11 @@ Uint64 VFS_ReadAt(int FD, Uint64 Offset, Uint64 Length, void *Buffer) if( !(h->Mode & VFS_OPENFLAG_READ) ) return -1; if( h->Node->Flags & VFS_FFLAG_DIRECTORY ) return -1; - if(!h->Node->Read) { + if( !h->Node->Type || !h->Node->Type->Read) { Warning("VFS_ReadAt - Node %p, does not have a read method", h->Node); return 0; } - ret = h->Node->Read(h->Node, Offset, Length, Buffer); + ret = h->Node->Type->Read(h->Node, Offset, Length, Buffer); if(ret == -1) return -1; return ret; } @@ -93,11 +74,11 @@ Uint64 VFS_Write(int FD, Uint64 Length, const void *Buffer) if( !(h->Mode & VFS_OPENFLAG_WRITE) ) return -1; if( h->Node->Flags & VFS_FFLAG_DIRECTORY ) return -1; - if(!h->Node->Write) return 0; + if( !h->Node->Type || !h->Node->Type->Write ) return 0; - // TODO: This is a hack, I need to change VFS_Node to have "const void*" - ret = h->Node->Write(h->Node, h->Position, Length, (void*)Buffer); + ret = h->Node->Type->Write(h->Node, h->Position, Length, Buffer); if(ret == -1) return -1; + h->Position += ret; return ret; } @@ -117,9 +98,9 @@ Uint64 VFS_WriteAt(int FD, Uint64 Offset, Uint64 Length, const void *Buffer) if( !(h->Mode & VFS_OPENFLAG_WRITE) ) return -1; if( h->Node->Flags & VFS_FFLAG_DIRECTORY ) return -1; - if(!h->Node->Write) return 0; - // TODO: This is a hack, I need to change VFS_Node to have "const void*" - ret = h->Node->Write(h->Node, Offset, Length, (void*)Buffer); + 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; return ret; } @@ -163,6 +144,8 @@ 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; + h->Position = h->Node->Size - Offset; return 0; } @@ -183,8 +166,8 @@ int VFS_IOCtl(int FD, int ID, void *Buffer) h = VFS_GetHandle(FD); if(!h) return -1; - if(!h->Node->IOCtl) return -1; - return h->Node->IOCtl(h->Node, ID, Buffer); + if(!h->Node->Type || !h->Node->Type->IOCtl) return -1; + return h->Node->Type->IOCtl(h->Node, ID, Buffer); } /** @@ -199,7 +182,12 @@ int VFS_FInfo(int FD, tFInfo *Dest, int MaxACLs) h = VFS_GetHandle(FD); if(!h) return -1; - + + if( h->Mount ) + Dest->mount = h->Mount->Identifier; + else + Dest->mount = 0; + Dest->inode = h->Node->Inode; Dest->uid = h->Node->UID; Dest->gid = h->Node->GID; Dest->size = h->Node->Size;