コード例 #1
0
        public FatDirectoryStream(Listing.FatDirectory aDirectory)
        {
            mDirectory = aDirectory;
            mFS        = mDirectory.FileSystem;
            if (mFS == null)
            {
                FatHelpers.Debug("mFS is null!");
            }

            if (mDirectory.Size > 0)
            {
                mFatTable = mFS.GetFatTable(mDirectory.FirstClusterNum);
            }
        }
コード例 #2
0
        public FatDirectoryStream(Listing.FatDirectory aDirectory)
        {
            mDirectory = aDirectory;
            mFS = mDirectory.FileSystem;
            if (mFS == null)
            {
                FatHelpers.Debug("mFS is null!");
            }

            if (mDirectory.Size > 0)
            {
                mFatTable = mFS.GetFatTable(mDirectory.FirstClusterNum);
            }
        }
コード例 #3
0
ファイル: FatFileSystem.cs プロジェクト: nstone101/Cosmos
 public void SetDirectoryLength(FatDirectory file, long value)
 {
     throw new NotImplementedException("Changing directory length not yet implemented!");
 }
コード例 #4
0
ファイル: FatFileSystem.cs プロジェクト: nstone101/Cosmos
        private List<Base> GetDirectoryContents(FatDirectory directory, Stream directoryContents)
        {
            if (directory == null)
            {
                throw new ArgumentNullException("directory");
            }

            FatHelpers.Debug("--GetDirectoryContents");
            if (directoryContents == null)
            {
                FatHelpers.Debug("No Stream specified!");
            }
            else
            {
                FatHelpers.Debug("Stream specified.");
            }

            var xResult = new List<Base>();
            //TODO: Change xLongName to StringBuilder
            string xLongName = "";
            string xName = "";
            var xBuff = new byte[32];
            FatHelpers.Debug("Stream.Position");
            FatHelpers.DebugNumber((uint) directoryContents.Position);
            FatHelpers.Debug("Stream.Length");
            FatHelpers.DebugNumber((uint) directoryContents.Length);

            if (directoryContents.Position < directoryContents.Length)
            {
                FatHelpers.Debug("Data to read!");
            }
            else
            {
                FatHelpers.Debug("No data to read!");
            }

            while (directoryContents.Position < directoryContents.Length)
            {
                if (directoryContents.Read(xBuff, 0, 32) != 32)
                {
                    FatHelpers.Debug("Not enough data read!");
                    throw new Exception("Unable to read 32 bytes from stream!");
                }
                FatHelpers.Debug("No data read");
                FatHelpers.DevDebug("-------------------------------------------------");
                byte xAttrib = xBuff[11];
                byte xStatus = xBuff[0];

                FatHelpers.DevDebug("Attrib = " + xAttrib.ToString() + ", Status = " + xStatus);
                if (xAttrib == DirectoryEntryAttributeConsts.LongName)
                {
                    byte xType = xBuff[12];
                    byte xOrd = xBuff[0];
                    FatHelpers.DevDebug("Reading LFN with Seqnr " + xOrd.ToString() + ", Type = " + xType);
                    if (xOrd == 0xE5)
                    {
                        FatHelpers.DevDebug("Skipping deleted entry");
                        continue;
                    }
                    if (xType == 0)
                    {
                        if ((xOrd & 0x40) > 0)
                        {
                            xLongName = "";
                        }
                        //TODO: Check LDIR_Ord for ordering and throw exception
                        // if entries are found out of order.
                        // Also save buffer and only copy name if a end Ord marker is found.
                        string xLongPart = xBuff.GetUtf16String(0 + 1, 5);
                        // We have to check the length because 0xFFFF is a valid Unicode codepoint.
                        // So we only want to stop if the 0xFFFF is AFTER a 0x0000. We can determin
                        // this by also looking at the length. Since we short circuit the or, the length
                        // is rarely evaluated.
                        if (xBuff.ToUInt16(0 + 14) != 0xFFFF || xLongPart.Length == 5)
                        {
                            xLongPart = xLongPart + xBuff.GetUtf16String(0 + 14, 6);
                            if (xBuff.ToUInt16(0 + 28) != 0xFFFF || xLongPart.Length == 11)
                            {
                                xLongPart = xLongPart + xBuff.GetUtf16String(0 + 28, 2);
                            }
                        }
                        xLongName = xLongPart + xLongName;
                        xLongPart = null;
                        //TODO: LDIR_Chksum
                    }
                }
                else
                {
                    xName = xLongName;
                    if (xStatus == 0x00)
                    {
                        // Empty slot, and no more entries after this
                        break;
                    }
                    else if (xStatus == 0x05)
                    {
                        // Japanese characters - We dont handle these
                    }
                    else if (xStatus == 0xE5)
                    {
                        // Empty slot, skip it
                    }
                    else if (xStatus >= 0x20)
                    {
                        if (xLongName.Length > 0)
                        {
                            // Leading and trailing spaces are to be ignored according to spec.
                            // Many programs (including Windows) pad trailing spaces although it
                            // it is not required for long names.
                            // As per spec, ignore trailing periods
                            xName = xLongName.Trim();

                            //If there are trailing periods
                            int nameIndex = xName.Length - 1;
                            if (xName[nameIndex] == '.')
                            {
                                //Search backwards till we find the first non-period character
                                for (; nameIndex > 0; nameIndex--)
                                {
                                    if (xName[nameIndex] != '.')
                                    {
                                        break;
                                    }
                                }
                                //Substring to remove the periods
                                xName = xName.Substring(0, nameIndex + 1);
                            }
                            xLongName = "";
                        }
                        else
                        {
                            string xEntry = xBuff.GetAsciiString(0, 11);
                            xName = xEntry.Substring(0, 8).TrimEnd();
                            string xExt = xEntry.Substring(8, 3).TrimEnd();
                            if (xExt.Length > 0)
                            {
                                xName = xName + "." + xExt;
                            }
                        }
                    }
                }
                UInt32 xFirstCluster = (UInt32)(xBuff.ToUInt16(0 + 20) << 16 | xBuff.ToUInt16(0 + 26));

                var xTest = xAttrib & (DirectoryEntryAttributeConsts.Directory | DirectoryEntryAttributeConsts.VolumeID);
                if (xAttrib == DirectoryEntryAttributeConsts.LongName)
                {
                    // skip adding, as it's a LongFileName entry, meaning the next normal entry is the item with the name.
                    FatHelpers.Debug("Entry was an Long FileName entry. Current LongName = '" + xLongName + "'");
                }
                else if (xTest == 0)
                {
                    UInt32 xSize = xBuff.ToUInt32(0 + 28);
                    if (xSize == 0 && xName.Length == 0)
                    {
                        continue;
                    }
                    xResult.Add(new FatFile(this, xName, xSize, xFirstCluster, directory));
                    FatHelpers.Debug("Returning file '" + xName + "'");
                }
                else if (xTest == DirectoryEntryAttributeConsts.Directory)
                {
                    UInt32 xSize = xBuff.ToUInt32(0 + 28);
                    var xFatDirectory = new FatDirectory(this, xName, xFirstCluster, directory, xSize);
                    FatHelpers.Debug("Returning directory '" + xFatDirectory.Name + "', FirstCluster = " + xFirstCluster);
                    xResult.Add(xFatDirectory);
                }
                else if (xTest == DirectoryEntryAttributeConsts.VolumeID)
                {
                    FatHelpers.DevDebug("Directory entry is VolumeID");
                    //
                }
                else
                {
                    FatHelpers.DevDebug("Not sure what to do!");
                }
            }

            return xResult;
        }
コード例 #5
0
        public TestFatDirectoryStream(FatDirectory directory) : base(directory, directory.FileSystem, directory.FirstClusterNum)
        {

        }
コード例 #6
0
ファイル: FatFile.cs プロジェクト: nstone101/Cosmos
 // Size is UInt32 because FAT doesn't support bigger.
 // Dont change to UInt64
 public FatFile(FatFileSystem aFileSystem, string aName, UInt32 aSize, UInt64 aFirstCluster, FatDirectory baseDirectory)
     : base(aFileSystem, aName, aSize, baseDirectory)
 {
     FileSystem = aFileSystem;
     FirstClusterNum = aFirstCluster;
 }
コード例 #7
0
ファイル: FatFile.cs プロジェクト: nstone101/Cosmos
 // Size is UInt32 because FAT doesn't support bigger.
 // Dont change to UInt64
 public FatFile(FatFileSystem aFileSystem, string aName, UInt32 aSize, UInt64 aFirstCluster, FatDirectory baseDirectory)
     : base(aFileSystem, aName, aSize, baseDirectory)
 {
     FileSystem      = aFileSystem;
     FirstClusterNum = aFirstCluster;
 }