/// <summary> /// Создаёт файл-образ раздела жёсткого диска с файловой системой DehaxFS с параметрами. /// </summary> /// <param name="diskPartitionSize">Размер раздела</param> /// <param name="diskClusterFactor">Размер кластера, множитель секторов диска</param> public DFSImage(long diskPartitionSize, byte diskClusterFactor) { diskClusterFactor = (byte)Math.Pow(2, diskClusterFactor - 1); _diskPartitionSize = diskPartitionSize; _diskClusterFactor = diskClusterFactor; _diskClusterSize = DISK_BYTES_PER_SECTOR * diskClusterFactor; _bitMap = new BitMap((int)(_diskPartitionSize / _diskClusterSize)); _inodes = new Inodes((int)(_diskPartitionSize / _diskClusterSize)); _rootDirectory = new RootDirectory(_diskClusterSize); _emptyData = new byte[_diskPartitionSize - Marshal.SizeOf <Superblock>() - _bitMap.GetLength() - _inodes.GetLength() - _rootDirectory.GetLength()]; _superblock = new Superblock() { filesystemType = 0x28, numClusters = (int)(_diskPartitionSize / _diskClusterSize), clusterFactor = diskClusterFactor, inodeArraySize = _inodes.GetLength(), bitMapSize = _bitMap.GetLength(), numFreeClusters = _emptyData.Length / _diskClusterSize, numFreeInode = (int)(_diskPartitionSize / _diskClusterSize - 1) }; InitializeFileSystem(); }
protected override void ProcessRecord() { #region MBR MasterBootRecord mbr = MasterBootRecord.Get(devicePath); uint superblockOffset = 0; foreach (PartitionEntry partition in mbr.PartitionTable) { if (partition.Bootable && partition.SystemID == "LINUX") { superblockOffset = partition.StartSector; } } #endregion MBR // Obtain a handle to the device named "devicePath" IntPtr hDevice = NativeMethods.getHandle(devicePath); using (FileStream streamToRead = NativeMethods.getFileStream(hDevice)) { // Get Superblock to understand File System Layout Superblock superBlock = new Superblock(Superblock.GetBytes(streamToRead, superblockOffset)); // Derive the location and length of the Block Group Descriptor Table uint bgdtOffset = (superblockOffset * NativeMethods.BYTES_PER_SECTOR) + ((superBlock.FirstDataBlock + 1) * superBlock.BlockSize); uint bgdtEntries = (superBlock.TotalBlockCount / superBlock.BlocksPerGroup) + 1; uint bgdtLength = bgdtEntries * BlockGroupDescriptor.BLOCK_GROUP_DESCRIPTOR_LENGTH; } } // ProcessRecord
public void Format() { // Setup superblock Array.Clear(_tmpBuffer, 0, BlockSize); Encoding.ASCII.GetBytes(HeaderMagic).CopyTo(_tmpBuffer, 0); BitConverter.GetBytes((int)0).CopyTo(_tmpBuffer, HeaderMagic.Length); Source.WriteAll(0, _tmpBuffer, 0, BlockSize); _superBlock = Superblock.ReadFrom(_tmpBuffer); // Setup block bitmap byte[] tmpBuffer = new byte[BlockSize]; Source.WriteAll(BlockSize * 1, tmpBuffer, 0, BlockSize); // Clear inode bitmap BitArray inodeBitmap = new BitArray(tmpBuffer); inodeBitmap[0] = true; inodeBitmap.CopyTo(tmpBuffer, 0); Source.WriteAll(BlockSize * 2, tmpBuffer, 0, BlockSize); // Create root directory BobFsNode root = new BobFsNode(this, 0); root.Type = ENodeType.Directory; root.NumLinks = 1; root.Size = 0; root.Commit(); }
public HardLinkInfo(H5BinaryReader reader, Superblock superblock) : base(reader) { _superblock = superblock; // object header address this.HeaderAddress = superblock.ReadOffset(reader); }
public void GetInformation(IMediaImage imagePlugin, Partition partition, out string information, Encoding encoding) { Encoding = Encoding.UTF8; information = ""; if (imagePlugin.Info.SectorSize < 512) { return; } bool bigEndian = true; byte[] sector = imagePlugin.ReadSector(partition.Start); Superblock fatxSb = Marshal.ByteArrayToStructureBigEndian <Superblock>(sector); if (fatxSb.magic == FATX_CIGAM) { fatxSb = Marshal.ByteArrayToStructureLittleEndian <Superblock>(sector); bigEndian = false; } if (fatxSb.magic != FATX_MAGIC) { return; } int logicalSectorsPerPhysicalSectors = partition.Offset == 0 && !bigEndian ? 8 : 1; StringBuilder sb = new StringBuilder(); sb.AppendLine("FATX filesystem"); sb.AppendFormat("{0} logical sectors ({1} bytes) per physical sector", logicalSectorsPerPhysicalSectors, logicalSectorsPerPhysicalSectors * imagePlugin.Info.SectorSize).AppendLine(); sb.AppendFormat("{0} sectors ({1} bytes) per cluster", fatxSb.sectorsPerCluster, fatxSb.sectorsPerCluster * logicalSectorsPerPhysicalSectors * imagePlugin.Info.SectorSize) .AppendLine(); sb.AppendFormat("Root directory starts on cluster {0}", fatxSb.rootDirectoryCluster).AppendLine(); string volumeLabel = StringHandlers.CToString(fatxSb.volumeLabel, bigEndian ? Encoding.BigEndianUnicode : Encoding.Unicode, true); sb.AppendFormat("Volume label: {0}", volumeLabel).AppendLine(); sb.AppendFormat("Volume serial: {0:X8}", fatxSb.id).AppendLine(); information = sb.ToString(); XmlFsType = new FileSystemType { Type = "FATX filesystem", ClusterSize = (uint)(fatxSb.sectorsPerCluster * logicalSectorsPerPhysicalSectors * imagePlugin.Info.SectorSize), VolumeName = volumeLabel, VolumeSerial = $"{fatxSb.id:X8}" }; XmlFsType.Clusters = (partition.End - partition.Start + 1) * imagePlugin.Info.SectorSize / XmlFsType.ClusterSize; }
public GlobalHeapId(H5BinaryReader reader, Superblock superblock) : base(reader) { _superblock = superblock; this.CollectionAddress = superblock.ReadOffset(reader); this.ObjectIndex = reader.ReadUInt32(); }
public bool Identify(IMediaImage imagePlugin, Partition partition) { if (imagePlugin.Info.SectorSize < 512) { return(false); } uint sbSize = (uint)(Marshal.SizeOf <Superblock>() / imagePlugin.Info.SectorSize); if (Marshal.SizeOf <Superblock>() % imagePlugin.Info.SectorSize != 0) { sbSize++; } byte[] sector = imagePlugin.ReadSectors(partition.Start, sbSize); if (sector.Length < Marshal.SizeOf <Superblock>()) { return(false); } Superblock unicosSb = Marshal.ByteArrayToStructureBigEndian <Superblock>(sector); AaruConsole.DebugWriteLine("UNICOS plugin", "magic = 0x{0:X16} (expected 0x{1:X16})", unicosSb.s_magic, UNICOS_MAGIC); return(unicosSb.s_magic == UNICOS_MAGIC); }
protected override void ProcessRecord() { #region MBR MasterBootRecord mbr = MasterBootRecord.Get(devicePath); uint offset = 0; foreach (PartitionEntry partition in mbr.PartitionTable) { if (partition.Bootable && partition.SystemID == "LINUX") { offset = partition.StartSector; } } #endregion MBR IntPtr hDevice = NativeMethods.getHandle(devicePath); using (FileStream streamToRead = NativeMethods.getFileStream(hDevice)) { if (asbytes) { WriteObject(Superblock.GetBytes(streamToRead, offset)); } else { WriteObject(new Superblock(Superblock.GetBytes(streamToRead, offset))); } } } // ProcessRecord
public BTree2Record04(H5BinaryReader reader, Superblock superblock) { this.FilteredHugeObjectAddress = superblock.ReadOffset(reader); this.FilteredHugeObjectLength = superblock.ReadLength(reader); this.FilterMask = reader.ReadUInt32(); this.FilteredHugeObjectMemorySize = superblock.ReadLength(reader); }
public VirtualStoragePropertyDescription(H5BinaryReader reader, Superblock superblock) : base(reader) { // address this.Address = superblock.ReadOffset(reader); // index this.Index = reader.ReadUInt32(); }
public static Superblock ReadFrom(byte[] buffer, int bufOffset = 0) { Superblock superBlock = new Superblock(); superBlock.Magic = Encoding.ASCII.GetString(buffer, bufOffset + 0, bufOffset + 8); superBlock.RootInum = BitConverter.ToUInt32(buffer, bufOffset + 8); return(superBlock); }
public void GetInformation(IMediaImage imagePlugin, Partition partition, out string information, Encoding encoding) { Encoding = encoding ?? Encoding.GetEncoding("iso-8859-15"); information = ""; if (imagePlugin.Info.SectorSize < 512) { return; } uint sbAddr = REISER4_SUPER_OFFSET / imagePlugin.Info.SectorSize; if (sbAddr == 0) { sbAddr = 1; } uint sbSize = (uint)(Marshal.SizeOf <Superblock>() / imagePlugin.Info.SectorSize); if (Marshal.SizeOf <Superblock>() % imagePlugin.Info.SectorSize != 0) { sbSize++; } byte[] sector = imagePlugin.ReadSectors(partition.Start + sbAddr, sbSize); if (sector.Length < Marshal.SizeOf <Superblock>()) { return; } Superblock reiserSb = Marshal.ByteArrayToStructureLittleEndian <Superblock>(sector); if (!_magic.SequenceEqual(reiserSb.magic)) { return; } var sb = new StringBuilder(); sb.AppendLine("Reiser 4 filesystem"); sb.AppendFormat("{0} bytes per block", reiserSb.blocksize).AppendLine(); sb.AppendFormat("Volume disk format: {0}", reiserSb.diskformat).AppendLine(); sb.AppendFormat("Volume UUID: {0}", reiserSb.uuid).AppendLine(); sb.AppendFormat("Volume name: {0}", StringHandlers.CToString(reiserSb.label, Encoding)).AppendLine(); information = sb.ToString(); XmlFsType = new FileSystemType { Type = "Reiser 4 filesystem", ClusterSize = reiserSb.blocksize, Clusters = ((partition.End - partition.Start) * imagePlugin.Info.SectorSize) / reiserSb.blocksize, VolumeName = StringHandlers.CToString(reiserSb.label, Encoding), VolumeSerial = reiserSb.uuid.ToString() }; }
private BobFs(BlockSource source, bool caching = true) { Source = source; _caching = caching; _tmpBuffer = new byte[BlockSize]; Source.ReadAll(0, _tmpBuffer, 0, BlockSize); _superBlock = Superblock.ReadFrom(_tmpBuffer); }
public byte[] GetBytes(string volume) { IntPtr hDevice = NativeMethods.getHandle(volume); using (FileStream streamToRead = NativeMethods.getFileStream(hDevice)) { Superblock sb = new Superblock(Superblock.GetBytes(streamToRead, 0)); return NativeMethods.readDrive(streamToRead, (sb.BlockSize * this.StartBlock), (sb.BlockSize * this.BlockCount)); } }
public ExternalFileListSlot(H5BinaryReader reader, Superblock superblock) : base(reader) { // name heap offset this.NameHeapOffset = superblock.ReadLength(reader); // offset this.Offset = superblock.ReadLength(reader); // size this.Size = superblock.ReadLength(reader); }
public SingleChunkIndexingInformation(H5BinaryReader reader, Superblock superblock, ChunkedStoragePropertyFlags flags) : base(reader) { if (flags.HasFlag(ChunkedStoragePropertyFlags.SINGLE_INDEX_WITH_FILTER)) { // filtered chunk size this.FilteredChunkSize = superblock.ReadLength(reader); // chunk filters this.ChunkFilters = reader.ReadUInt32(); } }
/// <summary> /// The ProcessRecord method instantiates a Superblock object based /// on the disk given as an argument. /// </summary> protected override void ProcessRecord() { #region MBR MasterBootRecord mbr = MasterBootRecord.Get(devicePath); uint superblockOffset = 0; foreach (PartitionEntry partition in mbr.PartitionTable) { if (partition.Bootable && partition.SystemID == "LINUX") { superblockOffset = partition.StartSector; } } #endregion MBR // Obtain a handle to the device named "devicePath" IntPtr hDevice = NativeMethods.getHandle(devicePath); using (FileStream streamToRead = NativeMethods.getFileStream(hDevice)) { // Get Superblock to understand File System Layout Superblock superBlock = new Superblock(Superblock.GetBytes(streamToRead, superblockOffset)); if (this.MyInvocation.BoundParameters.ContainsKey("GroupNumber")) { if (asbytes) { WriteObject(BlockGroupDescriptor.GetBytes(streamToRead, superblockOffset, superBlock, number)); } else { WriteObject(new BlockGroupDescriptor(BlockGroupDescriptor.GetBytes(streamToRead, superblockOffset, superBlock, number))); } } else { if (asbytes) { BlockGroupDescriptorTable.GetBytes(streamToRead, superblockOffset, superBlock); } else { byte[] bgdtBytes = BlockGroupDescriptorTable.GetBytes(streamToRead, superblockOffset, superBlock); for (uint o = 0; o < bgdtBytes.Length; o += BlockGroupDescriptor.BLOCK_GROUP_DESCRIPTOR_LENGTH) { WriteObject(new BlockGroupDescriptor(NativeMethods.GetSubArray(bgdtBytes, o, BlockGroupDescriptor.BLOCK_GROUP_DESCRIPTOR_LENGTH))); } } } } }
public DataBlockPage(H5BinaryReader reader, Superblock superblock, ulong elementsPerPage, ClientID clientID, uint chunkSizeLength) { // elements this.Elements = ArrayIndexUtils.ReadElements(reader, superblock, elementsPerPage, clientID, chunkSizeLength); // checksum this.Checksum = reader.ReadUInt32(); }
public bool Identify(IMediaImage imagePlugin, Partition partition) { if (imagePlugin.Info.SectorSize < 512) { return(false); } byte[] sector = imagePlugin.ReadSector(partition.Start); Superblock sb = Marshal.ByteArrayToStructureBigEndian <Superblock>(sector); return(sb.magic == FATX_MAGIC || sb.magic == FATX_CIGAM); }
public BTree2Record10(H5BinaryReader reader, Superblock superblock, byte rank) { // address this.Address = superblock.ReadOffset(reader); // scaled offsets this.ScaledOffsets = new ulong[rank]; for (int i = 0; i < rank; i++) { this.ScaledOffsets[i] = reader.ReadUInt64(); } }
public bool Identify(IMediaImage imagePlugin, Partition partition) { if (partition.Start + 1 >= imagePlugin.Info.Sectors) { return(false); } byte[] sector = imagePlugin.ReadSector(partition.Start + 1); if (sector.Length < 512) { return(false); } Superblock qnxSb = Marshal.ByteArrayToStructureLittleEndian <Superblock>(sector); // Check root directory name if (!_rootDirFname.SequenceEqual(qnxSb.rootDir.di_fname)) { return(false); } // Check sizes are multiple of blocks if (qnxSb.rootDir.di_size % 512 != 0 || qnxSb.inode.di_size % 512 != 0 || qnxSb.boot.di_size % 512 != 0 || qnxSb.altBoot.di_size % 512 != 0) { return(false); } // Check extents are not past device if (qnxSb.rootDir.di_first_xtnt.block + partition.Start >= partition.End || qnxSb.inode.di_first_xtnt.block + partition.Start >= partition.End || qnxSb.boot.di_first_xtnt.block + partition.Start >= partition.End || qnxSb.altBoot.di_first_xtnt.block + partition.Start >= partition.End) { return(false); } // Check inodes are in use if ((qnxSb.rootDir.di_status & 0x01) != 0x01 || (qnxSb.inode.di_status & 0x01) != 0x01 || (qnxSb.boot.di_status & 0x01) != 0x01) { return(false); } // All hail filesystems without identification marks return(true); }
internal static byte[] GetBytes(FileStream streamToRead, uint superblockOffset, Superblock superBlock) { // Derive the location and length of the Block Group Descriptor Table uint offset = (superblockOffset * NativeMethods.BYTES_PER_SECTOR) + ((superBlock.FirstDataBlock + 1) * superBlock.BlockSize); uint bgdtEntries = (superBlock.TotalBlockCount / superBlock.BlocksPerGroup) + 1; uint length = bgdtEntries * BlockGroupDescriptor.BLOCK_GROUP_DESCRIPTOR_LENGTH; // Ensure the bgdtLength value is a multiple of 512 (minimum value for reading bytes from disk) if ((length % NativeMethods.BYTES_PER_SECTOR) != 0) { length += (NativeMethods.BYTES_PER_SECTOR - (length % NativeMethods.BYTES_PER_SECTOR)); } // Get BlockGroupDescriptor bytes return NativeMethods.readDrive(streamToRead, offset, length); }
public BlockGroups(byte[] fsByteArray, Superblock.Superblock superblock) { #warning Check this statement int numberofBlockGroups = (superblock.BlocksPerGroup.Value % superblock.BlocksCount.Value); if (numberofBlockGroups < 1) numberofBlockGroups = 1; //if there are too few blocks for a group BinaryReader reader = new BinaryReader(new MemoryStream(fsByteArray)); //at this point we may have multiple copies of the FS in memory, figure out a way around this reader.ReadBytes(1024); //advance past superblock for (int i=0; i<numberofBlockGroups; i++) { byte[] buffer = new byte[31]; buffer = reader.ReadBytes(32); Groups.Add(new BlockGroup(buffer)); } }
public ChunkedStoragePropertyDescription3(H5BinaryReader reader, Superblock superblock) : base(reader) { // rank this.Rank = reader.ReadByte(); // address this.Address = superblock.ReadOffset(reader); // dimension sizes this.DimensionSizes = new uint[this.Rank]; for (uint i = 0; i < this.Rank; i++) { this.DimensionSizes[i] = reader.ReadUInt32(); } }
public ObjectHeaderSharedMessageRecord(H5BinaryReader reader, Superblock superblock) : base(reader) { _superblock = superblock; // hash value this.HashValue = reader.ReadUInt32(); // reserved reader.ReadByte(); // message type this.MessageType = (HeaderMessageType)reader.ReadByte(); // creation index this.CreationIndex = reader.ReadUInt16(); // object header address this.ObjectHeaderAddress = superblock.ReadOffset(reader); }
public bool Identify(IMediaImage imagePlugin, Partition partition) { if (imagePlugin.Info.SectorSize < 512) { return(false); } for (ulong location = 0; location <= 8; location++) { uint sbSize = (uint)(Marshal.SizeOf <Superblock>() / imagePlugin.Info.SectorSize); if (Marshal.SizeOf <Superblock>() % imagePlugin.Info.SectorSize != 0) { sbSize++; } if (partition.Start + location + sbSize >= imagePlugin.Info.Sectors) { break; } byte[] sector = imagePlugin.ReadSectors(partition.Start + location, sbSize); if (sector.Length < Marshal.SizeOf <Superblock>()) { return(false); } Superblock locusSb = Marshal.ByteArrayToStructureLittleEndian <Superblock>(sector); AaruConsole.DebugWriteLine("Locus plugin", "magic at {1} = 0x{0:X8}", locusSb.s_magic, location); if (locusSb.s_magic == LOCUS_MAGIC || locusSb.s_magic == LOCUS_CIGAM || locusSb.s_magic == LOCUS_MAGIC_OLD || locusSb.s_magic == LOCUS_CIGAM_OLD) { return(true); } } return(false); }
public BTree2Record11(H5BinaryReader reader, Superblock superblock, byte rank, uint chunkSizeLength) { // address this.Address = superblock.ReadOffset(reader); // chunk size this.ChunkSize = H5Utils.ReadUlong(reader, chunkSizeLength); // filter mask this.FilterMask = reader.ReadUInt32(); // scaled offsets this.ScaledOffsets = new ulong[rank]; for (int i = 0; i < rank; i++) { this.ScaledOffsets[i] = reader.ReadUInt64(); } }
internal static byte[] GetBytes(FileStream streamToRead, uint superblockOffset, Superblock superBlock, uint group) { // Derive the location and length of the Block Group Descriptor Table uint bgdtOffset = (superblockOffset * NativeMethods.BYTES_PER_SECTOR) + ((superBlock.FirstDataBlock + 1) * superBlock.BlockSize); uint bgdtEntries = (superBlock.TotalBlockCount / superBlock.BlocksPerGroup) + 1; uint bgdtLength = bgdtEntries * BlockGroupDescriptor.BLOCK_GROUP_DESCRIPTOR_LENGTH; // Determine the offset from the beginning of the BGDT to the desired group uint groupOffset = group * BLOCK_GROUP_DESCRIPTOR_LENGTH; // Determine what Sector contains the raw bytes uint groupSectorOffset = groupOffset / NativeMethods.BYTES_PER_SECTOR; // Read the sector that the desired block resides within byte[] SectorBytes = NativeMethods.readDrive(streamToRead, bgdtOffset + (groupSectorOffset * NativeMethods.BYTES_PER_SECTOR), NativeMethods.BYTES_PER_SECTOR); // Get Block Group Descriptor offset into Sector uint sectorOffset = (group % BLOCK_GROUPS_PER_SECTOR) * BLOCK_GROUP_DESCRIPTOR_LENGTH; // Create byte[] containing only bytes for the requested Block Group Descriptor return NativeMethods.GetSubArray(SectorBytes, sectorOffset, BLOCK_GROUP_DESCRIPTOR_LENGTH); }
public bool Identify(IMediaImage imagePlugin, Partition partition) { if (imagePlugin.Info.SectorSize < F2FS_MIN_SECTOR || imagePlugin.Info.SectorSize > F2FS_MAX_SECTOR) { return(false); } uint sbAddr = F2FS_SUPER_OFFSET / imagePlugin.Info.SectorSize; if (sbAddr == 0) { sbAddr = 1; } uint sbSize = (uint)(Marshal.SizeOf <Superblock>() / imagePlugin.Info.SectorSize); if (Marshal.SizeOf <Superblock>() % imagePlugin.Info.SectorSize != 0) { sbSize++; } if (partition.Start + sbAddr >= partition.End) { return(false); } byte[] sector = imagePlugin.ReadSectors(partition.Start + sbAddr, sbSize); if (sector.Length < Marshal.SizeOf <Superblock>()) { return(false); } Superblock sb = Marshal.ByteArrayToStructureLittleEndian <Superblock>(sector); return(sb.magic == F2FS_MAGIC); }
public bool Identify(IMediaImage imagePlugin, Partition partition) { if (imagePlugin.Info.SectorSize < 512) { return(false); } uint sbAddr = REISER_SUPER_OFFSET / imagePlugin.Info.SectorSize; if (sbAddr == 0) { sbAddr = 1; } uint sbSize = (uint)(Marshal.SizeOf <Superblock>() / imagePlugin.Info.SectorSize); if (Marshal.SizeOf <Superblock>() % imagePlugin.Info.SectorSize != 0) { sbSize++; } if (partition.Start + sbAddr + sbSize >= partition.End) { return(false); } byte[] sector = imagePlugin.ReadSectors(partition.Start + sbAddr, sbSize); if (sector.Length < Marshal.SizeOf <Superblock>()) { return(false); } Superblock reiserSb = Marshal.ByteArrayToStructureLittleEndian <Superblock>(sector); return(_magic35.SequenceEqual(reiserSb.magic) || _magic36.SequenceEqual(reiserSb.magic) || _magicJr.SequenceEqual(reiserSb.magic)); }
public void GetInformation(IMediaImage imagePlugin, Partition partition, out string information, Encoding encoding) { Encoding = encoding ?? Encoding.GetEncoding("iso-8859-15"); information = ""; byte[] sector = imagePlugin.ReadSector(partition.Start + 1); if (sector.Length < 512) { return; } Superblock qnxSb = Marshal.ByteArrayToStructureLittleEndian <Superblock>(sector); // Too much useless information /* * AaruConsole.DebugWriteLine("QNX4 plugin", "qnxSb.rootDir.di_fname = {0}", CurrentEncoding.GetString(qnxSb.rootDir.di_fname)); * AaruConsole.DebugWriteLine("QNX4 plugin", "qnxSb.rootDir.di_size = {0}", qnxSb.rootDir.di_size); * AaruConsole.DebugWriteLine("QNX4 plugin", "qnxSb.rootDir.di_first_xtnt.block = {0}", qnxSb.rootDir.di_first_xtnt.block); * AaruConsole.DebugWriteLine("QNX4 plugin", "qnxSb.rootDir.di_first_xtnt.length = {0}", qnxSb.rootDir.di_first_xtnt.length); * AaruConsole.DebugWriteLine("QNX4 plugin", "qnxSb.rootDir.di_xblk = {0}", qnxSb.rootDir.di_xblk); * AaruConsole.DebugWriteLine("QNX4 plugin", "qnxSb.rootDir.di_ftime = {0}", DateHandlers.UNIXUnsignedToDateTime(qnxSb.rootDir.di_ftime)); * AaruConsole.DebugWriteLine("QNX4 plugin", "qnxSb.rootDir.di_mtime = {0}", DateHandlers.UNIXUnsignedToDateTime(qnxSb.rootDir.di_mtime)); * AaruConsole.DebugWriteLine("QNX4 plugin", "qnxSb.rootDir.di_atime = {0}", DateHandlers.UNIXUnsignedToDateTime(qnxSb.rootDir.di_atime)); * AaruConsole.DebugWriteLine("QNX4 plugin", "qnxSb.rootDir.di_ctime = {0}", DateHandlers.UNIXUnsignedToDateTime(qnxSb.rootDir.di_ctime)); * AaruConsole.DebugWriteLine("QNX4 plugin", "qnxSb.rootDir.di_num_xtnts = {0}", qnxSb.rootDir.di_num_xtnts); * AaruConsole.DebugWriteLine("QNX4 plugin", "qnxSb.rootDir.di_mode = {0}", Convert.ToString(qnxSb.rootDir.di_mode, 8)); * AaruConsole.DebugWriteLine("QNX4 plugin", "qnxSb.rootDir.di_uid = {0}", qnxSb.rootDir.di_uid); * AaruConsole.DebugWriteLine("QNX4 plugin", "qnxSb.rootDir.di_gid = {0}", qnxSb.rootDir.di_gid); * AaruConsole.DebugWriteLine("QNX4 plugin", "qnxSb.rootDir.di_nlink = {0}", qnxSb.rootDir.di_nlink); * AaruConsole.DebugWriteLine("QNX4 plugin", "qnxSb.rootDir.di_zero = {0}", qnxSb.rootDir.di_zero); * AaruConsole.DebugWriteLine("QNX4 plugin", "qnxSb.rootDir.di_type = {0}", qnxSb.rootDir.di_type); * AaruConsole.DebugWriteLine("QNX4 plugin", "qnxSb.rootDir.di_status = {0}", qnxSb.rootDir.di_status); * * AaruConsole.DebugWriteLine("QNX4 plugin", "qnxSb.inode.di_fname = {0}", CurrentEncoding.GetString(qnxSb.inode.di_fname)); * AaruConsole.DebugWriteLine("QNX4 plugin", "qnxSb.inode.di_size = {0}", qnxSb.inode.di_size); * AaruConsole.DebugWriteLine("QNX4 plugin", "qnxSb.inode.di_first_xtnt.block = {0}", qnxSb.inode.di_first_xtnt.block); * AaruConsole.DebugWriteLine("QNX4 plugin", "qnxSb.inode.di_first_xtnt.length = {0}", qnxSb.inode.di_first_xtnt.length); * AaruConsole.DebugWriteLine("QNX4 plugin", "qnxSb.inode.di_xblk = {0}", qnxSb.inode.di_xblk); * AaruConsole.DebugWriteLine("QNX4 plugin", "qnxSb.inode.di_ftime = {0}", DateHandlers.UNIXUnsignedToDateTime(qnxSb.inode.di_ftime)); * AaruConsole.DebugWriteLine("QNX4 plugin", "qnxSb.inode.di_mtime = {0}", DateHandlers.UNIXUnsignedToDateTime(qnxSb.inode.di_mtime)); * AaruConsole.DebugWriteLine("QNX4 plugin", "qnxSb.inode.di_atime = {0}", DateHandlers.UNIXUnsignedToDateTime(qnxSb.inode.di_atime)); * AaruConsole.DebugWriteLine("QNX4 plugin", "qnxSb.inode.di_ctime = {0}", DateHandlers.UNIXUnsignedToDateTime(qnxSb.inode.di_ctime)); * AaruConsole.DebugWriteLine("QNX4 plugin", "qnxSb.inode.di_num_xtnts = {0}", qnxSb.inode.di_num_xtnts); * AaruConsole.DebugWriteLine("QNX4 plugin", "qnxSb.inode.di_mode = {0}", Convert.ToString(qnxSb.inode.di_mode, 8)); * AaruConsole.DebugWriteLine("QNX4 plugin", "qnxSb.inode.di_uid = {0}", qnxSb.inode.di_uid); * AaruConsole.DebugWriteLine("QNX4 plugin", "qnxSb.inode.di_gid = {0}", qnxSb.inode.di_gid); * AaruConsole.DebugWriteLine("QNX4 plugin", "qnxSb.inode.di_nlink = {0}", qnxSb.inode.di_nlink); * AaruConsole.DebugWriteLine("QNX4 plugin", "qnxSb.inode.di_zero = {0}", qnxSb.inode.di_zero); * AaruConsole.DebugWriteLine("QNX4 plugin", "qnxSb.inode.di_type = {0}", qnxSb.inode.di_type); * AaruConsole.DebugWriteLine("QNX4 plugin", "qnxSb.inode.di_status = {0}", qnxSb.inode.di_status); * * AaruConsole.DebugWriteLine("QNX4 plugin", "qnxSb.boot.di_fname = {0}", CurrentEncoding.GetString(qnxSb.boot.di_fname)); * AaruConsole.DebugWriteLine("QNX4 plugin", "qnxSb.boot.di_size = {0}", qnxSb.boot.di_size); * AaruConsole.DebugWriteLine("QNX4 plugin", "qnxSb.boot.di_first_xtnt.block = {0}", qnxSb.boot.di_first_xtnt.block); * AaruConsole.DebugWriteLine("QNX4 plugin", "qnxSb.boot.di_first_xtnt.length = {0}", qnxSb.boot.di_first_xtnt.length); * AaruConsole.DebugWriteLine("QNX4 plugin", "qnxSb.boot.di_xblk = {0}", qnxSb.boot.di_xblk); * AaruConsole.DebugWriteLine("QNX4 plugin", "qnxSb.boot.di_ftime = {0}", DateHandlers.UNIXUnsignedToDateTime(qnxSb.boot.di_ftime)); * AaruConsole.DebugWriteLine("QNX4 plugin", "qnxSb.boot.di_mtime = {0}", DateHandlers.UNIXUnsignedToDateTime(qnxSb.boot.di_mtime)); * AaruConsole.DebugWriteLine("QNX4 plugin", "qnxSb.boot.di_atime = {0}", DateHandlers.UNIXUnsignedToDateTime(qnxSb.boot.di_atime)); * AaruConsole.DebugWriteLine("QNX4 plugin", "qnxSb.boot.di_ctime = {0}", DateHandlers.UNIXUnsignedToDateTime(qnxSb.boot.di_ctime)); * AaruConsole.DebugWriteLine("QNX4 plugin", "qnxSb.boot.di_num_xtnts = {0}", qnxSb.boot.di_num_xtnts); * AaruConsole.DebugWriteLine("QNX4 plugin", "qnxSb.boot.di_mode = {0}", Convert.ToString(qnxSb.boot.di_mode, 8)); * AaruConsole.DebugWriteLine("QNX4 plugin", "qnxSb.boot.di_uid = {0}", qnxSb.boot.di_uid); * AaruConsole.DebugWriteLine("QNX4 plugin", "qnxSb.boot.di_gid = {0}", qnxSb.boot.di_gid); * AaruConsole.DebugWriteLine("QNX4 plugin", "qnxSb.boot.di_nlink = {0}", qnxSb.boot.di_nlink); * AaruConsole.DebugWriteLine("QNX4 plugin", "qnxSb.boot.di_zero = {0}", qnxSb.boot.di_zero); * AaruConsole.DebugWriteLine("QNX4 plugin", "qnxSb.boot.di_type = {0}", qnxSb.boot.di_type); * AaruConsole.DebugWriteLine("QNX4 plugin", "qnxSb.boot.di_status = {0}", qnxSb.boot.di_status); * * AaruConsole.DebugWriteLine("QNX4 plugin", "qnxSb.altBoot.di_fname = {0}", CurrentEncoding.GetString(qnxSb.altBoot.di_fname)); * AaruConsole.DebugWriteLine("QNX4 plugin", "qnxSb.altBoot.di_size = {0}", qnxSb.altBoot.di_size); * AaruConsole.DebugWriteLine("QNX4 plugin", "qnxSb.altBoot.di_first_xtnt.block = {0}", qnxSb.altBoot.di_first_xtnt.block); * AaruConsole.DebugWriteLine("QNX4 plugin", "qnxSb.altBoot.di_first_xtnt.length = {0}", qnxSb.altBoot.di_first_xtnt.length); * AaruConsole.DebugWriteLine("QNX4 plugin", "qnxSb.altBoot.di_xblk = {0}", qnxSb.altBoot.di_xblk); * AaruConsole.DebugWriteLine("QNX4 plugin", "qnxSb.altBoot.di_ftime = {0}", DateHandlers.UNIXUnsignedToDateTime(qnxSb.altBoot.di_ftime)); * AaruConsole.DebugWriteLine("QNX4 plugin", "qnxSb.altBoot.di_mtime = {0}", DateHandlers.UNIXUnsignedToDateTime(qnxSb.altBoot.di_mtime)); * AaruConsole.DebugWriteLine("QNX4 plugin", "qnxSb.altBoot.di_atime = {0}", DateHandlers.UNIXUnsignedToDateTime(qnxSb.altBoot.di_atime)); * AaruConsole.DebugWriteLine("QNX4 plugin", "qnxSb.altBoot.di_ctime = {0}", DateHandlers.UNIXUnsignedToDateTime(qnxSb.altBoot.di_ctime)); * AaruConsole.DebugWriteLine("QNX4 plugin", "qnxSb.altBoot.di_num_xtnts = {0}", qnxSb.altBoot.di_num_xtnts); * AaruConsole.DebugWriteLine("QNX4 plugin", "qnxSb.altBoot.di_mode = {0}", Convert.ToString(qnxSb.altBoot.di_mode, 8)); * AaruConsole.DebugWriteLine("QNX4 plugin", "qnxSb.altBoot.di_uid = {0}", qnxSb.altBoot.di_uid); * AaruConsole.DebugWriteLine("QNX4 plugin", "qnxSb.altBoot.di_gid = {0}", qnxSb.altBoot.di_gid); * AaruConsole.DebugWriteLine("QNX4 plugin", "qnxSb.altBoot.di_nlink = {0}", qnxSb.altBoot.di_nlink); * AaruConsole.DebugWriteLine("QNX4 plugin", "qnxSb.altBoot.di_zero = {0}", qnxSb.altBoot.di_zero); * AaruConsole.DebugWriteLine("QNX4 plugin", "qnxSb.altBoot.di_type = {0}", qnxSb.altBoot.di_type); * AaruConsole.DebugWriteLine("QNX4 plugin", "qnxSb.altBoot.di_status = {0}", qnxSb.altBoot.di_status); */ information = $"QNX4 filesystem\nCreated on {DateHandlers.UnixUnsignedToDateTime(qnxSb.rootDir.di_ftime)}\n"; XmlFsType = new FileSystemType { Type = "QNX4 filesystem", Clusters = partition.Length, ClusterSize = 512, CreationDate = DateHandlers.UnixUnsignedToDateTime(qnxSb.rootDir.di_ftime), CreationDateSpecified = true, ModificationDate = DateHandlers.UnixUnsignedToDateTime(qnxSb.rootDir.di_mtime), ModificationDateSpecified = true }; XmlFsType.Bootable |= qnxSb.boot.di_size != 0 || qnxSb.altBoot.di_size != 0; }
/// <summary> /// /// </summary> protected override void ProcessRecord() { #region MBR MasterBootRecord mbr = MasterBootRecord.Get(devicePath); uint superblockOffset = 0; foreach (PartitionEntry partition in mbr.PartitionTable) { if (partition.Bootable && partition.SystemID == "LINUX") { superblockOffset = partition.StartSector; } } #endregion MBR // Obtain a handle to the device named "devicePath" IntPtr hDevice = NativeMethods.getHandle(devicePath); using (FileStream streamToRead = NativeMethods.getFileStream(hDevice)) { // Get Superblock to understand File System Layout Superblock superBlock = new Superblock(Superblock.GetBytes(streamToRead, superblockOffset)); if (this.MyInvocation.BoundParameters.ContainsKey("Inode")) { if (inode == 0) { throw new Exception("0 is not a valid Inode value."); } else { uint block_group = (inode - 1) / superBlock.InodesPerGroup; BlockGroupDescriptor bgd = new BlockGroupDescriptor(BlockGroupDescriptorTable.GetBytes(streamToRead, superblockOffset, superBlock)); uint inodeTableOffset = (superblockOffset * NativeMethods.BYTES_PER_SECTOR) + (bgd.InodeTableOffset * superBlock.BlockSize); uint inodeSectorOffset = (inode - 1) / (NativeMethods.BYTES_PER_SECTOR / (uint)superBlock.InodeSize); byte[] SectorBytes = NativeMethods.readDrive(streamToRead, inodeTableOffset + (inodeSectorOffset * NativeMethods.BYTES_PER_SECTOR), NativeMethods.BYTES_PER_SECTOR); uint sectorOffset = ((inode - 1) % (NativeMethods.BYTES_PER_SECTOR / (uint)superBlock.InodeSize)) * (uint)superBlock.InodeSize; byte[] inodeBytes = NativeMethods.GetSubArray(SectorBytes, sectorOffset, (uint)superBlock.InodeSize); if (asbytes) { WriteObject(inodeBytes); } else { WriteObject(new Inode(inodeBytes, inode)); } } } else { // Create a byte array representing the BGDT byte[] bgdtBytes = BlockGroupDescriptorTable.GetBytes(streamToRead, superblockOffset, superBlock); // Iterate through BGDTs and output associate Inodes for (uint o = 0; o < bgdtBytes.Length; o += BlockGroupDescriptor.BLOCK_GROUP_DESCRIPTOR_LENGTH) { BlockGroupDescriptor bgd = new BlockGroupDescriptor(NativeMethods.GetSubArray(bgdtBytes, o, BlockGroupDescriptor.BLOCK_GROUP_DESCRIPTOR_LENGTH)); uint inodeTableOffset = (superblockOffset * NativeMethods.BYTES_PER_SECTOR) + (bgd.InodeTableOffset * superBlock.BlockSize); byte[] inodeTableBytes = InodeTable.GetBytes(streamToRead, superBlock, inodeTableOffset); for (uint i = 0; i < inodeTableBytes.Length; i += (uint)superBlock.InodeSize) { uint inode = ((o / BlockGroupDescriptor.BLOCK_GROUP_DESCRIPTOR_LENGTH) + 1) * ((i / (uint)superBlock.InodeSize) + 1); WriteObject(new Inode(NativeMethods.GetSubArray(inodeTableBytes, i, superBlock.InodeSize), inode)); } } } } }
/// <summary> /// Выполняет инициализацию структур файловой системы. /// </summary> private void Initialize() { _superblock = (Superblock)ReadStruct(FileStream, typeof(Superblock)); CLUSTER_SIZE = _superblock.clusterFactor * DISK_BYTES_PER_SECTOR; FileStream.Seek(_superblock.bitMapAddress, SeekOrigin.Begin); byte[] bitMapData = new byte[_superblock.bitMapSize]; FileStream.Read(bitMapData, 0, bitMapData.Length); _bitMap = new BitMap(bitMapData); if (_superblock.filesystemType != DFS_ID) { throw new InvalidDataException("Неизвестный тип файлово системы! Возможно, диск был повреждён."); } _rootDirectory = ReadDirectoryClusters(0, null, true); CurrentDirectory = _rootDirectory; //_openedPath = "/"; }
public ObjectHeaderContinuationMessage(H5BinaryReader reader, Superblock superblock) : base(reader) { this.Offset = superblock.ReadOffset(reader); this.Length = superblock.ReadLength(reader); }
public void GetInformation(IMediaImage imagePlugin, Partition partition, out string information, Encoding encoding) { Encoding = encoding ?? Encoding.GetEncoding("iso-8859-15"); information = ""; if (imagePlugin.Info.SectorSize < 512) { return; } uint sbAddr = REISER_SUPER_OFFSET / imagePlugin.Info.SectorSize; if (sbAddr == 0) { sbAddr = 1; } uint sbSize = (uint)(Marshal.SizeOf <Superblock>() / imagePlugin.Info.SectorSize); if (Marshal.SizeOf <Superblock>() % imagePlugin.Info.SectorSize != 0) { sbSize++; } byte[] sector = imagePlugin.ReadSectors(partition.Start + sbAddr, sbSize); if (sector.Length < Marshal.SizeOf <Superblock>()) { return; } Superblock reiserSb = Marshal.ByteArrayToStructureLittleEndian <Superblock>(sector); if (!_magic35.SequenceEqual(reiserSb.magic) && !_magic36.SequenceEqual(reiserSb.magic) && !_magicJr.SequenceEqual(reiserSb.magic)) { return; } var sb = new StringBuilder(); if (_magic35.SequenceEqual(reiserSb.magic)) { sb.AppendLine("Reiser 3.5 filesystem"); } else if (_magic36.SequenceEqual(reiserSb.magic)) { sb.AppendLine("Reiser 3.6 filesystem"); } else if (_magicJr.SequenceEqual(reiserSb.magic)) { sb.AppendLine("Reiser Jr. filesystem"); } sb.AppendFormat("Volume has {0} blocks with {1} blocks free", reiserSb.block_count, reiserSb.free_blocks). AppendLine(); sb.AppendFormat("{0} bytes per block", reiserSb.blocksize).AppendLine(); sb.AppendFormat("Root directory resides on block {0}", reiserSb.root_block).AppendLine(); if (reiserSb.umount_state == 2) { sb.AppendLine("Volume has not been cleanly umounted"); } sb.AppendFormat("Volume last checked on {0}", DateHandlers.UnixUnsignedToDateTime(reiserSb.last_check)). AppendLine(); if (reiserSb.version >= 2) { sb.AppendFormat("Volume UUID: {0}", reiserSb.uuid).AppendLine(); sb.AppendFormat("Volume name: {0}", Encoding.GetString(reiserSb.label)).AppendLine(); } information = sb.ToString(); XmlFsType = new FileSystemType(); if (_magic35.SequenceEqual(reiserSb.magic)) { XmlFsType.Type = "Reiser 3.5 filesystem"; } else if (_magic36.SequenceEqual(reiserSb.magic)) { XmlFsType.Type = "Reiser 3.6 filesystem"; } else if (_magicJr.SequenceEqual(reiserSb.magic)) { XmlFsType.Type = "Reiser Jr. filesystem"; } XmlFsType.ClusterSize = reiserSb.blocksize; XmlFsType.Clusters = reiserSb.block_count; XmlFsType.FreeClusters = reiserSb.free_blocks; XmlFsType.FreeClustersSpecified = true; XmlFsType.Dirty = reiserSb.umount_state == 2; if (reiserSb.version < 2) { return; } XmlFsType.VolumeName = Encoding.GetString(reiserSb.label); XmlFsType.VolumeSerial = reiserSb.uuid.ToString(); }
/// <summary> /// The ProcessRecord method instantiates a Superblock object based /// on the disk given as an argument. /// </summary> protected override void ProcessRecord() { #region MBR MasterBootRecord mbr = MasterBootRecord.Get(devicePath); uint superblockOffset = 0; foreach (PartitionEntry partition in mbr.PartitionTable) { if (partition.Bootable && partition.SystemID == "LINUX") { superblockOffset = partition.StartSector; } } #endregion MBR // Obtain a handle to the device named "devicePath" IntPtr hDevice = NativeMethods.getHandle(devicePath); using (FileStream streamToRead = NativeMethods.getFileStream(hDevice)) { // Get Superblock to understand File System Layout Superblock superBlock = new Superblock(Superblock.GetBytes(streamToRead, superblockOffset)); // Derive the location and length of the Block Group Descriptor Table uint bgdtOffset = (superblockOffset * NativeMethods.BYTES_PER_SECTOR) + ((superBlock.FirstDataBlock + 1) * superBlock.BlockSize); uint bgdtEntries = (superBlock.TotalBlockCount / superBlock.BlocksPerGroup) + 1; uint bgdtLength = bgdtEntries * BlockGroupDescriptor.BLOCK_GROUP_DESCRIPTOR_LENGTH; } }
/// <summary> /// Создаёт файл-образ раздела жёсткого диска с файловой системой DehaxFS с параметрами. /// </summary> /// <param name="diskPartitionSize">Размер раздела</param> /// <param name="diskClusterFactor">Размер кластера, множитель секторов диска</param> public DFSImage(long diskPartitionSize, byte diskClusterFactor) { diskClusterFactor = (byte)Math.Pow(2, diskClusterFactor - 1); _diskPartitionSize = diskPartitionSize; _diskClusterFactor = diskClusterFactor; _diskClusterSize = DISK_BYTES_PER_SECTOR * diskClusterFactor; _bitMap = new BitMap((int)(_diskPartitionSize / _diskClusterSize)); _inodes = new Inodes((int)(_diskPartitionSize / _diskClusterSize)); _rootDirectory = new RootDirectory(_diskClusterSize); _emptyData = new byte[_diskPartitionSize - Marshal.SizeOf<Superblock>() - _bitMap.GetLength() - _inodes.GetLength() - _rootDirectory.GetLength()]; _superblock = new Superblock() { filesystemType = 0x28, numClusters = (int)(_diskPartitionSize / _diskClusterSize), clusterFactor = diskClusterFactor, inodeArraySize = _inodes.GetLength(), bitMapSize = _bitMap.GetLength(), numFreeClusters = _emptyData.Length / _diskClusterSize, numFreeInode = (int)(_diskPartitionSize / _diskClusterSize - 1) }; InitializeFileSystem(); }