/// <summary> /// /// </summary> /// <param name="volume"></param> /// <param name="sector"></param> /// <returns></returns> public static FileAllocationTableEntry Get(string volume, int sector) { FatVolumeBootRecord vbr = VolumeBootRecord.Get(volume) as FatVolumeBootRecord; byte[] bytes = FileAllocationTable.GetBytes(volume, vbr); int endSector = 0; switch (vbr.FatType) { case "FAT12": endSector = parseFat12(bytes, sector); break; case "FAT16": endSector = parseFat16(bytes, sector); break; case "FAT32": endSector = parseFat32(bytes, sector); break; } return(new FileAllocationTableEntry(sector, endSector)); }
/// <summary> /// /// </summary> /// <returns></returns> public byte[] GetContent() { FatVolumeBootRecord vbr = VolumeBootRecord.Get(this.Volume) as FatVolumeBootRecord; int RootDirSectors = ((vbr.BPB_RootEntryCount * 32) + (vbr.BytesPerSector - 1)) / vbr.BytesPerSector; uint FirstDataSector = (uint)(vbr.ReservedSectors + (vbr.BPB_NumberOfFATs * vbr.BPB_FatSize) + RootDirSectors); uint FirstSectorofCluster = ((this.FirstCluster - 2) * vbr.SectorsPerCluster) + FirstDataSector; byte[] bytes = DD.Get(this.Volume, (long)FirstSectorofCluster * (long)vbr.BytesPerSector, vbr.BytesPerSector, 1); if (this.Directory) { return(bytes); } else { if (this.FileSize <= bytes.Length) { return(Helper.GetSubArray(bytes, 0, this.FileSize)); } else { List <byte> byteList = new List <byte>(); int[] clusters = FileAllocationTable.GetFatEntry(this.Volume, (int)this.FirstCluster); foreach (int cluster in clusters) { long targetCluster = ((cluster - 2) * vbr.SectorsPerCluster) + FirstDataSector; byteList.AddRange(DD.Get(this.Volume, targetCluster * vbr.BytesPerSector, vbr.BytesPerSector, 1)); } return(Helper.GetSubArray(byteList.ToArray(), 0, this.FileSize)); } } }