Ejemplo n.º 1
0
        public int ReadFrom(byte[] buffer, int offset)
        {
            Mode = Utilities.ToUInt16LittleEndian(buffer, offset + 0);
            UserIdLow = Utilities.ToUInt16LittleEndian(buffer, offset + 2);
            FileSize = Utilities.ToUInt32LittleEndian(buffer, offset + 4);
            AccessTime = Utilities.ToUInt32LittleEndian(buffer, offset + 8);
            CreationTime = Utilities.ToUInt32LittleEndian(buffer, offset + 12);
            ModificationTime = Utilities.ToUInt32LittleEndian(buffer, offset + 16);
            DeletionTime = Utilities.ToUInt32LittleEndian(buffer, offset + 20);
            GroupIdLow = Utilities.ToUInt16LittleEndian(buffer, offset + 24);
            LinksCount = Utilities.ToUInt16LittleEndian(buffer, offset + 26);
            BlocksCount = Utilities.ToUInt32LittleEndian(buffer, offset + 28);
            Flags = (InodeFlags)Utilities.ToUInt32LittleEndian(buffer, offset + 32);

            FastSymlink = null;
            Extents = null;
            DirectBlocks = null;
            if (FileType == UnixFileType.Link && BlocksCount == 0)
            {
                FastSymlink = new byte[60];
                Array.Copy(buffer, offset + 40, FastSymlink, 0, 60);
            }
            else if ((Flags & InodeFlags.ExtentsUsed) != 0)
            {
                Extents = Utilities.ToStruct<ExtentBlock>(buffer, offset + 40);
            }
            else
            {
                DirectBlocks = new uint[12];
                for (int i = 0; i < 12; ++i)
                {
                    DirectBlocks[i] = Utilities.ToUInt32LittleEndian(buffer, offset + 40 + (i * 4));
                }

                IndirectBlock = Utilities.ToUInt32LittleEndian(buffer, offset + 88);
                DoubleIndirectBlock = Utilities.ToUInt32LittleEndian(buffer, offset + 92);
                TripleIndirectBlock = Utilities.ToUInt32LittleEndian(buffer, offset + 96);
            }

            FileVersion = Utilities.ToUInt32LittleEndian(buffer, offset + 100);
            FileAcl = Utilities.ToUInt32LittleEndian(buffer, offset + 104);
            DirAcl = Utilities.ToUInt32LittleEndian(buffer, offset + 108);
            FragAddress = Utilities.ToUInt32LittleEndian(buffer, offset + 112);
            Fragment = buffer[offset + 116];
            FragmentSize = buffer[offset + 117];
            UserIdHigh = Utilities.ToUInt16LittleEndian(buffer, offset + 120);
            GroupIdHigh = Utilities.ToUInt16LittleEndian(buffer, offset + 122);

            return 128;
        }
Ejemplo n.º 2
0
        private Extent FindExtent(ExtentBlock node, uint logicalBlock)
        {
            if (node.Index != null)
            {
                ExtentIndex idxEntry = null;

                if (node.Index.Length == 0)
                {
                    return null;
                }
                else if (node.Index[0].FirstLogicalBlock >= logicalBlock)
                {
                    idxEntry = node.Index[0];
                }
                else
                {
                    for (int i = 0; i < node.Index.Length; ++i)
                    {
                        if (node.Index[i].FirstLogicalBlock > logicalBlock)
                        {
                            idxEntry = node.Index[i - 1];
                            break;
                        }
                    }
                }

                if (idxEntry == null)
                {
                    idxEntry = node.Index[node.Index.Length - 1];
                }

                ExtentBlock subBlock = LoadExtentBlock(idxEntry);
                return FindExtent(subBlock, logicalBlock);
            }
            else if (node.Extents != null)
            {
                Extent entry = null;

                if (node.Extents.Length == 0)
                {
                    return null;
                }
                else if (node.Extents[0].FirstLogicalBlock >= logicalBlock)
                {
                    return node.Extents[0];
                }
                else
                {
                    for (int i = 0; i < node.Extents.Length; ++i)
                    {
                        if (node.Extents[i].FirstLogicalBlock > logicalBlock)
                        {
                            entry = node.Extents[i - 1];
                            break;
                        }
                    }
                }

                if (entry == null)
                {
                    entry = node.Extents[node.Extents.Length - 1];
                }

                return entry;
            }
            else
            {
                return null;
            }
        }