Example #1
0
        public FatDirectoryEntry CreateSub(Fat fat)
        {
            var chain = new ClusterChain(fat, false);

            chain.SetChainLength(1);

            var entry = FatDirectoryEntry.Create(true);

            entry.SetStartCluster(chain.GetStartCluster());

            var dir =
                new ClusterChainDirectory(chain, false);

            /* add "." entry */

            var dot = FatDirectoryEntry.Create(true);

            dot.SetShortName(ShortName.Dot);
            dot.SetStartCluster(dir.GetStorageCluster());
            CopyDateTimeFields(entry, dot);
            dir.AddEntry(dot);

            /* add ".." entry */

            var dotDot = FatDirectoryEntry.Create(true);

            dotDot.SetShortName(ShortName.DotDot);
            dotDot.SetStartCluster(GetStorageCluster());
            CopyDateTimeFields(entry, dotDot);
            dir.AddEntry(dotDot);

            dir.Flush();

            return(entry);
        }
Example #2
0
        /// <summary>
        /// Sets the size (in bytes) of this file. Because
        /// <see cref="Write(long, MemoryStream)"/> to the file will grow
        /// it automatically if needed, this method is mainly usefull for truncating
        /// a file.
        /// </summary>
        /// <param name="length">the new length of the file in bytes</param>
        /// <exception cref="ReadOnlyException">ReadOnlyException if this file is read-only</exception>
        /// <exception cref="IOException">IOException on error updating the file size</exception>
        public void SetLength(long length)
        {
            CheckWritable();

            if (GetLength() == length)
            {
                return;
            }

            UpdateTimeStamps(true);
            chain.SetSize(length);

            entry.SetStartCluster(chain.GetStartCluster());
            entry.SetLength(length);
        }
Example #3
0
        public static ClusterChainDirectory CreateRoot(Fat fat)
        {
            if (fat.GetFatType() != FatType.BaseFat32)
            {
                throw new ArgumentException(
                          "only FAT32 stores root directory in a cluster chain");
            }

            var bs = (Fat32BootSector)fat.GetBootSector();
            var cc = new ClusterChain(fat, false);

            cc.SetChainLength(1);

            bs.SetRootDirFirstCluster(cc.GetStartCluster());

            var result =
                new ClusterChainDirectory(cc, true);

            result.Flush();
            return(result);
        }
Example #4
0
 /// <summary>
 /// Returns the first cluster of the chain that stores this directory for
 /// non-root instances or 0 if this is the root directory.
 /// </summary>
 /// <returns>the first storage cluster of this directory</returns>
 /// <seealso cref="AbstractDirectory.IsRoot"/>
 protected override long GetStorageCluster()
 {
     return(IsRoot() ? 0 : Chain.GetStartCluster());
 }