Ejemplo n.º 1
0
        internal static LongFileName FromPath(string path)
        {
            byte[]       pathData = Encoding.Unicode.GetBytes(path);
            LongFileName lfn      = new LongFileName();

            for (int offset = 0; offset < pathData.Length; offset += 26)
            {
                byte[] segmentData = new byte[32];

                segmentData[0x00] = (byte)(offset == 0 ? 0x42 : 0x01); /* Reserved */
                // 0x01+10 - LFS Name
                segmentData[0x0B] = (byte)0x0F;                        /* Attributes (ReadOnly, Hidden, System and VolumeId) */
                segmentData[0x0C] = (byte)0x00;                        /* Reserved */
                segmentData[0x0D] = (byte)0x00;                        /* Checksum */
                // 0x0E+12 - LFS Name
                segmentData[0x1B] = (byte)0x00;                        /* Reserved */
                // 0x1C+4 - LFS Name

                Array.Copy(pathData, offset + 0, segmentData, 0x01, 10);
                Array.Copy(pathData, offset + 10, segmentData, 0x0E, 12);
                Array.Copy(pathData, offset + 22, segmentData, 0x1C, 4);

                lfn.AddEntry(segmentData, 0);
            }

            return(lfn);
        }
Ejemplo n.º 2
0
        private void LoadEntries()
        {
            LongFileName lfnData = new LongFileName();

            _entries     = new Dictionary <long, DirectoryEntry>();
            _freeEntries = new List <long>();

            _selfEntryLocation   = -1;
            _parentEntryLocation = -1;

            while (_dirStream.Position < _dirStream.Length)
            {
                long           streamPos = _dirStream.Position;
                DirectoryEntry entry     = new DirectoryEntry(FileSystem.FatOptions, _dirStream, FileSystem.FatVariant);

                if (entry.Attributes ==
                    (FatAttributes.ReadOnly | FatAttributes.Hidden | FatAttributes.System | FatAttributes.VolumeId))
                {
                    // Long File Name entry
                    lfnData.AddEntry(entry);
                }
                else if (entry.Name.IsDeleted())
                {
                    lfnData.CopyTo(entry.LongName);
                    lfnData.Clear();

                    // E5 = Free Entry
                    _freeEntries.Add(streamPos);
                }
                else if (entry.Name == FileName.SelfEntryName)
                {
                    lfnData.CopyTo(entry.LongName);
                    lfnData.Clear();

                    _selfEntry         = entry;
                    _selfEntryLocation = streamPos;
                }
                else if (entry.Name == FileName.ParentEntryName)
                {
                    lfnData.CopyTo(entry.LongName);
                    lfnData.Clear();

                    _parentEntry         = entry;
                    _parentEntryLocation = streamPos;
                }
                else if (entry.Name.IsEndMarker())
                {
                    lfnData.CopyTo(entry.LongName);
                    lfnData.Clear();

                    // Free Entry, no more entries available
                    _endOfEntries = streamPos;
                    break;
                }
                else
                {
                    lfnData.CopyTo(entry.LongName);
                    lfnData.Clear();

                    _entries.Add(streamPos, entry);
                }
            }
        }