internal static UnixFileType FileTypeFromInodeType(InodeType inodeType)
 {
     switch (inodeType)
     {
         case InodeType.BlockDevice:
         case InodeType.ExtendedBlockDevice:
             return UnixFileType.Block;
         case InodeType.CharacterDevice:
         case InodeType.ExtendedCharacterDevice:
             return UnixFileType.Character;
         case InodeType.Directory:
         case InodeType.ExtendedDirectory:
             return UnixFileType.Directory;
         case InodeType.Fifo:
         case InodeType.ExtendedFifo:
             return UnixFileType.Fifo;
         case InodeType.File:
         case InodeType.ExtendedFile:
             return UnixFileType.Regular;
         case InodeType.Socket:
         case InodeType.ExtendedSocket:
             return UnixFileType.Socket;
         case InodeType.Symlink:
         case InodeType.ExtendedSymlink:
             return UnixFileType.Link;
         default:
             throw new NotSupportedException("Unrecognized inode type: " + inodeType);
     }
 }
Beispiel #2
0
 public virtual int ReadFrom(byte[] buffer, int offset)
 {
     Type             = (InodeType)Utilities.ToUInt16LittleEndian(buffer, offset + 0);
     Mode             = Utilities.ToUInt16LittleEndian(buffer, offset + 2);
     UidKey           = Utilities.ToUInt16LittleEndian(buffer, offset + 4);
     GidKey           = Utilities.ToUInt16LittleEndian(buffer, offset + 6);
     ModificationTime = Utilities.DateTimeFromUnix(Utilities.ToUInt32LittleEndian(buffer, offset + 8));
     InodeNumber      = Utilities.ToUInt32LittleEndian(buffer, offset + 12);
     return(16);
 }
Beispiel #3
0
 public virtual int ReadFrom(byte[] buffer, int offset)
 {
     Type = (InodeType)Utilities.ToUInt16LittleEndian(buffer, offset + 0);
     Mode = Utilities.ToUInt16LittleEndian(buffer, offset + 2);
     UidKey = Utilities.ToUInt16LittleEndian(buffer, offset + 4);
     GidKey = Utilities.ToUInt16LittleEndian(buffer, offset + 6);
     ModificationTime = Utilities.DateTimeFromUnix(Utilities.ToUInt32LittleEndian(buffer, offset + 8));
     InodeNumber = Utilities.ToUInt32LittleEndian(buffer, offset + 12);
     return 16;
 }
Beispiel #4
0
 public virtual int ReadFrom(byte[] buffer, int offset)
 {
     Type             = (InodeType)EndianUtilities.ToUInt16LittleEndian(buffer, offset + 0);
     Mode             = EndianUtilities.ToUInt16LittleEndian(buffer, offset + 2);
     UidKey           = EndianUtilities.ToUInt16LittleEndian(buffer, offset + 4);
     GidKey           = EndianUtilities.ToUInt16LittleEndian(buffer, offset + 6);
     ModificationTime = ((long)EndianUtilities.ToUInt32LittleEndian(buffer, offset + 8)).FromUnixTimeSeconds().DateTime;
     InodeNumber      = EndianUtilities.ToUInt32LittleEndian(buffer, offset + 12);
     return(16);
 }
Beispiel #5
0
        private static Inode InstantiateType(InodeType type)
        {
            switch (type)
            {
            case InodeType.Directory:
                return(new DirectoryInode());

            case InodeType.ExtendedDirectory:
                return(new ExtendedDirectoryInode());

            case InodeType.File:
                return(new RegularInode());

            case InodeType.Symlink:
                return(new SymlinkInode());

            case InodeType.CharacterDevice:
            case InodeType.BlockDevice:
                return(new DeviceInode());

            default:
                throw new NotImplementedException("Inode type not implemented: " + type);
            }
        }
Beispiel #6
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);
        }
Beispiel #7
0
 private static Inode InstantiateType(InodeType type)
 {
     switch (type)
     {
         case InodeType.Directory:
             return new DirectoryInode();
         case InodeType.ExtendedDirectory:
             return new ExtendedDirectoryInode();
         case InodeType.File:
             return new RegularInode();
         case InodeType.Symlink:
             return new SymlinkInode();
         case InodeType.CharacterDevice:
         case InodeType.BlockDevice:
             return new DeviceInode();
         default:
             throw new NotImplementedException("Inode type not implemented: " + type);
     }
 }