Exemplo n.º 1
0
        /// <summary>
        /// Fs read entry
        /// </summary>
        /// <param name="node"></param>
        /// <param name="offset"></param>
        /// <param name="size"></param>
        /// <param name="buffer"></param>
        private static unsafe uint read(Node node, uint offset, uint size, byte[] buffer)
        {
            PacketFSCookie cookie = (PacketFSCookie)node.Cookie;

            PacketFSEntry entry = GetEntryByName(cookie.PacketFSEntry);

            if (entry == null)
            {
                return(0);
            }

            int pid = Tasking.CurrentTask.PID;

            if (entry.ControlPID == pid)
            {
                PacketFSPacket packet = (PacketFSPacket)Util.VoidPtrToObject(entry.ControlQueue.Pop());

                uint readSize = packet.Length;
                if (readSize > size)
                {
                    readSize = size;
                }

                Memory.Memcpy(Util.ObjectToVoidPtr(buffer), packet.buffer, (int)readSize);

                Heap.Free(packet.buffer);
                //Heap.Free(Util.ObjectToVoidPtr(packet));

                return(readSize);
            }
            else
            {
                Queue queue = GetQueueByPID(entry, pid);

                if (queue == null)
                {
                    return(0);
                }

                PacketFSPacket packet = (PacketFSPacket)Util.VoidPtrToObject(queue.Pop());

                uint readSize = packet.Length;
                if (readSize > size)
                {
                    readSize = size;
                }

                Memory.Memcpy(Util.ObjectToVoidPtr(buffer), packet.buffer, (int)readSize);

                Heap.Free(packet.buffer);
                //Heap.Free(Util.ObjectToVoidPtr(packet));

                return(readSize);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// FS write entry
        /// </summary>
        /// <param name="node"></param>
        /// <param name="offset"></param>
        /// <param name="size"></param>
        /// <param name="buffer"></param>
        private static unsafe uint write(Node node, uint offset, uint size, byte[] buffer)
        {
            PacketFSCookie cookie = (PacketFSCookie)node.Cookie;

            PacketFSEntry entry = GetEntryByName(cookie.PacketFSEntry);

            if (entry == null)
            {
                return(0);
            }

            int pid = Tasking.CurrentTask.PID;

            if (entry.ControlPID == pid)
            {
                if (size < 4)
                {
                    return(0);
                }

                byte *buf     = (byte *)Util.ObjectToVoidPtr(buffer);
                byte *dataBuf = buf + 4;

                int packetSize = (int)size - 4;

                int targetPID = *(int *)buf;


                Queue queue = GetQueueByPID(entry, pid);

                // Queue for pid even exists?
                if (queue == null)
                {
                    return(0);
                }

                PacketFSPacket packet = new PacketFSPacket();
                packet.buffer = (byte *)Heap.Alloc(packetSize);
                packet.Length = (uint)packetSize;

                Memory.Memcpy(packet.buffer, dataBuf, packetSize);

                queue.Push(Util.ObjectToVoidPtr(packet));

                return((uint)packetSize);
            }
            else
            {
                int totalSize = (int)size + 4;

                byte *buf     = (byte *)Heap.Alloc((int)size);
                byte *dataBuf = buf + 4;

                // Set PID
                *(int *)buf = pid;

                PacketFSPacket packet = new PacketFSPacket();
                packet.buffer = (byte *)Heap.Alloc(totalSize);
                packet.Length = (uint)totalSize;

                entry.ControlQueue.Push(Util.ObjectToVoidPtr(packet));

                return(size);
            }
        }