public static BootSectorInfo ParseBootSector_FATx(byte[] bootSector, FATxType fatType) { BootSectorInfo info = new BootSectorInfo(); byte[] BytesPerSector = new byte[] { bootSector[11], bootSector[12] }; byte[] SectorsPerCluster = new byte[] { bootSector[13] }; byte[] ReservedSectors = new byte[] { bootSector[14], bootSector[15] }; byte[] FileSystemName = null; byte[] VolumeSerialNumber = null; if (fatType == FATxType.Fat32) { //FAT32 FileSystemName = new byte[] { bootSector[82], bootSector[83], bootSector[84], bootSector[85], bootSector[86], bootSector[87], bootSector[88], bootSector[89] }; VolumeSerialNumber = new byte[] { bootSector[67], bootSector[68], bootSector[69], bootSector[70] }; } else if (fatType == FATxType.Fat12_16) { //FAT12/16 FileSystemName = new byte[] { bootSector[54], bootSector[55], bootSector[56], bootSector[57], bootSector[58], bootSector[59], bootSector[60], bootSector[61] }; VolumeSerialNumber = new byte[] { bootSector[39], bootSector[40], bootSector[41], bootSector[42] }; } info.FileSystemName_Parsed = Encoding.ASCII.GetString(FileSystemName); info.BytesPerSector = BitConverter.ToUInt16(BytesPerSector, 0); info.SectorsPerCluster = SectorsPerCluster[0]; info.ReservedSectors = BitConverter.ToUInt16(ReservedSectors, 0); info.VolumeSerialNumber = BitConverter.ToUInt32(VolumeSerialNumber, 0); return(info); }
public static BootSectorInfo ParseBootSector_ExFat(byte[] bootSector) { BootSectorInfo info = new BootSectorInfo(); byte[] BytesPerSector = new byte[] { bootSector[108] }; byte[] SectorsPerCluster = new byte[] { bootSector[109] }; byte[] FileSystemName = new byte[] { bootSector[3], bootSector[4], bootSector[5], bootSector[6], bootSector[7], bootSector[8], bootSector[9], bootSector[10] }; byte[] VolumeSerialNumber = new byte[] { bootSector[100], bootSector[101], bootSector[102], bootSector[103] }; info.FileSystemName_Parsed = Encoding.ASCII.GetString(FileSystemName); info.BytesPerSector = (uint)Math.Pow(2.0, BytesPerSector[0]); info.SectorsPerCluster = (byte)Math.Pow(2.0, SectorsPerCluster[0]); info.VolumeSerialNumber = BitConverter.ToUInt32(VolumeSerialNumber, 0); return(info); }
public static BootSectorInfo ParseBootSector_NTFS(byte[] bootSector) { BootSectorInfo info = new BootSectorInfo(); byte[] BytesPerSector = new byte[] { bootSector[11], bootSector[12] }; byte[] SectorsPerCluster = new byte[] { bootSector[13] }; byte[] ReservedSectors = new byte[] { bootSector[14], bootSector[15] }; byte[] FileSystemName = new byte[] { bootSector[3], bootSector[4], bootSector[5], bootSector[6], bootSector[7], bootSector[8], bootSector[9], bootSector[10] }; byte[] VolumeSerialNumber = new byte[] { bootSector[72], bootSector[73], bootSector[74], bootSector[75], bootSector[76], bootSector[77], bootSector[78], bootSector[79] }; if (!BitConverter.IsLittleEndian) { Array.Reverse(BytesPerSector); Array.Reverse(ReservedSectors); } info.FileSystemName_Parsed = Encoding.ASCII.GetString(FileSystemName); info.BytesPerSector = BitConverter.ToUInt16(BytesPerSector, 0); info.SectorsPerCluster = SectorsPerCluster[0]; info.ReservedSectors = BitConverter.ToUInt16(ReservedSectors, 0); info.VolumeSerialNumber = BitConverter.ToUInt64(VolumeSerialNumber, 0); return(info); }
public UsbDeviceInfo(DeviceInfo deviceInfo, BootSectorInfo bootSectorInfo, DiskSpaceLayout?diskSpaceLayout) { DiskSpaceLayout = diskSpaceLayout; DeviceInfo = deviceInfo; BootSectorInfo = bootSectorInfo; }