예제 #1
0
 public static DirectoryHeader ReadFrom(MetablockReader reader)
 {
     DirectoryHeader result = new DirectoryHeader();
     result.Count = reader.ReadInt();
     result.StartBlock = reader.ReadInt();
     result.InodeNumber = reader.ReadInt();
     return result;
 }
예제 #2
0
        public static DirectoryHeader ReadFrom(MetablockReader reader)
        {
            DirectoryHeader result = new DirectoryHeader();

            result.Count       = reader.ReadInt();
            result.StartBlock  = reader.ReadInt();
            result.InodeNumber = reader.ReadInt();
            return(result);
        }
예제 #3
0
 public DirectoryEntry(DirectoryHeader header, DirectoryRecord record)
 {
     _header = header;
     _record = record;
 }
예제 #4
0
 public DirectoryEntry(DirectoryHeader header, DirectoryRecord record)
 {
     _header = header;
     _record = record;
 }
예제 #5
0
        private void WriteDirectory(BuilderContext context)
        {
            MetadataRef startPos = context.DirectoryWriter.Position;

            int currentChild = 0;
            int numDirs      = 0;

            while (currentChild < _children.Count)
            {
                long thisBlock  = _children[currentChild].Node.InodeRef.Block;
                int  firstInode = _children[currentChild].Node.InodeNumber;

                int count = 1;
                while (currentChild + count < _children.Count &&
                       _children[currentChild + count].Node.InodeRef.Block == thisBlock &&
                       _children[currentChild + count].Node.InodeNumber - firstInode < 0x7FFF)
                {
                    ++count;
                }

                DirectoryHeader hdr = new DirectoryHeader()
                {
                    Count       = count - 1,
                    InodeNumber = firstInode,
                    StartBlock  = (int)thisBlock
                };

                hdr.WriteTo(context.IoBuffer, 0);
                context.DirectoryWriter.Write(context.IoBuffer, 0, hdr.Size);

                for (int i = 0; i < count; ++i)
                {
                    Entry           child  = _children[currentChild + i];
                    DirectoryRecord record = new DirectoryRecord()
                    {
                        Offset      = (ushort)child.Node.InodeRef.Offset,
                        InodeNumber = (short)(child.Node.InodeNumber - firstInode),
                        Type        = child.Node.Inode.Type,
                        Name        = child.Name
                    };

                    record.WriteTo(context.IoBuffer, 0);
                    context.DirectoryWriter.Write(context.IoBuffer, 0, record.Size);

                    if (child.Node.Inode.Type == InodeType.Directory ||
                        child.Node.Inode.Type == InodeType.ExtendedDirectory)
                    {
                        ++numDirs;
                    }
                }

                currentChild += count;
            }

            long size = context.DirectoryWriter.DistanceFrom(startPos);

            if (size > uint.MaxValue)
            {
                throw new NotImplementedException("Writing large directories");
            }

            NumLinks = numDirs + 2; // +1 for self, +1 for parent

            _inode.StartBlock = (uint)startPos.Block;
            _inode.Offset     = (ushort)startPos.Offset;
            _inode.FileSize   = (uint)size + 3; // For some reason, always +3
        }