Example #1
0
 public Directory(Context context, Inode inode, MetadataRef inodeRef)
     : base(context, inode, inodeRef)
 {
     _dirInode = inode as IDirectoryInode;
     if (_dirInode == null)
     {
         throw new ArgumentException("Inode is not a directory", "inode");
     }
 }
Example #2
0
        public UnixFileSystemInfo GetUnixFileInfo(string path)
        {
            File        file    = GetFile(path);
            Inode       inode   = file.Inode;
            DeviceInode devInod = inode as DeviceInode;

            UnixFileSystemInfo info = new UnixFileSystemInfo()
            {
                FileType    = FileTypeFromInodeType(inode.Type),
                UserId      = GetId(inode.UidKey),
                GroupId     = GetId(inode.GidKey),
                Permissions = (UnixFilePermissions)inode.Mode,
                Inode       = inode.InodeNumber,
                LinkCount   = inode.NumLinks,
                DeviceId    = (devInod == null) ? 0 : devInod.DeviceId
            };

            return(info);
        }
Example #3
0
        protected override File ConvertDirEntryToFile(DirectoryEntry dirEntry)
        {
            MetadataRef inodeRef = dirEntry.InodeReference;

            _context.InodeReader.SetPosition(inodeRef);
            Inode inode = Inode.Read(_context.InodeReader);

            if (dirEntry.IsSymlink)
            {
                return(new Symlink(_context, inode, inodeRef));
            }
            else if (dirEntry.IsDirectory)
            {
                return(new Directory(_context, inode, inodeRef));
            }
            else
            {
                return(new File(_context, inode, inodeRef));
            }
        }
Example #4
0
        public static Inode Read(MetablockReader inodeReader)
        {
            byte[] typeData = new byte[2];
            if (inodeReader.Read(typeData, 0, 2) != 2)
            {
                throw new IOException("Unable to read Inode type");
            }

            InodeType type  = (InodeType)Utilities.ToUInt16LittleEndian(typeData, 0);
            Inode     inode = InstantiateType(type);

            byte[] inodeData = new byte[inode.Size];
            inodeData[0] = typeData[0];
            inodeData[1] = typeData[1];

            if (inodeReader.Read(inodeData, 2, inode.Size - 2) != inode.Size - 2)
            {
                throw new IOException("Unable to read whole Inode");
            }

            inode.ReadFrom(inodeData, 0);

            return(inode);
        }
Example #5
0
 public File(Context context, Inode inode, MetadataRef inodeRef)
 {
     _context = context;
     _inode = inode;
     _inodeRef = inodeRef;
 }
Example #6
0
 public Symlink(Context context, Inode inode, MetadataRef inodeRef)
     : base(context, inode, inodeRef)
 {
 }
Example #7
0
        public VfsSquashFileSystemReader(Stream stream)
            : base(new DiscFileSystemOptions())
        {
            _context            = new Context();
            _context.SuperBlock = new SuperBlock();
            _context.RawStream  = stream;

            // Read superblock
            stream.Position = 0;
            byte[] buffer = Utilities.ReadFully(stream, _context.SuperBlock.Size);
            _context.SuperBlock.ReadFrom(buffer, 0);

            if (_context.SuperBlock.Magic != SuperBlock.SquashFsMagic)
            {
                throw new IOException("Invalid SquashFS filesystem - magic mismatch");
            }

            if (_context.SuperBlock.Compression != 1)
            {
                throw new IOException("Unsupported compression used");
            }

            if (_context.SuperBlock.ExtendedAttrsTableStart != -1)
            {
                throw new IOException("Unsupported extended attributes present");
            }

            if (_context.SuperBlock.MajorVersion != 4)
            {
                throw new IOException("Unsupported file system version: " + _context.SuperBlock.MajorVersion + "." + _context.SuperBlock.MinorVersion);
            }

            // Create block caches, used to reduce the amount of I/O and decompression activity.
            _blockCache            = new BlockCache <Block>((int)_context.SuperBlock.BlockSize, 20);
            _metablockCache        = new BlockCache <Metablock>(MetadataBufferSize, 20);
            _context.ReadBlock     = ReadBlock;
            _context.ReadMetaBlock = ReadMetaBlock;

            _context.InodeReader     = new MetablockReader(_context, _context.SuperBlock.InodeTableStart);
            _context.DirectoryReader = new MetablockReader(_context, _context.SuperBlock.DirectoryTableStart);

            if (_context.SuperBlock.FragmentTableStart != -1)
            {
                _context.FragmentTableReaders = LoadIndirectReaders(
                    _context.SuperBlock.FragmentTableStart,
                    (int)_context.SuperBlock.FragmentsCount,
                    FragmentRecord.RecordSize);
            }

            if (_context.SuperBlock.UidGidTableStart != -1)
            {
                _context.UidGidTableReaders = LoadIndirectReaders(
                    _context.SuperBlock.UidGidTableStart,
                    _context.SuperBlock.UidGidCount,
                    4);
            }

            // Bootstrap the root directory
            _context.InodeReader.SetPosition(_context.SuperBlock.RootInode);
            DirectoryInode dirInode = (DirectoryInode)Inode.Read(_context.InodeReader);

            RootDirectory = new Directory(_context, dirInode, _context.SuperBlock.RootInode);
        }
Example #8
0
 public File(Context context, Inode inode, MetadataRef inodeRef)
 {
     _context  = context;
     _inode    = inode;
     _inodeRef = inodeRef;
 }