Esempio n. 1
0
        /// <summary>
        /// Sets the volume label that is stored in this directory. Setting the
        /// volume label is supported on the root directory only.
        /// </summary>
        /// <param name="label">the new volume label</param>
        /// <exception cref="ArgumentException">ArgumentException if the label is too long</exception>
        /// <exception cref="NotSupportedException">NotSupportedException if this is not a root directory</exception>
        /// <seealso cref="IsRoot"/>
        public void SetLabel(string label)
        {
            CheckRoot();

            if (label.Length > MAX_LABEL_LENGTH)
            {
                throw new
                      ArgumentException("label too long");
            }

            if (volumeLabel != null)
            {
                if (label == null)
                {
                    ChangeSize(GetSize() - 1);
                    volumeLabel = null;
                }
                else
                {
                    ShortName.CheckValidChars(label.ToCharArray());
                    volumeLabel = label;
                }
            }
            else
            {
                if (label != null)
                {
                    ChangeSize(GetSize() + 1);
                    ShortName.CheckValidChars(label.ToCharArray());
                    volumeLabel = label;
                }
            }

            dirty = true;
        }
Esempio n. 2
0
        /**
         * Returns the {@code ShortName} that is stored in this directory entry or
         * {@code null} if this entry has not been initialized.
         *
         * @return the {@code ShortName} stored in this entry or {@code null}
         */
        public ShortName GetShortName()
        {
            if (data[0] == 0)
            {
                return(null);
            }

            return(ShortName.Parse(data));
        }
Esempio n. 3
0
        public void SetShortName(ShortName sn)
        {
            if (sn.Equals(GetShortName()))
            {
                return;
            }

            sn.Write(data);
            HasShortNameOnly = sn.HasShortNameOnly();
            dirty            = true;
        }
Esempio n. 4
0
        internal FatLfnDirectoryEntry(string name, ShortName sn, FatLfnDirectory parent, bool directory) : base(false)
        {
            this.parent = parent;
            fileName    = name;

            var now = (long)(DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)).TotalMilliseconds;

            RealEntry = FatDirectoryEntry.Create(directory);
            RealEntry.SetShortName(sn);
            RealEntry.SetCreated(now);
            RealEntry.SetLastAccessed(now);
        }
Esempio n. 5
0
        /// <summary>
        /// According to the FAT file system specification, leading and trailing
        /// spaces in the name are ignored by this method.
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        public IFsDirectoryEntry GetEntry(string name)
        {
            name = name.Trim().ToLowerInvariant();

            longNameIndex.TryGetValue(name, out var entry);

            if (entry == null)
            {
                if (!ShortName.CanConvert(name))
                {
                    return(null);
                }
                return(shortNameIndex[ShortName.Get(name)]);
            }

            return(entry);
        }
        /// <summary>
        /// See original C Linux patch by Andrew Tridgell ([email protected])
        /// build a 11 byte 8.3 buffer which is not a short filename. We want 11
        /// bytes which: - will be seen as a constant string to all APIs on Linux and
        /// Windows - cannot be matched with wildcard patterns - cannot be used to
        /// access the file - has a low probability of collision within a directory -
        /// has an invalid 3 byte extension - contains at least one non-space and
        /// non-nul byte
        /// </summary>
        /// <param name="longFullName">the long file name to generate the buffer for</param>
        /// <returns>the generated 8.3 buffer</returns>
        public ShortName Generate83BufferNew(string longFullName)
        {
            if (longFullName == null)
            {
                throw new ArgumentNullException(nameof(longFullName));
            }

            var retBuffer = new char[11];

            var hasRealShortName = false;// getRealShortNameInstead(longFullName,

            // retBuffer);
            if (!hasRealShortName)
            {
                int i, tildePos, slashPos;
                var randomNumber = Math.Abs(mRandom.Next());

                /*
                 * the '/' makes sure that even unpatched Linux systems can't get at
                 * files by the 8.3 entry.
                 */

                slashPos       = randomNumber % 8;
                randomNumber >>= 3;

                /*
                 * fill in the first 8 bytes with invalid characters. Note that we
                 * need to be careful not to run out of randomness. We use the same
                 * extension for all buffers.
                 */
                for (i = 0; i < 8; i++)
                {
                    if (i == slashPos)
                    {
                        retBuffer[i] = '/';
                    }
                    else
                    {
                        retBuffer[i] =
                            Invalidchar[randomNumber % Invalidchar.Length];
                        randomNumber /= Invalidchar.Length;
                        if (randomNumber < Invalidchar.Length)
                        {
                            randomNumber = Math.Abs(mRandom.Next());
                        }
                    }
                }

                for (i = 0; i < 8; i++)
                {
                    if (retBuffer[i] == 0xe5)
                    {
                        throw new Exception();
                    }
                }

                retBuffer[8]  = 'i';
                retBuffer[9]  = 'f';
                retBuffer[10] = 'l';
            }
            var retName = new ShortName(retBuffer);

            retName.SetHasShortNameOnly(hasRealShortName);
            return(retName);
        }