Esempio n. 1
0
        public virtual FileRecord GetFileRecord(string path)
        {
            if (path != String.Empty && !path.StartsWith(@"\"))
            {
                throw new InvalidPathException(String.Format("The path '{0}' is invalid", path));
            }

            if (path.EndsWith(@"\"))
            {
                path = path.Substring(0, path.Length - 1);
            }

            if (path == String.Empty)
            {
                return(GetFileRecord(MasterFileTable.RootDirSegmentReference));
            }

            string[]            components         = path.Substring(1).Split('\\');
            MftSegmentReference directoryReference = MasterFileTable.RootDirSegmentReference;

            lock (m_mftLock)
            {
                for (int index = 0; index < components.Length; index++)
                {
                    FileRecord directoryRecord = GetFileRecord(directoryReference);
                    if (index < components.Length - 1)
                    {
                        if (!directoryRecord.IsDirectory)
                        {
                            throw new InvalidPathException(String.Format("The path '{0}' is invalid", path));
                        }
                        IndexData indexData = new IndexData(this, directoryRecord, AttributeType.FileName);
                        directoryReference = indexData.FindFileNameRecordSegmentReference(components[index]);
                        if (directoryReference == null)
                        {
                            throw new DirectoryNotFoundException(String.Format("Could not find part of the path '{0}'", path));
                        }
                    }
                    else // Last component
                    {
                        IndexData           indexData     = new IndexData(this, directoryRecord, AttributeType.FileName);
                        MftSegmentReference fileReference = indexData.FindFileNameRecordSegmentReference(components[index]);
                        if (fileReference == null)
                        {
                            throw new FileNotFoundException(String.Format("Could not find file '{0}'", path));
                        }
                        FileRecord fileRecord = GetFileRecord(fileReference);
                        if (!fileRecord.IsMetaFile)
                        {
                            return(fileRecord);
                        }
                    }
                }
            }
            // We should never get here
            throw new InvalidPathException();
        }
Esempio n. 2
0
        public virtual FileRecord GetFileRecord(string path)
        {
            if (path != String.Empty && !path.StartsWith(@"\"))
            {
                throw new ArgumentException("Invalid path");
            }

            if (path.EndsWith(@"\"))
            {
                path = path.Substring(0, path.Length - 1);
            }

            if (path == String.Empty)
            {
                return(GetFileRecord(MasterFileTable.RootDirSegmentReference));
            }

            string[]            components         = path.Substring(1).Split('\\');
            MftSegmentReference directoryReference = MasterFileTable.RootDirSegmentReference;

            for (int index = 0; index < components.Length; index++)
            {
                FileRecord directoryRecord = GetFileRecord(directoryReference);
                if (index < components.Length - 1)
                {
                    if (!directoryRecord.IsDirectory)
                    {
                        return(null);
                    }
                    IndexData indexData = new IndexData(this, directoryRecord, AttributeType.FileName);
                    directoryReference = indexData.FindFileNameRecordSegmentReference(components[index]);
                    if (directoryReference == null)
                    {
                        return(null);
                    }
                }
                else // Last component
                {
                    IndexData           indexData     = new IndexData(this, directoryRecord, AttributeType.FileName);
                    MftSegmentReference fileReference = indexData.FindFileNameRecordSegmentReference(components[index]);
                    if (fileReference == null)
                    {
                        return(null);
                    }
                    FileRecord fileRecord = GetFileRecord(fileReference);
                    if (fileRecord != null && !fileRecord.IsMetaFile)
                    {
                        return(fileRecord);
                    }
                }
            }

            return(null);
        }