Exemplo n.º 1
0
        public override FileSystemEntry CreateFile(string path)
        {
            string     parentDirectoryName   = Path.GetDirectoryName(path);
            string     fileName              = Path.GetFileName(path);
            FileRecord parentDirectoryRecord = m_volume.GetFileRecord(parentDirectoryName);

            if (parentDirectoryRecord != null)
            {
                FileRecord fileRecord = m_volume.CreateFile(parentDirectoryRecord.BaseSegmentReference, fileName, false);
                return(ToFileSystemEntry(path, fileRecord));
            }
            else
            {
                throw new DirectoryNotFoundException();
            }
        }
Exemplo n.º 2
0
        public override FileSystemEntry CreateFile(string path)
        {
            string streamName = GetStreamName(path);

            path = GetFilePath(path);
            string     parentDirectoryName   = Path.GetDirectoryName(path);
            string     fileName              = Path.GetFileName(path);
            FileRecord parentDirectoryRecord = m_volume.GetFileRecord(parentDirectoryName);
            FileRecord fileRecord            = null;

            if (streamName == String.Empty)
            {
                fileRecord = m_volume.CreateFile(parentDirectoryRecord.BaseSegmentReference, fileName, false);
            }
            else
            {
                try
                {
                    fileRecord = m_volume.GetFileRecord(path);
                }
                catch (FileNotFoundException)
                {
                }

                if (fileRecord == null)
                {
                    fileRecord = m_volume.CreateFile(parentDirectoryRecord.BaseSegmentReference, fileName, false);
                }
                else
                {
                    // We might need to allocate an additional FileRecordSegment so we have to make sure we can extend the MFT if it is full
                    if (m_volume.NumberOfFreeClusters < m_volume.NumberOfClustersRequiredToExtendMft)
                    {
                        throw new DiskFullException();
                    }
                }
                fileRecord.CreateAttributeRecord(AttributeType.Data, streamName);
                m_volume.UpdateFileRecord(fileRecord);
            }
            return(ToFileSystemEntry(path, fileRecord));
        }