Example #1
0
        internal void FreshenFileName(FileNameRecord fileName, bool updateMftRecord)
        {
            //
            // Freshen the record from the definitive info in the other attributes
            //
            StandardInformation si           = StandardInformation;
            NtfsAttribute       anonDataAttr = GetAttribute(AttributeType.Data, null);

            fileName.CreationTime     = si.CreationTime;
            fileName.ModificationTime = si.ModificationTime;
            fileName.MftChangedTime   = si.MftChangedTime;
            fileName.LastAccessTime   = si.LastAccessTime;
            fileName.Flags            = si.FileAttributes;

            if (_dirty && NtfsTransaction.Current != null)
            {
                fileName.MftChangedTime = NtfsTransaction.Current.Timestamp;
            }

            // Directories don't have directory flag set in StandardInformation, so set from MFT record
            if ((_records[0].Flags & FileRecordFlags.IsDirectory) != 0)
            {
                fileName.Flags |= FileAttributeFlags.Directory;
            }

            if (anonDataAttr != null)
            {
                fileName.RealSize      = (ulong)anonDataAttr.PrimaryRecord.DataLength;
                fileName.AllocatedSize = (ulong)anonDataAttr.PrimaryRecord.AllocatedLength;
            }

            if (updateMftRecord)
            {
                foreach (NtfsStream stream in GetStreams(AttributeType.FileName, null))
                {
                    FileNameRecord fnr = stream.GetContent <FileNameRecord>();
                    if (fnr.Equals(fileName))
                    {
                        fnr        = new FileNameRecord(fileName);
                        fnr.Flags &= ~FileAttributeFlags.ReparsePoint;
                        stream.SetContent(fnr);
                    }
                }
            }
        }
Example #2
0
        internal void RemoveEntry(DirectoryEntry dirEntry)
        {
            File file = _context.GetFileByRef(dirEntry.Reference);

            FileNameRecord nameRecord = dirEntry.Details;

            Index.Remove(dirEntry.Details);

            foreach (NtfsStream stream in file.GetStreams(AttributeType.FileName, null))
            {
                FileNameRecord streamName = stream.GetContent <FileNameRecord>();
                if (nameRecord.Equals(streamName))
                {
                    file.RemoveStream(stream);
                    break;
                }
            }

            file.HardLinkCount--;
            file.UpdateRecordInMft();

            Modified();
            UpdateRecordInMft();
        }