Beispiel #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);
            }
        }
Beispiel #2
0
        /// <summary>
        /// FS finddir
        /// </summary>
        /// <param name="node">The node</param>
        /// <param name="name">The name to look for</param>
        /// <returns>The node</returns>
        private static unsafe Node findDirImpl(Node node, string name)
        {
            PacketFSCookie cookie = (PacketFSCookie)node.Cookie;

            PacketFSEntry entry = GetEntryByName(cookie.PacketFSEntry);

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

            Node returnNode = new Node();

            returnNode.Cookie = new PacketFSCookie(name);
            returnNode.Close  = close;
            returnNode.Open   = open;
            returnNode.Write  = write;
            returnNode.Read   = read;

            return(returnNode);
        }
Beispiel #3
0
        /// <summary>
        /// FS open enty
        /// </summary>
        /// <param name="node">The node</param>
        private static unsafe void open(Node node)
        {
            PacketFSCookie cookie = (PacketFSCookie)node.Cookie;

            PacketFSEntry entry = GetEntryByName(cookie.PacketFSEntry);

            // Entry found?
            if (entry == null)
            {
                return;
            }

            int pid = Tasking.CurrentTask.PID;

            // Do we need to create a queue for him?
            if (pid != entry.ControlPID)
            {
                entry.QueueMutex.Lock();

                Queue queue = (Queue)entry.Queue.GetByKey(pid);

                // Do we even need to create him?
                if (queue != null)
                {
                    entry.QueueMutex.Unlock();

                    return;
                }

                // Create queue and add him
                Queue newFif = new Queue();

                entry.Queue.Add(pid, newFif);

                entry.QueueMutex.Unlock();
            }
        }
Beispiel #4
0
        /// <summary>
        /// FS close entry (eg: remove packetfsentry)
        /// </summary>
        /// <param name="node">The node</param>
        private static unsafe void close(Node node)
        {
            int            pid    = Tasking.CurrentTask.PID;
            PacketFSCookie cookie = (PacketFSCookie)node.Cookie;

            m_mutex.Lock();

            PacketFSEntry entry = (PacketFSEntry)m_children.Get(cookie.PacketFSEntry);

            // Entry even found?
            if (entry == null)
            {
                m_mutex.Unlock();

                return;
            }

            // Do we only need to remove the pid from the queue?
            if (pid != entry.ControlPID)
            {
                m_mutex.Unlock();

                entry.QueueMutex.Lock();

                entry.Queue.Remove(pid);

                entry.QueueMutex.Unlock();

                return;
            }

            // Remove entry
            m_children.Remove(cookie.PacketFSEntry);

            m_mutex.Unlock();
        }
Beispiel #5
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);
            }
        }