Example #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);
        }
Example #2
0
 internal DirectoryEntry(FatFileSystemOptions options, FileName name, FatAttributes attrs, FatType fatVariant)
 {
     _options      = options;
     _fatVariant   = fatVariant;
     Name          = name;
     _attr         = (byte)attrs;
     _longFileName = LongFileName.Empty;
 }
Example #3
0
 internal DirectoryEntry(FatFileSystemOptions options, Stream stream, FatType fatVariant)
 {
     _options      = options;
     _fatVariant   = fatVariant;
     _longFileName = new LongFileName();
     byte[] buffer = StreamUtilities.ReadExact(stream, 32);
     _buffer = buffer;
     Load(buffer, 0);
 }
Example #4
0
        public void CopyTo(LongFileName target)
        {
            if (_readOnly || target._readOnly)
            {
                return;
            }
            foreach (LongFileNameEntry entry in _entries)
            {
                byte[] copyData = new byte[entry.Data.Length];
                Array.Copy(entry.Data, 0, copyData, 0, copyData.Length);

                target._entries.Add(new LongFileNameEntry(copyData, entry.Offset, entry.IsFirstEntry));
            }
        }
Example #5
0
 internal DirectoryEntry(DirectoryEntry toCopy)
 {
     _options           = toCopy._options;
     _fatVariant        = toCopy._fatVariant;
     Name               = toCopy.Name;
     _attr              = toCopy._attr;
     _creationTimeTenth = toCopy._creationTimeTenth;
     _creationTime      = toCopy._creationTime;
     _creationDate      = toCopy._creationDate;
     _lastAccessDate    = toCopy._lastAccessDate;
     _firstClusterHi    = toCopy._firstClusterHi;
     _lastWriteTime     = toCopy._lastWriteTime;
     _firstClusterLo    = toCopy._firstClusterLo;
     _fileSize          = toCopy._fileSize;
     _longFileName      = new LongFileName();
     toCopy._longFileName.CopyTo(_longFileName);
 }
Example #6
0
        public FileName(string longname, Encoding encoding, Func <string, string> getShortName)
        {
            _longFileName = new LongFileName(longname);
            var name = getShortName(longname);

            _raw = new byte[11];
            byte[] bytes = encoding.GetBytes(name.ToUpperInvariant());

            int nameIdx = 0;
            int rawIdx  = 0;

            while (nameIdx < bytes.Length && bytes[nameIdx] != '.' && rawIdx < _raw.Length)
            {
                byte b = bytes[nameIdx++];
                if (b < 0x20 || Contains(InvalidBytes, b))
                {
                    throw new ArgumentException("Invalid character in file name '" + (char)b + "'", "name");
                }

                _raw[rawIdx++] = b;
            }

            if (rawIdx > 8)
            {
                throw new ArgumentException("File name too long '" + name + "'", "name");
            }
            else if (rawIdx == 0)
            {
                throw new ArgumentException("File name too short '" + name + "'", "name");
            }

            while (rawIdx < 8)
            {
                _raw[rawIdx++] = SpaceByte;
            }

            if (nameIdx < bytes.Length && bytes[nameIdx] == '.')
            {
                ++nameIdx;
            }

            while (nameIdx < bytes.Length && rawIdx < _raw.Length)
            {
                byte b = bytes[nameIdx++];
                if (b < 0x20 || Contains(InvalidBytes, b))
                {
                    throw new ArgumentException("Invalid character in file extension '" + (char)b + "'", "name");
                }

                _raw[rawIdx++] = b;
            }

            while (rawIdx < 11)
            {
                _raw[rawIdx++] = SpaceByte;
            }

            if (nameIdx != bytes.Length)
            {
                throw new ArgumentException("File extension too long '" + name + "'", "name");
            }
        }
Example #7
0
 public FileName(byte[] data, int offset, LongFileName longFileName)
 {
     _raw = new byte[11];
     Array.Copy(data, offset, _raw, 0, 11);
     _longFileName = longFileName;
 }
Example #8
0
 public FileName(byte[] data, int offset, string longFileName = null)
 {
     _raw = new byte[11];
     Array.Copy(data, offset, _raw, 0, 11);
     _longFileName = !string.IsNullOrEmpty(longFileName) ? new LongFileName(longFileName) : null;
 }
Example #9
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);
                }
            }
        }