private void Touch() { if (file != null) { return; } if (!persistent) { var tempFileName = TemporaryFilesManager.Instance.GetTemporaryFile(); FileCopier.Copy(underlyingFile, tempFileName, true); underlyingFile = tempFileName; } file = new SerializableFileStreamWrapper(underlyingFile); var size = blockSize * (long)numberOfBlocks; // punch a hole if it is needed if (file.Stream.Length < size) { file.Stream.Seek(size - 1, SeekOrigin.Begin); file.Stream.WriteByte(0); } }
public SDCard(string imageFile, long? cardSize, bool persistent) { if(String.IsNullOrEmpty(imageFile)) { throw new ConstructionException("No card image file provided."); } else { if(!persistent) { var tempFileName = TemporaryFilesManager.Instance.GetTemporaryFile(); FileCopier.Copy(imageFile, tempFileName, true); imageFile = tempFileName; } file = new SerializableFileStreamWrapper(imageFile); } CardSize = cardSize ?? file.Stream.Length; var cardIdentificationBytes = new byte[] {0x01, 0x00, 0x00, 0x00, // 1b always one + 7b CRC (ignored) + 12b manufacturing date + 4b reserved 0x00, 0x00, 0x00, 0x00, // 32b product serial number + 8b product revision 0x38, 0x6c, 0x75, 0x6d, 0x45, // Product name, 5 character string. "Emul8" (backwards) 0x00, 0x00, 0x00 // 16b application ID + 8b manufacturer ID }; cardIdentification = new uint[4]; cardIdentification[0] = BitConverter.ToUInt32(cardIdentificationBytes, 0); cardIdentification[1] = BitConverter.ToUInt32(cardIdentificationBytes, 4); cardIdentification[2] = BitConverter.ToUInt32(cardIdentificationBytes, 8); cardIdentification[3] = BitConverter.ToUInt32(cardIdentificationBytes, 12); cardSpecificData = new uint[4]; uint deviceSize = (uint)(CardSize / 0x80000 - 1); cardSpecificData[0] = 0x0a4040af; cardSpecificData[1] = 0x3b377f80 | ((deviceSize & 0xffff) << 16); cardSpecificData[2] = 0x5b590000 | ((deviceSize >> 16) & 0x3f); cardSpecificData[3] = 0x400e0032; }
private void Init(string fileName) { if(nonPersistent) { var tempFile = TemporaryFilesManager.Instance.GetTemporaryFile(); FileCopier.Copy(fileName, tempFile, true); fileName = tempFile; } stream = new SerializableFileStreamWrapper(fileName); CheckUnderlyingFile(); size2n = (byte)Misc.Logarithm2(size); buffer = new byte[DesiredBufferSize]; }
private void Touch() { if(file != null) { return; } if(!persistent) { var tempFileName = TemporaryFilesManager.Instance.GetTemporaryFile(); FileCopier.Copy(underlyingFile, tempFileName, true); underlyingFile = tempFileName; } file = new SerializableFileStreamWrapper(underlyingFile); var size = blockSize * (long)numberOfBlocks; // punch a hole if it is needed if(file.Stream.Length < size) { file.Stream.Seek(size - 1, SeekOrigin.Begin); file.Stream.WriteByte(0); } }