/// <summary> /// Read from a file descriptor /// </summary> /// <param name="descriptor">The descriptor ID</param> /// <param name="buffer">The buffer</param> /// <param name="size">The size</param> /// <returns>The amount of bytes read</returns> public static int Read(int descriptor, byte[] buffer, uint size) { FileDescriptors descriptors = Tasking.CurrentTask.FileDescriptors; Node node = descriptors.GetNode(descriptor); if (node == null) { return(-(int)ErrorCode.EBADF); } // Can't do read from a directory if ((node.Flags & NodeFlags.DIRECTORY) == NodeFlags.DIRECTORY) { return(-(int)ErrorCode.EISDIR); } bool isNonBlocking = ((node.OpenFlags & O_NONBLOCK) == O_NONBLOCK); // Wait until data is available if its blocking if (!isNonBlocking) { while (VFS.GetSize(node) == 0) { Tasking.Yield(); } } // Non-blocking but no data available? else { if (VFS.GetSize(node) == 0) { return(-(int)ErrorCode.EAGAIN); } } uint offset = descriptors.GetOffset(descriptor); uint readBytes = VFS.Read(node, offset, size, buffer); descriptors.SetOffset(descriptor, offset + readBytes); return((int)readBytes); }