Example #1
0
        public FatDirectoryEntry AddDirectoryEntry(string aName, DirectoryEntryTypeEnum aType)
        {
            Global.mFileSystemDebugger.SendInternal("-- FatDirectoryEntry.AddDirectoryEntry --");
            Global.mFileSystemDebugger.SendInternal("aName =");
            Global.mFileSystemDebugger.SendInternal(aName);
            Global.mFileSystemDebugger.SendInternal("aType =");
            Global.mFileSystemDebugger.SendInternal((uint)aType);

            if ((aType == DirectoryEntryTypeEnum.Directory) || (aType == DirectoryEntryTypeEnum.File))
            {
                string xFullPath              = Path.Combine(mFullPath, aName);
                uint   xFirstCluster          = ((FatFileSystem)mFileSystem).GetFat(0).GetNextUnallocatedFatEntry();
                uint   xEntryHeaderDataOffset = GetNextUnallocatedDirectoryEntry();
                Global.mFileSystemDebugger.SendInternal("xFullPath =");
                Global.mFileSystemDebugger.SendInternal(xFullPath);
                Global.mFileSystemDebugger.SendInternal("xFirstCluster =");
                Global.mFileSystemDebugger.SendInternal(xFirstCluster);
                Global.mFileSystemDebugger.SendInternal("xEntryHeaderDataOffset =");
                Global.mFileSystemDebugger.SendInternal(xEntryHeaderDataOffset);

                var xNewEntry = new FatDirectoryEntry((FatFileSystem)mFileSystem, this, xFullPath, aName, 0, xFirstCluster, xEntryHeaderDataOffset, aType);
                xNewEntry.AllocateDirectoryEntry();
                return(xNewEntry);
            }
            throw new ArgumentOutOfRangeException(nameof(aType), "Unknown directory entry type.");
        }
Example #2
0
 public FatDirectoryEntry AddDirectoryEntry(string aName, DirectoryEntryTypeEnum aType)
 {
     Global.mFileSystemDebugger.SendInternal($"FatDirectoryEntry.AddDirectoryEntry : aName = {aName}, aType = {aType}");
     if ((aType == DirectoryEntryTypeEnum.Directory) || (aType == DirectoryEntryTypeEnum.File))
     {
         uint xFirstCluster          = mFileSystem.GetFat(0).GetNextUnallocatedFatEntry();
         uint xEntryHeaderDataOffset = GetNextUnallocatedEntry();
         var  xNewEntry = new FatDirectoryEntry(mFileSystem, this, aName, 0, xFirstCluster, xEntryHeaderDataOffset, aType);
         xNewEntry.AllocateDirectoryEntry();
         return(xNewEntry);
     }
     throw new ArgumentOutOfRangeException("aType", "Unknown directory entry type.");
 }
Example #3
0
        public FatDirectoryEntry AddDirectoryEntry(string aName, DirectoryEntryTypeEnum aType)
        {
            Global.mFileSystemDebugger.SendInternal("-- FatDirectoryEntry.AddDirectoryEntry --");
            Global.mFileSystemDebugger.SendInternal("aName =");
            Global.mFileSystemDebugger.SendInternal(aName);
            Global.mFileSystemDebugger.SendInternal("aType =");
            Global.mFileSystemDebugger.SendInternal((uint)aType);

            if ((aType == DirectoryEntryTypeEnum.Directory) || (aType == DirectoryEntryTypeEnum.File))
            {
                string xFullPath = Path.Combine(mFullPath, aName);
                uint xFirstCluster = ((FatFileSystem)mFileSystem).GetFat(0).GetNextUnallocatedFatEntry();
                uint xEntryHeaderDataOffset = GetNextUnallocatedDirectoryEntry();
                Global.mFileSystemDebugger.SendInternal("xFullPath =");
                Global.mFileSystemDebugger.SendInternal(xFullPath);
                Global.mFileSystemDebugger.SendInternal("xFirstCluster =");
                Global.mFileSystemDebugger.SendInternal(xFirstCluster);
                Global.mFileSystemDebugger.SendInternal("xEntryHeaderDataOffset =");
                Global.mFileSystemDebugger.SendInternal(xEntryHeaderDataOffset);

                var xNewEntry = new FatDirectoryEntry((FatFileSystem)mFileSystem, this, xFullPath, aName, 0, xFirstCluster, xEntryHeaderDataOffset, aType);
                xNewEntry.AllocateDirectoryEntry();
                return xNewEntry;
            }
            throw new ArgumentOutOfRangeException(nameof(aType), "Unknown directory entry type.");
        }
Example #4
0
        public FatDirectoryEntry AddDirectoryEntry(string aName, DirectoryEntryTypeEnum aEntryType)
        {
            Global.mFileSystemDebugger.SendInternal("-- FatDirectoryEntry.AddDirectoryEntry --");
            Global.mFileSystemDebugger.SendInternal("aName =");
            Global.mFileSystemDebugger.SendInternal(aName);
            Global.mFileSystemDebugger.SendInternal("aEntryType =");
            Global.mFileSystemDebugger.SendInternal((uint)aEntryType);

            if ((aEntryType == DirectoryEntryTypeEnum.Directory) || (aEntryType == DirectoryEntryTypeEnum.File))
            {
                string xShortName = aName;
                uint[] xDirectoryEntriesToAllocate = null;

                //Stack corruption, just delete everything from this until commented if when it's fixed
                var x1 = aEntryType == DirectoryEntryTypeEnum.File;
                var x2 = aName.Contains(".");
                var x3 = x2 ? aName.Substring(0, aName.LastIndexOf('.')).Contains(".") : false;
                var x4 = x2 ? aName.Substring(0, aName.IndexOf('.')).Length > 8 : false;
                var x5 = x2 ? aName.Substring(aName.IndexOf('.') + 1).Length > 3 : false;
                var x6 = aEntryType == DirectoryEntryTypeEnum.Directory;
                var x7 = aName.Length > 11;

                var x8 = (x3 || (x4 || x5));
                var x9 = (x2 && x8);

                var x10 = (x1 && x9) || (x6 && x7);

                //if ((aEntryType == DirectoryEntryTypeEnum.File && (aName.Contains(".") && (aName.Substring(0, aName.LastIndexOf('.')).Contains(".") || (aName.Substring(0, aName.IndexOf('.')).Length > 8 || aName.Substring(aName.IndexOf('.') + 1).Length > 3)))) ||
                //    (aEntryType == DirectoryEntryTypeEnum.Directory && aName.Length > 11))
                if (x10)
                {
                    string xLongName = aName;

                    char[] xInvalidShortNameChars = new char[] { '"', '*', '+', ',', '.', '/', ':', ';', '<', '=', '>', '?', '[', '\\', ']', '|' };

                    int xLastPeriodPosition = aName.LastIndexOf('.');

                    string xExt = "";

                    if (xLastPeriodPosition + 1 > 0 && xLastPeriodPosition + 1 < aName.Length)
                    {
                        xExt = xShortName.Substring(xLastPeriodPosition + 1);
                    }

                    for (int i = xShortName.Length - 1; i > 0; i--)
                    {
                        char xChar = xShortName[i];

                        if (char.IsWhiteSpace(xChar) || (xChar == '.' && i != xLastPeriodPosition))
                        {
                            xShortName.Remove(i, 1);
                        }
                    }

                    foreach (char xInvalidChar in xInvalidShortNameChars)
                    {
                        xShortName.Replace(xInvalidChar, '_');
                    }

                    int n = 1;
                    List<FatDirectoryEntry> xDirectoryEntries = ReadDirectoryContents(true);
                    string[] xShortFilenames = new string[xDirectoryEntries.Count];

                    for (int i = 0; i < xDirectoryEntries.Count; i++)
                    {
                        xShortFilenames[i] = xDirectoryEntries[i].mName;
                    }

                    string xNameTry = "";

                    bool xTest = false;

                    do
                    {
                        xNameTry = (xShortName.Substring(0, 7 - n.ToString().Length) + "~" + n).ToUpperInvariant();

                        if (!string.IsNullOrEmpty(xExt))
                        {
                            xNameTry += '.' + xExt.ToUpperInvariant();
                        }

                        n++;

                        xTest = false;

                        foreach (string name in xShortFilenames)
                        {
                            if (name == xNameTry)
                            {
                                xTest = true;
                                break;
                            }
                        }
                    }
                    //TODO: Array.TrySZIndexOf plug is not being recognized; to use the generic version of IndexOf, just remove the cast to Array
                    //while (Array.IndexOf((Array)xShortFilenames, xNameTry) != -1);
                    while (xTest);

                    xShortName = xNameTry;

                    uint xChecksum = CalculateChecksum(GetShortName(xShortName));

                    int xNumEntries = (int)Math.Ceiling((double)xLongName.Length / (double)13);

                    char[] xLongNameWithPad = new char[xNumEntries * 13];

                    xLongNameWithPad[xLongNameWithPad.Length - 1] = (char)0xFFFF;
                    Array.Copy(xLongName.ToCharArray(), xLongNameWithPad, xLongName.Length);

                    xDirectoryEntriesToAllocate = GetNextUnallocatedDirectoryEntries(xNumEntries + 1);

                    for (int i = xNumEntries - 1; i >= 0; i--)
                    {
                        uint xEntry = xDirectoryEntriesToAllocate[xNumEntries - i - 1];

                        SetLongFilenameEntryMetadataValue(xEntry, FatDirectoryEntryMetadata.LongFilenameEntryMetadata.SequenceNumberAndAllocationStatus, (i + 1) | (i == xNumEntries - 1 ? (1 << 6) : 0));
                        SetLongFilenameEntryMetadataValue(xEntry, FatDirectoryEntryMetadata.LongFilenameEntryMetadata.Attributes, FatDirectoryEntryAttributeConsts.LongName);
                        SetLongFilenameEntryMetadataValue(xEntry, FatDirectoryEntryMetadata.LongFilenameEntryMetadata.Checksum, xChecksum);

                        SetLongFilenameEntryMetadataValue(xEntry, FatDirectoryEntryMetadata.LongFilenameEntryMetadata.LongName1, new string(xLongNameWithPad, i * 13, 5));
                        SetLongFilenameEntryMetadataValue(xEntry, FatDirectoryEntryMetadata.LongFilenameEntryMetadata.LongName2, new string(xLongNameWithPad, i * 13 + 5, 6));
                        SetLongFilenameEntryMetadataValue(xEntry, FatDirectoryEntryMetadata.LongFilenameEntryMetadata.LongName3, new string(xLongNameWithPad, i * 13 + 11, 2));
                    }
                }

                string xFullPath = Path.Combine(mFullPath, aName);
                uint xFirstCluster = ((FatFileSystem)mFileSystem).GetFat(0).GetNextUnallocatedFatEntry();
                uint xEntryHeaderDataOffset = xDirectoryEntriesToAllocate == null ? GetNextUnallocatedDirectoryEntry() : xDirectoryEntriesToAllocate[xDirectoryEntriesToAllocate.Length - 1];

                Global.mFileSystemDebugger.SendInternal("xFullPath =");
                Global.mFileSystemDebugger.SendInternal(xFullPath);
                Global.mFileSystemDebugger.SendInternal("xFirstCluster =");
                Global.mFileSystemDebugger.SendInternal(xFirstCluster);
                Global.mFileSystemDebugger.SendInternal("xEntryHeaderDataOffset =");
                Global.mFileSystemDebugger.SendInternal(xEntryHeaderDataOffset);

                var xNewEntry = new FatDirectoryEntry((FatFileSystem)mFileSystem, this, xFullPath, aName, 0, xFirstCluster, xEntryHeaderDataOffset, aEntryType);

                xNewEntry.AllocateDirectoryEntry(xShortName);

                return xNewEntry;
            }

            throw new ArgumentOutOfRangeException(nameof(aEntryType), "Unknown directory entry type.");
        }
Example #5
0
 public FatDirectoryEntry AddDirectoryEntry(string aName, DirectoryEntryTypeEnum aType)
 {
     FileSystemHelpers.Debug("FatDirectoryEntry.AddDirectoryEntry");
     if ((aType == DirectoryEntryTypeEnum.Directory) || (aType == DirectoryEntryTypeEnum.File))
     {
         uint xFirstCluster = mFileSystem.GetFat(0).GetNextUnallocatedFatEntry();
         uint xEntryHeaderDataOffset = GetNextUnallocatedEntry();
         var xNewEntry = new FatDirectoryEntry(mFileSystem, this, aName, 0, xFirstCluster, xEntryHeaderDataOffset, aType);
         xNewEntry.AllocateDirectoryEntry();
         return xNewEntry;
     }
     throw new ArgumentOutOfRangeException("aType", "Unknown directory entry type.");
 }
Example #6
0
 public FatDirectoryEntry AddDirectoryEntry(string aName, DirectoryEntryTypeEnum aType)
 {
     FileSystemHelpers.Debug("FatDirectoryEntry.AddDirectoryEntry", "aName =", aName, ", aType =", aType.ToString());
     if (aType == DirectoryEntryTypeEnum.Directory)
     {
         uint xFirstCluster = mFileSystem.GetFat(0).GetNextUnallocatedFatEntry();
         uint xEntryHeaderDataOffset = GetNextUnallocatedEntry();
         var xNewEntry = new FatDirectoryEntry(
             mFileSystem,
             this,
             aName,
             0,
             xFirstCluster,
             xEntryHeaderDataOffset,
             aType);
         xNewEntry.AllocateDirectoryEntry();
         return xNewEntry;
     }
     if (aType == DirectoryEntryTypeEnum.File)
     {
         throw new NotImplementedException("Creating new files is currently not implemented.");
     }
     throw new ArgumentOutOfRangeException("aType", "Unknown directory entry type.");
 }