public static File CreateNew(INtfsContext context, FileRecordFlags flags, FileAttributeFlags dirFlags) { File newFile = context.AllocateFile(flags); FileAttributeFlags fileFlags = FileAttributeFlags.Archive | FileRecord.ConvertFlags(flags) | (dirFlags & FileAttributeFlags.Compressed); AttributeFlags dataAttrFlags = AttributeFlags.None; if ((dirFlags & FileAttributeFlags.Compressed) != 0) { dataAttrFlags |= AttributeFlags.Compressed; } StandardInformation.InitializeNewFile(newFile, fileFlags); if (context.ObjectIds != null) { Guid newId = CreateNewGuid(context); NtfsStream stream = newFile.CreateStream(AttributeType.ObjectId, null); ObjectId objId = new ObjectId(); objId.Id = newId; stream.SetContent(objId); context.ObjectIds.Add(newId, newFile.MftReference, newId, Guid.Empty, Guid.Empty); } newFile.CreateAttribute(AttributeType.Data, dataAttrFlags); newFile.UpdateRecordInMft(); return(newFile); }
private File CreateFixedSystemFile(long mftIndex, long firstCluster, ulong numClusters, bool wipe) { BiosParameterBlock bpb = _context.BiosParameterBlock; if (wipe) { byte[] wipeBuffer = new byte[bpb.BytesPerCluster]; _context.RawStream.Position = firstCluster * bpb.BytesPerCluster; for (ulong i = 0; i < numClusters; ++i) { _context.RawStream.Write(wipeBuffer, 0, wipeBuffer.Length); } } FileRecord fileRec = _context.Mft.AllocateRecord((uint)mftIndex, FileRecordFlags.None); fileRec.Flags = FileRecordFlags.InUse; fileRec.SequenceNumber = (ushort)mftIndex; File file = new File(_context, fileRec); StandardInformation.InitializeNewFile(file, FileAttributeFlags.Hidden | FileAttributeFlags.System); file.CreateStream(AttributeType.Data, null, firstCluster, numClusters, (uint)bpb.BytesPerCluster); file.UpdateRecordInMft(); if (_context.ClusterBitmap != null) { _context.ClusterBitmap.MarkAllocated(firstCluster, (long)numClusters); } return(file); }
internal static new Directory CreateNew(INtfsContext context, FileAttributeFlags parentDirFlags) { Directory dir = (Directory)context.AllocateFile(FileRecordFlags.IsDirectory); StandardInformation.InitializeNewFile( dir, FileAttributeFlags.Archive | (parentDirFlags & FileAttributeFlags.Compressed)); // Create the index root attribute by instantiating a new index dir.CreateIndex("$I30", AttributeType.FileName, AttributeCollationRule.Filename); dir.UpdateRecordInMft(); return(dir); }
private File CreateSystemFile(long mftIndex, FileRecordFlags flags) { FileRecord fileRec = _context.Mft.AllocateRecord((uint)mftIndex, flags); fileRec.SequenceNumber = (ushort)mftIndex; File file = new File(_context, fileRec); StandardInformation.InitializeNewFile(file, FileAttributeFlags.Hidden | FileAttributeFlags.System | FileRecord.ConvertFlags(flags)); file.CreateStream(AttributeType.Data, null); file.UpdateRecordInMft(); return(file); }
private Directory CreateSystemDirectory(long mftIndex) { FileRecord fileRec = _context.Mft.AllocateRecord((uint)mftIndex, FileRecordFlags.None); fileRec.Flags = FileRecordFlags.InUse | FileRecordFlags.IsDirectory; fileRec.SequenceNumber = (ushort)mftIndex; Directory dir = new Directory(_context, fileRec); StandardInformation.InitializeNewFile(dir, FileAttributeFlags.Hidden | FileAttributeFlags.System); dir.CreateIndex("$I30", AttributeType.FileName, AttributeCollationRule.Filename); dir.UpdateRecordInMft(); return(dir); }
public File InitializeNew(INtfsContext context, long firstBitmapCluster, ulong numBitmapClusters, long firstRecordsCluster, ulong numRecordsClusters) { BiosParameterBlock bpb = context.BiosParameterBlock; FileRecord fileRec = new FileRecord(bpb.BytesPerSector, bpb.MftRecordSize, (uint)MftIndex); fileRec.Flags = FileRecordFlags.InUse; fileRec.SequenceNumber = 1; _recordCache[MftIndex] = fileRec; _self = new File(context, fileRec); StandardInformation.InitializeNewFile(_self, FileAttributeFlags.Hidden | FileAttributeFlags.System); NtfsStream recordsStream = _self.CreateStream(AttributeType.Data, null, firstRecordsCluster, numRecordsClusters, (uint)bpb.BytesPerCluster); _recordStream = recordsStream.Open(FileAccess.ReadWrite); Wipe(_recordStream); NtfsStream bitmapStream = _self.CreateStream(AttributeType.Bitmap, null, firstBitmapCluster, numBitmapClusters, (uint)bpb.BytesPerCluster); using (Stream s = bitmapStream.Open(FileAccess.ReadWrite)) { Wipe(s); s.SetLength(8); _bitmap = new Bitmap(s, long.MaxValue); } _recordLength = context.BiosParameterBlock.MftRecordSize; _bytesPerSector = context.BiosParameterBlock.BytesPerSector; _bitmap.MarkPresentRange(0, 1); // Write the MFT's own record to itself byte[] buffer = new byte[_recordLength]; fileRec.ToBytes(buffer, 0); _recordStream.Position = 0; _recordStream.Write(buffer, 0, _recordLength); _recordStream.Flush(); return(_self); }